Example of using the mDot UDK with the X-NUCLEO-IKS01A2 board
Dependencies: MTS_X_NUCLEO_IKS01A2 libmDot-mbed5
Fork of mDot-IKS01A1 by
dot_util.cpp@13:e165a137c3af, 2018-01-26 (annotated)
- Committer:
- pferland
- Date:
- Fri Jan 26 17:53:23 2018 +0000
- Revision:
- 13:e165a137c3af
- Parent:
- 12:63e90d375afd
Updated to libmdot 3.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pferland | 0:9e88a9018fc0 | 1 | #include "dot_util.h" |
pferland | 0:9e88a9018fc0 | 2 | #if defined(TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 3 | #include "xdot_low_power.h" |
pferland | 0:9e88a9018fc0 | 4 | #endif |
pferland | 0:9e88a9018fc0 | 5 | |
pferland | 0:9e88a9018fc0 | 6 | #if defined(TARGET_MTS_MDOT_F411RE) |
pferland | 0:9e88a9018fc0 | 7 | uint32_t portA[6]; |
pferland | 0:9e88a9018fc0 | 8 | uint32_t portB[6]; |
pferland | 0:9e88a9018fc0 | 9 | uint32_t portC[6]; |
pferland | 0:9e88a9018fc0 | 10 | uint32_t portD[6]; |
pferland | 0:9e88a9018fc0 | 11 | uint32_t portH[6]; |
pferland | 0:9e88a9018fc0 | 12 | #endif |
pferland | 0:9e88a9018fc0 | 13 | |
pferland | 0:9e88a9018fc0 | 14 | |
pferland | 0:9e88a9018fc0 | 15 | void display_config() { |
pferland | 0:9e88a9018fc0 | 16 | // display configuration and library version information |
pferland | 0:9e88a9018fc0 | 17 | logInfo("====================="); |
pferland | 0:9e88a9018fc0 | 18 | logInfo("general configuration"); |
pferland | 0:9e88a9018fc0 | 19 | logInfo("====================="); |
pferland | 0:9e88a9018fc0 | 20 | logInfo("version ------------------ %s", dot->getId().c_str()); |
pferland | 0:9e88a9018fc0 | 21 | logInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(dot->getDeviceId()).c_str()); |
pferland | 13:e165a137c3af | 22 | logInfo("default channel plan ----- %s", mDot::FrequencyBandStr(dot->getDefaultFrequencyBand()).c_str()); |
pferland | 13:e165a137c3af | 23 | logInfo("current channel plan ----- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str()); |
pferland | 13:e165a137c3af | 24 | if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { |
pferland | 0:9e88a9018fc0 | 25 | logInfo("frequency sub band ------- %u", dot->getFrequencySubBand()); |
pferland | 0:9e88a9018fc0 | 26 | } |
pferland | 0:9e88a9018fc0 | 27 | logInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 28 | logInfo("========================="); |
pferland | 0:9e88a9018fc0 | 29 | logInfo("credentials configuration"); |
pferland | 0:9e88a9018fc0 | 30 | logInfo("========================="); |
pferland | 0:9e88a9018fc0 | 31 | logInfo("device class ------------- %s", dot->getClass().c_str()); |
pferland | 0:9e88a9018fc0 | 32 | logInfo("network join mode -------- %s", mDot::JoinModeStr(dot->getJoinMode()).c_str()); |
pferland | 0:9e88a9018fc0 | 33 | if (dot->getJoinMode() == mDot::MANUAL || dot->getJoinMode() == mDot::PEER_TO_PEER) { |
pferland | 0:9e88a9018fc0 | 34 | logInfo("network address ---------- %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str()); |
pferland | 0:9e88a9018fc0 | 35 | logInfo("network session key------- %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str()); |
pferland | 0:9e88a9018fc0 | 36 | logInfo("data session key---------- %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str()); |
pferland | 0:9e88a9018fc0 | 37 | } else { |
pferland | 0:9e88a9018fc0 | 38 | logInfo("network name ------------- %s", dot->getNetworkName().c_str()); |
pferland | 0:9e88a9018fc0 | 39 | logInfo("network phrase ----------- %s", dot->getNetworkPassphrase().c_str()); |
pferland | 0:9e88a9018fc0 | 40 | logInfo("network EUI -------------- %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str()); |
pferland | 0:9e88a9018fc0 | 41 | logInfo("network KEY -------------- %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str()); |
pferland | 0:9e88a9018fc0 | 42 | } |
pferland | 0:9e88a9018fc0 | 43 | logInfo("========================"); |
pferland | 0:9e88a9018fc0 | 44 | logInfo("communication parameters"); |
pferland | 0:9e88a9018fc0 | 45 | logInfo("========================"); |
pferland | 0:9e88a9018fc0 | 46 | if (dot->getJoinMode() == mDot::PEER_TO_PEER) { |
pferland | 0:9e88a9018fc0 | 47 | logInfo("TX frequency ------------- %lu", dot->getTxFrequency()); |
pferland | 0:9e88a9018fc0 | 48 | } else { |
pferland | 0:9e88a9018fc0 | 49 | logInfo("acks --------------------- %s, %u attempts", dot->getAck() > 0 ? "on" : "off", dot->getAck()); |
pferland | 0:9e88a9018fc0 | 50 | } |
pferland | 0:9e88a9018fc0 | 51 | logInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str()); |
pferland | 0:9e88a9018fc0 | 52 | logInfo("TX power ----------------- %lu dBm", dot->getTxPower()); |
pferland | 13:e165a137c3af | 53 | logInfo("antenna gain ------------- %u dBm", dot->getAntennaGain()); |
pferland | 13:e165a137c3af | 54 | logInfo("LBT ---------------------- %s", dot->getLbtTimeUs() ? "on" : "off"); |
pferland | 13:e165a137c3af | 55 | if (dot->getLbtTimeUs()) { |
pferland | 13:e165a137c3af | 56 | logInfo("LBT time ----------------- %lu us", dot->getLbtTimeUs()); |
pferland | 13:e165a137c3af | 57 | logInfo("LBT threshold ------------ %d dBm", dot->getLbtThreshold()); |
pferland | 13:e165a137c3af | 58 | } |
pferland | 0:9e88a9018fc0 | 59 | } |
pferland | 0:9e88a9018fc0 | 60 | |
pferland | 0:9e88a9018fc0 | 61 | void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { |
pferland | 0:9e88a9018fc0 | 62 | std::string current_network_name = dot->getNetworkName(); |
pferland | 0:9e88a9018fc0 | 63 | std::string current_network_passphrase = dot->getNetworkPassphrase(); |
pferland | 0:9e88a9018fc0 | 64 | uint8_t current_frequency_sub_band = dot->getFrequencySubBand(); |
pferland | 0:9e88a9018fc0 | 65 | bool current_public_network = dot->getPublicNetwork(); |
pferland | 0:9e88a9018fc0 | 66 | uint8_t current_ack = dot->getAck(); |
pferland | 0:9e88a9018fc0 | 67 | |
pferland | 0:9e88a9018fc0 | 68 | if (current_network_name != network_name) { |
pferland | 0:9e88a9018fc0 | 69 | logInfo("changing network name from \"%s\" to \"%s\"", current_network_name.c_str(), network_name.c_str()); |
pferland | 0:9e88a9018fc0 | 70 | if (dot->setNetworkName(network_name) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 71 | logError("failed to set network name to \"%s\"", network_name.c_str()); |
pferland | 0:9e88a9018fc0 | 72 | } |
pferland | 0:9e88a9018fc0 | 73 | } |
pferland | 0:9e88a9018fc0 | 74 | |
pferland | 0:9e88a9018fc0 | 75 | if (current_network_passphrase != network_passphrase) { |
pferland | 0:9e88a9018fc0 | 76 | logInfo("changing network passphrase from \"%s\" to \"%s\"", current_network_passphrase.c_str(), network_passphrase.c_str()); |
pferland | 0:9e88a9018fc0 | 77 | if (dot->setNetworkPassphrase(network_passphrase) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 78 | logError("failed to set network passphrase to \"%s\"", network_passphrase.c_str()); |
pferland | 0:9e88a9018fc0 | 79 | } |
pferland | 0:9e88a9018fc0 | 80 | } |
pferland | 0:9e88a9018fc0 | 81 | |
pferland | 13:e165a137c3af | 82 | if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { |
pferland | 13:e165a137c3af | 83 | if (current_frequency_sub_band != frequency_sub_band) { |
pferland | 13:e165a137c3af | 84 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
pferland | 13:e165a137c3af | 85 | if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { |
pferland | 13:e165a137c3af | 86 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
pferland | 13:e165a137c3af | 87 | } |
pferland | 13:e165a137c3af | 88 | } |
pferland | 0:9e88a9018fc0 | 89 | } |
pferland | 0:9e88a9018fc0 | 90 | |
pferland | 0:9e88a9018fc0 | 91 | if (current_public_network != public_network) { |
pferland | 0:9e88a9018fc0 | 92 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 93 | if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 94 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 95 | } |
pferland | 0:9e88a9018fc0 | 96 | } |
pferland | 0:9e88a9018fc0 | 97 | |
pferland | 0:9e88a9018fc0 | 98 | if (current_ack != ack) { |
pferland | 0:9e88a9018fc0 | 99 | logInfo("changing acks from %u to %u", current_ack, ack); |
pferland | 0:9e88a9018fc0 | 100 | if (dot->setAck(ack) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 101 | logError("failed to set acks to %u", ack); |
pferland | 0:9e88a9018fc0 | 102 | } |
pferland | 0:9e88a9018fc0 | 103 | } |
pferland | 0:9e88a9018fc0 | 104 | } |
pferland | 0:9e88a9018fc0 | 105 | |
pferland | 0:9e88a9018fc0 | 106 | void update_ota_config_id_key(uint8_t *network_id, uint8_t *network_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { |
pferland | 0:9e88a9018fc0 | 107 | std::vector<uint8_t> current_network_id = dot->getNetworkId(); |
pferland | 0:9e88a9018fc0 | 108 | std::vector<uint8_t> current_network_key = dot->getNetworkKey(); |
pferland | 0:9e88a9018fc0 | 109 | uint8_t current_frequency_sub_band = dot->getFrequencySubBand(); |
pferland | 0:9e88a9018fc0 | 110 | bool current_public_network = dot->getPublicNetwork(); |
pferland | 0:9e88a9018fc0 | 111 | uint8_t current_ack = dot->getAck(); |
pferland | 0:9e88a9018fc0 | 112 | |
pferland | 0:9e88a9018fc0 | 113 | std::vector<uint8_t> network_id_vector(network_id, network_id + 8); |
pferland | 0:9e88a9018fc0 | 114 | std::vector<uint8_t> network_key_vector(network_key, network_key + 16); |
pferland | 0:9e88a9018fc0 | 115 | |
pferland | 0:9e88a9018fc0 | 116 | if (current_network_id != network_id_vector) { |
pferland | 0:9e88a9018fc0 | 117 | logInfo("changing network ID from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_id).c_str(), mts::Text::bin2hexString(network_id_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 118 | if (dot->setNetworkId(network_id_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 119 | logError("failed to set network ID to \"%s\"", mts::Text::bin2hexString(network_id_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 120 | } |
pferland | 0:9e88a9018fc0 | 121 | } |
pferland | 0:9e88a9018fc0 | 122 | |
pferland | 0:9e88a9018fc0 | 123 | if (current_network_key != network_key_vector) { |
pferland | 0:9e88a9018fc0 | 124 | logInfo("changing network KEY from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_key).c_str(), mts::Text::bin2hexString(network_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 125 | if (dot->setNetworkKey(network_key_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 126 | logError("failed to set network KEY to \"%s\"", mts::Text::bin2hexString(network_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 127 | } |
pferland | 0:9e88a9018fc0 | 128 | } |
pferland | 0:9e88a9018fc0 | 129 | |
pferland | 13:e165a137c3af | 130 | if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { |
pferland | 13:e165a137c3af | 131 | if (current_frequency_sub_band != frequency_sub_band) { |
pferland | 13:e165a137c3af | 132 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
pferland | 13:e165a137c3af | 133 | if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { |
pferland | 13:e165a137c3af | 134 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
pferland | 13:e165a137c3af | 135 | } |
pferland | 13:e165a137c3af | 136 | } |
pferland | 0:9e88a9018fc0 | 137 | } |
pferland | 0:9e88a9018fc0 | 138 | |
pferland | 0:9e88a9018fc0 | 139 | if (current_public_network != public_network) { |
pferland | 0:9e88a9018fc0 | 140 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 141 | if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 142 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 143 | } |
pferland | 0:9e88a9018fc0 | 144 | } |
pferland | 0:9e88a9018fc0 | 145 | |
pferland | 0:9e88a9018fc0 | 146 | if (current_ack != ack) { |
pferland | 0:9e88a9018fc0 | 147 | logInfo("changing acks from %u to %u", current_ack, ack); |
pferland | 0:9e88a9018fc0 | 148 | if (dot->setAck(ack) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 149 | logError("failed to set acks to %u", ack); |
pferland | 0:9e88a9018fc0 | 150 | } |
pferland | 0:9e88a9018fc0 | 151 | } |
pferland | 0:9e88a9018fc0 | 152 | } |
pferland | 0:9e88a9018fc0 | 153 | |
pferland | 0:9e88a9018fc0 | 154 | void update_manual_config(uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { |
pferland | 0:9e88a9018fc0 | 155 | std::vector<uint8_t> current_network_address = dot->getNetworkAddress(); |
pferland | 0:9e88a9018fc0 | 156 | std::vector<uint8_t> current_network_session_key = dot->getNetworkSessionKey(); |
pferland | 0:9e88a9018fc0 | 157 | std::vector<uint8_t> current_data_session_key = dot->getDataSessionKey(); |
pferland | 0:9e88a9018fc0 | 158 | uint8_t current_frequency_sub_band = dot->getFrequencySubBand(); |
pferland | 0:9e88a9018fc0 | 159 | bool current_public_network = dot->getPublicNetwork(); |
pferland | 0:9e88a9018fc0 | 160 | uint8_t current_ack = dot->getAck(); |
pferland | 0:9e88a9018fc0 | 161 | |
pferland | 0:9e88a9018fc0 | 162 | std::vector<uint8_t> network_address_vector(network_address, network_address + 4); |
pferland | 0:9e88a9018fc0 | 163 | std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16); |
pferland | 0:9e88a9018fc0 | 164 | std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16); |
pferland | 0:9e88a9018fc0 | 165 | |
pferland | 0:9e88a9018fc0 | 166 | if (current_network_address != network_address_vector) { |
pferland | 0:9e88a9018fc0 | 167 | logInfo("changing network address from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_address).c_str(), mts::Text::bin2hexString(network_address_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 168 | if (dot->setNetworkAddress(network_address_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 169 | logError("failed to set network address to \"%s\"", mts::Text::bin2hexString(network_address_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 170 | } |
pferland | 0:9e88a9018fc0 | 171 | } |
pferland | 0:9e88a9018fc0 | 172 | |
pferland | 0:9e88a9018fc0 | 173 | if (current_network_session_key != network_session_key_vector) { |
pferland | 0:9e88a9018fc0 | 174 | logInfo("changing network session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_session_key).c_str(), mts::Text::bin2hexString(network_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 175 | if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 176 | logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 177 | } |
pferland | 0:9e88a9018fc0 | 178 | } |
pferland | 0:9e88a9018fc0 | 179 | |
pferland | 0:9e88a9018fc0 | 180 | if (current_data_session_key != data_session_key_vector) { |
pferland | 0:9e88a9018fc0 | 181 | logInfo("changing data session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_data_session_key).c_str(), mts::Text::bin2hexString(data_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 182 | if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 183 | logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 184 | } |
pferland | 0:9e88a9018fc0 | 185 | } |
pferland | 0:9e88a9018fc0 | 186 | |
pferland | 0:9e88a9018fc0 | 187 | if (current_frequency_sub_band != frequency_sub_band) { |
pferland | 0:9e88a9018fc0 | 188 | logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); |
pferland | 0:9e88a9018fc0 | 189 | if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 190 | logError("failed to set frequency sub band to %u", frequency_sub_band); |
pferland | 0:9e88a9018fc0 | 191 | } |
pferland | 0:9e88a9018fc0 | 192 | } |
pferland | 0:9e88a9018fc0 | 193 | |
pferland | 0:9e88a9018fc0 | 194 | if (current_public_network != public_network) { |
pferland | 0:9e88a9018fc0 | 195 | logInfo("changing public network from %s to %s", current_public_network ? "on" : "off", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 196 | if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 197 | logError("failed to set public network to %s", public_network ? "on" : "off"); |
pferland | 0:9e88a9018fc0 | 198 | } |
pferland | 0:9e88a9018fc0 | 199 | } |
pferland | 0:9e88a9018fc0 | 200 | |
pferland | 0:9e88a9018fc0 | 201 | if (current_ack != ack) { |
pferland | 0:9e88a9018fc0 | 202 | logInfo("changing acks from %u to %u", current_ack, ack); |
pferland | 0:9e88a9018fc0 | 203 | if (dot->setAck(ack) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 204 | logError("failed to set acks to %u", ack); |
pferland | 0:9e88a9018fc0 | 205 | } |
pferland | 0:9e88a9018fc0 | 206 | } |
pferland | 0:9e88a9018fc0 | 207 | } |
pferland | 0:9e88a9018fc0 | 208 | |
pferland | 0:9e88a9018fc0 | 209 | void update_peer_to_peer_config(uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key, uint32_t tx_frequency, uint8_t tx_datarate, uint8_t tx_power) { |
pferland | 0:9e88a9018fc0 | 210 | std::vector<uint8_t> current_network_address = dot->getNetworkAddress(); |
pferland | 0:9e88a9018fc0 | 211 | std::vector<uint8_t> current_network_session_key = dot->getNetworkSessionKey(); |
pferland | 0:9e88a9018fc0 | 212 | std::vector<uint8_t> current_data_session_key = dot->getDataSessionKey(); |
pferland | 0:9e88a9018fc0 | 213 | uint32_t current_tx_frequency = dot->getTxFrequency(); |
pferland | 0:9e88a9018fc0 | 214 | uint8_t current_tx_datarate = dot->getTxDataRate(); |
pferland | 0:9e88a9018fc0 | 215 | uint8_t current_tx_power = dot->getTxPower(); |
pferland | 0:9e88a9018fc0 | 216 | |
pferland | 0:9e88a9018fc0 | 217 | std::vector<uint8_t> network_address_vector(network_address, network_address + 4); |
pferland | 0:9e88a9018fc0 | 218 | std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16); |
pferland | 0:9e88a9018fc0 | 219 | std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16); |
pferland | 0:9e88a9018fc0 | 220 | |
pferland | 0:9e88a9018fc0 | 221 | if (current_network_address != network_address_vector) { |
pferland | 0:9e88a9018fc0 | 222 | logInfo("changing network address from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_address).c_str(), mts::Text::bin2hexString(network_address_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 223 | if (dot->setNetworkAddress(network_address_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 224 | logError("failed to set network address to \"%s\"", mts::Text::bin2hexString(network_address_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 225 | } |
pferland | 0:9e88a9018fc0 | 226 | } |
pferland | 0:9e88a9018fc0 | 227 | |
pferland | 0:9e88a9018fc0 | 228 | if (current_network_session_key != network_session_key_vector) { |
pferland | 0:9e88a9018fc0 | 229 | logInfo("changing network session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_session_key).c_str(), mts::Text::bin2hexString(network_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 230 | if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 231 | logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 232 | } |
pferland | 0:9e88a9018fc0 | 233 | } |
pferland | 0:9e88a9018fc0 | 234 | |
pferland | 0:9e88a9018fc0 | 235 | if (current_data_session_key != data_session_key_vector) { |
pferland | 0:9e88a9018fc0 | 236 | logInfo("changing data session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_data_session_key).c_str(), mts::Text::bin2hexString(data_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 237 | if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 238 | logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str()); |
pferland | 0:9e88a9018fc0 | 239 | } |
pferland | 0:9e88a9018fc0 | 240 | } |
pferland | 0:9e88a9018fc0 | 241 | |
pferland | 0:9e88a9018fc0 | 242 | if (current_tx_frequency != tx_frequency) { |
pferland | 0:9e88a9018fc0 | 243 | logInfo("changing TX frequency from %lu to %lu", current_tx_frequency, tx_frequency); |
pferland | 0:9e88a9018fc0 | 244 | if (dot->setTxFrequency(tx_frequency) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 245 | logError("failed to set TX frequency to %lu", tx_frequency); |
pferland | 0:9e88a9018fc0 | 246 | } |
pferland | 0:9e88a9018fc0 | 247 | } |
pferland | 0:9e88a9018fc0 | 248 | |
pferland | 0:9e88a9018fc0 | 249 | if (current_tx_datarate != tx_datarate) { |
pferland | 0:9e88a9018fc0 | 250 | logInfo("changing TX datarate from %u to %u", current_tx_datarate, tx_datarate); |
pferland | 0:9e88a9018fc0 | 251 | if (dot->setTxDataRate(tx_datarate) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 252 | logError("failed to set TX datarate to %u", tx_datarate); |
pferland | 0:9e88a9018fc0 | 253 | } |
pferland | 0:9e88a9018fc0 | 254 | } |
pferland | 0:9e88a9018fc0 | 255 | |
pferland | 0:9e88a9018fc0 | 256 | if (current_tx_power != tx_power) { |
pferland | 0:9e88a9018fc0 | 257 | logInfo("changing TX power from %u to %u", current_tx_power, tx_power); |
pferland | 0:9e88a9018fc0 | 258 | if (dot->setTxPower(tx_power) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 259 | logError("failed to set TX power to %u", tx_power); |
pferland | 0:9e88a9018fc0 | 260 | } |
pferland | 0:9e88a9018fc0 | 261 | } |
pferland | 0:9e88a9018fc0 | 262 | } |
pferland | 0:9e88a9018fc0 | 263 | |
pferland | 0:9e88a9018fc0 | 264 | void update_network_link_check_config(uint8_t link_check_count, uint8_t link_check_threshold) { |
pferland | 0:9e88a9018fc0 | 265 | uint8_t current_link_check_count = dot->getLinkCheckCount(); |
pferland | 0:9e88a9018fc0 | 266 | uint8_t current_link_check_threshold = dot->getLinkCheckThreshold(); |
pferland | 0:9e88a9018fc0 | 267 | |
pferland | 0:9e88a9018fc0 | 268 | if (current_link_check_count != link_check_count) { |
pferland | 0:9e88a9018fc0 | 269 | logInfo("changing link check count from %u to %u", current_link_check_count, link_check_count); |
pferland | 0:9e88a9018fc0 | 270 | if (dot->setLinkCheckCount(link_check_count) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 271 | logError("failed to set link check count to %u", link_check_count); |
pferland | 0:9e88a9018fc0 | 272 | } |
pferland | 0:9e88a9018fc0 | 273 | } |
pferland | 0:9e88a9018fc0 | 274 | |
pferland | 0:9e88a9018fc0 | 275 | if (current_link_check_threshold != link_check_threshold) { |
pferland | 0:9e88a9018fc0 | 276 | logInfo("changing link check threshold from %u to %u", current_link_check_threshold, link_check_threshold); |
pferland | 0:9e88a9018fc0 | 277 | if (dot->setLinkCheckThreshold(link_check_threshold) != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 278 | logError("failed to set link check threshold to %u", link_check_threshold); |
pferland | 0:9e88a9018fc0 | 279 | } |
pferland | 0:9e88a9018fc0 | 280 | } |
pferland | 0:9e88a9018fc0 | 281 | } |
pferland | 0:9e88a9018fc0 | 282 | |
pferland | 0:9e88a9018fc0 | 283 | void join_network() { |
pferland | 0:9e88a9018fc0 | 284 | int32_t j_attempts = 0; |
pferland | 0:9e88a9018fc0 | 285 | int32_t ret = mDot::MDOT_ERROR; |
pferland | 0:9e88a9018fc0 | 286 | |
pferland | 0:9e88a9018fc0 | 287 | // attempt to join the network |
pferland | 0:9e88a9018fc0 | 288 | while (ret != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 289 | logInfo("attempt %d to join network", ++j_attempts); |
pferland | 0:9e88a9018fc0 | 290 | ret = dot->joinNetwork(); |
pferland | 0:9e88a9018fc0 | 291 | if (ret != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 292 | logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); |
pferland | 0:9e88a9018fc0 | 293 | // in some frequency bands we need to wait until another channel is available before transmitting again |
pferland | 0:9e88a9018fc0 | 294 | uint32_t delay_s = (dot->getNextTxMs() / 1000) + 1; |
pferland | 0:9e88a9018fc0 | 295 | if (delay_s < 2) { |
pferland | 0:9e88a9018fc0 | 296 | logInfo("waiting %lu s until next free channel", delay_s); |
pferland | 0:9e88a9018fc0 | 297 | wait(delay_s); |
pferland | 0:9e88a9018fc0 | 298 | } else { |
pferland | 0:9e88a9018fc0 | 299 | logInfo("sleeping %lu s until next free channel", delay_s); |
pferland | 0:9e88a9018fc0 | 300 | dot->sleep(delay_s, mDot::RTC_ALARM, false); |
pferland | 0:9e88a9018fc0 | 301 | } |
pferland | 0:9e88a9018fc0 | 302 | } |
pferland | 0:9e88a9018fc0 | 303 | } |
pferland | 0:9e88a9018fc0 | 304 | } |
pferland | 0:9e88a9018fc0 | 305 | |
pferland | 0:9e88a9018fc0 | 306 | void sleep_wake_rtc_only(bool deepsleep) { |
pferland | 0:9e88a9018fc0 | 307 | // in some frequency bands we need to wait until another channel is available before transmitting again |
pferland | 0:9e88a9018fc0 | 308 | // wait at least 10s between transmissions |
pferland | 0:9e88a9018fc0 | 309 | uint32_t delay_s = dot->getNextTxMs() / 1000; |
pferland | 9:e642e8f9ea37 | 310 | if (delay_s < 10) { |
pferland | 12:63e90d375afd | 311 | delay_s = 10; |
pferland | 0:9e88a9018fc0 | 312 | } |
pferland | 0:9e88a9018fc0 | 313 | |
pferland | 0:9e88a9018fc0 | 314 | logInfo("%ssleeping %lus", deepsleep ? "deep" : "", delay_s); |
pferland | 0:9e88a9018fc0 | 315 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
pferland | 0:9e88a9018fc0 | 316 | |
pferland | 0:9e88a9018fc0 | 317 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
pferland | 0:9e88a9018fc0 | 318 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
pferland | 0:9e88a9018fc0 | 319 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
pferland | 0:9e88a9018fc0 | 320 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
pferland | 0:9e88a9018fc0 | 321 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
pferland | 0:9e88a9018fc0 | 322 | // steps are: |
pferland | 0:9e88a9018fc0 | 323 | // * save IO configuration |
pferland | 0:9e88a9018fc0 | 324 | // * configure IOs to reduce current consumption |
pferland | 0:9e88a9018fc0 | 325 | // * sleep |
pferland | 0:9e88a9018fc0 | 326 | // * restore IO configuration |
pferland | 0:9e88a9018fc0 | 327 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 328 | // save the GPIO state. |
pferland | 0:9e88a9018fc0 | 329 | sleep_save_io(); |
pferland | 0:9e88a9018fc0 | 330 | |
pferland | 0:9e88a9018fc0 | 331 | // configure GPIOs for lowest current |
pferland | 0:9e88a9018fc0 | 332 | sleep_configure_io(); |
pferland | 0:9e88a9018fc0 | 333 | } |
pferland | 0:9e88a9018fc0 | 334 | |
pferland | 0:9e88a9018fc0 | 335 | // go to sleep/deepsleep for delay_s seconds and wake using the RTC alarm |
pferland | 0:9e88a9018fc0 | 336 | dot->sleep(delay_s, mDot::RTC_ALARM, deepsleep); |
pferland | 0:9e88a9018fc0 | 337 | |
pferland | 0:9e88a9018fc0 | 338 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 339 | // restore the GPIO state. |
pferland | 0:9e88a9018fc0 | 340 | sleep_restore_io(); |
pferland | 0:9e88a9018fc0 | 341 | } |
pferland | 0:9e88a9018fc0 | 342 | } |
pferland | 0:9e88a9018fc0 | 343 | |
pferland | 0:9e88a9018fc0 | 344 | void sleep_wake_interrupt_only(bool deepsleep) { |
pferland | 0:9e88a9018fc0 | 345 | #if defined (TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 346 | if (deepsleep) { |
pferland | 0:9e88a9018fc0 | 347 | // for xDot, WAKE pin (connected to S2 on xDot-DK) is the only pin that can wake the processor from deepsleep |
pferland | 0:9e88a9018fc0 | 348 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the mDot::sleep call |
pferland | 0:9e88a9018fc0 | 349 | } else { |
pferland | 0:9e88a9018fc0 | 350 | // configure WAKE pin (connected to S2 on xDot-DK) as the pin that will wake the xDot from low power modes |
pferland | 0:9e88a9018fc0 | 351 | // other pins can be confgured instead: GPIO0-3 or UART_RX |
pferland | 0:9e88a9018fc0 | 352 | dot->setWakePin(WAKE); |
pferland | 0:9e88a9018fc0 | 353 | } |
pferland | 0:9e88a9018fc0 | 354 | |
pferland | 0:9e88a9018fc0 | 355 | logInfo("%ssleeping until interrupt on %s pin", deepsleep ? "deep" : "", deepsleep ? "WAKE" : mDot::pinName2Str(dot->getWakePin()).c_str()); |
pferland | 0:9e88a9018fc0 | 356 | #else |
pferland | 0:9e88a9018fc0 | 357 | |
pferland | 0:9e88a9018fc0 | 358 | if (deepsleep) { |
pferland | 0:9e88a9018fc0 | 359 | // for mDot, XBEE_DIO7 pin is the only pin that can wake the processor from deepsleep |
pferland | 0:9e88a9018fc0 | 360 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the mDot::sleep call |
pferland | 0:9e88a9018fc0 | 361 | } else { |
pferland | 0:9e88a9018fc0 | 362 | // configure XBEE_DIO7 pin as the pin that will wake the mDot from low power modes |
pferland | 0:9e88a9018fc0 | 363 | // other pins can be confgured instead: XBEE_DIO2-6, XBEE_DI8, XBEE_DIN |
pferland | 0:9e88a9018fc0 | 364 | dot->setWakePin(XBEE_DIO7); |
pferland | 0:9e88a9018fc0 | 365 | } |
pferland | 0:9e88a9018fc0 | 366 | |
pferland | 0:9e88a9018fc0 | 367 | logInfo("%ssleeping until interrupt on %s pin", deepsleep ? "deep" : "", deepsleep ? "DIO7" : mDot::pinName2Str(dot->getWakePin()).c_str()); |
pferland | 0:9e88a9018fc0 | 368 | #endif |
pferland | 0:9e88a9018fc0 | 369 | |
pferland | 0:9e88a9018fc0 | 370 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
pferland | 0:9e88a9018fc0 | 371 | |
pferland | 0:9e88a9018fc0 | 372 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
pferland | 0:9e88a9018fc0 | 373 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
pferland | 0:9e88a9018fc0 | 374 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
pferland | 0:9e88a9018fc0 | 375 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
pferland | 0:9e88a9018fc0 | 376 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
pferland | 0:9e88a9018fc0 | 377 | // steps are: |
pferland | 0:9e88a9018fc0 | 378 | // * save IO configuration |
pferland | 0:9e88a9018fc0 | 379 | // * configure IOs to reduce current consumption |
pferland | 0:9e88a9018fc0 | 380 | // * sleep |
pferland | 0:9e88a9018fc0 | 381 | // * restore IO configuration |
pferland | 0:9e88a9018fc0 | 382 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 383 | // save the GPIO state. |
pferland | 0:9e88a9018fc0 | 384 | sleep_save_io(); |
pferland | 0:9e88a9018fc0 | 385 | |
pferland | 0:9e88a9018fc0 | 386 | // configure GPIOs for lowest current |
pferland | 0:9e88a9018fc0 | 387 | sleep_configure_io(); |
pferland | 0:9e88a9018fc0 | 388 | } |
pferland | 0:9e88a9018fc0 | 389 | |
pferland | 0:9e88a9018fc0 | 390 | // go to sleep/deepsleep and wake on rising edge of configured wake pin (only the WAKE pin in deepsleep) |
pferland | 0:9e88a9018fc0 | 391 | // since we're not waking on the RTC alarm, the interval is ignored |
pferland | 0:9e88a9018fc0 | 392 | dot->sleep(0, mDot::INTERRUPT, deepsleep); |
pferland | 0:9e88a9018fc0 | 393 | |
pferland | 0:9e88a9018fc0 | 394 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 395 | // restore the GPIO state. |
pferland | 0:9e88a9018fc0 | 396 | sleep_restore_io(); |
pferland | 0:9e88a9018fc0 | 397 | } |
pferland | 0:9e88a9018fc0 | 398 | } |
pferland | 0:9e88a9018fc0 | 399 | |
pferland | 0:9e88a9018fc0 | 400 | void sleep_wake_rtc_or_interrupt(bool deepsleep) { |
pferland | 0:9e88a9018fc0 | 401 | // in some frequency bands we need to wait until another channel is available before transmitting again |
pferland | 0:9e88a9018fc0 | 402 | // wait at least 10s between transmissions |
pferland | 0:9e88a9018fc0 | 403 | uint32_t delay_s = dot->getNextTxMs() / 1000; |
pferland | 0:9e88a9018fc0 | 404 | if (delay_s < 10) { |
pferland | 0:9e88a9018fc0 | 405 | delay_s = 10; |
pferland | 0:9e88a9018fc0 | 406 | } |
pferland | 0:9e88a9018fc0 | 407 | |
pferland | 0:9e88a9018fc0 | 408 | #if defined (TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 409 | if (deepsleep) { |
pferland | 0:9e88a9018fc0 | 410 | // for xDot, WAKE pin (connected to S2 on xDot-DK) is the only pin that can wake the processor from deepsleep |
pferland | 0:9e88a9018fc0 | 411 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the mDot::sleep call |
pferland | 0:9e88a9018fc0 | 412 | } else { |
pferland | 0:9e88a9018fc0 | 413 | // configure WAKE pin (connected to S2 on xDot-DK) as the pin that will wake the xDot from low power modes |
pferland | 0:9e88a9018fc0 | 414 | // other pins can be confgured instead: GPIO0-3 or UART_RX |
pferland | 0:9e88a9018fc0 | 415 | dot->setWakePin(WAKE); |
pferland | 0:9e88a9018fc0 | 416 | } |
pferland | 0:9e88a9018fc0 | 417 | |
pferland | 0:9e88a9018fc0 | 418 | logInfo("%ssleeping %lus or until interrupt on %s pin", deepsleep ? "deep" : "", delay_s, deepsleep ? "WAKE" : mDot::pinName2Str(dot->getWakePin()).c_str()); |
pferland | 0:9e88a9018fc0 | 419 | #else |
pferland | 0:9e88a9018fc0 | 420 | if (deepsleep) { |
pferland | 0:9e88a9018fc0 | 421 | // for mDot, XBEE_DIO7 pin is the only pin that can wake the processor from deepsleep |
pferland | 0:9e88a9018fc0 | 422 | // it is automatically configured when INTERRUPT or RTC_ALARM_OR_INTERRUPT is the wakeup source and deepsleep is true in the mDot::sleep call |
pferland | 0:9e88a9018fc0 | 423 | } else { |
pferland | 0:9e88a9018fc0 | 424 | // configure XBEE_DIO7 pin as the pin that will wake the mDot from low power modes |
pferland | 0:9e88a9018fc0 | 425 | // other pins can be confgured instead: XBEE_DIO2-6, XBEE_DI8, XBEE_DIN |
pferland | 0:9e88a9018fc0 | 426 | dot->setWakePin(XBEE_DIO7); |
pferland | 0:9e88a9018fc0 | 427 | } |
pferland | 0:9e88a9018fc0 | 428 | |
pferland | 0:9e88a9018fc0 | 429 | logInfo("%ssleeping %lus or until interrupt on %s pin", deepsleep ? "deep" : "", delay_s, deepsleep ? "DIO7" : mDot::pinName2Str(dot->getWakePin()).c_str()); |
pferland | 0:9e88a9018fc0 | 430 | #endif |
pferland | 0:9e88a9018fc0 | 431 | |
pferland | 0:9e88a9018fc0 | 432 | logInfo("application will %s after waking up", deepsleep ? "execute from beginning" : "resume"); |
pferland | 0:9e88a9018fc0 | 433 | |
pferland | 0:9e88a9018fc0 | 434 | // lowest current consumption in sleep mode can only be achieved by configuring IOs as analog inputs with no pull resistors |
pferland | 0:9e88a9018fc0 | 435 | // the library handles all internal IOs automatically, but the external IOs are the application's responsibility |
pferland | 0:9e88a9018fc0 | 436 | // certain IOs may require internal pullup or pulldown resistors because leaving them floating would cause extra current consumption |
pferland | 0:9e88a9018fc0 | 437 | // for xDot: UART_*, I2C_*, SPI_*, GPIO*, WAKE |
pferland | 0:9e88a9018fc0 | 438 | // for mDot: XBEE_*, USBTX, USBRX, PB_0, PB_1 |
pferland | 0:9e88a9018fc0 | 439 | // steps are: |
pferland | 0:9e88a9018fc0 | 440 | // * save IO configuration |
pferland | 0:9e88a9018fc0 | 441 | // * configure IOs to reduce current consumption |
pferland | 0:9e88a9018fc0 | 442 | // * sleep |
pferland | 0:9e88a9018fc0 | 443 | // * restore IO configuration |
pferland | 0:9e88a9018fc0 | 444 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 445 | // save the GPIO state. |
pferland | 0:9e88a9018fc0 | 446 | sleep_save_io(); |
pferland | 0:9e88a9018fc0 | 447 | |
pferland | 0:9e88a9018fc0 | 448 | // configure GPIOs for lowest current |
pferland | 0:9e88a9018fc0 | 449 | sleep_configure_io(); |
pferland | 0:9e88a9018fc0 | 450 | } |
pferland | 0:9e88a9018fc0 | 451 | |
pferland | 0:9e88a9018fc0 | 452 | // 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) |
pferland | 0:9e88a9018fc0 | 453 | // whichever comes first will wake the xDot |
pferland | 0:9e88a9018fc0 | 454 | dot->sleep(delay_s, mDot::RTC_ALARM_OR_INTERRUPT, deepsleep); |
pferland | 0:9e88a9018fc0 | 455 | |
pferland | 0:9e88a9018fc0 | 456 | if (! deepsleep) { |
pferland | 0:9e88a9018fc0 | 457 | // restore the GPIO state. |
pferland | 0:9e88a9018fc0 | 458 | sleep_restore_io(); |
pferland | 0:9e88a9018fc0 | 459 | } |
pferland | 0:9e88a9018fc0 | 460 | } |
pferland | 0:9e88a9018fc0 | 461 | |
pferland | 0:9e88a9018fc0 | 462 | void sleep_save_io() { |
pferland | 0:9e88a9018fc0 | 463 | #if defined(TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 464 | xdot_save_gpio_state(); |
pferland | 0:9e88a9018fc0 | 465 | #else |
pferland | 0:9e88a9018fc0 | 466 | portA[0] = GPIOA->MODER; |
pferland | 0:9e88a9018fc0 | 467 | portA[1] = GPIOA->OTYPER; |
pferland | 0:9e88a9018fc0 | 468 | portA[2] = GPIOA->OSPEEDR; |
pferland | 0:9e88a9018fc0 | 469 | portA[3] = GPIOA->PUPDR; |
pferland | 0:9e88a9018fc0 | 470 | portA[4] = GPIOA->AFR[0]; |
pferland | 0:9e88a9018fc0 | 471 | portA[5] = GPIOA->AFR[1]; |
pferland | 0:9e88a9018fc0 | 472 | |
pferland | 0:9e88a9018fc0 | 473 | portB[0] = GPIOB->MODER; |
pferland | 0:9e88a9018fc0 | 474 | portB[1] = GPIOB->OTYPER; |
pferland | 0:9e88a9018fc0 | 475 | portB[2] = GPIOB->OSPEEDR; |
pferland | 0:9e88a9018fc0 | 476 | portB[3] = GPIOB->PUPDR; |
pferland | 0:9e88a9018fc0 | 477 | portB[4] = GPIOB->AFR[0]; |
pferland | 0:9e88a9018fc0 | 478 | portB[5] = GPIOB->AFR[1]; |
pferland | 0:9e88a9018fc0 | 479 | |
pferland | 0:9e88a9018fc0 | 480 | portC[0] = GPIOC->MODER; |
pferland | 0:9e88a9018fc0 | 481 | portC[1] = GPIOC->OTYPER; |
pferland | 0:9e88a9018fc0 | 482 | portC[2] = GPIOC->OSPEEDR; |
pferland | 0:9e88a9018fc0 | 483 | portC[3] = GPIOC->PUPDR; |
pferland | 0:9e88a9018fc0 | 484 | portC[4] = GPIOC->AFR[0]; |
pferland | 0:9e88a9018fc0 | 485 | portC[5] = GPIOC->AFR[1]; |
pferland | 0:9e88a9018fc0 | 486 | |
pferland | 0:9e88a9018fc0 | 487 | portD[0] = GPIOD->MODER; |
pferland | 0:9e88a9018fc0 | 488 | portD[1] = GPIOD->OTYPER; |
pferland | 0:9e88a9018fc0 | 489 | portD[2] = GPIOD->OSPEEDR; |
pferland | 0:9e88a9018fc0 | 490 | portD[3] = GPIOD->PUPDR; |
pferland | 0:9e88a9018fc0 | 491 | portD[4] = GPIOD->AFR[0]; |
pferland | 0:9e88a9018fc0 | 492 | portD[5] = GPIOD->AFR[1]; |
pferland | 0:9e88a9018fc0 | 493 | |
pferland | 0:9e88a9018fc0 | 494 | portH[0] = GPIOH->MODER; |
pferland | 0:9e88a9018fc0 | 495 | portH[1] = GPIOH->OTYPER; |
pferland | 0:9e88a9018fc0 | 496 | portH[2] = GPIOH->OSPEEDR; |
pferland | 0:9e88a9018fc0 | 497 | portH[3] = GPIOH->PUPDR; |
pferland | 0:9e88a9018fc0 | 498 | portH[4] = GPIOH->AFR[0]; |
pferland | 0:9e88a9018fc0 | 499 | portH[5] = GPIOH->AFR[1]; |
pferland | 0:9e88a9018fc0 | 500 | #endif |
pferland | 0:9e88a9018fc0 | 501 | } |
pferland | 0:9e88a9018fc0 | 502 | |
pferland | 0:9e88a9018fc0 | 503 | void sleep_configure_io() { |
pferland | 0:9e88a9018fc0 | 504 | #if defined(TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 505 | // GPIO Ports Clock Enable |
pferland | 0:9e88a9018fc0 | 506 | __GPIOA_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 507 | __GPIOB_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 508 | __GPIOC_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 509 | __GPIOH_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 510 | |
pferland | 0:9e88a9018fc0 | 511 | GPIO_InitTypeDef GPIO_InitStruct; |
pferland | 0:9e88a9018fc0 | 512 | |
pferland | 0:9e88a9018fc0 | 513 | // UART1_TX, UART1_RTS & UART1_CTS to analog nopull - RX could be a wakeup source |
pferland | 0:9e88a9018fc0 | 514 | GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12; |
pferland | 0:9e88a9018fc0 | 515 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 516 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 517 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 518 | |
pferland | 0:9e88a9018fc0 | 519 | // I2C_SDA & I2C_SCL to analog nopull |
pferland | 0:9e88a9018fc0 | 520 | GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9; |
pferland | 0:9e88a9018fc0 | 521 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 522 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 523 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 524 | |
pferland | 0:9e88a9018fc0 | 525 | // SPI_MOSI, SPI_MISO, SPI_SCK, & SPI_NSS to analog nopull |
pferland | 0:9e88a9018fc0 | 526 | GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
pferland | 0:9e88a9018fc0 | 527 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 528 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 529 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 530 | |
pferland | 0:9e88a9018fc0 | 531 | // iterate through potential wake pins - leave the configured wake pin alone if one is needed |
pferland | 0:9e88a9018fc0 | 532 | if (dot->getWakePin() != WAKE || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 533 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
pferland | 0:9e88a9018fc0 | 534 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 535 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 536 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 537 | } |
pferland | 0:9e88a9018fc0 | 538 | if (dot->getWakePin() != GPIO0 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 539 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
pferland | 0:9e88a9018fc0 | 540 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 541 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 542 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 543 | } |
pferland | 0:9e88a9018fc0 | 544 | if (dot->getWakePin() != GPIO1 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 545 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
pferland | 0:9e88a9018fc0 | 546 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 547 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 548 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 549 | } |
pferland | 0:9e88a9018fc0 | 550 | if (dot->getWakePin() != GPIO2 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 551 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
pferland | 0:9e88a9018fc0 | 552 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 553 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 554 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 555 | } |
pferland | 0:9e88a9018fc0 | 556 | if (dot->getWakePin() != GPIO3 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 557 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
pferland | 0:9e88a9018fc0 | 558 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 559 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 560 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 561 | } |
pferland | 0:9e88a9018fc0 | 562 | if (dot->getWakePin() != UART1_RX || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 563 | GPIO_InitStruct.Pin = GPIO_PIN_10; |
pferland | 0:9e88a9018fc0 | 564 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 565 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 566 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 567 | } |
pferland | 0:9e88a9018fc0 | 568 | #else |
pferland | 0:9e88a9018fc0 | 569 | /* GPIO Ports Clock Enable */ |
pferland | 0:9e88a9018fc0 | 570 | __GPIOA_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 571 | __GPIOB_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 572 | __GPIOC_CLK_ENABLE(); |
pferland | 0:9e88a9018fc0 | 573 | |
pferland | 0:9e88a9018fc0 | 574 | GPIO_InitTypeDef GPIO_InitStruct; |
pferland | 0:9e88a9018fc0 | 575 | |
pferland | 0:9e88a9018fc0 | 576 | // XBEE_DOUT, XBEE_DIN, XBEE_DO8, XBEE_RSSI, USBTX, USBRX, PA_12, PA_13, PA_14 & PA_15 to analog nopull |
pferland | 0:9e88a9018fc0 | 577 | GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 |
pferland | 0:9e88a9018fc0 | 578 | | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; |
pferland | 0:9e88a9018fc0 | 579 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 580 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 581 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 582 | |
pferland | 0:9e88a9018fc0 | 583 | // PB_0, PB_1, PB_3 & PB_4 to analog nopull |
pferland | 0:9e88a9018fc0 | 584 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_4; |
pferland | 0:9e88a9018fc0 | 585 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 586 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 587 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 588 | |
pferland | 0:9e88a9018fc0 | 589 | // PC_9 & PC_13 to analog nopull |
pferland | 0:9e88a9018fc0 | 590 | GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_13; |
pferland | 0:9e88a9018fc0 | 591 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 592 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 593 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 594 | |
pferland | 0:9e88a9018fc0 | 595 | // iterate through potential wake pins - leave the configured wake pin alone if one is needed |
pferland | 0:9e88a9018fc0 | 596 | // XBEE_DIN - PA3 |
pferland | 0:9e88a9018fc0 | 597 | // XBEE_DIO2 - PA5 |
pferland | 0:9e88a9018fc0 | 598 | // XBEE_DIO3 - PA4 |
pferland | 0:9e88a9018fc0 | 599 | // XBEE_DIO4 - PA7 |
pferland | 0:9e88a9018fc0 | 600 | // XBEE_DIO5 - PC1 |
pferland | 0:9e88a9018fc0 | 601 | // XBEE_DIO6 - PA1 |
pferland | 0:9e88a9018fc0 | 602 | // XBEE_DIO7 - PA0 |
pferland | 0:9e88a9018fc0 | 603 | // XBEE_SLEEPRQ - PA11 |
pferland | 0:9e88a9018fc0 | 604 | |
pferland | 0:9e88a9018fc0 | 605 | if (dot->getWakePin() != XBEE_DIN || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 606 | GPIO_InitStruct.Pin = GPIO_PIN_3; |
pferland | 0:9e88a9018fc0 | 607 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 608 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 609 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 610 | } |
pferland | 0:9e88a9018fc0 | 611 | |
pferland | 0:9e88a9018fc0 | 612 | if (dot->getWakePin() != XBEE_DIO2 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 613 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
pferland | 0:9e88a9018fc0 | 614 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 615 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 616 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 617 | } |
pferland | 0:9e88a9018fc0 | 618 | |
pferland | 0:9e88a9018fc0 | 619 | if (dot->getWakePin() != XBEE_DIO3 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 620 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
pferland | 0:9e88a9018fc0 | 621 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 622 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 623 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 624 | } |
pferland | 0:9e88a9018fc0 | 625 | |
pferland | 0:9e88a9018fc0 | 626 | if (dot->getWakePin() != XBEE_DIO4 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 627 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
pferland | 0:9e88a9018fc0 | 628 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 629 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 630 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 631 | } |
pferland | 0:9e88a9018fc0 | 632 | |
pferland | 0:9e88a9018fc0 | 633 | if (dot->getWakePin() != XBEE_DIO5 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 634 | GPIO_InitStruct.Pin = GPIO_PIN_1; |
pferland | 0:9e88a9018fc0 | 635 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 636 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 637 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 638 | } |
pferland | 0:9e88a9018fc0 | 639 | |
pferland | 0:9e88a9018fc0 | 640 | if (dot->getWakePin() != XBEE_DIO6 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 641 | GPIO_InitStruct.Pin = GPIO_PIN_1; |
pferland | 0:9e88a9018fc0 | 642 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 643 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 644 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 645 | } |
pferland | 0:9e88a9018fc0 | 646 | |
pferland | 0:9e88a9018fc0 | 647 | if (dot->getWakePin() != XBEE_DIO7 || dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 648 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
pferland | 0:9e88a9018fc0 | 649 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 650 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 651 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 652 | } |
pferland | 0:9e88a9018fc0 | 653 | |
pferland | 0:9e88a9018fc0 | 654 | if (dot->getWakePin() != XBEE_SLEEPRQ|| dot->getWakeMode() == mDot::RTC_ALARM) { |
pferland | 0:9e88a9018fc0 | 655 | GPIO_InitStruct.Pin = GPIO_PIN_11; |
pferland | 0:9e88a9018fc0 | 656 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
pferland | 0:9e88a9018fc0 | 657 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
pferland | 0:9e88a9018fc0 | 658 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
pferland | 0:9e88a9018fc0 | 659 | } |
pferland | 0:9e88a9018fc0 | 660 | #endif |
pferland | 0:9e88a9018fc0 | 661 | } |
pferland | 0:9e88a9018fc0 | 662 | |
pferland | 0:9e88a9018fc0 | 663 | void sleep_restore_io() { |
pferland | 0:9e88a9018fc0 | 664 | #if defined(TARGET_XDOT_L151CC) |
pferland | 0:9e88a9018fc0 | 665 | xdot_restore_gpio_state(); |
pferland | 0:9e88a9018fc0 | 666 | #else |
pferland | 0:9e88a9018fc0 | 667 | GPIOA->MODER = portA[0]; |
pferland | 0:9e88a9018fc0 | 668 | GPIOA->OTYPER = portA[1]; |
pferland | 0:9e88a9018fc0 | 669 | GPIOA->OSPEEDR = portA[2]; |
pferland | 0:9e88a9018fc0 | 670 | GPIOA->PUPDR = portA[3]; |
pferland | 0:9e88a9018fc0 | 671 | GPIOA->AFR[0] = portA[4]; |
pferland | 0:9e88a9018fc0 | 672 | GPIOA->AFR[1] = portA[5]; |
pferland | 0:9e88a9018fc0 | 673 | |
pferland | 0:9e88a9018fc0 | 674 | GPIOB->MODER = portB[0]; |
pferland | 0:9e88a9018fc0 | 675 | GPIOB->OTYPER = portB[1]; |
pferland | 0:9e88a9018fc0 | 676 | GPIOB->OSPEEDR = portB[2]; |
pferland | 0:9e88a9018fc0 | 677 | GPIOB->PUPDR = portB[3]; |
pferland | 0:9e88a9018fc0 | 678 | GPIOB->AFR[0] = portB[4]; |
pferland | 0:9e88a9018fc0 | 679 | GPIOB->AFR[1] = portB[5]; |
pferland | 0:9e88a9018fc0 | 680 | |
pferland | 0:9e88a9018fc0 | 681 | GPIOC->MODER = portC[0]; |
pferland | 0:9e88a9018fc0 | 682 | GPIOC->OTYPER = portC[1]; |
pferland | 0:9e88a9018fc0 | 683 | GPIOC->OSPEEDR = portC[2]; |
pferland | 0:9e88a9018fc0 | 684 | GPIOC->PUPDR = portC[3]; |
pferland | 0:9e88a9018fc0 | 685 | GPIOC->AFR[0] = portC[4]; |
pferland | 0:9e88a9018fc0 | 686 | GPIOC->AFR[1] = portC[5]; |
pferland | 0:9e88a9018fc0 | 687 | |
pferland | 0:9e88a9018fc0 | 688 | GPIOD->MODER = portD[0]; |
pferland | 0:9e88a9018fc0 | 689 | GPIOD->OTYPER = portD[1]; |
pferland | 0:9e88a9018fc0 | 690 | GPIOD->OSPEEDR = portD[2]; |
pferland | 0:9e88a9018fc0 | 691 | GPIOD->PUPDR = portD[3]; |
pferland | 0:9e88a9018fc0 | 692 | GPIOD->AFR[0] = portD[4]; |
pferland | 0:9e88a9018fc0 | 693 | GPIOD->AFR[1] = portD[5]; |
pferland | 0:9e88a9018fc0 | 694 | |
pferland | 0:9e88a9018fc0 | 695 | GPIOH->MODER = portH[0]; |
pferland | 0:9e88a9018fc0 | 696 | GPIOH->OTYPER = portH[1]; |
pferland | 0:9e88a9018fc0 | 697 | GPIOH->OSPEEDR = portH[2]; |
pferland | 0:9e88a9018fc0 | 698 | GPIOH->PUPDR = portH[3]; |
pferland | 0:9e88a9018fc0 | 699 | GPIOH->AFR[0] = portH[4]; |
pferland | 0:9e88a9018fc0 | 700 | GPIOH->AFR[1] = portH[5]; |
pferland | 0:9e88a9018fc0 | 701 | #endif |
pferland | 0:9e88a9018fc0 | 702 | } |
pferland | 0:9e88a9018fc0 | 703 | |
pferland | 0:9e88a9018fc0 | 704 | void send_data(std::vector<uint8_t> data) { |
pferland | 13:e165a137c3af | 705 | int32_t ret; |
pferland | 0:9e88a9018fc0 | 706 | |
pferland | 0:9e88a9018fc0 | 707 | ret = dot->send(data); |
pferland | 0:9e88a9018fc0 | 708 | if (ret != mDot::MDOT_OK) { |
pferland | 0:9e88a9018fc0 | 709 | logError("failed to send data to %s [%d][%s]", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer" : "gateway", ret, mDot::getReturnCodeString(ret).c_str()); |
pferland | 0:9e88a9018fc0 | 710 | } else { |
pferland | 0:9e88a9018fc0 | 711 | logInfo("successfully sent data to %s", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer" : "gateway"); |
pferland | 0:9e88a9018fc0 | 712 | } |
pferland | 0:9e88a9018fc0 | 713 | } |
pferland | 13:e165a137c3af | 714 |