![](/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
xDotBridge/manualTest/testBaseboardIO/testBaseboardIO.cpp@100:0882cf295f8e, 2017-11-29 (annotated)
- Committer:
- mbriggs_vortex
- Date:
- Wed Nov 29 13:54:36 2017 -0700
- Revision:
- 100:0882cf295f8e
- Parent:
- 67:2115a2f1b945
Adding relaese bin to repo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 48:bab9f747d9ed | 1 | #include "mbed.h" |
Matt Briggs | 48:bab9f747d9ed | 2 | #include <string> |
Matt Briggs | 55:79ab0bbc5008 | 3 | #include "../../config.h" |
Matt Briggs | 48:bab9f747d9ed | 4 | #include "BaseboardIO.h" |
Matt Briggs | 56:40b454c952cc | 5 | //#include "MTSLog.h" |
Matt Briggs | 56:40b454c952cc | 6 | #include "dot_util.h" |
Matt Briggs | 67:2115a2f1b945 | 7 | #include "MyLog.h" |
Matt Briggs | 48:bab9f747d9ed | 8 | |
Matt Briggs | 48:bab9f747d9ed | 9 | #ifdef __TEST_BBIO__ |
Matt Briggs | 56:40b454c952cc | 10 | mDot* dot = NULL; // Used by dot-utils |
Matt Briggs | 48:bab9f747d9ed | 11 | Serial pc(USBTX, USBRX); // Externally defined |
Matt Briggs | 48:bab9f747d9ed | 12 | |
Matt Briggs | 67:2115a2f1b945 | 13 | const int VERSION = 7; |
Matt Briggs | 49:18f1354f9e51 | 14 | |
Matt Briggs | 48:bab9f747d9ed | 15 | char* bool2Str(bool in) { |
Matt Briggs | 48:bab9f747d9ed | 16 | if (in) { |
Matt Briggs | 48:bab9f747d9ed | 17 | return "Asserted\ "; // Extra space for alignment |
Matt Briggs | 48:bab9f747d9ed | 18 | } |
Matt Briggs | 48:bab9f747d9ed | 19 | else { |
Matt Briggs | 48:bab9f747d9ed | 20 | return "Not Asserted"; |
Matt Briggs | 48:bab9f747d9ed | 21 | } |
Matt Briggs | 48:bab9f747d9ed | 22 | } |
Matt Briggs | 48:bab9f747d9ed | 23 | |
Matt Briggs | 49:18f1354f9e51 | 24 | volatile uint8_t ccInIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 25 | volatile uint8_t tamperIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 26 | volatile uint8_t pairBtnIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 27 | volatile uint8_t pvdIntCnt; |
Matt Briggs | 48:bab9f747d9ed | 28 | |
Matt Briggs | 48:bab9f747d9ed | 29 | void ccInIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 30 | ccInIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 31 | } |
Matt Briggs | 48:bab9f747d9ed | 32 | void tamperIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 33 | tamperIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 34 | } |
Matt Briggs | 48:bab9f747d9ed | 35 | void pairBtnIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 36 | pairBtnIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 37 | } |
Matt Briggs | 51:58d2a1b8f9d2 | 38 | |
Matt Briggs | 48:bab9f747d9ed | 39 | class MenuManager |
Matt Briggs | 48:bab9f747d9ed | 40 | { |
Matt Briggs | 48:bab9f747d9ed | 41 | private: |
Matt Briggs | 48:bab9f747d9ed | 42 | uint8_t mCurrSel; // Current selection |
Matt Briggs | 48:bab9f747d9ed | 43 | BaseboardIO *mBbio; |
Matt Briggs | 48:bab9f747d9ed | 44 | bool validInput(uint8_t in) { |
Matt Briggs | 48:bab9f747d9ed | 45 | if (in > 0 && in <= 8) |
Matt Briggs | 48:bab9f747d9ed | 46 | return true; |
Matt Briggs | 48:bab9f747d9ed | 47 | else { |
Matt Briggs | 48:bab9f747d9ed | 48 | return false; |
Matt Briggs | 48:bab9f747d9ed | 49 | } |
Matt Briggs | 48:bab9f747d9ed | 50 | } |
Matt Briggs | 48:bab9f747d9ed | 51 | public: |
Matt Briggs | 48:bab9f747d9ed | 52 | MenuManager() { |
Matt Briggs | 48:bab9f747d9ed | 53 | mCurrSel = 0; |
Matt Briggs | 48:bab9f747d9ed | 54 | mBbio = NULL; |
Matt Briggs | 48:bab9f747d9ed | 55 | } |
Matt Briggs | 48:bab9f747d9ed | 56 | void regBBIO (BaseboardIO *bbio) { |
Matt Briggs | 48:bab9f747d9ed | 57 | mBbio = bbio; |
Matt Briggs | 48:bab9f747d9ed | 58 | } |
Matt Briggs | 48:bab9f747d9ed | 59 | uint8_t getCurrentSel() { |
Matt Briggs | 48:bab9f747d9ed | 60 | return mCurrSel; |
Matt Briggs | 48:bab9f747d9ed | 61 | } |
Matt Briggs | 48:bab9f747d9ed | 62 | void applyInput(uint8_t in) { |
Matt Briggs | 48:bab9f747d9ed | 63 | if (validInput(in)) { |
Matt Briggs | 48:bab9f747d9ed | 64 | // mCurrSel = in; |
Matt Briggs | 48:bab9f747d9ed | 65 | if (in == 1) { |
Matt Briggs | 48:bab9f747d9ed | 66 | mBbio->ledOn(); |
Matt Briggs | 48:bab9f747d9ed | 67 | } |
Matt Briggs | 48:bab9f747d9ed | 68 | else if (in == 2) { |
Matt Briggs | 48:bab9f747d9ed | 69 | mBbio->ledOff(); |
Matt Briggs | 48:bab9f747d9ed | 70 | } |
Matt Briggs | 48:bab9f747d9ed | 71 | else if (in == 3) { |
Matt Briggs | 48:bab9f747d9ed | 72 | mBbio->relayNormal(); |
Matt Briggs | 48:bab9f747d9ed | 73 | } |
Matt Briggs | 48:bab9f747d9ed | 74 | else if (in == 4) { |
Matt Briggs | 48:bab9f747d9ed | 75 | mBbio->relayAlert(); |
Matt Briggs | 48:bab9f747d9ed | 76 | } |
Matt Briggs | 48:bab9f747d9ed | 77 | else if (in == 5) { |
Matt Briggs | 48:bab9f747d9ed | 78 | mBbio->serialRx(true); |
Matt Briggs | 48:bab9f747d9ed | 79 | } |
Matt Briggs | 48:bab9f747d9ed | 80 | else if (in == 6) { |
Matt Briggs | 48:bab9f747d9ed | 81 | mBbio->serialRx(false); |
Matt Briggs | 48:bab9f747d9ed | 82 | } |
Matt Briggs | 48:bab9f747d9ed | 83 | else if (in == 7) { |
Matt Briggs | 48:bab9f747d9ed | 84 | mBbio->serialTx(true); |
Matt Briggs | 48:bab9f747d9ed | 85 | } |
Matt Briggs | 48:bab9f747d9ed | 86 | else if (in == 8) { |
Matt Briggs | 48:bab9f747d9ed | 87 | mBbio->serialTx(false); |
Matt Briggs | 48:bab9f747d9ed | 88 | } |
Matt Briggs | 48:bab9f747d9ed | 89 | } |
Matt Briggs | 48:bab9f747d9ed | 90 | } |
Matt Briggs | 48:bab9f747d9ed | 91 | void printMenu() { |
Matt Briggs | 48:bab9f747d9ed | 92 | mBbio->sampleUserSwitches(); |
Matt Briggs | 48:bab9f747d9ed | 93 | pc.printf("\r\n\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 94 | pc.printf("===============================================\r\n"); |
Matt Briggs | 49:18f1354f9e51 | 95 | pc.printf("= Baseboard I/O Tester v%02d =\r\n", VERSION); |
Matt Briggs | 48:bab9f747d9ed | 96 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 97 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 98 | pc.printf("= Selection Options =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 99 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 100 | pc.printf("= 0: Just refresh =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 101 | pc.printf("= 1: Turn on LED =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 102 | pc.printf("= 2: Turn off LED =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 103 | pc.printf("= 3: Toggle Relay Normal =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 104 | pc.printf("= 4: Toggle Relay Alert =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 105 | pc.printf("= 5: Turn on 232 RX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 106 | pc.printf("= 6: Turn off 232 RX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 107 | pc.printf("= 7: Turn on 232 TX (Note RX on as well) =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 108 | pc.printf("= 8: Turn off 232 TX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 109 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 110 | pc.printf("= Status and Counters =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 111 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 112 | pc.printf("= Pair btn. State: %s IntCnt: %02d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 113 | bool2Str(mBbio->isPairBtn()), pairBtnIntCnt); |
Matt Briggs | 49:18f1354f9e51 | 114 | pc.printf("= Tamper. State: N/A IntCnt: %04d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 115 | tamperIntCnt); |
Matt Briggs | 48:bab9f747d9ed | 116 | pc.printf("= CCIN. State: %s IntCnt: %02d =\r\n", |
Matt Briggs | 67:2115a2f1b945 | 117 | bool2Str(mBbio->isCCInAlert()), ccInIntCnt); |
Matt Briggs | 51:58d2a1b8f9d2 | 118 | pc.printf("= PVD (BROKEN). State: N/A IntCnt: %02d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 119 | pvdIntCnt); |
Matt Briggs | 61:8d9efd33cac9 | 120 | pc.printf("= CC Normally Closed. State: %s =\r\n", bool2Str(mBbio->isCCNC())); |
Matt Briggs | 48:bab9f747d9ed | 121 | pc.printf("= Is TX. State: %s =\r\n", bool2Str(mBbio->isTx())); |
Matt Briggs | 48:bab9f747d9ed | 122 | pc.printf("= Is LoraWAN. State: %s =\r\n", bool2Str(mBbio->isLoRaWANMode())); |
Matt Briggs | 50:e89647e77fd5 | 123 | pc.printf("= Is Serial En. State: %s =\r\n", bool2Str(mBbio->isSerialEnabled())); |
Matt Briggs | 48:bab9f747d9ed | 124 | pc.printf("= Rotary Switch 1. Value: %02d =\r\n", mBbio->rotarySwitch1()); |
Matt Briggs | 48:bab9f747d9ed | 125 | pc.printf("= Rotary Switch 2. Value: %02d =\r\n", mBbio->rotarySwitch2()); |
Matt Briggs | 48:bab9f747d9ed | 126 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 127 | } |
Matt Briggs | 48:bab9f747d9ed | 128 | }; |
Matt Briggs | 48:bab9f747d9ed | 129 | |
Matt Briggs | 49:18f1354f9e51 | 130 | char WAIT_CHARS [] = {'-', '\\', '|', '/'}; |
Matt Briggs | 48:bab9f747d9ed | 131 | /** |
Matt Briggs | 48:bab9f747d9ed | 132 | * Checks that in idle state all the IOs are pulled up. |
Matt Briggs | 48:bab9f747d9ed | 133 | */ |
Matt Briggs | 48:bab9f747d9ed | 134 | int main () |
Matt Briggs | 48:bab9f747d9ed | 135 | { |
Matt Briggs | 48:bab9f747d9ed | 136 | MenuManager menuMgr; |
Matt Briggs | 48:bab9f747d9ed | 137 | CmdResult result; |
Matt Briggs | 48:bab9f747d9ed | 138 | ccInIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 139 | tamperIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 140 | pairBtnIntCnt = 0; |
Matt Briggs | 49:18f1354f9e51 | 141 | pvdIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 142 | |
Matt Briggs | 48:bab9f747d9ed | 143 | pc.baud(115200); |
Matt Briggs | 49:18f1354f9e51 | 144 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); |
Matt Briggs | 67:2115a2f1b945 | 145 | MyLog::setLogLevel(MyLog::DEBUG_LEVEL); |
Matt Briggs | 49:18f1354f9e51 | 146 | |
Matt Briggs | 48:bab9f747d9ed | 147 | wait(1.0); |
Matt Briggs | 48:bab9f747d9ed | 148 | |
Matt Briggs | 48:bab9f747d9ed | 149 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 150 | pc.printf("= Baseboard Constructor Starting =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 151 | BaseboardIO bbio; |
Matt Briggs | 48:bab9f747d9ed | 152 | pc.printf("= Baseboard Constructor Finished =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 153 | |
Matt Briggs | 48:bab9f747d9ed | 154 | pc.printf("= Baseboard Init Starting =\r\n"); |
Matt Briggs | 56:40b454c952cc | 155 | result = bbio.init(true); // Overwrite current NVM |
Matt Briggs | 56:40b454c952cc | 156 | // result = bbio.init(false); |
Matt Briggs | 48:bab9f747d9ed | 157 | if (result == cmdSuccess) { |
Matt Briggs | 48:bab9f747d9ed | 158 | pc.printf("= Baseboard Init Finished Successfully =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 159 | } |
Matt Briggs | 48:bab9f747d9ed | 160 | else { |
Matt Briggs | 48:bab9f747d9ed | 161 | pc.printf("= Baseboard Init Finished with Error =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 162 | } |
Matt Briggs | 48:bab9f747d9ed | 163 | |
Matt Briggs | 49:18f1354f9e51 | 164 | Callback<void()> ccInIntObj (&ccInIntCallback); |
Matt Briggs | 49:18f1354f9e51 | 165 | Callback<void()> tamperIntObj (&tamperIntCallback); |
Matt Briggs | 49:18f1354f9e51 | 166 | Callback<void()> pairBtnIntObj (&pairBtnIntCallback); |
Matt Briggs | 49:18f1354f9e51 | 167 | bbio.regCCInInt(ccInIntObj); |
Matt Briggs | 49:18f1354f9e51 | 168 | bbio.regTamperInt(tamperIntObj); |
Matt Briggs | 49:18f1354f9e51 | 169 | bbio.regPairBtnInt(pairBtnIntObj); |
Matt Briggs | 48:bab9f747d9ed | 170 | |
Matt Briggs | 48:bab9f747d9ed | 171 | menuMgr.regBBIO(&bbio); |
Matt Briggs | 48:bab9f747d9ed | 172 | menuMgr.printMenu(); |
Matt Briggs | 48:bab9f747d9ed | 173 | |
Matt Briggs | 49:18f1354f9e51 | 174 | uint8_t waitCharIdx = 0; |
Matt Briggs | 48:bab9f747d9ed | 175 | while (true) { |
Matt Briggs | 48:bab9f747d9ed | 176 | |
Matt Briggs | 48:bab9f747d9ed | 177 | if (pc.readable()) { |
Matt Briggs | 48:bab9f747d9ed | 178 | char menuInput = pc.getc(); |
Matt Briggs | 48:bab9f747d9ed | 179 | menuInput -= '0'; // Convert to raw interger value |
Matt Briggs | 48:bab9f747d9ed | 180 | menuMgr.applyInput(menuInput); |
Matt Briggs | 48:bab9f747d9ed | 181 | menuMgr.printMenu(); |
Matt Briggs | 48:bab9f747d9ed | 182 | } |
Matt Briggs | 48:bab9f747d9ed | 183 | else { |
Matt Briggs | 49:18f1354f9e51 | 184 | pc.printf("\b%c", WAIT_CHARS[waitCharIdx]); |
Matt Briggs | 49:18f1354f9e51 | 185 | if (waitCharIdx >= sizeof(WAIT_CHARS)) { |
Matt Briggs | 49:18f1354f9e51 | 186 | waitCharIdx = 0; |
Matt Briggs | 49:18f1354f9e51 | 187 | } |
Matt Briggs | 49:18f1354f9e51 | 188 | else { |
Matt Briggs | 49:18f1354f9e51 | 189 | waitCharIdx++; |
Matt Briggs | 49:18f1354f9e51 | 190 | } |
Matt Briggs | 48:bab9f747d9ed | 191 | } |
Matt Briggs | 49:18f1354f9e51 | 192 | wait(0.1); |
Matt Briggs | 48:bab9f747d9ed | 193 | } |
Matt Briggs | 48:bab9f747d9ed | 194 | return 0; |
Matt Briggs | 48:bab9f747d9ed | 195 | } |
Matt Briggs | 51:58d2a1b8f9d2 | 196 | |
Matt Briggs | 48:bab9f747d9ed | 197 | #endif |