Multitech xDot Utils

Committer:
lucian@1.0.0.127.in-addr.arpa
Date:
Mon May 15 00:59:32 2017 +0300
Revision:
0:a5748bc6e3e1
Child:
1:73cea350269e
Add multitech dot utils

Who changed what in which revision?

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