Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
Revision 66:bcaa6dbf538a, committed 2017-03-15
- Comitter:
- Matt Briggs
- Date:
- Wed Mar 15 11:46:40 2017 -0600
- Parent:
- 65:d546060aa03d
- Child:
- 67:2115a2f1b945
- Commit message:
- Changed to only sample switches with user btn press. Also hand tuned times based off measurement.
Changed in this revision
--- a/xDotBridge/src/CommProtocolPeerBrute.cpp Wed Mar 15 09:49:58 2017 -0600
+++ b/xDotBridge/src/CommProtocolPeerBrute.cpp Wed Mar 15 11:46:40 2017 -0600
@@ -13,8 +13,9 @@
// wireless bridge protocol
const uint8_t TX_PWR = 20; // 20 dBm
const float RX_SLEEP_TIME = 2000; // ms (one second resolution, min 2 seconds)
-const uint8_t TX_TIME = 30; // in ms
-const unsigned int nTimesToTx = ceil(RX_SLEEP_TIME / ((float)TX_TIME));
+const uint8_t TX_TIME = 30*2; // in ms
+//const unsigned int nTimesToTx = ceil(RX_SLEEP_TIME / ((float)TX_TIME));
+const unsigned int nTimesToTx = 75; // Hand tuned to be over 2.03 seconds of transmitting
//const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion)
CommProtocolPeerBrute::CommProtocolPeerBrute()
@@ -224,11 +225,11 @@
if (!dot->getNetworkJoinStatus()) {
join_network();
}
- myLogDebug("Starting TX. Time: %lu", us_ticker_read());
+ myLogDebug("Starting TX. Time: %07lu", us_ticker_read());
for(uint8_t i=0;i<nTimesToTx;++i) {
dot->send(msg);
}
- myLogDebug("Finished TX. Time: %lu", us_ticker_read());
+ myLogDebug("Finished TX. Time: %07lu", us_ticker_read());
return cmdError;
}
@@ -251,12 +252,7 @@
// 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;
- }
+ return send(msg);
}
CmdResult CommProtocolPeerBrute::sendPairReq()
--- 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();
