Skip to content

Commit 5e4e79d

Browse files
pennamfacchinm
authored andcommitted
CellularStateMachine: add state data to timeout and retry callbacks
1 parent 05c0e3f commit 5e4e79d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

connectivity/cellular/include/cellular/framework/common/CellularCommon.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ struct cell_signal_quality_t {
4747
}
4848
};
4949

50+
struct cell_timeout_cb_t {
51+
int timeout; /* configured timeout */
52+
int state; /* cellular state */
53+
cell_timeout_cb_t()
54+
{
55+
timeout = -1;
56+
state = -1;
57+
}
58+
};
59+
60+
struct cell_retry_cb_t {
61+
int retry_count; /* retry count */
62+
int state; /* cellular state */
63+
cell_retry_cb_t()
64+
{
65+
retry_count = -1;
66+
state = -1;
67+
}
68+
};
69+
5070
/**
5171
* Cellular specific event changes.
5272
* Connect and disconnect are handled via NSAPI_EVENT_CONNECTION_STATUS_CHANGE

connectivity/cellular/include/cellular/framework/device/CellularStateMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ class CellularStateMachine {
189189
bool _command_success;
190190
bool _is_retry;
191191
cell_callback_data_t _cb_data;
192+
cell_timeout_cb_t _timeout_cb_data;
193+
cell_retry_cb_t _retry_cb_data;
192194
cellular_connection_status_t _current_event;
193195
int _status;
194196
PlatformMutex _mutex;

connectivity/cellular/source/framework/device/CellularStateMachine.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event
6161
_start_time(rand() % (MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY)),
6262
#endif // MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY
6363
_event_timeout(-1s), _event_id(-1), _plmn(0), _command_success(false),
64-
_is_retry(false), _cb_data(), _current_event(CellularDeviceReady), _status(0)
64+
_is_retry(false), _cb_data(), _timeout_cb_data(), _retry_cb_data(), _current_event(CellularDeviceReady), _status(0)
6565
{
6666

6767
// set initial retry values in seconds
@@ -289,8 +289,10 @@ void CellularStateMachine::retry_state_or_fail()
289289
if (_retry_count < _retry_array_length) {
290290
tr_debug("%s: retry %d/%d", get_state_string(_state), _retry_count, _retry_array_length);
291291
// send info to application/driver about error logic so it can implement proper error logic
292+
_retry_cb_data.retry_count = _retry_count;
293+
_retry_cb_data.state = _state;
292294
_cb_data.status_data = _current_event;
293-
_cb_data.data = &_retry_count;
295+
_cb_data.data = &_retry_cb_data;
294296
_cb_data.error = NSAPI_ERROR_OK;
295297
send_event_cb(CellularStateRetryEvent);
296298

@@ -680,8 +682,11 @@ void CellularStateMachine::send_event_cb(cellular_connection_status_t status)
680682

681683
void CellularStateMachine::change_timeout(const std::chrono::duration<int, std::milli> &timeout)
682684
{
685+
_timeout_cb_data.timeout = timeout.count();
686+
_timeout_cb_data.state = _state;
687+
683688
_cb_data.status_data = _current_event;
684-
_cb_data.data = &timeout;
689+
_cb_data.data = &_timeout_cb_data;
685690
_cb_data.error = NSAPI_ERROR_OK;
686691
// event callback is a preferred method to communicate to CellularDevice,
687692
// for example calling CellularDevice::set_timeout would call back to this class

0 commit comments

Comments
 (0)