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