ver1

Revision:
151:2242ecfd733a
Parent:
139:b2e9d643eef9
Child:
155:ecb07dbd16e3
diff -r 7f5203f0d4d5 -r 2242ecfd733a plans/ChannelPlan_KR920.cpp
--- a/plans/ChannelPlan_KR920.cpp	Fri May 04 15:33:24 2018 -0500
+++ b/plans/ChannelPlan_KR920.cpp	Fri May 04 15:44:58 2018 -0500
@@ -266,7 +266,11 @@
 uint8_t ChannelPlan_KR920::SetRxConfig(uint8_t window, bool continuous) {
 
     RxWindow rxw = GetRxWindow(window);
-    GetRadio()->SetChannel(rxw.Frequency);
+
+    if (_dlChannels[_txChannel].Frequency != 0)
+        GetRadio()->SetChannel(_dlChannels[_txChannel].Frequency);
+    else
+        GetRadio()->SetChannel(rxw.Frequency);
 
     Datarate rxDr = GetDatarate(rxw.DatarateIndex);
     uint32_t bw = rxDr.Bandwidth;
@@ -332,8 +336,12 @@
     uint16_t sto = rxDr.SymbolTimeout();
     bool crc = false; // downlink does not use CRC according to LORAWAN
     bool iq = GetTxDatarate().RxIQ;
+    uint32_t freq = rxw.Frequency;
 
-    logTrace("RX%d on freq: %lu", wnd, rxw.Frequency);
+    if (wnd == 1 && _dlChannels[_txChannel].Frequency != 0)
+        freq = _dlChannels[_txChannel].Frequency;
+
+    logTrace("RX%d on freq: %lu", wnd, freq);
     logTrace("RX DR: %u SF: %u BW: %u CR: %u PL: %u STO: %u CRC: %d IQ: %d", rxDr.Index, sf, bw, cr, pl, sto, crc, iq);
 }
 
@@ -425,18 +433,22 @@
         status &= 0xFE; // Channel index KO
     }
 
-    if (!GetRadio()->CheckRfFrequency(chParam.Frequency)) {
+    if (chParam.Frequency == 0) {
+        chParam.DrRange.Value = 0;
+    } else if (chParam.Frequency < _minFrequency || chParam.Frequency > _maxFrequency) {
         logError("New Channel frequency KO");
         status &= 0xFE; // Channel frequency KO
     }
 
-    if (chParam.DrRange.Fields.Min > chParam.DrRange.Fields.Max) {
+    if (chParam.DrRange.Fields.Min > chParam.DrRange.Fields.Max && chParam.Frequency != 0) {
         logError("New Channel datarate min/max KO");
         status &= 0xFD; // Datarate range KO
-    } else if (chParam.DrRange.Fields.Min < _minDatarate || chParam.DrRange.Fields.Min > _maxDatarate) {
+    } else if ((chParam.DrRange.Fields.Min < _minDatarate || chParam.DrRange.Fields.Min > _maxDatarate) &&
+               chParam.Frequency != 0) {
         logError("New Channel datarate min KO");
         status &= 0xFD; // Datarate range KO
-    } else if (chParam.DrRange.Fields.Max < _minDatarate || chParam.DrRange.Fields.Max > _maxDatarate) {
+    } else if ((chParam.DrRange.Fields.Max < _minDatarate || chParam.DrRange.Fields.Max > _maxDatarate) &&
+               chParam.Frequency != 0) {
         logError("New Channel datarate max KO");
         status &= 0xFD; // Datarate range KO
     }
@@ -533,7 +545,7 @@
     //
     // Remark MaxTxPower = 0 and MinTxPower = 7
     //
-    if (power < 0 || power > 7) {
+    if (power > 7) {
         status &= 0xFB; // TxPower KO
     }