Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mDot-IKS01A1 mDot-IKS01A1 mDot-Examples mDot-IKS01A1-Explora ... more
Fork of libmDot-dev-mbed2-deprecated by
mDot.h
00001 // TODO: add license header 00002 00003 #ifndef MDOT_H 00004 #define MDOT_H 00005 00006 #include "mbed.h" 00007 #include "rtos.h" 00008 #include "Mote.h" 00009 #include <vector> 00010 #include <map> 00011 #include <string> 00012 00013 class mDotEvent; 00014 class LoRaConfig; 00015 00016 00017 class mDot { 00018 friend class mDotEvent; 00019 00020 private: 00021 00022 mDot(lora::ChannelPlan* plan); 00023 ~mDot(); 00024 00025 void initLora(); 00026 00027 void setLastError(const std::string& str); 00028 00029 static bool validateBaudRate(const uint32_t& baud); 00030 static bool validateFrequencySubBand(const uint8_t& band); 00031 bool validateDataRate(const uint8_t& dr); 00032 00033 int32_t joinBase(const uint32_t& retries); 00034 int32_t sendBase(const std::vector<uint8_t>& data, const bool& confirmed = false, const bool& blocking = true, const bool& highBw = false); 00035 void waitForPacket(); 00036 void waitForLinkCheck(); 00037 00038 void setActivityLedState(const uint8_t& state); 00039 uint8_t getActivityLedState(); 00040 00041 void blinkActivityLed(void) { 00042 if (_activity_led) { 00043 int val = _activity_led->read(); 00044 _activity_led->write(!val); 00045 } 00046 } 00047 00048 mDot(const mDot&); 00049 mDot& operator=(const mDot&); 00050 00051 uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR); 00052 void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data); 00053 00054 void wakeup(); 00055 00056 void RTC_DisableWakeupTimer(); 00057 void RTC_EnableWakeupTimer(); 00058 00059 void enterStopMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM); 00060 void enterStandbyMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM); 00061 00062 static mDot* _instance; 00063 00064 lora::Mote* _mote; 00065 LoRaConfig* _config; 00066 lora::Settings _settings; 00067 mDotEvent* _events; 00068 00069 std::string _last_error; 00070 static const uint32_t _baud_rates[]; 00071 uint8_t _activity_led_state; 00072 Ticker _tick; 00073 DigitalOut* _activity_led; 00074 bool _activity_led_enable; 00075 PinName _activity_led_pin; 00076 bool _activity_led_external; 00077 uint8_t _linkFailCount; 00078 uint8_t _class; 00079 InterruptIn* _wakeup; 00080 PinName _wakeup_pin; 00081 00082 typedef enum { 00083 OFF, 00084 ON, 00085 BLINK, 00086 } state; 00087 00088 public: 00089 00090 #if defined(TARGET_MTS_MDOT_F411RE) 00091 typedef enum { 00092 FM_APPEND = (1 << 0), 00093 FM_TRUNC = (1 << 1), 00094 FM_CREAT = (1 << 2), 00095 FM_RDONLY = (1 << 3), 00096 FM_WRONLY = (1 << 4), 00097 FM_RDWR = (FM_RDONLY | FM_WRONLY), 00098 FM_DIRECT = (1 << 5) 00099 } FileMode; 00100 #endif /* TARGET_MTS_MDOT_F411RE */ 00101 00102 typedef enum { 00103 MDOT_OK = 0, 00104 MDOT_INVALID_PARAM = -1, 00105 MDOT_TX_ERROR = -2, 00106 MDOT_RX_ERROR = -3, 00107 MDOT_JOIN_ERROR = -4, 00108 MDOT_TIMEOUT = -5, 00109 MDOT_NOT_JOINED = -6, 00110 MDOT_ENCRYPTION_DISABLED = -7, 00111 MDOT_NO_FREE_CHAN = -8, 00112 MDOT_TEST_MODE = -9, 00113 MDOT_NO_ENABLED_CHAN = -10, 00114 MDOT_AGGREGATED_DUTY_CYCLE = -11, 00115 MDOT_MAX_PAYLOAD_EXCEEDED = -12, 00116 MDOT_LBT_CHANNEL_BUSY = -13, 00117 MDOT_NOT_IDLE = -14, 00118 MDOT_ERROR = -1024, 00119 } mdot_ret_code; 00120 00121 enum JoinMode { 00122 MANUAL = 0, 00123 OTA, 00124 AUTO_OTA, 00125 PEER_TO_PEER 00126 }; 00127 00128 enum Mode { 00129 COMMAND_MODE, 00130 SERIAL_MODE 00131 }; 00132 00133 enum RX_Output { 00134 HEXADECIMAL, 00135 BINARY, 00136 EXTENDED 00137 }; 00138 00139 enum DataRates { 00140 DR0, 00141 DR1, 00142 DR2, 00143 DR3, 00144 DR4, 00145 DR5, 00146 DR6, 00147 DR7, 00148 DR8, 00149 DR9, 00150 DR10, 00151 DR11, 00152 DR12, 00153 DR13, 00154 DR14, 00155 DR15 00156 }; 00157 00158 enum FrequencySubBands { 00159 FSB_ALL, 00160 FSB_1, 00161 FSB_2, 00162 FSB_3, 00163 FSB_4, 00164 FSB_5, 00165 FSB_6, 00166 FSB_7, 00167 FSB_8 00168 }; 00169 00170 enum JoinByteOrder { 00171 LSB, 00172 MSB 00173 }; 00174 00175 enum wakeup_mode { 00176 RTC_ALARM, 00177 INTERRUPT, 00178 RTC_ALARM_OR_INTERRUPT 00179 }; 00180 00181 enum UserBackupRegs { 00182 UBR0, 00183 UBR1, 00184 UBR2, 00185 UBR3, 00186 UBR4, 00187 UBR5, 00188 UBR6, 00189 UBR7, 00190 UBR8, 00191 UBR9 00192 #if defined (TARGET_XDOT_L151CC) 00193 ,UBR10, 00194 UBR11, 00195 UBR12, 00196 UBR13, 00197 UBR14, 00198 UBR15, 00199 UBR16, 00200 UBR17, 00201 UBR18, 00202 UBR19, 00203 UBR20, 00204 UBR21 00205 #endif /* TARGET_XDOT_L151CC */ 00206 }; 00207 00208 #if defined(TARGET_MTS_MDOT_F411RE) 00209 typedef struct { 00210 int16_t fd; 00211 char name[33]; 00212 uint32_t size; 00213 } mdot_file; 00214 #endif /* TARGET_MTS_MDOT_F411RE */ 00215 00216 typedef struct { 00217 uint32_t Up; 00218 uint32_t Down; 00219 uint32_t Joins; 00220 uint32_t JoinFails; 00221 uint32_t MissedAcks; 00222 uint32_t CRCErrors; 00223 } mdot_stats; 00224 00225 typedef struct { 00226 int16_t last; 00227 int16_t min; 00228 int16_t max; 00229 int16_t avg; 00230 } rssi_stats; 00231 00232 typedef struct { 00233 int16_t last; 00234 int16_t min; 00235 int16_t max; 00236 int16_t avg; 00237 } snr_stats; 00238 00239 typedef struct { 00240 bool status; 00241 uint8_t dBm; 00242 uint32_t gateways; 00243 std::vector<uint8_t> payload; 00244 } link_check; 00245 00246 typedef struct { 00247 int32_t status; 00248 int16_t rssi; 00249 int16_t snr; 00250 } ping_response; 00251 00252 static std::string JoinModeStr(uint8_t mode); 00253 static std::string ModeStr(uint8_t mode); 00254 static std::string RxOutputStr(uint8_t format); 00255 static std::string DataRateStr(uint8_t rate); 00256 static std::string FrequencyBandStr(uint8_t band); 00257 static std::string FrequencySubBandStr(uint8_t band); 00258 00259 #if defined(TARGET_MTS_MDOT_F411RE) 00260 uint32_t UserRegisters[10]; 00261 #else 00262 uint32_t UserRegisters[22]; 00263 #endif /* TARGET_MTS_MDOT_F411RE */ 00264 00265 /** 00266 * Get a handle to the singleton object 00267 * @param plan the channel plan to use 00268 * @returns pointer to mDot object 00269 */ 00270 static mDot* getInstance(lora::ChannelPlan* plan); 00271 00272 /** 00273 * Can only be used after a dot has 00274 * configured with a plan 00275 * @returns pointer to mDot object 00276 */ 00277 static mDot* getInstance(); 00278 00279 void setEvents(mDotEvent* events); 00280 00281 /** 00282 * 00283 * Get library version information 00284 * @returns string containing library version information 00285 */ 00286 std::string getId(); 00287 00288 /** 00289 * Get MTS LoRa version information 00290 * @returns string containing MTS LoRa version information 00291 */ 00292 std::string getMtsLoraId(); 00293 00294 /** 00295 * Perform a soft reset of the system 00296 */ 00297 void resetCpu(); 00298 00299 /** 00300 * Reset config to factory default 00301 */ 00302 void resetConfig(); 00303 00304 /** 00305 * Save config data to non volatile memory 00306 * @returns true if success, false if failure 00307 */ 00308 bool saveConfig(); 00309 00310 /** 00311 * Set the log level for the library 00312 * options are: 00313 * NONE_LEVEL - logging is off at this level 00314 * FATAL_LEVEL - only critical errors will be reported 00315 * ERROR_LEVEL 00316 * WARNING_LEVEL 00317 * INFO_LEVEL 00318 * DEBUG_LEVEL 00319 * TRACE_LEVEL - every detail will be reported 00320 * @param level the level to log at 00321 * @returns MDOT_OK if success 00322 */ 00323 int32_t setLogLevel(const uint8_t& level); 00324 00325 /** 00326 * Get the current log level for the library 00327 * @returns current log level 00328 */ 00329 uint8_t getLogLevel(); 00330 00331 /** 00332 * Seed pseudo RNG in LoRaMac layer, uses random value from radio RSSI reading by default 00333 * @param seed for RNG 00334 */ 00335 void seedRandom(uint32_t seed); 00336 00337 00338 uint8_t setChannelPlan(lora::ChannelPlan* plan); 00339 00340 lora::Settings* getSettings(); 00341 00342 /** 00343 * Enable or disable the activity LED. 00344 * @param enable true to enable the LED, false to disable 00345 */ 00346 void setActivityLedEnable(const bool& enable); 00347 00348 /** 00349 * Find out if the activity LED is enabled 00350 * @returns true if activity LED is enabled, false if disabled 00351 */ 00352 bool getActivityLedEnable(); 00353 00354 /** 00355 * Use a different pin for the activity LED. 00356 * The default is XBEE_RSSI. 00357 * @param pin the new pin to use 00358 */ 00359 void setActivityLedPin(const PinName& pin); 00360 00361 /** 00362 * Use an external DigitalOut object for the activity LED. 00363 * The pointer must stay valid! 00364 * @param pin the DigitalOut object to use 00365 */ 00366 void setActivityLedPin(DigitalOut* pin); 00367 00368 /** 00369 * Find out what pin the activity LED is on 00370 * @returns the pin the activity LED is using 00371 */ 00372 PinName getActivityLedPin(); 00373 00374 /** 00375 * Returns boolean indicative of start-up from standby mode 00376 * @returns true if dot woke from standby 00377 */ 00378 bool getStandbyFlag(); 00379 00380 std::vector<uint16_t> getChannelMask(); 00381 00382 int32_t setChannelMask(uint8_t offset, uint16_t mask); 00383 00384 /** 00385 * Add a channel 00386 * @returns MDOT_OK 00387 */ 00388 int32_t addChannel(uint8_t index, uint32_t frequency, uint8_t datarateRange); 00389 00390 /** 00391 * Add a downlink channel 00392 * @returns MDOT_OK 00393 */ 00394 int32_t addDownlinkChannel(uint8_t index, uint32_t frequency); 00395 00396 /** 00397 * Get list of channel frequencies currently in use 00398 * @returns vector of channels currently in use 00399 */ 00400 std::vector<uint32_t> getChannels(); 00401 00402 /** 00403 * Get list of downlink channel frequencies currently in use 00404 * @returns vector of channels currently in use 00405 */ 00406 std::vector<uint32_t> getDownlinkChannels(); 00407 00408 /** 00409 * Get list of channel datarate ranges currently in use 00410 * @returns vector of datarate ranges currently in use 00411 */ 00412 std::vector<uint8_t> getChannelRanges(); 00413 00414 /** 00415 * Get list of channel frequencies in config file to be used as session defaults 00416 * @returns vector of channels in config file 00417 */ 00418 std::vector<uint32_t> getConfigChannels(); 00419 00420 /** 00421 * Get list of channel datarate ranges in config file to be used as session defaults 00422 * @returns vector of datarate ranges in config file 00423 */ 00424 std::vector<uint8_t> getConfigChannelRanges(); 00425 00426 /** 00427 * Get default frequency band 00428 * @returns frequency band the device was manufactured for 00429 */ 00430 uint8_t getDefaultFrequencyBand(); 00431 00432 /** 00433 * Set frequency sub band 00434 * only applicable if frequency band is set for United States (FB_915) 00435 * sub band 0 will allow the radio to use all 64 channels 00436 * sub band 1 - 8 will allow the radio to use the 8 channels in that sub band 00437 * for use with Conduit gateway and MTAC_LORA, use sub bands 1 - 8, not sub band 0 00438 * @param band the sub band to use (0 - 8) 00439 * @returns MDOT_OK if success 00440 */ 00441 int32_t setFrequencySubBand(const uint8_t& band); 00442 00443 /** 00444 * Get frequency sub band 00445 * @returns frequency sub band currently in use 00446 */ 00447 uint8_t getFrequencySubBand(); 00448 00449 /** 00450 * Get frequency band 00451 * @returns frequency band (channel plan) currently in use 00452 */ 00453 uint8_t getFrequencyBand(); 00454 00455 /** 00456 * Get channel plan name 00457 * @returns name of channel plan currently in use 00458 */ 00459 std::string getChannelPlanName(); 00460 00461 /** 00462 * Get the datarate currently in use within the MAC layer 00463 * returns 0-15 00464 */ 00465 uint8_t getSessionDataRate(); 00466 00467 00468 /** 00469 * Get the current max EIRP used in the channel plan 00470 * May be changed by the network server 00471 * returns 0-36 00472 */ 00473 uint8_t getSessionMaxEIRP(); 00474 00475 /** 00476 * Set the current max EIRP used in the channel plan 00477 * May be changed by the network server 00478 * accepts 0-36 00479 */ 00480 void setSessionMaxEIRP(uint8_t max); 00481 00482 /** 00483 * Get the current downlink dwell time used in the channel plan 00484 * May be changed by the network server 00485 * returns 0-1 00486 */ 00487 uint8_t getSessionDownlinkDwelltime(); 00488 00489 /** 00490 * Set the current downlink dwell time used in the channel plan 00491 * May be changed by the network server 00492 * accepts 0-1 00493 */ 00494 void setSessionDownlinkDwelltime(uint8_t dwell); 00495 00496 /** 00497 * Get the current uplink dwell time used in the channel plan 00498 * May be changed by the network server 00499 * returns 0-1 00500 */ 00501 uint8_t getSessionUplinkDwelltime(); 00502 00503 /** 00504 * Set the current uplink dwell time used in the channel plan 00505 * May be changed by the network server 00506 * accepts 0-1 00507 */ 00508 void setSessionUplinkDwelltime(uint8_t dwell); 00509 00510 /** 00511 * Set the current downlink dwell time used in the channel plan 00512 * May be changed by the network server 00513 * accepts 0-1 00514 */ 00515 uint32_t getListenBeforeTalkTime(uint8_t ms); 00516 00517 /** 00518 * Set the current downlink dwell time used in the channel plan 00519 * May be changed by the network server 00520 * accepts 0-1 00521 */ 00522 void setListenBeforeTalkTime(uint32_t ms); 00523 00524 /** 00525 * Set public network mode 00526 * 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN 00527 * PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band 00528 * PUBLIC_LORAWAN - Sync Word 0x34 00529 * PRIVATE_LORAWAN - Sync Word 0x12 00530 * 00531 * The default Join Delay is 5 seconds 00532 * The default Join Delay for PRIVATE_MTS was 1 second in the previous release 00533 * The Join Delay must be changed independently of Public Network setting 00534 * 00535 * @see lora::NetworkType 00536 * @returns MDOT_OK if success 00537 */ 00538 int32_t setPublicNetwork(const uint8_t& val); 00539 00540 /** 00541 * Get public network mode 00542 * 00543 * The default Join Delay is 5 seconds 00544 * The default Join Delay for PRIVATE_MTS was 1 second in the previous release 00545 * The Join Delay must be changed independently of Public Network setting 00546 * 00547 * @see lora:NetworkType 00548 * @returns 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN 00549 */ 00550 uint8_t getPublicNetwork(); 00551 00552 /** 00553 * Get the device ID 00554 * @returns vector containing the device ID (size 8) 00555 */ 00556 std::vector<uint8_t> getDeviceId(); 00557 00558 /** 00559 * Get the device port to be used for lora application data (1-223) 00560 * @returns port 00561 */ 00562 uint8_t getAppPort(); 00563 00564 /** 00565 * Set the device port to be used for lora application data (1-223) 00566 * @returns MDOT_OK if success 00567 */ 00568 int32_t setAppPort(uint8_t port); 00569 00570 /** 00571 * Set the device class A, B or C 00572 * @returns MDOT_OK if success 00573 */ 00574 int32_t setClass(std::string newClass); 00575 00576 /** 00577 * Get the device class A, B or C 00578 * @returns MDOT_OK if success 00579 */ 00580 std::string getClass(); 00581 00582 /** 00583 * Get the max packet length with current settings 00584 * @returns max packet length 00585 */ 00586 uint8_t getMaxPacketLength(); 00587 00588 /** 00589 * Set network address 00590 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes 00591 * @param addr a vector of 4 bytes 00592 * @returns MDOT_OK if success 00593 */ 00594 int32_t setNetworkAddress(const std::vector<uint8_t>& addr); 00595 00596 /** 00597 * Get network address 00598 * @returns vector containing network address (size 4) 00599 */ 00600 std::vector<uint8_t> getNetworkAddress(); 00601 00602 /** 00603 * Set network session key 00604 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes 00605 * @param key a vector of 16 bytes 00606 * @returns MDOT_OK if success 00607 */ 00608 int32_t setNetworkSessionKey(const std::vector<uint8_t>& key); 00609 00610 /** 00611 * Get network session key 00612 * @returns vector containing network session key (size 16) 00613 */ 00614 std::vector<uint8_t> getNetworkSessionKey(); 00615 00616 /** 00617 * Set data session key 00618 * for use with MANUAL network join mode, will be assigned in OTA & AUTO_OTA modes 00619 * @param key a vector of 16 bytes 00620 * @returns MDOT_OK if success 00621 */ 00622 int32_t setDataSessionKey(const std::vector<uint8_t>& key); 00623 00624 /** 00625 * Get data session key 00626 * @returns vector containing data session key (size 16) 00627 */ 00628 std::vector<uint8_t> getDataSessionKey(); 00629 00630 /** 00631 * Set network name 00632 * for use with OTA & AUTO_OTA network join modes 00633 * generates network ID (crc64 of name) automatically 00634 * @param name a string of of at least 8 bytes and no more than 128 bytes 00635 * @return MDOT_OK if success 00636 */ 00637 int32_t setNetworkName(const std::string& name); 00638 00639 /** 00640 * Get network name 00641 * @return string containing network name (size 8 to 128) 00642 */ 00643 std::string getNetworkName(); 00644 00645 /** 00646 * Set network ID 00647 * for use with OTA & AUTO_OTA network join modes 00648 * setting network ID via this function sets network name to empty 00649 * @param id a vector of 8 bytes 00650 * @returns MDOT_OK if success 00651 */ 00652 int32_t setNetworkId(const std::vector<uint8_t>& id); 00653 00654 /** 00655 * Get network ID 00656 * @returns vector containing network ID (size 8) 00657 */ 00658 std::vector<uint8_t> getNetworkId(); 00659 00660 /** 00661 * Set network passphrase 00662 * for use with OTA & AUTO_OTA network join modes 00663 * generates network key (cmac of passphrase) automatically 00664 * @param name a string of of at least 8 bytes and no more than 128 bytes 00665 * @return MDOT_OK if success 00666 */ 00667 int32_t setNetworkPassphrase(const std::string& passphrase); 00668 00669 /** 00670 * Get network passphrase 00671 * @return string containing network passphrase (size 8 to 128) 00672 */ 00673 std::string getNetworkPassphrase(); 00674 00675 /** 00676 * Set network key 00677 * for use with OTA & AUTO_OTA network join modes 00678 * setting network key via this function sets network passphrase to empty 00679 * @param id a vector of 16 bytes 00680 * @returns MDOT_OK if success 00681 */ 00682 int32_t setNetworkKey(const std::vector<uint8_t>& id); 00683 00684 /** 00685 * Get network key 00686 * @returns a vector containing network key (size 16) 00687 */ 00688 std::vector<uint8_t> getNetworkKey(); 00689 00690 /** 00691 * Set lorawan application EUI 00692 * equivalent to setNetworkId 00693 * @param eui application EUI (size 8) 00694 */ 00695 int32_t setAppEUI(const uint8_t* eui); 00696 00697 /** 00698 * Get lorawan application EUI 00699 * equivalent to getNetworkId 00700 * @returns vector containing application EUI (size 8) 00701 */ 00702 const uint8_t* getAppEUI(); 00703 00704 /** 00705 * Set lorawan application key 00706 * equivalent to setNetworkKey 00707 * @param eui application key (size 16) 00708 */ 00709 int32_t setAppKey(const uint8_t* key); 00710 00711 /** 00712 * Set lorawan application key 00713 * equivalent to getNetworkKey 00714 * @returns eui application key (size 16) 00715 */ 00716 const uint8_t* getAppKey(); 00717 00718 /** 00719 * Add a multicast session address and keys 00720 * Downlink counter is set to 0 00721 * Up to 3 MULTICAST_SESSIONS can be set 00722 */ 00723 int32_t setMulticastSession(uint8_t index, uint32_t addr, const uint8_t* nsk, const uint8_t* dsk); 00724 00725 /** 00726 * Set a multicast session counter 00727 * Up to 3 MULTICAST_SESSIONS can be set 00728 */ 00729 int32_t setMulticastDownlinkCounter(uint8_t index, uint32_t count); 00730 00731 /** 00732 * Set join byte order 00733 * @param order 0:LSB 1:MSB 00734 */ 00735 uint32_t setJoinByteOrder(uint8_t order); 00736 00737 /** 00738 * Get join byte order 00739 * @returns byte order to use in joins 0:LSB 1:MSB 00740 */ 00741 uint8_t getJoinByteOrder(); 00742 00743 /** 00744 * Attempt to join network 00745 * each attempt will be made with a random datarate up to the configured datarate 00746 * JoinRequest backoff between tries is enforced to 1% for 1st hour, 0.1% for 1-10 hours and 0.01% after 10 hours 00747 * Check getNextTxMs() for time until next join attempt can be made 00748 * @returns MDOT_OK if success 00749 */ 00750 int32_t joinNetwork(); 00751 00752 /** 00753 * Attempts to join network once 00754 * @returns MDOT_OK if success 00755 */ 00756 int32_t joinNetworkOnce(); 00757 00758 /** 00759 * Resets current network session, essentially disconnecting from the network 00760 * has no effect for MANUAL network join mode 00761 */ 00762 void resetNetworkSession(); 00763 00764 /** 00765 * Restore saved network session from flash 00766 * has no effect for MANUAL network join mode 00767 */ 00768 void restoreNetworkSession(); 00769 00770 /** 00771 * Save current network session to flash 00772 * has no effect for MANUAL network join mode 00773 */ 00774 void saveNetworkSession(); 00775 00776 /** 00777 * Set number of times joining will retry each sub-band before changing 00778 * to the next subband in US915 and AU915 00779 * @param retries must be between 0 - 255 00780 * @returns MDOT_OK if success 00781 */ 00782 int32_t setJoinRetries(const uint8_t& retries); 00783 00784 /** 00785 * Get number of times joining will retry each sub-band 00786 * @returns join retries (0 - 255) 00787 */ 00788 uint8_t getJoinRetries(); 00789 00790 /** 00791 * Set network join mode 00792 * MANUAL: set network address and session keys manually 00793 * OTA: User sets network name and passphrase, then attempts to join 00794 * AUTO_OTA: same as OTA, but network sessions can be saved and restored 00795 * @param mode MANUAL, OTA, or AUTO_OTA 00796 * @returns MDOT_OK if success 00797 */ 00798 int32_t setJoinMode(const uint8_t& mode); 00799 00800 /** 00801 * Get network join mode 00802 * @returns MANUAL, OTA, or AUTO_OTA 00803 */ 00804 uint8_t getJoinMode(); 00805 00806 /** 00807 * Get network join status 00808 * @returns true if currently joined to network 00809 */ 00810 bool getNetworkJoinStatus(); 00811 00812 /** 00813 * Do a network link check 00814 * application data may be returned in response to a network link check command 00815 * @returns link_check structure containing success, dBm above noise floor, gateways in range, and packet payload 00816 */ 00817 link_check networkLinkCheck(); 00818 00819 /** 00820 * Set network link check count to perform automatic link checks every count packets 00821 * only applicable if ACKs are disabled 00822 * @param count must be between 0 - 255 00823 * @returns MDOT_OK if success 00824 */ 00825 int32_t setLinkCheckCount(const uint8_t& count); 00826 00827 /** 00828 * Get network link check count 00829 * @returns count (0 - 255) 00830 */ 00831 uint8_t getLinkCheckCount(); 00832 00833 /** 00834 * Set network link check threshold, number of link check failures or missed acks to tolerate 00835 * before considering network connection lost 00836 * @pararm count must be between 0 - 255 00837 * @returns MDOT_OK if success 00838 */ 00839 int32_t setLinkCheckThreshold(const uint8_t& count); 00840 00841 /** 00842 * Get network link check threshold 00843 * @returns threshold (0 - 255) 00844 */ 00845 uint8_t getLinkCheckThreshold(); 00846 00847 /** 00848 * Get/set number of failed link checks in the current session 00849 * @returns count (0 - 255) 00850 */ 00851 uint8_t getLinkFailCount(); 00852 int32_t setLinkFailCount(uint8_t count); 00853 00854 /** 00855 * Set UpLinkCounter number of packets sent to the gateway during this network session (sequence number) 00856 * @returns MDOT_OK 00857 */ 00858 int32_t setUpLinkCounter(uint32_t count); 00859 00860 /** 00861 * Get UpLinkCounter 00862 * @returns number of packets sent to the gateway during this network session (sequence number) 00863 */ 00864 uint32_t getUpLinkCounter(); 00865 00866 /** 00867 * Set UpLinkCounter number of packets sent by the gateway during this network session (sequence number) 00868 * @returns MDOT_OK 00869 */ 00870 int32_t setDownLinkCounter(uint32_t count); 00871 00872 /** 00873 * Get DownLinkCounter 00874 * @returns number of packets sent by the gateway during this network session (sequence number) 00875 */ 00876 uint32_t getDownLinkCounter(); 00877 00878 /** 00879 * Enable/disable AES encryption 00880 * AES encryption must be enabled for use with Conduit gateway and MTAC_LORA card 00881 * @param on true for AES encryption to be enabled 00882 * @returns MDOT_OK if success 00883 */ 00884 int32_t setAesEncryption(const bool& on); 00885 00886 /** 00887 * Get AES encryption 00888 * @returns true if AES encryption is enabled 00889 */ 00890 bool getAesEncryption(); 00891 00892 /** 00893 * Get RSSI stats 00894 * @returns rssi_stats struct containing last, min, max, and avg RSSI in dB 00895 */ 00896 rssi_stats getRssiStats(); 00897 00898 /** 00899 * Get SNR stats 00900 * @returns snr_stats struct containing last, min, max, and avg SNR in cB 00901 */ 00902 snr_stats getSnrStats(); 00903 00904 /** 00905 * Get ms until next free channel 00906 * only applicable for European models, US models return 0 00907 * @returns time (ms) until a channel is free to use for transmitting 00908 */ 00909 uint32_t getNextTxMs(); 00910 00911 /** 00912 * Get join delay in seconds 00913 * Defaults to 5 seconds 00914 * Must match join delay setting of the network server 00915 * 00916 * The default Join Delay is 5 seconds 00917 * The default Join Delay for PRIVATE_MTS was 1 second in the previous release 00918 * 00919 * @returns number of seconds before join accept message is expected 00920 */ 00921 uint8_t getJoinDelay(); 00922 00923 /** 00924 * Set join delay in seconds 00925 * Defaults to 5 seconds 00926 * Must match join delay setting of the network server 00927 * 00928 * The default Join Delay is 5 seconds 00929 * The default Join Delay for PRIVATE_MTS was 1 second in the previous release 00930 * 00931 * @param delay number of seconds before join accept message is expected 00932 * @return MDOT_OK if success 00933 */ 00934 uint32_t setJoinDelay(uint8_t delay); 00935 00936 /** 00937 * Get join Rx1 datarate offset 00938 * defaults to 0 00939 * @returns offset 00940 */ 00941 uint8_t getJoinRx1DataRateOffset(); 00942 00943 /** 00944 * Set join Rx1 datarate offset 00945 * @param offset for datarate 00946 * @return MDOT_OK if success 00947 */ 00948 uint32_t setJoinRx1DataRateOffset(uint8_t offset); 00949 00950 /** 00951 * Get join Rx2 datarate 00952 * defaults to US:DR8, AU:DR8, EU:DR0 00953 * @returns datarate 00954 */ 00955 uint8_t getJoinRx2DataRate(); 00956 00957 /** 00958 * Set join Rx2 datarate 00959 * @param datarate 00960 * @return MDOT_OK if success 00961 */ 00962 uint32_t setJoinRx2DataRate(uint8_t datarate); 00963 00964 /** 00965 * Get join Rx2 frequency 00966 * defaults US:923.3, AU:923.3, EU:869.525 00967 * @returns frequency 00968 */ 00969 uint32_t getJoinRx2Frequency(); 00970 00971 /** 00972 * Set join Rx2 frequency 00973 * @param frequency 00974 * @return MDOT_OK if success 00975 */ 00976 uint32_t setJoinRx2Frequency(uint32_t frequency); 00977 00978 /** 00979 * Get rx delay in seconds 00980 * Defaults to 1 second 00981 * @returns number of seconds before response message is expected 00982 */ 00983 uint8_t getRxDelay(); 00984 00985 /** 00986 * Set rx delay in seconds 00987 * Defaults to 1 second 00988 * @param delay number of seconds before response message is expected 00989 * @return MDOT_OK if success 00990 */ 00991 uint32_t setRxDelay(uint8_t delay); 00992 00993 /** 00994 * Get preserve session to save network session info through reset or power down in AUTO_OTA mode 00995 * Defaults to off 00996 * @returns true if enabled 00997 */ 00998 bool getPreserveSession(); 00999 01000 /** 01001 * Set preserve session to save network session info through reset or power down in AUTO_OTA mode 01002 * Defaults to off 01003 * @param enable 01004 * @return MDOT_OK if success 01005 */ 01006 uint32_t setPreserveSession(bool enable); 01007 01008 /** 01009 * Get data pending 01010 * only valid after sending data to the gateway 01011 * @returns true if server has available packet(s) 01012 */ 01013 bool getDataPending(); 01014 01015 /** 01016 * Get ack requested 01017 * only valid after sending data to the gateway 01018 * @returns true if server has requested ack 01019 */ 01020 bool getAckRequested(); 01021 01022 /** 01023 * Get is transmitting indicator 01024 * @returns true if currently transmitting 01025 */ 01026 bool getIsTransmitting(); 01027 01028 /** 01029 * Get is idle indicator 01030 * @returns true if not currently transmitting, waiting or receiving 01031 */ 01032 bool getIsIdle(); 01033 01034 /** 01035 * Set TX data rate 01036 * data rates affect maximum payload size 01037 * @param dr DR0-DR7 for Europe, DR0-DR4 for United States 01038 * @returns MDOT_OK if success 01039 */ 01040 int32_t setTxDataRate(const uint8_t& dr); 01041 01042 /** 01043 * Get TX data rate 01044 * @returns current TX data rate (DR0-DR15) 01045 */ 01046 uint8_t getTxDataRate(); 01047 01048 /** 01049 * Get a random value from the radio based on RSSI 01050 * @returns randome value 01051 */ 01052 uint32_t getRadioRandom(); 01053 01054 /** 01055 * Get data rate spreading factor and bandwidth 01056 * EU868 Datarates 01057 * --------------- 01058 * DR0 - SF12BW125 01059 * DR1 - SF11BW125 01060 * DR2 - SF10BW125 01061 * DR3 - SF9BW125 01062 * DR4 - SF8BW125 01063 * DR5 - SF7BW125 01064 * DR6 - SF7BW250 01065 * DR7 - FSK 01066 * 01067 * US915 Datarates 01068 * --------------- 01069 * DR0 - SF10BW125 01070 * DR1 - SF9BW125 01071 * DR2 - SF8BW125 01072 * DR3 - SF7BW125 01073 * DR4 - SF8BW500 01074 * 01075 * AU915 Datarates 01076 * --------------- 01077 * DR0 - SF10BW125 01078 * DR1 - SF9BW125 01079 * DR2 - SF8BW125 01080 * DR3 - SF7BW125 01081 * DR4 - SF8BW500 01082 * 01083 * @returns spreading factor and bandwidth 01084 */ 01085 std::string getDataRateDetails(uint8_t rate); 01086 std::string getDateRateDetails(uint8_t rate); 01087 01088 01089 /** 01090 * Set TX power output of radio before antenna gain, default: 14 dBm 01091 * actual output power may be limited by local regulations for the chosen frequency 01092 * power affects maximum range 01093 * @param power 2 dBm - 20 dBm 01094 * @returns MDOT_OK if success 01095 */ 01096 int32_t setTxPower(const uint32_t& power); 01097 01098 /** 01099 * Get TX power 01100 * @returns TX power (2 dBm - 20 dBm) 01101 */ 01102 uint32_t getTxPower(); 01103 01104 /** 01105 * Get configured gain of installed antenna, default: +3 dBi 01106 * @returns gain of antenna in dBi 01107 */ 01108 int8_t getAntennaGain(); 01109 01110 /** 01111 * Set configured gain of installed antenna, default: +3 dBi 01112 * @param gain -127 dBi - 128 dBi 01113 * @returns MDOT_OK if success 01114 */ 01115 int32_t setAntennaGain(int8_t gain); 01116 01117 /** 01118 * Enable/disable TX waiting for rx windows 01119 * when enabled, send calls will block until a packet is received or RX timeout 01120 * @param enable set to true if expecting responses to transmitted packets 01121 * @returns MDOT_OK if success 01122 */ 01123 int32_t setTxWait(const bool& enable); 01124 01125 /** 01126 * Get TX wait 01127 * @returns true if TX wait is enabled 01128 */ 01129 bool getTxWait(); 01130 01131 /** 01132 * Cancel pending rx windows 01133 */ 01134 void cancelRxWindow(); 01135 01136 /** 01137 * Get time on air 01138 * @returns the amount of time (in ms) it would take to send bytes bytes based on current configuration 01139 */ 01140 uint32_t getTimeOnAir(uint8_t bytes); 01141 01142 /** 01143 * Get min frequency 01144 * @returns minimum frequency based on current channel plan 01145 */ 01146 uint32_t getMinFrequency(); 01147 01148 /** 01149 * Get max frequency 01150 * @returns maximum frequency based on current channel plan 01151 */ 01152 uint32_t getMaxFrequency(); 01153 01154 /** 01155 * Get min datarate 01156 * @returns minimum datarate based on current channel plan 01157 */ 01158 uint8_t getMinDatarate(); 01159 01160 /** 01161 * Get max datarate 01162 * @returns maximum datarate based on current channel plan 01163 */ 01164 uint8_t getMaxDatarate(); 01165 01166 /** 01167 * Get min datarate offset 01168 * @returns minimum datarate offset based on current channel plan 01169 */ 01170 uint8_t getMinDatarateOffset(); 01171 01172 /** 01173 * Get max datarate offset 01174 * @returns maximum datarate based on current channel plan 01175 */ 01176 uint8_t getMaxDatarateOffset(); 01177 01178 /** 01179 * Get min datarate 01180 * @returns minimum datarate based on current channel plan 01181 */ 01182 uint8_t getMinRx2Datarate(); 01183 01184 /** 01185 * Get max rx2 datarate 01186 * @returns maximum rx2 datarate based on current channel plan 01187 */ 01188 uint8_t getMaxRx2Datarate(); 01189 01190 /** 01191 * Get max tx power 01192 * @returns maximum tx power based on current channel plan 01193 */ 01194 uint8_t getMaxTxPower(); 01195 01196 /** 01197 * Get min tx power 01198 * @returns minimum tx power based on current channel plan 01199 */ 01200 uint8_t getMinTxPower(); 01201 01202 /** 01203 * Set ping slot periodicity 01204 * Specify the the number of ping slots in a given beacon interval 01205 * Note: Must switch back to class A for the change to take effect 01206 * @param exp - number_of_pings = 2^(7 - exp) where 0 <= exp <= 7 01207 * @returns MDOT_OK if success 01208 */ 01209 uint32_t setPingPeriodicity(uint8_t exp); 01210 01211 /** 01212 * Get ping slot periodicity 01213 * @returns exp = 7 - log2(number_of_pings) 01214 */ 01215 uint8_t getPingPeriodicity(); 01216 01217 /** 01218 * 01219 * get/set adaptive data rate 01220 * configure data rates and power levels based on signal to noise of packets received at gateway 01221 * true == adaptive data rate is on 01222 * set function returns MDOT_OK if success 01223 */ 01224 int32_t setAdr(const bool& on); 01225 bool getAdr(); 01226 01227 /** 01228 * Set the ADR ACK Limit 01229 * @param limit - ADR ACK limit 01230 */ 01231 void setAdrAckLimit(uint16_t limit); 01232 01233 /** 01234 * Get the ADR ACK Limit 01235 * @returns ADR ACK limit 01236 */ 01237 uint16_t getAdrAckLimit(); 01238 01239 /** 01240 * Set the ADR ACK Delay 01241 * @param delay - ADR ACK delay 01242 */ 01243 void setAdrAckDelay(uint16_t delay); 01244 01245 /** 01246 * Get the ADR ACK Delay 01247 * @returns ADR ACK delay 01248 */ 01249 uint16_t getAdrAckDelay(); 01250 01251 /** 01252 * Enable/disable CRC checking of packets 01253 * CRC checking must be enabled for use with Conduit gateway and MTAC_LORA card 01254 * @param on set to true to enable CRC checking 01255 * @returns MDOT_OK if success 01256 */ 01257 int32_t setCrc(const bool& on); 01258 01259 /** 01260 * Get CRC checking 01261 * @returns true if CRC checking is enabled 01262 */ 01263 bool getCrc(); 01264 01265 /** 01266 * Set ack 01267 * @param retries 0 to disable acks, otherwise 1 - 8 01268 * @returns MDOT_OK if success 01269 */ 01270 int32_t setAck(const uint8_t& retries); 01271 01272 /** 01273 * Get ack 01274 * @returns 0 if acks are disabled, otherwise retries (1 - 8) 01275 */ 01276 uint8_t getAck(); 01277 01278 /** 01279 * Set number of packet repeats for unconfirmed frames 01280 * @param repeat 0 or 1 for no repeats, otherwise 2-15 01281 * @returns MDOT_OK if success 01282 */ 01283 int32_t setRepeat(const uint8_t& repeat); 01284 01285 /** 01286 * Get number of packet repeats for unconfirmed frames 01287 * @returns 0 or 1 if no repeats, otherwise 2-15 01288 */ 01289 uint8_t getRepeat(); 01290 01291 /** 01292 * Send data to the gateway 01293 * validates data size (based on spreading factor) 01294 * @param data a vector of up to 242 bytes (may be less based on spreading factor) 01295 * @returns MDOT_OK if packet was sent successfully (ACKs disabled), or if an ACK was received (ACKs enabled) 01296 */ 01297 int32_t send(const std::vector<uint8_t>& data, const bool& blocking = true, const bool& highBw = false); 01298 01299 /** 01300 * Inject mac command 01301 * @param data a vector containing mac commands 01302 * @returns MDOT_OK 01303 */ 01304 int32_t injectMacCommand(const std::vector<uint8_t>& data); 01305 01306 /** 01307 * Clear MAC command buffer to be sent in next uplink 01308 * @returns MDOT_OK 01309 */ 01310 int32_t clearMacCommands(); 01311 01312 /** 01313 * Get MAC command buffer to be sent in next uplink 01314 * @returns command bytes 01315 */ 01316 std::vector<uint8_t> getMacCommands(); 01317 01318 /** 01319 * Fetch data received from the gateway 01320 * this function only checks to see if a packet has been received - it does not open a receive window 01321 * send() must be called before recv() 01322 * @param data a vector to put the received data into 01323 * @returns MDOT_OK if packet was successfully received 01324 */ 01325 int32_t recv(std::vector<uint8_t>& data); 01326 01327 /** 01328 * Ping 01329 * status will be MDOT_OK if ping succeeded 01330 * @returns ping_response struct containing status, RSSI, and SNR 01331 */ 01332 ping_response ping(); 01333 01334 /** 01335 * Get return code string 01336 * @returns string containing a description of the given error code 01337 */ 01338 static std::string getReturnCodeString(const int32_t& code); 01339 01340 /** 01341 * Get last error 01342 * @returns string explaining the last error that occured 01343 */ 01344 std::string getLastError(); 01345 01346 /** 01347 * Go to sleep 01348 * @param interval the number of seconds to sleep before waking up if wakeup_mode == RTC_ALARM or RTC_ALARM_OR_INTERRUPT, else ignored 01349 * @param wakeup_mode RTC_ALARM, INTERRUPT, RTC_ALARM_OR_INTERRUPT 01350 * if RTC_ALARM the real time clock is configured to wake the device up after the specified interval 01351 * if INTERRUPT the device will wake up on the rising edge of the interrupt pin 01352 * if RTC_ALARM_OR_INTERRUPT the device will wake on the first event to occur 01353 * @param deepsleep if true go into deep sleep mode (lowest power, all memory and registers are lost, peripherals turned off) 01354 * else go into sleep mode (low power, memory and registers are maintained, peripherals stay on) 01355 * 01356 * For the MDOT 01357 * in sleep mode, the device can be woken up on an XBEE_DI (2-8) pin or by the RTC alarm 01358 * in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, XBEE_DIO7) or by the RTC alarm 01359 * For the XDOT 01360 * in sleep mode, the device can be woken up on GPIO (0-3), UART1_RX, WAKE or by the RTC alarm 01361 * in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, WAKE) or by the RTC alarm 01362 * @returns MDOT_OK on success 01363 */ 01364 int32_t sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true); 01365 01366 /** 01367 * Set wake pin 01368 * @param pin the pin to use to wake the device from sleep mode 01369 * For MDOT, XBEE_DI (2-8) 01370 * For XDOT, GPIO (0-3), UART1_RX, or WAKE 01371 */ 01372 void setWakePin(const PinName& pin); 01373 01374 /** 01375 * Get wake pin 01376 * @returns the pin to use to wake the device from sleep mode 01377 * For MDOT, XBEE_DI (2-8) 01378 * For XDOT, GPIO (0-3), UART1_RX, or WAKE 01379 */ 01380 PinName getWakePin(); 01381 01382 /** 01383 * Write data in a user backup register 01384 * @param register one of UBR0 through UBR9 for MDOT, one of UBR0 through UBR21 for XDOT 01385 * @param data user data to back up 01386 * @returns true if success 01387 */ 01388 bool writeUserBackupRegister(uint32_t reg, uint32_t data); 01389 01390 /** 01391 * Read data in a user backup register 01392 * @param register one of UBR0 through UBR9 for MDOT, one of UBR0 through UBR21 for XDOT 01393 * @param data gets set to content of register 01394 * @returns true if success 01395 */ 01396 bool readUserBackupRegister(uint32_t reg, uint32_t& data); 01397 01398 /** 01399 * Set LBT time in us 01400 * @param ms time in us 01401 * @returns true if success 01402 */ 01403 bool setLbtTimeUs(uint16_t us); 01404 01405 /** 01406 * Get LBT time in us 01407 * @returns LBT time in us 01408 */ 01409 uint16_t getLbtTimeUs(); 01410 01411 /** 01412 * Set LBT threshold in dBm 01413 * @param rssi threshold in dBm 01414 * @returns true if success 01415 */ 01416 bool setLbtThreshold(int8_t rssi); 01417 01418 /** 01419 * Get LBT threshold in dBm 01420 * @returns LBT threshold in dBm 01421 */ 01422 int8_t getLbtThreshold(); 01423 01424 /** 01425 * Get Radio Frequency Offset 01426 * Used for fine calibration of radio frequencies 01427 * @returns frequency offset in MHz 01428 */ 01429 int32_t getFrequencyOffset(); 01430 /** 01431 * Get Radio Frequency Offset 01432 * Used for fine calibration of radio frequencies 01433 * @param offset frequency offset in MHz 01434 */ 01435 void setFrequencyOffset(int32_t offset); 01436 01437 01438 #if defined(TARGET_MTS_MDOT_F411RE) 01439 /////////////////////////////////////////////////////////////////// 01440 // Filesystem (Non Volatile Memory) Operation Functions for mDot // 01441 /////////////////////////////////////////////////////////////////// 01442 01443 // Save user file data to flash 01444 // file - name of file max 30 chars 01445 // data - data of file 01446 // size - size of file 01447 // returns true if successful 01448 bool saveUserFile(const char* file, void* data, uint32_t size); 01449 01450 // Append user file data to flash 01451 // file - name of file max 30 chars 01452 // data - data of file 01453 // size - size of file 01454 // returns true if successful 01455 bool appendUserFile(const char* file, void* data, uint32_t size); 01456 01457 // Read user file data from flash 01458 // file - name of file max 30 chars 01459 // data - data of file 01460 // size - size of file 01461 // returns true if successful 01462 bool readUserFile(const char* file, void* data, uint32_t size); 01463 01464 // Move a user file in flash 01465 // file - name of file 01466 // new_name - new name of file 01467 // returns true if successful 01468 bool moveUserFile(const char* file, const char* new_name); 01469 01470 // Delete user file data from flash 01471 // file - name of file max 30 chars 01472 // returns true if successful 01473 bool deleteUserFile(const char* file); 01474 01475 // Open user file in flash, max of 4 files open concurrently 01476 // file - name of file max 30 chars 01477 // mode - combination of FM_APPEND | FM_TRUNC | FM_CREAT | 01478 // FM_RDONLY | FM_WRONLY | FM_RDWR | FM_DIRECT 01479 // returns - mdot_file struct, fd field will be a negative value if file could not be opened 01480 mDot::mdot_file openUserFile(const char* file, int mode); 01481 01482 // Seek an open file 01483 // file - mdot file struct 01484 // offset - offset in bytes 01485 // whence - where offset is based SEEK_SET, SEEK_CUR, SEEK_END 01486 // returns true if successful 01487 bool seekUserFile(mDot::mdot_file& file, size_t offset, int whence); 01488 01489 // Read bytes from open file 01490 // file - mdot file struct 01491 // data - mem location to store data 01492 // length - number of bytes to read 01493 // returns - number of bytes read, negative if error 01494 int readUserFile(mDot::mdot_file& file, void* data, size_t length); 01495 01496 // Write bytes to open file 01497 // file - mdot file struct 01498 // data - data to write 01499 // length - number of bytes to write 01500 // returns - number of bytes written, negative if error 01501 int writeUserFile(mDot::mdot_file& file, void* data, size_t length); 01502 01503 // Close open file 01504 // file - mdot file struct 01505 // returns true if successful 01506 bool closeUserFile(mDot::mdot_file& file); 01507 01508 // List user files stored in flash 01509 std::vector<mDot::mdot_file> listUserFiles(); 01510 01511 // Move file into the firmware upgrade path to be flashed on next boot 01512 // file - name of file 01513 // returns true if successful 01514 bool moveUserFileToFirmwareUpgrade(const char* file); 01515 #else 01516 /////////////////////////////////////////////////////////////// 01517 // EEPROM (Non Volatile Memory) Operation Functions for xDot // 01518 /////////////////////////////////////////////////////////////// 01519 01520 // Write to EEPROM 01521 // addr - address to write to (0 - 0x17FF) 01522 // data - data to write 01523 // size - size of data 01524 // returns true if successful 01525 bool nvmWrite(uint16_t addr, void* data, uint16_t size); 01526 01527 // Read from EEPROM 01528 // addr - address to read from (0 - 0x17FF) 01529 // data - buffer for data 01530 // size - size of buffer 01531 // returns true if successful 01532 bool nvmRead(uint16_t addr, void* data, uint16_t size); 01533 #endif /* TARGET_MTS_MDOT_F411RE */ 01534 01535 // get current statistics 01536 // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks 01537 mdot_stats getStats(); 01538 01539 // reset statistics 01540 // Join Attempts, Join Fails, Up Packets, Down Packets, Missed Acks 01541 void resetStats(); 01542 01543 // Convert pin number 2-8 to pin name DIO2-DI8 01544 static PinName pinNum2Name(uint8_t num); 01545 01546 // Convert pin name DIO2-DI8 to pin number 2-8 01547 static uint8_t pinName2Num(PinName name); 01548 01549 // Convert pin name DIO2-DI8 to string 01550 static std::string pinName2Str(PinName name); 01551 01552 uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); 01553 01554 /************************************************************************* 01555 * The following functions are only used by the AT command application and 01556 * should not be used by standard applications consuming the mDot library 01557 ************************************************************************/ 01558 01559 // set/get configured baud rate for command port 01560 // only for use in conjunction with AT interface 01561 // set function returns MDOT_OK if success 01562 int32_t setBaud(const uint32_t& baud); 01563 uint32_t getBaud(); 01564 01565 // set/get baud rate for debug port 01566 // set function returns MDOT_OK if success 01567 int32_t setDebugBaud(const uint32_t& baud); 01568 uint32_t getDebugBaud(); 01569 01570 // set/get command terminal echo 01571 // set function returns MDOT_OK if success 01572 int32_t setEcho(const bool& on); 01573 bool getEcho(); 01574 01575 // set/get command terminal verbose mode 01576 // set function returns MDOT_OK if success 01577 int32_t setVerbose(const bool& on); 01578 bool getVerbose(); 01579 01580 // set/get startup mode 01581 // COMMAND_MODE (default), starts up ready to accept AT commands 01582 // SERIAL_MODE, read serial data and send it as LoRa packets 01583 // set function returns MDOT_OK if success 01584 int32_t setStartUpMode(const uint8_t& mode); 01585 uint8_t getStartUpMode(); 01586 01587 int32_t setRxDataRate(const uint8_t& dr); 01588 uint8_t getRxDataRate(); 01589 01590 // get/set TX/RX frequency 01591 // if frequency band == FB_868 (Europe), must be between 863000000 - 870000000 01592 // if frequency band == FB_915 (United States), must be between 902000000-928000000 01593 // if set to 0, device will hop frequencies 01594 // set function returns MDOT_OK if success 01595 int32_t setTxFrequency(const uint32_t& freq); 01596 uint32_t getTxFrequency(); 01597 int32_t setRxFrequency(const uint32_t& freq); 01598 uint32_t getRxFrequency(); 01599 01600 // get/set RX output mode 01601 // valid options are HEXADECIMAL, BINARY, and EXTENDED 01602 // set function returns MDOT_OK if success 01603 int32_t setRxOutput(const uint8_t& mode); 01604 uint8_t getRxOutput(); 01605 01606 // get/set serial wake interval 01607 // valid values are 2 s - INT_MAX (2147483647) s 01608 // set function returns MDOT_OK if success 01609 int32_t setWakeInterval(const uint32_t& interval); 01610 uint32_t getWakeInterval(); 01611 01612 // get/set serial wake delay 01613 // valid values are 2 ms - INT_MAX (2147483647) ms 01614 // set function returns MDOT_OK if success 01615 int32_t setWakeDelay(const uint32_t& delay); 01616 uint32_t getWakeDelay(); 01617 01618 // get/set serial receive timeout 01619 // valid values are 0 ms - 65000 ms 01620 // set function returns MDOT_OK if success 01621 int32_t setWakeTimeout(const uint16_t& timeout); 01622 uint16_t getWakeTimeout(); 01623 01624 // get/set serial wake mode 01625 // valid values are INTERRUPT or RTC_ALARM 01626 // set function returns MDOT_OK if success 01627 int32_t setWakeMode(const uint8_t& delay); 01628 uint8_t getWakeMode(); 01629 01630 // get/set serial flow control enabled 01631 // set function returns MDOT_OK if success 01632 int32_t setFlowControl(const bool& on); 01633 bool getFlowControl(); 01634 01635 // get/set serial clear on error 01636 // if enabled the data read from the serial port will be discarded if it cannot be sent or if the send fails 01637 // set function returns MDOT_OK if success 01638 int32_t setSerialClearOnError(const bool& on); 01639 bool getSerialClearOnError(); 01640 01641 // MTS_RADIO_DEBUG_COMMANDS 01642 01643 /** 01644 * Disable Duty cycle 01645 * enables or disables the duty cycle limitations 01646 * **** ONLY TO BE USED FOR TESTINGS PURPOSES **** 01647 * **** ALL DEPLOYABLE CODE MUST ADHERE TO LOCAL REGULATIONS **** 01648 * **** THIS SETTING WILL NOT BE SAVED TO CONFIGURATION ***** 01649 * @param val true to disable duty-cycle (default:false) 01650 */ 01651 int32_t setDisableDutyCycle(bool val); 01652 01653 /** 01654 * Disable Duty cycle 01655 * **** ONLY TO BE USED FOR TESTINGS PURPOSES **** 01656 * **** ALL DEPLOYABLE CODE MUST ADHERE TO LOCAL REGULATIONS **** 01657 * **** THIS SETTING WILL NOT BE SAVED TO CONFIGURATION ***** 01658 * @return true if duty-cycle is disabled (default:false) 01659 */ 01660 uint8_t getDisableDutyCycle(); 01661 01662 /** 01663 * LBT RSSI 01664 * @return the current RSSI on the configured frequency (SetTxFrequency) using configured LBT Time 01665 */ 01666 int16_t lbtRssi(); 01667 01668 void openRxWindow(uint32_t timeout, uint8_t bandwidth = 0); 01669 void closeRxWindow(); 01670 void sendContinuous(bool enable=true, uint32_t timeout=0, uint32_t frequency=0, int8_t txpower=-1); 01671 int32_t setDeviceId(const std::vector<uint8_t>& id); 01672 int32_t setProtectedAppEUI(const std::vector<uint8_t>& appEUI); 01673 int32_t setProtectedAppKey(const std::vector<uint8_t>& appKey); 01674 int32_t setDefaultFrequencyBand(const uint8_t& band); 01675 bool saveProtectedConfig(); 01676 // resets the radio/mac/link 01677 void resetRadio(); 01678 int32_t setRadioMode(const uint8_t& mode); 01679 std::map<uint8_t, uint8_t> dumpRegisters(); 01680 void eraseFlash(); 01681 01682 // deprecated - use setWakeInterval 01683 int32_t setSerialWakeInterval(const uint32_t& interval); 01684 // deprecated - use getWakeInterval 01685 uint32_t getSerialWakeInterval(); 01686 01687 // deprecated - use setWakeDelay 01688 int32_t setSerialWakeDelay(const uint32_t& delay); 01689 // deprecated - use setWakeDelay 01690 uint32_t getSerialWakeDelay(); 01691 01692 // deprecated - use setWakeTimeout 01693 int32_t setSerialReceiveTimeout(const uint16_t& timeout); 01694 // deprecated - use getWakeTimeout 01695 uint16_t getSerialReceiveTimeout(); 01696 01697 void setWakeupCallback(void (*function)(void)); 01698 01699 template<typename T> 01700 void setWakeupCallback(T *object, void (T::*member)(void)) { 01701 _wakeup_callback.attach(object, member); 01702 } 01703 01704 lora::ChannelPlan* getChannelPlan(void); 01705 01706 uint32_t setRx2DataRate(uint8_t dr); 01707 uint8_t getRx2DataRate(); 01708 01709 void mcGroupKeys(uint8_t *mcKeyEncrypt, uint32_t addr, uint8_t groupId, uint32_t frame_count); 01710 private: 01711 void sleep_ms(uint32_t interval, 01712 uint8_t wakeup_mode = RTC_ALARM, 01713 bool deepsleep = true); 01714 01715 mdot_stats _stats; 01716 01717 FunctionPointer _wakeup_callback; 01718 01719 bool _standbyFlag; 01720 bool _testMode; 01721 uint8_t _savedPort; 01722 void handleTestModePacket(); 01723 lora::ChannelPlan* _plan; 01724 }; 01725 01726 #endif
Generated on Tue Jul 12 2022 18:16:26 by
1.7.2
