![](/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@57:bdac7dd17af2, 2017-02-28 (annotated)
- Committer:
- Matt Briggs
- Date:
- Tue Feb 28 09:26:27 2017 -0700
- Revision:
- 57:bdac7dd17af2
- Parent:
- 56:40b454c952cc
- Child:
- 61:8d9efd33cac9
Got static networking with static configuration working. Also added disabling test mode for DS2408.
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 | 48:bab9f747d9ed | 7 | |
Matt Briggs | 48:bab9f747d9ed | 8 | #ifdef __TEST_BBIO__ |
Matt Briggs | 56:40b454c952cc | 9 | mDot* dot = NULL; // Used by dot-utils |
Matt Briggs | 48:bab9f747d9ed | 10 | Serial pc(USBTX, USBRX); // Externally defined |
Matt Briggs | 48:bab9f747d9ed | 11 | |
Matt Briggs | 57:bdac7dd17af2 | 12 | const int VERSION = 4; |
Matt Briggs | 49:18f1354f9e51 | 13 | |
Matt Briggs | 48:bab9f747d9ed | 14 | char* bool2Str(bool in) { |
Matt Briggs | 48:bab9f747d9ed | 15 | if (in) { |
Matt Briggs | 48:bab9f747d9ed | 16 | return "Asserted\ "; // Extra space for alignment |
Matt Briggs | 48:bab9f747d9ed | 17 | } |
Matt Briggs | 48:bab9f747d9ed | 18 | else { |
Matt Briggs | 48:bab9f747d9ed | 19 | return "Not Asserted"; |
Matt Briggs | 48:bab9f747d9ed | 20 | } |
Matt Briggs | 48:bab9f747d9ed | 21 | } |
Matt Briggs | 48:bab9f747d9ed | 22 | |
Matt Briggs | 49:18f1354f9e51 | 23 | volatile uint8_t ccInIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 24 | volatile uint8_t tamperIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 25 | volatile uint8_t pairBtnIntCnt; |
Matt Briggs | 49:18f1354f9e51 | 26 | volatile uint8_t pvdIntCnt; |
Matt Briggs | 48:bab9f747d9ed | 27 | |
Matt Briggs | 48:bab9f747d9ed | 28 | void ccInIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 29 | ccInIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 30 | } |
Matt Briggs | 48:bab9f747d9ed | 31 | void tamperIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 32 | tamperIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 33 | } |
Matt Briggs | 48:bab9f747d9ed | 34 | void pairBtnIntCallback () { |
Matt Briggs | 48:bab9f747d9ed | 35 | pairBtnIntCnt++; |
Matt Briggs | 48:bab9f747d9ed | 36 | } |
Matt Briggs | 51:58d2a1b8f9d2 | 37 | |
Matt Briggs | 51:58d2a1b8f9d2 | 38 | // TODO Add in later after I figure out how |
Matt Briggs | 48:bab9f747d9ed | 39 | |
Matt Briggs | 48:bab9f747d9ed | 40 | class MenuManager |
Matt Briggs | 48:bab9f747d9ed | 41 | { |
Matt Briggs | 48:bab9f747d9ed | 42 | private: |
Matt Briggs | 48:bab9f747d9ed | 43 | uint8_t mCurrSel; // Current selection |
Matt Briggs | 48:bab9f747d9ed | 44 | BaseboardIO *mBbio; |
Matt Briggs | 48:bab9f747d9ed | 45 | bool validInput(uint8_t in) { |
Matt Briggs | 48:bab9f747d9ed | 46 | if (in > 0 && in <= 8) |
Matt Briggs | 48:bab9f747d9ed | 47 | return true; |
Matt Briggs | 48:bab9f747d9ed | 48 | else { |
Matt Briggs | 48:bab9f747d9ed | 49 | return false; |
Matt Briggs | 48:bab9f747d9ed | 50 | } |
Matt Briggs | 48:bab9f747d9ed | 51 | } |
Matt Briggs | 48:bab9f747d9ed | 52 | public: |
Matt Briggs | 48:bab9f747d9ed | 53 | MenuManager() { |
Matt Briggs | 48:bab9f747d9ed | 54 | mCurrSel = 0; |
Matt Briggs | 48:bab9f747d9ed | 55 | mBbio = NULL; |
Matt Briggs | 48:bab9f747d9ed | 56 | } |
Matt Briggs | 48:bab9f747d9ed | 57 | void regBBIO (BaseboardIO *bbio) { |
Matt Briggs | 48:bab9f747d9ed | 58 | mBbio = bbio; |
Matt Briggs | 48:bab9f747d9ed | 59 | } |
Matt Briggs | 48:bab9f747d9ed | 60 | uint8_t getCurrentSel() { |
Matt Briggs | 48:bab9f747d9ed | 61 | return mCurrSel; |
Matt Briggs | 48:bab9f747d9ed | 62 | } |
Matt Briggs | 48:bab9f747d9ed | 63 | void applyInput(uint8_t in) { |
Matt Briggs | 48:bab9f747d9ed | 64 | if (validInput(in)) { |
Matt Briggs | 48:bab9f747d9ed | 65 | // mCurrSel = in; |
Matt Briggs | 48:bab9f747d9ed | 66 | if (in == 1) { |
Matt Briggs | 48:bab9f747d9ed | 67 | mBbio->ledOn(); |
Matt Briggs | 48:bab9f747d9ed | 68 | } |
Matt Briggs | 48:bab9f747d9ed | 69 | else if (in == 2) { |
Matt Briggs | 48:bab9f747d9ed | 70 | mBbio->ledOff(); |
Matt Briggs | 48:bab9f747d9ed | 71 | } |
Matt Briggs | 48:bab9f747d9ed | 72 | else if (in == 3) { |
Matt Briggs | 48:bab9f747d9ed | 73 | mBbio->relayNormal(); |
Matt Briggs | 48:bab9f747d9ed | 74 | } |
Matt Briggs | 48:bab9f747d9ed | 75 | else if (in == 4) { |
Matt Briggs | 48:bab9f747d9ed | 76 | mBbio->relayAlert(); |
Matt Briggs | 48:bab9f747d9ed | 77 | } |
Matt Briggs | 48:bab9f747d9ed | 78 | else if (in == 5) { |
Matt Briggs | 48:bab9f747d9ed | 79 | mBbio->serialRx(true); |
Matt Briggs | 48:bab9f747d9ed | 80 | } |
Matt Briggs | 48:bab9f747d9ed | 81 | else if (in == 6) { |
Matt Briggs | 48:bab9f747d9ed | 82 | mBbio->serialRx(false); |
Matt Briggs | 48:bab9f747d9ed | 83 | } |
Matt Briggs | 48:bab9f747d9ed | 84 | else if (in == 7) { |
Matt Briggs | 48:bab9f747d9ed | 85 | mBbio->serialTx(true); |
Matt Briggs | 48:bab9f747d9ed | 86 | } |
Matt Briggs | 48:bab9f747d9ed | 87 | else if (in == 8) { |
Matt Briggs | 48:bab9f747d9ed | 88 | mBbio->serialTx(false); |
Matt Briggs | 48:bab9f747d9ed | 89 | } |
Matt Briggs | 48:bab9f747d9ed | 90 | } |
Matt Briggs | 48:bab9f747d9ed | 91 | } |
Matt Briggs | 48:bab9f747d9ed | 92 | void printMenu() { |
Matt Briggs | 48:bab9f747d9ed | 93 | mBbio->sampleUserSwitches(); |
Matt Briggs | 48:bab9f747d9ed | 94 | pc.printf("\r\n\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 95 | pc.printf("===============================================\r\n"); |
Matt Briggs | 49:18f1354f9e51 | 96 | pc.printf("= Baseboard I/O Tester v%02d =\r\n", VERSION); |
Matt Briggs | 48:bab9f747d9ed | 97 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 98 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 99 | pc.printf("= Selection Options =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 100 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 101 | pc.printf("= 0: Just refresh =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 102 | pc.printf("= 1: Turn on LED =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 103 | pc.printf("= 2: Turn off LED =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 104 | pc.printf("= 3: Toggle Relay Normal =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 105 | pc.printf("= 4: Toggle Relay Alert =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 106 | pc.printf("= 5: Turn on 232 RX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 107 | pc.printf("= 6: Turn off 232 RX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 108 | pc.printf("= 7: Turn on 232 TX (Note RX on as well) =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 109 | pc.printf("= 8: Turn off 232 TX =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 110 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 111 | pc.printf("= Status and Counters =\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 112 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 113 | pc.printf("= Pair btn. State: %s IntCnt: %02d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 114 | bool2Str(mBbio->isPairBtn()), pairBtnIntCnt); |
Matt Briggs | 49:18f1354f9e51 | 115 | pc.printf("= Tamper. State: N/A IntCnt: %04d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 116 | tamperIntCnt); |
Matt Briggs | 48:bab9f747d9ed | 117 | pc.printf("= CCIN. State: %s IntCnt: %02d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 118 | bool2Str(0), ccInIntCnt); |
Matt Briggs | 51:58d2a1b8f9d2 | 119 | pc.printf("= PVD (BROKEN). State: N/A IntCnt: %02d =\r\n", |
Matt Briggs | 49:18f1354f9e51 | 120 | pvdIntCnt); |
Matt Briggs | 48:bab9f747d9ed | 121 | pc.printf("= Is TX. State: %s =\r\n", bool2Str(mBbio->isTx())); |
Matt Briggs | 49:18f1354f9e51 | 122 | pc.printf("= CC Normally Closed. State: %s =\r\n", bool2Str(mBbio->isCCNC())); |
Matt Briggs | 48:bab9f747d9ed | 123 | pc.printf("= Is LoraWAN. State: %s =\r\n", bool2Str(mBbio->isLoRaWANMode())); |
Matt Briggs | 50:e89647e77fd5 | 124 | pc.printf("= Is Serial En. State: %s =\r\n", bool2Str(mBbio->isSerialEnabled())); |
Matt Briggs | 48:bab9f747d9ed | 125 | pc.printf("= Rotary Switch 1. Value: %02d =\r\n", mBbio->rotarySwitch1()); |
Matt Briggs | 48:bab9f747d9ed | 126 | pc.printf("= Rotary Switch 2. Value: %02d =\r\n", mBbio->rotarySwitch2()); |
Matt Briggs | 48:bab9f747d9ed | 127 | pc.printf("===============================================\r\n"); |
Matt Briggs | 48:bab9f747d9ed | 128 | } |
Matt Briggs | 48:bab9f747d9ed | 129 | }; |
Matt Briggs | 48:bab9f747d9ed | 130 | |
Matt Briggs | 49:18f1354f9e51 | 131 | char WAIT_CHARS [] = {'-', '\\', '|', '/'}; |
Matt Briggs | 48:bab9f747d9ed | 132 | /** |
Matt Briggs | 48:bab9f747d9ed | 133 | * Checks that in idle state all the IOs are pulled up. |
Matt Briggs | 48:bab9f747d9ed | 134 | */ |
Matt Briggs | 48:bab9f747d9ed | 135 | int main () |
Matt Briggs | 48:bab9f747d9ed | 136 | { |
Matt Briggs | 48:bab9f747d9ed | 137 | MenuManager menuMgr; |
Matt Briggs | 48:bab9f747d9ed | 138 | CmdResult result; |
Matt Briggs | 48:bab9f747d9ed | 139 | ccInIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 140 | tamperIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 141 | pairBtnIntCnt = 0; |
Matt Briggs | 49:18f1354f9e51 | 142 | pvdIntCnt = 0; |
Matt Briggs | 48:bab9f747d9ed | 143 | |
Matt Briggs | 48:bab9f747d9ed | 144 | pc.baud(115200); |
Matt Briggs | 49:18f1354f9e51 | 145 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_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 |