Jason Reiss / Mbed OS Dot-AT-Firmware-XDOT

Dependencies:   MTS-Serial libxDot-mbed5

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdLbt.cpp Source File

CmdLbt.cpp

00001 #include "CmdLbt.h"
00002 
00003 CmdLbt::CmdLbt() :
00004     Command("Listen Before Talk", "AT+LBT", "Enable/Disable listen before talk (0,0: disable, time,threshold: enable)", "time(0-65535 us),threshold(-127-128 dBm) (0,0: disable, time,threshold: enable)")
00005 {
00006     _queryable = true;
00007 }
00008 
00009 uint32_t CmdLbt::action(std::vector<std::string> args)
00010 {
00011     if (args.size() == 1)
00012     {
00013         CommandTerminal::Serial()->writef("%u,%d\r\n", CommandTerminal::Dot()->getLbtTimeUs(), CommandTerminal::Dot()->getLbtThreshold());
00014     }
00015     else
00016     {
00017         uint32_t us;
00018         int32_t rssi;
00019 
00020         sscanf(args[1].c_str(), "%lu", &us);
00021         sscanf(args[2].c_str(), "%ld", &rssi);
00022 
00023         CommandTerminal::Dot()->setLbtTimeUs((uint16_t)us);
00024         CommandTerminal::Dot()->setLbtThreshold((int8_t)rssi);
00025     }
00026 
00027     return 0;
00028 }
00029 
00030 bool CmdLbt::verify(std::vector<std::string> args)
00031 {
00032     if (args.size() == 1)
00033         return true;
00034 
00035     if (args.size() == 3) {
00036         uint32_t us;
00037         int32_t rssi;
00038 
00039         if (args[1].find("-") != std::string::npos || sscanf(args[1].c_str(), "%lu", &us) != 1 || us > 65535) {
00040             CommandTerminal::setErrorMessage("Invalid LBT time, expects 0-65535 us");
00041             return false;
00042         }
00043 
00044         if (sscanf(args[2].c_str(), "%ld", &rssi) != 1 || rssi < -127 || rssi > 128) {
00045             CommandTerminal::setErrorMessage("Invalid LBT threshold, expects -127-128 dBm");
00046             return false;
00047         }
00048 
00049         return true;
00050     }
00051 
00052     CommandTerminal::setErrorMessage("Invalid arguments");
00053     return false;
00054 }