MTDOT-BOX-EVB-Factory-Firmware
Dependencies: NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2
Diff: Mode/ModeDemo.cpp
- Revision:
- 12:05435282f899
- Parent:
- 7:a31236c2e75c
diff -r 19ce32436b9b -r 05435282f899 Mode/ModeDemo.cpp --- a/Mode/ModeDemo.cpp Thu Nov 10 22:10:58 2016 +0000 +++ b/Mode/ModeDemo.cpp Tue Oct 09 13:49:30 2018 -0500 @@ -18,7 +18,6 @@ #include "ModeDemo.h" #include "MTSLog.h" - // 10 s, 30 s, 1 min, 5 min, 10 min, 15 min, 30 min 1 hour const uint32_t ModeDemo::_intervals[] = { 10, 30, 60, 5 * 60, 10 * 60, 15 * 60, 30 * 60 }; @@ -39,16 +38,12 @@ osSignalClear(_main_id, buttonSignal | loraSignal); _initial_data_rate = _dot->getTxDataRate(); - - // use configured data rate and power if possible - if ((_band == mDot::FB_US915 || _band == mDot::FB_AU915) && (_initial_data_rate == mDot::DR0 || _initial_data_rate == mDot::SF_10)) { - if(_initial_data_rate == mDot::DR0){ - logInfo("using DR1 instead of DR0 - DR0 max packet size is too small for data"); - _dot->setTxDataRate(mDot::DR1); - }else{ - logInfo("using SF_9 instead of SF_10 - SF_10 max packet size is too small for data"); - _dot->setTxDataRate(mDot::SF_9); - } + std::vector<uint8_t> s_data = formatSensorData(_data); + for(int i = 0; i < _dot->getMaxDatarate(); i++) { + _dot->setTxDataRate(i); + if(s_data.size() < _dot->getMaxPacketLength()) { + i = _dot->getMaxDatarate(); + } } _state = show_help; @@ -108,7 +103,7 @@ case ButtonHandler::sw1_hold: _send_timer.stop(); _send_timer.reset(); - if (_band == mDot::FB_US915 || _band == mDot::FB_AU915) { + if (lora::ChannelPlan::IsPlanFixed(_band)) { _dot->setTxDataRate(_initial_data_rate); } return true; @@ -168,7 +163,8 @@ } } if (send) { - std::vector<uint8_t> s_data = formatSensorData(_data); + s_data.clear(); + s_data = formatSensorData(_data); logInfo("sending data %s %d", _dot->DataRateStr(_dot->getTxDataRate()).c_str(), _dot->getTxPower()); _sam.updateInfo("Sending..."); _sam.updateSw1(" ");