2018-12-19 09:15:42 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 dimercur
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "commonitor.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
#include "base64/base64.h"
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
/*
|
|
|
|
* @brief Constants used for sending commands to monitor
|
|
|
|
*/
|
|
|
|
const string LABEL_MONITOR_ANSWER_ACK = "AACK";
|
|
|
|
const string LABEL_MONITOR_ANSWER_NACK = "ANAK";
|
2018-12-21 16:36:52 +01:00
|
|
|
const string LABEL_MONITOR_ANSWER_COM_ERROR = "ACER";
|
|
|
|
const string LABEL_MONITOR_ANSWER_TIMEOUT = "ATIM";
|
|
|
|
const string LABEL_MONITOR_ANSWER_CMD_REJECTED = "ACRJ";
|
2018-12-19 09:15:42 +01:00
|
|
|
const string LABEL_MONITOR_MESSAGE = "MSSG";
|
2018-12-21 16:36:52 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_OPEN = "COPN";
|
|
|
|
const string LABEL_MONITOR_CAMERA_CLOSE = "CCLS";
|
2018-12-19 09:15:42 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_IMAGE = "CIMG";
|
|
|
|
const string LABEL_MONITOR_CAMERA_ARENA_ASK = "CASA";
|
2019-01-04 16:55:48 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_ARENA_INFIRM = "CAIN";
|
2018-12-19 09:15:42 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_ARENA_CONFIRM = "CACO";
|
2018-12-21 16:36:52 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_POSITION_COMPUTE = "CPCO";
|
|
|
|
const string LABEL_MONITOR_CAMERA_POSITION_STOP = "CPST";
|
2018-12-19 09:15:42 +01:00
|
|
|
const string LABEL_MONITOR_CAMERA_POSITION = "CPOS";
|
|
|
|
const string LABEL_MONITOR_ROBOT_COM_OPEN = "ROPN";
|
|
|
|
const string LABEL_MONITOR_ROBOT_COM_CLOSE = "RCLS";
|
|
|
|
const string LABEL_MONITOR_ROBOT_PING = "RPIN";
|
|
|
|
const string LABEL_MONITOR_ROBOT_RESET = "RRST";
|
2018-12-21 16:36:52 +01:00
|
|
|
const string LABEL_MONITOR_ROBOT_START_WITHOUT_WD = "RSOW";
|
|
|
|
const string LABEL_MONITOR_ROBOT_START_WITH_WD = "RSWW";
|
2018-12-19 09:15:42 +01:00
|
|
|
const string LABEL_MONITOR_ROBOT_RELOAD_WD = "RLDW";
|
|
|
|
const string LABEL_MONITOR_ROBOT_MOVE = "RMOV";
|
|
|
|
const string LABEL_MONITOR_ROBOT_TURN = "RTRN";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GO_FORWARD = "RGFW";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GO_BACKWARD = "RGBW";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GO_LEFT = "RGLF";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GO_RIGHT = "RGRI";
|
|
|
|
const string LABEL_MONITOR_ROBOT_STOP = "RSTP";
|
|
|
|
const string LABEL_MONITOR_ROBOT_POWEROFF = "RPOF";
|
|
|
|
const string LABEL_MONITOR_ROBOT_BATTERY_LEVEL = "RBLV";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GET_BATTERY = "RGBT";
|
|
|
|
const string LABEL_MONITOR_ROBOT_GET_STATE = "RGST";
|
|
|
|
const string LABEL_MONITOR_ROBOT_CURRENT_STATE = "RCST";
|
|
|
|
|
|
|
|
const string LABEL_SEPARATOR_CHAR = ":";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a server and open a socket over TCP
|
|
|
|
*
|
|
|
|
* @param port Port used for communication
|
|
|
|
* @return Socket number
|
|
|
|
* @throw std::runtime_error if it fails
|
|
|
|
*/
|
|
|
|
int ComMonitor::Open(int port) {
|
|
|
|
struct sockaddr_in server;
|
|
|
|
|
|
|
|
socketFD = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (socketFD < 0) {
|
2018-12-21 16:36:52 +01:00
|
|
|
throw std::runtime_error{"Can not create socket"};
|
2018-12-19 09:15:42 +01:00
|
|
|
}
|
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
int enable = 1;
|
|
|
|
if (setsockopt(socketFD, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
|
|
|
|
cerr<<"setsockopt(SO_REUSEADDR) failed"<<endl<<flush;
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero((char *) &server, sizeof(server));
|
2018-12-19 09:15:42 +01:00
|
|
|
server.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
server.sin_family = AF_INET;
|
|
|
|
server.sin_port = htons(port);
|
|
|
|
|
|
|
|
if (bind(socketFD, (struct sockaddr *) &server, sizeof (server)) < 0) {
|
2018-12-21 16:36:52 +01:00
|
|
|
cerr<<"["<<__PRETTY_FUNCTION__<<"] Can not bind socket ("<<to_string(port)<<")"<<endl<<flush;
|
|
|
|
throw std::runtime_error{"Can not bind socket"};
|
2018-12-19 09:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
listen(socketFD, 1);
|
|
|
|
|
|
|
|
return socketFD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close socket and server
|
|
|
|
*/
|
|
|
|
void ComMonitor::Close() {
|
|
|
|
close(socketFD);
|
|
|
|
|
|
|
|
socketFD = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for a client to connect
|
|
|
|
* @return Client number
|
|
|
|
* @throw std::runtime_error if it fails
|
|
|
|
*/
|
|
|
|
int ComMonitor::AcceptClient() {
|
|
|
|
struct sockaddr_in client;
|
|
|
|
int c = sizeof (struct sockaddr_in);
|
|
|
|
|
|
|
|
clientID = accept(socketFD, (struct sockaddr *) &client, (socklen_t*) & c);
|
|
|
|
|
|
|
|
if (clientID < 0)
|
2018-12-21 16:36:52 +01:00
|
|
|
throw std::runtime_error {"Accept failed"};
|
2018-12-19 09:15:42 +01:00
|
|
|
|
|
|
|
return clientID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message to monitor
|
|
|
|
*
|
|
|
|
* @param msg Message to send to monitor
|
|
|
|
* @attention Message given in parameter will be destroyed (delete) after being sent. No need for user to delete message after that.
|
|
|
|
* @warning Write is not thread safe : check that multiple tasks can't access this method simultaneously
|
|
|
|
*/
|
2019-01-04 16:55:48 +01:00
|
|
|
void ComMonitor::Write(Message *msg) {
|
2018-12-19 09:15:42 +01:00
|
|
|
string str;
|
2019-01-04 16:55:48 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
// Call user method before Write
|
|
|
|
Write_Pre();
|
|
|
|
|
|
|
|
/* Convert message to string to send to monitor */
|
|
|
|
str = MessageToString(msg);
|
|
|
|
|
|
|
|
//cout << "Message sent to monitor: " << str->c_str() << endl;
|
|
|
|
write(clientID, str.c_str(), str.length());
|
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
if (!msg->CompareID(MESSAGE_CAM_IMAGE)) {
|
|
|
|
delete(msg);
|
|
|
|
}
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
// Call user method after write
|
|
|
|
Write_Post();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Receive a message from monitor
|
|
|
|
*
|
|
|
|
* @return Message received from monitor
|
|
|
|
* @attention Message provided is produced by the method. You must delete it when you are done using it
|
|
|
|
* @warning Read is not thread safe : check that multiple tasks can't access this method simultaneously
|
|
|
|
*/
|
|
|
|
Message *ComMonitor::Read() {
|
|
|
|
char length = 0;
|
|
|
|
string s;
|
|
|
|
char data;
|
2018-12-21 16:36:52 +01:00
|
|
|
bool endReception = false;
|
2018-12-19 09:15:42 +01:00
|
|
|
Message *msg;
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
// Call user method before read
|
|
|
|
Read_Pre();
|
|
|
|
|
|
|
|
if (clientID > 0) {
|
|
|
|
while (!endReception) {
|
|
|
|
if ((length = recv(clientID, (void*) &data, 1, MSG_WAITALL)) > 0) {
|
2019-02-08 17:06:17 +01:00
|
|
|
//cout << "length = " << to_string(length) << endl << flush;
|
2018-12-19 09:15:42 +01:00
|
|
|
if (data != '\n') {
|
2018-12-21 16:36:52 +01:00
|
|
|
s += data;
|
2018-12-19 09:15:42 +01:00
|
|
|
} else endReception = true;
|
|
|
|
}
|
2019-02-08 17:06:17 +01:00
|
|
|
else {
|
|
|
|
endReception = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//cout << "2- length = " << to_string(length) << endl << flush;
|
2018-12-19 09:15:42 +01:00
|
|
|
}
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
if (length <= 0) msg = new Message(MESSAGE_MONITOR_LOST);
|
2018-12-19 09:15:42 +01:00
|
|
|
else {
|
2018-12-21 16:36:52 +01:00
|
|
|
msg = StringToMessage(s);
|
2018-12-19 09:15:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call user method after read
|
|
|
|
Read_Post();
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method used internally to convert a message content to a string that can be sent over TCP
|
|
|
|
* @param msg Message to be converted
|
|
|
|
* @return A string, image of the message
|
|
|
|
*/
|
2019-01-04 16:55:48 +01:00
|
|
|
string ComMonitor::MessageToString(Message *msg) {
|
2018-12-19 09:15:42 +01:00
|
|
|
int id;
|
|
|
|
string str;
|
2019-01-04 16:55:48 +01:00
|
|
|
//Message *localMsg = msg;
|
2018-12-19 09:15:42 +01:00
|
|
|
Position pos;
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2019-01-04 16:55:48 +01:00
|
|
|
Img *image;
|
|
|
|
Jpg jpeg ;
|
|
|
|
string s;
|
|
|
|
|
|
|
|
id = msg->GetID();
|
2018-12-19 09:15:42 +01:00
|
|
|
|
|
|
|
switch (id) {
|
2018-12-21 16:36:52 +01:00
|
|
|
case MESSAGE_ANSWER_ACK :
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_ACK);
|
|
|
|
break;
|
|
|
|
case MESSAGE_ANSWER_NACK:
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_NACK);
|
|
|
|
break;
|
|
|
|
case MESSAGE_ANSWER_ROBOT_TIMEOUT:
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_TIMEOUT);
|
|
|
|
break;
|
|
|
|
case MESSAGE_ANSWER_ROBOT_UNKNOWN_COMMAND:
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_CMD_REJECTED);
|
2018-12-19 09:15:42 +01:00
|
|
|
break;
|
2018-12-21 16:36:52 +01:00
|
|
|
case MESSAGE_ANSWER_ROBOT_ERROR:
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_CMD_REJECTED);
|
|
|
|
break;
|
|
|
|
case MESSAGE_ANSWER_COM_ERROR:
|
|
|
|
str.append(LABEL_MONITOR_ANSWER_COM_ERROR);
|
|
|
|
break;
|
|
|
|
case MESSAGE_CAM_POSITION:
|
2019-01-04 16:55:48 +01:00
|
|
|
pos = ((MessagePosition*) msg)->GetPosition();
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
str.append(LABEL_MONITOR_CAMERA_POSITION + LABEL_SEPARATOR_CHAR + to_string(pos.robotId) + ";" +
|
|
|
|
to_string(pos.angle) + ";" + to_string(pos.center.x) + ";" + to_string(pos.center.y) + ";" +
|
|
|
|
to_string(pos.direction.x) + ";" + to_string(pos.direction.y));
|
|
|
|
break;
|
2018-12-21 16:36:52 +01:00
|
|
|
case MESSAGE_CAM_IMAGE:
|
2019-01-04 16:55:48 +01:00
|
|
|
image=((MessageImg*) msg)->GetImage();
|
|
|
|
jpeg = image->ToJpg();
|
|
|
|
|
2019-01-09 16:32:16 +01:00
|
|
|
//cout << "Jpeg size: " << to_string(jpeg.size())<<endl<<flush;
|
2019-01-04 16:55:48 +01:00
|
|
|
|
|
|
|
s = base64_encode(jpeg.data(), jpeg.size());
|
|
|
|
str.append(LABEL_MONITOR_CAMERA_IMAGE + LABEL_SEPARATOR_CHAR + s);
|
2018-12-19 09:15:42 +01:00
|
|
|
break;
|
|
|
|
case MESSAGE_ROBOT_BATTERY_LEVEL:
|
2019-01-04 16:55:48 +01:00
|
|
|
str.append(LABEL_MONITOR_ROBOT_BATTERY_LEVEL + LABEL_SEPARATOR_CHAR + to_string(((MessageBattery*) msg)->GetLevel()));
|
2018-12-21 16:36:52 +01:00
|
|
|
break;
|
|
|
|
case MESSAGE_ROBOT_STATE_BUSY:
|
|
|
|
str.append(LABEL_MONITOR_ROBOT_CURRENT_STATE + LABEL_SEPARATOR_CHAR + "1");
|
2018-12-19 09:15:42 +01:00
|
|
|
break;
|
2018-12-21 16:36:52 +01:00
|
|
|
case MESSAGE_ROBOT_STATE_NOT_BUSY:
|
|
|
|
str.append(LABEL_MONITOR_ROBOT_CURRENT_STATE + LABEL_SEPARATOR_CHAR + "0");
|
2018-12-19 09:15:42 +01:00
|
|
|
break;
|
|
|
|
case MESSAGE_LOG:
|
2019-01-04 16:55:48 +01:00
|
|
|
str.append(LABEL_MONITOR_MESSAGE + LABEL_SEPARATOR_CHAR + ((MessageString*) msg)->GetString());
|
2018-12-19 09:15:42 +01:00
|
|
|
break;
|
|
|
|
case MESSAGE_EMPTY:
|
|
|
|
str.append(""); //empty string
|
|
|
|
break;
|
|
|
|
default:
|
2019-01-04 16:55:48 +01:00
|
|
|
cerr<<"["<<__PRETTY_FUNCTION__<<"] (from ComMonitor::Write): Invalid message to send ("<<msg->ToString()<<")"<<endl<<flush;
|
2018-12-21 16:36:52 +01:00
|
|
|
throw std::runtime_error {"Invalid message to send"};
|
2018-12-19 09:15:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
str.append("\n");
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method used internally to convert a string received over TCP to a message
|
|
|
|
* @param s String containing message
|
|
|
|
* @return A message, image of the string
|
|
|
|
*/
|
|
|
|
Message *ComMonitor::StringToMessage(string &s) {
|
|
|
|
Message *msg;
|
|
|
|
size_t pos;
|
2018-12-21 16:36:52 +01:00
|
|
|
string org = s;
|
2018-12-19 09:15:42 +01:00
|
|
|
string tokenCmd;
|
|
|
|
string tokenData;
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
/* Separate command from data if string contains a ':' */
|
2018-12-21 16:36:52 +01:00
|
|
|
if ((pos = org.find(LABEL_SEPARATOR_CHAR)) != string::npos) {
|
|
|
|
tokenCmd = org.substr(0, pos);
|
|
|
|
org.erase(0, pos + 1);
|
|
|
|
tokenData = org;
|
|
|
|
} else tokenCmd = org;
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
/* Convert command to message */
|
2018-12-21 16:36:52 +01:00
|
|
|
if (tokenCmd.find(LABEL_MONITOR_ROBOT_MOVE) != string::npos) {
|
|
|
|
msg = new MessageInt(MESSAGE_ROBOT_MOVE, stoi(tokenData));
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_TURN) != string::npos) {
|
|
|
|
msg = new MessageInt(MESSAGE_ROBOT_TURN, stoi(tokenData));
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_START_WITHOUT_WD) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_START_WITHOUT_WD);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_START_WITH_WD) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_START_WITH_WD);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_RELOAD_WD) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_RELOAD_WD);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_PING) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_PING);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_RESET) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_RESET);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_ARENA_ASK) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_CAM_ASK_ARENA);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_ARENA_CONFIRM) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_CAM_ARENA_CONFIRM);
|
2019-01-04 16:55:48 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_ARENA_INFIRM) != string::npos) {
|
2018-12-21 16:36:52 +01:00
|
|
|
msg = new Message(MESSAGE_CAM_ARENA_INFIRM);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_CLOSE) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_CAM_CLOSE);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_OPEN) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_CAM_OPEN);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_POSITION_COMPUTE) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_CAM_POSITION_COMPUTE_START);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_CAMERA_POSITION_STOP) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_CAM_POSITION_COMPUTE_STOP);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_MESSAGE) != string::npos) {
|
|
|
|
msg = new MessageString(MESSAGE_LOG, tokenData);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_COM_CLOSE) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_COM_CLOSE);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_COM_OPEN) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_COM_OPEN);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GET_BATTERY) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_BATTERY_GET);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GET_STATE) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_STATE_GET);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GO_FORWARD) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_GO_FORWARD);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GO_BACKWARD) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_GO_BACKWARD);
|
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GO_LEFT) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_GO_LEFT);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_GO_RIGHT) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_GO_RIGHT);
|
2019-01-15 16:25:48 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_STOP) != string::npos) {
|
|
|
|
msg = new Message(MESSAGE_ROBOT_STOP);
|
2018-12-21 16:36:52 +01:00
|
|
|
} else if (tokenCmd.find(LABEL_MONITOR_ROBOT_POWEROFF) != string::npos) {
|
2018-12-19 09:15:42 +01:00
|
|
|
msg = new Message(MESSAGE_ROBOT_POWEROFF);
|
|
|
|
} else {
|
|
|
|
msg = new Message(MESSAGE_EMPTY);
|
|
|
|
}
|
2018-12-21 16:36:52 +01:00
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
return msg;
|
|
|
|
}
|