From bab4a5b513641461af2ec0574275087757183912 Mon Sep 17 00:00:00 2001 From: "leire.querejeta" <leire.querejeta@tecnalia.com> Date: Thu, 10 Nov 2022 09:24:53 +0100 Subject: [PATCH] new command SendCustomCommand included --- .../include/CLASS_SerialPort.h | 2 ++ serial_port_class_api/src/CLASS_SerialPort.cpp | 18 +++++++++++++++--- serial_port_class_api/src/main.cpp | 13 ++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/serial_port_class_api/include/CLASS_SerialPort.h b/serial_port_class_api/include/CLASS_SerialPort.h index 360e9a5..1445aea 100644 --- a/serial_port_class_api/include/CLASS_SerialPort.h +++ b/serial_port_class_api/include/CLASS_SerialPort.h @@ -189,6 +189,8 @@ public: std::string ping(); std::string getHelp(); + + std::string sendCustomCommand(std::string &command); }; #endif \ No newline at end of file diff --git a/serial_port_class_api/src/CLASS_SerialPort.cpp b/serial_port_class_api/src/CLASS_SerialPort.cpp index 4eba738..471f824 100644 --- a/serial_port_class_api/src/CLASS_SerialPort.cpp +++ b/serial_port_class_api/src/CLASS_SerialPort.cpp @@ -168,9 +168,9 @@ std::string CLASS_SerialPort::communication(const char *buffer, std::string auxC std::string result; - std::string buf("[" + auxControl + "] "); - buf.append(buffer); - buffer = buf.c_str(); + //std::string buf("[" + auxControl + "] "); + //buf.append(buffer); + //buffer = buf.c_str(); bool ret = write(buffer); if(!ret) @@ -1526,4 +1526,16 @@ std::string CLASS_SerialPort::getHelp() std::string msg = commands::ClassCommands::CMD_HELP; std::string result = communication(msg.c_str()); return result; +} + +/** + * @brief sends custom command to class + * + * @param command custom command string to send to class device + * @return std::string answer + */ +std::string CLASS_SerialPort::sendCustomCommand(std::string &command) +{ + std::string result = communication(command.c_str()); + return result; } \ No newline at end of file diff --git a/serial_port_class_api/src/main.cpp b/serial_port_class_api/src/main.cpp index ad1f26b..3177885 100644 --- a/serial_port_class_api/src/main.cpp +++ b/serial_port_class_api/src/main.cpp @@ -20,19 +20,23 @@ using namespace std; int main(void) { std::string port; - port = "COM3"; // name of port assigned to class bluetooth device + port = "COM4"; // name of port assigned to class bluetooth device CLASS_SerialPort serial; bool port_status = serial.SetOpenPort(port); cout << "Port Status :"; cout << port_status <<endl; - + if(port_status == 1) { //start communication command depending on device --> startFESCommunication() ; startTACTILITYCommunication() ; startCommunication(std::string &prototipeName) std::string start_communication = serial.startFESCommunication(); cout << "start_communication : " + start_communication << endl; + std::string customcommand = "ping\r\n"; + std::string custom = serial.sendCustomCommand(customcommand); + cout << "custom : " << custom << endl; + std::string setStimulationOn = serial.setStimulationOn(); cout << "setStimulationOn : " << setStimulationOn << endl; @@ -301,13 +305,16 @@ int main(void) //std::string setRTCTime = serial.setRTCTime(time); //cout << "setRTCTime : " << setRTCTime << endl; - std::string ping = serial.ping(); cout << "ping : " + ping << endl; std::string help = serial.getHelp(); cout << "Help : " + help << endl; + std::string customcommand = "ping\r\n"; + std::string custom = serial.sendCustomCommand(customcommand); + cout << "custom : " << custom << endl; + std::string shutDown = serial.shutDown(); cout << "shutDown : " << shutDown << endl; -- GitLab