Skip to content

Commit 1c6d485

Browse files
author
Cruz Monrreal
authored
Merge pull request #6572 from TeemuKultala/at_send_wait
cellular: ATHandler send delay
2 parents 495ae06 + 328919c commit 1c6d485

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#ifdef MBED_CONF_RTOS_PRESENT
2525
#include "rtos/Thread.h"
2626
#endif
27+
#include "Kernel.h"
2728

2829
using namespace mbed;
2930
using namespace events;
@@ -58,7 +59,7 @@ static const uint8_t map_3gpp_errors[][2] = {
5859
{ 146, 46 }, { 178, 65 }, { 179, 66 }, { 180, 48 }, { 181, 83 }, { 171, 49 },
5960
};
6061

61-
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter) :
62+
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) :
6263
_nextATHandler(0),
6364
_fileHandle(fh),
6465
_queue(queue),
@@ -68,6 +69,8 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
6869
_oobs(NULL),
6970
_at_timeout(timeout),
7071
_previous_at_timeout(timeout),
72+
_at_send_delay(send_delay),
73+
_last_response_stop(0),
7174
_fh_sigio_set(false),
7275
_processing(false),
7376
_ref_count(1),
@@ -893,6 +896,8 @@ void ATHandler::resp_stop()
893896
set_tag(&_resp_stop, OK);
894897
// Reset info resp prefix
895898
memset(_info_resp_prefix, 0, sizeof(_info_resp_prefix));
899+
900+
_last_response_stop = rtos::Kernel::get_ms_count();
896901
}
897902

898903
void ATHandler::information_response_stop()
@@ -936,8 +941,21 @@ const char* ATHandler::mem_str(const char* dest, size_t dest_len, const char* sr
936941

937942
void ATHandler::cmd_start(const char* cmd)
938943
{
944+
945+
if (_at_send_delay) {
946+
uint64_t current_time = rtos::Kernel::get_ms_count();
947+
uint64_t time_difference = current_time - _last_response_stop;
948+
949+
if (time_difference < (uint64_t)_at_send_delay) {
950+
wait_ms((uint64_t)_at_send_delay - time_difference);
951+
tr_debug("AT wait %llu %llu", current_time, _last_response_stop);
952+
}
953+
}
954+
939955
tr_debug("AT> %s", cmd);
940956

957+
958+
941959
if (_last_err != NSAPI_ERROR_OK) {
942960
return;
943961
}

features/cellular/framework/AT/ATHandler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ class ATHandler
7474
* @param queue Event queue used to transfer sigio events to this thread
7575
* @param timeout Timeout when reading for AT response
7676
* @param output_delimiter delimiter used when parsing at responses, "\r" should be used as output_delimiter
77+
* @param send_delay the minimum delay in ms between the end of last response and the beginning of a new command
7778
*/
78-
ATHandler(FileHandle *fh, events::EventQueue &queue, int timeout, const char *output_delimiter);
79+
ATHandler(FileHandle *fh, events::EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay = 0);
7980
~ATHandler();
8081

8182
/** Return used file handle.
@@ -196,6 +197,9 @@ class ATHandler
196197
uint32_t _at_timeout;
197198
uint32_t _previous_at_timeout;
198199

200+
uint16_t _at_send_delay;
201+
uint64_t _last_response_stop;
202+
199203
bool _fh_sigio_set;
200204

201205
bool _processing;

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ATHandler* AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
6060
atHandler = atHandler->_nextATHandler;
6161
}
6262

63-
atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r");
63+
atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r", get_send_delay());
6464
if (atHandler) {
6565
if (_modem_debug_on) {
6666
atHandler->enable_debug(_modem_debug_on);
@@ -225,6 +225,11 @@ void AT_CellularDevice::set_timeout(int timeout)
225225
}
226226
}
227227

228+
uint16_t AT_CellularDevice::get_send_delay()
229+
{
230+
return 0;
231+
}
232+
228233
void AT_CellularDevice::modem_debug_on(bool on)
229234
{
230235
_modem_debug_on = on;

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class AT_CellularDevice : public CellularDevice
7777

7878
virtual void set_timeout(int timeout);
7979

80+
virtual uint16_t get_send_delay();
81+
8082
virtual void modem_debug_on(bool on);
8183

8284
virtual NetworkStack *get_stack();

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ CellularNetwork *TELIT_HE910::open_network(FileHandle *fh)
5858
}
5959
return _network;
6060
}
61+
62+
uint16_t TELIT_HE910::get_send_delay()
63+
{
64+
return DEFAULT_DELAY_BETWEEN_AT_COMMANDS;
65+
}
66+

features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
#include "AT_CellularDevice.h"
2222

23+
//the delay between sending AT commands
24+
#define DEFAULT_DELAY_BETWEEN_AT_COMMANDS 20
25+
2326
namespace mbed {
2427

2528
class TELIT_HE910 : public AT_CellularDevice
@@ -32,6 +35,7 @@ class TELIT_HE910 : public AT_CellularDevice
3235
public: // from CellularDevice
3336
virtual CellularPower *open_power(FileHandle *fh);
3437
virtual CellularNetwork *open_network(FileHandle *fh);
38+
virtual uint16_t get_send_delay();
3539
};
3640
} // namespace mbed
3741
#endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */

0 commit comments

Comments
 (0)