From 06b59abeeea6efdb600f815cc19432470475eb1e Mon Sep 17 00:00:00 2001
From: "leire.querejeta" <leire.querejeta@tecnalia.com>
Date: Mon, 17 Oct 2022 15:36:38 +0200
Subject: [PATCH] included function deactivateAllVirtualElectrodes. Included
 auxControl argument in communication function

---
 .../include/CLASS_SerialPort.h                | 19 +++---
 .../src/CLASS_SerialPort.cpp                  | 27 +++++++-
 serial_port_class_api/src/CMakeLists.txt      | 66 ++++---------------
 serial_port_class_api/src/main.cpp            |  5 +-
 4 files changed, 52 insertions(+), 65 deletions(-)

diff --git a/serial_port_class_api/include/CLASS_SerialPort.h b/serial_port_class_api/include/CLASS_SerialPort.h
index 62425f5..360e9a5 100644
--- a/serial_port_class_api/include/CLASS_SerialPort.h
+++ b/serial_port_class_api/include/CLASS_SerialPort.h
@@ -73,15 +73,15 @@ private:
 
 public:
 
-	CLASS_SerialPort();                            				  //constructor
-	~CLASS_SerialPort();                          				  //constructor
-	bool SetOpenPort(std::string &commPortName);				  //serial port settings
-	bool write(const char buffer[]);							  //write
-	void flush();												  //flush serial port read buffer
-	int flushread(char *buffer, int buffLen);                     //auxiliar function for flush serial port
-	std::string read();											  //read
-	std::string communication(const char buffer[]); 			  //write/read
-	void CloseSerialPort();										  //serial port close
+	CLASS_SerialPort();                            				 					//constructor
+	~CLASS_SerialPort();                          				  					//constructor
+	bool SetOpenPort(std::string &commPortName);				  					//serial port settings
+	bool write(const char buffer[]);							  					//write
+	void flush();												  					//flush serial port read buffer
+	int flushread(char *buffer, int buffLen);                     					//auxiliar function for flush serial port
+	std::string read();											  					//read
+	std::string communication(const char buffer[], std::string auxControl = "0"); 	//write/read
+	void CloseSerialPort();										  					//serial port close
 
 	
 	std::string setStimulationOn();
@@ -94,6 +94,7 @@ public:
 	std::string setVirtualElectrodeOld(std::string &virtualElectrodeNumber, std::string &virtualElectrodeName, std::vector<int> cathodes, std::vector<int> anodes , std::vector<double> amplitudes, std::vector<int> pulsewiths, bool selected , bool sync);
 	std::string setVirtualElectrode(std::string &virtualElectrodeNumber, std::string virtualElectrodeName = "", std::vector<int> cathodes = {0}, std::vector<int> anodes = {0}, std::vector<CathodeAmplitude> amplitudes = {{"0",0.0}}, std::vector<CathodeWidth> pulsewiths = {{"0",0}}, std::string selected = "", std::string sync = "");
 	std::string setVirtualElectrodeSelection(std::string &virtualElectrodeNumber, bool selection);
+	std::string deactivateAllVirtualElectrodes();
 
 	std::string getPattern(std::string &patternNumber);
 	std::string clearPattern(std::string &patternNumber);
diff --git a/serial_port_class_api/src/CLASS_SerialPort.cpp b/serial_port_class_api/src/CLASS_SerialPort.cpp
index 8f8c8a2..4eba738 100644
--- a/serial_port_class_api/src/CLASS_SerialPort.cpp
+++ b/serial_port_class_api/src/CLASS_SerialPort.cpp
@@ -159,13 +159,19 @@ std::string CLASS_SerialPort::read()
  * @brief writers command to CLASS device and reads the answer through serial port
  * 
  * @param buffer command to send
- * @return std::string received information
+ * @param auxControl optional send/receive control argument shown in the response with the following format "Re[auxControl] answer"
+ * @return std::string answer
  */
-std::string CLASS_SerialPort::communication(const char *buffer)
+std::string CLASS_SerialPort::communication(const char *buffer, std::string auxControl)
 {
 	flush();
 
 	std::string result;
+
+	std::string buf("[" + auxControl + "] ");
+	buf.append(buffer);
+	buffer = buf.c_str();
+
 	bool ret = write(buffer);
     if(!ret)
 	{
@@ -198,7 +204,6 @@ void CLASS_SerialPort::CloseSerialPort()
 	CloseHandle(hCom);
 }
 
-
 /**
  * @brief turns stimulation on
  * 
@@ -486,6 +491,22 @@ std::string CLASS_SerialPort::setVirtualElectrodeSelection(std::string &virtualE
 	return result;
 }
 
+/**
+ * @brief deactivates (selected = 0) all virtual electrodes
+ * 
+ * @return std::string answer
+ */
+std::string CLASS_SerialPort::deactivateAllVirtualElectrodes()
+{
+	std::string result = ERROR_NOT_VALID_VALUE;
+	for(int i = 0 ; i < MAX_ALLOWED_VIRTUAL_ELECTRODES; i++)
+	{
+		std::string virtual_electrode = std::to_string(i);
+		result = setVirtualElectrodeSelection(virtual_electrode,0);
+	}
+	return result;
+}
+
 /**
  * @brief gives information about a pattern
  * 
diff --git a/serial_port_class_api/src/CMakeLists.txt b/serial_port_class_api/src/CMakeLists.txt
index e6263a2..7d01c5e 100644
--- a/serial_port_class_api/src/CMakeLists.txt
+++ b/serial_port_class_api/src/CMakeLists.txt
@@ -1,60 +1,22 @@
-cmake_minimum_required(VERSION 3.14)
-
-project(class_api)
-
-add_subdirectory(src)
-add_subdirectory(libreria_LQL)
-
-find_package(SWIG REQUIRED)
-include(${SWIG_USE_FILE})
-
-set(NET_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/csharpwrapper")
-set(PYTHON_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/pythonwrapper")
 
-set(CMAKE_SWIG_FLAGS "")
-
-set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i PROPERTY CPLUSPLUS ON)
-
-swig_add_library(CLASS_SerialPort
-  TYPE SHARED
-  LANGUAGE csharp
-  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i
-  OUTPUT_DIR ${NET_PROJECT_DIR} 
-  OUTFILE_DIR ${NET_PROJECT_DIR} 
-  )
-swig_link_libraries(CLASS_SerialPort class_serial_port)
-
-set_target_properties(CLASS_SerialPort
-    PROPERTIES
-    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${NET_PROJECT_DIR}
-    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${NET_PROJECT_DIR}
-    LIBRARY_OUTPUT_DIRECTORY ${NET_PROJECT_DIR}
-    INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
-    )
+cmake_minimum_required(VERSION 3.14)
+project (class_serial_port VERSION 0.1.0)
 
 find_package(PythonInterp)
-find_package(PythonLibs REQUIRED)
+find_package(PythonLibs)
 
 include_directories(${PYTHON_INCLUDE_DIRS})
-include_directories(${PYTHON_INCLUDE_PATH})
-
-swig_add_library(CLASS_SerialPortPython 
-    TYPE SHARED 
-    LANGUAGE python 
-    SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i 
-    OUTPUT_DIR ${PYTHON_PROJECT_DIR} 
-    OUTFILE_DIR ${PYTHON_PROJECT_DIR})
+add_executable(class_api_exe
+               CLASS_SerialPort.cpp
+               main.cpp)
 
-swig_link_libraries(CLASS_SerialPortPython class_serial_port ${PYTHON_LIBRARIES})
-set_target_properties(CLASS_SerialPortPython 
-    PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
-    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PYTHON_PROJECT_DIR}
-    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PYTHON_PROJECT_DIR}
-    LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PROJECT_DIR})
+target_link_libraries(class_api_exe ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib)
+target_link_libraries(class_api_exe ${PYTHON_LIBRARIES})
 
+set_target_properties(class_api_exe PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
 
-option(BUILD_DOC "Build documentation" ON)
-message(STATUS "Build documentation: ${BUILD_DOC}")
-if (BUILD_DOC)
-    add_subdirectory(docs)
-endif()
\ No newline at end of file
+set(class_files_local ${CMAKE_CURRENT_SOURCE_DIR}/CLASS_SerialPort.cpp)
+add_library(class_serial_port ${class_files_local})
+set_target_properties( class_serial_port PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
+target_link_libraries(class_serial_port ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib)
+target_link_libraries(class_serial_port ${PYTHON_LIBRARIES})
diff --git a/serial_port_class_api/src/main.cpp b/serial_port_class_api/src/main.cpp
index a477975..ad1f26b 100644
--- a/serial_port_class_api/src/main.cpp
+++ b/serial_port_class_api/src/main.cpp
@@ -88,11 +88,14 @@ int main(void)
 
         std::string setVirtualElectrode = serial.setVirtualElectrode(setvirtual_electrode_number, setvirtual_electrode_name, setvirtual_electrode_cathodes, setvirtual_electrode_anodes, setvirtual_electrode_amplitudes, setvirtual_electrode_widths, setselection, setsynchronous);
         cout << "setVirtualElectrode :" + setVirtualElectrode << endl;
-
+       
         std::string selectionvirtual_electrode_number = "11";
         bool selection_setselection = 0;
         std::string setVirtualElectrodeSelection = serial.setVirtualElectrodeSelection(selectionvirtual_electrode_number, selection_setselection);
         cout << "setVirtualElectrodeSelection :" + setVirtualElectrodeSelection << endl;
+        
+        //std::string deactivateAllVirtualElectrodes = serial.deactivateAllVirtualElectrodes();
+        //cout << "deactivateAllVirtualElectrodes :" + deactivateAllVirtualElectrodes << endl;
 
         std::string pattern_number = "11";
         std::string getPattern = serial.getPattern(pattern_number);
-- 
GitLab