![](/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/src/SerialTermMgr.cpp@75:600cb3a9f126, 2017-05-10 (annotated)
- Committer:
- Matt Briggs
- Date:
- Wed May 10 13:54:25 2017 -0600
- Revision:
- 75:600cb3a9f126
- Child:
- 76:d1b20a259d8f
Skeleton version of terminal. Compiled version of prototype code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Matt Briggs | 75:600cb3a9f126 | 1 | /* |
Matt Briggs | 75:600cb3a9f126 | 2 | * SerialTermMgr.cpp |
Matt Briggs | 75:600cb3a9f126 | 3 | * |
Matt Briggs | 75:600cb3a9f126 | 4 | * Created on: May 8, 2017 |
Matt Briggs | 75:600cb3a9f126 | 5 | * Author: mbriggs |
Matt Briggs | 75:600cb3a9f126 | 6 | */ |
Matt Briggs | 75:600cb3a9f126 | 7 | |
Matt Briggs | 75:600cb3a9f126 | 8 | #include "SerialTermMgr.h" |
Matt Briggs | 75:600cb3a9f126 | 9 | #include "UserInterface.h" |
Matt Briggs | 75:600cb3a9f126 | 10 | |
Matt Briggs | 75:600cb3a9f126 | 11 | SerialTermMgr::SerialTermMgr(BaseboardIO *bbio, float fwVersion) |
Matt Briggs | 75:600cb3a9f126 | 12 | { |
Matt Briggs | 75:600cb3a9f126 | 13 | mPc = NULL; |
Matt Briggs | 75:600cb3a9f126 | 14 | mFwVersion = fwVersion; |
Matt Briggs | 75:600cb3a9f126 | 15 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 16 | mBbio = bbio; |
Matt Briggs | 75:600cb3a9f126 | 17 | } |
Matt Briggs | 75:600cb3a9f126 | 18 | void SerialTermMgr::printScreen() |
Matt Briggs | 75:600cb3a9f126 | 19 | { |
Matt Briggs | 75:600cb3a9f126 | 20 | switch (mCurrScreen) { |
Matt Briggs | 75:600cb3a9f126 | 21 | case mainScreenId: |
Matt Briggs | 75:600cb3a9f126 | 22 | printMainScreen(); |
Matt Briggs | 75:600cb3a9f126 | 23 | break; |
Matt Briggs | 75:600cb3a9f126 | 24 | case genInfoScreenId: |
Matt Briggs | 75:600cb3a9f126 | 25 | printGenInfo(); |
Matt Briggs | 75:600cb3a9f126 | 26 | break; |
Matt Briggs | 75:600cb3a9f126 | 27 | case settingsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 28 | case statsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 29 | case errorLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 30 | case liveLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 31 | case enterSerialBridgeScreenId: |
Matt Briggs | 75:600cb3a9f126 | 32 | case enterProgModeScreenId: |
Matt Briggs | 75:600cb3a9f126 | 33 | printMainScreen(); |
Matt Briggs | 75:600cb3a9f126 | 34 | } |
Matt Briggs | 75:600cb3a9f126 | 35 | } |
Matt Briggs | 75:600cb3a9f126 | 36 | bool SerialTermMgr::input() |
Matt Briggs | 75:600cb3a9f126 | 37 | { |
Matt Briggs | 75:600cb3a9f126 | 38 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 39 | return true; |
Matt Briggs | 75:600cb3a9f126 | 40 | } |
Matt Briggs | 75:600cb3a9f126 | 41 | bool quit = false; |
Matt Briggs | 75:600cb3a9f126 | 42 | char c = 10; |
Matt Briggs | 75:600cb3a9f126 | 43 | if (mPc->readable()) { |
Matt Briggs | 75:600cb3a9f126 | 44 | c = mPc->getc(); |
Matt Briggs | 75:600cb3a9f126 | 45 | } |
Matt Briggs | 75:600cb3a9f126 | 46 | else { |
Matt Briggs | 75:600cb3a9f126 | 47 | return false; // Do nothing if there is no input |
Matt Briggs | 75:600cb3a9f126 | 48 | } |
Matt Briggs | 75:600cb3a9f126 | 49 | switch (mCurrScreen) { |
Matt Briggs | 75:600cb3a9f126 | 50 | case mainScreenId: |
Matt Briggs | 75:600cb3a9f126 | 51 | quit = inputMainPage(c); |
Matt Briggs | 75:600cb3a9f126 | 52 | break; |
Matt Briggs | 75:600cb3a9f126 | 53 | case genInfoScreenId: |
Matt Briggs | 75:600cb3a9f126 | 54 | inputGenInfo(c); |
Matt Briggs | 75:600cb3a9f126 | 55 | break; |
Matt Briggs | 75:600cb3a9f126 | 56 | case settingsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 57 | case statsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 58 | case errorLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 59 | case liveLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 60 | case enterSerialBridgeScreenId: |
Matt Briggs | 75:600cb3a9f126 | 61 | case enterProgModeScreenId: |
Matt Briggs | 75:600cb3a9f126 | 62 | inputMainPage(c); |
Matt Briggs | 75:600cb3a9f126 | 63 | } |
Matt Briggs | 75:600cb3a9f126 | 64 | return quit; |
Matt Briggs | 75:600cb3a9f126 | 65 | } |
Matt Briggs | 75:600cb3a9f126 | 66 | |
Matt Briggs | 75:600cb3a9f126 | 67 | // private methods |
Matt Briggs | 75:600cb3a9f126 | 68 | bool SerialTermMgr::inputMainPage (char in) { |
Matt Briggs | 75:600cb3a9f126 | 69 | bool quit = false; |
Matt Briggs | 75:600cb3a9f126 | 70 | switch (in) { |
Matt Briggs | 75:600cb3a9f126 | 71 | case '1': |
Matt Briggs | 75:600cb3a9f126 | 72 | mCurrScreen = genInfoScreenId; |
Matt Briggs | 75:600cb3a9f126 | 73 | break; |
Matt Briggs | 75:600cb3a9f126 | 74 | case '2': |
Matt Briggs | 75:600cb3a9f126 | 75 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 76 | // mCurrScreen = settingsScreenId; |
Matt Briggs | 75:600cb3a9f126 | 77 | break; |
Matt Briggs | 75:600cb3a9f126 | 78 | case '3': |
Matt Briggs | 75:600cb3a9f126 | 79 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 80 | // mCurrScreen = statsScreenId; |
Matt Briggs | 75:600cb3a9f126 | 81 | break; |
Matt Briggs | 75:600cb3a9f126 | 82 | case '4': |
Matt Briggs | 75:600cb3a9f126 | 83 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 84 | // mCurrScreen = errorLogScreenId; |
Matt Briggs | 75:600cb3a9f126 | 85 | break; |
Matt Briggs | 75:600cb3a9f126 | 86 | case '5': |
Matt Briggs | 75:600cb3a9f126 | 87 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 88 | // mCurrScreen = liveLogScreenId; |
Matt Briggs | 75:600cb3a9f126 | 89 | break; |
Matt Briggs | 75:600cb3a9f126 | 90 | case '6': |
Matt Briggs | 75:600cb3a9f126 | 91 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 92 | // mCurrScreen = enterSerialBridgeScreenId; |
Matt Briggs | 75:600cb3a9f126 | 93 | break; |
Matt Briggs | 75:600cb3a9f126 | 94 | case '7': |
Matt Briggs | 75:600cb3a9f126 | 95 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 96 | // mCurrScreen = enterProgModeScreenId; |
Matt Briggs | 75:600cb3a9f126 | 97 | break; |
Matt Briggs | 75:600cb3a9f126 | 98 | case 0x11: // ctrl-q |
Matt Briggs | 75:600cb3a9f126 | 99 | quit=true; |
Matt Briggs | 75:600cb3a9f126 | 100 | break; |
Matt Briggs | 75:600cb3a9f126 | 101 | default: |
Matt Briggs | 75:600cb3a9f126 | 102 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 103 | } |
Matt Briggs | 75:600cb3a9f126 | 104 | if (!quit) { |
Matt Briggs | 75:600cb3a9f126 | 105 | printScreen(); |
Matt Briggs | 75:600cb3a9f126 | 106 | } |
Matt Briggs | 75:600cb3a9f126 | 107 | return quit; |
Matt Briggs | 75:600cb3a9f126 | 108 | } |
Matt Briggs | 75:600cb3a9f126 | 109 | |
Matt Briggs | 75:600cb3a9f126 | 110 | void SerialTermMgr::printMainScreen() |
Matt Briggs | 75:600cb3a9f126 | 111 | { |
Matt Briggs | 75:600cb3a9f126 | 112 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 113 | return; |
Matt Briggs | 75:600cb3a9f126 | 114 | } |
Matt Briggs | 75:600cb3a9f126 | 115 | mPc->printf("\r\n\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 116 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 117 | mPc->printf("= Wireless Bridge Terminal (Firmware: v%0.2f) =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 118 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 119 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 120 | mPc->printf("= Selection Options =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 121 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 122 | mPc->printf("= 0: Refresh (Enter and space also work) =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 123 | mPc->printf("= 1: General information =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 124 | mPc->printf("= 2: Settings =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 125 | mPc->printf("= 3: Statistics =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 126 | mPc->printf("= 4: Error log =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 127 | mPc->printf("= 5: Live log =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 128 | mPc->printf("= 6: Enter serial bridge mode =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 129 | mPc->printf("= 7: Enter programming mode =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 130 | mPc->printf("= <ctrl>-q: Exit terminal =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 131 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 132 | } |
Matt Briggs | 75:600cb3a9f126 | 133 | |
Matt Briggs | 75:600cb3a9f126 | 134 | void SerialTermMgr::inputGenInfo (char in) { |
Matt Briggs | 75:600cb3a9f126 | 135 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 136 | return; |
Matt Briggs | 75:600cb3a9f126 | 137 | } |
Matt Briggs | 75:600cb3a9f126 | 138 | switch (in) { |
Matt Briggs | 75:600cb3a9f126 | 139 | case 0x1B: |
Matt Briggs | 75:600cb3a9f126 | 140 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 141 | break; |
Matt Briggs | 75:600cb3a9f126 | 142 | case 'r': |
Matt Briggs | 75:600cb3a9f126 | 143 | mBbio->sampleUserSwitches(); |
Matt Briggs | 75:600cb3a9f126 | 144 | mPc->printf("User switches sampled.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 145 | break; |
Matt Briggs | 75:600cb3a9f126 | 146 | default: |
Matt Briggs | 75:600cb3a9f126 | 147 | mPc->printf("Invalid key.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 148 | } |
Matt Briggs | 75:600cb3a9f126 | 149 | printScreen(); |
Matt Briggs | 75:600cb3a9f126 | 150 | } |
Matt Briggs | 75:600cb3a9f126 | 151 | |
Matt Briggs | 75:600cb3a9f126 | 152 | void SerialTermMgr::printGenInfo() |
Matt Briggs | 75:600cb3a9f126 | 153 | { |
Matt Briggs | 75:600cb3a9f126 | 154 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 155 | return; |
Matt Briggs | 75:600cb3a9f126 | 156 | } |
Matt Briggs | 75:600cb3a9f126 | 157 | mPc->printf("\r\n\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 158 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 159 | mPc->printf("= General Info (ESC to return to main menu) =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 160 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 161 | mPc->printf("= Press r to sample user switch values =\r\n"); // FIXME |
Matt Briggs | 75:600cb3a9f126 | 162 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 163 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 164 | mPc->printf("= Firmware version: v%0.2f =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 165 | //TODO |
Matt Briggs | 75:600cb3a9f126 | 166 | // mPc->printf("= Radio EUI: %s =\r\n", mts::Text::bin2hexString(dot->getDeviceId()).c_str()); |
Matt Briggs | 75:600cb3a9f126 | 167 | mPc->printf("= Contact closure: %s =\r\n", mBbio->isCCNO() ? "Normally open " : |
Matt Briggs | 75:600cb3a9f126 | 168 | "Normally closed"); |
Matt Briggs | 75:600cb3a9f126 | 169 | mPc->printf("= WB Mode: %s =\r\n", mBbio->isTx() ? "Transmitter" : |
Matt Briggs | 75:600cb3a9f126 | 170 | "Receiver "); |
Matt Briggs | 75:600cb3a9f126 | 171 | mPc->printf("= Comm Mode: %s =\r\n", mBbio->isLoRaWANMode() ? "LoRaWAN " : |
Matt Briggs | 75:600cb3a9f126 | 172 | "Peer-to-peer"); |
Matt Briggs | 75:600cb3a9f126 | 173 | mPc->printf("= Serial Mode: %s =\r\n", mBbio->isSerialEnabled() ? "Enabled " : |
Matt Briggs | 75:600cb3a9f126 | 174 | "Disabled"); |
Matt Briggs | 75:600cb3a9f126 | 175 | if (mBbio->isTx()) { |
Matt Briggs | 75:600cb3a9f126 | 176 | mPc->printf("= Currently no rotary switches apply for TX =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 177 | } |
Matt Briggs | 75:600cb3a9f126 | 178 | else { |
Matt Briggs | 75:600cb3a9f126 | 179 | mPc->printf("= Rotary 1 hold setting is %0.1f seconds =\r\n", HoldTimeSetting::rotVal2Sec(mBbio->rotarySwitch1())); |
Matt Briggs | 75:600cb3a9f126 | 180 | mPc->printf("= Rotary 2 currently does not apply for RX =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 181 | } |
Matt Briggs | 75:600cb3a9f126 | 182 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 183 | } |