Basic xdot code to check how many memory is available for user APP after initializing libxdot lorawan stack
Diff: examples/src/dot_util.cpp
- Revision:
- 11:d2e31743433a
- Parent:
- 10:4d0b765f7b9e
- Child:
- 15:364df461110f
--- a/examples/src/dot_util.cpp Mon Oct 10 15:04:22 2016 -0500 +++ b/examples/src/dot_util.cpp Tue Oct 11 11:49:56 2016 -0500 @@ -29,7 +29,7 @@ logInfo("========================="); logInfo("device class ------------- %s", dot->getClass().c_str()); logInfo("network join mode -------- %s", mDot::JoinModeStr(dot->getJoinMode()).c_str()); - if (dot->getJoinMode() == mDot::MANUAL) { + if (dot->getJoinMode() == mDot::MANUAL || dot->getJoinMode() == mDot::PEER_TO_PEER) { logInfo("network address ---------- %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str()); logInfo("network session key------- %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str()); logInfo("data session key---------- %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str()); @@ -42,7 +42,11 @@ logInfo("========================"); logInfo("communication parameters"); logInfo("========================"); - logInfo("acks --------------------- %s, %u attempts", dot->getAck() > 0 ? "on" : "off", dot->getAck()); + if (dot->getJoinMode() == mDot::PEER_TO_PEER) { + logInfo("TX frequency ------------- %lu", dot->getTxFrequency()); + } else { + logInfo("acks --------------------- %s, %u attempts", dot->getAck() > 0 ? "on" : "off", dot->getAck()); + } logInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str()); logInfo("TX power ----------------- %lu dBm", dot->getTxPower()); logInfo("atnenna gain ------------- %u dBm", dot->getAntennaGain()); @@ -192,6 +196,61 @@ } } +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) { + std::vector<uint8_t> current_network_address = dot->getNetworkAddress(); + std::vector<uint8_t> current_network_session_key = dot->getNetworkSessionKey(); + std::vector<uint8_t> current_data_session_key = dot->getDataSessionKey(); + uint32_t current_tx_frequency = dot->getTxFrequency(); + uint8_t current_tx_datarate = dot->getTxDataRate(); + uint8_t current_tx_power = dot->getTxPower(); + + std::vector<uint8_t> network_address_vector(network_address, network_address + 4); + std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16); + std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16); + + if (current_network_address != network_address_vector) { + logInfo("changing network address from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_address).c_str(), mts::Text::bin2hexString(network_address_vector).c_str()); + if (dot->setNetworkAddress(network_address_vector) != mDot::MDOT_OK) { + logError("failed to set network address to \"%s\"", mts::Text::bin2hexString(network_address_vector).c_str()); + } + } + + if (current_network_session_key != network_session_key_vector) { + 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()); + if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) { + logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str()); + } + } + + if (current_data_session_key != data_session_key_vector) { + 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()); + if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) { + logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str()); + } + } + + if (current_tx_frequency != tx_frequency) { + logInfo("changing TX frequency from %lu to %lu", current_tx_frequency, tx_frequency); + if (dot->setTxFrequency(tx_frequency) != mDot::MDOT_OK) { + logError("failed to set TX frequency to %lu", tx_frequency); + } + } + + if (current_tx_datarate != tx_datarate) { + logInfo("changing TX datarate from %u to %u", current_tx_datarate, tx_datarate); + if (dot->setTxDataRate(tx_datarate) != mDot::MDOT_OK) { + logError("failed to set TX datarate to %u", tx_datarate); + } + } + + if (current_tx_power != tx_power) { + logInfo("changing TX power from %u to %u", current_tx_power, tx_power); + if (dot->setTxPower(tx_power) != mDot::MDOT_OK) { + logError("failed to set TX power to %u", tx_power); + } + } +} + void join_network() { int32_t j_attempts = 0; int32_t ret = mDot::MDOT_ERROR; @@ -618,8 +677,8 @@ ret = dot->send(data); if (ret != mDot::MDOT_OK) { - logError("failed to send data to gateway [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str()); + logError("failed to send data to %s [%d][%s]", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer" : "gateway", ret, mDot::getReturnCodeString(ret).c_str()); } else { - logInfo("successfully sent data to gateway"); + logInfo("successfully sent data to %s", dot->getJoinMode() == mDot::PEER_TO_PEER ? "peer" : "gateway"); } }