Skip to content

Commit b666cd6

Browse files
author
Cruz Monrreal
authored
Merge pull request #8299 from hasnainvirk/issue_8285
Making cancel_sending() API robust
2 parents a9f4323 + 603ee28 commit b666cd6

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

features/lorawan/LoRaWANBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ class LoRaWANBase {
493493
* other negative error code if request failed:
494494
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
495495
* LORAWAN_STATUS_BUSY if the send cannot be canceled
496+
* LORAWAN_STATUS_NO_OP if the operation cannot be completed (nothing to cancel)
496497
*/
497498
virtual lorawan_status_t cancel_sending(void) = 0;
498499
};

features/lorawan/LoRaWANStack.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,17 @@ lorawan_status_t LoRaWANStack::stop_sending(void)
272272
return LORAWAN_STATUS_NOT_INITIALIZED;
273273
}
274274

275-
if (_loramac.clear_tx_pipe() == LORAWAN_STATUS_OK) {
275+
lorawan_status_t status = _loramac.clear_tx_pipe();
276+
277+
if (status == LORAWAN_STATUS_OK) {
276278
_ctrl_flags &= ~TX_DONE_FLAG;
277279
_ctrl_flags &= ~TX_ONGOING_FLAG;
278280
_loramac.set_tx_ongoing(false);
279281
_device_current_state = DEVICE_STATE_IDLE;
280282
return LORAWAN_STATUS_OK;
281283
}
282284

283-
return LORAWAN_STATUS_BUSY;
285+
return status;
284286
}
285287

286288
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
@@ -294,11 +296,6 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
294296
if (!null_allowed && !data) {
295297
return LORAWAN_STATUS_PARAMETER_INVALID;
296298
}
297-
// add a link check request with normal data, until the application
298-
// explicitly removes it.
299-
if (_link_check_requested) {
300-
_loramac.setup_link_check_request();
301-
}
302299

303300
if (!_lw_session.active) {
304301
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
@@ -308,6 +305,12 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
308305
return LORAWAN_STATUS_WOULD_BLOCK;
309306
}
310307

308+
// add a link check request with normal data, until the application
309+
// explicitly removes it.
310+
if (_link_check_requested) {
311+
_loramac.setup_link_check_request();
312+
}
313+
311314
lorawan_status_t status;
312315

313316
if (_loramac.nwk_joined() == false) {

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ LoRaMac::LoRaMac()
7777
_mlme_indication(),
7878
_mlme_confirmation(),
7979
_is_nwk_joined(false),
80+
_can_cancel_tx(true),
8081
_continuous_rx2_window_open(false),
8182
_device_class(CLASS_A)
8283
{
@@ -1030,11 +1031,16 @@ int LoRaMac::get_backoff_timer_event_id(void)
10301031

10311032
lorawan_status_t LoRaMac::clear_tx_pipe(void)
10321033
{
1034+
if (!_can_cancel_tx) {
1035+
return LORAWAN_STATUS_BUSY;
1036+
}
1037+
10331038
// check if the event is not already queued
10341039
const int id = get_backoff_timer_event_id();
1040+
10351041
if (id == 0) {
10361042
// No queued send request
1037-
return LORAWAN_STATUS_OK;
1043+
return LORAWAN_STATUS_NO_OP;
10381044
}
10391045

10401046
if (_ev_queue->time_left(id) > 0) {
@@ -1092,6 +1098,7 @@ lorawan_status_t LoRaMac::schedule_tx()
10921098
case LORAWAN_STATUS_DUTYCYCLE_RESTRICTED:
10931099
if (backoff_time != 0) {
10941100
tr_debug("DC enforced: Transmitting in %lu ms", backoff_time);
1101+
_can_cancel_tx = true;
10951102
_lora_time.start(_params.timers.backoff_timer, backoff_time);
10961103
}
10971104
return LORAWAN_STATUS_OK;
@@ -1154,6 +1161,7 @@ lorawan_status_t LoRaMac::schedule_tx()
11541161
_params.is_srv_ack_requested = false;
11551162
}
11561163

1164+
_can_cancel_tx = false;
11571165
return send_frame_on_channel(_params.channel);
11581166
}
11591167

@@ -1238,6 +1246,7 @@ bool LoRaMac::tx_ongoing()
12381246

12391247
void LoRaMac::set_tx_ongoing(bool ongoing)
12401248
{
1249+
_can_cancel_tx = true;
12411250
_ongoing_tx_msg.tx_ongoing = ongoing;
12421251
}
12431252

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ class LoRaMac {
669669

670670
bool _is_nwk_joined;
671671

672+
bool _can_cancel_tx;
673+
672674
bool _continuous_rx2_window_open;
673675

674676
device_class_t _device_class;

features/lorawan/lorawan_types.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,9 @@ typedef enum lorawan_status {
9898
LORAWAN_STATUS_CRYPTO_FAIL = -1014, /**< Service not started - crypto failure */
9999
LORAWAN_STATUS_PORT_INVALID = -1015, /**< Invalid port */
100100
LORAWAN_STATUS_CONNECT_IN_PROGRESS = -1016, /**< Services started - Connection in progress */
101-
LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */
101+
LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */
102102
LORAWAN_STATUS_IDLE = -1018, /**< Services started - Idle at the moment */
103-
#if defined(LORAWAN_COMPLIANCE_TEST)
104-
//Deprecated - will replace the code -1019 with something
105-
//else in future.
106-
LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */
107-
#endif
103+
LORAWAN_STATUS_NO_OP = -1019, /**< Cannot perform requested operation */
108104
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, /**< Transmission will continue after duty cycle backoff*/
109105
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021, /**< None of the channels is enabled at the moment*/
110106
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022, /**< None of the enabled channels is ready for another TX (duty cycle limited)*/

0 commit comments

Comments
 (0)