![](/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/main.cpp
- Revision:
- 66:bcaa6dbf538a
- Parent:
- 65:d546060aa03d
- Child:
- 67:2115a2f1b945
--- a/xDotBridge/src/main.cpp Wed Mar 15 09:49:58 2017 -0600 +++ b/xDotBridge/src/main.cpp Wed Mar 15 11:46:40 2017 -0600 @@ -44,12 +44,12 @@ RadioEvent events; // Custom event handler for automatically displaying RX data mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - MyLog::setLogLevel(MyLog::INFO_LEVEL); + MyLog::setLogLevel(MyLog::DEBUG_LEVEL); dot = mDot::getInstance(); // make sure library logging is turned on - dot->setLogLevel(mts::MTSLog::INFO_LEVEL); + dot->setLogLevel(mts::MTSLog::WARNING_LEVEL); myLogInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); myLogInfo("libxDot-mbed5 library ID: %s", dot->getId().c_str()); @@ -122,6 +122,13 @@ bbio->regTamperInt(tamperIntObj); bbio->regPairBtnInt(pairBtnIntObj); + if (bbio->isTx()) { + protocol->setTx(true); + } + else { // RX + protocol->setTx(false); + } + // Start flash powered down flash->powerDown(); @@ -132,29 +139,28 @@ * Main Loop */ while (true) { -// std::vector<uint8_t> data; + myLogInfo("Start of loop time %d", us_ticker_read()); ledPatterns.turnOff(); - // Sample IO and update any configuration - prevCCNormallyOpen = bbio->isCCNO(); - bbio->sampleUserSwitches(); - if (prevCCNormallyOpen == bbio->isCCNO()) { // Only activate the coil if the DIP SW has changed - bbio->regCCInInt(ccInIntObj); - bbio->relayNormal(); - } - if (bbio->isTx()) { - protocol->setTx(true); - } - else { // RX - protocol->setTx(false); - } - // End sample and update - // Pair logic + // Pair logic and switch sampling if (pairBtnIntFlag) { pairBtnState = PairBtnInterp::read(bbio); + + // Sample IO and update any configuration + prevCCNormallyOpen = bbio->isCCNO(); + bbio->sampleUserSwitches(); + if (prevCCNormallyOpen != bbio->isCCNO()) { // Only activate the coil if the DIP SW has changed + bbio->regCCInInt(ccInIntObj); + bbio->relayNormal(); + } + if (bbio->isTx()) { + protocol->setTx(true); + } + else { // RX + protocol->setTx(false); + } if (protocol->isTx()) { if (pairBtnState == pairBtnMediumPress) { -// protocol->sampleDLC(); protocol->configForPairingNetwork(); protocol->sendPairReq(); myLogInfo("Sent pair request. Waiting %f secs for accept.", TX_ACCEPT_WAIT_TIME); @@ -175,7 +181,6 @@ } if (protocol->isRx()) { if (pairBtnState == pairBtnMediumPress) { -// protocol->sampleDLC(); protocol->configForPairingNetwork(); ledPatterns.turnOn(); myLogInfo("Waiting for pair request for %f seconds", RX_PAIR_WAIT_TIME); @@ -216,8 +221,8 @@ ccIntFlag = false; ledPatterns.turnOn(); + myLogInfo("Sending msg num: %d.", protocol->getSeqNum()); protocol->sendAlert(0xBEEF); // TODO use this field to encode the alert type e.g. CCIN vs tamper - myLogInfo("Sent msg num: %d.", protocol->getSeqNum()); ledPatterns.turnOff(); } @@ -235,6 +240,10 @@ } if (protocol->isRx()) { + ccIntFlag = false; + pairBtnIntFlag = false; + tamperIntFlag = false; + myLogInfo("Before listen time %d", us_ticker_read()); bool msgPending; protocol->listen(msgPending); myLogInfo("Loop Cnt %d. Listening.", loopCnt); @@ -244,18 +253,17 @@ uint16_t data; uint32_t msgSeqNum; protocol->recvAlert(txEui, data, msgSeqNum); - myLogInfo("Got msg num: TODO"); + myLogInfo("Got msg num: %d", msgSeqNum); bbio->relayAlert(); ledPatterns.turnOn(); + myLogInfo("Holding alert for %f secs", HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1())); // Hold time for alert // TODO maybe use sleep instead of wait - myLogInfo("Holding alert for %f secs", HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1())); wait(HoldTimeSetting::rotVal2Sec(bbio->rotarySwitch1())); ledPatterns.turnOff(); bbio->relayNormal(); } myLogInfo("Sleeping. Time %d", us_ticker_read()); -// protocol->sampleDLC(); bbio->prepareSleep(); dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false); // Go to sleep until wake button bbio->exitSleep();