Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
Revision 48:bab9f747d9ed, committed 2017-02-13
- Comitter:
- Matt Briggs
- Date:
- Mon Feb 13 17:10:59 2017 -0700
- Parent:
- 47:a68747642a7a
- Child:
- 49:18f1354f9e51
- Commit message:
- First cut at manual testing for baseboard IO. Still needs to be debugged and used.
Changed in this revision
--- a/xDotBridge/config.h Fri Feb 10 07:41:16 2017 -0700 +++ b/xDotBridge/config.h Mon Feb 13 17:10:59 2017 -0700 @@ -5,7 +5,11 @@ #ifndef CONFIG_H_ #define CONFIG_H_ -#define __TEST__ 1 +#define __TEST__ 1 // Comment out for main application + +// Manual test +#define __TEST_BBIO__ // Comment out for main application +//#define __TEST_LRR__ // Comment out for main application // These define which wireless bridge you are generating code for #define BRIDGE_TX_BRUTE 0
--- a/xDotBridge/inc/BaseboardIO.h Fri Feb 10 07:41:16 2017 -0700
+++ b/xDotBridge/inc/BaseboardIO.h Mon Feb 13 17:10:59 2017 -0700
@@ -150,7 +150,7 @@
*
* @return bool
*/
- bool isCCOutNO();
+ bool isCCNO();
/**
* @brief Returns the current state of the NO/NC switch
@@ -167,7 +167,7 @@
*
* @return bool
*/
- bool isCCOutNC() {return isCCOutNO();}
+ bool isCCNC() {return isCCNO();}
/**
* @brief Returns the current state of the Rx/Tx switch
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp Mon Feb 13 17:10:59 2017 -0700
@@ -0,0 +1,171 @@
+#include "mbed.h"
+#include <string>
+#include "..\..\config.h"
+#include "BaseboardIO.h"
+
+#ifdef __TEST_BBIO__
+Serial pc(USBTX, USBRX); // Externally defined
+
+char* bool2Str(bool in) {
+ if (in) {
+ return "Asserted\ "; // Extra space for alignment
+ }
+ else {
+ return "Not Asserted";
+ }
+}
+
+uint8_t ccInIntCnt;
+uint8_t tamperIntCnt;
+uint8_t pairBtnIntCnt;
+
+void ccInIntCallback () {
+ ccInIntCnt++;
+}
+void tamperIntCallback () {
+ tamperIntCnt++;
+}
+void pairBtnIntCallback () {
+ pairBtnIntCnt++;
+}
+
+class MenuManager
+{
+private:
+ uint8_t mCurrSel; // Current selection
+ BaseboardIO *mBbio;
+ bool validInput(uint8_t in) {
+ if (in > 0 && in <= 8)
+ return true;
+ else {
+ return false;
+ }
+ }
+public:
+ MenuManager() {
+ mCurrSel = 0;
+ mBbio = NULL;
+ }
+ void regBBIO (BaseboardIO *bbio) {
+ mBbio = bbio;
+ }
+ uint8_t getCurrentSel() {
+ return mCurrSel;
+ }
+ void applyInput(uint8_t in) {
+ if (validInput(in)) {
+// mCurrSel = in;
+ if (in == 1) {
+ mBbio->ledOn();
+ }
+ else if (in == 2) {
+ mBbio->ledOff();
+ }
+ else if (in == 3) {
+ mBbio->relayNormal();
+ }
+ else if (in == 4) {
+ mBbio->relayAlert();
+ }
+ else if (in == 5) {
+ mBbio->serialRx(true);
+ }
+ else if (in == 6) {
+ mBbio->serialRx(false);
+ }
+ else if (in == 7) {
+ mBbio->serialTx(true);
+ }
+ else if (in == 8) {
+ mBbio->serialTx(false);
+ }
+ }
+ }
+ void printMenu() {
+ mBbio->sampleUserSwitches();
+ pc.printf("\r\n\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("= Baseboard I/O Tester =\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("= Selection Options =\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("= 0: Just refresh =\r\n");
+ pc.printf("= 1: Turn on LED =\r\n");
+ pc.printf("= 2: Turn off LED =\r\n");
+ pc.printf("= 3: Toggle Relay Normal =\r\n");
+ pc.printf("= 4: Toggle Relay Alert =\r\n");
+ pc.printf("= 5: Turn on 232 RX =\r\n");
+ pc.printf("= 6: Turn off 232 RX =\r\n");
+ pc.printf("= 7: Turn on 232 TX (Note RX on as well) =\r\n");
+ pc.printf("= 8: Turn off 232 TX =\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("= Status and Counters =\r\n");
+ pc.printf("===============================================\r\n");
+ pc.printf("= Pair btn. State: %s IntCnt: %02d =\r\n",
+ bool2Str(mBbio->isPairBtn()), 0);
+ pc.printf("= Tamper. State: N/A IntCnt: %02d =\r\n",
+ 0);
+ pc.printf("= CCIN. State: %s IntCnt: %02d =\r\n",
+ bool2Str(0), 0);
+ pc.printf("= Is TX. State: %s =\r\n", bool2Str(mBbio->isTx()));
+ pc.printf("= CC Normally Open. State: %s =\r\n", bool2Str(mBbio->isCCNO()));
+ pc.printf("= Is LoraWAN. State: %s =\r\n", bool2Str(mBbio->isLoRaWANMode()));
+ pc.printf("= Rotary Switch 1. Value: %02d =\r\n", mBbio->rotarySwitch1());
+ pc.printf("= Rotary Switch 2. Value: %02d =\r\n", mBbio->rotarySwitch2());
+ pc.printf("===============================================\r\n");
+ }
+};
+
+/**
+ * Checks that in idle state all the IOs are pulled up.
+ */
+int main ()
+{
+ MenuManager menuMgr;
+ CmdResult result;
+ ccInIntCnt = 0;
+ tamperIntCnt = 0;
+ pairBtnIntCnt = 0;
+
+ pc.baud(115200);
+
+ wait(1.0);
+
+ pc.printf("===============================================\r\n");
+ pc.printf("= Baseboard Constructor Starting =\r\n");
+ BaseboardIO bbio;
+ pc.printf("= Baseboard Constructor Finished =\r\n");
+
+ pc.printf("= Baseboard Init Starting =\r\n");
+ result = bbio.init();
+ if (result == cmdSuccess) {
+ pc.printf("= Baseboard Init Finished Successfully =\r\n");
+ }
+ else {
+ pc.printf("= Baseboard Init Finished with Error =\r\n");
+ }
+
+ bbio.regCCInInt(&ccInIntCallback);
+ bbio.regTamperInt(&tamperIntCallback);
+ bbio.regPairBtnInt(&pairBtnIntCallback);
+
+ menuMgr.regBBIO(&bbio);
+ menuMgr.printMenu();
+
+ while (true) {
+
+ if (pc.readable()) {
+ char menuInput = pc.getc();
+ menuInput -= '0'; // Convert to raw interger value
+ menuMgr.applyInput(menuInput);
+ menuMgr.printMenu();
+ }
+ else {
+ pc.printf("*");
+ }
+ wait(1.0);
+ }
+ return 0;
+}
+#endif
--- a/xDotBridge/manualTest/testLRRPins/testLRRPins.cpp Fri Feb 10 07:41:16 2017 -0700
+++ b/xDotBridge/manualTest/testLRRPins/testLRRPins.cpp Mon Feb 13 17:10:59 2017 -0700
@@ -1,12 +1,8 @@
#include "mbed.h"
#include <string>
-
-const uint8_t TIMEOUT = 120; // In seconds
+#include "..\..\config.h"
-/**
- * FIXME - This needs a lot of help
- */
-
+#ifdef __TEST_LRR__
DigitalOut gpio0(GPIO0);
DigitalOut gpio1(GPIO1);
DigitalOut gpio2(GPIO2);
@@ -97,7 +93,6 @@
/**
* Checks that in idle state all the IOs are pulled up.
*/
-//void menu_loop () {
int main ()
{
pc.baud(115200);
@@ -145,3 +140,4 @@
}
return 0;
}
+#endif
--- a/xDotBridge/src/BaseboardIO.cpp Fri Feb 10 07:41:16 2017 -0700
+++ b/xDotBridge/src/BaseboardIO.cpp Mon Feb 13 17:10:59 2017 -0700
@@ -40,7 +40,8 @@
mCCIn(WAKE), // Interrupt pin PA_0
mTamper(GPIO1), // Interrupt pin PA_5
mPairBtn(UART_CTS), // Interrupt pin PA_11
- mLed(SWDIO),
+// mLed(SWDIO),
+ mLed(GPIO0),
mSwitchedIOCtrl(I2C_SCL)
{
// mCCInIntCallback = NULL;
@@ -91,8 +92,14 @@
// Registering for interrupts
void BaseboardIO::regCCInInt(Callback<void()> func)
{
- // Pulled high, switched low
- mCCIn.fall(func);
+ sampleUserSwitches();
+ if (isCCNO()) {
+ // Pulled high, switched low
+ mCCIn.fall(func);
+ }
+ else {
+ mCCIn.rise(func);
+ }
}
void BaseboardIO::regTamperInt(Callback<void()> func)
{
@@ -108,6 +115,8 @@
// Input
CmdResult BaseboardIO::sampleUserSwitches()
{
+ if ((mPortEx0 == NULL) || (mPortEx1 == NULL))
+ return cmdError;
// Sample port expanders
if (mPortEx0->pioLogicRead(mPortExpanderVal0) != cmdSuccess) {
logError("Error reading port expander 0.");
@@ -124,7 +133,7 @@
// Depressed button is high
return mPairBtn.read() == 1;
}
-bool BaseboardIO::isCCOutNO()
+bool BaseboardIO::isCCNO()
{
// When DIP switch is not closed (i.e. value reads high) assume NO
return (mPortExpanderVal1 & pEx1NoNcSel) != 0;
@@ -181,7 +190,7 @@
}
CmdResult BaseboardIO::relayAlert()
{
- if (isCCOutNO()) { // Normally Open
+ if (isCCNO()) { // Normally Open
return closeRelay();
}
else { // Normally Close
@@ -190,7 +199,7 @@
}
CmdResult BaseboardIO::relayNormal()
{
- if (isCCOutNO()) { // Normally Open
+ if (isCCNO()) { // Normally Open
return openRelay();
}
else { // Normally Close
@@ -277,7 +286,7 @@
logInfo("Finished OneWire Search");
if (i != 2) {
- logError("Incorrect Number (Got %d. Expected 2) OneWire port expanders found.", i);
+ logError("Incorrect Number of OneWire devices (Got %d. Expected 2) OneWire port expanders found.", i);
return cmdError;
}
--- a/xDotBridge/src/main.cpp Fri Feb 10 07:41:16 2017 -0700
+++ b/xDotBridge/src/main.cpp Mon Feb 13 17:10:59 2017 -0700
@@ -14,15 +14,17 @@
mDot* dot = NULL; // Used by dot-utils
+DigitalOut gpio3(GPIO3, 1); // Flash ~hold signal
+
int main() {
+ pc.baud(115200);
+
CommProtocolPeerBrute protocol;
BaseboardIO bbio;
RadioEvent events; // Custom event handler for automatically displaying RX data
WinbondSPIFlash flash(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_NSS);
// flash.frequency(48e6); // TODO try overridding for faster freq (Default 1MHz)
- pc.baud(115200);
-
mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
dot = mDot::getInstance();
@@ -56,7 +58,26 @@
logInfo("Programmable Voltage Detector set for level: %d", pvdConfig.PVDLevel);
// HAL_PWR_PVDCallback need to define this I think this will override the current implementation
- // TODO setup IO here
+ // Appears to work but do not have a good way to measure power
+ for (int i=0; i<8; i++) {
+ int data = flash.readByte(0x000000+i);
+ logInfo("Idx: %d: %02X", i, data);
+ }
+ logInfo("Powering Down");
+ flash.powerDown();
+ wait(1.0);
+ for (int i=0; i<8; i++) {
+ int data = flash.readByte(0x000000+i);
+ logInfo("Idx: %d: %02X", i, data);
+ }
+ flash.releaseFromPowerDown();
+ logInfo("Waking up");
+ wait(1.0);
+ for (int i=0; i<8; i++) {
+ int data = flash.readByte(0x000000+i);
+ logInfo("Idx: %d: %02X", i, data);
+ }
+ return 0;
#if BRIDGE_TX_BRUTE
protocol.setTx(true);
