Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
xDotBridge/src/CommProtocolPeerBrute.cpp@55:79ab0bbc5008, 2017-02-27 (annotated)
- Committer:
- Matt Briggs
- Date:
- Mon Feb 27 08:06:36 2017 -0700
- Revision:
- 55:79ab0bbc5008
- Parent:
- 54:c04d7b6fa075
- Child:
- 61:8d9efd33cac9
Adding lots of NVM code to store parameters in eeprom. Also some work on documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 41:9ef4c4d77711 | 1 | /* |
Matt Briggs | 41:9ef4c4d77711 | 2 | * CommProtocolPeerBrute.cpp |
Matt Briggs | 41:9ef4c4d77711 | 3 | * |
Matt Briggs | 41:9ef4c4d77711 | 4 | * Created on: Jan 30, 2017 |
Matt Briggs | 41:9ef4c4d77711 | 5 | * Author: mbriggs |
Matt Briggs | 41:9ef4c4d77711 | 6 | */ |
Matt Briggs | 41:9ef4c4d77711 | 7 | |
Matt Briggs | 41:9ef4c4d77711 | 8 | #include "CommProtocolPeerBrute.h" |
Matt Briggs | 41:9ef4c4d77711 | 9 | #include "MTSLog.h" |
Matt Briggs | 41:9ef4c4d77711 | 10 | #include "dot_util.h" |
Matt Briggs | 41:9ef4c4d77711 | 11 | |
Matt Briggs | 41:9ef4c4d77711 | 12 | // wireless bridge protocol |
Matt Briggs | 41:9ef4c4d77711 | 13 | const uint8_t TX_PWR = 20; // 20 dBm |
Matt Briggs | 41:9ef4c4d77711 | 14 | const float RX_SLEEP_TIME = 2000; // ms (one second resolution, min 2 seconds) |
Matt Briggs | 41:9ef4c4d77711 | 15 | const uint8_t TX_TIME = 30; // in ms |
Matt Briggs | 41:9ef4c4d77711 | 16 | const unsigned int nTimesToTx = ceil(RX_SLEEP_TIME / ((float)TX_TIME)); |
Matt Briggs | 41:9ef4c4d77711 | 17 | //const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion) |
Matt Briggs | 41:9ef4c4d77711 | 18 | |
Matt Briggs | 44:ece6330e9b57 | 19 | CommProtocolPeerBrute::CommProtocolPeerBrute() |
Matt Briggs | 41:9ef4c4d77711 | 20 | { |
Matt Briggs | 41:9ef4c4d77711 | 21 | logInfo("RX_SLEEP_TIME %f, timeOnAir %lu, nTimesToTx %lu", RX_SLEEP_TIME, TX_TIME, nTimesToTx); |
Matt Briggs | 41:9ef4c4d77711 | 22 | |
Matt Briggs | 44:ece6330e9b57 | 23 | mIsTx = true; // default to TX |
Matt Briggs | 54:c04d7b6fa075 | 24 | mPrevDownLinkCnt = dot->getDownLinkCounter(); |
Matt Briggs | 53:a1563574a980 | 25 | // dot = mDot::getInstance(); |
Matt Briggs | 41:9ef4c4d77711 | 26 | } |
Matt Briggs | 41:9ef4c4d77711 | 27 | |
Matt Briggs | 41:9ef4c4d77711 | 28 | CmdResult CommProtocolPeerBrute::init() |
Matt Briggs | 41:9ef4c4d77711 | 29 | { |
Matt Briggs | 55:79ab0bbc5008 | 30 | // FIXME add NVM stuff |
Matt Briggs | 55:79ab0bbc5008 | 31 | dotDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 32 | |
Matt Briggs | 55:79ab0bbc5008 | 33 | } |
Matt Briggs | 55:79ab0bbc5008 | 34 | CmdResult CommProtocolPeerBrute::dotDefaults() |
Matt Briggs | 55:79ab0bbc5008 | 35 | { |
Matt Briggs | 55:79ab0bbc5008 | 36 | // TODO add more error checking |
Matt Briggs | 55:79ab0bbc5008 | 37 | logWarning("defaulting Dot configuration"); |
Matt Briggs | 55:79ab0bbc5008 | 38 | dot->resetConfig(); |
Matt Briggs | 55:79ab0bbc5008 | 39 | |
Matt Briggs | 41:9ef4c4d77711 | 40 | // Common Configuration |
Matt Briggs | 41:9ef4c4d77711 | 41 | dot->setAesEncryption(true); // Enable encryption |
Matt Briggs | 41:9ef4c4d77711 | 42 | dot->setTxWait(false); |
Matt Briggs | 41:9ef4c4d77711 | 43 | dot->setAck(0); // Disable Ack |
Matt Briggs | 41:9ef4c4d77711 | 44 | dot->setClass("C"); // Set class C |
Matt Briggs | 41:9ef4c4d77711 | 45 | dot->setTxPower(TX_PWR); |
Matt Briggs | 55:79ab0bbc5008 | 46 | dot->setPreserveSession(true); // TODO need to better handle counters |
Matt Briggs | 41:9ef4c4d77711 | 47 | |
Matt Briggs | 41:9ef4c4d77711 | 48 | // TODO break out in a utility function |
Matt Briggs | 41:9ef4c4d77711 | 49 | // update configuration if necessary |
Matt Briggs | 41:9ef4c4d77711 | 50 | logInfo("Setting up peer to peer configuration"); |
Matt Briggs | 41:9ef4c4d77711 | 51 | if (dot->getJoinMode() != mDot::PEER_TO_PEER) { |
Matt Briggs | 41:9ef4c4d77711 | 52 | logInfo("changing network join mode to PEER_TO_PEER"); |
Matt Briggs | 41:9ef4c4d77711 | 53 | if (dot->setJoinMode(mDot::PEER_TO_PEER) != mDot::MDOT_OK) { |
Matt Briggs | 41:9ef4c4d77711 | 54 | logError("failed to set network join mode to PEER_TO_PEER"); |
Matt Briggs | 41:9ef4c4d77711 | 55 | } |
Matt Briggs | 41:9ef4c4d77711 | 56 | } |
Matt Briggs | 41:9ef4c4d77711 | 57 | uint8_t tx_power; |
Matt Briggs | 41:9ef4c4d77711 | 58 | uint8_t tx_datarate; |
Matt Briggs | 41:9ef4c4d77711 | 59 | uint32_t tx_frequency; |
Matt Briggs | 41:9ef4c4d77711 | 60 | uint8_t frequency_band = dot->getFrequencyBand(); |
Matt Briggs | 41:9ef4c4d77711 | 61 | switch (frequency_band) { |
Matt Briggs | 41:9ef4c4d77711 | 62 | case mDot::FB_EU868: |
Matt Briggs | 41:9ef4c4d77711 | 63 | // 250kHz channels achieve higher throughput |
Matt Briggs | 41:9ef4c4d77711 | 64 | // DR6 : SF7 @ 250kHz |
Matt Briggs | 41:9ef4c4d77711 | 65 | // DR0 - DR5 (125kHz channels) available but much slower |
Matt Briggs | 41:9ef4c4d77711 | 66 | tx_frequency = 869850000; |
Matt Briggs | 41:9ef4c4d77711 | 67 | tx_datarate = mDot::DR6; |
Matt Briggs | 41:9ef4c4d77711 | 68 | // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7 |
Matt Briggs | 41:9ef4c4d77711 | 69 | tx_power = 4; |
Matt Briggs | 41:9ef4c4d77711 | 70 | break; |
Matt Briggs | 41:9ef4c4d77711 | 71 | case mDot::FB_US915: |
Matt Briggs | 41:9ef4c4d77711 | 72 | case mDot::FB_AU915: |
Matt Briggs | 41:9ef4c4d77711 | 73 | default: |
Matt Briggs | 41:9ef4c4d77711 | 74 | // 500kHz channels achieve highest throughput |
Matt Briggs | 41:9ef4c4d77711 | 75 | // DR8 : SF12 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 76 | // DR9 : SF11 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 77 | // DR10 : SF10 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 78 | // DR11 : SF9 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 79 | // DR12 : SF8 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 80 | // DR13 : SF7 @ 500kHz |
Matt Briggs | 41:9ef4c4d77711 | 81 | // DR0 - DR3 (125kHz channels) available but much slower |
Matt Briggs | 41:9ef4c4d77711 | 82 | tx_frequency = 915500000; |
Matt Briggs | 41:9ef4c4d77711 | 83 | tx_datarate = mDot::DR13; |
Matt Briggs | 41:9ef4c4d77711 | 84 | // 915 bands have no duty cycle restrictions, set tx power to max |
Matt Briggs | 41:9ef4c4d77711 | 85 | tx_power = 20; |
Matt Briggs | 41:9ef4c4d77711 | 86 | break; |
Matt Briggs | 41:9ef4c4d77711 | 87 | } |
Matt Briggs | 41:9ef4c4d77711 | 88 | // in PEER_TO_PEER mode there is no join request/response transaction |
Matt Briggs | 41:9ef4c4d77711 | 89 | // as long as both Dots are configured correctly, they should be able to communicate |
Matt Briggs | 41:9ef4c4d77711 | 90 | |
Matt Briggs | 41:9ef4c4d77711 | 91 | // FIXME just using pairing keys for now |
Matt Briggs | 41:9ef4c4d77711 | 92 | update_peer_to_peer_config(pair_network_address, pair_network_session_key, pair_data_session_key, tx_frequency, tx_datarate, tx_power); |
Matt Briggs | 53:a1563574a980 | 93 | dot->saveConfig(); |
Matt Briggs | 41:9ef4c4d77711 | 94 | return cmdSuccess; |
Matt Briggs | 41:9ef4c4d77711 | 95 | } |
Matt Briggs | 44:ece6330e9b57 | 96 | void CommProtocolPeerBrute::setTx(bool isTx) |
Matt Briggs | 44:ece6330e9b57 | 97 | { |
Matt Briggs | 44:ece6330e9b57 | 98 | mIsTx = isTx; |
Matt Briggs | 44:ece6330e9b57 | 99 | } |
Matt Briggs | 41:9ef4c4d77711 | 100 | bool CommProtocolPeerBrute::isTx() |
Matt Briggs | 41:9ef4c4d77711 | 101 | { |
Matt Briggs | 41:9ef4c4d77711 | 102 | return mIsTx; |
Matt Briggs | 41:9ef4c4d77711 | 103 | } |
Matt Briggs | 41:9ef4c4d77711 | 104 | CmdResult CommProtocolPeerBrute::clearPair() |
Matt Briggs | 41:9ef4c4d77711 | 105 | { |
Matt Briggs | 41:9ef4c4d77711 | 106 | logError("Not implemented yet!!!"); |
Matt Briggs | 41:9ef4c4d77711 | 107 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 108 | } |
Matt Briggs | 41:9ef4c4d77711 | 109 | |
Matt Briggs | 41:9ef4c4d77711 | 110 | // TX focused |
Matt Briggs | 41:9ef4c4d77711 | 111 | CmdResult CommProtocolPeerBrute::send (const std::vector<uint8_t> &msg) |
Matt Briggs | 41:9ef4c4d77711 | 112 | { |
Matt Briggs | 41:9ef4c4d77711 | 113 | if (!dot->getNetworkJoinStatus()) { |
Matt Briggs | 41:9ef4c4d77711 | 114 | join_network(); |
Matt Briggs | 41:9ef4c4d77711 | 115 | } |
Matt Briggs | 41:9ef4c4d77711 | 116 | logInfo("Starting TX. Time: %lu", us_ticker_read()); |
Matt Briggs | 53:a1563574a980 | 117 | for(uint8_t i=0;i<nTimesToTx;++i) { |
Matt Briggs | 41:9ef4c4d77711 | 118 | dot->send(msg); |
Matt Briggs | 41:9ef4c4d77711 | 119 | } |
Matt Briggs | 41:9ef4c4d77711 | 120 | logInfo("Finished TX. Time: %lu", us_ticker_read()); |
Matt Briggs | 41:9ef4c4d77711 | 121 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 122 | } |
Matt Briggs | 41:9ef4c4d77711 | 123 | |
Matt Briggs | 41:9ef4c4d77711 | 124 | CmdResult CommProtocolPeerBrute::sendPairReq() |
Matt Briggs | 41:9ef4c4d77711 | 125 | { |
Matt Briggs | 41:9ef4c4d77711 | 126 | if (!dot->getNetworkJoinStatus()) { |
Matt Briggs | 41:9ef4c4d77711 | 127 | join_network(); |
Matt Briggs | 41:9ef4c4d77711 | 128 | } |
Matt Briggs | 41:9ef4c4d77711 | 129 | logError("Not implemented yet!!!"); |
Matt Briggs | 41:9ef4c4d77711 | 130 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 131 | } |
Matt Briggs | 41:9ef4c4d77711 | 132 | |
Matt Briggs | 41:9ef4c4d77711 | 133 | // RX focused |
Matt Briggs | 41:9ef4c4d77711 | 134 | CmdResult CommProtocolPeerBrute::listen (bool &msgPending) |
Matt Briggs | 41:9ef4c4d77711 | 135 | { |
Matt Briggs | 41:9ef4c4d77711 | 136 | if (!dot->getNetworkJoinStatus()) { |
Matt Briggs | 41:9ef4c4d77711 | 137 | join_network(); |
Matt Briggs | 41:9ef4c4d77711 | 138 | } |
Matt Briggs | 41:9ef4c4d77711 | 139 | |
Matt Briggs | 54:c04d7b6fa075 | 140 | // uint32_t cDwnLink = dot->getDownLinkCounter(); |
Matt Briggs | 41:9ef4c4d77711 | 141 | |
Matt Briggs | 41:9ef4c4d77711 | 142 | wait(TX_TIME/1000.0); // Wait TX_TIME |
Matt Briggs | 41:9ef4c4d77711 | 143 | |
Matt Briggs | 54:c04d7b6fa075 | 144 | if (mPrevDownLinkCnt < dot->getDownLinkCounter()) { |
Matt Briggs | 41:9ef4c4d77711 | 145 | msgPending = true; |
Matt Briggs | 41:9ef4c4d77711 | 146 | } |
Matt Briggs | 41:9ef4c4d77711 | 147 | else { |
Matt Briggs | 41:9ef4c4d77711 | 148 | msgPending = false; |
Matt Briggs | 41:9ef4c4d77711 | 149 | } |
Matt Briggs | 54:c04d7b6fa075 | 150 | mPrevDownLinkCnt = dot->getDownLinkCounter(); |
Matt Briggs | 41:9ef4c4d77711 | 151 | return cmdSuccess; // Maybe add timeout as a possible return value |
Matt Briggs | 41:9ef4c4d77711 | 152 | } |
Matt Briggs | 41:9ef4c4d77711 | 153 | |
Matt Briggs | 54:c04d7b6fa075 | 154 | CmdResult CommProtocolPeerBrute::sampleDLC () { |
Matt Briggs | 54:c04d7b6fa075 | 155 | mPrevDownLinkCnt = dot->getDownLinkCounter(); |
Matt Briggs | 54:c04d7b6fa075 | 156 | return cmdSuccess; |
Matt Briggs | 54:c04d7b6fa075 | 157 | } |
Matt Briggs | 54:c04d7b6fa075 | 158 | |
Matt Briggs | 41:9ef4c4d77711 | 159 | CmdResult CommProtocolPeerBrute::recv (std::vector<uint8_t> &msg) |
Matt Briggs | 41:9ef4c4d77711 | 160 | { |
Matt Briggs | 41:9ef4c4d77711 | 161 | dot->recv(msg); |
Matt Briggs | 41:9ef4c4d77711 | 162 | return cmdSuccess; |
Matt Briggs | 41:9ef4c4d77711 | 163 | } |
Matt Briggs | 41:9ef4c4d77711 | 164 | |
Matt Briggs | 41:9ef4c4d77711 | 165 | CmdResult CommProtocolPeerBrute::waitForPairing(float waitTime) |
Matt Briggs | 41:9ef4c4d77711 | 166 | { |
Matt Briggs | 41:9ef4c4d77711 | 167 | logError("Not implemented yet!!!"); |
Matt Briggs | 41:9ef4c4d77711 | 168 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 169 | } |
Matt Briggs | 41:9ef4c4d77711 | 170 | |
Matt Briggs | 41:9ef4c4d77711 | 171 | CmdResult CommProtocolPeerBrute::sendPairAccepted() |
Matt Briggs | 41:9ef4c4d77711 | 172 | { |
Matt Briggs | 41:9ef4c4d77711 | 173 | logError("Not implemented yet!!!"); |
Matt Briggs | 41:9ef4c4d77711 | 174 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 175 | } |
Matt Briggs | 41:9ef4c4d77711 | 176 | |
Matt Briggs | 41:9ef4c4d77711 | 177 | // xDot Peer to Peer Specific |
Matt Briggs | 41:9ef4c4d77711 | 178 | uint32_t CommProtocolPeerBrute::getDLC() |
Matt Briggs | 41:9ef4c4d77711 | 179 | { |
Matt Briggs | 41:9ef4c4d77711 | 180 | return dot->getDownLinkCounter(); |
Matt Briggs | 41:9ef4c4d77711 | 181 | } |
Matt Briggs | 41:9ef4c4d77711 | 182 | |
Matt Briggs | 41:9ef4c4d77711 | 183 | uint32_t CommProtocolPeerBrute::getULC() |
Matt Briggs | 41:9ef4c4d77711 | 184 | { |
Matt Briggs | 41:9ef4c4d77711 | 185 | return dot->getUpLinkCounter(); |
Matt Briggs | 41:9ef4c4d77711 | 186 | } |
Matt Briggs | 41:9ef4c4d77711 | 187 | |
Matt Briggs | 41:9ef4c4d77711 | 188 | // private: |
Matt Briggs | 41:9ef4c4d77711 | 189 | |
Matt Briggs | 41:9ef4c4d77711 | 190 | CmdResult CommProtocolPeerBrute::readInfoFromNVM() |
Matt Briggs | 41:9ef4c4d77711 | 191 | { |
Matt Briggs | 55:79ab0bbc5008 | 192 | // TODO store / retrieve network keys |
Matt Briggs | 55:79ab0bbc5008 | 193 | bool nvmReadResult; |
Matt Briggs | 55:79ab0bbc5008 | 194 | uint8_t *data = new uint8_t [PROTOCOL_NVM_SIZE]; |
Matt Briggs | 55:79ab0bbc5008 | 195 | |
Matt Briggs | 55:79ab0bbc5008 | 196 | nvmReadResult = dot->nvmRead(PROTOCOL_NVM_START_ADDR, data, PROTOCOL_NVM_SIZE); |
Matt Briggs | 55:79ab0bbc5008 | 197 | if (!nvmReadResult) { |
Matt Briggs | 55:79ab0bbc5008 | 198 | delete [] data; |
Matt Briggs | 55:79ab0bbc5008 | 199 | return cmdError; |
Matt Briggs | 55:79ab0bbc5008 | 200 | } |
Matt Briggs | 55:79ab0bbc5008 | 201 | mMemObj.fromBytes(data, PROTOCOL_NVM_SIZE); |
Matt Briggs | 55:79ab0bbc5008 | 202 | delete [] data; |
Matt Briggs | 55:79ab0bbc5008 | 203 | if (!mMemObj.validProtocolFlag()) { |
Matt Briggs | 55:79ab0bbc5008 | 204 | logWarning("Invalid Protocol Flag. Using default values."); |
Matt Briggs | 55:79ab0bbc5008 | 205 | mMemObj.setDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 206 | dotDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 207 | } |
Matt Briggs | 55:79ab0bbc5008 | 208 | else if (!mMemObj.validProtocolRev()) { |
Matt Briggs | 55:79ab0bbc5008 | 209 | logWarning("Invalid Protocol Rev. Using default values."); |
Matt Briggs | 55:79ab0bbc5008 | 210 | mMemObj.setDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 211 | dotDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 212 | } |
Matt Briggs | 55:79ab0bbc5008 | 213 | return cmdSuccess; |
Matt Briggs | 41:9ef4c4d77711 | 214 | } |
Matt Briggs | 41:9ef4c4d77711 | 215 | |
Matt Briggs | 41:9ef4c4d77711 | 216 | CmdResult CommProtocolPeerBrute::writeInfoToNVM() |
Matt Briggs | 41:9ef4c4d77711 | 217 | { |
Matt Briggs | 55:79ab0bbc5008 | 218 | uint8_t *data = new uint8_t [PROTOCOL_NVM_SIZE]; |
Matt Briggs | 55:79ab0bbc5008 | 219 | uint8_t size = PROTOCOL_NVM_SIZE; |
Matt Briggs | 55:79ab0bbc5008 | 220 | mMemObj.toBytes(data, size); |
Matt Briggs | 55:79ab0bbc5008 | 221 | dot->nvmWrite(PROTOCOL_NVM_START_ADDR, data, PROTOCOL_NVM_SIZE); |
Matt Briggs | 55:79ab0bbc5008 | 222 | |
Matt Briggs | 55:79ab0bbc5008 | 223 | delete [] data; |
Matt Briggs | 55:79ab0bbc5008 | 224 | return cmdSuccess; |
Matt Briggs | 41:9ef4c4d77711 | 225 | } |
Matt Briggs | 41:9ef4c4d77711 | 226 | |
Matt Briggs | 41:9ef4c4d77711 | 227 | CmdResult CommProtocolPeerBrute::resetCounters() |
Matt Briggs | 41:9ef4c4d77711 | 228 | { |
Matt Briggs | 41:9ef4c4d77711 | 229 | dot->setDownLinkCounter(0); |
Matt Briggs | 41:9ef4c4d77711 | 230 | dot->setUpLinkCounter(0); |
Matt Briggs | 41:9ef4c4d77711 | 231 | return cmdSuccess; |
Matt Briggs | 41:9ef4c4d77711 | 232 | } |
Matt Briggs | 41:9ef4c4d77711 | 233 | |
Matt Briggs | 41:9ef4c4d77711 | 234 | CmdResult CommProtocolPeerBrute::genEncypKeys() |
Matt Briggs | 41:9ef4c4d77711 | 235 | { |
Matt Briggs | 41:9ef4c4d77711 | 236 | logError("Not implemented yet!!!"); |
Matt Briggs | 41:9ef4c4d77711 | 237 | return cmdError; |
Matt Briggs | 41:9ef4c4d77711 | 238 | } |
Matt Briggs | 55:79ab0bbc5008 | 239 | |
Matt Briggs | 55:79ab0bbc5008 | 240 | // NvmProtocolObj |
Matt Briggs | 55:79ab0bbc5008 | 241 | NvmProtocolObj::NvmProtocolObj() |
Matt Briggs | 55:79ab0bbc5008 | 242 | { |
Matt Briggs | 55:79ab0bbc5008 | 243 | setDefaults(); |
Matt Briggs | 55:79ab0bbc5008 | 244 | } |
Matt Briggs | 55:79ab0bbc5008 | 245 | void NvmProtocolObj::setDefaults() |
Matt Briggs | 55:79ab0bbc5008 | 246 | { |
Matt Briggs | 55:79ab0bbc5008 | 247 | mProtocolFlag = PROTOCOL_FLAG; |
Matt Briggs | 55:79ab0bbc5008 | 248 | mProtocolRev = PROTOCOL_REV; |
Matt Briggs | 55:79ab0bbc5008 | 249 | mLogicalAddr = 0x00000000; |
Matt Briggs | 55:79ab0bbc5008 | 250 | mSeqNum = 0x00000000; |
Matt Briggs | 55:79ab0bbc5008 | 251 | } |
Matt Briggs | 55:79ab0bbc5008 | 252 | CmdResult NvmProtocolObj::fromBytes(uint8_t *data, uint8_t size) |
Matt Briggs | 55:79ab0bbc5008 | 253 | { |
Matt Briggs | 55:79ab0bbc5008 | 254 | if (size != PROTOCOL_NVM_SIZE) { |
Matt Briggs | 55:79ab0bbc5008 | 255 | return cmdError; |
Matt Briggs | 55:79ab0bbc5008 | 256 | } |
Matt Briggs | 55:79ab0bbc5008 | 257 | |
Matt Briggs | 55:79ab0bbc5008 | 258 | mProtocolFlag = *((uint16_t *) (data)); |
Matt Briggs | 55:79ab0bbc5008 | 259 | mProtocolRev = *((uint16_t *) (data+2)); |
Matt Briggs | 55:79ab0bbc5008 | 260 | mLogicalAddr = *((uint32_t *) (data+4)); |
Matt Briggs | 55:79ab0bbc5008 | 261 | mSeqNum = *((uint32_t *) (data+6)); |
Matt Briggs | 55:79ab0bbc5008 | 262 | |
Matt Briggs | 55:79ab0bbc5008 | 263 | return cmdSuccess; |
Matt Briggs | 55:79ab0bbc5008 | 264 | } |
Matt Briggs | 55:79ab0bbc5008 | 265 | CmdResult NvmProtocolObj::toBytes(uint8_t *data, uint8_t &size) { |
Matt Briggs | 55:79ab0bbc5008 | 266 | // TODO check data size |
Matt Briggs | 55:79ab0bbc5008 | 267 | |
Matt Briggs | 55:79ab0bbc5008 | 268 | *((uint16_t *) (data)) = mProtocolFlag; |
Matt Briggs | 55:79ab0bbc5008 | 269 | *((uint16_t *) (data+2)) = mProtocolRev; |
Matt Briggs | 55:79ab0bbc5008 | 270 | *((uint32_t *) (data+4)) = mLogicalAddr; |
Matt Briggs | 55:79ab0bbc5008 | 271 | *((uint32_t *) (data+6)) = mSeqNum; |
Matt Briggs | 55:79ab0bbc5008 | 272 | |
Matt Briggs | 55:79ab0bbc5008 | 273 | size = PROTOCOL_NVM_SIZE; |
Matt Briggs | 55:79ab0bbc5008 | 274 | |
Matt Briggs | 55:79ab0bbc5008 | 275 | return cmdSuccess; |
Matt Briggs | 55:79ab0bbc5008 | 276 | } |
Matt Briggs | 55:79ab0bbc5008 | 277 | uint16_t NvmProtocolObj::getProtocolFlag() |
Matt Briggs | 55:79ab0bbc5008 | 278 | { |
Matt Briggs | 55:79ab0bbc5008 | 279 | return mProtocolFlag; |
Matt Briggs | 55:79ab0bbc5008 | 280 | } |
Matt Briggs | 55:79ab0bbc5008 | 281 | bool NvmProtocolObj::validProtocolFlag() |
Matt Briggs | 55:79ab0bbc5008 | 282 | { |
Matt Briggs | 55:79ab0bbc5008 | 283 | return mProtocolFlag == PROTOCOL_FLAG; |
Matt Briggs | 55:79ab0bbc5008 | 284 | } |
Matt Briggs | 55:79ab0bbc5008 | 285 | uint16_t NvmProtocolObj::getProtocolRev() |
Matt Briggs | 55:79ab0bbc5008 | 286 | { |
Matt Briggs | 55:79ab0bbc5008 | 287 | return mProtocolRev; |
Matt Briggs | 55:79ab0bbc5008 | 288 | } |
Matt Briggs | 55:79ab0bbc5008 | 289 | bool NvmProtocolObj::validProtocolRev() |
Matt Briggs | 55:79ab0bbc5008 | 290 | { |
Matt Briggs | 55:79ab0bbc5008 | 291 | return mProtocolRev == PROTOCOL_REV; |
Matt Briggs | 55:79ab0bbc5008 | 292 | } |
Matt Briggs | 55:79ab0bbc5008 | 293 | uint16_t NvmProtocolObj::getLogicalAddr() |
Matt Briggs | 55:79ab0bbc5008 | 294 | { |
Matt Briggs | 55:79ab0bbc5008 | 295 | return mLogicalAddr; |
Matt Briggs | 55:79ab0bbc5008 | 296 | } |
Matt Briggs | 55:79ab0bbc5008 | 297 | void NvmProtocolObj::setLogicalAddr(uint16_t in) |
Matt Briggs | 55:79ab0bbc5008 | 298 | { |
Matt Briggs | 55:79ab0bbc5008 | 299 | mLogicalAddr= in; |
Matt Briggs | 55:79ab0bbc5008 | 300 | } |
Matt Briggs | 55:79ab0bbc5008 | 301 | uint32_t NvmProtocolObj::getLastMsgSeq() |
Matt Briggs | 55:79ab0bbc5008 | 302 | { |
Matt Briggs | 55:79ab0bbc5008 | 303 | return mSeqNum; |
Matt Briggs | 55:79ab0bbc5008 | 304 | } |