Fork to see if I can get working

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

Fork of xDotBridge_update_test20180823 by Matt Briggs

Files at this revision

API Documentation at this revision

Comitter:
Matt Briggs
Date:
Tue Mar 14 11:53:53 2017 -0600
Parent:
63:e1efbe3402d9
Child:
65:d546060aa03d
Commit message:
Continuted debug of pairing code. Qcuik hack to disable counters.

Changed in this revision

xDotBridge/inc/CommProtocolPeerBrute.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/UserInterface.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/CommProtocolPeerBrute.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/UserInterface.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/xDotBridge/inc/CommProtocolPeerBrute.h	Tue Mar 14 09:54:04 2017 -0600
+++ b/xDotBridge/inc/CommProtocolPeerBrute.h	Tue Mar 14 11:53:53 2017 -0600
@@ -205,6 +205,12 @@
      */
     uint32_t getULC();
 
+    /**
+     * Resets both uplink and downlink counters (1 and 0 respectively).
+     * @return
+     */
+    CmdResult resetCounters();
+
     // TODO maybe this should be private
     CmdResult configForPairingNetwork();
     void printDotConfig();
@@ -247,12 +253,6 @@
     CmdResult writeInfoToNVM();
 
     /**
-     * Resets both uplink and downlink counters to zero.  Useful for when pairing.
-     * @return
-     */
-    CmdResult resetCounters();
-
-    /**
      * Generates new encryption keys for radio
      * @return
      */
--- a/xDotBridge/inc/UserInterface.h	Tue Mar 14 09:54:04 2017 -0600
+++ b/xDotBridge/inc/UserInterface.h	Tue Mar 14 11:53:53 2017 -0600
@@ -38,4 +38,15 @@
     static float rotVal2Sec(uint8_t in) {return rotVal2Msec(in)/1000.0;}
 };
 
+class LedPatterns {
+public:
+    LedPatterns(BaseboardIO *bbio);
+    void turnOn();
+    void turnOff();
+    void singleBlink();
+    void tripleBlink();
+    void tenBlinks();
+private:
+    BaseboardIO *mBbio;
+};
 #endif /* XDOTBRIDGE_INC_USERINTERFACE_H_ */
--- a/xDotBridge/src/CommProtocolPeerBrute.cpp	Tue Mar 14 09:54:04 2017 -0600
+++ b/xDotBridge/src/CommProtocolPeerBrute.cpp	Tue Mar 14 11:53:53 2017 -0600
@@ -33,10 +33,11 @@
     if (result != cmdSuccess) {
         myLogWarning("Reverting to protocol defaults NVM Read failed");
         mMemObj.setDefaults();
+        writeInfoToNVM();
     }
     configForSavedNetwork();
 
-    writeInfoToNVM();
+    resetCounters();
 
     mPrevDownLinkCnt = dot->getDownLinkCounter();
     return cmdSuccess;
@@ -122,6 +123,8 @@
     dot->setClass("C"); // Set class C
     dot->setTxPower(TX_PWR);
     dot->setPreserveSession(false);
+//    dot->setDownLinkCounter(0);
+//    dot->setUpLinkCounter(1);
     // TODO break out in a utility function
     // update configuration if necessary
     myLogDebug("Setting up peer to peer configuration");
@@ -183,27 +186,12 @@
     std::vector<uint8_t> key;
     key.reserve(16);
 
-    // REPLACE WITH NETWORK ADDRESS
-//    result = genEncypKey(key, 8);
-//    if (result != cmdSuccess) {
-//        myLogError("Error generating network ID.");
-//        return cmdError;
-//    }
-//    if (dot->setNetworkId(key) != mDot::MDOT_OK) {
-//        myLogError("Error setting network ID.");
-//        return cmdError;
-//    }
-
     result = genEncypKey(key, 4, false);
     if (result != cmdSuccess) {
         myLogError("Error generating network address.");
         return cmdError;
     }
     mMemObj.setNetworkAddr(key);
-//    if (dot->setNetworkAddress(key) != mDot::MDOT_OK) {
-//        myLogError("Error setting network address.");
-//        return cmdError;
-//    }
 
     result = genEncypKey(key, 16);
     if (result != cmdSuccess) {
@@ -211,10 +199,6 @@
         return cmdError;
     }
     mMemObj.setNetworkSessionKey(key);
-//    if (dot->setNetworkSessionKey(key) != mDot::MDOT_OK) {
-//        myLogError("Error setting network session key.");
-//        return cmdError;
-//    }
 
     result = genEncypKey(key, 16);
     if (result != cmdSuccess) {
@@ -222,14 +206,9 @@
         return cmdError;
     }
     mMemObj.setDataSessionKey(key);
-//    if (dot->setDataSessionKey(key) != mDot::MDOT_OK) {
-//        myLogError("Error setting data session key.");
-//        return cmdError;
-//    }
 
     configForSavedNetwork();
     writeInfoToNVM();
-    display_config();
 
     return cmdSuccess;
 }
@@ -281,6 +260,7 @@
 
     wait(TX_TIME/1000.0); // Wait TX_TIME
 
+    mPrevDownLinkCnt = 0;  // FIXME just test code
     if (mPrevDownLinkCnt < dot->getDownLinkCounter()) {
         msgPending = true;
     }
@@ -462,7 +442,7 @@
 CmdResult CommProtocolPeerBrute::resetCounters()
 {
     dot->setDownLinkCounter(0);
-    dot->setUpLinkCounter(0);
+    dot->setUpLinkCounter(1);
     return cmdSuccess;
 }
 
--- a/xDotBridge/src/UserInterface.cpp	Tue Mar 14 09:54:04 2017 -0600
+++ b/xDotBridge/src/UserInterface.cpp	Tue Mar 14 11:53:53 2017 -0600
@@ -65,3 +65,42 @@
         return pairBtnLongPress;
     }
 }
+
+LedPatterns::LedPatterns(BaseboardIO *bbio)
+{
+    mBbio = bbio;
+}
+
+void LedPatterns::turnOn()
+{
+    mBbio->ledOn();
+}
+
+void LedPatterns::turnOff()
+{
+    mBbio->ledOff();
+}
+
+void LedPatterns::singleBlink()
+{
+    mBbio->ledOn();
+    wait(0.5);
+    mBbio->ledOff();
+}
+
+void LedPatterns::tripleBlink()
+{
+    singleBlink();
+    wait(0.5);
+    singleBlink();
+    wait(0.5);
+    singleBlink();
+}
+
+void LedPatterns::tenBlinks()
+{
+    for (uint8_t i=0; i<10; i++) {
+        singleBlink();
+        wait(0.5);
+    }
+}
--- a/xDotBridge/src/main.cpp	Tue Mar 14 09:54:04 2017 -0600
+++ b/xDotBridge/src/main.cpp	Tue Mar 14 11:53:53 2017 -0600
@@ -49,6 +49,7 @@
     dot = mDot::getInstance();
 
     // make sure library logging is turned on
+//    dot->setLogLevel(mts::MTSLog::WARNING_LEVEL);
     dot->setLogLevel(mts::MTSLog::WARNING_LEVEL);
 
     myLogInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
@@ -110,6 +111,7 @@
     else {
         myLogInfo("= Baseboard Init Finished with Error      =\r\n");
     }
+    LedPatterns ledPatterns(bbio);
 
     uint16_t txSeqNum=0;
     uint16_t rxSeqNum=0;
@@ -134,7 +136,7 @@
      */
     while (true) {
         std::vector<uint8_t> data;
-        bbio->ledOff();
+        ledPatterns.turnOff();
 
         // Sample IO and update any configuration
         prevCCNormallyOpen = bbio->isCCNO();
@@ -155,31 +157,36 @@
             pairBtnState = PairBtnInterp::read(bbio);
             if (protocol->isTx()) {
                 if (pairBtnState == pairBtnMediumPress) {
-                    protocol->sampleDLC();
+//                    protocol->sampleDLC();
                     protocol->configForPairingNetwork();
                     protocol->sendPairReq();
                     myLogInfo("Sent pair request.  Waiting %f secs for accept.", TX_ACCEPT_WAIT_TIME);
                     result = protocol->waitForAccept(TX_ACCEPT_WAIT_TIME);
                     if (result == cmdSuccess) {
                         myLogInfo("Got accept");
+                        ledPatterns.turnOff();
+                        wait(0.5);
+                        ledPatterns.tripleBlink();
                     }
                     else {
                         myLogInfo("Did not receive accept");
                     }
                     protocol->configForSavedNetwork();
                     protocol->printDotConfig();
+                    protocol->resetCounters();
                 }
             }
             if (protocol->isRx()) {
                 if (pairBtnState == pairBtnMediumPress) {
-                    protocol->sampleDLC();
+//                    protocol->sampleDLC();
                     protocol->configForPairingNetwork();
-                    bbio->ledOn();
+                    ledPatterns.turnOn();
                     myLogInfo("Waiting for pair request for %f seconds", RX_PAIR_WAIT_TIME);
                     result = protocol->waitForPairing(RX_PAIR_WAIT_TIME);
-                    bbio->ledOff();
+                    ledPatterns.turnOff();
                     if (result == cmdSuccess) {
                         myLogInfo("Got pair request and responded");
+                        ledPatterns.tripleBlink();
                     }
                     else if (result == cmdTimeout) {
                         myLogInfo("Did not receive request");
@@ -189,11 +196,14 @@
                     }
                     protocol->configForSavedNetwork();
                     protocol->printDotConfig();
+                    protocol->resetCounters();
                 }
                 else if (pairBtnState == pairBtnLongPress) {
                     myLogInfo("Clearing pair values and generating new ones.");
                     protocol->clearPair();
                     protocol->printDotConfig();
+                    ledPatterns.tenBlinks();
+                    protocol->resetCounters();
                 }
             }
         }
@@ -207,9 +217,7 @@
 		       bbio->isCCInAlert() || // If closure remains in effect
 		       (pairBtnIntFlag && (pairBtnState == pairBtnShortPress))) {
                 ccIntFlag = false;
-                #if LED_FEEDBACK
-                bbio->ledOn();
-                #endif
+                ledPatterns.turnOn();
 
                 data.clear();
                 data.push_back((txSeqNum >> 8) & 0xFF);
@@ -218,10 +226,10 @@
                 myLogInfo("Sent msg num: %d, payload: %s", txSeqNum, dataStr.c_str());
                 protocol->send(data);
                 txSeqNum++;
-                wait(0.5); // Leave the LED on so a person can see it.
+                ledPatterns.turnOff();
 		    }
 
-            bbio->ledOff();
+            ledPatterns.turnOff();
             pairBtnIntFlag = false;
             tamperIntFlag = false;
             bbio->prepareSleep();
@@ -245,23 +253,22 @@
                 myLogInfo("Got msg num: %d, payload: %s", rxSeqNum, dataStr.c_str());
                 bbio->relayAlert();
                 rxSeqNum++;
-                #if LED_FEEDBACK
-                bbio->ledOn();
-                #endif
+                ledPatterns.turnOn();
                 // 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()));
-                bbio->ledOff();
+                ledPatterns.turnOff();
                 bbio->relayNormal();
 		    }
             myLogInfo("Sleeping.  Time %d", us_ticker_read());
-            protocol->sampleDLC();
+//            protocol->sampleDLC();
             bbio->prepareSleep();
             dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false);  // Go to sleep until wake button
             bbio->exitSleep();
 		}
 
+		protocol->resetCounters();
         myLogInfo("\r\n================================");
         loopCnt++;
     }