firm newest

Dependencies:   MTS-Serial libmDot-dev-mbed5-deprecated

CommandTerminal/CmdJoinByteOrder.cpp

Committer:
nguyenhoang9x5555
Date:
2018-10-18
Revision:
0:3c869a8cb8f8

File content as of revision 0:3c869a8cb8f8:

#include "CmdJoinByteOrder.h"

CmdJoinByteOrder::CmdJoinByteOrder() :
        Command("Join Byte Order", "AT+JBO", "Send EUI's in join request with configured byte ordering (0:LSB,1:MSB)", "(0:LSB,1:MSB)")
{
    _queryable = true;
}

uint32_t CmdJoinByteOrder::action(std::vector<std::string> args)
{
    if (args.size() == 1)
    {
        CommandTerminal::Serial()->writef("%d\r\n", CommandTerminal::Dot()->getJoinByteOrder());
    }
    else if (args.size() == 2)
    {
        mDot::JoinByteOrder order = mDot::LSB;

        if (args[1] == "1")
            order = mDot::MSB;

        if (CommandTerminal::Dot()->setJoinByteOrder(order) != mDot::MDOT_OK)
        {
            CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());;
            return 1;
        }
    }

    return 0;
}

bool CmdJoinByteOrder::verify(std::vector<std::string> args)
{
    if (args.size() == 1)
        return true;

    if (args.size() == 2)
    {
        if (args[1] != "0" && args[1] != "1") {
            CommandTerminal::setErrorMessage("Invalid argument");
            return false;
        }

        return true;
    }

    CommandTerminal::setErrorMessage("Invalid arguments");
    return false;
}