Factory firmware for the MultiTech Dotbox (MTDOT-BOX) and EVB (MTDOT-EVB) products.

Dependencies:   NCP5623B GpsParser ISL29011 libmDot-mbed5 MTS-Serial MMA845x DOGS102 MPL3115A2

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdTxDataRate.cpp Source File

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     _usage = "7-10|DR0-DR15, Depends on Channel Plan";
00029     _queryable = true;
00030 }
00031 
00032 uint32_t CmdTxDataRate::action(std::vector<std::string> args) {
00033     if (args.size() == 1)
00034         {
00035         _serial.writef("DR%d - %s\r\n", _dot->getTxDataRate(), _dot->getDateRateDetails(_dot->getTxDataRate()).c_str());
00036     } else if (args.size() == 2) {
00037         std::string dr = mts::Text::toUpper(args[1]);
00038         int32_t code;
00039         int datarate = -1;
00040         uint8_t i;
00041 
00042         int res = sscanf(dr.c_str(), "%d", &datarate);
00043 
00044         if (res == 0) {
00045             for (i = 0; i < 24; i++) {
00046                 if (mDot::DataRateStr(i).find(dr) != std::string::npos) {
00047                     datarate = i;
00048                     break;
00049                 }
00050             }
00051         }
00052 
00053         if ((code = _dot->setTxDataRate(datarate)) != mDot::MDOT_OK) {
00054             setErrorMessage(_dot->getLastError());
00055             return 1;
00056         }
00057     }
00058 
00059     return 0;
00060 }
00061 
00062 bool CmdTxDataRate::verify(std::vector<std::string> args) {
00063     if (args.size() == 1)
00064         return true;
00065 
00066     if (args.size() == 2)
00067         return true;
00068 
00069     setErrorMessage("Invalid arguments");
00070     return false;
00071 }