Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Committer:
Matt Briggs
Date:
Fri Mar 24 08:15:37 2017 -0600
Revision:
69:eb391644b346
Parent:
68:51c25f4f6d9a
Child:
71:2b57529df137
Improved pair button functionality and added eeprom logging

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Matt Briggs 34:5618603e5fc3 1 #include <math.h>
Matt Briggs 22:9453658b8d4b 2 #include "config.h"
Matt Briggs 30:2e673a672884 3 #include "xdot_flash.h"
Mike Fiore 11:d2e31743433a 4 #include "dot_util.h"
Mike Fiore 14:19fae4509473 5 #include "RadioEvent.h"
Matt Briggs 47:a68747642a7a 6 #include "WinbondSPIFlash.h"
Matt Briggs 58:15aa7a785b9f 7 #include "UserInterface.h"
Matt Briggs 41:9ef4c4d77711 8 //#include <xdot_low_power.h>
Matt Briggs 58:15aa7a785b9f 9 #include "mDot.h"
Matt Briggs 63:e1efbe3402d9 10 #include "MyLog.h"
Matt Briggs 69:eb391644b346 11 #include "SimpleRxSeqLog.h"
mfiore 17:d4f82e16de5f 12
Matt Briggs 47:a68747642a7a 13 #include "BaseboardIO.h"
Matt Briggs 41:9ef4c4d77711 14 #include "CommProtocolPeerBrute.h"
Matt Briggs 31:9c535a708ae9 15
Matt Briggs 69:eb391644b346 16 #define RX_SEQ_LOG 1
Matt Briggs 69:eb391644b346 17
Matt Briggs 69:eb391644b346 18 const float BridgeVersion = 0.2;
Matt Briggs 69:eb391644b346 19
Matt Briggs 47:a68747642a7a 20 #ifndef __TEST__ // Exclude code for tests
Mike Fiore 11:d2e31743433a 21 Serial pc(USBTX, USBRX);
Mike Fiore 11:d2e31743433a 22
Matt Briggs 47:a68747642a7a 23 mDot* dot = NULL; // Used by dot-utils
Matt Briggs 39:64f79fa6e3cc 24
Matt Briggs 50:e89647e77fd5 25 volatile bool ccIntFlag;
Matt Briggs 50:e89647e77fd5 26 volatile bool tamperIntFlag;
Matt Briggs 50:e89647e77fd5 27 volatile bool pairBtnIntFlag;
Matt Briggs 50:e89647e77fd5 28 void ccInIntCallback () {
Matt Briggs 50:e89647e77fd5 29 ccIntFlag = true;
Matt Briggs 50:e89647e77fd5 30 }
Matt Briggs 50:e89647e77fd5 31 void tamperIntCallback () {
Matt Briggs 50:e89647e77fd5 32 tamperIntFlag = true;
Matt Briggs 50:e89647e77fd5 33 }
Matt Briggs 50:e89647e77fd5 34 void pairBtnIntCallback () {
Matt Briggs 50:e89647e77fd5 35 pairBtnIntFlag = true;
Matt Briggs 50:e89647e77fd5 36 }
Matt Briggs 50:e89647e77fd5 37
Mike Fiore 11:d2e31743433a 38 int main() {
Matt Briggs 53:a1563574a980 39 CommProtocolPeerBrute *protocol = new CommProtocolPeerBrute();
Matt Briggs 53:a1563574a980 40 BaseboardIO *bbio = new BaseboardIO();
Matt Briggs 58:15aa7a785b9f 41 WinbondSPIFlash *flash = new WinbondSPIFlash(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_NSS);
Matt Briggs 58:15aa7a785b9f 42
Matt Briggs 52:64a2c71c7c49 43 CmdResult result;
Matt Briggs 50:e89647e77fd5 44 ccIntFlag = false;
Matt Briggs 50:e89647e77fd5 45 tamperIntFlag = false;
Matt Briggs 50:e89647e77fd5 46 pairBtnIntFlag = false;
Matt Briggs 48:bab9f747d9ed 47 pc.baud(115200);
Matt Briggs 48:bab9f747d9ed 48
Matt Briggs 31:9c535a708ae9 49 RadioEvent events; // Custom event handler for automatically displaying RX data
Matt Briggs 69:eb391644b346 50 #if RX_SEQ_LOG
Matt Briggs 69:eb391644b346 51 SimpleRxSeqLog rxSeqLog(0x0000);
Matt Briggs 69:eb391644b346 52 rxSeqLog.read();
Matt Briggs 69:eb391644b346 53 #endif
Mike Fiore 11:d2e31743433a 54
Matt Briggs 27:6b68ff715ae1 55 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
Matt Briggs 66:bcaa6dbf538a 56 MyLog::setLogLevel(MyLog::DEBUG_LEVEL);
Matt Briggs 47:a68747642a7a 57
Mike Fiore 11:d2e31743433a 58 dot = mDot::getInstance();
Mike Fiore 11:d2e31743433a 59
Mike Fiore 11:d2e31743433a 60 // make sure library logging is turned on
Matt Briggs 66:bcaa6dbf538a 61 dot->setLogLevel(mts::MTSLog::WARNING_LEVEL);
Mike Fiore 11:d2e31743433a 62
Matt Briggs 63:e1efbe3402d9 63 myLogInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
Matt Briggs 63:e1efbe3402d9 64 myLogInfo("libxDot-mbed5 library ID: %s", dot->getId().c_str());
Matt Briggs 69:eb391644b346 65 myLogInfo("Vortex Wireless Bridge SW Version %0.2f", BridgeVersion);
Matt Briggs 62:9751a8504c82 66
Mike Fiore 11:d2e31743433a 67 // attach the custom events handler
Matt Briggs 54:c04d7b6fa075 68 dot->setEvents(&events); // Little bonus event debug information
Matt Briggs 53:a1563574a980 69
Matt Briggs 53:a1563574a980 70 // Finish radio init
Matt Briggs 63:e1efbe3402d9 71 myLogInfo("= Protocol Init Starting =\r\n");
Matt Briggs 53:a1563574a980 72 protocol->init();
Matt Briggs 62:9751a8504c82 73 if (result == cmdSuccess) {
Matt Briggs 63:e1efbe3402d9 74 myLogInfo("= Protocol Init Finished Successfully =\r\n");
Matt Briggs 62:9751a8504c82 75 }
Matt Briggs 62:9751a8504c82 76 else {
Matt Briggs 63:e1efbe3402d9 77 myLogInfo("= Protocol Init Finished with Error =\r\n");
Matt Briggs 62:9751a8504c82 78 }
Matt Briggs 63:e1efbe3402d9 79 protocol->printDotConfig();
Matt Briggs 53:a1563574a980 80
Matt Briggs 53:a1563574a980 81 // save changes to configuration
Matt Briggs 53:a1563574a980 82 // logInfo("saving configuration");
Matt Briggs 53:a1563574a980 83 // core_util_critical_section_enter();
Matt Briggs 53:a1563574a980 84 // bool dotConfigSaved = dot->saveConfig();
Matt Briggs 53:a1563574a980 85 // core_util_critical_section_exit();
Matt Briggs 53:a1563574a980 86 // if (!dotConfigSaved) {
Matt Briggs 53:a1563574a980 87 // logError("failed to save configuration");
Matt Briggs 53:a1563574a980 88 // }
Mike Fiore 11:d2e31743433a 89
Matt Briggs 31:9c535a708ae9 90 // Setup programmable voltage detector
Matt Briggs 31:9c535a708ae9 91 // PVD_LEVEL0 Falling 1.85
Matt Briggs 31:9c535a708ae9 92 // PVD_LEVEL1 Falling 2.04
Matt Briggs 31:9c535a708ae9 93 // PVD_LEVEL2 Falling 2.24
Matt Briggs 31:9c535a708ae9 94 // PVD_LEVEL3 Falling 2.44
Matt Briggs 31:9c535a708ae9 95 // PVD_LEVEL4 Falling 2.64
Matt Briggs 31:9c535a708ae9 96 // PVD_LEVEL5 Falling 2.84
Matt Briggs 31:9c535a708ae9 97 // PVD_LEVEL6 Falling 3.05
Matt Briggs 50:e89647e77fd5 98 // PWR_PVDTypeDef pvdConfig;
Matt Briggs 50:e89647e77fd5 99 // pvdConfig.Mode = PWR_PVD_MODE_NORMAL;
Matt Briggs 50:e89647e77fd5 100 // pvdConfig.PVDLevel = PWR_PVDLEVEL_5;
Matt Briggs 50:e89647e77fd5 101 //
Matt Briggs 50:e89647e77fd5 102 // HAL_PWR_ConfigPVD(&pvdConfig);
Matt Briggs 50:e89647e77fd5 103 // HAL_PWR_EnablePVD();
Matt Briggs 50:e89647e77fd5 104 // logInfo("Programmable Voltage Detector set for level: %d", pvdConfig.PVDLevel);
Matt Briggs 50:e89647e77fd5 105 // // HAL_PWR_PVDCallback need to define this I think this will override the current implementation
Mike Fiore 11:d2e31743433a 106
Matt Briggs 58:15aa7a785b9f 107 dot->setWakeMode(mDot::RTC_ALARM_OR_INTERRUPT);
Matt Briggs 54:c04d7b6fa075 108 dot->setWakePin(UART1_RX);
Matt Briggs 24:fdf87e4b72e5 109
Matt Briggs 62:9751a8504c82 110 display_config(); // Print configuration for now
Matt Briggs 62:9751a8504c82 111
Mike Fiore 11:d2e31743433a 112 // display configuration
Matt Briggs 53:a1563574a980 113 // display_config();
Matt Briggs 52:64a2c71c7c49 114
Matt Briggs 63:e1efbe3402d9 115 myLogInfo("= Baseboard Init Starting =\r\n");
Matt Briggs 53:a1563574a980 116 result = bbio->init();
Matt Briggs 52:64a2c71c7c49 117 if (result == cmdSuccess) {
Matt Briggs 63:e1efbe3402d9 118 myLogInfo("= Baseboard Init Finished Successfully =\r\n");
Matt Briggs 52:64a2c71c7c49 119 }
Matt Briggs 52:64a2c71c7c49 120 else {
Matt Briggs 63:e1efbe3402d9 121 myLogInfo("= Baseboard Init Finished with Error =\r\n");
Matt Briggs 52:64a2c71c7c49 122 }
Matt Briggs 64:46c8819c07cc 123 LedPatterns ledPatterns(bbio);
Mike Fiore 11:d2e31743433a 124
Matt Briggs 50:e89647e77fd5 125 Callback<void()> ccInIntObj (&ccInIntCallback);
Matt Briggs 69:eb391644b346 126 // Callback<void()> tamperIntObj (&tamperIntCallback);
Matt Briggs 50:e89647e77fd5 127 Callback<void()> pairBtnIntObj (&pairBtnIntCallback);
Matt Briggs 50:e89647e77fd5 128
Matt Briggs 53:a1563574a980 129 bbio->sampleUserSwitches();
Matt Briggs 53:a1563574a980 130 bbio->relayNormal(); // Always force relay in known state
Matt Briggs 58:15aa7a785b9f 131 bbio->regCCInInt(ccInIntObj);
Matt Briggs 69:eb391644b346 132 // bbio->regTamperInt(tamperIntObj);
Matt Briggs 58:15aa7a785b9f 133 bbio->regPairBtnInt(pairBtnIntObj);
Matt Briggs 26:9411b26a5084 134
Matt Briggs 66:bcaa6dbf538a 135 if (bbio->isTx()) {
Matt Briggs 66:bcaa6dbf538a 136 protocol->setTx(true);
Matt Briggs 66:bcaa6dbf538a 137 }
Matt Briggs 66:bcaa6dbf538a 138 else { // RX
Matt Briggs 66:bcaa6dbf538a 139 protocol->setTx(false);
Matt Briggs 66:bcaa6dbf538a 140 }
Matt Briggs 66:bcaa6dbf538a 141
Matt Briggs 58:15aa7a785b9f 142 // Start flash powered down
Matt Briggs 58:15aa7a785b9f 143 flash->powerDown();
Matt Briggs 58:15aa7a785b9f 144
Matt Briggs 69:eb391644b346 145 unsigned int loopCnt = 0; // Just a quick temp variable to keep track of loopNums
Matt Briggs 58:15aa7a785b9f 146 bool prevCCNormallyOpen;
Matt Briggs 61:8d9efd33cac9 147 PairBtnState pairBtnState;
Matt Briggs 67:2115a2f1b945 148 uint32_t rxMsgCnt = 0;
Matt Briggs 69:eb391644b346 149 uint32_t maxSeenMsgSeqNum = 0;
Matt Briggs 47:a68747642a7a 150 /**
Matt Briggs 47:a68747642a7a 151 * Main Loop
Matt Briggs 47:a68747642a7a 152 */
Mike Fiore 11:d2e31743433a 153 while (true) {
Matt Briggs 69:eb391644b346 154 // myLogInfo("Start of loop time %d", us_ticker_read());
Matt Briggs 64:46c8819c07cc 155 ledPatterns.turnOff();
Matt Briggs 47:a68747642a7a 156
Matt Briggs 66:bcaa6dbf538a 157 // Pair logic and switch sampling
Matt Briggs 61:8d9efd33cac9 158 if (pairBtnIntFlag) {
Matt Briggs 61:8d9efd33cac9 159 pairBtnState = PairBtnInterp::read(bbio);
Matt Briggs 66:bcaa6dbf538a 160
Matt Briggs 66:bcaa6dbf538a 161 // Sample IO and update any configuration
Matt Briggs 66:bcaa6dbf538a 162 prevCCNormallyOpen = bbio->isCCNO();
Matt Briggs 66:bcaa6dbf538a 163 bbio->sampleUserSwitches();
Matt Briggs 66:bcaa6dbf538a 164 if (prevCCNormallyOpen != bbio->isCCNO()) { // Only activate the coil if the DIP SW has changed
Matt Briggs 66:bcaa6dbf538a 165 bbio->regCCInInt(ccInIntObj);
Matt Briggs 66:bcaa6dbf538a 166 bbio->relayNormal();
Matt Briggs 66:bcaa6dbf538a 167 }
Matt Briggs 66:bcaa6dbf538a 168 if (bbio->isTx()) {
Matt Briggs 66:bcaa6dbf538a 169 protocol->setTx(true);
Matt Briggs 66:bcaa6dbf538a 170 }
Matt Briggs 66:bcaa6dbf538a 171 else { // RX
Matt Briggs 66:bcaa6dbf538a 172 protocol->setTx(false);
Matt Briggs 66:bcaa6dbf538a 173 }
Matt Briggs 61:8d9efd33cac9 174 if (protocol->isTx()) {
Matt Briggs 61:8d9efd33cac9 175 if (pairBtnState == pairBtnMediumPress) {
Matt Briggs 62:9751a8504c82 176 protocol->configForPairingNetwork();
Matt Briggs 61:8d9efd33cac9 177 protocol->sendPairReq();
Matt Briggs 63:e1efbe3402d9 178 myLogInfo("Sent pair request. Waiting %f secs for accept.", TX_ACCEPT_WAIT_TIME);
Matt Briggs 61:8d9efd33cac9 179 result = protocol->waitForAccept(TX_ACCEPT_WAIT_TIME);
Matt Briggs 61:8d9efd33cac9 180 if (result == cmdSuccess) {
Matt Briggs 63:e1efbe3402d9 181 myLogInfo("Got accept");
Matt Briggs 64:46c8819c07cc 182 ledPatterns.turnOff();
Matt Briggs 64:46c8819c07cc 183 wait(0.5);
Matt Briggs 64:46c8819c07cc 184 ledPatterns.tripleBlink();
Matt Briggs 61:8d9efd33cac9 185 }
Matt Briggs 61:8d9efd33cac9 186 else {
Matt Briggs 63:e1efbe3402d9 187 myLogInfo("Did not receive accept");
Matt Briggs 61:8d9efd33cac9 188 }
Matt Briggs 62:9751a8504c82 189 protocol->configForSavedNetwork();
Matt Briggs 63:e1efbe3402d9 190 protocol->printDotConfig();
Matt Briggs 64:46c8819c07cc 191 protocol->resetCounters();
Matt Briggs 61:8d9efd33cac9 192 }
Matt Briggs 61:8d9efd33cac9 193 }
Matt Briggs 61:8d9efd33cac9 194 if (protocol->isRx()) {
Matt Briggs 61:8d9efd33cac9 195 if (pairBtnState == pairBtnMediumPress) {
Matt Briggs 62:9751a8504c82 196 protocol->configForPairingNetwork();
Matt Briggs 64:46c8819c07cc 197 ledPatterns.turnOn();
Matt Briggs 63:e1efbe3402d9 198 myLogInfo("Waiting for pair request for %f seconds", RX_PAIR_WAIT_TIME);
Matt Briggs 61:8d9efd33cac9 199 result = protocol->waitForPairing(RX_PAIR_WAIT_TIME);
Matt Briggs 64:46c8819c07cc 200 ledPatterns.turnOff();
Matt Briggs 61:8d9efd33cac9 201 if (result == cmdSuccess) {
Matt Briggs 63:e1efbe3402d9 202 myLogInfo("Got pair request and responded");
Matt Briggs 64:46c8819c07cc 203 ledPatterns.tripleBlink();
Matt Briggs 61:8d9efd33cac9 204 }
Matt Briggs 61:8d9efd33cac9 205 else if (result == cmdTimeout) {
Matt Briggs 63:e1efbe3402d9 206 myLogInfo("Did not receive request");
Matt Briggs 61:8d9efd33cac9 207 }
Matt Briggs 61:8d9efd33cac9 208 else {
Matt Briggs 63:e1efbe3402d9 209 myLogInfo("Unknown pair error");
Matt Briggs 61:8d9efd33cac9 210 }
Matt Briggs 62:9751a8504c82 211 protocol->configForSavedNetwork();
Matt Briggs 63:e1efbe3402d9 212 protocol->printDotConfig();
Matt Briggs 64:46c8819c07cc 213 protocol->resetCounters();
Matt Briggs 61:8d9efd33cac9 214 }
Matt Briggs 61:8d9efd33cac9 215 else if (pairBtnState == pairBtnLongPress) {
Matt Briggs 63:e1efbe3402d9 216 myLogInfo("Clearing pair values and generating new ones.");
Matt Briggs 61:8d9efd33cac9 217 protocol->clearPair();
Matt Briggs 63:e1efbe3402d9 218 protocol->printDotConfig();
Matt Briggs 64:46c8819c07cc 219 ledPatterns.tenBlinks();
Matt Briggs 64:46c8819c07cc 220 protocol->resetCounters();
Matt Briggs 61:8d9efd33cac9 221 }
Matt Briggs 61:8d9efd33cac9 222 }
Matt Briggs 61:8d9efd33cac9 223 }
Matt Briggs 69:eb391644b346 224 else {
Matt Briggs 69:eb391644b346 225 pairBtnState = pairBtnNoPress;
Matt Briggs 69:eb391644b346 226 }
Matt Briggs 69:eb391644b346 227 pairBtnIntFlag = false;
Matt Briggs 47:a68747642a7a 228
Matt Briggs 69:eb391644b346 229 myLogInfo("Loop #%d. isTX %d, CCFlag %d, CCAlertState %d, TamperFlag %d, PairBtnState %d",
Matt Briggs 69:eb391644b346 230 loopCnt, protocol->isTx(), ccIntFlag, bbio->isCCInAlert(), tamperIntFlag, pairBtnState);
Matt Briggs 61:8d9efd33cac9 231 // Alert code
Matt Briggs 53:a1563574a980 232 if (protocol->isTx()) {
Matt Briggs 53:a1563574a980 233 // TODO add tamper
Matt Briggs 50:e89647e77fd5 234 if (ccIntFlag || // If contact closure in
Matt Briggs 57:bdac7dd17af2 235 bbio->isCCInAlert() || // If closure remains in effect
Matt Briggs 69:eb391644b346 236 pairBtnState == pairBtnShortPress) {
Matt Briggs 50:e89647e77fd5 237 ccIntFlag = false;
Matt Briggs 64:46c8819c07cc 238 ledPatterns.turnOn();
Matt Briggs 50:e89647e77fd5 239
Matt Briggs 66:bcaa6dbf538a 240 myLogInfo("Sending msg num: %d.", protocol->getSeqNum());
Matt Briggs 65:d546060aa03d 241 protocol->sendAlert(0xBEEF); // TODO use this field to encode the alert type e.g. CCIN vs tamper
Matt Briggs 64:46c8819c07cc 242 ledPatterns.turnOff();
Matt Briggs 50:e89647e77fd5 243 }
Matt Briggs 50:e89647e77fd5 244
Matt Briggs 64:46c8819c07cc 245 ledPatterns.turnOff();
Matt Briggs 69:eb391644b346 246 // tamperIntFlag = false;
Matt Briggs 69:eb391644b346 247 if (pairBtnIntFlag) {// An Interrupt happened during transmission
Matt Briggs 69:eb391644b346 248 continue; // Go straight to pair handling
Matt Briggs 69:eb391644b346 249 }
Matt Briggs 58:15aa7a785b9f 250 bbio->prepareSleep();
Matt Briggs 57:bdac7dd17af2 251 if (bbio->isCCInAlert()) { // Still in alert mode
Matt Briggs 68:51c25f4f6d9a 252 // Sleep for 5 seconds to ensure that receiver does not miss a message sequence
Matt Briggs 68:51c25f4f6d9a 253 dot->sleep(5, mDot::RTC_ALARM_OR_INTERRUPT, false); // Go to sleep and check in 5 secs if CCInAlert is asserted
Matt Briggs 57:bdac7dd17af2 254 }
Matt Briggs 57:bdac7dd17af2 255 else {
Matt Briggs 57:bdac7dd17af2 256 dot->sleep(0, mDot::INTERRUPT, false); // Go to sleep until wake button
Matt Briggs 57:bdac7dd17af2 257 }
Matt Briggs 58:15aa7a785b9f 258 bbio->exitSleep();
Matt Briggs 47:a68747642a7a 259 }
Mike Fiore 11:d2e31743433a 260
Matt Briggs 53:a1563574a980 261 if (protocol->isRx()) {
Matt Briggs 66:bcaa6dbf538a 262 ccIntFlag = false;
Matt Briggs 69:eb391644b346 263 // tamperIntFlag = false;
Matt Briggs 69:eb391644b346 264 // myLogInfo("Before listen time %d", us_ticker_read());
Matt Briggs 47:a68747642a7a 265 bool msgPending;
Matt Briggs 53:a1563574a980 266 protocol->listen(msgPending);
Matt Briggs 47:a68747642a7a 267 if (msgPending) {
Matt Briggs 65:d546060aa03d 268 std::vector<uint8_t> txEui;
Matt Briggs 65:d546060aa03d 269 txEui.reserve(8);
Matt Briggs 65:d546060aa03d 270 uint16_t data;
Matt Briggs 65:d546060aa03d 271 uint32_t msgSeqNum;
Matt Briggs 65:d546060aa03d 272 protocol->recvAlert(txEui, data, msgSeqNum);
Matt Briggs 69:eb391644b346 273 if (msgSeqNum > maxSeenMsgSeqNum)
Matt Briggs 69:eb391644b346 274 maxSeenMsgSeqNum = msgSeqNum;
Matt Briggs 69:eb391644b346 275 rxMsgCnt++; // for message
Matt Briggs 69:eb391644b346 276 myLogInfo("Got rxMsgCnt #%d, with Seqnum: %d", rxMsgCnt, msgSeqNum);
Matt Briggs 53:a1563574a980 277 bbio->relayAlert();
Matt Briggs 64:46c8819c07cc 278 ledPatterns.turnOn();
Matt Briggs 66:bcaa6dbf538a 279 myLogInfo("Holding alert for %f secs", HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1()));
Matt Briggs 58:15aa7a785b9f 280 // Hold time for alert
Matt Briggs 58:15aa7a785b9f 281 // TODO maybe use sleep instead of wait
Matt Briggs 58:15aa7a785b9f 282 wait(HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1()));
Matt Briggs 64:46c8819c07cc 283 ledPatterns.turnOff();
Matt Briggs 58:15aa7a785b9f 284 bbio->relayNormal();
Matt Briggs 47:a68747642a7a 285 }
Matt Briggs 69:eb391644b346 286 if (pairBtnIntFlag) {// An Interrupt happened during reception
Matt Briggs 69:eb391644b346 287 continue; // Go straight to pair handling
Matt Briggs 69:eb391644b346 288 }
Matt Briggs 69:eb391644b346 289 //// TEMP LOGGING
Matt Briggs 69:eb391644b346 290 #if RX_SEQ_LOG
Matt Briggs 69:eb391644b346 291 if ((loopCnt % 1000 == 0) &&
Matt Briggs 69:eb391644b346 292 rxMsgCnt > rxSeqLog.rxMsgCount()) {
Matt Briggs 69:eb391644b346 293 rxSeqLog.setLoopCount(loopCnt);
Matt Briggs 69:eb391644b346 294 rxSeqLog.setRxMsgCount(rxMsgCnt);
Matt Briggs 69:eb391644b346 295 rxSeqLog.setMaxSeenMsgSeqNum(maxSeenMsgSeqNum);
Matt Briggs 69:eb391644b346 296 rxSeqLog.save();
Matt Briggs 69:eb391644b346 297 myLogInfo("EEPROM Saved.");
Matt Briggs 69:eb391644b346 298 }
Matt Briggs 69:eb391644b346 299 myLogInfo("NVM Log: Loop Cnt: %d, RxMsgCnt %d, MaxSeenSeqNum %d",
Matt Briggs 69:eb391644b346 300 rxSeqLog.loopCount(), rxSeqLog.rxMsgCount(), rxSeqLog.maxSeenMsgSeqNum());
Matt Briggs 69:eb391644b346 301 #endif
Matt Briggs 69:eb391644b346 302
Matt Briggs 63:e1efbe3402d9 303 myLogInfo("Sleeping. Time %d", us_ticker_read());
Matt Briggs 58:15aa7a785b9f 304 bbio->prepareSleep();
Matt Briggs 47:a68747642a7a 305 dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false); // Go to sleep until wake button
Matt Briggs 58:15aa7a785b9f 306 bbio->exitSleep();
Matt Briggs 47:a68747642a7a 307 }
Matt Briggs 31:9c535a708ae9 308
Matt Briggs 64:46c8819c07cc 309 protocol->resetCounters();
Matt Briggs 63:e1efbe3402d9 310 myLogInfo("\r\n================================");
Matt Briggs 58:15aa7a785b9f 311 loopCnt++;
Mike Fiore 11:d2e31743433a 312 }
Matt Briggs 47:a68747642a7a 313
Matt Briggs 55:79ab0bbc5008 314 delete protocol;
Matt Briggs 55:79ab0bbc5008 315 delete bbio;
Mike Fiore 11:d2e31743433a 316 return 0;
Mike Fiore 11:d2e31743433a 317 }
Matt Briggs 47:a68747642a7a 318 #endif
Mike Fiore 11:d2e31743433a 319
Matt Briggs 27:6b68ff715ae1 320