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