firm newest
Dependencies: MTS-Serial libmDot-dev-mbed5-deprecated
CommandTerminal/CmdAppPort.cpp@0:3c869a8cb8f8, 2018-10-18 (annotated)
- Committer:
- nguyenhoang9x5555
- Date:
- Thu Oct 18 04:18:48 2018 +0000
- Revision:
- 0:3c869a8cb8f8
DOT AT FIRMWARE 18102018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 1 | /* |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 2 | * CmdAppPort.cpp |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 3 | * |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 4 | * Created on: Nov 4, 2015 |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 5 | * Author: jreiss |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 6 | */ |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 7 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 8 | #include "CmdAppPort.h" |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 9 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 10 | CmdAppPort::CmdAppPort() |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 11 | : |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 12 | Command("App Port", "AT+AP", "Port used for application data (1 - 223)", "(1-223)") |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 13 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 14 | _queryable = true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 15 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 16 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 17 | CmdAppPort::~CmdAppPort() |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 18 | { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 19 | // TODO Auto-generated destructor stub |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 20 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 21 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 22 | uint32_t CmdAppPort::action(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 23 | if (args.size() == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 24 | CommandTerminal::Serial()->writef("%u\r\n", CommandTerminal::Dot()->getAppPort()); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 25 | } else if (args.size() == 2) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 26 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 27 | int appPort; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 28 | sscanf(args[1].c_str(), "%d", &appPort); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 29 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 30 | if (CommandTerminal::Dot()->setAppPort(appPort) != mDot::MDOT_OK) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 31 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 32 | CommandTerminal::setErrorMessage(CommandTerminal::Dot()->getLastError());; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 33 | return 1; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 34 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 35 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 36 | return 0; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 37 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 38 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 39 | bool CmdAppPort::verify(std::vector<std::string> args) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 40 | if (args.size() == 1) |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 41 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 42 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 43 | if (args.size() == 2) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 44 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 45 | int appPort; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 46 | if (sscanf(args[1].c_str(), "%d", &appPort) == 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 47 | if (appPort > 223 || appPort < 1) { |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 48 | CommandTerminal::setErrorMessage("Invalid app port, expects (1-223)"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 49 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 50 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 51 | return true; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 52 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 53 | } |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 54 | |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 55 | CommandTerminal::setErrorMessage("Invalid arguments"); |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 56 | return false; |
nguyenhoang9x5555 | 0:3c869a8cb8f8 | 57 | } |