Skip to content

Commit 375e1b7

Browse files
author
Hasnain Virk
committed
Adding useful trace and setting no. of retries
MCPS confirmation should be filled with the current number of retries if the ack is not recieved for a CONFIRMED message. Ack retry number needs to be incremented after the retry is made not before that. A few traces are added at the crucial junctions of the code just to tally with the conceptual flow for debug purposes.
1 parent 26b28f7 commit 375e1b7

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ void LoRaWANStack::process_transmission(void)
553553
if (_loramac.get_mcps_confirmation()->req_type == MCPS_CONFIRMED) {
554554
_ctrl_flags |= TX_ONGOING_FLAG;
555555
_ctrl_flags &= ~TX_DONE_FLAG;
556+
tr_debug("Awaiting ACK");
556557
_device_current_state = DEVICE_STATE_AWAITING_ACK;
557558
return;
558559
}

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ void LoRaMac::post_process_mcps_req()
170170
_params.ul_frame_counter++;
171171
}
172172
}
173-
174173
} else {
175174
//UNCONFIRMED or PROPRIETARY
176175
if (_params.is_ul_frame_counter_fixed == false) {
@@ -548,6 +547,10 @@ void LoRaMac::handle_data_frame(const uint8_t* const payload,
548547
return;
549548
}
550549

550+
// message is intended for us and MIC have passed, stop RX2 Window
551+
// Spec: 3.3.4 Receiver Activity during the receive windows
552+
_lora_time.stop(_params.timers.rx_window2_timer);
553+
551554
_mcps_confirmation.ack_received = false;
552555
_mcps_indication.is_ack_recvd = false;
553556
_mcps_indication.pending = true;
@@ -662,7 +665,6 @@ void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
662665
{
663666
// on reception turn off queued timers
664667
_lora_time.stop(_params.timers.rx_window1_timer);
665-
_lora_time.stop(_params.timers.rx_window2_timer);
666668

667669
if (_device_class == CLASS_C) {
668670
open_rx2_window();
@@ -847,6 +849,7 @@ void LoRaMac::on_backoff_timer_expiry(void)
847849
void LoRaMac::open_rx1_window(void)
848850
{
849851
Lock lock(*this);
852+
tr_debug("Opening RX1 Window");
850853
_lora_time.stop(_params.timers.rx_window1_timer);
851854
_params.rx_slot = RX_SLOT_WIN_1;
852855

@@ -871,6 +874,7 @@ void LoRaMac::open_rx1_window(void)
871874
void LoRaMac::open_rx2_window()
872875
{
873876
Lock lock(*this);
877+
tr_debug("Opening RX2 Window");
874878
_lora_time.stop(_params.timers.rx_window2_timer);
875879

876880
_params.rx_window2_config.channel = _params.channel;
@@ -925,14 +929,17 @@ void LoRaMac::check_to_disable_ack_timeout(bool node_ack_requested,
925929
void LoRaMac::on_ack_timeout_timer_event(void)
926930
{
927931
Lock lock(*this);
928-
_params.ack_timeout_retry_counter++;
932+
tr_debug("ACK_TIMEOUT Elapses, Retrying ...");
933+
_lora_time.stop(_params.timers.ack_timeout_timer);
929934

930935
// reduce data rate
931936
if ((_params.ack_timeout_retry_counter % 2)) {
932937
_params.sys_params.channel_data_rate = _lora_phy.get_next_lower_tx_datarate(
933938
_params.sys_params.channel_data_rate);
934939
}
935940

941+
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
942+
936943
// Schedule a retry
937944
if (handle_retransmission() != LORAWAN_STATUS_OK) {
938945
// In a case when enabled channels are not found, PHY layer
@@ -943,12 +950,13 @@ void LoRaMac::on_ack_timeout_timer_event(void)
943950
_mac_commands.clear_command_buffer();
944951
_params.is_node_ack_requested = false;
945952
_mcps_confirmation.ack_received = false;
946-
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
947953

948954
// now that is a critical failure
949955
lorawan_status_t status = handle_retransmission();
950956
MBED_ASSERT(status==LORAWAN_STATUS_OK);
951957
}
958+
959+
_params.ack_timeout_retry_counter++;
952960
}
953961

954962
bool LoRaMac::validate_payload_length(uint16_t length,
@@ -1062,15 +1070,15 @@ lorawan_status_t LoRaMac::schedule_tx()
10621070
return status;
10631071
case LORAWAN_STATUS_DUTYCYCLE_RESTRICTED:
10641072
if (backoff_time != 0) {
1065-
tr_debug("Next Transmission in %lu ms", backoff_time);
1073+
tr_debug("DC enforced: Transmitting in %lu ms", backoff_time);
10661074
_lora_time.start(_params.timers.backoff_timer, backoff_time);
10671075
}
10681076
return LORAWAN_STATUS_OK;
10691077
default:
10701078
break;
10711079
}
10721080

1073-
tr_debug("Next Channel Idx=%d, DR=%d", _params.channel, next_channel.current_datarate);
1081+
tr_debug("TX: Channel=%d, DR=%d", _params.channel, next_channel.current_datarate);
10741082

10751083
uint8_t dr_offset = _lora_phy.apply_DR_offset(_params.sys_params.channel_data_rate,
10761084
_params.sys_params.rx1_dr_offset);
@@ -1271,9 +1279,7 @@ lorawan_status_t LoRaMac::send_ongoing_tx()
12711279
_params.is_last_tx_join_request = false;
12721280
int8_t datarate = _params.sys_params.channel_data_rate;
12731281

1274-
// TODO: The comment is different than the code???
1275-
// Apply the minimum possible datarate.
1276-
// Some regions have limitations for the minimum datarate.
1282+
// This prohibits the data rate going below the minimum value.
12771283
datarate = MAX(datarate, (int8_t)_lora_phy.get_minimum_tx_datarate());
12781284

12791285
loramac_mhdr_t machdr;

features/lorawan/system/lorawan_data_structures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ typedef struct {
13051305

13061306
} loramac_protocol_params;
13071307

1308+
13081309
#if defined(LORAWAN_COMPLIANCE_TEST)
13091310

13101311
typedef struct {

0 commit comments

Comments
 (0)