![](/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
Diff: xDotBridge/src/SerialTermMgr.cpp
- Revision:
- 76:d1b20a259d8f
- Parent:
- 75:600cb3a9f126
- Child:
- 77:176e3eb8f712
--- a/xDotBridge/src/SerialTermMgr.cpp Wed May 10 13:54:25 2017 -0600 +++ b/xDotBridge/src/SerialTermMgr.cpp Tue May 16 15:15:58 2017 -0600 @@ -8,6 +8,10 @@ #include "SerialTermMgr.h" #include "UserInterface.h" +extern Serial pc; +const char ACK = 0x06; +const char NAK = 0x15; + SerialTermMgr::SerialTermMgr(BaseboardIO *bbio, float fwVersion) { mPc = NULL; @@ -29,8 +33,10 @@ case errorLogScreenId: case liveLogScreenId: case enterSerialBridgeScreenId: + printMainScreen(); + break; case enterProgModeScreenId: - printMainScreen(); + printEnterProgMode(); } } bool SerialTermMgr::input() @@ -58,8 +64,10 @@ case errorLogScreenId: case liveLogScreenId: case enterSerialBridgeScreenId: + inputMainPage(c); + break; case enterProgModeScreenId: - inputMainPage(c); + inputEnterProgMode(c); } return quit; } @@ -92,8 +100,7 @@ // mCurrScreen = enterSerialBridgeScreenId; break; case '7': - mPc->printf("\r\nNot implemented yet.\r\n"); -// mCurrScreen = enterProgModeScreenId; + mCurrScreen = enterProgModeScreenId; break; case 0x11: // ctrl-q quit=true; @@ -181,3 +188,72 @@ } mPc->printf("===============================================\r\n"); } + +void SerialTermMgr::printEnterProgMode() +{ + if (mPc == NULL) { + return; + } + mPc->printf("\r\n\r\n"); + mPc->printf("===============================================\r\n"); + mPc->printf("= Serial Firmware Prog Mode (Esc to return) =\r\n"); + mPc->printf("===============================================\r\n"); + mPc->printf("===============================================\r\n"); + mPc->printf("= To program firmware: \r\n"); + mPc->printf("= 1: Have bin file ready =\r\n"); + mPc->printf("= 2: Hit <ctrl>-d to enter XMODEM mode =\r\n"); + mPc->printf("= 3: In terminal program (such as teraterm) =\r\n"); + mPc->printf("= select transfer via XMODEM =\r\n"); + mPc->printf("= 4: Programming may take up to a minute =\r\n"); + mPc->printf("= 5: If successful terminal will print \"Success\" =\r\n"); + mPc->printf("= 6: Wireless Bridge will then automatically =\r\n"); + mPc->printf("= reboot with new firmware. =\r\n"); + mPc->printf("===============================================\r\n"); +} + +void SerialTermMgr::inputEnterProgMode (char in) { + if (mPc == NULL) { + return; + } + switch (in) { + case 0x1B: + mCurrScreen = mainScreenId; + break; + case 0x04: + xmodem2Flash(); + break; + default: + mPc->printf("Invalid key.\r\n"); + } + printScreen(); +} + +bool SerialTermMgr::xmodem2Flash () +{ + mPc->printf("Ready to receive file"); + // TODO may need to buffer input + char packetBuf[132]; + unsigned char pktIdx = 0; + time_t lastValidInput = 0; + while (1) { + if ((time(NULL)-lastValidInput) > XMODEM_TIMEOUT){ + mPc->printf("%c", 0x15); // Send NAK + lastValidInput = time(NULL); + pc.printf("Total chars: %d\r\n", pktIdx); + pktIdx = 0; + } + if (mPc->readable()) { + mPc->gets(packetBuf, 132); + pc.printf("Got full packet.\r\n"); + for (int i=0; i<132; i++) { + pc.printf("%02X", packetBuf[i]); + } +// if (pktIdx >= 132) { +// pc.printf("Got full packet.\r\n"); +// for (int i=0; i<132; i++) { +// pc.printf("%02X", packetBuf[i]); +// } +// } + } + } +}