Bleeding edge development version of the mDot 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:   mDot-IKS01A1 mDot-IKS01A1 mDot-Examples mDot-IKS01A1-Explora ... more

Fork of libmDot-dev-mbed2-deprecated by MultiTech

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.

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;