![](/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@77:176e3eb8f712, 2017-05-17 (annotated)
- Committer:
- Matt Briggs
- Date:
- Wed May 17 16:41:56 2017 -0600
- Revision:
- 77:176e3eb8f712
- Parent:
- 76:d1b20a259d8f
- Child:
- 78:43f074baac34
Added serial terminal and Buffered lib
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 | 76:d1b20a259d8f | 11 | extern Serial pc; |
Matt Briggs | 76:d1b20a259d8f | 12 | const char ACK = 0x06; |
Matt Briggs | 76:d1b20a259d8f | 13 | const char NAK = 0x15; |
Matt Briggs | 77:176e3eb8f712 | 14 | const char SOH = 0x01; |
Matt Briggs | 77:176e3eb8f712 | 15 | const char EOT = 0x04; |
Matt Briggs | 77:176e3eb8f712 | 16 | const char SUB = 0x1A; |
Matt Briggs | 76:d1b20a259d8f | 17 | |
Matt Briggs | 77:176e3eb8f712 | 18 | SerialTermMgr::SerialTermMgr(BaseboardIO *bbio, WinbondSPIFlash *flash, float fwVersion) |
Matt Briggs | 75:600cb3a9f126 | 19 | { |
Matt Briggs | 75:600cb3a9f126 | 20 | mPc = NULL; |
Matt Briggs | 75:600cb3a9f126 | 21 | mFwVersion = fwVersion; |
Matt Briggs | 75:600cb3a9f126 | 22 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 23 | mBbio = bbio; |
Matt Briggs | 77:176e3eb8f712 | 24 | mFlash = flash; |
Matt Briggs | 75:600cb3a9f126 | 25 | } |
Matt Briggs | 75:600cb3a9f126 | 26 | void SerialTermMgr::printScreen() |
Matt Briggs | 75:600cb3a9f126 | 27 | { |
Matt Briggs | 75:600cb3a9f126 | 28 | switch (mCurrScreen) { |
Matt Briggs | 75:600cb3a9f126 | 29 | case mainScreenId: |
Matt Briggs | 75:600cb3a9f126 | 30 | printMainScreen(); |
Matt Briggs | 75:600cb3a9f126 | 31 | break; |
Matt Briggs | 75:600cb3a9f126 | 32 | case genInfoScreenId: |
Matt Briggs | 75:600cb3a9f126 | 33 | printGenInfo(); |
Matt Briggs | 75:600cb3a9f126 | 34 | break; |
Matt Briggs | 75:600cb3a9f126 | 35 | case settingsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 36 | case statsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 37 | case errorLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 38 | case liveLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 39 | case enterSerialBridgeScreenId: |
Matt Briggs | 76:d1b20a259d8f | 40 | printMainScreen(); |
Matt Briggs | 76:d1b20a259d8f | 41 | break; |
Matt Briggs | 75:600cb3a9f126 | 42 | case enterProgModeScreenId: |
Matt Briggs | 76:d1b20a259d8f | 43 | printEnterProgMode(); |
Matt Briggs | 75:600cb3a9f126 | 44 | } |
Matt Briggs | 75:600cb3a9f126 | 45 | } |
Matt Briggs | 75:600cb3a9f126 | 46 | bool SerialTermMgr::input() |
Matt Briggs | 75:600cb3a9f126 | 47 | { |
Matt Briggs | 75:600cb3a9f126 | 48 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 49 | return true; |
Matt Briggs | 75:600cb3a9f126 | 50 | } |
Matt Briggs | 75:600cb3a9f126 | 51 | bool quit = false; |
Matt Briggs | 75:600cb3a9f126 | 52 | char c = 10; |
Matt Briggs | 75:600cb3a9f126 | 53 | if (mPc->readable()) { |
Matt Briggs | 75:600cb3a9f126 | 54 | c = mPc->getc(); |
Matt Briggs | 75:600cb3a9f126 | 55 | } |
Matt Briggs | 75:600cb3a9f126 | 56 | else { |
Matt Briggs | 75:600cb3a9f126 | 57 | return false; // Do nothing if there is no input |
Matt Briggs | 75:600cb3a9f126 | 58 | } |
Matt Briggs | 75:600cb3a9f126 | 59 | switch (mCurrScreen) { |
Matt Briggs | 75:600cb3a9f126 | 60 | case mainScreenId: |
Matt Briggs | 75:600cb3a9f126 | 61 | quit = inputMainPage(c); |
Matt Briggs | 75:600cb3a9f126 | 62 | break; |
Matt Briggs | 75:600cb3a9f126 | 63 | case genInfoScreenId: |
Matt Briggs | 75:600cb3a9f126 | 64 | inputGenInfo(c); |
Matt Briggs | 75:600cb3a9f126 | 65 | break; |
Matt Briggs | 75:600cb3a9f126 | 66 | case settingsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 67 | case statsScreenId: |
Matt Briggs | 75:600cb3a9f126 | 68 | case errorLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 69 | case liveLogScreenId: |
Matt Briggs | 75:600cb3a9f126 | 70 | case enterSerialBridgeScreenId: |
Matt Briggs | 76:d1b20a259d8f | 71 | inputMainPage(c); |
Matt Briggs | 76:d1b20a259d8f | 72 | break; |
Matt Briggs | 75:600cb3a9f126 | 73 | case enterProgModeScreenId: |
Matt Briggs | 76:d1b20a259d8f | 74 | inputEnterProgMode(c); |
Matt Briggs | 75:600cb3a9f126 | 75 | } |
Matt Briggs | 75:600cb3a9f126 | 76 | return quit; |
Matt Briggs | 75:600cb3a9f126 | 77 | } |
Matt Briggs | 75:600cb3a9f126 | 78 | |
Matt Briggs | 75:600cb3a9f126 | 79 | // private methods |
Matt Briggs | 75:600cb3a9f126 | 80 | bool SerialTermMgr::inputMainPage (char in) { |
Matt Briggs | 75:600cb3a9f126 | 81 | bool quit = false; |
Matt Briggs | 75:600cb3a9f126 | 82 | switch (in) { |
Matt Briggs | 75:600cb3a9f126 | 83 | case '1': |
Matt Briggs | 75:600cb3a9f126 | 84 | mCurrScreen = genInfoScreenId; |
Matt Briggs | 75:600cb3a9f126 | 85 | break; |
Matt Briggs | 75:600cb3a9f126 | 86 | case '2': |
Matt Briggs | 75:600cb3a9f126 | 87 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 88 | // mCurrScreen = settingsScreenId; |
Matt Briggs | 75:600cb3a9f126 | 89 | break; |
Matt Briggs | 75:600cb3a9f126 | 90 | case '3': |
Matt Briggs | 75:600cb3a9f126 | 91 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 92 | // mCurrScreen = statsScreenId; |
Matt Briggs | 75:600cb3a9f126 | 93 | break; |
Matt Briggs | 75:600cb3a9f126 | 94 | case '4': |
Matt Briggs | 75:600cb3a9f126 | 95 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 96 | // mCurrScreen = errorLogScreenId; |
Matt Briggs | 75:600cb3a9f126 | 97 | break; |
Matt Briggs | 75:600cb3a9f126 | 98 | case '5': |
Matt Briggs | 75:600cb3a9f126 | 99 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 100 | // mCurrScreen = liveLogScreenId; |
Matt Briggs | 75:600cb3a9f126 | 101 | break; |
Matt Briggs | 75:600cb3a9f126 | 102 | case '6': |
Matt Briggs | 75:600cb3a9f126 | 103 | mPc->printf("\r\nNot implemented yet.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 104 | // mCurrScreen = enterSerialBridgeScreenId; |
Matt Briggs | 75:600cb3a9f126 | 105 | break; |
Matt Briggs | 75:600cb3a9f126 | 106 | case '7': |
Matt Briggs | 76:d1b20a259d8f | 107 | mCurrScreen = enterProgModeScreenId; |
Matt Briggs | 75:600cb3a9f126 | 108 | break; |
Matt Briggs | 75:600cb3a9f126 | 109 | case 0x11: // ctrl-q |
Matt Briggs | 75:600cb3a9f126 | 110 | quit=true; |
Matt Briggs | 75:600cb3a9f126 | 111 | break; |
Matt Briggs | 75:600cb3a9f126 | 112 | default: |
Matt Briggs | 75:600cb3a9f126 | 113 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 114 | } |
Matt Briggs | 75:600cb3a9f126 | 115 | if (!quit) { |
Matt Briggs | 75:600cb3a9f126 | 116 | printScreen(); |
Matt Briggs | 75:600cb3a9f126 | 117 | } |
Matt Briggs | 75:600cb3a9f126 | 118 | return quit; |
Matt Briggs | 75:600cb3a9f126 | 119 | } |
Matt Briggs | 75:600cb3a9f126 | 120 | |
Matt Briggs | 75:600cb3a9f126 | 121 | void SerialTermMgr::printMainScreen() |
Matt Briggs | 75:600cb3a9f126 | 122 | { |
Matt Briggs | 75:600cb3a9f126 | 123 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 124 | return; |
Matt Briggs | 75:600cb3a9f126 | 125 | } |
Matt Briggs | 75:600cb3a9f126 | 126 | mPc->printf("\r\n\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 127 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 128 | mPc->printf("= Wireless Bridge Terminal (Firmware: v%0.2f) =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 129 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 130 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 131 | mPc->printf("= Selection Options =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 132 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 133 | mPc->printf("= 0: Refresh (Enter and space also work) =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 134 | mPc->printf("= 1: General information =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 135 | mPc->printf("= 2: Settings =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 136 | mPc->printf("= 3: Statistics =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 137 | mPc->printf("= 4: Error log =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 138 | mPc->printf("= 5: Live log =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 139 | mPc->printf("= 6: Enter serial bridge mode =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 140 | mPc->printf("= 7: Enter programming mode =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 141 | mPc->printf("= <ctrl>-q: Exit terminal =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 142 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 143 | } |
Matt Briggs | 75:600cb3a9f126 | 144 | |
Matt Briggs | 75:600cb3a9f126 | 145 | void SerialTermMgr::inputGenInfo (char in) { |
Matt Briggs | 75:600cb3a9f126 | 146 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 147 | return; |
Matt Briggs | 75:600cb3a9f126 | 148 | } |
Matt Briggs | 75:600cb3a9f126 | 149 | switch (in) { |
Matt Briggs | 75:600cb3a9f126 | 150 | case 0x1B: |
Matt Briggs | 75:600cb3a9f126 | 151 | mCurrScreen = mainScreenId; |
Matt Briggs | 75:600cb3a9f126 | 152 | break; |
Matt Briggs | 75:600cb3a9f126 | 153 | case 'r': |
Matt Briggs | 75:600cb3a9f126 | 154 | mBbio->sampleUserSwitches(); |
Matt Briggs | 75:600cb3a9f126 | 155 | mPc->printf("User switches sampled.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 156 | break; |
Matt Briggs | 75:600cb3a9f126 | 157 | default: |
Matt Briggs | 75:600cb3a9f126 | 158 | mPc->printf("Invalid key.\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 159 | } |
Matt Briggs | 75:600cb3a9f126 | 160 | printScreen(); |
Matt Briggs | 75:600cb3a9f126 | 161 | } |
Matt Briggs | 75:600cb3a9f126 | 162 | |
Matt Briggs | 75:600cb3a9f126 | 163 | void SerialTermMgr::printGenInfo() |
Matt Briggs | 75:600cb3a9f126 | 164 | { |
Matt Briggs | 75:600cb3a9f126 | 165 | if (mPc == NULL) { |
Matt Briggs | 75:600cb3a9f126 | 166 | return; |
Matt Briggs | 75:600cb3a9f126 | 167 | } |
Matt Briggs | 75:600cb3a9f126 | 168 | mPc->printf("\r\n\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 169 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 170 | mPc->printf("= General Info (ESC to return to main menu) =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 171 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 172 | mPc->printf("= Press r to sample user switch values =\r\n"); // FIXME |
Matt Briggs | 75:600cb3a9f126 | 173 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 174 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 175 | mPc->printf("= Firmware version: v%0.2f =\r\n", mFwVersion); |
Matt Briggs | 75:600cb3a9f126 | 176 | //TODO |
Matt Briggs | 75:600cb3a9f126 | 177 | // mPc->printf("= Radio EUI: %s =\r\n", mts::Text::bin2hexString(dot->getDeviceId()).c_str()); |
Matt Briggs | 75:600cb3a9f126 | 178 | mPc->printf("= Contact closure: %s =\r\n", mBbio->isCCNO() ? "Normally open " : |
Matt Briggs | 75:600cb3a9f126 | 179 | "Normally closed"); |
Matt Briggs | 75:600cb3a9f126 | 180 | mPc->printf("= WB Mode: %s =\r\n", mBbio->isTx() ? "Transmitter" : |
Matt Briggs | 75:600cb3a9f126 | 181 | "Receiver "); |
Matt Briggs | 75:600cb3a9f126 | 182 | mPc->printf("= Comm Mode: %s =\r\n", mBbio->isLoRaWANMode() ? "LoRaWAN " : |
Matt Briggs | 75:600cb3a9f126 | 183 | "Peer-to-peer"); |
Matt Briggs | 75:600cb3a9f126 | 184 | mPc->printf("= Serial Mode: %s =\r\n", mBbio->isSerialEnabled() ? "Enabled " : |
Matt Briggs | 75:600cb3a9f126 | 185 | "Disabled"); |
Matt Briggs | 75:600cb3a9f126 | 186 | if (mBbio->isTx()) { |
Matt Briggs | 75:600cb3a9f126 | 187 | mPc->printf("= Currently no rotary switches apply for TX =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 188 | } |
Matt Briggs | 75:600cb3a9f126 | 189 | else { |
Matt Briggs | 75:600cb3a9f126 | 190 | mPc->printf("= Rotary 1 hold setting is %0.1f seconds =\r\n", HoldTimeSetting::rotVal2Sec(mBbio->rotarySwitch1())); |
Matt Briggs | 75:600cb3a9f126 | 191 | mPc->printf("= Rotary 2 currently does not apply for RX =\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 192 | } |
Matt Briggs | 75:600cb3a9f126 | 193 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 75:600cb3a9f126 | 194 | } |
Matt Briggs | 76:d1b20a259d8f | 195 | |
Matt Briggs | 76:d1b20a259d8f | 196 | void SerialTermMgr::printEnterProgMode() |
Matt Briggs | 76:d1b20a259d8f | 197 | { |
Matt Briggs | 76:d1b20a259d8f | 198 | if (mPc == NULL) { |
Matt Briggs | 76:d1b20a259d8f | 199 | return; |
Matt Briggs | 76:d1b20a259d8f | 200 | } |
Matt Briggs | 76:d1b20a259d8f | 201 | mPc->printf("\r\n\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 202 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 203 | mPc->printf("= Serial Firmware Prog Mode (Esc to return) =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 204 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 205 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 206 | mPc->printf("= To program firmware: \r\n"); |
Matt Briggs | 76:d1b20a259d8f | 207 | mPc->printf("= 1: Have bin file ready =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 208 | mPc->printf("= 2: Hit <ctrl>-d to enter XMODEM mode =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 209 | mPc->printf("= 3: In terminal program (such as teraterm) =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 210 | mPc->printf("= select transfer via XMODEM =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 211 | mPc->printf("= 4: Programming may take up to a minute =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 212 | mPc->printf("= 5: If successful terminal will print \"Success\" =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 213 | mPc->printf("= 6: Wireless Bridge will then automatically =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 214 | mPc->printf("= reboot with new firmware. =\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 215 | mPc->printf("===============================================\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 216 | } |
Matt Briggs | 76:d1b20a259d8f | 217 | |
Matt Briggs | 76:d1b20a259d8f | 218 | void SerialTermMgr::inputEnterProgMode (char in) { |
Matt Briggs | 76:d1b20a259d8f | 219 | if (mPc == NULL) { |
Matt Briggs | 76:d1b20a259d8f | 220 | return; |
Matt Briggs | 76:d1b20a259d8f | 221 | } |
Matt Briggs | 76:d1b20a259d8f | 222 | switch (in) { |
Matt Briggs | 76:d1b20a259d8f | 223 | case 0x1B: |
Matt Briggs | 76:d1b20a259d8f | 224 | mCurrScreen = mainScreenId; |
Matt Briggs | 76:d1b20a259d8f | 225 | break; |
Matt Briggs | 76:d1b20a259d8f | 226 | case 0x04: |
Matt Briggs | 76:d1b20a259d8f | 227 | xmodem2Flash(); |
Matt Briggs | 76:d1b20a259d8f | 228 | break; |
Matt Briggs | 76:d1b20a259d8f | 229 | default: |
Matt Briggs | 76:d1b20a259d8f | 230 | mPc->printf("Invalid key.\r\n"); |
Matt Briggs | 76:d1b20a259d8f | 231 | } |
Matt Briggs | 76:d1b20a259d8f | 232 | printScreen(); |
Matt Briggs | 76:d1b20a259d8f | 233 | } |
Matt Briggs | 76:d1b20a259d8f | 234 | |
Matt Briggs | 76:d1b20a259d8f | 235 | bool SerialTermMgr::xmodem2Flash () |
Matt Briggs | 76:d1b20a259d8f | 236 | { |
Matt Briggs | 77:176e3eb8f712 | 237 | mPc->printf("Ready to receive file\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 238 | mFlash->releaseFromPowerDown(); |
Matt Briggs | 77:176e3eb8f712 | 239 | mFlash->chipErase(); |
Matt Briggs | 76:d1b20a259d8f | 240 | char packetBuf[132]; |
Matt Briggs | 77:176e3eb8f712 | 241 | uint16_t packetNum = 1; |
Matt Briggs | 77:176e3eb8f712 | 242 | uint8_t csum = 0; |
Matt Briggs | 76:d1b20a259d8f | 243 | unsigned char pktIdx = 0; |
Matt Briggs | 76:d1b20a259d8f | 244 | time_t lastValidInput = 0; |
Matt Briggs | 76:d1b20a259d8f | 245 | while (1) { |
Matt Briggs | 77:176e3eb8f712 | 246 | // Send a NAK if a packet is not received within timeout period |
Matt Briggs | 76:d1b20a259d8f | 247 | if ((time(NULL)-lastValidInput) > XMODEM_TIMEOUT){ |
Matt Briggs | 76:d1b20a259d8f | 248 | pc.printf("Total chars: %d\r\n", pktIdx); |
Matt Briggs | 76:d1b20a259d8f | 249 | pktIdx = 0; |
Matt Briggs | 77:176e3eb8f712 | 250 | mPc->printf("%c", NAK); // Send NAK |
Matt Briggs | 77:176e3eb8f712 | 251 | lastValidInput = time(NULL); |
Matt Briggs | 77:176e3eb8f712 | 252 | // TODO need to timeout of XMODEM |
Matt Briggs | 76:d1b20a259d8f | 253 | } |
Matt Briggs | 76:d1b20a259d8f | 254 | if (mPc->readable()) { |
Matt Briggs | 77:176e3eb8f712 | 255 | packetBuf[pktIdx++] = mPc->getc(); |
Matt Briggs | 77:176e3eb8f712 | 256 | if (pktIdx == 1 && packetBuf[0] == EOT) { |
Matt Briggs | 77:176e3eb8f712 | 257 | lastValidInput = time(NULL); |
Matt Briggs | 77:176e3eb8f712 | 258 | mPc->printf("%c", ACK); // Last ACK |
Matt Briggs | 77:176e3eb8f712 | 259 | wait(0.01); |
Matt Briggs | 77:176e3eb8f712 | 260 | mPc->printf("Success.\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 261 | pc.printf("Success on xmodem.\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 262 | break; |
Matt Briggs | 76:d1b20a259d8f | 263 | } |
Matt Briggs | 77:176e3eb8f712 | 264 | else if (pktIdx >= 132) { |
Matt Briggs | 77:176e3eb8f712 | 265 | lastValidInput = time(NULL); |
Matt Briggs | 77:176e3eb8f712 | 266 | csum = 0; |
Matt Briggs | 76:d1b20a259d8f | 267 | // pc.printf("Got full packet.\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 268 | // pc.printf("Header SOH: %02X, Packet #%02X, inv #%02x\r\n", packetBuf[0], packetBuf[1], packetBuf[2]); |
Matt Briggs | 77:176e3eb8f712 | 269 | for (int i=3; i<131; i++) { |
Matt Briggs | 76:d1b20a259d8f | 270 | // pc.printf("%02X", packetBuf[i]); |
Matt Briggs | 77:176e3eb8f712 | 271 | csum += packetBuf[i]; |
Matt Briggs | 77:176e3eb8f712 | 272 | } |
Matt Briggs | 77:176e3eb8f712 | 273 | pktIdx = 0; |
Matt Briggs | 77:176e3eb8f712 | 274 | // pc.printf("\r\ncsum = %d (%02X). Got %d (%02X)\r\n", csum, csum, packetBuf[131], packetBuf[131]); |
Matt Briggs | 77:176e3eb8f712 | 275 | if ((csum == packetBuf[131]) && (packetBuf[0] == SOH) && |
Matt Briggs | 77:176e3eb8f712 | 276 | (packetBuf[1] == ((uint8_t)packetNum)) && (((uint8_t)~packetBuf[2]) == ((uint8_t)packetNum))) { |
Matt Briggs | 77:176e3eb8f712 | 277 | // if (packetBuf[1] == packetNum) { |
Matt Briggs | 77:176e3eb8f712 | 278 | // pc.printf("One works.\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 279 | // } |
Matt Briggs | 77:176e3eb8f712 | 280 | // if (((uint8_t)~packetBuf[2]) == packetNum) { |
Matt Briggs | 77:176e3eb8f712 | 281 | // pc.printf("Two works.\r\n"); |
Matt Briggs | 77:176e3eb8f712 | 282 | // } |
Matt Briggs | 77:176e3eb8f712 | 283 | // pc.printf("%02X == %02X\r\n", packetNum, (uint8_t)~packetBuf[2]); |
Matt Briggs | 77:176e3eb8f712 | 284 | mFlash->writeStream(FLASH_BIN_OFFSET+packetNum*XMODEM_PACKET_SIZE, packetBuf+3, XMODEM_PACKET_SIZE); |
Matt Briggs | 77:176e3eb8f712 | 285 | mPc->printf("%c", ACK); |
Matt Briggs | 77:176e3eb8f712 | 286 | packetNum++; |
Matt Briggs | 77:176e3eb8f712 | 287 | } |
Matt Briggs | 77:176e3eb8f712 | 288 | else { |
Matt Briggs | 77:176e3eb8f712 | 289 | mPc->printf("%c", NAK); |
Matt Briggs | 77:176e3eb8f712 | 290 | } |
Matt Briggs | 77:176e3eb8f712 | 291 | } |
Matt Briggs | 76:d1b20a259d8f | 292 | } |
Matt Briggs | 76:d1b20a259d8f | 293 | } |
Matt Briggs | 77:176e3eb8f712 | 294 | mCurrScreen = mainScreenId; // Just return to main screen for now |
Matt Briggs | 77:176e3eb8f712 | 295 | mFlash->powerDown(); |
Matt Briggs | 77:176e3eb8f712 | 296 | |
Matt Briggs | 77:176e3eb8f712 | 297 | return true; |
Matt Briggs | 76:d1b20a259d8f | 298 | } |