![](/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:
- 26:9411b26a5084
- Parent:
- 25:fea776239709
- Child:
- 27:6b68ff715ae1
--- a/xDotBridge/src/main.cpp Tue Jan 03 16:07:16 2017 -0700 +++ b/xDotBridge/src/main.cpp Wed Jan 04 11:20:07 2017 -0700 @@ -1,6 +1,7 @@ #include "config.h" #include "dot_util.h" #include "RadioEvent.h" +#include <math.h> ///////////////////////////////////////////////////////////////////////////// @@ -23,6 +24,11 @@ static uint8_t network_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; static uint8_t data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; +// wireless bridge protocol +//const float dutyCycle = 0.01; // 1% +const float rxSleepTime = 2000; // ms +const uint8_t maxPayloadSize = 10; // Number of bytes (used for toa calcultion) + DigitalOut led1(LED1); mDot* dot = NULL; @@ -38,7 +44,7 @@ pc.baud(115200); - mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); + mts::MTSLog::setLogLevel(mts::MTSLog::WARNING_LEVEL); dot = mDot::getInstance(); @@ -49,7 +55,7 @@ dot->resetConfig(); // make sure library logging is turned on - dot->setLogLevel(mts::MTSLog::INFO_LEVEL); + dot->setLogLevel(mts::MTSLog::WARNING_LEVEL); // attach the custom events handler dot->setEvents(&events); @@ -95,6 +101,7 @@ unsigned int wakeMode; + /////////////////////////////// // Transmitter Configuration // /////////////////////////////// @@ -123,8 +130,13 @@ // display configuration 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); + uint16_t seqNum=0; - uint32_t cDwnLink; + uint32_t cDwnLink = dot->getDownLinkCounter(); while (true) { std::vector<uint8_t> data; led1=0; @@ -138,30 +150,39 @@ join_network(); } + logError("Time: %lu", us_ticker_read()); + led1=1; data.push_back((seqNum >> 8) & 0xFF); data.push_back(seqNum & 0xFF); logInfo("seqNum: %lu", seqNum); - send_data(data); + for(uint i=0;i<nTimesToTx;++i) { + send_data(data); + } seqNum++; - led1=1; - wait(0.5); + //wait(0.5); led1=0; + logError("Time: %lu", us_ticker_read()); dot->sleep(0, wakeMode, false); // Go to sleep until wake button #endif #if BRIDGE_RX - cDwnLink = dot->getDownLinkCounter(); logInfo("Waiting for new message current DLC: %d", cDwnLink); - while (cDwnLink >= dot->getDownLinkCounter()) { - wait(0.1); + // For Class C device type +// while (cDwnLink >= dot->getDownLinkCounter()) { +// wait(0.1); +// } + wait(timeOnAir*2.0/1000.0); // Wait twice the time on air + if (cDwnLink < dot->getDownLinkCounter()) { + led1 = 1; + cDwnLink = dot->getDownLinkCounter(); + dot->recv(data); + std::string dataStr(data.begin(), data.end()); + logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str()); + seqNum++; + wait(0.5); } - led1 = 1; - dot->recv(data); - std::string dataStr(data.begin(), data.end()); - logInfo("Got msg num: %d, payload: %s", seqNum, dataStr.c_str()); - seqNum++; - wait(0.5); - led1=0; + led1=0; + dot->sleep(2, wakeMode, false); // Go to sleep until wake button #endif }