Library for LoRa communication using MultiTech MDOT.

Dependents:   mDot_test_rx adc_sensor_lora mDotEVBM2X mDot_AT_firmware ... more

Function documentation is in mDot.h

Warning

Using libmDot 2.0.3 and above with an existing application may require a change in the MacEvent handler!
Compile applications with mbed v121 and mbed-rtos v116 libraries.

In AT Command Firmware remove line 803.

CommandTerminal/CommandTerminal.cpp

        delete[] info->RxBuffer;

Likewise, if your application is handling events from the library asynchronously.

Committer:
Mike Fiore
Date:
Tue Mar 29 10:18:28 2016 -0500
Revision:
11:9938ba31d428
Parent:
10:0b4eb17d07ae
Child:
15:b50f92f1c6ff
update to version 1.0.7 of mDot library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 10:0b4eb17d07ae 1 // TODO: add license header
mfiore 0:c62615f15125 2
mfiore 0:c62615f15125 3 #ifndef MDOT_H
mfiore 0:c62615f15125 4 #define MDOT_H
mfiore 0:c62615f15125 5
mfiore 0:c62615f15125 6 #include "mbed.h"
mfiore 0:c62615f15125 7 #include "rtos.h"
mfiore 0:c62615f15125 8 #include <vector>
mfiore 0:c62615f15125 9 #include <map>
mfiore 0:c62615f15125 10 #include <string>
mfiore 0:c62615f15125 11
Mike Fiore 11:9938ba31d428 12 class mDotEvent;
mfiore 0:c62615f15125 13 class LoRaMacEvent;
mfiore 0:c62615f15125 14 class LoRaConfig;
mfiore 0:c62615f15125 15 class LoRaMac;
mfiore 0:c62615f15125 16 class MdotRadio;
mfiore 0:c62615f15125 17
mfiore 0:c62615f15125 18 class mDot {
mfiore 0:c62615f15125 19
mfiore 0:c62615f15125 20 private:
mfiore 0:c62615f15125 21
mfiore 0:c62615f15125 22 mDot();
mfiore 0:c62615f15125 23 ~mDot();
mfiore 0:c62615f15125 24
mfiore 0:c62615f15125 25 static void idle(void const* args) {
mfiore 0:c62615f15125 26 while (1)
mfiore 0:c62615f15125 27 __WFI();
mfiore 0:c62615f15125 28 }
mfiore 0:c62615f15125 29
mfiore 0:c62615f15125 30 void setLastError(const std::string& str);
mfiore 0:c62615f15125 31
mfiore 0:c62615f15125 32 static bool validateBaudRate(const uint32_t& baud);
mfiore 0:c62615f15125 33 static bool validateFrequencySubBand(const uint8_t& band);
mfiore 0:c62615f15125 34 bool validateDataRate(const uint8_t& dr);
mfiore 0:c62615f15125 35
mfiore 0:c62615f15125 36 int32_t joinBase(const uint32_t& retries);
mfiore 0:c62615f15125 37 int32_t sendBase(const std::vector<uint8_t>& data, const bool& confirmed = false, const bool& blocking = true, const bool& highBw = false);
mfiore 0:c62615f15125 38 void waitForPacket();
mfiore 0:c62615f15125 39 void waitForLinkCheck();
mfiore 0:c62615f15125 40
mfiore 0:c62615f15125 41 void setActivityLedState(const uint8_t& state);
mfiore 0:c62615f15125 42 uint8_t getActivityLedState();
mfiore 0:c62615f15125 43
mfiore 0:c62615f15125 44 void blinkActivityLed(void) {
Mike Fiore 6:390fc83d588d 45 if (_activity_led) {
Mike Fiore 6:390fc83d588d 46 int val = _activity_led->read();
Mike Fiore 6:390fc83d588d 47 _activity_led->write(!val);
Mike Fiore 6:390fc83d588d 48 }
mfiore 0:c62615f15125 49 }
mfiore 0:c62615f15125 50
mfiore 0:c62615f15125 51 mDot(const mDot&);
mfiore 0:c62615f15125 52 mDot& operator=(const mDot&);
mfiore 0:c62615f15125 53
Mike Fiore 7:683dba5d576f 54 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
Mike Fiore 7:683dba5d576f 55 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
Mike Fiore 7:683dba5d576f 56
Mike Fiore 7:683dba5d576f 57 void wakeup();
Mike Fiore 7:683dba5d576f 58
Mike Fiore 11:9938ba31d428 59 void enterStopMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
Mike Fiore 11:9938ba31d428 60 void enterStandbyMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
Mike Fiore 11:9938ba31d428 61
mfiore 0:c62615f15125 62 static mDot* _instance;
mfiore 0:c62615f15125 63
mfiore 0:c62615f15125 64 LoRaMac* _mac;
mfiore 0:c62615f15125 65 MdotRadio* _radio;
mfiore 0:c62615f15125 66 LoRaMacEvent* _events;
mfiore 0:c62615f15125 67 LoRaConfig* _config;
mfiore 0:c62615f15125 68 Thread _idle_thread;
mfiore 0:c62615f15125 69 std::string _last_error;
mfiore 0:c62615f15125 70 static const uint32_t _baud_rates[];
mfiore 0:c62615f15125 71 uint8_t _activity_led_state;
mfiore 0:c62615f15125 72 Ticker _tick;
Mike Fiore 6:390fc83d588d 73 DigitalOut* _activity_led;
Mike Fiore 6:390fc83d588d 74 bool _activity_led_enable;
Mike Fiore 6:390fc83d588d 75 PinName _activity_led_pin;
Mike Fiore 5:0bfe6a650513 76 bool _activity_led_external;
Mike Fiore 10:0b4eb17d07ae 77 uint8_t _linkFailCount;
Mike Fiore 7:683dba5d576f 78 uint8_t _class;
Mike Fiore 7:683dba5d576f 79 InterruptIn* _wakeup;
Mike Fiore 7:683dba5d576f 80 PinName _wakeup_pin;
mfiore 0:c62615f15125 81
mfiore 0:c62615f15125 82 typedef enum {
Mike Fiore 11:9938ba31d428 83 OFF,
Mike Fiore 11:9938ba31d428 84 ON,
Mike Fiore 11:9938ba31d428 85 BLINK,
mfiore 0:c62615f15125 86 } state;
mfiore 0:c62615f15125 87
mfiore 0:c62615f15125 88 public:
mfiore 0:c62615f15125 89
mfiore 0:c62615f15125 90 typedef enum {
Mike Fiore 7:683dba5d576f 91 FM_APPEND = (1 << 0),
Mike Fiore 7:683dba5d576f 92 FM_TRUNC = (1 << 1),
Mike Fiore 7:683dba5d576f 93 FM_CREAT = (1 << 2),
Mike Fiore 7:683dba5d576f 94 FM_RDONLY = (1 << 3),
Mike Fiore 7:683dba5d576f 95 FM_WRONLY = (1 << 4),
Mike Fiore 7:683dba5d576f 96 FM_RDWR = (FM_RDONLY | FM_WRONLY),
Mike Fiore 7:683dba5d576f 97 FM_DIRECT = (1 << 5)
Mike Fiore 7:683dba5d576f 98 } FileMode;
Mike Fiore 7:683dba5d576f 99
Mike Fiore 7:683dba5d576f 100 typedef enum {
mfiore 0:c62615f15125 101 MDOT_OK = 0,
mfiore 0:c62615f15125 102 MDOT_INVALID_PARAM = -1,
mfiore 0:c62615f15125 103 MDOT_TX_ERROR = -2,
mfiore 0:c62615f15125 104 MDOT_RX_ERROR = -3,
mfiore 0:c62615f15125 105 MDOT_JOIN_ERROR = -4,
mfiore 0:c62615f15125 106 MDOT_TIMEOUT = -5,
mfiore 0:c62615f15125 107 MDOT_NOT_JOINED = -6,
mfiore 0:c62615f15125 108 MDOT_ENCRYPTION_DISABLED = -7,
mfiore 0:c62615f15125 109 MDOT_NO_FREE_CHAN = -8,
Mike Fiore 11:9938ba31d428 110 MDOT_TEST_MODE = -9,
Mike Fiore 11:9938ba31d428 111 MDOT_NO_ENABLED_CHAN = -10,
Mike Fiore 11:9938ba31d428 112 MDOT_AGGREGATED_DUTY_CYCLE = -11,
mfiore 0:c62615f15125 113 MDOT_ERROR = -1024,
mfiore 0:c62615f15125 114 } mdot_ret_code;
mfiore 0:c62615f15125 115
mfiore 0:c62615f15125 116 enum JoinMode {
Mike Fiore 11:9938ba31d428 117 MANUAL,
Mike Fiore 11:9938ba31d428 118 OTA,
Mike Fiore 11:9938ba31d428 119 AUTO_OTA,
Mike Fiore 11:9938ba31d428 120 PEER_TO_PEER
mfiore 0:c62615f15125 121 };
mfiore 0:c62615f15125 122
mfiore 0:c62615f15125 123 enum Mode {
Mike Fiore 11:9938ba31d428 124 COMMAND_MODE,
Mike Fiore 11:9938ba31d428 125 SERIAL_MODE
mfiore 0:c62615f15125 126 };
mfiore 0:c62615f15125 127
mfiore 0:c62615f15125 128 enum RX_Output {
Mike Fiore 11:9938ba31d428 129 HEXADECIMAL,
Mike Fiore 11:9938ba31d428 130 BINARY
mfiore 0:c62615f15125 131 };
mfiore 0:c62615f15125 132
mfiore 0:c62615f15125 133 enum DataRates {
Mike Fiore 11:9938ba31d428 134 DR0,
Mike Fiore 11:9938ba31d428 135 DR1,
Mike Fiore 11:9938ba31d428 136 DR2,
Mike Fiore 11:9938ba31d428 137 DR3,
Mike Fiore 11:9938ba31d428 138 DR4,
Mike Fiore 11:9938ba31d428 139 DR5,
Mike Fiore 11:9938ba31d428 140 DR6,
Mike Fiore 11:9938ba31d428 141 DR7,
Mike Fiore 11:9938ba31d428 142 DR8,
Mike Fiore 11:9938ba31d428 143 DR9,
Mike Fiore 11:9938ba31d428 144 DR10,
Mike Fiore 11:9938ba31d428 145 DR11,
Mike Fiore 11:9938ba31d428 146 DR12,
Mike Fiore 11:9938ba31d428 147 DR13,
Mike Fiore 11:9938ba31d428 148 DR14,
Mike Fiore 11:9938ba31d428 149 DR15,
Mike Fiore 11:9938ba31d428 150 SF_12 = 16,
Mike Fiore 11:9938ba31d428 151 SF_11,
Mike Fiore 11:9938ba31d428 152 SF_10,
Mike Fiore 11:9938ba31d428 153 SF_9,
Mike Fiore 11:9938ba31d428 154 SF_8,
Mike Fiore 11:9938ba31d428 155 SF_7,
Mike Fiore 11:9938ba31d428 156 SF_7H,
Mike Fiore 11:9938ba31d428 157 SF_FSK
mfiore 0:c62615f15125 158 };
mfiore 0:c62615f15125 159
mfiore 0:c62615f15125 160 enum FrequencyBands {
Mike Fiore 11:9938ba31d428 161 FB_868, // EU868
Mike Fiore 11:9938ba31d428 162 FB_915 // US915
mfiore 0:c62615f15125 163 };
mfiore 0:c62615f15125 164
mfiore 0:c62615f15125 165 enum FrequencySubBands {
Mike Fiore 11:9938ba31d428 166 FSB_ALL,
Mike Fiore 11:9938ba31d428 167 FSB_1,
Mike Fiore 11:9938ba31d428 168 FSB_2,
Mike Fiore 11:9938ba31d428 169 FSB_3,
Mike Fiore 11:9938ba31d428 170 FSB_4,
Mike Fiore 11:9938ba31d428 171 FSB_5,
Mike Fiore 11:9938ba31d428 172 FSB_6,
Mike Fiore 11:9938ba31d428 173 FSB_7,
Mike Fiore 11:9938ba31d428 174 FSB_8
mfiore 0:c62615f15125 175 };
mfiore 0:c62615f15125 176
Mike Fiore 6:390fc83d588d 177 enum JoinByteOrder {
Mike Fiore 11:9938ba31d428 178 LSB,
Mike Fiore 11:9938ba31d428 179 MSB
Mike Fiore 6:390fc83d588d 180 };
Mike Fiore 6:390fc83d588d 181
Mike Fiore 7:683dba5d576f 182 enum wakeup_mode {
Mike Fiore 11:9938ba31d428 183 RTC_ALARM,
Mike Fiore 11:9938ba31d428 184 INTERRUPT,
Mike Fiore 11:9938ba31d428 185 RTC_ALARM_OR_INTERRUPT
Mike Fiore 11:9938ba31d428 186 };
Mike Fiore 11:9938ba31d428 187
Mike Fiore 11:9938ba31d428 188 enum UserBackupRegs {
Mike Fiore 11:9938ba31d428 189 UBR0,
Mike Fiore 11:9938ba31d428 190 UBR1,
Mike Fiore 11:9938ba31d428 191 UBR2,
Mike Fiore 11:9938ba31d428 192 UBR3,
Mike Fiore 11:9938ba31d428 193 UBR4,
Mike Fiore 11:9938ba31d428 194 UBR5,
Mike Fiore 11:9938ba31d428 195 UBR6,
Mike Fiore 11:9938ba31d428 196 UBR7,
Mike Fiore 11:9938ba31d428 197 UBR8,
Mike Fiore 11:9938ba31d428 198 UBR9
Mike Fiore 7:683dba5d576f 199 };
Mike Fiore 7:683dba5d576f 200
Mike Fiore 7:683dba5d576f 201 typedef struct {
Mike Fiore 7:683dba5d576f 202 int16_t fd;
Mike Fiore 7:683dba5d576f 203 char name[30];
Mike Fiore 7:683dba5d576f 204 uint32_t size;
Mike Fiore 7:683dba5d576f 205 } mdot_file;
Mike Fiore 7:683dba5d576f 206
mfiore 0:c62615f15125 207 typedef struct {
mfiore 0:c62615f15125 208 uint32_t Up;
mfiore 0:c62615f15125 209 uint32_t Down;
mfiore 0:c62615f15125 210 uint32_t Joins;
mfiore 0:c62615f15125 211 uint32_t JoinFails;
mfiore 0:c62615f15125 212 uint32_t MissedAcks;
mfiore 0:c62615f15125 213 } mdot_stats;
mfiore 0:c62615f15125 214
mfiore 0:c62615f15125 215 typedef struct {
mfiore 0:c62615f15125 216 int16_t last;
mfiore 0:c62615f15125 217 int16_t min;
mfiore 0:c62615f15125 218 int16_t max;
mfiore 0:c62615f15125 219 int16_t avg;
mfiore 0:c62615f15125 220 } rssi_stats;
mfiore 0:c62615f15125 221
mfiore 0:c62615f15125 222 typedef struct {
Mike Fiore 11:9938ba31d428 223 int16_t last;
Mike Fiore 11:9938ba31d428 224 int16_t min;
Mike Fiore 11:9938ba31d428 225 int16_t max;
Mike Fiore 11:9938ba31d428 226 int16_t avg;
mfiore 0:c62615f15125 227 } snr_stats;
mfiore 0:c62615f15125 228
mfiore 0:c62615f15125 229 typedef struct {
mfiore 0:c62615f15125 230 bool status;
mfiore 0:c62615f15125 231 int32_t dBm;
mfiore 0:c62615f15125 232 uint32_t gateways;
mfiore 0:c62615f15125 233 std::vector<uint8_t> payload;
mfiore 0:c62615f15125 234 } link_check;
mfiore 0:c62615f15125 235
mfiore 0:c62615f15125 236 typedef struct {
mfiore 0:c62615f15125 237 int32_t status;
mfiore 0:c62615f15125 238 int16_t rssi;
mfiore 0:c62615f15125 239 int16_t snr;
mfiore 0:c62615f15125 240 } ping_response;
mfiore 0:c62615f15125 241
mfiore 0:c62615f15125 242 static const uint8_t MaxLengths_915[];
mfiore 0:c62615f15125 243 static const uint8_t MaxLengths_868[];
mfiore 0:c62615f15125 244
mfiore 0:c62615f15125 245 static std::string JoinModeStr(uint8_t mode);
mfiore 0:c62615f15125 246 static std::string ModeStr(uint8_t mode);
mfiore 0:c62615f15125 247 static std::string RxOutputStr(uint8_t format);
mfiore 0:c62615f15125 248 static std::string DataRateStr(uint8_t rate);
mfiore 0:c62615f15125 249 static std::string FrequencyBandStr(uint8_t band);
mfiore 0:c62615f15125 250 static std::string FrequencySubBandStr(uint8_t band);
mfiore 0:c62615f15125 251
Mike Fiore 11:9938ba31d428 252 uint32_t UserRegisters[10];
Mike Fiore 11:9938ba31d428 253
mfiore 0:c62615f15125 254 /** Get a handle to the singleton object
mfiore 0:c62615f15125 255 * @returns pointer to mDot object
mfiore 0:c62615f15125 256 */
mfiore 0:c62615f15125 257 static mDot* getInstance();
mfiore 0:c62615f15125 258
Mike Fiore 11:9938ba31d428 259 void setEvents(mDotEvent* events);
Mike Fiore 11:9938ba31d428 260
mfiore 0:c62615f15125 261 /** Get library version information
mfiore 0:c62615f15125 262 * @returns string containing library version information
mfiore 0:c62615f15125 263 */
mfiore 0:c62615f15125 264 std::string getId();
mfiore 0:c62615f15125 265
mfiore 0:c62615f15125 266 /** Perform a soft reset of the system
mfiore 0:c62615f15125 267 */
mfiore 0:c62615f15125 268 void resetCpu();
mfiore 0:c62615f15125 269
mfiore 0:c62615f15125 270 /** Reset config to factory default
mfiore 0:c62615f15125 271 */
mfiore 0:c62615f15125 272 void resetConfig();
mfiore 0:c62615f15125 273
mfiore 0:c62615f15125 274 /** Save config data to non volatile memory
mfiore 0:c62615f15125 275 * @returns true if success, false if failure
mfiore 0:c62615f15125 276 */
mfiore 0:c62615f15125 277 bool saveConfig();
mfiore 0:c62615f15125 278
mfiore 0:c62615f15125 279 /** Set the log level for the library
mfiore 0:c62615f15125 280 * options are:
mfiore 0:c62615f15125 281 * NONE_LEVEL - logging is off at this level
mfiore 0:c62615f15125 282 * FATAL_LEVEL - only critical errors will be reported
mfiore 0:c62615f15125 283 * ERROR_LEVEL
mfiore 0:c62615f15125 284 * WARNING_LEVEL
mfiore 0:c62615f15125 285 * INFO_LEVEL
mfiore 0:c62615f15125 286 * DEBUG_LEVEL
mfiore 0:c62615f15125 287 * TRACE_LEVEL - every detail will be reported
mfiore 0:c62615f15125 288 * @param level the level to log at
mfiore 0:c62615f15125 289 * @returns MDOT_OK if success
mfiore 0:c62615f15125 290 */
mfiore 0:c62615f15125 291 int32_t setLogLevel(const uint8_t& level);
mfiore 0:c62615f15125 292
mfiore 0:c62615f15125 293 /** Get the current log level for the library
mfiore 0:c62615f15125 294 * @returns current log level
mfiore 0:c62615f15125 295 */
Mike Fiore 6:390fc83d588d 296 uint8_t getLogLevel();
Mike Fiore 6:390fc83d588d 297
Mike Fiore 11:9938ba31d428 298 /** Seed pseudo RNG in LoRaMac layer, uses random value from radio RSSI reading by default
Mike Fiore 11:9938ba31d428 299 * @param seed for RNG
Mike Fiore 11:9938ba31d428 300 */
Mike Fiore 11:9938ba31d428 301 void seedRandom(uint32_t seed);
Mike Fiore 11:9938ba31d428 302
Mike Fiore 6:390fc83d588d 303 /** Enable or disable the activity LED.
Mike Fiore 6:390fc83d588d 304 * @param enable true to enable the LED, false to disable
Mike Fiore 6:390fc83d588d 305 */
Mike Fiore 6:390fc83d588d 306 void setActivityLedEnable(const bool& enable);
Mike Fiore 4:94969e981dcc 307
Mike Fiore 6:390fc83d588d 308 /** Find out if the activity LED is enabled
Mike Fiore 6:390fc83d588d 309 * @returns true if activity LED is enabled, false if disabled
Mike Fiore 6:390fc83d588d 310 */
Mike Fiore 6:390fc83d588d 311 bool getActivityLedEnable();
Mike Fiore 6:390fc83d588d 312
Mike Fiore 6:390fc83d588d 313 /** Use a different pin for the activity LED.
Mike Fiore 6:390fc83d588d 314 * The default is XBEE_RSSI.
Mike Fiore 6:390fc83d588d 315 * @param pin the new pin to use
Mike Fiore 6:390fc83d588d 316 */
Mike Fiore 6:390fc83d588d 317 void setActivityLedPin(const PinName& pin);
Mike Fiore 6:390fc83d588d 318
Mike Fiore 5:0bfe6a650513 319 /** Use an external DigitalOut object for the activity LED.
Mike Fiore 5:0bfe6a650513 320 * The pointer must stay valid!
Mike Fiore 5:0bfe6a650513 321 * @param pin the DigitalOut object to use
Mike Fiore 5:0bfe6a650513 322 */
Mike Fiore 5:0bfe6a650513 323 void setActivityLedPin(DigitalOut* pin);
Mike Fiore 6:390fc83d588d 324
Mike Fiore 6:390fc83d588d 325 /** Find out what pin the activity LED is on
Mike Fiore 6:390fc83d588d 326 * @returns the pin the activity LED is using
Mike Fiore 6:390fc83d588d 327 */
Mike Fiore 6:390fc83d588d 328 PinName getActivityLedPin();
mfiore 0:c62615f15125 329
Mike Fiore 11:9938ba31d428 330 /** Returns boolean indicative of start-up from standby mode
Mike Fiore 11:9938ba31d428 331 * @returns true if dot woke from standby
Mike Fiore 11:9938ba31d428 332 */
Mike Fiore 11:9938ba31d428 333 bool getStandbyFlag();
Mike Fiore 11:9938ba31d428 334
Mike Fiore 11:9938ba31d428 335 /** Add a channel frequencies currently in use
Mike Fiore 11:9938ba31d428 336 * @returns MDOT_OK
Mike Fiore 11:9938ba31d428 337 */
Mike Fiore 11:9938ba31d428 338 int32_t addChannel(uint8_t index, uint32_t frequency, uint8_t datarateRange);
Mike Fiore 11:9938ba31d428 339
mfiore 0:c62615f15125 340 /** Get list of channel frequencies currently in use
mfiore 0:c62615f15125 341 * @returns vector of channels currently in use
mfiore 0:c62615f15125 342 */
mfiore 0:c62615f15125 343 std::vector<uint32_t> getChannels();
mfiore 0:c62615f15125 344
Mike Fiore 11:9938ba31d428 345 /** Get list of channel datarate ranges currently in use
Mike Fiore 11:9938ba31d428 346 * @returns vector of datarate ranges currently in use
Mike Fiore 11:9938ba31d428 347 */
Mike Fiore 11:9938ba31d428 348 std::vector<uint8_t> getChannelRanges();
Mike Fiore 11:9938ba31d428 349
Mike Fiore 11:9938ba31d428 350 /** Get list of channel frequencies in config file to be used as session defaults
Mike Fiore 11:9938ba31d428 351 * @returns vector of channels in config file
Mike Fiore 11:9938ba31d428 352 */
Mike Fiore 11:9938ba31d428 353 std::vector<uint32_t> getConfigChannels();
Mike Fiore 11:9938ba31d428 354
Mike Fiore 11:9938ba31d428 355 /** Get list of channel datarate ranges in config file to be used as session defaults
Mike Fiore 11:9938ba31d428 356 * @returns vector of datarate ranges in config file
Mike Fiore 11:9938ba31d428 357 */
Mike Fiore 11:9938ba31d428 358 std::vector<uint8_t> getConfigChannelRanges();
Mike Fiore 11:9938ba31d428 359
mfiore 0:c62615f15125 360 /** Get frequency band
mfiore 0:c62615f15125 361 * @returns FB_915 if configured for United States, FB_868 if configured for Europe
mfiore 0:c62615f15125 362 */
mfiore 0:c62615f15125 363 uint8_t getFrequencyBand();
mfiore 0:c62615f15125 364
mfiore 0:c62615f15125 365 /** Set frequency sub band
mfiore 0:c62615f15125 366 * only applicable if frequency band is set for United States (FB_915)
Mike Fiore 11:9938ba31d428 367 * sub band 0 will allow the radio to use all 64 channels
mfiore 0:c62615f15125 368 * sub band 1 - 8 will allow the radio to use the 8 channels in that sub band
mfiore 0:c62615f15125 369 * for use with Conduit gateway and MTAC_LORA, use sub bands 1 - 8, not sub band 0
mfiore 0:c62615f15125 370 * @param band the sub band to use (0 - 8)
mfiore 0:c62615f15125 371 * @returns MDOT_OK if success
mfiore 0:c62615f15125 372 */
mfiore 0:c62615f15125 373 int32_t setFrequencySubBand(const uint8_t& band);
mfiore 0:c62615f15125 374
mfiore 0:c62615f15125 375 /** Get frequency sub band
mfiore 0:c62615f15125 376 * @returns frequency sub band currently in use
mfiore 0:c62615f15125 377 */
mfiore 0:c62615f15125 378 uint8_t getFrequencySubBand();
mfiore 0:c62615f15125 379
Mike Fiore 11:9938ba31d428 380 /** Get the datarate currently in use within the MAC layer
Mike Fiore 11:9938ba31d428 381 * returns 0-15
Mike Fiore 11:9938ba31d428 382 */
Mike Fiore 11:9938ba31d428 383 uint8_t getSessionDataRate();
Mike Fiore 11:9938ba31d428 384
mfiore 0:c62615f15125 385 /** Enable/disable public network mode
Mike Fiore 11:9938ba31d428 386 * JoinDelay will be set to (public: 5s, private: 1s) and
Mike Fiore 11:9938ba31d428 387 * RxDelay will be set to 1s both can be adjusted afterwards
mfiore 0:c62615f15125 388 * @param on should be true to enable public network mode
mfiore 0:c62615f15125 389 * @returns MDOT_OK if success
mfiore 0:c62615f15125 390 */
mfiore 0:c62615f15125 391 int32_t setPublicNetwork(const bool& on);
mfiore 0:c62615f15125 392
mfiore 0:c62615f15125 393 /** Get public network mode
mfiore 0:c62615f15125 394 * @returns true if public network mode is enabled
mfiore 0:c62615f15125 395 */
mfiore 0:c62615f15125 396 bool getPublicNetwork();
mfiore 0:c62615f15125 397
mfiore 0:c62615f15125 398 /** Get the device ID
mfiore 0:c62615f15125 399 * @returns vector containing the device ID (size 8)
mfiore 0:c62615f15125 400 */
mfiore 0:c62615f15125 401 std::vector<uint8_t> getDeviceId();
mfiore 0:c62615f15125 402
Mike Fiore 11:9938ba31d428 403 /** Get the device port to be used for lora application data (1-223)
Mike Fiore 11:9938ba31d428 404 * @returns port
Mike Fiore 11:9938ba31d428 405 */
Mike Fiore 11:9938ba31d428 406 uint8_t getAppPort();
Mike Fiore 11:9938ba31d428 407
Mike Fiore 11:9938ba31d428 408 /** Set the device port to be used for lora application data (1-223)
Mike Fiore 11:9938ba31d428 409 * @returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 410 */
Mike Fiore 11:9938ba31d428 411 int32_t setAppPort(uint8_t port);
Mike Fiore 11:9938ba31d428 412
Mike Fiore 11:9938ba31d428 413 /** Set the device class A, B or C
Mike Fiore 11:9938ba31d428 414 * @returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 415 */
Mike Fiore 11:9938ba31d428 416 int32_t setClass(std::string newClass);
Mike Fiore 11:9938ba31d428 417
Mike Fiore 11:9938ba31d428 418 /** Get the device class A, B or C
Mike Fiore 11:9938ba31d428 419 * @returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 420 */
Mike Fiore 11:9938ba31d428 421 std::string getClass();
Mike Fiore 11:9938ba31d428 422
Mike Fiore 11:9938ba31d428 423 /** Get the max packet length with current settings
Mike Fiore 11:9938ba31d428 424 * @returns max packet length
Mike Fiore 11:9938ba31d428 425 */
Mike Fiore 11:9938ba31d428 426 uint8_t getMaxPacketLength();
Mike Fiore 11:9938ba31d428 427
mfiore 0:c62615f15125 428 /** Set network address
mfiore 0:c62615f15125 429 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
mfiore 0:c62615f15125 430 * @param addr a vector of 4 bytes
mfiore 0:c62615f15125 431 * @returns MDOT_OK if success
mfiore 0:c62615f15125 432 */
mfiore 0:c62615f15125 433 int32_t setNetworkAddress(const std::vector<uint8_t>& addr);
mfiore 0:c62615f15125 434
mfiore 0:c62615f15125 435 /** Get network address
mfiore 0:c62615f15125 436 * @returns vector containing network address (size 4)
mfiore 0:c62615f15125 437 */
mfiore 0:c62615f15125 438 std::vector<uint8_t> getNetworkAddress();
mfiore 0:c62615f15125 439
mfiore 0:c62615f15125 440 /** Set network session key
mfiore 0:c62615f15125 441 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
mfiore 0:c62615f15125 442 * @param key a vector of 16 bytes
mfiore 0:c62615f15125 443 * @returns MDOT_OK if success
mfiore 0:c62615f15125 444 */
mfiore 0:c62615f15125 445 int32_t setNetworkSessionKey(const std::vector<uint8_t>& key);
mfiore 0:c62615f15125 446
mfiore 0:c62615f15125 447 /** Get network session key
mfiore 0:c62615f15125 448 * @returns vector containing network session key (size 16)
mfiore 0:c62615f15125 449 */
mfiore 0:c62615f15125 450 std::vector<uint8_t> getNetworkSessionKey();
mfiore 0:c62615f15125 451
mfiore 0:c62615f15125 452 /** Set data session key
mfiore 0:c62615f15125 453 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes
mfiore 0:c62615f15125 454 * @param key a vector of 16 bytes
mfiore 0:c62615f15125 455 * @returns MDOT_OK if success
mfiore 0:c62615f15125 456 */
mfiore 0:c62615f15125 457 int32_t setDataSessionKey(const std::vector<uint8_t>& key);
mfiore 0:c62615f15125 458
mfiore 0:c62615f15125 459 /** Get data session key
mfiore 0:c62615f15125 460 * @returns vector containing data session key (size 16)
mfiore 0:c62615f15125 461 */
mfiore 0:c62615f15125 462 std::vector<uint8_t> getDataSessionKey();
mfiore 0:c62615f15125 463
mfiore 0:c62615f15125 464 /** Set network name
mfiore 0:c62615f15125 465 * for use with OTA & AUTO_OTA network join modes
mfiore 0:c62615f15125 466 * generates network ID (crc64 of name) automatically
mfiore 0:c62615f15125 467 * @param name a string of of at least 8 bytes and no more than 128 bytes
mfiore 0:c62615f15125 468 * @return MDOT_OK if success
mfiore 0:c62615f15125 469 */
mfiore 0:c62615f15125 470 int32_t setNetworkName(const std::string& name);
mfiore 0:c62615f15125 471
mfiore 0:c62615f15125 472 /** Get network name
mfiore 0:c62615f15125 473 * @return string containing network name (size 8 to 128)
mfiore 0:c62615f15125 474 */
mfiore 0:c62615f15125 475 std::string getNetworkName();
mfiore 0:c62615f15125 476
mfiore 0:c62615f15125 477 /** Set network ID
mfiore 0:c62615f15125 478 * for use with OTA & AUTO_OTA network join modes
mfiore 0:c62615f15125 479 * setting network ID via this function sets network name to empty
mfiore 0:c62615f15125 480 * @param id a vector of 8 bytes
mfiore 0:c62615f15125 481 * @returns MDOT_OK if success
mfiore 0:c62615f15125 482 */
mfiore 0:c62615f15125 483 int32_t setNetworkId(const std::vector<uint8_t>& id);
mfiore 0:c62615f15125 484
mfiore 0:c62615f15125 485 /** Get network ID
mfiore 0:c62615f15125 486 * @returns vector containing network ID (size 8)
mfiore 0:c62615f15125 487 */
mfiore 0:c62615f15125 488 std::vector<uint8_t> getNetworkId();
mfiore 0:c62615f15125 489
mfiore 0:c62615f15125 490 /** Set network passphrase
mfiore 0:c62615f15125 491 * for use with OTA & AUTO_OTA network join modes
mfiore 0:c62615f15125 492 * generates network key (cmac of passphrase) automatically
mfiore 0:c62615f15125 493 * @param name a string of of at least 8 bytes and no more than 128 bytes
mfiore 0:c62615f15125 494 * @return MDOT_OK if success
mfiore 0:c62615f15125 495 */
mfiore 0:c62615f15125 496 int32_t setNetworkPassphrase(const std::string& passphrase);
mfiore 0:c62615f15125 497
mfiore 0:c62615f15125 498 /** Get network passphrase
mfiore 0:c62615f15125 499 * @return string containing network passphrase (size 8 to 128)
mfiore 0:c62615f15125 500 */
mfiore 0:c62615f15125 501 std::string getNetworkPassphrase();
mfiore 0:c62615f15125 502
mfiore 0:c62615f15125 503 /** Set network key
mfiore 0:c62615f15125 504 * for use with OTA & AUTO_OTA network join modes
mfiore 0:c62615f15125 505 * setting network key via this function sets network passphrase to empty
mfiore 0:c62615f15125 506 * @param id a vector of 16 bytes
mfiore 0:c62615f15125 507 * @returns MDOT_OK if success
mfiore 0:c62615f15125 508 */
mfiore 0:c62615f15125 509 int32_t setNetworkKey(const std::vector<uint8_t>& id);
mfiore 0:c62615f15125 510
mfiore 0:c62615f15125 511 /** Get network key
mfiore 0:c62615f15125 512 * @returns a vector containing network key (size 16)
mfiore 0:c62615f15125 513 */
mfiore 0:c62615f15125 514 std::vector<uint8_t> getNetworkKey();
mfiore 0:c62615f15125 515
Mike Fiore 6:390fc83d588d 516 /** Set join byte order
Mike Fiore 6:390fc83d588d 517 * @param order 0:LSB 1:MSB
Mike Fiore 6:390fc83d588d 518 */
Mike Fiore 6:390fc83d588d 519 uint32_t setJoinByteOrder(uint8_t order);
Mike Fiore 6:390fc83d588d 520
Mike Fiore 6:390fc83d588d 521 /** Get join byte order
Mike Fiore 6:390fc83d588d 522 * @returns byte order to use in joins 0:LSB 1:MSB
Mike Fiore 6:390fc83d588d 523 */
Mike Fiore 6:390fc83d588d 524 uint8_t getJoinByteOrder();
Mike Fiore 6:390fc83d588d 525
mfiore 0:c62615f15125 526 /** Attempt to join network
Mike Fiore 11:9938ba31d428 527 * each attempt will be made with a random datarate up to the configured datarate
Mike Fiore 11:9938ba31d428 528 * JoinRequest backoff between tries is enforced to 1% for 1st hour, 0.1% for 1-10 hours and 0.01% after 10 hours
Mike Fiore 11:9938ba31d428 529 * Check getNextTxMs() for time until next join attempt can be made
mfiore 0:c62615f15125 530 * @returns MDOT_OK if success
mfiore 0:c62615f15125 531 */
mfiore 0:c62615f15125 532 int32_t joinNetwork();
mfiore 0:c62615f15125 533
mfiore 0:c62615f15125 534 /** Attempts to join network once
mfiore 0:c62615f15125 535 * @returns MDOT_OK if success
mfiore 0:c62615f15125 536 */
mfiore 0:c62615f15125 537 int32_t joinNetworkOnce();
mfiore 0:c62615f15125 538
mfiore 0:c62615f15125 539 /** Resets current network session, essentially disconnecting from the network
mfiore 0:c62615f15125 540 * has no effect for MANUAL network join mode
mfiore 0:c62615f15125 541 */
mfiore 0:c62615f15125 542 void resetNetworkSession();
mfiore 0:c62615f15125 543
Mike Fiore 11:9938ba31d428 544 /** Restore saved network session from flash
Mike Fiore 11:9938ba31d428 545 * has no effect for MANUAL network join mode
Mike Fiore 11:9938ba31d428 546 */
Mike Fiore 11:9938ba31d428 547 void restoreNetworkSession();
Mike Fiore 11:9938ba31d428 548
Mike Fiore 11:9938ba31d428 549 /** Save current network session to flash
Mike Fiore 11:9938ba31d428 550 * has no effect for MANUAL network join mode
Mike Fiore 11:9938ba31d428 551 */
Mike Fiore 11:9938ba31d428 552 void saveNetworkSession();
Mike Fiore 11:9938ba31d428 553
mfiore 0:c62615f15125 554 /** Set number of times joining will retry before giving up
mfiore 0:c62615f15125 555 * @param retries must be between 0 - 255
mfiore 0:c62615f15125 556 * @returns MDOT_OK if success
mfiore 0:c62615f15125 557 */
mfiore 0:c62615f15125 558 int32_t setJoinRetries(const uint8_t& retries);
mfiore 0:c62615f15125 559
mfiore 0:c62615f15125 560 /** Set number of times joining will retry before giving up
mfiore 0:c62615f15125 561 * @returns join retries (0 - 255)
mfiore 0:c62615f15125 562 */
mfiore 0:c62615f15125 563 uint8_t getJoinRetries();
mfiore 0:c62615f15125 564
mfiore 0:c62615f15125 565 /** Set network join mode
mfiore 0:c62615f15125 566 * MANUAL: set network address and session keys manually
mfiore 0:c62615f15125 567 * OTA: User sets network name and passphrase, then attempts to join
mfiore 0:c62615f15125 568 * AUTO_OTA: same as OTA, but network sessions can be saved and restored
mfiore 0:c62615f15125 569 * @param mode MANUAL, OTA, or AUTO_OTA
mfiore 0:c62615f15125 570 * @returns MDOT_OK if success
mfiore 0:c62615f15125 571 */
mfiore 0:c62615f15125 572 int32_t setJoinMode(const uint8_t& mode);
mfiore 0:c62615f15125 573
mfiore 0:c62615f15125 574 /** Get network join mode
mfiore 0:c62615f15125 575 * @returns MANUAL, OTA, or AUTO_OTA
mfiore 0:c62615f15125 576 */
mfiore 0:c62615f15125 577 uint8_t getJoinMode();
mfiore 0:c62615f15125 578
mfiore 0:c62615f15125 579 /** Get network join status
mfiore 0:c62615f15125 580 * @returns true if currently joined to network
mfiore 0:c62615f15125 581 */
mfiore 0:c62615f15125 582 bool getNetworkJoinStatus();
mfiore 0:c62615f15125 583
mfiore 0:c62615f15125 584 /** Do a network link check
mfiore 0:c62615f15125 585 * application data may be returned in response to a network link check command
mfiore 0:c62615f15125 586 * @returns link_check structure containing success, dBm above noise floor, gateways in range, and packet payload
mfiore 0:c62615f15125 587 */
mfiore 0:c62615f15125 588 link_check networkLinkCheck();
mfiore 0:c62615f15125 589
mfiore 0:c62615f15125 590 /** Set network link check count to perform automatic link checks every count packets
mfiore 0:c62615f15125 591 * only applicable if ACKs are disabled
mfiore 0:c62615f15125 592 * @param count must be between 0 - 255
mfiore 0:c62615f15125 593 * @returns MDOT_OK if success
mfiore 0:c62615f15125 594 */
mfiore 0:c62615f15125 595 int32_t setLinkCheckCount(const uint8_t& count);
mfiore 0:c62615f15125 596
mfiore 0:c62615f15125 597 /** Get network link check count
mfiore 0:c62615f15125 598 * @returns count (0 - 255)
mfiore 0:c62615f15125 599 */
mfiore 0:c62615f15125 600 uint8_t getLinkCheckCount();
mfiore 0:c62615f15125 601
mfiore 0:c62615f15125 602 /** Set network link check threshold, number of link check failures or missed acks to tolerate
mfiore 0:c62615f15125 603 * before considering network connection lost
mfiore 0:c62615f15125 604 * @pararm count must be between 0 - 255
mfiore 0:c62615f15125 605 * @returns MDOT_OK if success
mfiore 0:c62615f15125 606 */
mfiore 0:c62615f15125 607 int32_t setLinkCheckThreshold(const uint8_t& count);
mfiore 0:c62615f15125 608
mfiore 0:c62615f15125 609 /** Get network link check threshold
mfiore 0:c62615f15125 610 * @returns threshold (0 - 255)
mfiore 0:c62615f15125 611 */
mfiore 0:c62615f15125 612 uint8_t getLinkCheckThreshold();
mfiore 0:c62615f15125 613
Mike Fiore 11:9938ba31d428 614 /** Get/set number of failed link checks in the current session
Mike Fiore 11:9938ba31d428 615 * @returns count (0 - 255)
Mike Fiore 11:9938ba31d428 616 */
Mike Fiore 11:9938ba31d428 617 uint8_t getLinkFailCount();
Mike Fiore 11:9938ba31d428 618 int32_t setLinkFailCount(uint8_t count);
Mike Fiore 11:9938ba31d428 619
Mike Fiore 11:9938ba31d428 620 /** Set UpLinkCounter number of packets sent to the gateway during this network session (sequence number)
Mike Fiore 11:9938ba31d428 621 * @returns MDOT_OK
Mike Fiore 11:9938ba31d428 622 */
Mike Fiore 11:9938ba31d428 623 int32_t setUpLinkCounter(uint32_t count);
Mike Fiore 11:9938ba31d428 624
mfiore 0:c62615f15125 625 /** Get UpLinkCounter
mfiore 0:c62615f15125 626 * @returns number of packets sent to the gateway during this network session (sequence number)
mfiore 0:c62615f15125 627 */
mfiore 0:c62615f15125 628 uint32_t getUpLinkCounter();
mfiore 0:c62615f15125 629
Mike Fiore 11:9938ba31d428 630 /** Set UpLinkCounter number of packets sent by the gateway during this network session (sequence number)
Mike Fiore 11:9938ba31d428 631 * @returns MDOT_OK
Mike Fiore 11:9938ba31d428 632 */
Mike Fiore 11:9938ba31d428 633 int32_t setDownLinkCounter(uint32_t count);
Mike Fiore 11:9938ba31d428 634
Mike Fiore 11:9938ba31d428 635 /** Get DownLinkCounter
Mike Fiore 11:9938ba31d428 636 * @returns number of packets sent by the gateway during this network session (sequence number)
Mike Fiore 11:9938ba31d428 637 */
Mike Fiore 11:9938ba31d428 638 uint32_t getDownLinkCounter();
Mike Fiore 11:9938ba31d428 639
mfiore 0:c62615f15125 640 /** Enable/disable AES encryption
mfiore 0:c62615f15125 641 * AES encryption must be enabled for use with Conduit gateway and MTAC_LORA card
mfiore 0:c62615f15125 642 * @param on true for AES encryption to be enabled
mfiore 0:c62615f15125 643 * @returns MDOT_OK if success
mfiore 0:c62615f15125 644 */
mfiore 0:c62615f15125 645 int32_t setAesEncryption(const bool& on);
mfiore 0:c62615f15125 646
mfiore 0:c62615f15125 647 /** Get AES encryption
mfiore 0:c62615f15125 648 * @returns true if AES encryption is enabled
mfiore 0:c62615f15125 649 */
mfiore 0:c62615f15125 650 bool getAesEncryption();
mfiore 0:c62615f15125 651
mfiore 0:c62615f15125 652 /** Get RSSI stats
Mike Fiore 11:9938ba31d428 653 * @returns rssi_stats struct containing last, min, max, and avg RSSI in dB
mfiore 0:c62615f15125 654 */
mfiore 0:c62615f15125 655 rssi_stats getRssiStats();
mfiore 0:c62615f15125 656
mfiore 0:c62615f15125 657 /** Get SNR stats
Mike Fiore 11:9938ba31d428 658 * @returns snr_stats struct containing last, min, max, and avg SNR in cB
mfiore 0:c62615f15125 659 */
mfiore 0:c62615f15125 660 snr_stats getSnrStats();
mfiore 0:c62615f15125 661
mfiore 0:c62615f15125 662 /** Get ms until next free channel
mfiore 0:c62615f15125 663 * only applicable for European models, US models return 0
mfiore 0:c62615f15125 664 * @returns time (ms) until a channel is free to use for transmitting
mfiore 0:c62615f15125 665 */
mfiore 0:c62615f15125 666 uint32_t getNextTxMs();
mfiore 0:c62615f15125 667
Mike Fiore 11:9938ba31d428 668 /** Get join delay in seconds
Mike Fiore 11:9938ba31d428 669 * Public network defaults to 5 seconds
Mike Fiore 11:9938ba31d428 670 * Private network defaults to 1 second
Mike Fiore 11:9938ba31d428 671 * @returns number of seconds before join accept message is expected
Mike Fiore 11:9938ba31d428 672 */
Mike Fiore 11:9938ba31d428 673 uint8_t getJoinDelay();
Mike Fiore 11:9938ba31d428 674
Mike Fiore 11:9938ba31d428 675 /** Set join delay in seconds
Mike Fiore 11:9938ba31d428 676 * Public network defaults to 5 seconds
Mike Fiore 11:9938ba31d428 677 * Private network defaults to 1 second
Mike Fiore 11:9938ba31d428 678 * @param delay number of seconds before join accept message is expected
Mike Fiore 11:9938ba31d428 679 * @return MDOT_OK if success
Mike Fiore 11:9938ba31d428 680 */
Mike Fiore 11:9938ba31d428 681 uint32_t setJoinDelay(uint8_t delay);
Mike Fiore 11:9938ba31d428 682
Mike Fiore 11:9938ba31d428 683 /** Get rx delay in seconds
Mike Fiore 11:9938ba31d428 684 * Defaults to 1 second
Mike Fiore 11:9938ba31d428 685 * @returns number of seconds before response message is expected
Mike Fiore 11:9938ba31d428 686 */
Mike Fiore 11:9938ba31d428 687 uint8_t getRxDelay();
Mike Fiore 11:9938ba31d428 688
Mike Fiore 11:9938ba31d428 689 /** Set rx delay in seconds
Mike Fiore 11:9938ba31d428 690 * Defaults to 1 second
Mike Fiore 11:9938ba31d428 691 * @param delay number of seconds before response message is expected
Mike Fiore 11:9938ba31d428 692 * @return MDOT_OK if success
Mike Fiore 11:9938ba31d428 693 */
Mike Fiore 11:9938ba31d428 694 uint32_t setRxDelay(uint8_t delay);
Mike Fiore 11:9938ba31d428 695
Mike Fiore 11:9938ba31d428 696 /** Get preserve session to save network session info through reset or power down in AUTO_OTA mode
Mike Fiore 11:9938ba31d428 697 * Defaults to off
Mike Fiore 11:9938ba31d428 698 * @returns true if enabled
Mike Fiore 11:9938ba31d428 699 */
Mike Fiore 11:9938ba31d428 700 bool getPreserveSession();
Mike Fiore 11:9938ba31d428 701
Mike Fiore 11:9938ba31d428 702 /** Set preserve session to save network session info through reset or power down in AUTO_OTA mode
Mike Fiore 11:9938ba31d428 703 * Defaults to off
Mike Fiore 11:9938ba31d428 704 * @param enable
Mike Fiore 11:9938ba31d428 705 * @return MDOT_OK if success
Mike Fiore 11:9938ba31d428 706 */
Mike Fiore 11:9938ba31d428 707 uint32_t setPreserveSession(bool enable);
Mike Fiore 11:9938ba31d428 708
mfiore 0:c62615f15125 709 /** Get data pending
mfiore 0:c62615f15125 710 * only valid after sending data to the gateway
mfiore 0:c62615f15125 711 * @returns true if server has available packet(s)
mfiore 0:c62615f15125 712 */
mfiore 0:c62615f15125 713 bool getDataPending();
mfiore 0:c62615f15125 714
Mike Fiore 11:9938ba31d428 715 /** Get transmitting
mfiore 0:c62615f15125 716 * @returns true if currently transmitting
mfiore 0:c62615f15125 717 */
mfiore 0:c62615f15125 718 bool getIsTransmitting();
mfiore 0:c62615f15125 719
mfiore 0:c62615f15125 720 /** Set TX data rate
mfiore 0:c62615f15125 721 * data rates affect maximum payload size
Mike Fiore 11:9938ba31d428 722 * @param dr SF_7 - SF_12|DR0-DR7 for Europe, SF_7 - SF_10 | DR0-DR4 for United States
mfiore 0:c62615f15125 723 * @returns MDOT_OK if success
mfiore 0:c62615f15125 724 */
mfiore 0:c62615f15125 725 int32_t setTxDataRate(const uint8_t& dr);
mfiore 0:c62615f15125 726
mfiore 0:c62615f15125 727 /** Get TX data rate
Mike Fiore 11:9938ba31d428 728 * @returns current TX data rate (DR0-DR15)
mfiore 0:c62615f15125 729 */
mfiore 0:c62615f15125 730 uint8_t getTxDataRate();
mfiore 0:c62615f15125 731
Mike Fiore 11:9938ba31d428 732 /** Get a random value from the radio based on RSSI
Mike Fiore 11:9938ba31d428 733 * @returns randome value
Mike Fiore 11:9938ba31d428 734 */
Mike Fiore 11:9938ba31d428 735 uint32_t getRadioRandom();
Mike Fiore 11:9938ba31d428 736
Mike Fiore 11:9938ba31d428 737
Mike Fiore 11:9938ba31d428 738 /** Get data rate spreading factor and bandwidth
Mike Fiore 11:9938ba31d428 739 * EU868 Datarates
Mike Fiore 11:9938ba31d428 740 * ---------------
Mike Fiore 11:9938ba31d428 741 * DR0 - SF12BW125
Mike Fiore 11:9938ba31d428 742 * DR1 - SF11BW125
Mike Fiore 11:9938ba31d428 743 * DR2 - SF10BW125
Mike Fiore 11:9938ba31d428 744 * DR3 - SF9BW125
Mike Fiore 11:9938ba31d428 745 * DR4 - SF8BW125
Mike Fiore 11:9938ba31d428 746 * DR5 - SF7BW125
Mike Fiore 11:9938ba31d428 747 * DR6 - SF7BW250
Mike Fiore 11:9938ba31d428 748 * DR7 - FSK
Mike Fiore 11:9938ba31d428 749 *
Mike Fiore 11:9938ba31d428 750 * US915 Datarates
Mike Fiore 11:9938ba31d428 751 * ---------------
Mike Fiore 11:9938ba31d428 752 * DR0 - SF10BW125
Mike Fiore 11:9938ba31d428 753 * DR1 - SF9BW125
Mike Fiore 11:9938ba31d428 754 * DR2 - SF8BW125
Mike Fiore 11:9938ba31d428 755 * DR3 - SF7BW125
Mike Fiore 11:9938ba31d428 756 * DR4 - SF8BW500
Mike Fiore 11:9938ba31d428 757 *
Mike Fiore 11:9938ba31d428 758 * @returns spreading factor and bandwidth
Mike Fiore 11:9938ba31d428 759 */
Mike Fiore 11:9938ba31d428 760 std::string getDateRateDetails(uint8_t rate);
Mike Fiore 11:9938ba31d428 761
Mike Fiore 11:9938ba31d428 762 /** Set TX power output of radio before antenna gain, default: 14 dBm
Mike Fiore 11:9938ba31d428 763 * actual output power may be limited by local regulations for the chosen frequency
mfiore 0:c62615f15125 764 * power affects maximum range
mfiore 0:c62615f15125 765 * @param power 2 dBm - 20 dBm
mfiore 0:c62615f15125 766 * @returns MDOT_OK if success
mfiore 0:c62615f15125 767 */
mfiore 0:c62615f15125 768 int32_t setTxPower(const uint32_t& power);
mfiore 0:c62615f15125 769
mfiore 0:c62615f15125 770 /** Get TX power
mfiore 0:c62615f15125 771 * @returns TX power (2 dBm - 20 dBm)
mfiore 0:c62615f15125 772 */
mfiore 0:c62615f15125 773 uint32_t getTxPower();
mfiore 0:c62615f15125 774
Mike Fiore 11:9938ba31d428 775 /** Get configured gain of installed antenna, default: +3 dBi
Mike Fiore 11:9938ba31d428 776 * @returns gain of antenna in dBi
Mike Fiore 11:9938ba31d428 777 */
Mike Fiore 11:9938ba31d428 778 int8_t getAntennaGain();
Mike Fiore 11:9938ba31d428 779
Mike Fiore 11:9938ba31d428 780 /** Set configured gain of installed antenna, default: +3 dBi
Mike Fiore 11:9938ba31d428 781 * @param gain -127 dBi - 128 dBi
Mike Fiore 11:9938ba31d428 782 * @returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 783 */
Mike Fiore 11:9938ba31d428 784 int32_t setAntennaGain(int8_t gain);
Mike Fiore 11:9938ba31d428 785
mfiore 0:c62615f15125 786 /** Enable/disable TX waiting for rx windows
mfiore 0:c62615f15125 787 * when enabled, send calls will block until a packet is received or RX timeout
mfiore 0:c62615f15125 788 * @param enable set to true if expecting responses to transmitted packets
mfiore 0:c62615f15125 789 * @returns MDOT_OK if success
mfiore 0:c62615f15125 790 */
mfiore 0:c62615f15125 791 int32_t setTxWait(const bool& enable);
mfiore 0:c62615f15125 792
mfiore 0:c62615f15125 793 /** Get TX wait
mfiore 0:c62615f15125 794 * @returns true if TX wait is enabled
mfiore 0:c62615f15125 795 */
mfiore 0:c62615f15125 796 bool getTxWait();
mfiore 0:c62615f15125 797
mfiore 0:c62615f15125 798 /** Get time on air
mfiore 0:c62615f15125 799 * @returns the amount of time (in ms) it would take to send bytes bytes based on current configuration
mfiore 0:c62615f15125 800 */
mfiore 0:c62615f15125 801 uint32_t getTimeOnAir(uint8_t bytes);
mfiore 0:c62615f15125 802
mfiore 0:c62615f15125 803 /** Get min frequency
mfiore 0:c62615f15125 804 * @returns minimum frequency based on current configuration
mfiore 0:c62615f15125 805 */
mfiore 0:c62615f15125 806 uint32_t getMinFrequency();
mfiore 0:c62615f15125 807
mfiore 0:c62615f15125 808 /** Get max frequency
mfiore 0:c62615f15125 809 * @returns maximum frequency based on current configuration
mfiore 0:c62615f15125 810 */
mfiore 0:c62615f15125 811 uint32_t getMaxFrequency();
mfiore 0:c62615f15125 812
Mike Fiore 11:9938ba31d428 813 // get/set adaptive data rate
Mike Fiore 11:9938ba31d428 814 // configure data rates and power levels based on signal to noise of packets received at gateway
Mike Fiore 11:9938ba31d428 815 // true == adaptive data rate is on
Mike Fiore 11:9938ba31d428 816 // set function returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 817 int32_t setAdr(const bool& on);
Mike Fiore 11:9938ba31d428 818 bool getAdr();
Mike Fiore 11:9938ba31d428 819
mfiore 0:c62615f15125 820 /** Set forward error correction bytes
mfiore 0:c62615f15125 821 * @param bytes 1 - 4 bytes
mfiore 0:c62615f15125 822 * @returns MDOT_OK if success
mfiore 0:c62615f15125 823 */
mfiore 0:c62615f15125 824 int32_t setFec(const uint8_t& bytes);
mfiore 0:c62615f15125 825
mfiore 0:c62615f15125 826 /** Get forward error correction bytes
mfiore 0:c62615f15125 827 * @returns bytes (1 - 4)
mfiore 0:c62615f15125 828 */
mfiore 0:c62615f15125 829 uint8_t getFec();
mfiore 0:c62615f15125 830
mfiore 0:c62615f15125 831 /** Enable/disable CRC checking of packets
mfiore 0:c62615f15125 832 * CRC checking must be enabled for use with Conduit gateway and MTAC_LORA card
mfiore 0:c62615f15125 833 * @param on set to true to enable CRC checking
mfiore 0:c62615f15125 834 * @returns MDOT_OK if success
mfiore 0:c62615f15125 835 */
mfiore 0:c62615f15125 836 int32_t setCrc(const bool& on);
mfiore 0:c62615f15125 837
mfiore 0:c62615f15125 838 /** Get CRC checking
mfiore 0:c62615f15125 839 * @returns true if CRC checking is enabled
mfiore 0:c62615f15125 840 */
mfiore 0:c62615f15125 841 bool getCrc();
mfiore 0:c62615f15125 842
mfiore 0:c62615f15125 843 /** Set ack
mfiore 0:c62615f15125 844 * @param retries 0 to disable acks, otherwise 1 - 8
mfiore 0:c62615f15125 845 * @returns MDOT_OK if success
mfiore 0:c62615f15125 846 */
mfiore 0:c62615f15125 847 int32_t setAck(const uint8_t& retries);
mfiore 0:c62615f15125 848
mfiore 0:c62615f15125 849 /** Get ack
mfiore 0:c62615f15125 850 * @returns 0 if acks are disabled, otherwise retries (1 - 8)
mfiore 0:c62615f15125 851 */
mfiore 0:c62615f15125 852 uint8_t getAck();
mfiore 0:c62615f15125 853
Mike Fiore 11:9938ba31d428 854 /** Set number of packet repeats for unconfirmed frames
Mike Fiore 11:9938ba31d428 855 * @param repeat 0 or 1 for no repeats, otherwise 2-15
Mike Fiore 11:9938ba31d428 856 * @returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 857 */
Mike Fiore 11:9938ba31d428 858 int32_t setRepeat(const uint8_t& repeat);
Mike Fiore 11:9938ba31d428 859
Mike Fiore 11:9938ba31d428 860 /** Get number of packet repeats for unconfirmed frames
Mike Fiore 11:9938ba31d428 861 * @returns 0 or 1 if no repeats, otherwise 2-15
Mike Fiore 11:9938ba31d428 862 */
Mike Fiore 11:9938ba31d428 863 uint8_t getRepeat();
Mike Fiore 11:9938ba31d428 864
mfiore 0:c62615f15125 865 /** Send data to the gateway
mfiore 0:c62615f15125 866 * validates data size (based on spreading factor)
mfiore 0:c62615f15125 867 * @param data a vector of up to 242 bytes (may be less based on spreading factor)
mfiore 0:c62615f15125 868 * @returns MDOT_OK if packet was sent successfully (ACKs disabled), or if an ACK was received (ACKs enabled)
mfiore 0:c62615f15125 869 */
mfiore 0:c62615f15125 870 int32_t send(const std::vector<uint8_t>& data, const bool& blocking = true, const bool& highBw = false);
mfiore 0:c62615f15125 871
mfiore 0:c62615f15125 872 /** Fetch data received from the gateway
mfiore 0:c62615f15125 873 * this function only checks to see if a packet has been received - it does not open a receive window
mfiore 0:c62615f15125 874 * send() must be called before recv()
mfiore 0:c62615f15125 875 * @param data a vector to put the received data into
mfiore 0:c62615f15125 876 * @returns MDOT_OK if packet was successfully received
mfiore 0:c62615f15125 877 */
mfiore 0:c62615f15125 878 int32_t recv(std::vector<uint8_t>& data);
mfiore 0:c62615f15125 879
mfiore 0:c62615f15125 880 /** Ping
mfiore 0:c62615f15125 881 * status will be MDOT_OK if ping succeeded
mfiore 0:c62615f15125 882 * @returns ping_response struct containing status, RSSI, and SNR
mfiore 0:c62615f15125 883 */
mfiore 0:c62615f15125 884 ping_response ping();
mfiore 0:c62615f15125 885
mfiore 0:c62615f15125 886 /** Get return code string
mfiore 0:c62615f15125 887 * @returns string containing a description of the given error code
mfiore 0:c62615f15125 888 */
mfiore 0:c62615f15125 889 static std::string getReturnCodeString(const int32_t& code);
mfiore 0:c62615f15125 890
mfiore 0:c62615f15125 891 /** Get last error
mfiore 0:c62615f15125 892 * @returns string explaining the last error that occured
mfiore 0:c62615f15125 893 */
mfiore 0:c62615f15125 894 std::string getLastError();
mfiore 0:c62615f15125 895
Mike Fiore 7:683dba5d576f 896 /** Go to sleep
Mike Fiore 11:9938ba31d428 897 * @param interval the number of seconds to sleep before waking up if wakeup_mode == RTC_ALARM or RTC_ALARM_OR_INTERRUPT, else ignored
Mike Fiore 11:9938ba31d428 898 * @param wakeup_mode RTC_ALARM, INTERRUPT, RTC_ALARM_OR_INTERRUPT
Mike Fiore 7:683dba5d576f 899 * if RTC_ALARM the real time clock is configured to wake the device up after the specified interval
Mike Fiore 7:683dba5d576f 900 * if INTERRUPT the device will wake up on the rising edge of the interrupt pin
Mike Fiore 11:9938ba31d428 901 * if RTC_ALARM_OR_INTERRUPT the device will wake on the first event to occur
Mike Fiore 7:683dba5d576f 902 * @param deepsleep if true go into deep sleep mode (lowest power, all memory and registers are lost, peripherals turned off)
Mike Fiore 7:683dba5d576f 903 * else go into sleep mode (low power, memory and registers are maintained, peripherals stay on)
Mike Fiore 7:683dba5d576f 904 *
Mike Fiore 11:9938ba31d428 905 * in sleep mode, the device can be woken up on an XBEE_DI (2-8) pin or by the RTC alarm
Mike Fiore 7:683dba5d576f 906 * in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, XBEE_DIO7) or by the RTC alarm
Mike Fiore 7:683dba5d576f 907 */
Mike Fiore 7:683dba5d576f 908 void sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
Mike Fiore 7:683dba5d576f 909
Mike Fiore 7:683dba5d576f 910 /** Set wake pin
Mike Fiore 11:9938ba31d428 911 * @param pin the pin to use to wake the device from sleep mode XBEE_DI (2-8)
Mike Fiore 7:683dba5d576f 912 */
Mike Fiore 7:683dba5d576f 913 void setWakePin(const PinName& pin);
Mike Fiore 7:683dba5d576f 914
Mike Fiore 7:683dba5d576f 915 /** Get wake pin
Mike Fiore 11:9938ba31d428 916 * @returns the pin to use to wake the device from sleep mode XBEE_DI (2-8)
Mike Fiore 7:683dba5d576f 917 */
Mike Fiore 7:683dba5d576f 918 PinName getWakePin();
Mike Fiore 7:683dba5d576f 919
Mike Fiore 11:9938ba31d428 920 /** Write data in a user backup register
Mike Fiore 11:9938ba31d428 921 * @param register one of UBR0 through UBR9
Mike Fiore 11:9938ba31d428 922 * @param data user data to back up
Mike Fiore 11:9938ba31d428 923 * @returns true if success
Mike Fiore 11:9938ba31d428 924 */
Mike Fiore 11:9938ba31d428 925 bool writeUserBackupRegister(uint32_t reg, uint32_t data);
Mike Fiore 11:9938ba31d428 926
Mike Fiore 11:9938ba31d428 927 /** Read data in a user backup register
Mike Fiore 11:9938ba31d428 928 * @param register one of UBR0 through UBR9
Mike Fiore 11:9938ba31d428 929 * @param data gets set to content of register
Mike Fiore 11:9938ba31d428 930 * @returns true if success
Mike Fiore 11:9938ba31d428 931 */
Mike Fiore 11:9938ba31d428 932 bool readUserBackupRegister(uint32_t reg, uint32_t& data);
Mike Fiore 11:9938ba31d428 933
Mike Fiore 11:9938ba31d428 934 // Save user file data to flash
Mike Fiore 11:9938ba31d428 935 // file - name of file max 30 chars
Mike Fiore 11:9938ba31d428 936 // data - data of file
Mike Fiore 11:9938ba31d428 937 // size - size of file
Mike Fiore 11:9938ba31d428 938 bool saveUserFile(const char* file, void* data, uint32_t size);
Mike Fiore 11:9938ba31d428 939
Mike Fiore 11:9938ba31d428 940 // Append user file data to flash
Mike Fiore 11:9938ba31d428 941 // file - name of file max 30 chars
Mike Fiore 11:9938ba31d428 942 // data - data of file
Mike Fiore 11:9938ba31d428 943 // size - size of file
Mike Fiore 11:9938ba31d428 944 bool appendUserFile(const char* file, void* data, uint32_t size);
Mike Fiore 11:9938ba31d428 945
Mike Fiore 11:9938ba31d428 946 // Read user file data from flash
Mike Fiore 11:9938ba31d428 947 // file - name of file max 30 chars
Mike Fiore 11:9938ba31d428 948 // data - data of file
Mike Fiore 11:9938ba31d428 949 // size - size of file
Mike Fiore 11:9938ba31d428 950 bool readUserFile(const char* file, void* data, uint32_t size);
Mike Fiore 11:9938ba31d428 951
Mike Fiore 11:9938ba31d428 952 // Move a user file in flash
Mike Fiore 11:9938ba31d428 953 // file - name of file
Mike Fiore 11:9938ba31d428 954 // new_name - new name of file
Mike Fiore 11:9938ba31d428 955 bool moveUserFile(const char* file, const char* new_name);
Mike Fiore 11:9938ba31d428 956
Mike Fiore 11:9938ba31d428 957 // Delete user file data from flash
Mike Fiore 11:9938ba31d428 958 // file - name of file max 30 chars
Mike Fiore 11:9938ba31d428 959 bool deleteUserFile(const char* file);
Mike Fiore 11:9938ba31d428 960
Mike Fiore 11:9938ba31d428 961 // Open user file in flash, max of 4 files open concurrently
Mike Fiore 11:9938ba31d428 962 // file - name of file max 30 chars
Mike Fiore 11:9938ba31d428 963 // mode - combination of FM_APPEND | FM_TRUNC | FM_CREAT |
Mike Fiore 11:9938ba31d428 964 // FM_RDONLY | FM_WRONLY | FM_RDWR | FM_DIRECT
Mike Fiore 11:9938ba31d428 965 // returns - mdot_file struct, fd field will be a negative value if file could not be opened
Mike Fiore 11:9938ba31d428 966 mDot::mdot_file openUserFile(const char* file, int mode);
Mike Fiore 11:9938ba31d428 967
Mike Fiore 11:9938ba31d428 968 // Seek an open file
Mike Fiore 11:9938ba31d428 969 // file - mdot file struct
Mike Fiore 11:9938ba31d428 970 // offset - offset in bytes
Mike Fiore 11:9938ba31d428 971 // whence - where offset is based SEEK_SET, SEEK_CUR, SEEK_END
Mike Fiore 11:9938ba31d428 972 bool seekUserFile(mDot::mdot_file& file, size_t offset, int whence);
Mike Fiore 11:9938ba31d428 973
Mike Fiore 11:9938ba31d428 974 // Read bytes from open file
Mike Fiore 11:9938ba31d428 975 // file - mdot file struct
Mike Fiore 11:9938ba31d428 976 // data - mem location to store data
Mike Fiore 11:9938ba31d428 977 // length - number of bytes to read
Mike Fiore 11:9938ba31d428 978 // returns - number of bytes written
Mike Fiore 11:9938ba31d428 979 int readUserFile(mDot::mdot_file& file, void* data, size_t length);
Mike Fiore 11:9938ba31d428 980
Mike Fiore 11:9938ba31d428 981 // Write bytes to open file
Mike Fiore 11:9938ba31d428 982 // file - mdot file struct
Mike Fiore 11:9938ba31d428 983 // data - data to write
Mike Fiore 11:9938ba31d428 984 // length - number of bytes to write
Mike Fiore 11:9938ba31d428 985 // returns - number of bytes written
Mike Fiore 11:9938ba31d428 986 int writeUserFile(mDot::mdot_file& file, void* data, size_t length);
Mike Fiore 11:9938ba31d428 987
Mike Fiore 11:9938ba31d428 988 // Close open file
Mike Fiore 11:9938ba31d428 989 // file - mdot file struct
Mike Fiore 11:9938ba31d428 990 bool closeUserFile(mDot::mdot_file& file);
Mike Fiore 11:9938ba31d428 991
Mike Fiore 11:9938ba31d428 992 // List user files stored in flash
Mike Fiore 11:9938ba31d428 993 std::vector<mDot::mdot_file> listUserFiles();
Mike Fiore 11:9938ba31d428 994
Mike Fiore 11:9938ba31d428 995 // Move file into the firmware upgrade path to be flashed on next boot
Mike Fiore 11:9938ba31d428 996 // file - name of file
Mike Fiore 11:9938ba31d428 997 bool moveUserFileToFirmwareUpgrade(const char* file);
Mike Fiore 11:9938ba31d428 998
Mike Fiore 11:9938ba31d428 999 // get current statistics
Mike Fiore 11:9938ba31d428 1000 // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks
Mike Fiore 11:9938ba31d428 1001 mdot_stats getStats();
Mike Fiore 11:9938ba31d428 1002
Mike Fiore 11:9938ba31d428 1003 // reset statistics
Mike Fiore 11:9938ba31d428 1004 // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks
Mike Fiore 11:9938ba31d428 1005 void resetStats();
Mike Fiore 11:9938ba31d428 1006
Mike Fiore 11:9938ba31d428 1007 // Convert pin number 2-8 to pin name DIO2-DI8
Mike Fiore 11:9938ba31d428 1008 static PinName pinNum2Name(uint8_t num);
Mike Fiore 11:9938ba31d428 1009
Mike Fiore 11:9938ba31d428 1010 // Convert pin name DIO2-DI8 to pin number 2-8
Mike Fiore 11:9938ba31d428 1011 static uint8_t pinName2Num(PinName name);
Mike Fiore 11:9938ba31d428 1012
Mike Fiore 11:9938ba31d428 1013 // Convert pin name DIO2-DI8 to string
Mike Fiore 11:9938ba31d428 1014 static std::string pinName2Str(PinName name);
Mike Fiore 11:9938ba31d428 1015
Mike Fiore 11:9938ba31d428 1016 uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
mfiore 0:c62615f15125 1017
mfiore 0:c62615f15125 1018 /*************************************************************************
mfiore 0:c62615f15125 1019 * The following functions are only used by the AT command application and
mfiore 0:c62615f15125 1020 * should not be used by standard applications consuming the mDot library
mfiore 0:c62615f15125 1021 ************************************************************************/
Mike Fiore 7:683dba5d576f 1022
mfiore 0:c62615f15125 1023 // set/get configured baud rate for command port
mfiore 0:c62615f15125 1024 // only for use in conjunction with AT interface
mfiore 0:c62615f15125 1025 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1026 int32_t setBaud(const uint32_t& baud);
mfiore 0:c62615f15125 1027 uint32_t getBaud();
mfiore 0:c62615f15125 1028
mfiore 0:c62615f15125 1029 // set/get baud rate for debug port
mfiore 0:c62615f15125 1030 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1031 int32_t setDebugBaud(const uint32_t& baud);
mfiore 0:c62615f15125 1032 uint32_t getDebugBaud();
mfiore 0:c62615f15125 1033
mfiore 0:c62615f15125 1034 // set/get command terminal echo
mfiore 0:c62615f15125 1035 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1036 int32_t setEcho(const bool& on);
mfiore 0:c62615f15125 1037 bool getEcho();
mfiore 0:c62615f15125 1038
mfiore 0:c62615f15125 1039 // set/get command terminal verbose mode
mfiore 0:c62615f15125 1040 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1041 int32_t setVerbose(const bool& on);
mfiore 0:c62615f15125 1042 bool getVerbose();
mfiore 0:c62615f15125 1043
mfiore 0:c62615f15125 1044 // set/get startup mode
mfiore 0:c62615f15125 1045 // COMMAND_MODE (default), starts up ready to accept AT commands
mfiore 0:c62615f15125 1046 // SERIAL_MODE, read serial data and send it as LoRa packets
mfiore 0:c62615f15125 1047 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1048 int32_t setStartUpMode(const uint8_t& mode);
mfiore 0:c62615f15125 1049 uint8_t getStartUpMode();
mfiore 0:c62615f15125 1050
mfiore 0:c62615f15125 1051 int32_t setRxDataRate(const uint8_t& dr);
mfiore 0:c62615f15125 1052 uint8_t getRxDataRate();
mfiore 0:c62615f15125 1053
mfiore 0:c62615f15125 1054 // get/set TX/RX frequency
mfiore 0:c62615f15125 1055 // if frequency band == FB_868 (Europe), must be between 863000000 - 870000000
mfiore 0:c62615f15125 1056 // if frequency band == FB_915 (United States), must be between 902000000-928000000
mfiore 0:c62615f15125 1057 // if set to 0, device will hop frequencies
mfiore 0:c62615f15125 1058 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1059 int32_t setTxFrequency(const uint32_t& freq);
mfiore 0:c62615f15125 1060 uint32_t getTxFrequency();
mfiore 0:c62615f15125 1061 int32_t setRxFrequency(const uint32_t& freq);
mfiore 0:c62615f15125 1062 uint32_t getRxFrequency();
mfiore 0:c62615f15125 1063
mfiore 0:c62615f15125 1064 // get/set TX/RX inverted
mfiore 0:c62615f15125 1065 // true == signal is inverted
mfiore 0:c62615f15125 1066 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1067 int32_t setTxInverted(const bool& on);
mfiore 0:c62615f15125 1068 bool getTxInverted();
mfiore 0:c62615f15125 1069 int32_t setRxInverted(const bool& on);
mfiore 0:c62615f15125 1070 bool getRxInverted();
mfiore 0:c62615f15125 1071
mfiore 0:c62615f15125 1072 // get/set RX output mode
mfiore 0:c62615f15125 1073 // valid options are HEXADECIMAL and BINARY
mfiore 0:c62615f15125 1074 // set function returns MDOT_OK if success
mfiore 0:c62615f15125 1075 int32_t setRxOutput(const uint8_t& mode);
mfiore 0:c62615f15125 1076 uint8_t getRxOutput();
mfiore 0:c62615f15125 1077
mfiore 0:c62615f15125 1078 // get/set serial wake interval
mfiore 0:c62615f15125 1079 // valid values are 2 s - INT_MAX (2147483647) s
mfiore 0:c62615f15125 1080 // set function returns MDOT_OK if success
Mike Fiore 7:683dba5d576f 1081 int32_t setWakeInterval(const uint32_t& interval);
Mike Fiore 7:683dba5d576f 1082 uint32_t getWakeInterval();
mfiore 0:c62615f15125 1083
mfiore 0:c62615f15125 1084 // get/set serial wake delay
mfiore 0:c62615f15125 1085 // valid values are 2 ms - INT_MAX (2147483647) ms
mfiore 0:c62615f15125 1086 // set function returns MDOT_OK if success
Mike Fiore 7:683dba5d576f 1087 int32_t setWakeDelay(const uint32_t& delay);
Mike Fiore 7:683dba5d576f 1088 uint32_t getWakeDelay();
mfiore 0:c62615f15125 1089
mfiore 0:c62615f15125 1090 // get/set serial receive timeout
mfiore 0:c62615f15125 1091 // valid values are 0 ms - 65000 ms
mfiore 0:c62615f15125 1092 // set function returns MDOT_OK if success
Mike Fiore 7:683dba5d576f 1093 int32_t setWakeTimeout(const uint16_t& timeout);
Mike Fiore 7:683dba5d576f 1094 uint16_t getWakeTimeout();
Mike Fiore 7:683dba5d576f 1095
Mike Fiore 7:683dba5d576f 1096 // get/set serial wake mode
Mike Fiore 7:683dba5d576f 1097 // valid values are INTERRUPT or RTC_ALARM
Mike Fiore 7:683dba5d576f 1098 // set function returns MDOT_OK if success
Mike Fiore 7:683dba5d576f 1099 int32_t setWakeMode(const uint8_t& delay);
Mike Fiore 7:683dba5d576f 1100 uint8_t getWakeMode();
Mike Fiore 7:683dba5d576f 1101
Mike Fiore 11:9938ba31d428 1102 // get/set serial flow control enabled
Mike Fiore 11:9938ba31d428 1103 // set function returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 1104 int32_t setFlowControl(const bool& on);
Mike Fiore 11:9938ba31d428 1105 bool getFlowControl();
Mike Fiore 7:683dba5d576f 1106
mfiore 0:c62615f15125 1107
Mike Fiore 11:9938ba31d428 1108 // get/set serial clear on error
Mike Fiore 11:9938ba31d428 1109 // if enabled the data read from the serial port will be discarded if it cannot be sent or if the send fails
Mike Fiore 11:9938ba31d428 1110 // set function returns MDOT_OK if success
Mike Fiore 11:9938ba31d428 1111 int32_t setSerialClearOnError(const bool& on);
Mike Fiore 11:9938ba31d428 1112 bool getSerialClearOnError();
mfiore 0:c62615f15125 1113
mfiore 0:c62615f15125 1114 // MTS_RADIO_DEBUG_COMMANDS
Mike Fiore 7:683dba5d576f 1115
Mike Fiore 7:683dba5d576f 1116 void openRxWindow(uint32_t timeout, uint8_t bandwidth = 0);
Mike Fiore 6:390fc83d588d 1117 void sendContinuous();
mfiore 0:c62615f15125 1118 int32_t setDeviceId(const std::vector<uint8_t>& id);
mfiore 0:c62615f15125 1119 int32_t setFrequencyBand(const uint8_t& band);
mfiore 0:c62615f15125 1120 bool saveProtectedConfig();
mfiore 0:c62615f15125 1121 void resetRadio();
mfiore 0:c62615f15125 1122 int32_t setRadioMode(const uint8_t& mode);
mfiore 0:c62615f15125 1123 std::map<uint8_t, uint8_t> dumpRegisters();
mfiore 0:c62615f15125 1124 void eraseFlash();
mfiore 0:c62615f15125 1125
Mike Fiore 7:683dba5d576f 1126 // deprecated - use setWakeInterval
Mike Fiore 7:683dba5d576f 1127 int32_t setSerialWakeInterval(const uint32_t& interval);
Mike Fiore 7:683dba5d576f 1128 // deprecated - use getWakeInterval
Mike Fiore 7:683dba5d576f 1129 uint32_t getSerialWakeInterval();
Mike Fiore 6:390fc83d588d 1130
Mike Fiore 7:683dba5d576f 1131 // deprecated - use setWakeDelay
Mike Fiore 7:683dba5d576f 1132 int32_t setSerialWakeDelay(const uint32_t& delay);
Mike Fiore 7:683dba5d576f 1133 // deprecated - use setWakeDelay
Mike Fiore 7:683dba5d576f 1134 uint32_t getSerialWakeDelay();
Mike Fiore 7:683dba5d576f 1135
Mike Fiore 7:683dba5d576f 1136 // deprecated - use setWakeTimeout
Mike Fiore 7:683dba5d576f 1137 int32_t setSerialReceiveTimeout(const uint16_t& timeout);
Mike Fiore 7:683dba5d576f 1138 // deprecated - use getWakeTimeout
Mike Fiore 7:683dba5d576f 1139 uint16_t getSerialReceiveTimeout();
mfiore 0:c62615f15125 1140
Mike Fiore 11:9938ba31d428 1141 void setWakeupCallback(void (*function)(void));
Mike Fiore 11:9938ba31d428 1142
Mike Fiore 11:9938ba31d428 1143 template<typename T>
Mike Fiore 11:9938ba31d428 1144 void setWakeupCallback(T *object, void (T::*member)(void)) {
Mike Fiore 11:9938ba31d428 1145 _wakeup_callback.attach(object, member);
Mike Fiore 11:9938ba31d428 1146 }
Mike Fiore 11:9938ba31d428 1147
mfiore 0:c62615f15125 1148 private:
mfiore 0:c62615f15125 1149 mdot_stats _stats;
mfiore 0:c62615f15125 1150
Mike Fiore 11:9938ba31d428 1151 FunctionPointer _wakeup_callback;
Mike Fiore 11:9938ba31d428 1152
Mike Fiore 11:9938ba31d428 1153 bool _standbyFlag;
Mike Fiore 11:9938ba31d428 1154 bool _testMode;
Mike Fiore 11:9938ba31d428 1155 uint8_t _savedPort;
Mike Fiore 11:9938ba31d428 1156 void handleTestModePacket();
Mike Fiore 11:9938ba31d428 1157
mfiore 0:c62615f15125 1158 };
mfiore 0:c62615f15125 1159
mfiore 0:c62615f15125 1160 #endif