MicroLabo / Mbed OS mbed-Dot-AT-Firmware

Dependencies:   MTS-Serial libmDot-mbed5

Fork of Dot-AT-Firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CmdReceiveOnce.cpp Source File

CmdReceiveOnce.cpp

00001 #include "CmdReceiveOnce.h"
00002 #include "CommandTerminal.h"
00003 
00004 CmdReceiveOnce::CmdReceiveOnce() : Command("Receive Once", "AT+RECV", "Receive and display one packet.", "(string:242) or (hex:242)")
00005     
00006 {
00007 }
00008 
00009 uint32_t CmdReceiveOnce::action(std::vector<std::string> args)
00010 {
00011     std::vector<uint8_t> data;
00012 
00013     if (CommandTerminal::Dot()->recv(data) == mDot::MDOT_OK) {
00014         if (!data.empty()) {
00015             if (CommandTerminal::Dot()->getRxOutput() == mDot::HEXADECIMAL) {
00016                 for (size_t i = 0; i < data.size(); i++) {
00017                     CommandTerminal::Serial()->writef("%02x", data[i]);
00018                 }
00019                 CommandTerminal::Serial()->writef("\r\n");
00020             } else {
00021                 CommandTerminal::Serial()->writef("%s\r\n", CommandTerminal::formatPacketData(data, CommandTerminal::Dot()->getRxOutput()).c_str());
00022             }
00023         }
00024     }
00025 
00026     return 0;
00027 }
00028 
00029 bool CmdReceiveOnce::verify(std::vector<std::string> args)
00030 {
00031     if (args.size() == 1)
00032         return true;
00033 
00034     CommandTerminal::setErrorMessage("Invalid arguments");
00035     return false;
00036 }