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 Feb 28 09:26:27 2017 -0700
Parent:
56:40b454c952cc
Child:
58:15aa7a785b9f
Commit message:
Got static networking with static configuration working. Also added disabling test mode for DS2408.

Changed in this revision

xDotBridge/config.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/BaseboardIO.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/inc/DS2408.h Show annotated file Show diff for this revision Revisions of this file
xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/BaseboardIO.cpp Show annotated file Show diff for this revision Revisions of this file
xDotBridge/src/DS2408.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/config.h	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/config.h	Tue Feb 28 09:26:27 2017 -0700
@@ -5,12 +5,12 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 
-//#define __TEST__ 1 // Comment out for main application
+#define __TEST__ 1 // Comment out for main application
 
-// Manual test.  Comment out for main application.  Or comment for individual test.
-//#define __TEST_BBIO__
-//#define __TEST_LRR__  // Comment out for main application
-//#define __TEST_PVD__  // Comment out for main application
+// Manual test.  Comment out for main application.  Or uncomment for individual test.
+#define __TEST_BBIO__
+//#define __TEST_LRR__
+//#define __TEST_PVD__
 
 // These define which wireless bridge you are generating code for
 #define LED_FEEDBACK 1  // If 1 then LED is shown and 0 LED is not shown to conserve power
--- a/xDotBridge/inc/BaseboardIO.h	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/inc/BaseboardIO.h	Tue Feb 28 09:26:27 2017 -0700
@@ -174,6 +174,7 @@
     * @return bool
     */
     bool isPairBtn();
+    bool isCCInAlert();
 
     /**
     * @brief Returns the current state of the NO/NC switch
--- a/xDotBridge/inc/DS2408.h	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/inc/DS2408.h	Tue Feb 28 09:26:27 2017 -0700
@@ -136,7 +136,7 @@
     * @brief disableTestMode()
     *
     * @details Per datasheet if slew power on has a specific slew rate the
-    * chip may enter a test mode.
+    * chip may enter a test mode.  See page 38 of application information.
     *
     * @return CmdResult - result of operation
     */
--- a/xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp	Tue Feb 28 09:26:27 2017 -0700
@@ -9,7 +9,7 @@
 mDot* dot = NULL; // Used by dot-utils
 Serial pc(USBTX, USBRX); // Externally defined
 
-const int VERSION = 3;
+const int VERSION = 4;
 
 char* bool2Str(bool in) {
     if (in) {
--- a/xDotBridge/src/BaseboardIO.cpp	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/src/BaseboardIO.cpp	Tue Feb 28 09:26:27 2017 -0700
@@ -119,17 +119,17 @@
         logInfo("PortEx1 Control register reads %02X", val);
     }
 
+    if (sampleUserSwitches() != cmdSuccess) {
+        logError("Error sampling user switches");
+        return cmdError;
+    }
+
     // Put relay in known state
     if (relayNormal() != cmdSuccess) {
         logError("Error setting relay during init");
         return cmdError;
     }
 
-    if (sampleUserSwitches() != cmdSuccess) {
-        logError("Error sampling user switches");
-        return cmdError;
-    }
-
     logInfo("Baseboard IO initialization successful");
     return cmdSuccess;
 }
@@ -185,6 +185,15 @@
     disableSwitchedIO();
     return cmdSuccess;
 }
+bool BaseboardIO::isCCInAlert()
+{
+    if (isCCNO()) { // If NO then the CCIn should float high if not in alert state
+        return mCCIn == 0;
+    }
+    else { // If NC then the CCIN should be held low if not in alert state
+        return mCCIn == 1;
+    }
+}
 bool BaseboardIO::isPairBtn()
 {
     // Depressed button is high
--- a/xDotBridge/src/DS2408.cpp	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/src/DS2408.cpp	Tue Feb 28 09:26:27 2017 -0700
@@ -14,9 +14,7 @@
 
 CmdResult DS2408::init()
 {
-    mMaster->reset();
-    // TODO implement safety cancel test mode recommendation
-    return cmdSuccess;
+    return disableTestMode();
 }
 
 CmdResult DS2408::registerReadReliable(uint8_t addr, uint8_t &val)
@@ -81,7 +79,8 @@
     }
 }
 
-CmdResult DS2408::pioLogicReliableWrite(uint8_t val) {
+CmdResult DS2408::pioLogicReliableWrite(uint8_t val)
+{
     uint8_t result;
     for (int i=0; i < DS2408_NRETRIES; i++) {
         result = pioLogicWrite(val);
@@ -91,3 +90,15 @@
     }
     return cmdTimeout;
 }
+
+CmdResult DS2408::disableTestMode()
+{
+    mMaster->reset();
+    mMaster->write(0x96);
+
+    for (uint8_t i = 0; i < 8; i++) mMaster->write(mRomAddr[i]);
+
+    mMaster->write(0x3C);
+    mMaster->reset();
+    return cmdSuccess;
+}
--- a/xDotBridge/src/main.cpp	Mon Feb 27 14:06:54 2017 -0700
+++ b/xDotBridge/src/main.cpp	Tue Feb 28 09:26:27 2017 -0700
@@ -102,7 +102,8 @@
         pc.printf("= Baseboard Init Finished with Error      =\r\n");
     }
 
-    uint16_t seqNum=0;
+    uint16_t txSeqNum=0;
+    uint16_t rxSeqNum=0;
     Callback<void()> ccInIntObj (&ccInIntCallback);
     Callback<void()> tamperIntObj (&tamperIntCallback);
     Callback<void()> pairBtnIntObj (&pairBtnIntCallback);
@@ -136,8 +137,8 @@
         // End sample and update
 
 		if (protocol->isTx()) {
-            logInfo("Got int #%d. CCFlag %d, TamperFlag %d, PairBtnFlag %d",
-                    intCnt, ccIntFlag, tamperIntFlag, pairBtnIntFlag);
+            logInfo("Status #%d. CCFlag %d, CCAlertState %d, TamperFlag %d, PairBtnFlag %d",
+                    intCnt, ccIntFlag, bbio->isCCInAlert(), tamperIntFlag, pairBtnIntFlag);
             // TODO add tamper
             if (pairBtnIntFlag) { // Wait up to 1 second for short button hit
                 for (int i=0; i<10;i++) {
@@ -148,26 +149,34 @@
                 }
             }
 		    if (ccIntFlag || // If contact closure in
+		       bbio->isCCInAlert() || // If closure remains in effect
 		       (pairBtnIntFlag && (bbio->isPairBtn() == false))) { // If short pair btn hit
 
                 ccIntFlag = false;
+                pairBtnIntFlag = false;
                 tamperIntFlag = false;
-                pairBtnIntFlag = false;
                 #if LED_FEEDBACK
                 bbio->ledOn();
                 #endif
 
-                data.push_back((seqNum >> 8) & 0xFF);
-                data.push_back(seqNum & 0xFF);
+                data.push_back((txSeqNum >> 8) & 0xFF);
+                data.push_back(txSeqNum & 0xFF);
+                std::string dataStr(data.begin(), data.end());
+                logInfo("Sent msg num: %d, payload: %s", txSeqNum, dataStr.c_str());
                 protocol->send(data);
-                seqNum++;
+                txSeqNum++;
                 wait(0.5); // Leave the LED on so a person can see it.
 		    }
 
             bbio->ledOff();
 //            sleep_save_io();
 //            sleep_configure_io();
-            dot->sleep(0, mDot::INTERRUPT, false);  // Go to sleep until wake button
+		    if (bbio->isCCInAlert()) { // Still in alert mode
+                dot->sleep(10, mDot::RTC_ALARM_OR_INTERRUPT, false);  // Go to sleep and check in 2 secs if CCInAlert is asserted
+		    }
+		    else {
+                dot->sleep(0, mDot::INTERRUPT, false);  // Go to sleep until wake button
+		    }
 //            sleep_restore_io();
 		}
 
@@ -178,9 +187,9 @@
 		    if (msgPending) {
 		        protocol->recv(data);
                 std::string dataStr(data.begin(), data.end());
-                logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str());
+                logInfo("Got msg num: %d, payload: %s", rxSeqNum, dataStr.c_str());
                 bbio->relayAlert();
-                seqNum++;
+                rxSeqNum++;
                 #if LED_FEEDBACK
                 bbio->ledOn();
                 #endif
@@ -200,7 +209,7 @@
 		// TODO maybe a good place to put pairing logic
 
         logInfo("================================");
-        wait(1.0);
+        wait(1.0); // May want to remove
         // Need to re-implement some of these sleep functions
 //		sleep_save_io();
 //		sleep_configure_io();