mDot AT-Firmware for testing

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Committer:
Mike Fiore
Date:
Fri Nov 04 14:25:43 2016 -0500
Revision:
14:f9a77400b622
update from git revision 2.0.16

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 14:f9a77400b622 1 #include "CmdChannelMask.h"
Mike Fiore 14:f9a77400b622 2
Mike Fiore 14:f9a77400b622 3 CmdChannelMask::CmdChannelMask()
Mike Fiore 14:f9a77400b622 4 :
Mike Fiore 14:f9a77400b622 5 Command("Channel Mask", "AT+CHM", "Get/set channel mask (OFFSET:0-4,MASK:0000-FFFF)", "(OFFSET:0-4,MASK:0000-FFFF)")
Mike Fiore 14:f9a77400b622 6 {
Mike Fiore 14:f9a77400b622 7 _queryable = true;
Mike Fiore 14:f9a77400b622 8 }
Mike Fiore 14:f9a77400b622 9
Mike Fiore 14:f9a77400b622 10 uint32_t CmdChannelMask::action(std::vector<std::string> args) {
Mike Fiore 14:f9a77400b622 11
Mike Fiore 14:f9a77400b622 12 if (args.size() == 1) {
Mike Fiore 14:f9a77400b622 13 if (CommandTerminal::Dot()->getVerbose())
Mike Fiore 14:f9a77400b622 14 CommandTerminal::Serial()->writef("Channel Mask: ");
Mike Fiore 14:f9a77400b622 15
Mike Fiore 14:f9a77400b622 16 std::vector<uint16_t> mask = CommandTerminal::Dot()->getChannelMask();
Mike Fiore 14:f9a77400b622 17
Mike Fiore 14:f9a77400b622 18 for (int i = int(mask.size()) - 1; i >= 0; i--) {
Mike Fiore 14:f9a77400b622 19 CommandTerminal::Serial()->writef("%04X", mask[i]);
Mike Fiore 14:f9a77400b622 20 }
Mike Fiore 14:f9a77400b622 21
Mike Fiore 14:f9a77400b622 22 CommandTerminal::Serial()->writef("\r\n");
Mike Fiore 14:f9a77400b622 23
Mike Fiore 14:f9a77400b622 24 } else if (args.size() == 3) {
Mike Fiore 14:f9a77400b622 25 int code = 0;
Mike Fiore 14:f9a77400b622 26 int temp = 0;
Mike Fiore 14:f9a77400b622 27 int offset = 0;
Mike Fiore 14:f9a77400b622 28 uint16_t mask = 0;
Mike Fiore 14:f9a77400b622 29
Mike Fiore 14:f9a77400b622 30 sscanf(args[1].c_str(), "%d", &offset);
Mike Fiore 14:f9a77400b622 31
Mike Fiore 14:f9a77400b622 32 // Convert the ASCII hex data to binary...
Mike Fiore 14:f9a77400b622 33 sscanf(&args[2][0], "%02x", &temp);
Mike Fiore 14:f9a77400b622 34 mask = uint8_t(temp) << 8;
Mike Fiore 14:f9a77400b622 35 sscanf(&args[2][2], "%02x", &temp);
Mike Fiore 14:f9a77400b622 36 mask |= uint8_t(temp);
Mike Fiore 14:f9a77400b622 37
Mike Fiore 14:f9a77400b622 38 if ((code = CommandTerminal::Dot()->setChannelMask(offset, mask)) != mDot::MDOT_OK) {
Mike Fiore 14:f9a77400b622 39 CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());
Mike Fiore 14:f9a77400b622 40 return 1;
Mike Fiore 14:f9a77400b622 41 }
Mike Fiore 14:f9a77400b622 42 }
Mike Fiore 14:f9a77400b622 43
Mike Fiore 14:f9a77400b622 44 return 0;
Mike Fiore 14:f9a77400b622 45 }
Mike Fiore 14:f9a77400b622 46
Mike Fiore 14:f9a77400b622 47 bool CmdChannelMask::verify(std::vector<std::string> args) {
Mike Fiore 14:f9a77400b622 48 if (args.size() == 1)
Mike Fiore 14:f9a77400b622 49 return true;
Mike Fiore 14:f9a77400b622 50
Mike Fiore 14:f9a77400b622 51 if (args.size() == 3) {
Mike Fiore 14:f9a77400b622 52
Mike Fiore 14:f9a77400b622 53 int offset;
Mike Fiore 14:f9a77400b622 54 if (sscanf(args[1].c_str(), "%d", &offset) != 1) {
Mike Fiore 14:f9a77400b622 55 CommandTerminal::setErrorMessage("Invalid argument");
Mike Fiore 14:f9a77400b622 56 return false;
Mike Fiore 14:f9a77400b622 57 }
Mike Fiore 14:f9a77400b622 58
Mike Fiore 14:f9a77400b622 59 if (CommandTerminal::Dot()->getFrequencyBand() == mDot::FB_EU868) {
Mike Fiore 14:f9a77400b622 60 if (offset > 0) {
Mike Fiore 14:f9a77400b622 61 CommandTerminal::setErrorMessage("Invalid offset, expects (0)");
Mike Fiore 14:f9a77400b622 62 return false;
Mike Fiore 14:f9a77400b622 63 }
Mike Fiore 14:f9a77400b622 64 } else {
Mike Fiore 14:f9a77400b622 65 if (offset < 0 || offset > 4) {
Mike Fiore 14:f9a77400b622 66 CommandTerminal::setErrorMessage("Invalid offset, expects (0-4)");
Mike Fiore 14:f9a77400b622 67 return false;
Mike Fiore 14:f9a77400b622 68 }
Mike Fiore 14:f9a77400b622 69 }
Mike Fiore 14:f9a77400b622 70
Mike Fiore 14:f9a77400b622 71 if (!isHexString(args[2], 2)) {
Mike Fiore 14:f9a77400b622 72 CommandTerminal::setErrorMessage("Invalid mask, expect (0000-FFFF)");
Mike Fiore 14:f9a77400b622 73 return false;
Mike Fiore 14:f9a77400b622 74 }
Mike Fiore 14:f9a77400b622 75
Mike Fiore 14:f9a77400b622 76 return true;
Mike Fiore 14:f9a77400b622 77 }
Mike Fiore 14:f9a77400b622 78
Mike Fiore 14:f9a77400b622 79 CommandTerminal::setErrorMessage("Invalid arguments");
Mike Fiore 14:f9a77400b622 80 return false;
Mike Fiore 14:f9a77400b622 81 }