ver1

Revision:
182:b642f4d0c95b
Parent:
179:578d8030ba57
diff -r 220e42003ef7 -r b642f4d0c95b plans/ChannelPlan_AU915.cpp
--- a/plans/ChannelPlan_AU915.cpp	Tue Sep 18 12:29:45 2018 -0500
+++ b/plans/ChannelPlan_AU915.cpp	Fri Oct 12 10:33:08 2018 -0500
@@ -24,6 +24,10 @@
 const uint8_t ChannelPlan_AU915::AU915_RADIO_POWERS[] = { 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 19, 19 };
 const uint8_t ChannelPlan_AU915::AU915_MAX_PAYLOAD_SIZE[] = { 51, 51, 51, 115, 242, 242, 242, 0, 53, 129, 242, 242, 242, 242, 0, 0 };
 const uint8_t ChannelPlan_AU915::AU915_MAX_PAYLOAD_SIZE_REPEATER[] = { 51, 51, 51, 115, 222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 };
+const uint8_t ChannelPlan_AU915::AU915_MAX_PAYLOAD_SIZE_400[] = { 0, 0, 11, 53, 125, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+const uint8_t ChannelPlan_AU915::AU915_MAX_PAYLOAD_SIZE_REPEATER_400[] = { 0, 0, 11, 53, 125, 222, 222, 222, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+const uint8_t ChannelPlan_AU915::MAX_ERP_VALUES[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
 
 ChannelPlan_AU915::ChannelPlan_AU915()
 :
@@ -412,6 +416,20 @@
     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);
 }
 
+uint8_t ChannelPlan_AU915::GetMaxPayloadSize() {
+    if (GetSettings()->Session.UplinkDwelltime == 1) {
+        if (GetSettings()->Network.RepeaterMode)
+            return AU915_MAX_PAYLOAD_SIZE_REPEATER_400[GetSettings()->Session.TxDatarate];
+        else
+            return AU915_MAX_PAYLOAD_SIZE_400[GetSettings()->Session.TxDatarate];
+    } else {
+        if (GetSettings()->Network.RepeaterMode)
+            return MAX_PAYLOAD_SIZE_REPEATER[GetSettings()->Session.TxDatarate];
+        else
+            return MAX_PAYLOAD_SIZE[GetSettings()->Session.TxDatarate];
+    }
+}
+
 RxWindow ChannelPlan_AU915::GetRxWindow(uint8_t window) {
     RxWindow rxw;
     int index = 0;
@@ -637,6 +655,8 @@
         status &= 0xFB; // TxPower KO
     }
 
+    uint16_t t_125k = 0; //used only in ctrl case 5
+
     switch (ctrl) {
         case 0:
         case 1:
@@ -646,6 +666,25 @@
             SetChannelMask(ctrl, mask);
             break;
 
+        case 5:
+            if(mask != 0) { //see US915 for same code with comments
+                for(int i = 0; i < 8; i++) {
+                    if(((mask >> i) & 1) == 1) {
+                        t_125k |= (0xff << ((i % 2) * 8));
+                    }
+                    if(i % 2 == 1) {
+                        SetChannelMask(i/2, t_125k);
+                        t_125k = 0;
+                    }
+                }
+                SetChannelMask(4, mask);
+            } else {
+                status &= 0xFE; // ChannelMask KO
+                logWarning("Rejecting mask, will not disable all channels");
+                return LORA_ERROR;
+            }
+            break;
+
         case 6:
             // enable all 125 kHz channels
             SetChannelMask(0, 0xFFFF);
@@ -941,7 +980,7 @@
         if (altDatarate && CountBits(_channelMask[4] > 0)) {
             dr = lora::DR_6;
         } else {
-            dr = lora::DR_0;
+            dr = lora::DR_2;
         }
         altDatarate = !altDatarate;
     }
@@ -1039,6 +1078,44 @@
     return LORA_OK;
 }
 
+uint8_t ChannelPlan_AU915::HandleMacCommand(uint8_t* payload, uint8_t& index) {
+    logDebug("AU915 Handle Mac index: %d", index);
+
+    switch (payload[index++]) {
+        case SRV_MAC_TX_PARAM_SETUP_REQ: {
+            uint8_t eirp_dwell = payload[index++];
+
+            GetSettings()->Session.DownlinkDwelltime = eirp_dwell >> 5 & 0x01;
+            GetSettings()->Session.UplinkDwelltime = eirp_dwell >> 4 & 0x01;
+            //change data rate with if dwell time changes
+            if(GetSettings()->Session.UplinkDwelltime == 0) {
+                _minDatarate = lora::DR_0;
+            } else {
+                _minDatarate = lora::DR_2;
+                if(GetSettings()->Session.TxDatarate < lora::DR_2) {
+                    GetSettings()->Session.TxDatarate = lora::DR_2;
+                    logDebug("Datarate is now DR%d",GetSettings()->Session.TxDatarate);
+                }
+            }
+
+            GetSettings()->Session.Max_EIRP = MAX_ERP_VALUES[(eirp_dwell & 0x0F)];
+            logDebug("buffer index %d", GetSettings()->Session.CommandBufferIndex);
+            if (GetSettings()->Session.CommandBufferIndex < COMMANDS_BUFFER_SIZE) {
+                logDebug("Add tx param setup mac cmd to buffer");
+                GetSettings()->Session.CommandBuffer[GetSettings()->Session.CommandBufferIndex++] = MOTE_MAC_TX_PARAM_SETUP_ANS;
+            }
+
+            logDebug("TX PARAM DWELL UL: %d DL: %d Max EIRP: %d", GetSettings()->Session.UplinkDwelltime, GetSettings()->Session.DownlinkDwelltime, GetSettings()->Session.Max_EIRP);
+            break;
+        }
+        default: {
+            return LORA_ERROR;
+        }
+    }
+
+    return LORA_OK;
+}
+
 bool ChannelPlan_AU915::DecodeBeacon(const uint8_t* payload, size_t size, BeaconData_t& data) {
     uint16_t crc1, crc1_rx, crc2, crc2_rx;
     const BCNPayload* beacon = (const BCNPayload*)payload;