Skip to content

cellular: ATHandler send delay #6572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/Thread.h"
#endif
#include "Kernel.h"

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

ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter) :
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint16_t send_delay - why uint16_t was chosen? vs int timeout (3rd parameter)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the delay is always positive, and 16 bits is enough for it for practical cases

Copy link
Contributor

@0xc0170 0xc0170 Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I was just asking as basic types should be sufficient , if there was a specific reason to use uint16_t (why then timeout is plain int). If I add a new method here, I would be confused which one to use

_nextATHandler(0),
_fileHandle(fh),
_queue(queue),
Expand All @@ -68,6 +69,8 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char
_oobs(NULL),
_at_timeout(timeout),
_previous_at_timeout(timeout),
_at_send_delay(send_delay),
_last_response_stop(0),
_fh_sigio_set(false),
_processing(false),
_ref_count(1),
Expand Down Expand Up @@ -893,6 +896,8 @@ void ATHandler::resp_stop()
set_tag(&_resp_stop, OK);
// Reset info resp prefix
memset(_info_resp_prefix, 0, sizeof(_info_resp_prefix));

_last_response_stop = rtos::Kernel::get_ms_count();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be 0 to avoid redundant initial waiting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set 0 in the constructor

}

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

void ATHandler::cmd_start(const char* cmd)
{

if (_at_send_delay) {
uint64_t current_time = rtos::Kernel::get_ms_count();
uint64_t time_difference = current_time - _last_response_stop;

if (time_difference < (uint64_t)_at_send_delay) {
wait_ms((uint64_t)_at_send_delay - time_difference);
tr_debug("AT wait %llu %llu", current_time, _last_response_stop);
}
}

tr_debug("AT> %s", cmd);



if (_last_err != NSAPI_ERROR_OK) {
return;
}
Expand Down
6 changes: 5 additions & 1 deletion features/cellular/framework/AT/ATHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class ATHandler
* @param queue Event queue used to transfer sigio events to this thread
* @param timeout Timeout when reading for AT response
* @param output_delimiter delimiter used when parsing at responses, "\r" should be used as output_delimiter
* @param send_delay the minimum delay in ms between the end of last response and the beginning of a new command
*/
ATHandler(FileHandle *fh, events::EventQueue &queue, int timeout, const char *output_delimiter);
ATHandler(FileHandle *fh, events::EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay = 0);
~ATHandler();

/** Return used file handle.
Expand Down Expand Up @@ -196,6 +197,9 @@ class ATHandler
uint32_t _at_timeout;
uint32_t _previous_at_timeout;

uint16_t _at_send_delay;
uint64_t _last_response_stop;

bool _fh_sigio_set;

bool _processing;
Expand Down
7 changes: 6 additions & 1 deletion features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ATHandler* AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
atHandler = atHandler->_nextATHandler;
}

atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r");
atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r", get_send_delay());
if (atHandler) {
if (_modem_debug_on) {
atHandler->enable_debug(_modem_debug_on);
Expand Down Expand Up @@ -225,6 +225,11 @@ void AT_CellularDevice::set_timeout(int timeout)
}
}

uint16_t AT_CellularDevice::get_send_delay()
{
return 0;
}

void AT_CellularDevice::modem_debug_on(bool on)
{
_modem_debug_on = on;
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/AT/AT_CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class AT_CellularDevice : public CellularDevice

virtual void set_timeout(int timeout);

virtual uint16_t get_send_delay();

virtual void modem_debug_on(bool on);

virtual NetworkStack *get_stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ CellularNetwork *TELIT_HE910::open_network(FileHandle *fh)
}
return _network;
}

uint16_t TELIT_HE910::get_send_delay()
{
return DEFAULT_DELAY_BETWEEN_AT_COMMANDS;
}

4 changes: 4 additions & 0 deletions features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#include "AT_CellularDevice.h"

//the delay between sending AT commands
#define DEFAULT_DELAY_BETWEEN_AT_COMMANDS 20

namespace mbed {

class TELIT_HE910 : public AT_CellularDevice
Expand All @@ -32,6 +35,7 @@ class TELIT_HE910 : public AT_CellularDevice
public: // from CellularDevice
virtual CellularPower *open_power(FileHandle *fh);
virtual CellularNetwork *open_network(FileHandle *fh);
virtual uint16_t get_send_delay();
};
} // namespace mbed
#endif /* CELLULAR_TARGETS_TELIT_HE910_TELIT_HE910_H_ */