Fork to see if I can get working

Dependencies:   BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated

Fork of xDotBridge_update_test20180823 by Matt Briggs

Committer:
Matt Briggs
Date:
Thu Mar 09 16:47:42 2017 -0700
Revision:
61:8d9efd33cac9
Slight modification of pair code and documentation.  Also some test code to all xDot dev boards to act like bridges.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Matt Briggs 61:8d9efd33cac9 1 #include "mbed.h"
Matt Briggs 61:8d9efd33cac9 2 #include "../../config.h"
Matt Briggs 61:8d9efd33cac9 3 #include "CommProtocolPeerBrute.h"
Matt Briggs 61:8d9efd33cac9 4 //#include "BaseboardIO.h"
Matt Briggs 61:8d9efd33cac9 5 //#include "MTSLog.h"
Matt Briggs 61:8d9efd33cac9 6 #include "RadioEvent.h"
Matt Briggs 61:8d9efd33cac9 7 #include "dot_util.h"
Matt Briggs 61:8d9efd33cac9 8 #include "mDot.h"
Matt Briggs 61:8d9efd33cac9 9
Matt Briggs 61:8d9efd33cac9 10 #ifdef __TEST_XDOT_DEV_COMM__
Matt Briggs 61:8d9efd33cac9 11 Serial pc(USBTX, USBRX); // Externally defined
Matt Briggs 61:8d9efd33cac9 12 mDot* dot = NULL; // Used by dot-utils
Matt Briggs 61:8d9efd33cac9 13
Matt Briggs 61:8d9efd33cac9 14 const int VERSION = 0;
Matt Briggs 61:8d9efd33cac9 15
Matt Briggs 61:8d9efd33cac9 16 volatile bool ccInIntFlag; // Wake pin
Matt Briggs 61:8d9efd33cac9 17
Matt Briggs 61:8d9efd33cac9 18 void ccInIntCallback () {
Matt Briggs 61:8d9efd33cac9 19 ccInIntFlag = true;
Matt Briggs 61:8d9efd33cac9 20 }
Matt Briggs 61:8d9efd33cac9 21
Matt Briggs 61:8d9efd33cac9 22 InterruptIn mCCIn(WAKE);
Matt Briggs 61:8d9efd33cac9 23 DigitalOut led(GPIO0);
Matt Briggs 61:8d9efd33cac9 24 /**
Matt Briggs 61:8d9efd33cac9 25 * Checks that in idle state all the IOs are pulled up.
Matt Briggs 61:8d9efd33cac9 26 */
Matt Briggs 61:8d9efd33cac9 27 int main ()
Matt Briggs 61:8d9efd33cac9 28 {
Matt Briggs 61:8d9efd33cac9 29 CommProtocolPeerBrute *protocol = new CommProtocolPeerBrute();
Matt Briggs 61:8d9efd33cac9 30 unsigned int loopCnt = 0;
Matt Briggs 61:8d9efd33cac9 31 uint16_t txSeqNum=0;
Matt Briggs 61:8d9efd33cac9 32 uint16_t rxSeqNum=0;
Matt Briggs 61:8d9efd33cac9 33 CmdResult result;
Matt Briggs 61:8d9efd33cac9 34 std::vector<uint8_t> data;
Matt Briggs 61:8d9efd33cac9 35 pc.baud(115200);
Matt Briggs 61:8d9efd33cac9 36 RadioEvent events; // Custom event handler for automatically displaying RX data
Matt Briggs 61:8d9efd33cac9 37 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
Matt Briggs 61:8d9efd33cac9 38 dot = mDot::getInstance();
Matt Briggs 61:8d9efd33cac9 39
Matt Briggs 61:8d9efd33cac9 40 dot->setLogLevel(mts::MTSLog::INFO_LEVEL); // This actually is very important
Matt Briggs 61:8d9efd33cac9 41
Matt Briggs 61:8d9efd33cac9 42 dot->setEvents(&events); // Little bonus event debug information
Matt Briggs 61:8d9efd33cac9 43
Matt Briggs 61:8d9efd33cac9 44 protocol->init();
Matt Briggs 61:8d9efd33cac9 45 dot->setWakeMode(mDot::RTC_ALARM_OR_INTERRUPT);
Matt Briggs 61:8d9efd33cac9 46 dot->setWakePin(UART_CTS);
Matt Briggs 61:8d9efd33cac9 47
Matt Briggs 61:8d9efd33cac9 48 ccInIntFlag = false;
Matt Briggs 61:8d9efd33cac9 49
Matt Briggs 61:8d9efd33cac9 50 Callback<void()> ccInIntObj (&ccInIntCallback);
Matt Briggs 61:8d9efd33cac9 51 mCCIn.rise(ccInIntCallback);
Matt Briggs 61:8d9efd33cac9 52 mCCIn.mode(PullDown);
Matt Briggs 61:8d9efd33cac9 53 mCCIn.enable_irq();
Matt Briggs 61:8d9efd33cac9 54
Matt Briggs 61:8d9efd33cac9 55 uint8_t waitCharIdx = 0;
Matt Briggs 61:8d9efd33cac9 56
Matt Briggs 61:8d9efd33cac9 57 logInfo("Version %d. Setup complete. Starting main loop.", VERSION);
Matt Briggs 61:8d9efd33cac9 58
Matt Briggs 61:8d9efd33cac9 59 while (true) {
Matt Briggs 61:8d9efd33cac9 60 if (ccInIntFlag) { // TX
Matt Briggs 61:8d9efd33cac9 61 led = 1;
Matt Briggs 61:8d9efd33cac9 62 data.clear();
Matt Briggs 61:8d9efd33cac9 63 data.push_back((txSeqNum >> 8) & 0xFF);
Matt Briggs 61:8d9efd33cac9 64 data.push_back(txSeqNum & 0xFF);
Matt Briggs 61:8d9efd33cac9 65 std::string dataStr(data.begin(), data.end());
Matt Briggs 61:8d9efd33cac9 66 logInfo("Sent msg num: %d, payload: %s", txSeqNum, dataStr.c_str());
Matt Briggs 61:8d9efd33cac9 67 protocol->send(data);
Matt Briggs 61:8d9efd33cac9 68 txSeqNum++;
Matt Briggs 61:8d9efd33cac9 69 ccInIntFlag = false;
Matt Briggs 61:8d9efd33cac9 70 }
Matt Briggs 61:8d9efd33cac9 71 else { // RX
Matt Briggs 61:8d9efd33cac9 72 bool msgPending;
Matt Briggs 61:8d9efd33cac9 73 protocol->listen(msgPending);
Matt Briggs 61:8d9efd33cac9 74 logInfo("Loop Cnt %d. Listening.", loopCnt);
Matt Briggs 61:8d9efd33cac9 75 if (msgPending) {
Matt Briggs 61:8d9efd33cac9 76 protocol->recv(data);
Matt Briggs 61:8d9efd33cac9 77 std::string dataStr(data.begin(), data.end());
Matt Briggs 61:8d9efd33cac9 78 logInfo("Got msg num: %d, payload: %s", rxSeqNum, dataStr.c_str());
Matt Briggs 61:8d9efd33cac9 79 rxSeqNum++;
Matt Briggs 61:8d9efd33cac9 80 led = 1;
Matt Briggs 61:8d9efd33cac9 81 wait(0.5);
Matt Briggs 61:8d9efd33cac9 82 protocol->sampleDLC();
Matt Briggs 61:8d9efd33cac9 83 }
Matt Briggs 61:8d9efd33cac9 84 }
Matt Briggs 61:8d9efd33cac9 85
Matt Briggs 61:8d9efd33cac9 86 loopCnt++;
Matt Briggs 61:8d9efd33cac9 87
Matt Briggs 61:8d9efd33cac9 88 led = 0;
Matt Briggs 61:8d9efd33cac9 89 sleep_save_io();
Matt Briggs 61:8d9efd33cac9 90 sleep_configure_io();
Matt Briggs 61:8d9efd33cac9 91 dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false); // Go to sleep until wake button
Matt Briggs 61:8d9efd33cac9 92 sleep_restore_io();
Matt Briggs 61:8d9efd33cac9 93 logInfo("\r\n================================");
Matt Briggs 61:8d9efd33cac9 94 }
Matt Briggs 61:8d9efd33cac9 95 return 0;
Matt Briggs 61:8d9efd33cac9 96 }
Matt Briggs 61:8d9efd33cac9 97
Matt Briggs 61:8d9efd33cac9 98 #endif