![](/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/main.cpp
- Revision:
- 27:6b68ff715ae1
- Parent:
- 26:9411b26a5084
- Child:
- 28:b14b2926e916
--- a/xDotBridge/src/main.cpp Wed Jan 04 11:20:07 2017 -0700 +++ b/xDotBridge/src/main.cpp Wed Jan 04 17:05:32 2017 -0700 @@ -26,7 +26,7 @@ // wireless bridge protocol //const float dutyCycle = 0.01; // 1% -const float rxSleepTime = 2000; // ms +const float rxSleepTime = 2000; // ms (one second resolution, min 2 seconds) const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion) DigitalOut led1(LED1); @@ -34,6 +34,33 @@ Serial pc(USBTX, USBRX); +//Ticker t; +// +//class RxHandler { +// private: +// uint m_dwnLink; +// mDot *m_dot; +// public: +// RxHandler (mDot *dot) { +// m_dot = dot; +// m_dwnLink = dot->getDownLinkCounter(); +// } +// void listen() { +// std::vector<uint8_t> data; +// led1 = 1; // FIXME +// logInfo("Listening for new message current DLC: %d, time: %lu", m_dwnLink, us_ticker_read()); +// wait(0.060); // Wait twice the time on air +// if (m_dwnLink < dot->getDownLinkCounter()) { +// m_dwnLink = dot->getDownLinkCounter(); +// m_dot->recv(data); +// std::string dataStr(data.begin(), data.end()); +// logInfo("Got msg num: -, payload: %s", dataStr.c_str()); +// wait(0.5); +// } +// led1=0; +// } +//}; + int main() { // Custom event handler for automatically displaying RX data RadioEvent events; @@ -44,7 +71,7 @@ pc.baud(115200); - mts::MTSLog::setLogLevel(mts::MTSLog::WARNING_LEVEL); + mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); dot = mDot::getInstance(); @@ -55,7 +82,7 @@ dot->resetConfig(); // make sure library logging is turned on - dot->setLogLevel(mts::MTSLog::WARNING_LEVEL); + dot->setLogLevel(mts::MTSLog::INFO_LEVEL); // attach the custom events handler dot->setEvents(&events); @@ -105,14 +132,14 @@ /////////////////////////////// // Transmitter Configuration // /////////////////////////////// - #if BRIDGE_TX + #if BRIDGE_TX_BRUTE wakeMode = mDot::INTERRUPT; #endif //////////////////////////// // Receiver Configuration // //////////////////////////// - #if BRIDGE_RX + #if BRIDGE_RX_BRUTE wakeMode = mDot::RTC_ALARM_OR_INTERRUPT; #endif @@ -131,47 +158,47 @@ display_config(); - uint32_t timeOnAir = dot->getTimeOnAir(maxPayloadSize); - unsigned int nTimesToTx = ceil(rxSleepTime / ((float)timeOnAir)); - logInfo("rxSleepTime %f, timeOnAir %f, nTimesToTx %d", rxSleepTime, (float) timeOnAir, nTimesToTx); + uint32_t txTime = 30; // in ms + unsigned int nTimesToTx = ceil(rxSleepTime / ((float)txTime)); + logInfo("rxSleepTime %f, timeOnAir %lu, nTimesToTx %lu", rxSleepTime, txTime, nTimesToTx); uint16_t seqNum=0; uint32_t cDwnLink = dot->getDownLinkCounter(); while (true) { std::vector<uint8_t> data; led1=0; - /////////////////////////// - // Transmitter main loop // - /////////////////////////// - #if BRIDGE_TX // join network if not joined if (!dot->getNetworkJoinStatus()) { join_network(); } - logError("Time: %lu", us_ticker_read()); + ////////////////////////////////////////// + // Brute Protocol Transmitter main loop // + ////////////////////////////////////////// + #if BRIDGE_TX_BRUTE led1=1; data.push_back((seqNum >> 8) & 0xFF); data.push_back(seqNum & 0xFF); - logInfo("seqNum: %lu", seqNum); + logInfo("Starting TX. Time: %lu, seqNum: %lu", us_ticker_read(), seqNum); for(uint i=0;i<nTimesToTx;++i) { - send_data(data); + dot->send(data); } seqNum++; - //wait(0.5); led1=0; - logError("Time: %lu", us_ticker_read()); + logInfo("Finished TX. Time: %lu", us_ticker_read()); + // TODO add GPIO low power stuff here dot->sleep(0, wakeMode, false); // Go to sleep until wake button #endif - #if BRIDGE_RX - logInfo("Waiting for new message current DLC: %d", cDwnLink); - // For Class C device type -// while (cDwnLink >= dot->getDownLinkCounter()) { -// wait(0.1); -// } - wait(timeOnAir*2.0/1000.0); // Wait twice the time on air + + /////////////////////////////////////// + // Brute Protocol Receiver main loop // + /////////////////////////////////////// + + #if BRIDGE_RX_BRUTE + logInfo("Waiting for new message current DLC: %d, Time %d", cDwnLink, us_ticker_read()); + wait(txTime*2.0/1000.0); // Wait twice the txTime if (cDwnLink < dot->getDownLinkCounter()) { led1 = 1; cDwnLink = dot->getDownLinkCounter(); @@ -182,11 +209,20 @@ wait(0.5); } led1=0; + logInfo("Sleeping. Time %d", us_ticker_read()); dot->sleep(2, wakeMode, false); // Go to sleep until wake button - #endif +// // Idea to Setup Ticker +// RxHandler rxHandler(dot); +// t.attach(&rxHandler, &RxHandler::listen, 1.5); +// wait(5.0); +// while (true) { +// dot->sleep(0, wakeMode, false); // Go to sleep until wake button +// //sleep(); +// } } return 0; } +