Library for LoRa communication using MultiTech MDOT. Not sure why it wants to republish this

Fork of libmDot by MultiTech

Committer:
jreiss
Date:
Thu Aug 18 16:07:10 2016 +0000
Revision:
15:b50f92f1c6ff
Parent:
11:9938ba31d428
update libmDot to 2.0.3

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