|
| 1 | +From 1e2795ce9a47146d8c87e4ff957ac3784482e075 Mon Sep 17 00:00:00 2001 |
| 2 | +From: pennam <m.pennasilico@arduino.cc> |
| 3 | +Date: Fri, 17 Nov 2023 17:57:49 +0100 |
| 4 | +Subject: [PATCH 225/226] CellularStateMachine: add state data to timeout and |
| 5 | + retry callbacks |
| 6 | + |
| 7 | +--- |
| 8 | + .../framework/common/CellularCommon.h | 20 +++++++++++++++++++ |
| 9 | + .../framework/device/CellularStateMachine.h | 2 ++ |
| 10 | + .../framework/device/CellularStateMachine.cpp | 11 +++++++--- |
| 11 | + 3 files changed, 30 insertions(+), 3 deletions(-) |
| 12 | + |
| 13 | +diff --git a/connectivity/cellular/include/cellular/framework/common/CellularCommon.h b/connectivity/cellular/include/cellular/framework/common/CellularCommon.h |
| 14 | +index f0466e88cf..96e25dc991 100644 |
| 15 | +--- a/connectivity/cellular/include/cellular/framework/common/CellularCommon.h |
| 16 | ++++ b/connectivity/cellular/include/cellular/framework/common/CellularCommon.h |
| 17 | +@@ -47,6 +47,26 @@ struct cell_signal_quality_t { |
| 18 | + } |
| 19 | + }; |
| 20 | + |
| 21 | ++struct cell_timeout_cb_t { |
| 22 | ++ int timeout; /* configured timeout */ |
| 23 | ++ int state; /* cellular state */ |
| 24 | ++ cell_timeout_cb_t() |
| 25 | ++ { |
| 26 | ++ timeout = -1; |
| 27 | ++ state = -1; |
| 28 | ++ } |
| 29 | ++}; |
| 30 | ++ |
| 31 | ++struct cell_retry_cb_t { |
| 32 | ++ int retry_count; /* retry count */ |
| 33 | ++ int state; /* cellular state */ |
| 34 | ++ cell_retry_cb_t() |
| 35 | ++ { |
| 36 | ++ retry_count = -1; |
| 37 | ++ state = -1; |
| 38 | ++ } |
| 39 | ++}; |
| 40 | ++ |
| 41 | + /** |
| 42 | + * Cellular specific event changes. |
| 43 | + * Connect and disconnect are handled via NSAPI_EVENT_CONNECTION_STATUS_CHANGE |
| 44 | +diff --git a/connectivity/cellular/include/cellular/framework/device/CellularStateMachine.h b/connectivity/cellular/include/cellular/framework/device/CellularStateMachine.h |
| 45 | +index 67912e463c..aed9d615ce 100644 |
| 46 | +--- a/connectivity/cellular/include/cellular/framework/device/CellularStateMachine.h |
| 47 | ++++ b/connectivity/cellular/include/cellular/framework/device/CellularStateMachine.h |
| 48 | +@@ -189,6 +189,8 @@ private: |
| 49 | + bool _command_success; |
| 50 | + bool _is_retry; |
| 51 | + cell_callback_data_t _cb_data; |
| 52 | ++ cell_timeout_cb_t _timeout_cb_data; |
| 53 | ++ cell_retry_cb_t _retry_cb_data; |
| 54 | + cellular_connection_status_t _current_event; |
| 55 | + int _status; |
| 56 | + PlatformMutex _mutex; |
| 57 | +diff --git a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp |
| 58 | +index 833f1d2239..37416ca72e 100644 |
| 59 | +--- a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp |
| 60 | ++++ b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp |
| 61 | +@@ -61,7 +61,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event |
| 62 | + _start_time(rand() % (MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY)), |
| 63 | + #endif // MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY |
| 64 | + _event_timeout(-1s), _event_id(-1), _plmn(0), _command_success(false), |
| 65 | +- _is_retry(false), _cb_data(), _current_event(CellularDeviceReady), _status(0) |
| 66 | ++ _is_retry(false), _cb_data(), _timeout_cb_data(), _retry_cb_data(), _current_event(CellularDeviceReady), _status(0) |
| 67 | + { |
| 68 | + |
| 69 | + // set initial retry values in seconds |
| 70 | +@@ -289,8 +289,10 @@ void CellularStateMachine::retry_state_or_fail() |
| 71 | + if (_retry_count < _retry_array_length) { |
| 72 | + tr_debug("%s: retry %d/%d", get_state_string(_state), _retry_count, _retry_array_length); |
| 73 | + // send info to application/driver about error logic so it can implement proper error logic |
| 74 | ++ _retry_cb_data.retry_count = _retry_count; |
| 75 | ++ _retry_cb_data.state = _state; |
| 76 | + _cb_data.status_data = _current_event; |
| 77 | +- _cb_data.data = &_retry_count; |
| 78 | ++ _cb_data.data = &_retry_cb_data; |
| 79 | + _cb_data.error = NSAPI_ERROR_OK; |
| 80 | + send_event_cb(CellularStateRetryEvent); |
| 81 | + |
| 82 | +@@ -680,8 +682,11 @@ void CellularStateMachine::send_event_cb(cellular_connection_status_t status) |
| 83 | + |
| 84 | + void CellularStateMachine::change_timeout(const std::chrono::duration<int, std::milli> &timeout) |
| 85 | + { |
| 86 | ++ _timeout_cb_data.timeout = timeout.count(); |
| 87 | ++ _timeout_cb_data.state = _state; |
| 88 | ++ |
| 89 | + _cb_data.status_data = _current_event; |
| 90 | +- _cb_data.data = &timeout; |
| 91 | ++ _cb_data.data = &_timeout_cb_data; |
| 92 | + _cb_data.error = NSAPI_ERROR_OK; |
| 93 | + // event callback is a preferred method to communicate to CellularDevice, |
| 94 | + // for example calling CellularDevice::set_timeout would call back to this class |
| 95 | +-- |
| 96 | +2.42.0 |
| 97 | + |
0 commit comments