@@ -322,7 +322,7 @@ void SlimLoRa::printMAC(){
322
322
Serial.print (F (" Rx1 DR offset\t : " ));Serial.println (GetRx1DataRateOffset ());
323
323
Serial.print (F (" Rx2 DR RAM\t : " ));Serial.println (rx2_data_rate_);
324
324
Serial.print (F (" Rx2 DR EEPROM\t : " ));Serial.println (GetRx2DataRate ());
325
- Serial.print (F (" ADR_ACK_cnt\t : " ));Serial.println (adr_ack_counter_ );
325
+ Serial.print (F (" ADR_ACK_cnt\t : " ));Serial.println (adr_ack_limit_counter_ );
326
326
}
327
327
#endif // DEBUG_SLIM
328
328
@@ -758,7 +758,10 @@ void SlimLoRa::RfmSendPacket(uint8_t *packet, uint8_t packet_length, uint8_t cha
758
758
// semi TODO fCnt don't increase if we havee UNCONFIRMED_DATA_UP and NbTrans to do.
759
759
if ( NbTrans_counter == 0 ) {
760
760
tx_frame_counter_++;
761
- adr_ack_counter_++;
761
+ adr_ack_limit_counter_++;
762
+ if ( adr_ack_limit_counter_ >= LORAWAN_ADR_ACK_LIMIT ) {
763
+ adr_ack_delay_counter_++;
764
+ }
762
765
NbTrans_counter = NbTrans;
763
766
}
764
767
@@ -1274,7 +1277,9 @@ int8_t SlimLoRa::ProcessJoinAccept(uint8_t window) {
1274
1277
rx_frame_counter_ = 0 ;
1275
1278
SetRxFrameCounter ();
1276
1279
1277
- adr_ack_counter_ = 0 ;
1280
+ // reset counters. EVAL: I use this twice. Maybe better a function?
1281
+ adr_ack_limit_counter_ = 0 ;
1282
+ adr_ack_delay_counter_ = 0 ;
1278
1283
NbTrans_counter = NbTrans;
1279
1284
1280
1285
has_joined_ = true ;
@@ -1379,7 +1384,11 @@ void SlimLoRa::ProcessFrameOptions(uint8_t *options, uint8_t f_options_length) {
1379
1384
new_rx2_dr = options[i + 1 ] >> 4 ;
1380
1385
tx_power = options[i + 1 ] & 0xF ;
1381
1386
1387
+ #if defined(EU_DR6)
1382
1388
if (new_rx2_dr == 0xF || (new_rx2_dr >= SF12BW125 && new_rx2_dr <= SF7BW250)) { // Reversed table index
1389
+ #else
1390
+ if (new_rx2_dr == 0xF || (new_rx2_dr >= SF12BW125 && new_rx2_dr <= SF7BW125)) { // Reversed table index
1391
+ #endif
1383
1392
status |= 0x2 ; // DR ACK
1384
1393
}
1385
1394
// tx_power = 15 or less than 7
@@ -1433,7 +1442,11 @@ void SlimLoRa::ProcessFrameOptions(uint8_t *options, uint8_t f_options_length) {
1433
1442
if (new_rx1_dr_offset <= LORAWAN_EU868_RX1_DR_OFFSET_MAX) {
1434
1443
status |= 0x4 ;
1435
1444
}
1445
+ #if defined(EU_DR6)
1436
1446
if (new_rx2_dr >= SF12BW125 && new_rx2_dr <= SF7BW250) { // Reversed table index
1447
+ #else
1448
+ if (new_rx2_dr >= SF12BW125 && new_rx2_dr <= SF7BW125) { // Reversed table index
1449
+ #endif
1437
1450
status |= 0x2 ;
1438
1451
}
1439
1452
@@ -1597,8 +1610,13 @@ int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
1597
1610
1598
1611
if (window == 1 ) {
1599
1612
rx1_offset_dr = data_rate_ + rx1_data_rate_offset_; // Reversed table index
1613
+ #if defined(EU_DR6)
1600
1614
if (rx1_offset_dr > SF7BW250) {
1601
1615
rx1_offset_dr = SF7BW250;
1616
+ #else
1617
+ if (rx1_offset_dr > SF7BW125) {
1618
+ rx1_offset_dr = SF7BW125;
1619
+ #endif
1602
1620
}
1603
1621
rx_delay = CalculateRxDelay (rx1_offset_dr, rx1_delay_micros_);
1604
1622
packet_length = RfmReceivePacket (packet, sizeof (packet), channel_, rx1_offset_dr, tx_done_micros_ + rx_delay);
@@ -1670,7 +1688,8 @@ int8_t SlimLoRa::ProcessDownlink(uint8_t window) {
1670
1688
1671
1689
// We received downlink. Reset some values.
1672
1690
// Reset ADR acknowledge counter
1673
- adr_ack_counter_ = 0 ;
1691
+ adr_ack_limit_counter_ = 0 ;
1692
+ adr_ack_delay_counter_ = 0 ;
1674
1693
// Reset NbTrans
1675
1694
NbTrans_counter = NbTrans;
1676
1695
@@ -1837,14 +1856,29 @@ void SlimLoRa::Transmit(uint8_t fport, uint8_t *payload, uint8_t payload_length)
1837
1856
EncryptPayload (payload, payload_length, tx_frame_counter_, LORAWAN_DIRECTION_UP);
1838
1857
1839
1858
// ADR back-off
1840
- if (adr_enabled_ && adr_ack_counter_ >= LORAWAN_ADR_ACK_LIMIT + LORAWAN_ADR_ACK_DELAY) {
1859
+ // TODO p. 17, after first increase if DR, increase every LORAWAN_ADR_ACK_DELAY overflow
1860
+ if (adr_enabled_ && adr_ack_limit_counter_ >= LORAWAN_ADR_ACK_LIMIT && adr_ack_delay_counter_ == 0 ) {
1861
+ adr_ack_delay_counter_++; // this way, this if statement will be executed only once
1862
+ if ( data_rate_ > SF12BW125 ) {
1863
+ data_rate_--;
1864
+ }
1865
+ // EVAL: I think the order is important for the HOPE
1866
+ SetPower (16 );
1867
+ #if DEBUG_SLIM >= 1
1868
+ Serial.print (F (" \n ADR backoff 1st stage, DR: " ));Serial.print (data_rate_);
1869
+ #endif
1870
+ }
1871
+
1872
+ // Increase DR every overflow of LORAWAN_ADR_ACK_DELAY
1873
+ if (adr_enabled_ && adr_ack_delay_counter_ >= LORAWAN_ADR_ACK_DELAY ) {
1874
+ adr_ack_delay_counter_ = 0 ; // reset overflow
1841
1875
if ( data_rate_ > SF12BW125 ) {
1842
- data_rate_++ ;
1876
+ data_rate_-- ;
1843
1877
}
1844
1878
// EVAL: I think the order is important for the HOPE
1845
1879
SetPower (16 );
1846
1880
#if DEBUG_SLIM >= 1
1847
- Serial.print (F (" \n ADR backoff, DR: " ));Serial.print (data_rate_);
1881
+ Serial.print (F (" \n ADR backoff 2nd stage , DR: " ));Serial.print (data_rate_);
1848
1882
#endif
1849
1883
}
1850
1884
@@ -1870,9 +1904,9 @@ void SlimLoRa::Transmit(uint8_t fport, uint8_t *payload, uint8_t payload_length)
1870
1904
if (adr_enabled_) {
1871
1905
packet[packet_length] |= LORAWAN_FCTRL_ADR;
1872
1906
1873
- // Request ADR if adr_ack_counter_ is over the limit of LORAWAN_ADR_ACK_LIMIT
1907
+ // Request ADR if adr_ack_limit_counter_ is over the limit of LORAWAN_ADR_ACK_LIMIT
1874
1908
// p. 17
1875
- if (adr_ack_counter_ >= LORAWAN_ADR_ACK_LIMIT ) {
1909
+ if (adr_ack_limit_counter_ >= LORAWAN_ADR_ACK_LIMIT ) {
1876
1910
packet[packet_length] |= LORAWAN_FCTRL_ADR_ACK_REQ;
1877
1911
}
1878
1912
}
0 commit comments