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