Skip to content

Making cancel_sending() API robust #8299

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 1 commit into from
Oct 15, 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
1 change: 1 addition & 0 deletions features/lorawan/LoRaWANBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ class LoRaWANBase {
* other negative error code if request failed:
* LORAWAN_STATUS_NOT_INITIALIZED if system is not initialized with initialize(),
* LORAWAN_STATUS_BUSY if the send cannot be canceled
* LORAWAN_STATUS_NO_OP if the operation cannot be completed (nothing to cancel)
*/
virtual lorawan_status_t cancel_sending(void) = 0;
};
Expand Down
17 changes: 10 additions & 7 deletions features/lorawan/LoRaWANStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,17 @@ lorawan_status_t LoRaWANStack::stop_sending(void)
return LORAWAN_STATUS_NOT_INITIALIZED;
}

if (_loramac.clear_tx_pipe() == LORAWAN_STATUS_OK) {
lorawan_status_t status = _loramac.clear_tx_pipe();

if (status == LORAWAN_STATUS_OK) {
_ctrl_flags &= ~TX_DONE_FLAG;
_ctrl_flags &= ~TX_ONGOING_FLAG;
_loramac.set_tx_ongoing(false);
_device_current_state = DEVICE_STATE_IDLE;
return LORAWAN_STATUS_OK;
}

return LORAWAN_STATUS_BUSY;
return status;
}

int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
Expand All @@ -294,11 +296,6 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
if (!null_allowed && !data) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
// add a link check request with normal data, until the application
// explicitly removes it.
if (_link_check_requested) {
_loramac.setup_link_check_request();
}

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

// add a link check request with normal data, until the application
// explicitly removes it.
if (_link_check_requested) {
_loramac.setup_link_check_request();
}

lorawan_status_t status;

if (_loramac.nwk_joined() == false) {
Expand Down
11 changes: 10 additions & 1 deletion features/lorawan/lorastack/mac/LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ LoRaMac::LoRaMac()
_mlme_indication(),
_mlme_confirmation(),
_is_nwk_joined(false),
_can_cancel_tx(true),
_continuous_rx2_window_open(false),
_device_class(CLASS_A)
{
Expand Down Expand Up @@ -1030,11 +1031,16 @@ int LoRaMac::get_backoff_timer_event_id(void)

lorawan_status_t LoRaMac::clear_tx_pipe(void)
{
if (!_can_cancel_tx) {
return LORAWAN_STATUS_BUSY;
}

// check if the event is not already queued
const int id = get_backoff_timer_event_id();

if (id == 0) {
// No queued send request
return LORAWAN_STATUS_OK;
return LORAWAN_STATUS_NO_OP;
}

if (_ev_queue->time_left(id) > 0) {
Expand Down Expand Up @@ -1092,6 +1098,7 @@ lorawan_status_t LoRaMac::schedule_tx()
case LORAWAN_STATUS_DUTYCYCLE_RESTRICTED:
if (backoff_time != 0) {
tr_debug("DC enforced: Transmitting in %lu ms", backoff_time);
_can_cancel_tx = true;
_lora_time.start(_params.timers.backoff_timer, backoff_time);
}
return LORAWAN_STATUS_OK;
Expand Down Expand Up @@ -1154,6 +1161,7 @@ lorawan_status_t LoRaMac::schedule_tx()
_params.is_srv_ack_requested = false;
}

_can_cancel_tx = false;
return send_frame_on_channel(_params.channel);
}

Expand Down Expand Up @@ -1238,6 +1246,7 @@ bool LoRaMac::tx_ongoing()

void LoRaMac::set_tx_ongoing(bool ongoing)
{
_can_cancel_tx = true;
_ongoing_tx_msg.tx_ongoing = ongoing;
}

Expand Down
2 changes: 2 additions & 0 deletions features/lorawan/lorastack/mac/LoRaMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ class LoRaMac {

bool _is_nwk_joined;

bool _can_cancel_tx;

bool _continuous_rx2_window_open;

device_class_t _device_class;
Expand Down
8 changes: 2 additions & 6 deletions features/lorawan/lorawan_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ typedef enum lorawan_status {
LORAWAN_STATUS_CRYPTO_FAIL = -1014, /**< Service not started - crypto failure */
LORAWAN_STATUS_PORT_INVALID = -1015, /**< Invalid port */
LORAWAN_STATUS_CONNECT_IN_PROGRESS = -1016, /**< Services started - Connection in progress */
LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */
LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017, /**< Services not started - No active session */
LORAWAN_STATUS_IDLE = -1018, /**< Services started - Idle at the moment */
#if defined(LORAWAN_COMPLIANCE_TEST)
//Deprecated - will replace the code -1019 with something
//else in future.
LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */
#endif
LORAWAN_STATUS_NO_OP = -1019, /**< Cannot perform requested operation */
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, /**< Transmission will continue after duty cycle backoff*/
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021, /**< None of the channels is enabled at the moment*/
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022, /**< None of the enabled channels is ready for another TX (duty cycle limited)*/
Expand Down