Updated to libmDot 1.0.8-1
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot mbed-rtos mbed
Fork of MTDOT-BOX-EVB-Factory-Firmware by
Revision 6:ab581c4260e7, committed 2016-07-13
- Comitter:
- jreiss
- Date:
- Wed Jul 13 19:14:04 2016 +0000
- Parent:
- 5:10ea08959743
- Commit message:
- Use DR enum values instead of SF values
Changed in this revision
diff -r 10ea08959743 -r ab581c4260e7 CommandTerminal/CmdFactoryDefault.cpp --- a/CommandTerminal/CmdFactoryDefault.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/CommandTerminal/CmdFactoryDefault.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -29,7 +29,7 @@ _dot->resetConfig(); //Factory defaults for the DotBox. - _dot->setTxDataRate(mDot::SF_7); + _dot->setTxDataRate(mDot::DR0); _dot->setFrequencySubBand(1); _dot->setWakeDelay(242); //DotBox +MaxSize is stored here. Default is 242. _dot->setWakeInterval(11); //DotBox +MinSize is stored here. Default is 11.
diff -r 10ea08959743 -r ab581c4260e7 CommandTerminal/CmdTxDataRate.cpp --- a/CommandTerminal/CmdTxDataRate.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/CommandTerminal/CmdTxDataRate.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -15,49 +15,59 @@ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - #include "CmdTxDataRate.h" +#include "MTSText.h" +#include "MTSLog.h" -CmdTxDataRate::CmdTxDataRate(mDot* dot, mts::MTSSerial& serial) : - Command(dot, "Tx Data Rate", "AT+TXDR", "Set the Tx data rate for LoRa demo mode"), _serial(serial) +CmdTxDataRate::CmdTxDataRate(mDot* dot, mts::MTSSerial& serial) +: + Command(dot, "Tx Data Rate", "AT+TXDR", "Set the Tx data rate for all channels"), + _serial(serial) { _help = std::string(text()) + ": " + std::string(desc()); if (_dot->getFrequencyBand() == mDot::FB_915) - _usage = "(7-10)"; + _usage = "(7-10|DR0-DR4|DR8-DR13)"; else - _usage = "(7-12)"; + _usage = "(7-12|DR0-DR7)"; _queryable = true; } -uint32_t CmdTxDataRate::action(std::vector<std::string> args) -{ +uint32_t CmdTxDataRate::action(std::vector<std::string> args) { if (args.size() == 1) - { + { if (_dot->getVerbose()) _serial.writef("Tx Data Rate: "); - _serial.writef("%s\r\n", mDot::DataRateStr(_dot->getTxDataRate()).c_str()); - } - else if (args.size() == 2) - { + _serial.writef("DR%d - %s\r\n", _dot->getTxDataRate(), _dot->getDateRateDetails(_dot->getTxDataRate()).c_str()); + } else if (args.size() == 2) { + std::string dr = mts::Text::toUpper(args[1]); int32_t code; - uint8_t datarate = 0; + int datarate = -1; uint8_t i; - for (i = 0; i < 8; i++) - { - if (mDot::DataRateStr(i).find(args[1].c_str()) != std::string::npos) - { - datarate = i; - break; + int res = sscanf(dr.c_str(), "%d", &datarate); + + if (res == 0) { + for (i = 0; i < 24; i++) { + if (mDot::DataRateStr(i).find(dr) != std::string::npos) { + datarate = i; + break; + } + } + } else { + if (datarate > 6) { + // Convert SF to DR + if (_dot->getFrequencyBand() == mDot::FB_915) { + datarate = 10 - datarate; + } else { + datarate = 12 - datarate; + } } } - if ((code = _dot->setTxDataRate(datarate)) != mDot::MDOT_OK) - { - std::string error = mDot::getReturnCodeString(code) + " - " + _dot->getLastError(); - setErrorMessage(error); + if ((code = _dot->setTxDataRate(datarate)) != mDot::MDOT_OK) { + setErrorMessage(_dot->getLastError()); return 1; } } @@ -65,36 +75,69 @@ return 0; } -bool CmdTxDataRate::verify(std::vector<std::string> args) -{ +bool CmdTxDataRate::verify(std::vector<std::string> args) { if (args.size() == 1) return true; - if (args.size() == 2) - { + if (args.size() == 2) { + std::string dr = mts::Text::toUpper(args[1]); + uint8_t i; int datarate = -1; - for (i = 0; i < 8; i++) - { - if (mDot::DataRateStr(i).find(args[1].c_str()) != std::string::npos) - { - datarate = i; - break; + + int res = sscanf(dr.c_str(), "%d", &datarate); + + if (res == 0) { + for (i = 0; i < 24; i++) { + + if (mDot::DataRateStr(i).find(dr) != std::string::npos) { + uint8_t _dr = i; + + if (_dr > 15) { + _dr = 12 + (mDot::SF_12 - _dr); + + if (_dot->getFrequencyBand() == mDot::FB_868) { + if (_dr == mDot::SF_7H) { + _dr = mDot::DR6; + } else if (_dr == mDot::SF_FSK) { + _dr = mDot::DR7; + } else { + _dr = 12 - _dr; + } + } else { + + _dr = 10 - _dr; + } + } + + datarate = _dr; + break; + } + } + } else { + if (_dot->getFrequencyBand() == mDot::FB_915 && datarate > 10) { + datarate = -1; + } else if (_dot->getFrequencyBand() == mDot::FB_868 && datarate > 12) { + datarate = -1; + } else if (datarate > 6) { + // Convert SF to DR + if (_dot->getFrequencyBand() == mDot::FB_915) { + datarate = 10 - datarate; + } else { + datarate = 12 - datarate; + } } } - if (datarate < 0) - { - if (_dot->getFrequencyBand() == mDot::FB_915) - setErrorMessage("Invalid data rate, expects (7-10)"); - else - setErrorMessage("Invalid data rate, expects (7-12)"); - return false; - } - if (_dot->getFrequencyBand() == mDot::FB_915) { - if (datarate < 2) { - setErrorMessage("Invalid data rate, expects (7-10)"); + // DR8-13 used for P2P modes + if (datarate < 0 || datarate > 13 || (datarate >= 5 && datarate <= 7)) { + setErrorMessage("Invalid data rate, expects (7-10|DR0-DR4|DR8-DR13)"); + return false; + } + } else { + if (datarate < 0 || datarate > 7) { + setErrorMessage("Invalid data rate, expects (7-12|DR0-DR7)"); return false; } }
diff -r 10ea08959743 -r ab581c4260e7 Mode/Mode.cpp --- a/Mode/Mode.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/Mode/Mode.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -49,7 +49,7 @@ _index(0), _band(_dot->getFrequencyBand()), _sub_band(_dot->getFrequencySubBand()), - _data_rate(mDot::SF_7), + _data_rate(mDot::DR0), _power(2), _next_tx(0), _send_data(false), @@ -129,7 +129,7 @@ (data.gps_lock) ? alt_buf : "", (data.gps_lock) ? time_buf : "", data.status ? stats_buf : ",,,", - _dot->DataRateStr(data.data_rate).substr(3).c_str(), + _dot->DataRateStr(data.data_rate).substr(2).c_str(), data.power); if (size < 0) {
diff -r 10ea08959743 -r ab581c4260e7 Mode/ModeDemo.cpp --- a/Mode/ModeDemo.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/Mode/ModeDemo.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -41,9 +41,9 @@ _initial_data_rate = _dot->getTxDataRate(); // use configured data rate and power if possible - if (_band == mDot::FB_915 && _initial_data_rate == mDot::SF_10) { - logInfo("using SF_9 instead of SF_10 - SF_10 max packet size is too small for data"); - _dot->setTxDataRate(mDot::SF_9); + if (_band == mDot::FB_915 && _initial_data_rate == mDot::DR0) { + logInfo("using DR1 instead of DR0 - DR0 max packet size is too small for data"); + _dot->setTxDataRate(mDot::DR1); } _state = show_help;
diff -r 10ea08959743 -r ab581c4260e7 Mode/ModeJoin.cpp --- a/Mode/ModeJoin.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/Mode/ModeJoin.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -42,7 +42,7 @@ _initial_data_rate = _dot->getTxDataRate(); _initial_power = _dot->getTxPower(); - _data_rate = (_band == mDot::FB_915) ? mDot::SF_10 : mDot::SF_12; + _data_rate = mDot::DR0; _power = 20; _joined = false; @@ -123,8 +123,7 @@ _sub_band = _dot->getFrequencySubBand(); _join.updateFsb(_sub_band); } - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _join.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _join.updateRate(_dot->DataRateStr(_data_rate).substr(2)); _join.updatePower(_power); _join.updateAttempt(_lora->getJoinAttempts()); }
diff -r 10ea08959743 -r ab581c4260e7 Mode/ModeSingle.cpp --- a/Mode/ModeSingle.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/Mode/ModeSingle.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -176,8 +176,8 @@ _state = failure; _failure.display(); _failure.updateId(_index); - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _failure.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + // mDot::DataRateStr returns format DRXX - we only want to display the XX part + _failure.updateRate(_dot->DataRateStr(_data_rate).substr(2)); updateData(_data, single, false); appendDataFile(_data); _failure.updatePower(_power); @@ -291,7 +291,7 @@ _success.display(); _success.updateId(_index); // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _success.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _success.updateRate(_dot->DataRateStr(_data_rate).substr(2)); _success.updatePower(_power); _success.updateStats(_link_check_result); if (_gps_available && _gps->getLockStatus()) { @@ -312,7 +312,7 @@ size_t size; msg += "DR="; - msg += _dot->DataRateStr(_data_rate).substr(3); + msg += _dot->DataRateStr(_data_rate).substr(2); msg += " P="; size = snprintf(buf, sizeof(buf), "%u", _power); msg.append(buf, size); @@ -323,28 +323,9 @@ void ModeSingle::incrementRatePower() { if (_power == 20) { _power = 2; - switch (_data_rate) { - case mDot::SF_7: - _data_rate = mDot::SF_8; - break; - case mDot::SF_8: - _data_rate = mDot::SF_9; - break; - case mDot::SF_9: - _data_rate = mDot::SF_10; - break; - case mDot::SF_10: - if (_band == mDot::FB_915) - _data_rate = mDot::SF_7; - else - _data_rate = mDot::SF_11; - break; - case mDot::SF_11: - _data_rate = mDot::SF_12; - break; - case mDot::SF_12: - _data_rate = mDot::SF_7; - break; + _data_rate++; + if (_band == mDot::FB_915 && _data_rate > mDot::DR4 || _band == mDot::FB_868 && _data_rate > mDot::DR7) { + _data_rate = mDot::DR0; } } else { _power += 3;
diff -r 10ea08959743 -r ab581c4260e7 Mode/ModeSweep.cpp --- a/Mode/ModeSweep.cpp Mon Jul 11 14:06:36 2016 +0000 +++ b/Mode/ModeSweep.cpp Wed Jul 13 19:14:04 2016 +0000 @@ -207,8 +207,7 @@ _state = failure; _failure.display(); _failure.updateId(_index); - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _failure.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _failure.updateRate(_dot->DataRateStr(_data_rate).substr(2)); _failure.updatePower(_power); if (_gps_available && _gps->getLockStatus()) { GPSPARSER::latitude lat = _gps->getLatitude(); @@ -343,8 +342,7 @@ void ModeSweep::displaySuccess() { _success.display(); _success.updateId(_index); - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _success.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _success.updateRate(_dot->DataRateStr(_data_rate).substr(2)); _success.updatePower(_power); _success.updateStats(_link_check_result); if (_gps_available && _gps->getLockStatus()) { @@ -383,23 +381,21 @@ uint8_t ModeSweep::payloadToRate(uint8_t payload) { if (_band == mDot::FB_915) { - if (payload <= mDot::MaxLengths_915[mDot::SF_10]) - return mDot::SF_10; - else if (payload <= mDot::MaxLengths_915[mDot::SF_9]) - return mDot::SF_9; - else if (payload <= mDot::MaxLengths_915[mDot::SF_8]) - return mDot::SF_8; + if (payload <= mDot::MaxLengths_915[mDot::DR0]) + return mDot::DR0; + else if (payload <= mDot::MaxLengths_915[mDot::DR1]) + return mDot::DR1; + else if (payload <= mDot::MaxLengths_915[mDot::DR2]) + return mDot::DR2; else - return mDot::SF_7; + return mDot::DR4; } else { - if (payload <= mDot::MaxLengths_868[mDot::SF_12]) - return mDot::SF_12; - else if (payload <= mDot::MaxLengths_868[mDot::SF_9]) - return mDot::SF_9; + if (payload <= mDot::MaxLengths_868[mDot::DR0]) + return mDot::DR0; + else if (payload <= mDot::MaxLengths_868[mDot::DR3]) + return mDot::DR3; else - return mDot::SF_7; + return mDot::DR6; } - - return mDot::SF_7; }
diff -r 10ea08959743 -r ab581c4260e7 libmDot.lib --- a/libmDot.lib Mon Jul 11 14:06:36 2016 +0000 +++ b/libmDot.lib Wed Jul 13 19:14:04 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/MultiTech/code/libmDot/#0b4eb17d07ae +http://mbed.org/teams/MultiTech/code/libmDot/#121e4c454964
diff -r 10ea08959743 -r ab581c4260e7 mbed.bld --- a/mbed.bld Mon Jul 11 14:06:36 2016 +0000 +++ b/mbed.bld Wed Jul 13 19:14:04 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file