Bleeding edge development version of the xDot library for mbed 5. This version of the library is not guaranteed to be stable or well tested and should not be used in production or deployment scenarios.

Dependents:   Dot-Examples Dot-AT-Firmware Dot-Examples TEST_FF1705 ... more

The Dot library provides a LoRaWan certified stack for LoRa communication using MultiTech mDot and xDot devices. The stack is compatible with mbed 5.

Dot Library Version 3 Updates

Dot Library versions 3.x.x require a channel plan to be injected into the stack. Channel plans are included with the 3.x.x Dot Library releases. The following code snippet demonstrates how to create a channel plan and inject it into the stack.

#include "mDot.h"
#include "channel_plans.h"

int main() {
    ChannelPlan* plan = new lora::ChannelPlan_US915();
    assert(plan);
    mDot* dot = mDot::getInstance(plan);
    assert(dot);

    // ...
}

Dot devices must not be deployed with software using a different channel plan than the Dot's default plan! This functionality is for development and testing only!

Multicast Sessions

Multicast sessions and packet rx events in library. When in Class C mode Multicast downlinks can be received. Recieved packets should be filtered on address, counter value will be maintained in the session or can be set explicitly depending on Application support to share Multicast Address, Keys and Counters.

mDot.h

        /**
         * Add a multicast session address and keys
         * Downlink counter is set to 0
         * Up to 3 MULTICAST_SESSIONS can be set
         */
        int32_t setMulticastSession(uint8_t index, uint32_t addr, const uint8_t* nsk, const uint8_t* dsk);
 
        /**
         * Set a multicast session counter
         * Up to 3 MULTICAST_SESSIONS can be set
         */
        int32_t setMulticastDownlinkCounter(uint8_t index, uint32_t count);

mDotEvent.h

The address field was added to PacketRx event.

        virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address);

The name of the repository can be used to determine which device the stack was compiled for and if it's a development or production-ready build:

A changelog for the Dot library can be found here.

The Dot library version and the version of mbed-os it was compiled against can both be found in the commit message for that revision of the Dot library. Building your application with the same version of mbed-os as what was used to build the Dot library is highly recommended!

The Dot-Examples repository demonstrates how to use the Dot library in a custom application.

The mDot and xDot platform pages have lots of platform specific information and document potential issues, gotchas, etc, and provide instructions for getting started with development. Please take a look at the platform page before starting development as they should answer many questions you will have.

Files at this revision

API Documentation at this revision

Comitter:
Jenkins@KEILDM1.dc.multitech.prv
Date:
Mon Oct 08 10:41:45 2018 -0500
Parent:
127:db053d511848
Child:
129:7e4afccbee99
Commit message:
xdot-library revision 3.1.0-35-ge3d5c08 and mbed-os revision mbed-os-5.9.6

Changed in this revision

Lora.h Show annotated file Show diff for this revision Revisions of this file
MacEvents.h Show annotated file Show diff for this revision Revisions of this file
Mote.h Show annotated file Show diff for this revision Revisions of this file
libxDot-ARMCC.ar Show annotated file Show diff for this revision Revisions of this file
libxDot-GCC_ARM.a Show annotated file Show diff for this revision Revisions of this file
mDot.h Show annotated file Show diff for this revision Revisions of this file
mDotEvent.h Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_AS923.cpp Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_AS923.h Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_AU915.cpp Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_AU915.h Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_RU864.cpp Show annotated file Show diff for this revision Revisions of this file
plans/ChannelPlan_US915.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Lora.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/Lora.h	Mon Oct 08 10:41:45 2018 -0500
@@ -129,8 +129,8 @@
     const uint8_t PKT_JOIN_DL_SETTINGS = 11;                    //!< Index to downlink settings in Join Accept message
     const uint8_t PKT_JOIN_RX_DELAY = 12;                       //!< Index to rx delay in Join Accept message
 
-    const uint8_t ADR_ACK_LIMIT = 64;                           //!< Number of packets without ADR ACK Request
-    const uint8_t ADR_ACK_DELAY = 32;                           //!< Number of packets to expect ADR ACK Response within
+    const uint8_t DEFAULT_ADR_ACK_LIMIT = 64;                   //!< Number of packets without ADR ACK Request
+    const uint8_t DEFAULT_ADR_ACK_DELAY = 32;                   //!< Number of packets to expect ADR ACK Response within
 
     const uint16_t ACK_TIMEOUT = 2000;                          //!< Base millisecond timeout to resend after missed ACK
     const uint16_t ACK_TIMEOUT_RND = 1000;                      //!< Random millisecond adjustment to resend after missed ACK
@@ -346,6 +346,8 @@
             uint8_t AckAttempts;        //!< Number of attempts to send packet and receive an ACK from server
             uint8_t Retries;            //!< Number of times to resend a packet without receiving an ACK, redundancy
             uint8_t ADREnabled;         //!< Enable adaptive datarate
+            uint16_t AdrAckLimit;       //!< Number of uplinks without a downlink to allow before setting ADRACKReq
+            uint16_t AdrAckDelay;       //!< Number of downlinks to expect ADR ACK Response within
             uint8_t CADEnabled;         //!< Enable listen before talk/channel activity detection
             uint8_t RepeaterMode;       //!< Limit payloads to repeater compatible sizes
             uint8_t TxPower;            //!< Default radio output power in dBm
--- a/MacEvents.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/MacEvents.h	Mon Oct 08 10:41:45 2018 -0500
@@ -34,7 +34,7 @@
             virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries=0, uint32_t address=0, bool dupRx=false) = 0;
             virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) = 0;
 
-            virtual void BeaconRx(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) = 0;
+            virtual void BeaconRx(const BeaconData_t& beacon_data, int16_t rssi, int8_t snr) = 0;
             virtual void BeaconLost() = 0;
             virtual void ServerTime(uint32_t seconds, uint8_t sub_seconds) = 0;
 
--- a/Mote.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/Mote.h	Mon Oct 08 10:41:45 2018 -0500
@@ -95,12 +95,11 @@
 
             /**
              * Fired when a beacon is received
-             * @param payload received bytes
-             * @param size number of received bytes
+             * @param beacon_data parsed from the beacon payload
              * @param rssi of received beacon
              * @param snr of received beacon
              */
-            virtual void BeaconRx(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
+            virtual void BeaconRx(const BeaconData_t& beacon_data, int16_t rssi, int8_t snr);
 
             /**
              * Fired upon losing beacon synchronization (120 minutes elapsed from last beacon reception)
Binary file libxDot-ARMCC.ar has changed
Binary file libxDot-GCC_ARM.a has changed
--- a/mDot.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/mDot.h	Mon Oct 08 10:41:45 2018 -0500
@@ -1222,17 +1222,28 @@
         bool getAdr();
 
         /**
-         * Set forward error correction bytes
-         * @param bytes 1 - 4 bytes
-         * @returns MDOT_OK if success
+         * Set the ADR ACK Limit
+         * @param limit - ADR ACK limit
          */
-        int32_t setFec(const uint8_t& bytes);
+        void setAdrAckLimit(uint16_t limit);
 
         /**
-         * Get forward error correction bytes
-         * @returns bytes (1 - 4)
+         * Get the ADR ACK Limit
+         * @returns ADR ACK limit
          */
-        uint8_t getFec();
+        uint16_t getAdrAckLimit();
+
+        /**
+         * Set the ADR ACK Delay
+         * @param delay - ADR ACK delay
+         */
+        void setAdrAckDelay(uint16_t delay);
+
+        /**
+         * Get the ADR ACK Delay
+         * @returns ADR ACK delay
+         */
+        uint16_t getAdrAckDelay();
 
         /**
          * Enable/disable CRC checking of packets
@@ -1583,14 +1594,6 @@
         int32_t setRxFrequency(const uint32_t& freq);
         uint32_t getRxFrequency();
 
-        // get/set TX/RX inverted
-        // true == signal is inverted
-        // set function returns MDOT_OK if success
-        int32_t setTxInverted(const bool& on);
-        bool getTxInverted();
-        int32_t setRxInverted(const bool& on);
-        bool getRxInverted();
-
         // get/set RX output mode
         // valid options are HEXADECIMAL and BINARY
         // set function returns MDOT_OK if success
--- a/mDotEvent.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/mDotEvent.h	Mon Oct 08 10:41:45 2018 -0500
@@ -64,7 +64,6 @@
           RxPort(0),
           RxPayloadSize(0),
           BeaconLocked(false),
-          BeaconPayloadSize(0U),
           PongReceived(false),
           PongRssi(0),
           PongSnr(0),
@@ -220,12 +219,10 @@
             logDebug("mDotEvent - RxDone");
         }
 
-        virtual void BeaconRx(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
+        virtual void BeaconRx(const lora::BeaconData_t& beacon_data, int16_t rssi, int8_t snr) {
             logDebug("mDotEvent - BeaconRx");
             BeaconLocked = true;
-
-            memcpy(BeaconPayload, payload, size);
-            BeaconPayloadSize = size;
+            BeaconData = beacon_data;
         }
 
         virtual void BeaconLost() {
@@ -296,8 +293,7 @@
         uint8_t RxPayloadSize;
 
         bool BeaconLocked;
-        uint8_t BeaconPayload[25];
-        uint8_t BeaconPayloadSize;
+        lora::BeaconData_t BeaconData;
 
         bool PongReceived;
         int16_t PongRssi;
--- a/plans/ChannelPlan_AS923.cpp	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_AS923.cpp	Mon Oct 08 10:41:45 2018 -0500
@@ -26,7 +26,7 @@
 const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE_400[] = { 0, 0, 11, 53, 125, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0 };
 const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE_REPEATER_400[] = { 0, 0, 11, 53, 125, 222, 222, 222, 0, 0, 0, 0, 0, 0, 0, 0 };
 
-const uint8_t MAX_ERP_VALUES[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
+const uint8_t ChannelPlan_AS923::MAX_ERP_VALUES[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
 
 ChannelPlan_AS923::ChannelPlan_AS923()
 :
@@ -944,12 +944,8 @@
 
 
 uint8_t lora::ChannelPlan_AS923::GetJoinDatarate() {
-    uint8_t dr = GetSettings()->Session.TxDatarate;
-    
     // Default join datarate is DR2:SF10BW125
-    dr = lora::DR_2;
-    
-    return dr;
+    return lora::DR_2;
 }
 
 uint8_t ChannelPlan_AS923::CalculateJoinBackoff(uint8_t size) {
--- a/plans/ChannelPlan_AS923.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_AS923.h	Mon Oct 08 10:41:45 2018 -0500
@@ -253,12 +253,12 @@
         protected:
 
             static const uint8_t AS923_TX_POWERS[8];                    //!< List of available tx powers
-            static const uint8_t AS923_RADIO_POWERS[21];                 //!< List of calibrated tx powers
+            static const uint8_t AS923_RADIO_POWERS[21];                //!< List of calibrated tx powers
             static const uint8_t AS923_MAX_PAYLOAD_SIZE[];              //!< List of max payload sizes for each datarate
-            static const uint8_t AS923_MAX_PAYLOAD_SIZE_400[];              //!< List of max payload sizes for each datarate
+            static const uint8_t AS923_MAX_PAYLOAD_SIZE_400[];          //!< List of max payload sizes for each datarate
             static const uint8_t AS923_MAX_PAYLOAD_SIZE_REPEATER[];     //!< List of repeater compatible max payload sizes for each datarate
-            static const uint8_t AS923_MAX_PAYLOAD_SIZE_REPEATER_400[];     //!< List of repeater compatible max payload sizes for each datarate
-
+            static const uint8_t AS923_MAX_PAYLOAD_SIZE_REPEATER_400[]; //!< List of repeater compatible max payload sizes for each datarate
+            static const uint8_t MAX_ERP_VALUES[];                      //!< Lookup table for Max EIRP (dBm) codes
             typedef struct __attribute__((packed)) {
                 uint8_t RFU[2];
                 uint8_t Time[4];
--- a/plans/ChannelPlan_AU915.cpp	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_AU915.cpp	Mon Oct 08 10:41:45 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;
--- a/plans/ChannelPlan_AU915.h	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_AU915.h	Mon Oct 08 10:41:45 2018 -0500
@@ -271,6 +271,19 @@
              */
             virtual void EnableDefaultChannels();
 
+            /**
+             * Called when MAC layer doesn't know about a command.
+             * Use to add custom or new mac command handling
+             * @return LORA_OK
+             */
+            virtual uint8_t HandleMacCommand(uint8_t* payload, uint8_t& index);
+
+            /**
+             * Get max payload size for current datarate
+             * @return size in bytes
+             */
+            virtual uint8_t GetMaxPayloadSize();
+
             virtual uint8_t GetMinDatarate();
 
             virtual uint8_t GetMaxDatarate();
@@ -299,7 +312,10 @@
             static const uint8_t AU915_TX_POWERS[11];                   //!< List of available tx powers
             static const uint8_t AU915_RADIO_POWERS[21];                //!< List of calibrated tx powers
             static const uint8_t AU915_MAX_PAYLOAD_SIZE[];              //!< List of max payload sizes for each datarate
+            static const uint8_t AU915_MAX_PAYLOAD_SIZE_400[];          //!< List of max payload sizes for each datarate
             static const uint8_t AU915_MAX_PAYLOAD_SIZE_REPEATER[];     //!< List of repeater compatible max payload sizes for each datarate
+            static const uint8_t AU915_MAX_PAYLOAD_SIZE_REPEATER_400[]; //!< List of repeater compatible max payload sizes for each datarate
+            static const uint8_t MAX_ERP_VALUES[];                      //!< Lookup table for Max EIRP (dBm) codes
 
             typedef struct __attribute__((packed)) {
                 uint8_t RFU1[3];
--- a/plans/ChannelPlan_RU864.cpp	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_RU864.cpp	Mon Oct 08 10:41:45 2018 -0500
@@ -208,7 +208,7 @@
 
     if (size == 33) {
         Channel ch;
-        int index = 3;
+        int index = 2;
         for (int i = 13; i < size - 5; i += 3) {
 
             ch.Frequency = ((buffer[i]) | (buffer[i + 1] << 8) | (buffer[i + 2] << 16)) * 100u;
--- a/plans/ChannelPlan_US915.cpp	Tue Sep 18 08:25:41 2018 -0500
+++ b/plans/ChannelPlan_US915.cpp	Mon Oct 08 10:41:45 2018 -0500
@@ -646,6 +646,8 @@
         status &= 0xFB; // TxPower KO
     }
 
+    uint16_t t_125k = 0; //used only in ctrl case 5
+
     switch (ctrl) {
         case 0:
         case 1:
@@ -655,6 +657,25 @@
             SetChannelMask(ctrl, mask);
             break;
 
+        case 5:
+            if(mask != 0) {
+                for(int i = 0; i < 8; i++) {  //0 - 7 bits
+                    if(((mask >> i) & 1) == 1) { //if bit in mask is a one
+                        t_125k |= (0xff << ((i % 2) * 8)); // this does either 0xff00 or 0x00ff to t_125k 
+                    }
+                    if(i % 2 == 1) { // if 1 then both halfs of the mask were set
+                        SetChannelMask(i/2, t_125k); 
+                        t_125k = 0; //reset mask for next two bits
+                    }
+                }
+                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);
@@ -916,45 +937,24 @@
 
 uint8_t lora::ChannelPlan_US915::GetJoinDatarate() {
     uint8_t dr = GetSettings()->Session.TxDatarate;
-
+    static int fsb = 1; 
     if (GetSettings()->Test.DisableRandomJoinDatarate == lora::OFF) {
-        static bool altDatarate = false;
 
         if (GetSettings()->Network.FrequencySubBand == 0) {
-            static uint16_t used_bands_125k = 0;
-            static uint16_t used_bands_500k = 0;
-            uint8_t frequency_sub_band = 0;
 
-            if (altDatarate) {
-                // 500k channel
-                if (CountBits(used_bands_500k) == 8) {
-                    used_bands_500k = 0;
-                }
-                while ((frequency_sub_band = rand_r(1, 8)) && (used_bands_500k & (1 << (frequency_sub_band - 1))) != 0)
-                    ;
-                used_bands_500k |= (1 << (frequency_sub_band - 1));
+            if (fsb < 9) {
+                SetFrequencySubBand(fsb);
+                logDebug("JoinDatarate setting frequency sub band to %d",fsb);
+                fsb++;
+                dr = lora::DR_0;
             } else {
-                // 125k channel
-                if (CountBits(used_bands_125k) == 8) {
-                    used_bands_125k = 0;
-                }
-                while ((frequency_sub_band = rand_r(1, 8)) && (used_bands_125k & (1 << (frequency_sub_band - 1))) != 0)
-                    ;
-                used_bands_125k |= (1 << (frequency_sub_band - 1));
+                dr = lora::DR_4;
+                fsb = 1;
             }
-
-            logWarning("JoinDatarate setting frequency sub band to %d 125k: %04x 500k: %04x", frequency_sub_band, used_bands_125k, used_bands_500k);
-            SetFrequencySubBand(frequency_sub_band);
-        }
-
-        if (altDatarate && CountBits(_channelMask[4] > 0)) {
-            dr = lora::DR_4;
         } else {
             dr = lora::DR_0;
         }
-        altDatarate = !altDatarate;
     }
-
     return dr;
 }