Multitech xDot Utils
MultitechDot.cpp@1:73cea350269e, 2017-07-20 (annotated)
- Committer:
- lucian@1.0.0.127.in-addr.arpa
- Date:
- Thu Jul 20 16:43:35 2017 +0300
- Revision:
- 1:73cea350269e
- Parent:
- 0:a5748bc6e3e1
- Child:
- 2:8d1c64670642
IEM-249 Update libxDot and mbed-os and fix battery level resetting HSI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 1 | #include "ChannelPlan.h" |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 2 | #include "plans/ChannelPlan_EU868.h" |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 3 | #include "MultitechDot.h" |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 4 | |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 5 | MultitechDot *MultitechDot::getInstance() { |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 6 | using namespace lora; |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 7 | ChannelPlan *plan = new ChannelPlan_EU868(); |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 8 | return (MultitechDot *) mDot::getInstance(plan); |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 9 | } |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 10 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 11 | void MultitechDot::config(uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 12 | uint8_t frequency_sub_band, bool public_network, uint8_t ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 13 | if (!this->getStandbyFlag()) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 14 | logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 15 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 16 | // start from a well-known state |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 17 | logInfo("defaulting Dot configuration"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 18 | this->resetConfig(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 19 | this->resetNetworkSession(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 20 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 21 | // make sure library logging is turned on |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 22 | this->setLogLevel(mts::MTSLog::INFO_LEVEL); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 23 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 24 | // update configuration if necessary |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 25 | if (this->getJoinMode() != this->MANUAL) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 26 | logInfo("changing network join mode to MANUAL"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 27 | if (this->setJoinMode(this->MANUAL) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 28 | logError("failed to set network join mode to MANUAL"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 29 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 30 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 31 | // in MANUAL join mode there is no join request/response transaction |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 32 | // as long as the Dot is configured correctly and provisioned correctly on the gateway, it should be able to communicate |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 33 | // network address - 4 bytes (00000001 - FFFFFFFE) |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 34 | // network session key - 16 bytes |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 35 | // data session key - 16 bytes |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 36 | // to provision your Dot with a Conduit gateway, follow the following steps |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 37 | // * ssh into the Conduit |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 38 | // * provision the Dot using the lora-query application: http://www.multitech.net/developer/software/lora/lora-network-server/ |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 39 | // lora-query -a 01020304 A 0102030401020304 <your Dot's device ID> 01020304010203040102030401020304 01020304010203040102030401020304 |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 40 | // * if you change the network address, network session key, or data session key, make sure you update them on the gateway |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 41 | // to provision your Dot with a 3rd party gateway, see the gateway or network provider documentation |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 42 | this->update_manual_config(network_address, network_session_key, data_session_key, frequency_sub_band, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 43 | public_network, ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 44 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 45 | // save changes to configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 46 | logInfo("saving configuration"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 47 | if (!this->saveConfig()) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 48 | logError("failed to save configuration"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 49 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 50 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 51 | // display configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 52 | this->display_config(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 53 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 54 | // restore the saved session if the dot woke from deepsleep mode |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 55 | // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 56 | logInfo("restoring network session from NVM"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 57 | this->restoreNetworkSession(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 58 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 59 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 60 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 61 | void MultitechDot::display_config() { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 62 | // display configuration and library version information |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 63 | logInfo("====================="); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 64 | logInfo("general configuration"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 65 | logInfo("====================="); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 66 | logInfo("version ------------------ %s", this->getId().c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 67 | logInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(this->getDeviceId()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 68 | logInfo("frequency band ----------- %s", this->FrequencyBandStr(this->getFrequencyBand()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 69 | logInfo("frequency sub band ------- %u", this->getFrequencySubBand()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 70 | logInfo("public network ----------- %s", this->getPublicNetwork() ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 71 | logInfo("========================="); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 72 | logInfo("credentials configuration"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 73 | logInfo("========================="); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 74 | logInfo("device class ------------- %s", this->getClass().c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 75 | logInfo("network join mode -------- %s", this->JoinModeStr(this->getJoinMode()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 76 | if (this->getJoinMode() == this->MANUAL || this->getJoinMode() == this->PEER_TO_PEER) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 77 | logInfo("network address ---------- %s", mts::Text::bin2hexString(this->getNetworkAddress()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 78 | logInfo("network session key------- %s", mts::Text::bin2hexString(this->getNetworkSessionKey()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 79 | logInfo("data session key---------- %s", mts::Text::bin2hexString(this->getDataSessionKey()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 80 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 81 | logInfo("network name ------------- %s", this->getNetworkName().c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 82 | logInfo("network phrase ----------- %s", this->getNetworkPassphrase().c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 83 | logInfo("network EUI -------------- %s", mts::Text::bin2hexString(this->getNetworkId()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 84 | logInfo("network KEY -------------- %s", mts::Text::bin2hexString(this->getNetworkKey()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 85 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 86 | logInfo("========================"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 87 | logInfo("communication parameters"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 88 | logInfo("========================"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 89 | if (this->getJoinMode() == this->PEER_TO_PEER) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 90 | logInfo("TX frequency ------------- %lu", this->getTxFrequency()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 91 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 92 | logInfo("acks --------------------- %s, %u attempts", this->getAck() > 0 ? "on" : "off", this->getAck()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 93 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 94 | logInfo("TX datarate -------------- %s", this->DataRateStr(this->getTxDataRate()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 95 | logInfo("TX power ----------------- %lu dBm", this->getTxPower()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 96 | logInfo("atnenna gain ------------- %u dBm", this->getAntennaGain()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 97 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 98 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 99 | void MultitechDot::update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 100 | uint8_t frequency_sub_band, bool public_network, uint8_t ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 101 | std::string current_network_name = this->getNetworkName(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 102 | std::string current_network_passphrase = this->getNetworkPassphrase(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 103 | uint8_t current_frequency_sub_band = this->getFrequencySubBand(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 104 | bool current_public_network = this->getPublicNetwork(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 105 | uint8_t current_ack = this->getAck(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 106 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 107 | if (current_network_name != network_name) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 108 | logInfo("changing network name from \"%s\" to \"%s\"", current_network_name.c_str(), network_name.c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 109 | if (this->setNetworkName(network_name) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 110 | logError("failed to set network name to \"%s\"", network_name.c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 111 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 112 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 113 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 114 | if (current_network_passphrase != network_passphrase) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 115 | logInfo("changing network passphrase from \"%s\" to \"%s\"", current_network_passphrase.c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 116 | network_passphrase.c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 117 | if (this->setNetworkPassphrase(network_passphrase) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 118 | logError("failed to set network passphrase to \"%s\"", network_passphrase.c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 119 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 120 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 121 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 122 | if (current_frequency_sub_band != frequency_sub_band) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 123 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 124 | if (this->setFrequencySubBand(frequency_sub_band) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 125 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 126 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 127 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 128 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 129 | if (current_public_network != public_network) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 130 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 131 | public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 132 | if (this->setPublicNetwork(public_network) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 133 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 134 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 135 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 136 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 137 | if (current_ack != ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 138 | logInfo("changing acks from %u to %u", current_ack, ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 139 | if (this->setAck(ack) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 140 | logError("failed to set acks to %u", ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 141 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 142 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 143 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 144 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 145 | void MultitechDot::update_ota_config_id_key(uint8_t *network_id, uint8_t *network_key, uint8_t frequency_sub_band, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 146 | bool public_network, uint8_t ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 147 | std::vector<uint8_t> current_network_id = this->getNetworkId(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 148 | std::vector<uint8_t> current_network_key = this->getNetworkKey(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 149 | uint8_t current_frequency_sub_band = this->getFrequencySubBand(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 150 | bool current_public_network = this->getPublicNetwork(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 151 | uint8_t current_ack = this->getAck(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 152 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 153 | std::vector<uint8_t> network_id_vector(network_id, network_id + 8); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 154 | std::vector<uint8_t> network_key_vector(network_key, network_key + 16); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 155 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 156 | if (current_network_id != network_id_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 157 | logInfo("changing network ID from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_id).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 158 | mts::Text::bin2hexString(network_id_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 159 | if (this->setNetworkId(network_id_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 160 | logError("failed to set network ID to \"%s\"", mts::Text::bin2hexString(network_id_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 161 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 162 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 163 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 164 | if (current_network_key != network_key_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 165 | logInfo("changing network KEY from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_key).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 166 | mts::Text::bin2hexString(network_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 167 | if (this->setNetworkKey(network_key_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 168 | logError("failed to set network KEY to \"%s\"", mts::Text::bin2hexString(network_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 169 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 170 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 171 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 172 | if (current_frequency_sub_band != frequency_sub_band) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 173 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 174 | if (this->setFrequencySubBand(frequency_sub_band) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 175 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 176 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 177 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 178 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 179 | if (current_public_network != public_network) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 180 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 181 | public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 182 | if (this->setPublicNetwork(public_network) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 183 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 184 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 185 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 186 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 187 | if (current_ack != ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 188 | logInfo("changing acks from %u to %u", current_ack, ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 189 | if (this->setAck(ack) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 190 | logError("failed to set acks to %u", ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 191 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 192 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 193 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 194 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 195 | void MultitechDot::update_manual_config( |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 196 | uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 197 | uint8_t frequency_sub_band, bool public_network, uint8_t ack |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 198 | ) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 199 | std::vector<uint8_t> current_network_address = this->getNetworkAddress(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 200 | std::vector<uint8_t> current_network_session_key = this->getNetworkSessionKey(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 201 | std::vector<uint8_t> current_data_session_key = this->getDataSessionKey(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 202 | uint8_t current_frequency_sub_band = this->getFrequencySubBand(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 203 | bool current_public_network = this->getPublicNetwork(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 204 | uint8_t current_ack = this->getAck(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 205 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 206 | std::vector<uint8_t> network_address_vector(network_address, network_address + 4); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 207 | std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 208 | std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 209 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 210 | if (current_network_address != network_address_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 211 | logInfo("changing network address from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 212 | mts::Text::bin2hexString(current_network_address).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 213 | mts::Text::bin2hexString(network_address_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 214 | if (this->setNetworkAddress(network_address_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 215 | logError("failed to set network address to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 216 | mts::Text::bin2hexString(network_address_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 217 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 218 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 219 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 220 | if (current_network_session_key != network_session_key_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 221 | logInfo("changing network session key from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 222 | mts::Text::bin2hexString(current_network_session_key).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 223 | mts::Text::bin2hexString(network_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 224 | if (this->setNetworkSessionKey(network_session_key_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 225 | logError("failed to set network session key to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 226 | mts::Text::bin2hexString(network_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 227 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 228 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 229 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 230 | if (current_data_session_key != data_session_key_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 231 | logInfo("changing data session key from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 232 | mts::Text::bin2hexString(current_data_session_key).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 233 | mts::Text::bin2hexString(data_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 234 | if (this->setDataSessionKey(data_session_key_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 235 | logError("failed to set data session key to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 236 | mts::Text::bin2hexString(data_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 237 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 238 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 239 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 240 | if (current_frequency_sub_band != frequency_sub_band) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 241 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 242 | if (this->setFrequencySubBand(frequency_sub_band) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 243 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 244 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 245 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 246 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 247 | if (current_public_network != public_network) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 248 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 249 | public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 250 | if (this->setPublicNetwork(public_network) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 251 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 252 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 253 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 254 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 255 | if (current_ack != ack) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 256 | logInfo("changing acks from %u to %u", current_ack, ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 257 | if (this->setAck(ack) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 258 | logError("failed to set acks to %u", ack); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 259 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 260 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 261 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 262 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 263 | void MultitechDot::update_peer_to_peer_config(uint8_t *network_address, uint8_t *network_session_key, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 264 | uint8_t *data_session_key, uint32_t tx_frequency, uint8_t tx_datarate, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 265 | uint8_t tx_power) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 266 | std::vector<uint8_t> current_network_address = this->getNetworkAddress(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 267 | std::vector<uint8_t> current_network_session_key = this->getNetworkSessionKey(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 268 | std::vector<uint8_t> current_data_session_key = this->getDataSessionKey(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 269 | uint32_t current_tx_frequency = this->getTxFrequency(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 270 | uint8_t current_tx_datarate = this->getTxDataRate(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 271 | uint8_t current_tx_power = this->getTxPower(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 272 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 273 | std::vector<uint8_t> network_address_vector(network_address, network_address + 4); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 274 | std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 275 | std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 276 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 277 | if (current_network_address != network_address_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 278 | logInfo("changing network address from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 279 | mts::Text::bin2hexString(current_network_address).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 280 | mts::Text::bin2hexString(network_address_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 281 | if (this->setNetworkAddress(network_address_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 282 | logError("failed to set network address to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 283 | mts::Text::bin2hexString(network_address_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 284 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 285 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 286 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 287 | if (current_network_session_key != network_session_key_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 288 | logInfo("changing network session key from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 289 | mts::Text::bin2hexString(current_network_session_key).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 290 | mts::Text::bin2hexString(network_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 291 | if (this->setNetworkSessionKey(network_session_key_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 292 | logError("failed to set network session key to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 293 | mts::Text::bin2hexString(network_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 294 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 295 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 296 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 297 | if (current_data_session_key != data_session_key_vector) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 298 | logInfo("changing data session key from \"%s\" to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 299 | mts::Text::bin2hexString(current_data_session_key).c_str(), |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 300 | mts::Text::bin2hexString(data_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 301 | if (this->setDataSessionKey(data_session_key_vector) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 302 | logError("failed to set data session key to \"%s\"", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 303 | mts::Text::bin2hexString(data_session_key_vector).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 304 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 305 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 306 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 307 | if (current_tx_frequency != tx_frequency) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 308 | logInfo("changing TX frequency from %lu to %lu", current_tx_frequency, tx_frequency); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 309 | if (this->setTxFrequency(tx_frequency) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 310 | logError("failed to set TX frequency to %lu", tx_frequency); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 311 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 312 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 313 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 314 | if (current_tx_datarate != tx_datarate) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 315 | logInfo("changing TX datarate from %u to %u", current_tx_datarate, tx_datarate); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 316 | if (this->setTxDataRate(tx_datarate) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 317 | logError("failed to set TX datarate to %u", tx_datarate); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 318 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 319 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 320 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 321 | if (current_tx_power != tx_power) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 322 | logInfo("changing TX power from %u to %u", current_tx_power, tx_power); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 323 | if (this->setTxPower(tx_power) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 324 | logError("failed to set TX power to %u", tx_power); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 325 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 326 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 327 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 328 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 329 | void MultitechDot::update_network_link_check_config(uint8_t link_check_count, uint8_t link_check_threshold) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 330 | uint8_t current_link_check_count = this->getLinkCheckCount(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 331 | uint8_t current_link_check_threshold = this->getLinkCheckThreshold(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 332 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 333 | if (current_link_check_count != link_check_count) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 334 | logInfo("changing link check count from %u to %u", current_link_check_count, link_check_count); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 335 | if (this->setLinkCheckCount(link_check_count) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 336 | logError("failed to set link check count to %u", link_check_count); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 337 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 338 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 339 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 340 | if (current_link_check_threshold != link_check_threshold) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 341 | logInfo("changing link check threshold from %u to %u", current_link_check_threshold, link_check_threshold); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 342 | if (this->setLinkCheckThreshold(link_check_threshold) != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 343 | logError("failed to set link check threshold to %u", link_check_threshold); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 344 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 345 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 346 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 347 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 348 | void MultitechDot::join_network() { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 349 | int32_t j_attempts = 0; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 350 | int32_t ret = this->MDOT_ERROR; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 351 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 352 | // attempt to join the network |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 353 | while (ret != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 354 | logInfo("attempt %d to join network", ++j_attempts); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 355 | ret = this->joinNetwork(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 356 | if (ret != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 357 | logError("failed to join network %d:%s", ret, this->getReturnCodeString(ret).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 358 | // in some frequency bands we need to wait until another channel is available before transmitting again |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 359 | uint32_t delay_s = (this->getNextTxMs() / 1000) + 1; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 360 | if (delay_s < 2) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 361 | logInfo("waiting %lu s until next free channel", delay_s); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 362 | wait(delay_s); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 363 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 364 | logInfo("sleeping %lu s until next free channel", delay_s); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 365 | this->sleep(delay_s, this->RTC_ALARM, false); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 366 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 367 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 368 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 369 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 370 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 371 | void MultitechDot::deep_sleep(uint32_t min_delay_s) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 372 | uint32_t delay_s = this->getNextTxMs() / 1000; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 373 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 374 | // save the session so we don't need to join again after waking up |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 375 | // not necessary if going into sleep mode since RAM is retained |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 376 | logInfo("saving network session to NVM"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 377 | this->saveNetworkSession(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 378 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 379 | if (delay_s < min_delay_s) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 380 | delay_s = min_delay_s; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 381 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 382 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 383 | logInfo("deepsleeping %lus", delay_s); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 384 | logInfo("application will execute from beginning after waking up"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 385 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 386 | // go to deepsleep for delay_s seconds and wake using the RTC alarm |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 387 | this->sleep(delay_s, this->RTC_ALARM, true); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 388 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 389 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 390 | void MultitechDot::sleep_wake_rtc_only(bool deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 391 | // in some frequency bands we need to wait until another channel is available before transmitting again |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 392 | // wait at least 10s between transmissions |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 393 | uint32_t delay_s = this->getNextTxMs() / 1000; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 394 | if (delay_s < 10) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 395 | delay_s = 10; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 396 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 397 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 398 | logInfo("%ssleeping %lus", deepsleep ? "deep" : "", delay_s); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 399 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 400 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 401 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 402 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 403 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 404 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 405 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 406 | // steps are: |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 407 | // * save IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 408 | // * configure IOs to reduce current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 409 | // * sleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 410 | // * restore IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 411 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 412 | // save the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 413 | sleep_save_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 414 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 415 | // configure GPIOs for lowest current |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 416 | sleep_configure_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 417 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 418 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 419 | // go to sleep/deepsleep for delay_s seconds and wake using the RTC alarm |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 420 | this->sleep(delay_s, this->RTC_ALARM, deepsleep); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 421 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 422 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 423 | // restore the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 424 | sleep_restore_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 425 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 426 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 427 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 428 | void MultitechDot::sleep_wake_interrupt_only(bool deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 429 | if (deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 430 | // for xDot, WAKE pin (connected to S2 on xDot-DK) is the only pin that can wake the processor from deepsleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 431 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the mDot::sleep call |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 432 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 433 | // configure WAKE pin (connected to S2 on xDot-DK) as the pin that will wake the xDot from low power modes |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 434 | // other pins can be confgured instead: GPIO0-3 or UART_RX |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 435 | this->setWakePin(WAKE); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 436 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 437 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 438 | logInfo("%ssleeping until interrupt on %s pin", deepsleep ? "deep" : "", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 439 | deepsleep ? "WAKE" : this->pinName2Str(this->getWakePin()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 440 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 441 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 442 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 443 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 444 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 445 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 446 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 447 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 448 | // steps are: |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 449 | // * save IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 450 | // * configure IOs to reduce current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 451 | // * sleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 452 | // * restore IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 453 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 454 | // save the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 455 | this->sleep_save_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 456 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 457 | // configure GPIOs for lowest current |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 458 | this->sleep_configure_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 459 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 460 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 461 | // go to sleep/deepsleep and wake on rising edge of configured wake pin (only the WAKE pin in deepsleep) |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 462 | // since we're not waking on the RTC alarm, the interval is ignored |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 463 | this->sleep(0, this->INTERRUPT, deepsleep); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 464 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 465 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 466 | // restore the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 467 | this->sleep_restore_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 468 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 469 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 470 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 471 | void MultitechDot::sleep_wake_rtc_or_interrupt(uint32_t delay_s, bool deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 472 | if (deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 473 | // for xDot, WAKE pin (connected to S2 on xDot-DK) is the only pin that can wake the processor from deepsleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 474 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the this->sleep call |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 475 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 476 | // configure WAKE pin (connected to S2 on xDot-DK) as the pin that will wake the xDot from low power modes |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 477 | // other pins can be confgured instead: GPIO0-3 or UART_RX |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 478 | this->setWakePin(WAKE); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 479 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 480 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 481 | logInfo("%ssleeping %lus or until interrupt on %s pin", deepsleep ? "deep" : "", delay_s, |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 482 | deepsleep ? "WAKE" : this->pinName2Str(this->getWakePin()).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 483 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 484 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 485 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 486 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 487 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 488 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 489 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 490 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 491 | // steps are: |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 492 | // * save IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 493 | // * configure IOs to reduce current consumption |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 494 | // * sleep |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 495 | // * restore IO configuration |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 496 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 497 | // save the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 498 | this->sleep_save_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 499 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 500 | // configure GPIOs for lowest current |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 501 | this->sleep_configure_io(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 502 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 503 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 504 | // go to sleep/deepsleep and wake using the RTC alarm after delay_s seconds or rising edge of configured wake pin (only the WAKE pin in deepsleep) |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 505 | // whichever comes first will wake the xDot |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 506 | this->sleep(delay_s, this->RTC_ALARM_OR_INTERRUPT, deepsleep); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 507 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 508 | if (!deepsleep) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 509 | // restore the GPIO state. |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 510 | this->sleep_restore_io(); |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 511 | this->sleep_reset_hsi(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 512 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 513 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 514 | |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 515 | void MultitechDot::sleep_reset_hsi() { |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 516 | // Enable the HSI (to clock the ADC) |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 517 | RCC_OscInitTypeDef RCC_OscInitStruct; |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 518 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 519 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 520 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 521 | HAL_RCC_OscConfig(&RCC_OscInitStruct); |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 522 | } |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 523 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 524 | void MultitechDot::sleep_save_io() { |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 525 | logInfo("Save GPIO states"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 526 | xdot_save_gpio_state(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 527 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 528 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 529 | void MultitechDot::sleep_configure_io() { |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 530 | logInfo("Configure GPIO for lowest current"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 531 | // GPIO Ports Clock Enable |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 532 | __GPIOA_CLK_ENABLE(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 533 | __GPIOB_CLK_ENABLE(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 534 | __GPIOC_CLK_ENABLE(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 535 | __GPIOH_CLK_ENABLE(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 536 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 537 | GPIO_InitTypeDef GPIO_InitStruct; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 538 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 539 | // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 540 | GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 541 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 542 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 543 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 544 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 545 | // I2C_SDA & I2C_SCL to analog nopull |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 546 | GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 547 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 548 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 549 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 550 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 551 | // SPI_MOSI, SPI_MISO, SPI_SCK, & SPI_NSS to analog nopull |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 552 | GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 553 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 554 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 555 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 556 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 557 | // iterate through potential wake pins - leave the configured wake pin alone if one is needed |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 558 | if (this->getWakePin() != WAKE || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 559 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 560 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 561 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 562 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 563 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 564 | if (this->getWakePin() != GPIO0 || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 565 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 566 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 567 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 568 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 569 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 570 | if (this->getWakePin() != GPIO1 || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 571 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 572 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 573 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 574 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 575 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 576 | if (this->getWakePin() != GPIO2 || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 577 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 578 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 579 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 580 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 581 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 582 | if (this->getWakePin() != GPIO3 || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 583 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 584 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 585 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 586 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 587 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 588 | if (this->getWakePin() != UART1_RX || this->getWakeMode() == this->RTC_ALARM) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 589 | GPIO_InitStruct.Pin = GPIO_PIN_10; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 590 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 591 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 592 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 593 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 594 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 595 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 596 | void MultitechDot::sleep_restore_io() { |
lucian@1.0.0.127.in-addr.arpa | 1:73cea350269e | 597 | logInfo("Restore GPIO states"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 598 | xdot_restore_gpio_state(); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 599 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 600 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 601 | void MultitechDot::send_data(std::vector<uint8_t> data) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 602 | uint32_t ret; |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 603 | |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 604 | ret = this->send(data); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 605 | if (ret != this->MDOT_OK) { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 606 | logError("failed to send data to %s [%d][%s]", this->getJoinMode() == this->PEER_TO_PEER ? "peer" : "gateway", |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 607 | ret, this->getReturnCodeString(ret).c_str()); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 608 | } else { |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 609 | logInfo("successfully sent data to %s", this->getJoinMode() == this->PEER_TO_PEER ? "peer" : "gateway"); |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 610 | } |
lucian@1.0.0.127.in-addr.arpa | 0:a5748bc6e3e1 | 611 | } |