Fork to see if I can get working

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

Fork of xDotBridge_update_test20180823 by Matt Briggs

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers testXDotDevComm.cpp Source File

testXDotDevComm.cpp

00001 #include "mbed.h"
00002 #include "../../config.h"
00003 #include "CommProtocolPeerBrute.h"
00004 //#include "BaseboardIO.h"
00005 //#include "MTSLog.h"
00006 #include "RadioEvent.h"
00007 #include "dot_util.h"
00008 #include "mDot.h"
00009 
00010 #ifdef __TEST_XDOT_DEV_COMM__
00011 Serial pc(USBTX, USBRX); // Externally defined
00012 mDot* dot = NULL; // Used by dot-utils
00013 
00014 const int VERSION = 0;
00015 
00016 volatile bool ccInIntFlag;  // Wake pin
00017 
00018 void ccInIntCallback () {
00019     ccInIntFlag = true;
00020 }
00021 
00022 InterruptIn mCCIn(WAKE);
00023 DigitalOut led(GPIO0);
00024 /**
00025  * Checks that in idle state all the IOs are pulled up.
00026  */
00027 int main ()
00028 {
00029     CommProtocolPeerBrute *protocol = new CommProtocolPeerBrute();
00030     unsigned int loopCnt = 0;
00031     uint16_t txSeqNum=0;
00032     uint16_t rxSeqNum=0;
00033     CmdResult result;
00034     std::vector<uint8_t> data;
00035     pc.baud(115200);
00036     RadioEvent events;  // Custom event handler for automatically displaying RX data
00037     mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
00038     dot = mDot::getInstance();
00039 
00040     dot->setLogLevel(mts::MTSLog::INFO_LEVEL);  // This actually is very important
00041 
00042     dot->setEvents(&events);  // Little bonus event debug information
00043 
00044     protocol->init();
00045     dot->setWakeMode(mDot::RTC_ALARM_OR_INTERRUPT);
00046     dot->setWakePin(UART_CTS);
00047 
00048     ccInIntFlag = false;
00049 
00050     Callback<void()> ccInIntObj (&ccInIntCallback);
00051     mCCIn.rise(ccInIntCallback);
00052     mCCIn.mode(PullDown);
00053     mCCIn.enable_irq();
00054 
00055     uint8_t waitCharIdx = 0;
00056 
00057     logInfo("Version %d.  Setup complete.  Starting main loop.", VERSION);
00058 
00059     while (true) {
00060         if (ccInIntFlag) { // TX
00061             led = 1;
00062             data.clear();
00063             data.push_back((txSeqNum >> 8) & 0xFF);
00064             data.push_back(txSeqNum & 0xFF);
00065             std::string dataStr(data.begin(), data.end());
00066             logInfo("Sent msg num: %d, payload: %s", txSeqNum, dataStr.c_str());
00067             protocol->send(data);
00068             txSeqNum++;
00069             ccInIntFlag = false;
00070         }
00071         else { // RX
00072             bool msgPending;
00073             protocol->listen(msgPending);
00074             logInfo("Loop Cnt %d.  Listening.", loopCnt);
00075             if (msgPending) {
00076                 protocol->recv(data);
00077                 std::string dataStr(data.begin(), data.end());
00078                 logInfo("Got msg num: %d, payload: %s", rxSeqNum, dataStr.c_str());
00079                 rxSeqNum++;
00080                 led = 1;
00081                 wait(0.5);
00082                 protocol->sampleDLC();
00083             }
00084         }
00085 
00086         loopCnt++;
00087 
00088         led = 0;
00089         sleep_save_io();
00090         sleep_configure_io();
00091         dot->sleep(2, mDot::RTC_ALARM_OR_INTERRUPT, false);  // Go to sleep until wake button
00092         sleep_restore_io();
00093         logInfo("\r\n================================");
00094     }
00095     return 0;
00096 }
00097 
00098 #endif