Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot-dev-mbed5-deprecated
Fork of MTDOT-BOX-EVB-Factory-Firmware by
CmdTxDataRate.cpp
00001 /* Copyright (c) <2016> <MultiTech Systems>, MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00005 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00006 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00007 * furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 #include "CmdTxDataRate.h" 00019 #include "MTSText.h" 00020 #include "MTSLog.h" 00021 00022 CmdTxDataRate::CmdTxDataRate(mDot* dot, mts::MTSSerial& serial) 00023 : 00024 Command(dot, "Tx Data Rate", "AT+TXDR", "Set the Tx data rate for all channels"), 00025 _serial(serial) 00026 { 00027 _help = std::string(text()) + ": " + std::string(desc()); 00028 00029 if (_dot->getFrequencyBand() == mDot::FB_EU868) 00030 _usage = "(7-12|DR0-DR7)"; 00031 else 00032 _usage = "(7-10|DR0-DR4|DR8-DR13)"; 00033 00034 _queryable = true; 00035 } 00036 00037 uint32_t CmdTxDataRate::action(std::vector<std::string> args) { 00038 if (args.size() == 1) 00039 { 00040 if (_dot->getVerbose()) 00041 _serial.writef("Tx Data Rate: "); 00042 00043 _serial.writef("DR%d - %s\r\n", _dot->getTxDataRate(), _dot->getDateRateDetails(_dot->getTxDataRate()).c_str()); 00044 } else if (args.size() == 2) { 00045 std::string dr = mts::Text::toUpper(args[1]); 00046 int32_t code; 00047 int datarate = -1; 00048 uint8_t i; 00049 00050 int res = sscanf(dr.c_str(), "%d", &datarate); 00051 00052 if (res == 0) { 00053 for (i = 0; i < 24; i++) { 00054 if (mDot::DataRateStr(i).find(dr) != std::string::npos) { 00055 datarate = i; 00056 break; 00057 } 00058 } 00059 } else { 00060 if (datarate > 6) { 00061 // Convert SF to DR 00062 if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { 00063 datarate = 10 - datarate; 00064 } else { 00065 datarate = 12 - datarate; 00066 } 00067 } 00068 } 00069 00070 if ((code = _dot->setTxDataRate(datarate)) != mDot::MDOT_OK) { 00071 setErrorMessage(_dot->getLastError()); 00072 return 1; 00073 } 00074 } 00075 00076 return 0; 00077 } 00078 00079 bool CmdTxDataRate::verify(std::vector<std::string> args) { 00080 if (args.size() == 1) 00081 return true; 00082 00083 if (args.size() == 2) { 00084 std::string dr = mts::Text::toUpper(args[1]); 00085 00086 uint8_t i; 00087 int datarate = -1; 00088 00089 int res = sscanf(dr.c_str(), "%d", &datarate); 00090 00091 if (res == 0) { 00092 for (i = 0; i < 24; i++) { 00093 00094 if (mDot::DataRateStr(i).find(dr) != std::string::npos) { 00095 uint8_t _dr = i; 00096 00097 if (_dr > 15) { 00098 _dr = 12 + (mDot::SF_12 - _dr); 00099 00100 if (_dot->getFrequencyBand() == mDot::FB_EU868) { 00101 if (_dr == mDot::SF_7H) { 00102 _dr = mDot::DR6; 00103 } else if (_dr == mDot::SF_FSK) { 00104 _dr = mDot::DR7; 00105 } else { 00106 _dr = 12 - _dr; 00107 } 00108 } else { 00109 00110 _dr = 10 - _dr; 00111 } 00112 } 00113 00114 datarate = _dr; 00115 break; 00116 } 00117 } 00118 } else { 00119 if ((_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915) && datarate > 10) { 00120 datarate = -1; 00121 } else if (_dot->getFrequencyBand() == mDot::FB_EU868 && datarate > 12) { 00122 datarate = -1; 00123 } else if (datarate > 6) { 00124 // Convert SF to DR 00125 if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { 00126 datarate = 10 - datarate; 00127 } else { 00128 datarate = 12 - datarate; 00129 } 00130 } 00131 } 00132 00133 if (_dot->getFrequencyBand() == mDot::FB_US915 || _dot->getFrequencyBand() == mDot::FB_AU915 ) { 00134 // DR8-13 used for P2P modes 00135 if (datarate < 0 || datarate > 13 || (datarate >= 5 && datarate <= 7)) { 00136 setErrorMessage("Invalid data rate, expects (7-10|DR0-DR4|DR8-DR13)"); 00137 return false; 00138 } 00139 } else { 00140 if (datarate < 0 || datarate > 7) { 00141 setErrorMessage("Invalid data rate, expects (7-12|DR0-DR7)"); 00142 return false; 00143 } 00144 } 00145 00146 return true; 00147 } 00148 00149 setErrorMessage("Invalid arguments"); 00150 return false; 00151 }
Generated on Wed Jul 13 2022 01:58:37 by
1.7.2
