![](/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:
- 65:d546060aa03d
- Parent:
- 64:46c8819c07cc
- Child:
- 66:bcaa6dbf538a
diff -r 46c8819c07cc -r d546060aa03d xDotBridge/src/CommProtocolPeerBrute.cpp --- a/xDotBridge/src/CommProtocolPeerBrute.cpp Tue Mar 14 11:53:53 2017 -0600 +++ b/xDotBridge/src/CommProtocolPeerBrute.cpp Wed Mar 15 09:49:58 2017 -0600 @@ -7,6 +7,7 @@ #include "CommProtocolPeerBrute.h" #include "dot_util.h" +#include "util.h" #include "MyLog.h" // wireless bridge protocol @@ -214,6 +215,10 @@ } // TX focused +uint32_t CommProtocolPeerBrute::getSeqNum() +{ + return mMemObj.getLastMsgSeq(); +} CmdResult CommProtocolPeerBrute::send (const std::vector<uint8_t> &msg) { if (!dot->getNetworkJoinStatus()) { @@ -227,6 +232,33 @@ return cmdError; } +CmdResult CommProtocolPeerBrute::sendAlert(uint16_t data) +{ + if (!dot->getNetworkJoinStatus()) { + join_network(); + } + // Request Message + std::vector<uint8_t> msg; + msg.reserve(16); + // Flag 2 Bytes + msg.push_back(0xEF); + msg.push_back(0x10); + // EUI 8 Bytes + std::vector<uint8_t> eui(dot->getDeviceId()); + msg.insert(msg.end(), eui.begin(), eui.end()); + // Data 2 Bytes + appendUint16ToVector(msg, data); + // SeqNum 4 Bytes + appendUint32ToVector(msg, mMemObj.getLastMsgSeq()); + mMemObj.incLastMsgSeq(); + if (dot->send(msg) == mDot::MDOT_OK) {// Can just send once since the RX should be always listening + return cmdSuccess; + } + else { + return cmdError; + } +} + CmdResult CommProtocolPeerBrute::sendPairReq() { if (!dot->getNetworkJoinStatus()) { @@ -282,6 +314,31 @@ return cmdSuccess; } +CmdResult CommProtocolPeerBrute::recvAlert (std::vector<uint8_t> &eui, uint16_t &data, uint32_t &seqNum) +{ + std::vector<uint8_t> alertMsg; + dot->recv(alertMsg); + if (alertMsg[0] != 0xEF || alertMsg[1] != 0x10) { + myLogError("Invalid alert message flag."); + return cmdError; + } + if (alertMsg.size() < 16) { + myLogError("Alert message too short"); + return cmdError; + } + eui.clear(); + eui.assign(alertMsg.begin()+2, alertMsg.begin()+2+8); + + data = (alertMsg[10] << 8) + alertMsg[11]; + + seqNum = alertMsg[12] << 24; + seqNum += alertMsg[13] << 16; + seqNum += alertMsg[14] << 8; + seqNum += alertMsg[15]; + + return cmdSuccess; +} + CmdResult CommProtocolPeerBrute::waitForPairing(float waitTime) { float t = 0.0; @@ -627,3 +684,7 @@ { return mSeqNum; } +void NvmProtocolObj::incLastMsgSeq() +{ + mSeqNum++; +}