@@ -257,6 +257,21 @@ lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
257
257
return LORAWAN_STATUS_OK;
258
258
}
259
259
260
+ lorawan_status_t LoRaWANStack::stop_sending (void )
261
+ {
262
+ if (_loramac.clear_tx_pipe () == LORAWAN_STATUS_OK) {
263
+ if (_device_current_state == DEVICE_STATE_SENDING) {
264
+ _ctrl_flags &= ~TX_DONE_FLAG;
265
+ _ctrl_flags &= ~TX_ONGOING_FLAG;
266
+ _loramac.set_tx_ongoing (false );
267
+ _device_current_state = DEVICE_STATE_IDLE;
268
+ return LORAWAN_STATUS_OK;
269
+ }
270
+ }
271
+
272
+ return LORAWAN_STATUS_BUSY;
273
+ }
274
+
260
275
int16_t LoRaWANStack::handle_tx (const uint8_t port, const uint8_t * data,
261
276
uint16_t length, uint8_t flags,
262
277
bool null_allowed, bool allow_port_0)
@@ -517,8 +532,8 @@ void LoRaWANStack::process_transmission_timeout()
517
532
// this is a fatal error and should not happen
518
533
tr_debug (" TX Timeout" );
519
534
_loramac.on_radio_tx_timeout ();
520
- _ctrl_flags &= ~ TX_ONGOING_FLAG;
521
- _ctrl_flags |= TX_DONE_FLAG;
535
+ _ctrl_flags |= TX_ONGOING_FLAG;
536
+ _ctrl_flags &= ~ TX_DONE_FLAG;
522
537
state_controller (DEVICE_STATE_STATUS_CHECK);
523
538
state_machine_run_to_completion ();
524
539
}
@@ -576,12 +591,21 @@ void LoRaWANStack::process_reception(const uint8_t* const payload, uint16_t size
576
591
if (_loramac.get_mcps_confirmation ()->req_type == MCPS_CONFIRMED) {
577
592
// if ack was not received, we will try retransmission after
578
593
// ACK_TIMEOUT. handle_data_frame() already disables ACK_TIMEOUT timer
579
- // if ack was received
594
+ // if ack was received. Otherwise, following method will be called in
595
+ // LoRaMac.cpp, on_ack_timeout_timer_event().
580
596
if (_loramac.get_mcps_indication ()->is_ack_recvd ) {
581
597
tr_debug (" Ack=OK, NbTrials=%d" , _loramac.get_mcps_confirmation ()->nb_retries );
582
598
_loramac.post_process_mcps_req ();
583
599
_ctrl_flags |= TX_DONE_FLAG;
600
+ _ctrl_flags &= ~TX_ONGOING_FLAG;
584
601
state_controller (DEVICE_STATE_STATUS_CHECK);
602
+ } else {
603
+ if (!_loramac.continue_sending_process ()) {
604
+ tr_error (" Retries exhausted for Class A device" );
605
+ _ctrl_flags &= ~TX_DONE_FLAG;
606
+ _ctrl_flags |= TX_ONGOING_FLAG;
607
+ state_controller (DEVICE_STATE_STATUS_CHECK);
608
+ }
585
609
}
586
610
} else {
587
611
// handle UNCONFIRMED, PROPRIETARY case here, RX slots were turned off due to
@@ -636,13 +660,19 @@ void LoRaWANStack::process_reception_timeout(bool is_timeout)
636
660
* of UNCONFIRMED message after RX windows are done with.
637
661
* For a CONFIRMED message, it means that we have not received
638
662
* ack (actually nothing was received), and we should retransmit if we can.
663
+ *
664
+ * NOTE: This code block doesn't get hit for Class C as in Class C, RX2 timeout
665
+ * never occurs.
639
666
*/
640
667
if (slot == RX_SLOT_WIN_2) {
641
668
_loramac.post_process_mcps_req ();
642
669
643
- if (_loramac.get_mcps_confirmation ()->req_type == MCPS_CONFIRMED
644
- && _loramac.continue_sending_process ()) {
645
- return ;
670
+ if (_loramac.get_mcps_confirmation ()->req_type == MCPS_CONFIRMED) {
671
+ if (_loramac.continue_sending_process ()) {
672
+ return ;
673
+ } else {
674
+ tr_error (" Retries exhausted for Class A device" );
675
+ }
646
676
}
647
677
648
678
state_controller (DEVICE_STATE_STATUS_CHECK);
@@ -666,7 +696,6 @@ void LoRaWANStack::make_tx_metadata_available(void)
666
696
void LoRaWANStack::make_rx_metadata_available (void )
667
697
{
668
698
_rx_metadata.stale = false ;
669
- _rx_metadata.fpending_status = _loramac.get_mcps_indication ()->fpending_status ;
670
699
_rx_metadata.rx_datarate = _loramac.get_mcps_indication ()->rx_datarate ;
671
700
_rx_metadata.rssi = _loramac.get_mcps_indication ()->rssi ;
672
701
_rx_metadata.snr = _loramac.get_mcps_indication ()->snr ;
@@ -972,7 +1001,7 @@ void LoRaWANStack::process_status_check_state()
972
1001
// we may or may not have a successful UNCONFIRMED transmission
973
1002
// here. In CONFIRMED case this block is invoked only
974
1003
// when the MAX number of retries are exhausted, i.e., only error
975
- // case will fall here.
1004
+ // case will fall here. Moreover, it will happen for Class A only.
976
1005
_ctrl_flags &= ~TX_DONE_FLAG;
977
1006
_ctrl_flags &= ~TX_ONGOING_FLAG;
978
1007
_loramac.set_tx_ongoing (false );
@@ -981,8 +1010,11 @@ void LoRaWANStack::process_status_check_state()
981
1010
982
1011
} else if (_device_current_state == DEVICE_STATE_RECEIVING) {
983
1012
984
- if (_ctrl_flags & TX_DONE_FLAG) {
1013
+ if (( _ctrl_flags & TX_DONE_FLAG) || (_ctrl_flags & TX_ONGOING_FLAG) ) {
985
1014
// for CONFIRMED case, ack validity is already checked
1015
+ // If it was a successful transmission, TX_ONGOING_FLAG will not be set.
1016
+ // If it was indeed set, that means the device was in Class C mode and
1017
+ // CONFIRMED transmission was in place and the ack retries maxed out.
986
1018
_ctrl_flags &= ~TX_DONE_FLAG;
987
1019
_ctrl_flags &= ~TX_ONGOING_FLAG;
988
1020
_loramac.set_tx_ongoing (false );
0 commit comments