![](/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
Diff: xDotBridge/src/CommProtocolPeerBrute.cpp
- Revision:
- 63:e1efbe3402d9
- Parent:
- 62:9751a8504c82
- Child:
- 64:46c8819c07cc
--- a/xDotBridge/src/CommProtocolPeerBrute.cpp Tue Mar 14 08:32:55 2017 -0600 +++ b/xDotBridge/src/CommProtocolPeerBrute.cpp Tue Mar 14 09:54:04 2017 -0600 @@ -6,8 +6,8 @@ */ #include "CommProtocolPeerBrute.h" -#include "MTSLog.h" #include "dot_util.h" +#include "MyLog.h" // wireless bridge protocol const uint8_t TX_PWR = 20; // 20 dBm @@ -18,7 +18,7 @@ CommProtocolPeerBrute::CommProtocolPeerBrute() { - logInfo("RX_SLEEP_TIME %f, timeOnAir %lu, nTimesToTx %lu", RX_SLEEP_TIME, TX_TIME, nTimesToTx); + myLogDebug("RX_SLEEP_TIME %f, timeOnAir %lu, nTimesToTx %lu", RX_SLEEP_TIME, TX_TIME, nTimesToTx); mIsTx = true; // default to TX } @@ -31,7 +31,7 @@ } result = readInfoFromNVM(); if (result != cmdSuccess) { - logInfo("Reverting to protocol defaults NVM Read failed"); + myLogWarning("Reverting to protocol defaults NVM Read failed"); mMemObj.setDefaults(); } configForSavedNetwork(); @@ -47,7 +47,7 @@ return cmdError; } -// logInfo("defaulting Dot configuration"); +// myLogInfo("defaulting Dot configuration"); // dot->resetConfig(); // Common Configuration @@ -60,11 +60,11 @@ // TODO break out in a utility function // update configuration if necessary - logInfo("Setting up peer to peer configuration"); + myLogDebug("Setting up peer to peer configuration"); if (dot->getJoinMode() != mDot::PEER_TO_PEER) { - logInfo("changing network join mode to PEER_TO_PEER"); + myLogDebug("changing network join mode to PEER_TO_PEER"); if (dot->setJoinMode(mDot::PEER_TO_PEER) != mDot::MDOT_OK) { - logError("failed to set network join mode to PEER_TO_PEER"); + myLogError("failed to set network join mode to PEER_TO_PEER"); } } uint8_t tx_power; @@ -112,7 +112,7 @@ return cmdError; } -// logInfo("defaulting Dot configuration"); +// myLogInfo("defaulting Dot configuration"); // dot->resetConfig(); // Common Configuration @@ -124,11 +124,11 @@ dot->setPreserveSession(false); // TODO break out in a utility function // update configuration if necessary - logInfo("Setting up peer to peer configuration"); + myLogDebug("Setting up peer to peer configuration"); if (dot->getJoinMode() != mDot::PEER_TO_PEER) { - logInfo("changing network join mode to PEER_TO_PEER"); + myLogDebug("changing network join mode to PEER_TO_PEER"); if (dot->setJoinMode(mDot::PEER_TO_PEER) != mDot::MDOT_OK) { - logError("failed to set network join mode to PEER_TO_PEER"); + myLogError("failed to set network join mode to PEER_TO_PEER"); } } @@ -186,44 +186,44 @@ // REPLACE WITH NETWORK ADDRESS // result = genEncypKey(key, 8); // if (result != cmdSuccess) { -// logError("Error generating network ID."); +// myLogError("Error generating network ID."); // return cmdError; // } // if (dot->setNetworkId(key) != mDot::MDOT_OK) { -// logError("Error setting network ID."); +// myLogError("Error setting network ID."); // return cmdError; // } result = genEncypKey(key, 4, false); if (result != cmdSuccess) { - logError("Error generating network address."); + myLogError("Error generating network address."); return cmdError; } mMemObj.setNetworkAddr(key); // if (dot->setNetworkAddress(key) != mDot::MDOT_OK) { -// logError("Error setting network address."); +// myLogError("Error setting network address."); // return cmdError; // } result = genEncypKey(key, 16); if (result != cmdSuccess) { - logError("Error generating network encryption keys."); + myLogError("Error generating network encryption keys."); return cmdError; } mMemObj.setNetworkSessionKey(key); // if (dot->setNetworkSessionKey(key) != mDot::MDOT_OK) { -// logError("Error setting network session key."); +// myLogError("Error setting network session key."); // return cmdError; // } result = genEncypKey(key, 16); if (result != cmdSuccess) { - logError("Error generating data session encryption keys."); + myLogError("Error generating data session encryption keys."); return cmdError; } mMemObj.setDataSessionKey(key); // if (dot->setDataSessionKey(key) != mDot::MDOT_OK) { -// logError("Error setting data session key."); +// myLogError("Error setting data session key."); // return cmdError; // } @@ -240,11 +240,11 @@ if (!dot->getNetworkJoinStatus()) { join_network(); } - logInfo("Starting TX. Time: %lu", us_ticker_read()); + myLogDebug("Starting TX. Time: %lu", us_ticker_read()); for(uint8_t i=0;i<nTimesToTx;++i) { dot->send(msg); } - logInfo("Finished TX. Time: %lu", us_ticker_read()); + myLogDebug("Finished TX. Time: %lu", us_ticker_read()); return cmdError; } @@ -329,32 +329,32 @@ // Flag msg->push_back(0xFD); msg->push_back(0x02); - logInfo("flag msg size %d", msg->size()); + myLogDebug("flag msg size %d", msg->size()); // EUI std::vector<uint8_t> *eui = new std::vector<uint8_t>(dot->getDeviceId()); msg->insert(msg->end(),eui->begin(), eui->end()); delete eui; - logInfo("eui msg size %d", msg->size()); + myLogDebug("eui msg size %d", msg->size()); // Reserved for Freq for(uint8_t i=0;i<4;i++) { msg->push_back(0x00); } - logInfo("freq msg size %d", msg->size()); + myLogDebug("freq msg size %d", msg->size()); // Network Address std::vector<uint8_t> *networkAddr = new std::vector<uint8_t>; mMemObj.getNetworkAddr(*networkAddr); msg->insert(msg->end(),networkAddr->begin(), networkAddr->end()); delete networkAddr; - logInfo("netAddr msg size %d", msg->size()); + myLogDebug("netAddr msg size %d", msg->size()); // Network session key std::vector<uint8_t> *networkSessionKey = new std::vector<uint8_t>; mMemObj.getNetworkSessionKey(*networkSessionKey); msg->insert(msg->end(),networkSessionKey->begin(), networkSessionKey->end()); delete networkSessionKey; - logInfo("netSessionKey msg size %d", msg->size()); + myLogDebug("netSessionKey msg size %d", msg->size()); // Data session key std::vector<uint8_t> *dataSessionKey = new std::vector<uint8_t>; @@ -362,7 +362,7 @@ msg->insert(msg->end(),dataSessionKey->begin(), dataSessionKey->end()); delete dataSessionKey; - logInfo("msg size %d", msg->size()); + myLogDebug("msg size %d", msg->size()); // Only send once since requester should be listening always sendResult = mDot::MDOT_OK == dot->send(*msg); delete msg; @@ -389,7 +389,7 @@ std::vector<uint8_t> acceptMsg; dot->recv(acceptMsg); if (acceptMsg[0] != 0xFD || acceptMsg[1] != 0x02) { - logError("Invalid accept message flag."); + myLogError("Invalid accept message flag."); return cmdError; } @@ -436,12 +436,12 @@ mMemObj.fromBytes(data, PROTOCOL_NVM_SIZE); delete [] data; if (!mMemObj.validProtocolFlag()) { - logWarning("Invalid Protocol Flag. Using default values."); + myLogWarning("Invalid Protocol Flag. Using default values."); mMemObj.setDefaults(); return cmdError; } else if (!mMemObj.validProtocolRev()) { - logWarning("Invalid Protocol Rev. Using default values."); + myLogWarning("Invalid Protocol Rev. Using default values."); mMemObj.setDefaults(); return cmdError; } @@ -484,6 +484,47 @@ return cmdSuccess; } +void CommProtocolPeerBrute::printDotConfig() +{ + // display configuration and library version information + myLogInfo("====================="); + myLogInfo("general configuration"); + myLogInfo("====================="); + myLogInfo("version ------------------ %s", dot->getId().c_str()); + myLogInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(dot->getDeviceId()).c_str()); + myLogInfo("frequency band ----------- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str()); + if (dot->getFrequencySubBand() != mDot::FB_EU868) { + myLogInfo("frequency sub band ------- %u", dot->getFrequencySubBand()); + } + myLogInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off"); + myLogInfo("========================="); + myLogInfo("credentials configuration"); + myLogInfo("========================="); + myLogInfo("device class ------------- %s", dot->getClass().c_str()); + myLogInfo("network join mode -------- %s", mDot::JoinModeStr(dot->getJoinMode()).c_str()); + if (dot->getJoinMode() == mDot::MANUAL || dot->getJoinMode() == mDot::PEER_TO_PEER) { + myLogInfo("network address ---------- %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str()); + myLogInfo("network session key------- %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str()); + myLogInfo("data session key---------- %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str()); + } else { + myLogInfo("network name ------------- %s", dot->getNetworkName().c_str()); + myLogInfo("network phrase ----------- %s", dot->getNetworkPassphrase().c_str()); + myLogInfo("network EUI -------------- %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str()); + myLogInfo("network KEY -------------- %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str()); + } + myLogInfo("========================"); + myLogInfo("communication parameters"); + myLogInfo("========================"); + if (dot->getJoinMode() == mDot::PEER_TO_PEER) { + myLogInfo("TX frequency ------------- %lu", dot->getTxFrequency()); + } else { + myLogInfo("acks --------------------- %s, %u attempts", dot->getAck() > 0 ? "on" : "off", dot->getAck()); + } + myLogInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str()); + myLogInfo("TX power ----------------- %lu dBm", dot->getTxPower()); + myLogInfo("atnenna gain ------------- %u dBm", dot->getAntennaGain()); +} + // NvmProtocolObj NvmProtocolObj::NvmProtocolObj() {