Multitech xDot Utils

Committer:
lucian@192-168-0-103.rdsnet.ro
Date:
Mon Feb 19 16:11:52 2018 +0200
Revision:
2:8d1c64670642
Parent:
1:73cea350269e
Child:
3:7fa5603c10dc
IEM-380 Refactor raven device into its separate class

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