Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mdot_two_way unh-hackathon-example unh-hackathon-example-raw TelitSensorToCloud ... more
Fork of libmDot-dev-mbed5-deprecated by
The Dot library provides a LoRaWan certified stack for LoRa communication using MultiTech mDot and xDot devices. The stack is compatible with mbed 5.
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:
- libmDot-mbed5 -> production-ready build for mDot
- libmDot-dev-mbed5 -> development build for mDot
- libxDot-mbed5 -> production-ready build for xDot
- libxDot-dev-mbed5 -> development build for xDot
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.
FOTA
Full FOTA support is only available with mDot, xDot does not have the required external flash. xDot can use the FOTA example to dynamically join a multicast session only. After joining the multicast session the received Fragmentation packets could be handed to a host MCU for processing and at completion the firmware can be loaded into the xDot using the bootloader and y-modem. See xDot Developer Guide.
- Add the following code to allow Fota to use the Dot instance
main.cpp
// Initialize FOTA singleton
Fota::getInstance(dot);
- Add fragmentation handling the the PacketRx event
RadioEvent.h
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, bool dupRx) {
mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, dupRx);
#if ACTIVE_EXAMPLE == FOTA_EXAMPLE
if(port == 200 || port == 201 || port == 202) {
Fota::getInstance()->processCmd(payload, port, size);
}
#endif
}
A definition is needed to enable Fragmentation support on mDot and save fragments to flash. This should not be defined for xDot and will result in a compiler error.
mbed_app.json
{
"macros": [
"FOTA=1"
]
}
The FOTA implementation has a few differences from the LoRaWAN Protocol
- Fragmentation Indexing starts at 0
- McKEKey is 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
- Start Time is a count-down in seconds to start of session
Revision 64:64982192a2af, committed 2018-08-23
- Comitter:
- Jenkins@KEILDM1.dc.multitech.prv
- Date:
- Thu Aug 23 14:18:55 2018 -0500
- Parent:
- 63:ed37629c03cd
- Child:
- 65:acc0468b9aec
- Commit message:
- mdot-library revision 3.1.0 and mbed-os revision mbed-os-5.7.7
Changed in this revision
--- a/ChannelPlan.h Tue Jun 19 13:13:52 2018 -0500
+++ b/ChannelPlan.h Thu Aug 23 14:18:55 2018 -0500
@@ -74,6 +74,11 @@
* ChannelPlan destructor
*/
virtual ~ChannelPlan();
+
+ /**
+ * Checks that at least one channel exist for the data rate
+ */
+ virtual uint8_t ValidateAdrDatarate(uint8_t status);
/**
* Initialize channels, datarates and duty cycle bands according to current channel plan in settings
@@ -312,6 +317,16 @@
virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) = 0;
/**
+ * Callback to for downlink channel request ServerCommand
+ * @param payload packet data
+ * @param index of start of command buffer
+ * @param size number of bytes in command buffer
+ * @param[out] status to be returned in MoteCommand answer
+ * @return LORA_OK
+ */
+ virtual uint8_t HandleDownlinkChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
+
+ /**
* Callback to for ping slot channel request ServerCommand
* @param payload packet data
* @param index of start of command buffer
@@ -441,7 +456,7 @@
/**
* Update duty cycle with current settings
*/
- virtual void UpdateDutyCycle(uint8_t bytes);
+ void UpdateDutyCycle(uint8_t bytes);
/**
* Update duty cycle with at given frequency and time on air
@@ -536,7 +551,12 @@
virtual void DefaultLBT();
virtual bool ListenBeforeTalk();
-
+
+ /**
+ * use to clear downlink channels on join
+ */
+ virtual void ClearChannels();
+
protected:
SxRadio* GetRadio(); //!< Get pointer to the SxRadio object or assert if it is null
--- a/Lora.h Tue Jun 19 13:13:52 2018 -0500
+++ b/Lora.h Thu Aug 23 14:18:55 2018 -0500
@@ -140,19 +140,44 @@
const uint32_t AU915_FREQ_MAX = 928000000;
const uint8_t AU915_MIN_DATARATE = (uint8_t) DR_0; //!< Minimum transmit datarate for AU915
- const uint8_t AU915_MAX_DATARATE = (uint8_t) DR_4; //!< Maximum transmit datarate for AU915
+ const uint8_t AU915_MAX_DATARATE = (uint8_t) DR_6; //!< Maximum transmit datarate for AU915
const uint8_t AU915_MIN_DATARATE_OFFSET = (uint8_t) 0; //!< Minimum transmit datarate for AU915
- const uint8_t AU915_MAX_DATARATE_OFFSET = (uint8_t) 3; //!< Maximum transmit datarate for AU915
+ const uint8_t AU915_MAX_DATARATE_OFFSET = (uint8_t) 5; //!< Maximum transmit datarate for AU915
const uint8_t EU868_125K_NUM_CHANS = 16; //!< Number of 125k channels in EU868 channel plan
- const uint8_t EU868_DEFAULT_NUM_CHANS = 3; //!< Number of defualt channels in EU868 channel plan
+ const uint8_t EU868_DEFAULT_NUM_CHANS = 3; //!< Number of default channels in EU868 channel plan
const uint32_t EU868_125K_FREQ_BASE = 868100000; //!< Frequency base for 125k EU868 uplink channels
const uint32_t EU868_125K_FREQ_STEP = 200000; //!< Frequency step for 125k EU868 uplink channels
const uint32_t EU868_RX2_FREQ = 869525000; //!< Frequency default for second rx window in EU868
const uint8_t EU868_TX_POWER_MAX = 14; //!< Max power for EU868 channel plan
+ const uint8_t KR920_125K_NUM_CHANS = 16; //!< Number of 125k channels in KR920 channel plan
+ const uint8_t KR920_DEFAULT_NUM_CHANS = 3; //!< Number of default channels in KR920 channel plan
+ const uint32_t KR920_125K_FREQ_BASE = 868100000; //!< Frequency base for 125k KR920 uplink channels
+ const uint32_t KR920_125K_FREQ_STEP = 200000; //!< Frequency step for 125k KR920 uplink channels
+ const uint32_t KR920_RX2_FREQ = 869525000; //!< Frequency default for second rx window in KR920
+
+ const uint8_t KR920_TX_POWER_MAX = 14; //!< Max power for KR920 channel plan
+
+ const uint8_t AS923_125K_NUM_CHANS = 16; //!< Number of 125k channels in AS923 channel plan
+ const uint8_t AS923_DEFAULT_NUM_CHANS = 2; //!< Number of default channels in AS923 channel plan
+ const uint32_t AS923_125K_FREQ_BASE = 868100000; //!< Frequency base for 125k AS923 uplink channels
+ const uint32_t AS923_125K_FREQ_STEP = 200000; //!< Frequency step for 125k AS923 uplink channels
+ const uint32_t AS923_RX2_FREQ = 869525000; //!< Frequency default for second rx window in AS923
+
+ const uint8_t AS923_TX_POWER_MAX = 14; //!< Max power for AS923 channel plan
+
+ const uint8_t IN865_125K_NUM_CHANS = 16; //!< Number of 125k channels in IN865 channel plan
+ const uint8_t IN865_DEFAULT_NUM_CHANS = 3; //!< Number of default channels in IN865 channel plan
+ const uint32_t IN865_125K_DEF_FREQ_1 = 865062500;
+ const uint32_t IN865_125K_DEF_FREQ_2 = 865402500;
+ const uint32_t IN865_125K_DEF_FREQ_3 = 865985000;
+ const uint32_t IN865_RX2_FREQ = 866550000; //!< Frequency default for second rx window in IN865
+
+ const uint8_t IN865_TX_POWER_MAX = 30; //!< Max power for IN865 channel plan
+
// 0.1% duty cycle 863-868
// Limiting to 865-868 allows for 1% duty cycle
const uint32_t EU868_MILLI_FREQ_MIN = 865000000;
@@ -208,14 +233,21 @@
const uint8_t FRAME_OVERHEAD = 13; //!< Bytes of network info overhead in a frame
+ const uint16_t MAX_OFF_AIR_WAIT = 5000U; //!< Max time in ms to block for a duty cycle restriction to expire before erroring out
/**
* Settings for type of network
- * PUBLIC - defaults to 5/6 second join windows and 0x34 sync word
- * PRIVATE - defaults to 1/2 second join windows and 0x12 sync word
+ *
+ * PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band
+ * PUBLIC_LORAWAN - Sync Word 0x34
+ * PRIVATE_LORAWAN - Sync Word 0x12
+ * PEER_TO_PEER - Sync Word 0x56 used for Dot to Dot communication
+ *
+ * Join Delay window settings are independent of Network Type setting
*/
enum NetworkType {
- PRIVATE = 0,
- PUBLIC = 1,
+ PRIVATE_MTS = 0,
+ PUBLIC_LORAWAN = 1,
+ PRIVATE_LORAWAN = 2,
PEER_TO_PEER = 4
};
@@ -306,7 +338,8 @@
RX_1 = 1, //!< First receive window
RX_2, //!< Second receive window
RX_BEACON, //!< Beacon receive window
- RX_SLOT, //!< Beacon Slot receive window
+ RX_SLOT, //!< Ping Slot receive window
+ RXC, //!< Class C continuous window
RX_TEST
};
--- a/MTS-Lora/vendor/multitech/MTS-Utils/MTSCircularBuffer.h Tue Jun 19 13:13:52 2018 -0500
+++ b/MTS-Lora/vendor/multitech/MTS-Utils/MTSCircularBuffer.h Thu Aug 23 14:18:55 2018 -0500
@@ -1,6 +1,8 @@
#ifndef MTSCIRCULARBUFFER_H
#define MTSCIRCULARBUFFER_H
+#include <Callback.h>
+
#include "Utils.h"
namespace mts
@@ -99,7 +101,7 @@
void attach(void(*fptr)(void), int threshold, RelationalOperator op) {
_threshold = threshold;
_op = op;
- notify.attach(fptr);
+ notify = fptr;
}
/** This method returns the size of the storage space currently allocated for
@@ -147,7 +149,7 @@
int readIndex; // read index for circular buffer
int writeIndex; // write index for circular buffer
int bytes; // available data
- FunctionPointer notify; // function pointer used for the internal callback notification
+ Callback<void()> notify; // Internal callback notification
int _threshold; // threshold for the notification
RelationalOperator _op; // operator that determines the direction of the threshold
void checkThreshold(); // private function that checks thresholds and processes notifications
--- a/MacEvents.h Tue Jun 19 13:13:52 2018 -0500
+++ b/MacEvents.h Thu Aug 23 14:18:55 2018 -0500
@@ -25,12 +25,13 @@
public:
virtual ~MacEvents() {};
+ virtual void TxStart(void) = 0;
virtual void TxDone(uint8_t dr) = 0;
virtual void TxTimeout(void) = 0;
virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) = 0;
virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) = 0;
- 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) = 0;
+ 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 Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) = 0;
--- a/Mote.h Tue Jun 19 13:13:52 2018 -0500
+++ b/Mote.h Thu Aug 23 14:18:55 2018 -0500
@@ -31,6 +31,11 @@
class MoteEvents: public MacEvents {
/**
+ * Fired at start of TX
+ */
+ virtual void TxStart(void);
+
+ /**
* Fired at end of TX
* @param dr datarate used for TX
*/
@@ -60,7 +65,7 @@
virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);
/**
- * Fired when non duplicate packet is received and MIC is valid
+ * Fired when packet is received and MIC is valid
* @param port of packet
* @param payload received bytes
* @param size number of received bytes
@@ -69,8 +74,10 @@
* @param ctrl Downlink control field of packet
* @param slot rx window packet was received
* @param retries number of attempts before ack was received
+ * @param address of the end device
+ * @param dupRx set if this packet has already been received
*/
- 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);
+ 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);
/**
* Fired when radio has received a packet, packet is not validated
@@ -170,6 +177,7 @@
*/
uint8_t SetChannelPlan(ChannelPlan* plan);
+
Settings* GetSettings();
/**
--- a/SxRadio.h Tue Jun 19 13:13:52 2018 -0500
+++ b/SxRadio.h Thu Aug 23 14:18:55 2018 -0500
@@ -270,6 +270,10 @@
virtual void SignalMacEvent(void) {};
+ virtual void ResetRadio(void) {};
+
+ virtual uint32_t GetTimeOnAir(void) = 0;
+
void GrabMutex(void) { mutex.lock(); }
void ReleaseMutex(void) { mutex.unlock(); }
--- a/SxRadioEvents.h Tue Jun 19 13:13:52 2018 -0500
+++ b/SxRadioEvents.h Thu Aug 23 14:18:55 2018 -0500
@@ -22,6 +22,10 @@
{
public:
/*!
+ * \brief Tx Start callback prototype.
+ */
+ virtual void TxStart( void ) {}
+ /*!
* \brief Tx Done callback prototype.
*/
virtual void TxDone( void ) {}
Binary file libmDot-ARMCC.ar has changed
Binary file libmDot-GCC_ARM.a has changed
--- a/mDot.h Tue Jun 19 13:13:52 2018 -0500
+++ b/mDot.h Thu Aug 23 14:18:55 2018 -0500
@@ -51,8 +51,6 @@
uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
- void wakeup();
-
void enterStopMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
void enterStandbyMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
@@ -111,6 +109,7 @@
MDOT_AGGREGATED_DUTY_CYCLE = -11,
MDOT_MAX_PAYLOAD_EXCEEDED = -12,
MDOT_LBT_CHANNEL_BUSY = -13,
+ MDOT_NOT_IDLE = -14,
MDOT_ERROR = -1024,
} mdot_ret_code;
@@ -147,15 +146,7 @@
DR12,
DR13,
DR14,
- DR15,
- SF_12 = 16,
- SF_11,
- SF_10,
- SF_9,
- SF_8,
- SF_7,
- SF_7H,
- SF_FSK
+ DR15
};
enum FrequencySubBands {
@@ -241,7 +232,7 @@
typedef struct {
bool status;
- int32_t dBm;
+ uint8_t dBm;
uint32_t gateways;
std::vector<uint8_t> payload;
} link_check;
@@ -252,9 +243,6 @@
int16_t snr;
} ping_response;
- static const uint8_t MaxLengths_915[];
- static const uint8_t MaxLengths_868[];
-
static std::string JoinModeStr(uint8_t mode);
static std::string ModeStr(uint8_t mode);
static std::string RxOutputStr(uint8_t format);
@@ -275,6 +263,13 @@
*/
static mDot* getInstance(lora::ChannelPlan* plan);
+ /**
+ * Can only be used after a dot has
+ * configured with a plan
+ * @returns pointer to mDot object
+ */
+ static mDot* getInstance();
+
void setEvents(mDotEvent* events);
/**
@@ -521,19 +516,32 @@
void setListenBeforeTalkTime(uint32_t ms);
/**
- * Enable/disable public network mode
- * JoinDelay will be set to (public: 5s, private: 1s) and
- * RxDelay will be set to 1s both can be adjusted afterwards
- * @param on should be true to enable public network mode
+ * Set public network mode
+ * 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
+ * PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band
+ * PUBLIC_LORAWAN - Sync Word 0x34
+ * PRIVATE_LORAWAN - Sync Word 0x12
+ *
+ * The default Join Delay is 5 seconds
+ * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+ * The Join Delay must be changed independently of Public Network setting
+ *
+ * @see lora::NetworkType
* @returns MDOT_OK if success
*/
- int32_t setPublicNetwork(const bool& on);
+ int32_t setPublicNetwork(const uint8_t& val);
/**
* Get public network mode
- * @returns true if public network mode is enabled
+ *
+ * The default Join Delay is 5 seconds
+ * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+ * The Join Delay must be changed independently of Public Network setting
+ *
+ * @see lora:NetworkType
+ * @returns 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
*/
- bool getPublicNetwork();
+ uint8_t getPublicNetwork();
/**
* Get the device ID
@@ -702,6 +710,19 @@
const uint8_t* getAppKey();
/**
+ * 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);
+
+ /**
* Set join byte order
* @param order 0:LSB 1:MSB
*/
@@ -883,16 +904,24 @@
/**
* Get join delay in seconds
- * Public network defaults to 5 seconds
- * Private network defaults to 1 second
+ * Defaults to 5 seconds
+ * Must match join delay setting of the network server
+ *
+ * The default Join Delay is 5 seconds
+ * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+ *
* @returns number of seconds before join accept message is expected
*/
uint8_t getJoinDelay();
/**
* Set join delay in seconds
- * Public network defaults to 5 seconds
- * Private network defaults to 1 second
+ * Defaults to 5 seconds
+ * Must match join delay setting of the network server
+ *
+ * The default Join Delay is 5 seconds
+ * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+ *
* @param delay number of seconds before join accept message is expected
* @return MDOT_OK if success
*/
@@ -999,7 +1028,7 @@
/**
* Set TX data rate
* data rates affect maximum payload size
- * @param dr SF_7 - SF_12|DR0-DR7 for Europe, SF_7 - SF_10 | DR0-DR4 for United States
+ * @param dr DR0-DR7 for Europe, DR0-DR4 for United States
* @returns MDOT_OK if success
*/
int32_t setTxDataRate(const uint8_t& dr);
@@ -1298,8 +1327,24 @@
* For the XDOT
* in sleep mode, the device can be woken up on GPIO (0-3), UART1_RX, WAKE or by the RTC alarm
* in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, WAKE) or by the RTC alarm
+ * @returns MDOT_OK on success
*/
- void sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
+ int32_t sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
+
+ /**
+ * Set auto sleep mode
+ * Auto sleep mode will automatically put the MCU to sleep after tx and in between receive windows
+ * Note: The MCU will go into a stop mode sleep in between rx windows. This means that
+ * peripherals such as timers will not function during the sleep intervals.
+ * @param enable - Flag to enable auto sleep mode
+ */
+ void setAutoSleep(bool enable);
+
+ /**
+ * Get auto sleep mode
+ * @returns 0 if sleep mode is disabled, 1 if it is enabled
+ */
+ uint8_t getAutoSleep();
/**
* Set wake pin
@@ -1601,8 +1646,11 @@
void closeRxWindow();
void sendContinuous(bool enable=true);
int32_t setDeviceId(const std::vector<uint8_t>& id);
+ int32_t setProtectedAppEUI(const std::vector<uint8_t>& appEUI);
+ int32_t setProtectedAppKey(const std::vector<uint8_t>& appKey);
int32_t setDefaultFrequencyBand(const uint8_t& band);
bool saveProtectedConfig();
+ // resets the radio/mac/link
void resetRadio();
int32_t setRadioMode(const uint8_t& mode);
std::map<uint8_t, uint8_t> dumpRegisters();
@@ -1629,8 +1677,35 @@
void setWakeupCallback(T *object, void (T::*member)(void)) {
_wakeup_callback.attach(object, member);
}
+
+ lora::ChannelPlan* getChannelPlan(void);
+ uint32_t setRx2DataRate(uint8_t dr);
+ uint8_t getRx2DataRate();
+
+ void mcGroupKeys(uint8_t *mcKeyEncrypt, uint32_t addr, uint8_t groupId, uint32_t frame_count);
private:
+ typedef enum {
+ AUTO_SLEEP_EVT_CFG,
+ AUTO_SLEEP_EVT_TXDONE,
+ AUTO_SLEEP_EVT_RX1_TIMEOUT,
+ AUTO_SLEEP_EVT_CLEANUP
+ } AutoSleepEvent_t;
+
+ typedef enum {
+ USER_SLEEP,
+ AUTO_SLEEP
+ } SleepClient_t;
+
+ void sleep_ms(uint32_t interval,
+ uint8_t wakeup_mode = RTC_ALARM,
+ bool deepsleep = true,
+ SleepClient_t sleep_client = USER_SLEEP);
+
+ void auto_sleep(AutoSleepEvent_t evt);
+
+ void wakeup(SleepClient_t sleep_client);
+
mdot_stats _stats;
FunctionPointer _wakeup_callback;
--- a/mDotEvent.h Tue Jun 19 13:13:52 2018 -0500
+++ b/mDotEvent.h Thu Aug 23 14:18:55 2018 -0500
@@ -1,6 +1,7 @@
#ifndef MDOT_EVENT_H
#define MDOT_EVENT_H
+#include "mbed.h"
#include "mDot.h"
#include "MacEvents.h"
#include "MTSLog.h"
@@ -38,6 +39,7 @@
LoRaMacEventInfoStatus Status;
lora::DownlinkControl Ctrl;
bool TxAckReceived;
+ bool DuplicateRx;
uint8_t TxNbRetries;
uint8_t TxDatarate;
uint8_t RxPort;
@@ -65,7 +67,9 @@
PongRssi(0),
PongSnr(0),
AckReceived(false),
- TxNbRetries(0)
+ DuplicateRx(false),
+ TxNbRetries(0),
+ _sleep_cb(NULL)
{
memset(&_flags, 0, sizeof(LoRaMacEventFlags));
memset(&_info, 0, sizeof(LoRaMacEventInfo));
@@ -115,11 +119,20 @@
}
}
+ virtual void TxStart() {
+ logDebug("mDotEvent - TxStart");
+
+ // Fire auto sleep cfg event if enabled
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CFG);
+ }
+
virtual void TxDone(uint8_t dr) {
RxPayloadSize = 0;
LinkCheckAnsReceived = false;
PacketReceived = false;
AckReceived = false;
+ DuplicateRx = false;
PongReceived = false;
TxNbRetries = 0;
@@ -131,6 +144,10 @@
_info.TxDatarate = dr;
_info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Notify();
+
+ // If configured, we can sleep until the rx window opens
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_TXDONE);
}
void Notify() {
@@ -152,6 +169,9 @@
_flags.Bits.JoinAccept = 1;
_info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Notify();
+
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
}
virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
@@ -161,6 +181,9 @@
_flags.Bits.JoinAccept = 1;
_info.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL;
Notify();
+
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
}
virtual void MissedAck(uint8_t retries) {
@@ -169,8 +192,8 @@
_info.TxNbRetries = retries;
}
- 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) {
- logDebug("mDotEvent - PacketRx");
+ 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, bool dupRx) {
+ logDebug("mDotEvent - PacketRx ADDR: %08x", address);
RxPort = port;
PacketReceived = true;
@@ -181,6 +204,8 @@
AckReceived = true;
}
+ DuplicateRx = dupRx;
+
if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
std::string packet = mts::Text::bin2hexString(RxPayload, size);
logTrace("Payload: %s", packet.c_str());
@@ -196,6 +221,7 @@
_info.RxRssi = rssi;
_info.RxSnr = snr;
_info.TxAckReceived = AckReceived;
+ _info.DuplicateRx = DuplicateRx;
_info.TxNbRetries = retries;
_info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Notify();
@@ -203,6 +229,9 @@
virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) {
logDebug("mDotEvent - RxDone");
+
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
}
virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) {
@@ -229,12 +258,20 @@
}
virtual void RxTimeout(uint8_t slot) {
- // logDebug("mDotEvent - RxTimeout");
+ logDebug("mDotEvent - RxTimeout on Slot %d", slot);
_flags.Bits.Tx = 0;
_flags.Bits.RxSlot = slot;
_info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT;
Notify();
+
+ if (_sleep_cb) {
+ // If this is the first rx window we can sleep until the next one
+ if (slot == 1)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_RX1_TIMEOUT);
+ else
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
+ }
}
virtual void RxError(uint8_t slot) {
@@ -246,12 +283,23 @@
_flags.Bits.RxSlot = slot;
_info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR;
Notify();
+
+ if (_sleep_cb)
+ _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
}
virtual uint8_t MeasureBattery(void) {
return 255;
}
+ void AttachSleepCallback(Callback<void(mDot::AutoSleepEvent_t)> cb) {
+ _sleep_cb = cb;
+ }
+
+ void DetachSleepCallback() {
+ _sleep_cb = NULL;
+ }
+
bool LinkCheckAnsReceived;
uint8_t DemodMargin;
uint8_t NbGateways;
@@ -266,6 +314,7 @@
int16_t PongSnr;
bool AckReceived;
+ bool DuplicateRx;
uint8_t TxNbRetries;
LoRaMacEventFlags& Flags() {
@@ -276,6 +325,8 @@
}
private:
+ /* Hook to inject a sleep method in between receive windows */
+ Callback<void(mDot::AutoSleepEvent_t)> _sleep_cb;
LoRaMacEventFlags _flags;
LoRaMacEventInfo _info;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_lib.json Thu Aug 23 14:18:55 2018 -0500
@@ -0,0 +1,19 @@
+{
+ "name": "mdot-library",
+ "config": {
+ "main-stack-size": {
+ "macro_name": "MBED_CONF_APP_MAIN_STACK_SIZE",
+ "value": 4096
+ },
+ "thread-stack-size": {
+ "macro_name": "MBED_CONF_APP_THREAD_STACK_SIZE",
+ "value": 2048
+ }
+ },
+ "target_overrides": {
+ "XDOT_L151CC": {
+ "main-stack-size": 2048,
+ "thread-stack-size": 256
+ }
+ }
+}
--- a/plans/ChannelPlan_AS923.h Tue Jun 19 13:13:52 2018 -0500
+++ b/plans/ChannelPlan_AS923.h Thu Aug 23 14:18:55 2018 -0500
@@ -225,6 +225,11 @@
*/
virtual uint8_t GetMaxPayloadSize();
+ /**
+ * Decrements the datarate based on TxDwellTime
+ */
+ virtual void DecrementDatarate();
+
protected:
static const uint8_t AS923_TX_POWERS[8]; //!< List of available tx powers
--- a/plans/ChannelPlan_AU915.h Tue Jun 19 13:13:52 2018 -0500
+++ b/plans/ChannelPlan_AU915.h Thu Aug 23 14:18:55 2018 -0500
@@ -167,6 +167,16 @@
virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
/**
+ * Callback to for downlink channel request ServerCommand
+ * @param payload packet data
+ * @param index of start of command buffer
+ * @param size number of bytes in command buffer
+ * @param[out] status to be returned in MoteCommand answer
+ * @return LORA_OK
+ */
+ virtual uint8_t HandleDownlinkChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
+
+ /**
* Callback to for ping slot channel request ServerCommand
* @param payload packet data
* @param index of start of command buffer
--- a/plans/ChannelPlan_IN865.h Tue Jun 19 13:13:52 2018 -0500
+++ b/plans/ChannelPlan_IN865.h Thu Aug 23 14:18:55 2018 -0500
@@ -219,6 +219,16 @@
*/
virtual uint8_t HandleMacCommand(uint8_t* payload, uint8_t& index);
+ /**
+ *Decrements the datarate based on TxDwellTime
+ */
+ virtual void DecrementDatarate();
+
+ /**
+ *Decrements the datarate based on TxDwellTime
+ */
+ virtual void IncrementDatarate();
+
protected:
static const uint8_t IN865_TX_POWERS[11]; //!< List of available tx powers
--- a/plans/ChannelPlan_US915.h Tue Jun 19 13:13:52 2018 -0500
+++ b/plans/ChannelPlan_US915.h Thu Aug 23 14:18:55 2018 -0500
@@ -167,6 +167,16 @@
virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
/**
+ * Callback to for downlink channel request ServerCommand
+ * @param payload packet data
+ * @param index of start of command buffer
+ * @param size number of bytes in command buffer
+ * @param[out] status to be returned in MoteCommand answer
+ * @return LORA_OK
+ */
+ virtual uint8_t HandleDownlinkChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
+
+ /**
* Callback to for ping slot channel request ServerCommand
* @param payload packet data
* @param index of start of command buffer


