Multitech xDot Utils

Committer:
lucian@192-168-0-108.rdsnet.ro
Date:
Wed Feb 21 12:52:15 2018 +0200
Revision:
3:7fa5603c10dc
Parent:
2:8d1c64670642
Child:
4:db99b2a7d062
Add duty cycle config and remove unimplemented methods

Who changed what in which revision?

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