diff --git a/_bin/linux/debug/fsfw-example-linux.elf b/_bin/linux/debug/fsfw-example-linux.elf index 85938ae..76e93d9 100755 Binary files a/_bin/linux/debug/fsfw-example-linux.elf and b/_bin/linux/debug/fsfw-example-linux.elf differ diff --git a/_dep/linux/debug/mission/DeviceHandler/ArduinoComIF.d b/_dep/linux/debug/mission/DeviceHandler/ArduinoComIF.d index ffcc0c9..7621707 100644 --- a/_dep/linux/debug/mission/DeviceHandler/ArduinoComIF.d +++ b/_dep/linux/debug/mission/DeviceHandler/ArduinoComIF.d @@ -36,7 +36,6 @@ _obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o: \ fsfw/tmtcservices/../ipc/../objectmanager/SystemObjectIF.h \ fsfw/tmtcservices/../ipc/../objectmanager/../returnvalues/HasReturnvaluesIF.h \ fsfw/tmtcservices/../ipc/../objectmanager/../serviceinterface/ServiceInterfaceStream.h \ - mission/DeviceHandler/ArduinoCookie.h fsfw/devicehandlers/CookieIF.h \ fsfw/serialize/SerializeAdapter.h \ fsfw/serialize/../returnvalues/HasReturnvaluesIF.h \ fsfw/serialize/EndianConverter.h fsfw/serialize/../osal/Endiness.h \ @@ -85,7 +84,8 @@ _obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o: \ fsfw/tmtcpacket/pus/../../serialize/SerializeIF.h \ fsfw/tmtcpacket/pus/../../storagemanager/StorageManagerIF.h \ fsfw/tmtcpacket/pus/../../internalError/InternalErrorReporterIF.h \ - fsfw/tmtcpacket/pus/../../ipc/MessageQueueSenderIF.h + fsfw/tmtcpacket/pus/../../ipc/MessageQueueSenderIF.h \ + mission/DeviceHandler/ArduinoCookie.h fsfw/devicehandlers/CookieIF.h mission/DeviceHandler/ArduinoComIF.h: fsfw/devicehandlers/DeviceCommunicationIF.h: fsfw/devicehandlers/CookieIF.h: @@ -125,8 +125,6 @@ fsfw/tmtcservices/../ipc/../objectmanager/frameworkObjects.h: fsfw/tmtcservices/../ipc/../objectmanager/SystemObjectIF.h: fsfw/tmtcservices/../ipc/../objectmanager/../returnvalues/HasReturnvaluesIF.h: fsfw/tmtcservices/../ipc/../objectmanager/../serviceinterface/ServiceInterfaceStream.h: -mission/DeviceHandler/ArduinoCookie.h: -fsfw/devicehandlers/CookieIF.h: fsfw/serialize/SerializeAdapter.h: fsfw/serialize/../returnvalues/HasReturnvaluesIF.h: fsfw/serialize/EndianConverter.h: @@ -179,3 +177,5 @@ fsfw/tmtcpacket/pus/../../serialize/SerializeIF.h: fsfw/tmtcpacket/pus/../../storagemanager/StorageManagerIF.h: fsfw/tmtcpacket/pus/../../internalError/InternalErrorReporterIF.h: fsfw/tmtcpacket/pus/../../ipc/MessageQueueSenderIF.h: +mission/DeviceHandler/ArduinoCookie.h: +fsfw/devicehandlers/CookieIF.h: diff --git a/_dep/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.d b/_dep/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.d index 7492139..1b21dd0 100644 --- a/_dep/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.d +++ b/_dep/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.d @@ -170,17 +170,17 @@ _obj/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.o: \ fsfw/devicehandlers/../datapool/../action/../ipc/MessageQueueIF.h \ fsfw/devicehandlers/../datapool/../events/EventReportingProxyIF.h \ fsfw/globalfunctions/PeriodicOperationDivider.h \ - fsfw/timemanager/Countdown.h bsp_linux/fsfwconfig/OBSWConfig.h \ - fsfw/datapool/DataSet.h fsfw/datapool/DataPool.h \ - fsfw/datapool/PoolEntry.h fsfw/datapool/PoolEntryIF.h \ - fsfw/datapool/../globalfunctions/Type.h fsfw/datapool/../ipc/MutexIF.h \ - fsfw/datapool/DataSetIF.h fsfw/datapool/PoolRawAccess.h \ - fsfw/datapool/PoolVariableIF.h fsfw/datapool/PoolVariable.h \ + fsfw/timemanager/Countdown.h fsfw/datapool/DataSet.h \ + fsfw/datapool/DataPool.h fsfw/datapool/PoolEntry.h \ + fsfw/datapool/PoolEntryIF.h fsfw/datapool/../globalfunctions/Type.h \ + fsfw/datapool/../ipc/MutexIF.h fsfw/datapool/DataSetIF.h \ + fsfw/datapool/PoolRawAccess.h fsfw/datapool/PoolVariableIF.h \ + fsfw/datapool/PoolVariable.h \ fsfw/datapool/../serialize/SerializeAdapter.h \ fsfw/datapool/../serviceinterface/ServiceInterfaceStream.h \ fsfw/datapool/PoolVarList.h fsfw/datapool/PoolVector.h \ fsfw/datapool/PoolVector.h bsp_linux/fsfwconfig/datapool/dataPoolInit.h \ - fsfw/datapool/DataPool.h + fsfw/datapool/DataPool.h bsp_linux/fsfwconfig/OBSWConfig.h mission/DeviceHandler/ArduinoDeviceHandler.h: fsfw/devicehandlers/DeviceHandlerBase.h: fsfw/devicehandlers/DeviceHandlerIF.h: @@ -352,7 +352,6 @@ fsfw/devicehandlers/../datapool/../action/../ipc/MessageQueueIF.h: fsfw/devicehandlers/../datapool/../events/EventReportingProxyIF.h: fsfw/globalfunctions/PeriodicOperationDivider.h: fsfw/timemanager/Countdown.h: -bsp_linux/fsfwconfig/OBSWConfig.h: fsfw/datapool/DataSet.h: fsfw/datapool/DataPool.h: fsfw/datapool/PoolEntry.h: @@ -370,3 +369,4 @@ fsfw/datapool/PoolVector.h: fsfw/datapool/PoolVector.h: bsp_linux/fsfwconfig/datapool/dataPoolInit.h: fsfw/datapool/DataPool.h: +bsp_linux/fsfwconfig/OBSWConfig.h: diff --git a/_dep/linux/debug/mission/core/GenericFactory.d b/_dep/linux/debug/mission/core/GenericFactory.d index 87fd21e..de3fe6e 100644 --- a/_dep/linux/debug/mission/core/GenericFactory.d +++ b/_dep/linux/debug/mission/core/GenericFactory.d @@ -275,8 +275,27 @@ _obj/linux/debug/mission/core/GenericFactory.o: \ fsfw/devicehandlers/../datapool/../action/../ipc/MessageQueueIF.h \ fsfw/devicehandlers/../datapool/../events/EventReportingProxyIF.h \ fsfw/globalfunctions/PeriodicOperationDivider.h \ - fsfw/timemanager/Countdown.h mission/DeviceHandler/ArduinoComIF.h \ + fsfw/timemanager/Countdown.h fsfw/datapool/DataSet.h \ + fsfw/datapool/DataPool.h fsfw/datapool/DataSetIF.h \ + fsfw/datapool/PoolRawAccess.h fsfw/datapool/PoolVariableIF.h \ + fsfw/datapool/PoolVariable.h \ + fsfw/datapool/../serialize/SerializeAdapter.h \ + fsfw/datapool/../serviceinterface/ServiceInterfaceStream.h \ + fsfw/datapool/PoolVarList.h fsfw/datapool/PoolVector.h \ + fsfw/datapool/PoolVector.h bsp_linux/fsfwconfig/datapool/dataPoolInit.h \ + mission/DeviceHandler/ArduinoComIF.h \ fsfw/devicehandlers/DeviceCommunicationIF.h \ + fsfw/serialize/SerializeAdapter.h \ + fsfw/tmtcservices/CommandingServiceBase.h \ + fsfw/tmtcpacket/pus/TmPacketStored.h fsfw/tmtcpacket/pus/TmPacketBase.h \ + fsfw/tmtcpacket/pus/../SpacePacketBase.h \ + fsfw/tmtcpacket/pus/../../timemanager/TimeStamperIF.h \ + fsfw/tmtcpacket/pus/../../timemanager/Clock.h \ + fsfw/tmtcpacket/pus/../../objectmanager/SystemObjectIF.h \ + fsfw/tmtcpacket/pus/../../serialize/SerializeIF.h \ + fsfw/tmtcpacket/pus/../../storagemanager/StorageManagerIF.h \ + fsfw/tmtcpacket/pus/../../internalError/InternalErrorReporterIF.h \ + fsfw/tmtcpacket/pus/../../ipc/MessageQueueSenderIF.h \ mission/DeviceHandler/ArduinoCookie.h \ mission/Controller/ThermalController.h fsfw/action/HasActionsIF.h \ fsfw/action/SimpleActionHelper.h fsfw/events/EventReportingProxyIF.h \ @@ -289,14 +308,7 @@ _obj/linux/debug/mission/core/GenericFactory.o: \ fsfw/controller/../tasks/ExecutableObjectIF.h \ fsfw/controller/../datapool/HkSwitchHelper.h \ fsfw/datapool/ControllerSet.h fsfw/datapool/DataSet.h \ - fsfw/datapool/DataPool.h fsfw/datapool/DataSetIF.h \ - fsfw/datapool/PoolRawAccess.h fsfw/datapool/PoolVariableIF.h \ - fsfw/datapool/PoolVariable.h \ - fsfw/datapool/../serialize/SerializeAdapter.h \ - fsfw/datapool/../serviceinterface/ServiceInterfaceStream.h \ - fsfw/datapool/PoolVarList.h fsfw/datapool/PoolVector.h \ - fsfw/datapool/DataSet.h fsfw/datapool/PoolVariable.h \ - fsfw/datapool/PoolVector.h fsfw/health/HealthTableIF.h \ + fsfw/datapool/PoolVariable.h fsfw/health/HealthTableIF.h \ fsfw/returnvalues/HasReturnvaluesIF.h \ mission/Controller/ArduinoTCSTemperatureSensor.h \ fsfw/thermal/AbstractTemperatureSensor.h \ @@ -359,8 +371,7 @@ _obj/linux/debug/mission/core/GenericFactory.o: \ fsfw/thermal/../monitoring/../timemanager/TimeStamperIF.h \ fsfw/thermal/../monitoring/../parameters/HasParametersIF.h \ mission/Controller/TCS_Heater.h fsfw/power/PowerSwitchIF.h \ - fsfw/thermal/Heater.h bsp_linux/fsfwconfig/objects/systemObjectList.h \ - bsp_linux/fsfwconfig/datapool/dataPoolInit.h + fsfw/thermal/Heater.h bsp_linux/fsfwconfig/objects/systemObjectList.h mission/core/GenericFactory.h: bsp_linux/fsfwconfig/OBSWConfig.h: bsp_linux/fsfwconfig/datapool/dataPoolInit.h: @@ -659,8 +670,32 @@ fsfw/devicehandlers/../datapool/../action/../ipc/MessageQueueIF.h: fsfw/devicehandlers/../datapool/../events/EventReportingProxyIF.h: fsfw/globalfunctions/PeriodicOperationDivider.h: fsfw/timemanager/Countdown.h: +fsfw/datapool/DataSet.h: +fsfw/datapool/DataPool.h: +fsfw/datapool/DataSetIF.h: +fsfw/datapool/PoolRawAccess.h: +fsfw/datapool/PoolVariableIF.h: +fsfw/datapool/PoolVariable.h: +fsfw/datapool/../serialize/SerializeAdapter.h: +fsfw/datapool/../serviceinterface/ServiceInterfaceStream.h: +fsfw/datapool/PoolVarList.h: +fsfw/datapool/PoolVector.h: +fsfw/datapool/PoolVector.h: +bsp_linux/fsfwconfig/datapool/dataPoolInit.h: mission/DeviceHandler/ArduinoComIF.h: fsfw/devicehandlers/DeviceCommunicationIF.h: +fsfw/serialize/SerializeAdapter.h: +fsfw/tmtcservices/CommandingServiceBase.h: +fsfw/tmtcpacket/pus/TmPacketStored.h: +fsfw/tmtcpacket/pus/TmPacketBase.h: +fsfw/tmtcpacket/pus/../SpacePacketBase.h: +fsfw/tmtcpacket/pus/../../timemanager/TimeStamperIF.h: +fsfw/tmtcpacket/pus/../../timemanager/Clock.h: +fsfw/tmtcpacket/pus/../../objectmanager/SystemObjectIF.h: +fsfw/tmtcpacket/pus/../../serialize/SerializeIF.h: +fsfw/tmtcpacket/pus/../../storagemanager/StorageManagerIF.h: +fsfw/tmtcpacket/pus/../../internalError/InternalErrorReporterIF.h: +fsfw/tmtcpacket/pus/../../ipc/MessageQueueSenderIF.h: mission/DeviceHandler/ArduinoCookie.h: mission/Controller/ThermalController.h: fsfw/action/HasActionsIF.h: @@ -677,18 +712,7 @@ fsfw/controller/../tasks/ExecutableObjectIF.h: fsfw/controller/../datapool/HkSwitchHelper.h: fsfw/datapool/ControllerSet.h: fsfw/datapool/DataSet.h: -fsfw/datapool/DataPool.h: -fsfw/datapool/DataSetIF.h: -fsfw/datapool/PoolRawAccess.h: -fsfw/datapool/PoolVariableIF.h: fsfw/datapool/PoolVariable.h: -fsfw/datapool/../serialize/SerializeAdapter.h: -fsfw/datapool/../serviceinterface/ServiceInterfaceStream.h: -fsfw/datapool/PoolVarList.h: -fsfw/datapool/PoolVector.h: -fsfw/datapool/DataSet.h: -fsfw/datapool/PoolVariable.h: -fsfw/datapool/PoolVector.h: fsfw/health/HealthTableIF.h: fsfw/returnvalues/HasReturnvaluesIF.h: mission/Controller/ArduinoTCSTemperatureSensor.h: @@ -762,4 +786,3 @@ mission/Controller/TCS_Heater.h: fsfw/power/PowerSwitchIF.h: fsfw/thermal/Heater.h: bsp_linux/fsfwconfig/objects/systemObjectList.h: -bsp_linux/fsfwconfig/datapool/dataPoolInit.h: diff --git a/_obj/linux/debug/bsp_linux/core/ObjectFactory.o b/_obj/linux/debug/bsp_linux/core/ObjectFactory.o index 318c4e4..abccbcc 100644 Binary files a/_obj/linux/debug/bsp_linux/core/ObjectFactory.o and b/_obj/linux/debug/bsp_linux/core/ObjectFactory.o differ diff --git a/_obj/linux/debug/bsp_linux/fsfwconfig/datapool/dataPoolInit.o b/_obj/linux/debug/bsp_linux/fsfwconfig/datapool/dataPoolInit.o index d7fb5a9..5868052 100644 Binary files a/_obj/linux/debug/bsp_linux/fsfwconfig/datapool/dataPoolInit.o and b/_obj/linux/debug/bsp_linux/fsfwconfig/datapool/dataPoolInit.o differ diff --git a/_obj/linux/debug/bsp_linux/main.o b/_obj/linux/debug/bsp_linux/main.o index e914d03..63b787f 100644 Binary files a/_obj/linux/debug/bsp_linux/main.o and b/_obj/linux/debug/bsp_linux/main.o differ diff --git a/_obj/linux/debug/mission/Controller/ThermalController.o b/_obj/linux/debug/mission/Controller/ThermalController.o index e78f056..817fec5 100644 Binary files a/_obj/linux/debug/mission/Controller/ThermalController.o and b/_obj/linux/debug/mission/Controller/ThermalController.o differ diff --git a/_obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o b/_obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o index 7973b27..275d276 100644 Binary files a/_obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o and b/_obj/linux/debug/mission/DeviceHandler/ArduinoComIF.o differ diff --git a/_obj/linux/debug/mission/DeviceHandler/ArduinoCookie.o b/_obj/linux/debug/mission/DeviceHandler/ArduinoCookie.o index bcbefa2..3ad9409 100644 Binary files a/_obj/linux/debug/mission/DeviceHandler/ArduinoCookie.o and b/_obj/linux/debug/mission/DeviceHandler/ArduinoCookie.o differ diff --git a/_obj/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.o b/_obj/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.o index b0410ab..b548819 100644 Binary files a/_obj/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.o and b/_obj/linux/debug/mission/DeviceHandler/ArduinoDeviceHandler.o differ diff --git a/_obj/linux/debug/mission/core/GenericFactory.o b/_obj/linux/debug/mission/core/GenericFactory.o index 7b2bb48..5b4e8bd 100644 Binary files a/_obj/linux/debug/mission/core/GenericFactory.o and b/_obj/linux/debug/mission/core/GenericFactory.o differ diff --git a/bsp_linux/fsfwconfig/datapool/dataPoolInit.cpp b/bsp_linux/fsfwconfig/datapool/dataPoolInit.cpp index a4a7188..8d0688b 100644 --- a/bsp_linux/fsfwconfig/datapool/dataPoolInit.cpp +++ b/bsp_linux/fsfwconfig/datapool/dataPoolInit.cpp @@ -10,7 +10,6 @@ void dataPoolInit(std::map* pool_map) { //Here the pool map entries of the DH and CONTROLLER are defined. - float Temperature_value[36] = {0}; pool_map->insert( std::pair(datapool::Temperature_value, @@ -19,22 +18,6 @@ void dataPoolInit(std::map* pool_map) { pool_map->insert( std::pair(datapool::Temperature_Timestamp, new PoolEntry(Temperature_Timestamp, 36))); - float Environmental_value[9] = {0}; - pool_map->insert( - std::pair(datapool::Environmental_value, - new PoolEntry(Environmental_value, 9))); - unsigned int Environmental_Timestamp[9] = {0}; - pool_map->insert( - std::pair(datapool::Environmental_Timestamp, - new PoolEntry(Environmental_Timestamp, 9))); - float Accelerometer_value[15] = {0}; - pool_map->insert( - std::pair(datapool::Accelerometer_value, - new PoolEntry(Accelerometer_value, 15))); - unsigned int Accelerometer_Timestamp[15] = {0}; - pool_map->insert( - std::pair(datapool::Accelerometer_Timestamp, - new PoolEntry(Accelerometer_Timestamp, 15))); float TEMP_SENSOR_CH1[1] = {0}; pool_map->insert( std::pair(datapool::TEMP_SENSOR_CH1, diff --git a/bsp_linux/fsfwconfig/datapool/dataPoolInit.h b/bsp_linux/fsfwconfig/datapool/dataPoolInit.h index c7daa52..a8ea7d8 100644 --- a/bsp_linux/fsfwconfig/datapool/dataPoolInit.h +++ b/bsp_linux/fsfwconfig/datapool/dataPoolInit.h @@ -1,9 +1,7 @@ /* * dataPoolInit.h * -* brief: Initialisation function for all variables in the data pool. -* This file was auto-generated by getDataPoolFromFLPmib.py via -* the flpmib database at 2018-06-04T12:02:46+00:00. +* brief: Initialization function for all variables in the data pool. */ #ifndef DATAPOOLINIT_H_ #define DATAPOOLINIT_H_ @@ -16,19 +14,14 @@ namespace datapool { // The IDs of the variables of the DH and CONTROLLER are here defined. Temperature_value = 0x100001, Temperature_Timestamp = 0x100002, - Environmental_value = 0x10003, - Environmental_Timestamp = 0x10004, - Accelerometer_value = 0x10005, - Accelerometer_Timestamp = 0x10006, - TEMP_SENSOR_CH1 = 0x10007, - TEMP_SENSOR_CH2 = 0x10008, - TargetState_COMPONENT_1 = 0x10009, - CurrentState_COMPONENT_1 = 0x100010, - HeaterRequest_COMPONENT_1 = 0x100011, - TargetState_COMPONENT_2 = 0x100012, - CurrentState_COMPONENT_2 = 0x100013, - HeaterRequest_COMPONENT_2 = 0x100014 - + TEMP_SENSOR_CH1 = 0x10003, + TEMP_SENSOR_CH2 = 0x10004, + TargetState_COMPONENT_1 = 0x10005, + CurrentState_COMPONENT_1 = 0x100006, + HeaterRequest_COMPONENT_1 = 0x100007, + TargetState_COMPONENT_2 = 0x100008, + CurrentState_COMPONENT_2 = 0x100009, + HeaterRequest_COMPONENT_2 = 0x100010 }; } diff --git a/mission/DeviceHandler/ArduinoComIF.cpp b/mission/DeviceHandler/ArduinoComIF.cpp index 8ec4ec8..07065b6 100644 --- a/mission/DeviceHandler/ArduinoComIF.cpp +++ b/mission/DeviceHandler/ArduinoComIF.cpp @@ -1,26 +1,14 @@ /* - * ArduinoComIF.cpp - * - * Last Modify: 20/09/2021 - * Author: Marco Modè + * Title: ArduinoComIF.cpp + * Author: Marco Modè + * Last version: 24/09/2021 + * Project: ESBO-DS + *------------------------------------------------------------------------------------------------------------------- * */ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -// Linux headers -#include // Contains file controls like O_RDWR -#include // Error integer and strerror() function -#include // Contains POSIX terminal control definitions -#include // write(), read(), close() ArduinoComIF::ArduinoComIF(object_id_t objectId) : SystemObject(objectId) { @@ -30,22 +18,25 @@ ArduinoComIF::~ArduinoComIF() { } ReturnValue_t ArduinoComIF::initializeInterface(CookieIF *cookie) { + ArduinoCookie *Cookie = dynamic_cast(cookie); - // The Arduino device which manage the sensors of temperature, - // environmental data and acceleration, sends through serial - // output these data employing a USB port. - // Here it is then set-up the interface to manage this communication. - // - // In typical UNIX style, serial ports are represented by files - // within the operating system. - // These files usually pop-up in /dev/, and begin with the name tty*. - // - // To write/read to a serial port, you write/read to the file. - // Here the serial port parameters are defined exploiting a - // special tty configuration struct. + /* The Arduino device which manage the sensors of temperature, + * environmental data and orientation, sends through serial + * output these data employing a USB port. + * Here it is then set-up the interface to manage this communication. + * + * In typical UNIX style, serial ports are represented by files + * within the operating system. + * These files usually pop-up in /dev/, and begin with the name tty*. + * + * To write/read to a serial port, you write/read to the file. + * Here the serial port parameters are defined exploiting a + * special tty configuration struct. + */ - // Open the serial port. Change device path as needed (see README in InterfaceCode/testArduino/testArduino/ ). + // Set-up of the Linux serial port. + // The serial port is here opened. Change device path as needed. int serial_port = open("/dev/ttyACM0", O_RDWR); // Create new termios struc, we call it 'tty' for convention. @@ -64,15 +55,13 @@ ReturnValue_t ArduinoComIF::initializeInterface(CookieIF *cookie) { tty.c_cflag |= CS8; // 8 bits per byte (most common) tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control (most common) tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1) - - tty.c_lflag &= ~ICANON; + tty.c_lflag &= ~ICANON; //Canonical mode is disabled tty.c_lflag &= ~ECHO; // Disable echo tty.c_lflag &= ~ECHOE; // Disable erasure tty.c_lflag &= ~ECHONL; // Disable new-line echo tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes - tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars) tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed @@ -83,16 +72,23 @@ ReturnValue_t ArduinoComIF::initializeInterface(CookieIF *cookie) { cfsetispeed(&tty, B115200); cfsetospeed(&tty, B115200); - // Save tty settings, also checking for error. + // Save tty settings, also checking for error if (tcsetattr(serial_port, TCSANOW, &tty) != 0) { printf("Error %i from tcsetattr: %s\n", errno, strerror(errno)); return 1; } + printf( + "***********************************************************************************************\n"); + printf( + "***********************************************************************************************\n"); printf("\nSerial port set. \n"); // End of Linux serial port set-up. + /* The serial port number is saved in the cookie such that it can + * be exploited from other functionalities or components. + */ Cookie->Serial_port_number = serial_port; return RETURN_OK; @@ -116,119 +112,113 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) { ArduinoCookie *Cookie = dynamic_cast(cookie); - /* Afterward, the buffer array to store the data read are initialized. - * The whole data packet to be read is 2580 bytes, the limit for one reading (VMAX) is 255 bytes. - * In order to avoid problems during the acquisition of data in the framework, the buffer is set to - * be 3 times the needed dimension: 7740 bytes. - * Exploiting then some control loop, the beginning of a full and complete buffer is identified. - * Since the acquisition limit for one reading is of 255 bytes, as mentioned above, - * the reading is divided in 31 separate stages which employ 31 different buffer array. - * At the end these 31 arrays are concatenated in the main buffer array read_buf. - */ - uint8_t read_buf[7740]; // 7740 bytes from SPC serial output - // Intermediate buffers (limit for one single read call is 255 bytes) - uint8_t read_buf1[255]; uint8_t read_buf2[255]; uint8_t read_buf3[255]; - uint8_t read_buf4[255]; uint8_t read_buf5[255]; uint8_t read_buf6[255]; - uint8_t read_buf7[255]; uint8_t read_buf8[255]; uint8_t read_buf9[255]; - uint8_t read_buf10[255]; uint8_t read_buf11[255]; uint8_t read_buf12[255]; - uint8_t read_buf13[255]; uint8_t read_buf14[255]; uint8_t read_buf15[255]; - uint8_t read_buf16[255]; uint8_t read_buf17[255]; uint8_t read_buf18[255]; - uint8_t read_buf19[255]; uint8_t read_buf20[255]; uint8_t read_buf21[255]; - uint8_t read_buf22[255]; uint8_t read_buf23[255]; uint8_t read_buf24[255]; - uint8_t read_buf25[255]; uint8_t read_buf26[255]; uint8_t read_buf27[255]; - uint8_t read_buf28[255]; uint8_t read_buf29[255]; uint8_t read_buf30[255]; - uint8_t read_buf31[90]; - - // The buffer elements are initially set to 0. + // The buffer elements are set to 0 at the beginning of each read-loop. memset(&read_buf, '\0', sizeof(read_buf)); - memset(&read_buf1, '\0', 255); memset(&read_buf2, '\0', 255); memset(&read_buf3, '\0', 255); - memset(&read_buf4, '\0', 255); memset(&read_buf5, '\0', 255); memset(&read_buf6, '\0', 255); - memset(&read_buf7, '\0', 255); memset(&read_buf8, '\0', 255); memset(&read_buf9, '\0', 255); - memset(&read_buf10, '\0', 255); memset(&read_buf11, '\0', 255); memset(&read_buf12, '\0', 255); - memset(&read_buf13, '\0', 255); memset(&read_buf14, '\0', 255); memset(&read_buf15, '\0', 255); - memset(&read_buf16, '\0', 255); memset(&read_buf17, '\0', 255); memset(&read_buf18, '\0', 255); - memset(&read_buf19, '\0', 255); memset(&read_buf20, '\0', 255); memset(&read_buf21, '\0', 255); - memset(&read_buf22, '\0', 255); memset(&read_buf23, '\0', 255); memset(&read_buf24, '\0', 255); - memset(&read_buf25, '\0', 255); memset(&read_buf26, '\0', 255); memset(&read_buf27, '\0', 255); - memset(&read_buf28, '\0', 255); memset(&read_buf29, '\0', 255); memset(&read_buf30, '\0', 255); + memset(&read_buf1, '\0', 255); + memset(&read_buf2, '\0', 255); + memset(&read_buf3, '\0', 255); + memset(&read_buf4, '\0', 255); + memset(&read_buf5, '\0', 255); + memset(&read_buf6, '\0', 255); + memset(&read_buf7, '\0', 255); + memset(&read_buf8, '\0', 255); + memset(&read_buf9, '\0', 255); + memset(&read_buf10, '\0', 255); + memset(&read_buf11, '\0', 255); + memset(&read_buf12, '\0', 255); + memset(&read_buf13, '\0', 255); + memset(&read_buf14, '\0', 255); + memset(&read_buf15, '\0', 255); + memset(&read_buf16, '\0', 255); + memset(&read_buf17, '\0', 255); + memset(&read_buf18, '\0', 255); + memset(&read_buf19, '\0', 255); + memset(&read_buf20, '\0', 255); + memset(&read_buf21, '\0', 255); + memset(&read_buf22, '\0', 255); + memset(&read_buf23, '\0', 255); + memset(&read_buf24, '\0', 255); + memset(&read_buf25, '\0', 255); + memset(&read_buf26, '\0', 255); + memset(&read_buf27, '\0', 255); + memset(&read_buf28, '\0', 255); + memset(&read_buf29, '\0', 255); + memset(&read_buf30, '\0', 255); memset(&read_buf31, '\0', 90); - /*memset(&read_buf, '\0', sizeof(read_buf)); - memset(&read_buf1, '\0', 255); memset(&read_buf2, '\0', 255); memset(&read_buf3, '\0', 255); - memset(&read_buf4, '\0', 255); memset(&read_buf5, '\0', 255); memset(&read_buf6, '\0', 255); - memset(&read_buf7, '\0', 255); memset(&read_buf8, '\0', 255); memset(&read_buf9, '\0', 255); - memset(&read_buf10, '\0', 255); memset(&read_buf11, '\0', 255); memset(&read_buf12, '\0', 255); - memset(&read_buf13, '\0', 255); memset(&read_buf14, '\0', 255); memset(&read_buf15, '\0', 255); - memset(&read_buf16, '\0', 255); memset(&read_buf17, '\0', 255); memset(&read_buf18, '\0', 255); - memset(&read_buf19, '\0', 255); memset(&read_buf20, '\0', 255); memset(&read_buf21, '\0', 60);*/ - // Read bytes. The behaviour of read() (e.g. does it block?, how long does it block for?) - // depends on the configuration settings above, specifically VMIN and VTIME. - int num_bytes1 = read(Cookie->Serial_port_number, &read_buf1, sizeof(read_buf1)); - int num_bytes2 = read(Cookie->Serial_port_number, &read_buf2, sizeof(read_buf2)); - int num_bytes3 = read(Cookie->Serial_port_number, &read_buf3, sizeof(read_buf3)); - int num_bytes4 = read(Cookie->Serial_port_number, &read_buf4, sizeof(read_buf4)); - int num_bytes5 = read(Cookie->Serial_port_number, &read_buf5, sizeof(read_buf5)); - int num_bytes6 = read(Cookie->Serial_port_number, &read_buf6, sizeof(read_buf6)); - int num_bytes7 = read(Cookie->Serial_port_number, &read_buf7, sizeof(read_buf7)); - int num_bytes8 = read(Cookie->Serial_port_number, &read_buf8, sizeof(read_buf8)); - int num_bytes9 = read(Cookie->Serial_port_number, &read_buf9, sizeof(read_buf9)); - int num_bytes10 = read(Cookie->Serial_port_number, &read_buf10, sizeof(read_buf10)); - int num_bytes11 = read(Cookie->Serial_port_number, &read_buf11, sizeof(read_buf11)); - int num_bytes12 = read(Cookie->Serial_port_number, &read_buf12, sizeof(read_buf12)); - int num_bytes13 = read(Cookie->Serial_port_number, &read_buf13, sizeof(read_buf13)); - int num_bytes14 = read(Cookie->Serial_port_number, &read_buf14, sizeof(read_buf14)); - int num_bytes15 = read(Cookie->Serial_port_number, &read_buf15, sizeof(read_buf15)); - int num_bytes16 = read(Cookie->Serial_port_number, &read_buf16, sizeof(read_buf16)); - int num_bytes17 = read(Cookie->Serial_port_number, &read_buf17, sizeof(read_buf17)); - int num_bytes18 = read(Cookie->Serial_port_number, &read_buf18, sizeof(read_buf18)); - int num_bytes19 = read(Cookie->Serial_port_number, &read_buf19, sizeof(read_buf19)); - int num_bytes20 = read(Cookie->Serial_port_number, &read_buf20, sizeof(read_buf20)); - int num_bytes21 = read(Cookie->Serial_port_number, &read_buf21, sizeof(read_buf21)); - int num_bytes22 = read(Cookie->Serial_port_number, &read_buf22, sizeof(read_buf22)); - int num_bytes23 = read(Cookie->Serial_port_number, &read_buf23, sizeof(read_buf23)); - int num_bytes24 = read(Cookie->Serial_port_number, &read_buf24, sizeof(read_buf24)); - int num_bytes25 = read(Cookie->Serial_port_number, &read_buf25, sizeof(read_buf25)); - int num_bytes26 = read(Cookie->Serial_port_number, &read_buf26, sizeof(read_buf26)); - int num_bytes27 = read(Cookie->Serial_port_number, &read_buf27, sizeof(read_buf27)); - int num_bytes28 = read(Cookie->Serial_port_number, &read_buf28, sizeof(read_buf28)); - int num_bytes29 = read(Cookie->Serial_port_number, &read_buf29, sizeof(read_buf29)); - int num_bytes30 = read(Cookie->Serial_port_number, &read_buf30, sizeof(read_buf30)); - int num_bytes31 = read(Cookie->Serial_port_number, &read_buf31, sizeof(read_buf31)); + /* Read bytes. The behaviour of read() depends on the configuration + * settings in initializeInterface, specifically VMIN and VTIME. + */ + int num_bytes1 = read(Cookie->Serial_port_number, &read_buf1, + sizeof(read_buf1)); + int num_bytes2 = read(Cookie->Serial_port_number, &read_buf2, + sizeof(read_buf2)); + int num_bytes3 = read(Cookie->Serial_port_number, &read_buf3, + sizeof(read_buf3)); + int num_bytes4 = read(Cookie->Serial_port_number, &read_buf4, + sizeof(read_buf4)); + int num_bytes5 = read(Cookie->Serial_port_number, &read_buf5, + sizeof(read_buf5)); + int num_bytes6 = read(Cookie->Serial_port_number, &read_buf6, + sizeof(read_buf6)); + int num_bytes7 = read(Cookie->Serial_port_number, &read_buf7, + sizeof(read_buf7)); + int num_bytes8 = read(Cookie->Serial_port_number, &read_buf8, + sizeof(read_buf8)); + int num_bytes9 = read(Cookie->Serial_port_number, &read_buf9, + sizeof(read_buf9)); + int num_bytes10 = read(Cookie->Serial_port_number, &read_buf10, + sizeof(read_buf10)); + int num_bytes11 = read(Cookie->Serial_port_number, &read_buf11, + sizeof(read_buf11)); + int num_bytes12 = read(Cookie->Serial_port_number, &read_buf12, + sizeof(read_buf12)); + int num_bytes13 = read(Cookie->Serial_port_number, &read_buf13, + sizeof(read_buf13)); + int num_bytes14 = read(Cookie->Serial_port_number, &read_buf14, + sizeof(read_buf14)); + int num_bytes15 = read(Cookie->Serial_port_number, &read_buf15, + sizeof(read_buf15)); + int num_bytes16 = read(Cookie->Serial_port_number, &read_buf16, + sizeof(read_buf16)); + int num_bytes17 = read(Cookie->Serial_port_number, &read_buf17, + sizeof(read_buf17)); + int num_bytes18 = read(Cookie->Serial_port_number, &read_buf18, + sizeof(read_buf18)); + int num_bytes19 = read(Cookie->Serial_port_number, &read_buf19, + sizeof(read_buf19)); + int num_bytes20 = read(Cookie->Serial_port_number, &read_buf20, + sizeof(read_buf20)); + int num_bytes21 = read(Cookie->Serial_port_number, &read_buf21, + sizeof(read_buf21)); + int num_bytes22 = read(Cookie->Serial_port_number, &read_buf22, + sizeof(read_buf22)); + int num_bytes23 = read(Cookie->Serial_port_number, &read_buf23, + sizeof(read_buf23)); + int num_bytes24 = read(Cookie->Serial_port_number, &read_buf24, + sizeof(read_buf24)); + int num_bytes25 = read(Cookie->Serial_port_number, &read_buf25, + sizeof(read_buf25)); + int num_bytes26 = read(Cookie->Serial_port_number, &read_buf26, + sizeof(read_buf26)); + int num_bytes27 = read(Cookie->Serial_port_number, &read_buf27, + sizeof(read_buf27)); + int num_bytes28 = read(Cookie->Serial_port_number, &read_buf28, + sizeof(read_buf28)); + int num_bytes29 = read(Cookie->Serial_port_number, &read_buf29, + sizeof(read_buf29)); + int num_bytes30 = read(Cookie->Serial_port_number, &read_buf30, + sizeof(read_buf30)); + int num_bytes31 = read(Cookie->Serial_port_number, &read_buf31, + sizeof(read_buf31)); int num_bytes = num_bytes1 + num_bytes2 + num_bytes3 + num_bytes4 - + num_bytes5 + num_bytes6 + num_bytes7 + num_bytes8 - + num_bytes9 + num_bytes10 + num_bytes11 + num_bytes12 - + num_bytes13 + num_bytes14 + num_bytes15 + num_bytes16 - + num_bytes17 + num_bytes18 + num_bytes19 + num_bytes20 - + num_bytes21 + num_bytes22 + num_bytes23 + num_bytes24 - + num_bytes25 + num_bytes26 + num_bytes27 + num_bytes28 - + num_bytes29 + num_bytes30 + num_bytes31; - /*int num_bytes1 = read(Cookie->Serial_port_number, &read_buf1, sizeof(read_buf1)); - int num_bytes2 = read(Cookie->Serial_port_number, &read_buf2, sizeof(read_buf2)); - int num_bytes3 = read(Cookie->Serial_port_number, &read_buf3, sizeof(read_buf3)); - int num_bytes4 = read(Cookie->Serial_port_number, &read_buf4, sizeof(read_buf4)); - int num_bytes5 = read(Cookie->Serial_port_number, &read_buf5, sizeof(read_buf5)); - int num_bytes6 = read(Cookie->Serial_port_number, &read_buf6, sizeof(read_buf6)); - int num_bytes7 = read(Cookie->Serial_port_number, &read_buf7, sizeof(read_buf7)); - int num_bytes8 = read(Cookie->Serial_port_number, &read_buf8, sizeof(read_buf8)); - int num_bytes9 = read(Cookie->Serial_port_number, &read_buf9, sizeof(read_buf9)); - int num_bytes10 = read(Cookie->Serial_port_number, &read_buf10, sizeof(read_buf10)); - int num_bytes11 = read(Cookie->Serial_port_number, &read_buf11, sizeof(read_buf11)); - int num_bytes12 = read(Cookie->Serial_port_number, &read_buf12, sizeof(read_buf12)); - int num_bytes13 = read(Cookie->Serial_port_number, &read_buf13, sizeof(read_buf13)); - int num_bytes14 = read(Cookie->Serial_port_number, &read_buf14, sizeof(read_buf14)); - int num_bytes15 = read(Cookie->Serial_port_number, &read_buf15, sizeof(read_buf15)); - int num_bytes16 = read(Cookie->Serial_port_number, &read_buf16, sizeof(read_buf16)); - int num_bytes17 = read(Cookie->Serial_port_number, &read_buf17, sizeof(read_buf17)); - int num_bytes18 = read(Cookie->Serial_port_number, &read_buf18, sizeof(read_buf18)); - int num_bytes19 = read(Cookie->Serial_port_number, &read_buf19, sizeof(read_buf19)); - int num_bytes20 = read(Cookie->Serial_port_number, &read_buf20, sizeof(read_buf20)); - int num_bytes21 = read(Cookie->Serial_port_number, &read_buf21, sizeof(read_buf21)); - int num_bytes = num_bytes1 + num_bytes2 + num_bytes3 + num_bytes4 - + num_bytes5 + num_bytes6 + num_bytes7 + num_bytes8 - + num_bytes9 + num_bytes10 + num_bytes11 + num_bytes12 - + num_bytes13 + num_bytes14 + num_bytes15 + num_bytes16 - + num_bytes17 + num_bytes18 + num_bytes19 + num_bytes20 - + num_bytes21;*/ + + num_bytes5 + num_bytes6 + num_bytes7 + num_bytes8 + num_bytes9 + + num_bytes10 + num_bytes11 + num_bytes12 + num_bytes13 + + num_bytes14 + num_bytes15 + num_bytes16 + num_bytes17 + + num_bytes18 + num_bytes19 + num_bytes20 + num_bytes21 + + num_bytes22 + num_bytes23 + num_bytes24 + num_bytes25 + + num_bytes26 + num_bytes27 + num_bytes28 + num_bytes29 + + num_bytes30 + num_bytes31; // The 11 buffer arrays are here concatenated in one single vector. std::copy(read_buf1, read_buf1 + 255, read_buf); @@ -262,27 +252,6 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie, std::copy(read_buf29, read_buf29 + 255, read_buf + 28 * 255); std::copy(read_buf30, read_buf30 + 255, read_buf + 29 * 255); std::copy(read_buf31, read_buf31 + 90, read_buf + 30 * 255); - /*std::copy(read_buf1, read_buf1 + 255, read_buf); - std::copy(read_buf2, read_buf2 + 255, read_buf + 255); - std::copy(read_buf3, read_buf3 + 255, read_buf + 2 * 255); - std::copy(read_buf4, read_buf4 + 255, read_buf + 3 * 255); - std::copy(read_buf5, read_buf5 + 255, read_buf + 4 * 255); - std::copy(read_buf6, read_buf6 + 255, read_buf + 5 * 255); - std::copy(read_buf7, read_buf7 + 255, read_buf + 6 * 255); - std::copy(read_buf8, read_buf8 + 255, read_buf + 7 * 255); - std::copy(read_buf9, read_buf9 + 255, read_buf + 8 * 255); - std::copy(read_buf10, read_buf10 + 255, read_buf + 9 * 255); - std::copy(read_buf11, read_buf11 + 255, read_buf + 10 * 255); - std::copy(read_buf12, read_buf12 + 255, read_buf + 11 * 255); - std::copy(read_buf13, read_buf13 + 255, read_buf + 12 * 255); - std::copy(read_buf14, read_buf14 + 255, read_buf + 13 * 255); - std::copy(read_buf15, read_buf15 + 255, read_buf + 14 * 255); - std::copy(read_buf16, read_buf16 + 255, read_buf + 15 * 255); - std::copy(read_buf17, read_buf17 + 255, read_buf + 16 * 255); - std::copy(read_buf18, read_buf18 + 255, read_buf + 17 * 255); - std::copy(read_buf19, read_buf19 + 255, read_buf + 18 * 255); - std::copy(read_buf20, read_buf20 + 255, read_buf + 19 * 255); - std::copy(read_buf21, read_buf21 + 60, read_buf + 20 * 255);*/ // num_bytes is the number of bytes read (n=0: no bytes received, n=-1: error). if (num_bytes < 0) { @@ -293,16 +262,35 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie, printf("Read %i bytes.\n", num_bytes); // Loop to define the adress of the buffer start + /* + * Here it is performed a control loop in order to ensure the identification + * of a full and not-corrupted array of measurement in the buffer defined above. + * The index related to the first byte of the array is saved in the + * variable first_index which is given as output. + * It will then will be exploited in the device handler by ScanForReply and + * InterpreteForReply. + */ int first_index = 0; while (first_index < 7740) { - if (read_buf[first_index] == 91){ + // start character: '[' + if (read_buf[first_index] == 91) { + // fourth character: 'S' (First variable is the char [ChStr]) if (read_buf[first_index + 3] == 83) { + // first channel must be channel 1 (SPCChNumber: 1) if (read_buf[first_index + 9] == 1) { - if (read_buf[first_index + 27*35 + 9] == 39) { - if (read_buf[first_index + 27*35 + 22] == 69) { - if (read_buf[first_index + 27*45 + 91*13 + 9] == 122) { - if (read_buf[first_index + 27*45 + 91*14 + 9] == 123) { - if (read_buf[first_index + 27*45 + 91*14 + 86] == 69) { + // last channel of temperature board must be channel 39 (SPCChNumber: 39) + if (read_buf[first_index + 27 * 35 + 9] == 39) { + // 22nd character of last channel of temperature board: 'E' ([ChEnd]) + if (read_buf[first_index + 27 * 35 + 22] == 69) { + // second to last channel of orientation board must be channel 122 (SPCChNumber: 122) + if (read_buf[first_index + 27 * 45 + 91 * 13 + 9] + == 122) { + // last channel of orientation board must be channel 123 (SPCChNumber: 123) + if (read_buf[first_index + 27 * 45 + 91 * 14 + 9] + == 123) { + // 69th character of last channel of orientation board: 'E' ([ChEnd]) + if (read_buf[first_index + 27 * 45 + 91 * 14 + + 86] == 69) { break; } else { first_index++; @@ -330,11 +318,10 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie, } } - // Definition of buffer array and buffer size to return after reading. + // Definition of buffer size and buffer array start to return after reading. *size = num_bytes; *buffer = &read_buf[first_index]; - return RETURN_OK; } diff --git a/mission/DeviceHandler/ArduinoComIF.h b/mission/DeviceHandler/ArduinoComIF.h index 3e32e2b..52bfbfe 100644 --- a/mission/DeviceHandler/ArduinoComIF.h +++ b/mission/DeviceHandler/ArduinoComIF.h @@ -1,8 +1,17 @@ /* - * Title: ArduinoComIF.h + * Title: ArduinoComIF.h + * Author: Marco Modè + * Last version: 24/09/2021 + * Project: ESBO-DS * - * Last Modify: 20/09/2021 - * Author: Marco Modè + * @ brief: Used to initialize the communication Interface (USB connector, serial port) and + * to perform the 4 periodical function described in the DeviceCommunicationIF + * (child of DeviceCommunicationIF). + * In this case sendMessage, getSendSuccess and requestReceiveMessage are + * just returning RETURN_OK. + * @ details: The ArduinoComIF is instantiated in the generic factory. + * @ ingroup: mission/DeviceHandler + *------------------------------------------------------------------------------------------------------------------- * */ @@ -13,28 +22,29 @@ #include #include #include +#include +#include +#include #include #include #include #include #include #include - -/** - * @brief Used to initialize the communication Interface (USB connector, serial port) and - * to perform the 4 periodical function described in the DeviceCommunicationIF. - * In this case sendMessage, getSendSuccess and requestReceiveMessage are - * just returning RETURN_OK. - * @details The ArduinoComIF is instantiated in the generic factory. - * @author: Marco Modè - * @ingroup mission/DeviceHandler - */ +#include +// Linux headers +#include // Contains file controls like O_RDWR +#include // Error integer and strerror() function +#include // Contains POSIX terminal control definitions +#include // write(), read(), close() class ArduinoComIF: public DeviceCommunicationIF, public SystemObject { public: + ArduinoComIF(object_id_t objectId); virtual ~ArduinoComIF(); + // DeviceCommunicationIF inherited functions. ReturnValue_t initializeInterface(CookieIF *cookie) override; ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override; @@ -44,6 +54,51 @@ public: ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override; +protected: + + /* The buffer array to store the data read are initialized. + * The whole data packet to be read is 2580 bytes, the limit for one reading (VMAX) is 255 bytes. + * In order to avoid problems during the acquisition of data in the framework, the buffer is set to + * be 3 times the needed dimension: 7740 bytes. + * Exploiting then some control loop, the beginning of a full and complete buffer is identified. + * Since the acquisition limit for one reading is of 255 bytes, as mentioned above, + * the reading is divided in 31 separate stages which employ 31 different buffer array. + * At the end these 31 arrays are concatenated in the main buffer array read_buf. + */ + uint8_t read_buf[7740]; // 7740 bytes from SPC serial output + // Intermediate buffers (limit for one single read call is 255 bytes) + uint8_t read_buf1[255]; + uint8_t read_buf2[255]; + uint8_t read_buf3[255]; + uint8_t read_buf4[255]; + uint8_t read_buf5[255]; + uint8_t read_buf6[255]; + uint8_t read_buf7[255]; + uint8_t read_buf8[255]; + uint8_t read_buf9[255]; + uint8_t read_buf10[255]; + uint8_t read_buf11[255]; + uint8_t read_buf12[255]; + uint8_t read_buf13[255]; + uint8_t read_buf14[255]; + uint8_t read_buf15[255]; + uint8_t read_buf16[255]; + uint8_t read_buf17[255]; + uint8_t read_buf18[255]; + uint8_t read_buf19[255]; + uint8_t read_buf20[255]; + uint8_t read_buf21[255]; + uint8_t read_buf22[255]; + uint8_t read_buf23[255]; + uint8_t read_buf24[255]; + uint8_t read_buf25[255]; + uint8_t read_buf26[255]; + uint8_t read_buf27[255]; + uint8_t read_buf28[255]; + uint8_t read_buf29[255]; + uint8_t read_buf30[255]; + uint8_t read_buf31[90]; + }; #endif /* MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_ */ diff --git a/mission/DeviceHandler/ArduinoCookie.cpp b/mission/DeviceHandler/ArduinoCookie.cpp index bc5e98d..2adcdbc 100644 --- a/mission/DeviceHandler/ArduinoCookie.cpp +++ b/mission/DeviceHandler/ArduinoCookie.cpp @@ -1,16 +1,19 @@ /* - * ArduinoCookie.cpp - * - * Last Modify: 20/09/2021 - * Author: Marco Modè + * Title: ArduinoCookie.cpp + * Author: Marco Modè + * Last version: 24/09/2021 + * Project: ESBO-DS + *------------------------------------------------------------------------------------------------------------------- * */ #include -//The cookie tells to device handler which is the device to communicate with, if more -// devices are connected. In this case only one device, the Arduino board, is -// connected. +/*In this case only one device is connected to the controller, + * for this reason the adress is unique and there is no need + * to define it to distinguish with others. + * The constructor is therefore empty. + */ ArduinoCookie::ArduinoCookie() { } diff --git a/mission/DeviceHandler/ArduinoCookie.h b/mission/DeviceHandler/ArduinoCookie.h index fc3de3a..b1f2230 100644 --- a/mission/DeviceHandler/ArduinoCookie.h +++ b/mission/DeviceHandler/ArduinoCookie.h @@ -1,8 +1,17 @@ /* - * ArduinoCookie.h + * Title: ArduinoCookie.h + * Author: Marco Modè + * Last version: 24/09/2021 + * Project: ESBO-DS * - * Last Modify: 20/09/2021 - * Author: Marco Modè + * @ brief: Simple cookie which initializes the variables + * for the Linux serial port. + * The cookie tells to device handler which is the device + * to communicate with, if more devices are connected. + * In this case only one device, the Arduino board, is connected. + * @ details: The ArduinoCookie is instantiated in the generic factory. + * @ ingroup: mission/DeviceHandler + *------------------------------------------------------------------------------------------------------------------- * */ @@ -12,20 +21,15 @@ #include #include -/** - * @brief Simple cookie which initialize the variables - * for the Linux serial port. - * @details The ArduinoCookie is instantiated in the generic factory. - * @author: Marco Modè - * @ingroup mission/DeviceHandler - */ + class ArduinoCookie: public CookieIF { public: ArduinoCookie(); virtual ~ArduinoCookie(); - // Serial port for the communication with Arduino board is here initialized. - // It will be exploited in the ComIF to manage the computer serial port. + /* Serial port for the communication with Arduino board is here initialized. + * It will be exploited in the ComIF and DH to manage the computer serial port. + */ int Serial_port_number; }; diff --git a/mission/DeviceHandler/ArduinoDeviceHandler.cpp b/mission/DeviceHandler/ArduinoDeviceHandler.cpp index 8f626a9..d98461f 100644 --- a/mission/DeviceHandler/ArduinoDeviceHandler.cpp +++ b/mission/DeviceHandler/ArduinoDeviceHandler.cpp @@ -1,35 +1,31 @@ /* - * DeviceHandler.cpp - * - * Last Modify: 20/09/2021 - * Author: Marco Modè + * Title: ArduinoDeviceHandler.cpp + * Author: Marco Modè + * Last version: 24/09/2021 + * Project: ESBO-DS + *------------------------------------------------------------------------------------------------------------------- * */ #include -#include -#include -#include -#include -#include -#include -//#include - ArduinoDH::ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie) : - DeviceHandlerBase(objectId, comIF, cookie) { - mode = _MODE_START_UP; + DeviceHandlerBase(objectId, comIF, cookie), + TempValueVec(datapool::Temperature_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE), + TempTimeVec(datapool::Temperature_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE) { + mode = _MODE_START_UP; +} +ArduinoDH::~ArduinoDH() { } -ArduinoDH::~ArduinoDH() {} void ArduinoDH::doStartUp() { - std::cout<<"Arduino device -> Switching-ON"< Switching-ON" << std::endl; setMode(_MODE_TO_ON); return; } void ArduinoDH::doShutDown() { - std::cout<<"Arduino device -> Switching-OFF"< Switching-OFF" << std::endl; setMode(_MODE_SHUT_DOWN); return; } @@ -44,7 +40,7 @@ ReturnValue_t ArduinoDH::buildTransitionDeviceCommand(DeviceCommandId_t *id) { void ArduinoDH::doTransition(Mode_t modeFrom, Submode_t submodeFrom) { if (mode == _MODE_TO_NORMAL) { setMode(_MODE_TO_NORMAL); - std::cout<<"Arduino device is in Normal mode"< id {{*foundId, len}}; - //*foundId = id; + // The ID is defined as a macro. It includes info about the array size. + std::map id { { *foundId, len } }; - // check validity - if (len == *foundLen){ - // start character: '[' - if (*start == 91 ){ - // fourth character: 'S' (First variable is the char [ChStr]) - if (*(start + 3) == 83) { - // first channel must be channel 1 (SPCChNumber: 1) - if (*(start + 9) == 1) { - return APERIODIC_REPLY; - } else { - return DeviceHandlerIF::LENGTH_MISSMATCH; - } - } else { - return DeviceHandlerIF::LENGTH_MISSMATCH; - } - } else { - return DeviceHandlerIF::LENGTH_MISSMATCH; - } + /* Check validity of the packet in terms of length (the data have + * been already checked in ArduinoComIF.cpp in order to provide the + * start of the data buffer. + */ + if (*foundLen == 7740) { + return APERIODIC_REPLY; } else { - return IGNORE_REPLY_DATA; + return DeviceHandlerIF::LENGTH_MISSMATCH; } } ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { - - DataSet ArduinoDataSet; - //sif::debug<<"DEBUG_DH: interprete for reply"< "); - } - else if (k == 1 || k == 4 || k == 7 || k == 10 || k == 13) { + } else if (k == 1 || k == 4 || k == 7 || k == 10 || k == 13) { printf("\n\nY ==> "); - } - else { + } else { printf("\n\nZ ==> "); } printf("\nStart: %7s", Ornt_ch.start_string); @@ -207,54 +197,8 @@ ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id, std::cout << "\n\nEnd reading data.\n" << std::endl; - // The data are here written to the data pool where they would be available to be used for other objects - - /*PoolVector TempValueVec(datapool::Temperature_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int i = 0; i < 36; i++) { - memcpy(&TempValueVec[i], &vecTemp[i].temperature, 4); - } - ArduinoDataSet.commit(PoolVariableIF::VALID);*/ - - - /*PoolVector TempTimeVec(datapool::Temperature_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int i = 0; i < 36; i++) { - memcpy(&TempTimeVec[i], &vecTemp[i].Timestamp, 4); - } - ArduinoDataSet.commit(PoolVariableIF::VALID); - - sif::debug<<"\nDEBUG_DHi: End of copy to datapool"< EnvValueVec(datapool::Environmental_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int j = 0; j < 9; j++) { - memcpy(&EnvValueVec[j], &vecEnv[j].Value, 4); - } - ArduinoDataSet.commit(PoolVariableIF::VALID); - - PoolVector EnvTimeVec(datapool::Environmental_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int j = 0; j < 9; j++) { - memcpy(&EnvTimeVec[j], &vecEnv[j].Timestamp, 4); - } - ArduinoDataSet.commit(PoolVariableIF::VALID); - - sif::debug<<"\nDEBUG_DHj: End of copy to datapool"< AccValueVec(datapool::Accelerometer_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int k = 0; k < 15; k++) { - memcpy(&AccValueVec[k], &vecOrnt[k].Value, 36); - } - ArduinoDataSet.commit(PoolVariableIF::VALID); - sif::debug<<"\nDEBUG_DHk1: End of copy to datapool"< AccTimeVec(datapool::Accelerometer_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE); - for (int k = 0; k < 15; k++) { - memcpy(&AccTimeVec[k], &vecOrnt[k].Timestamp, 36); - } - ArduinoDataSet.commit(PoolVariableIF::VALID); - sif::debug<<"\nDEBUG_DHk2: End of copy to datapool"< #include #include #include +#include +#include +#include +#include +#include +#include +#include + -/** - * @brief Basic device handler to manage the communication with the Arduino sensor board. - * The data are sent to the serial port of the computer from the Arduino board. - * The device handler read and manages these data exploiting the ComIF and the - * DeviceHandlerBase functions. - * @details The ArduinoDH object is instantiated in the generic factory. - * @author Marco Modè - * @ingroup mission/DeviceHandler - */ class ArduinoDH: public DeviceHandlerBase { public: /** @@ -31,13 +88,18 @@ public: * @param comIF The ID of the Communication IF used by test device handler. * @param cookie Cookie object used by the test device handler. This is * also used and passed to the comIF object. - * @param onImmediately This will start a transition to MODE_ON immediately - * so the device handler jumps into #doStartUp. Should only be used - * in development to reduce need of commanding while debugging. */ ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie); virtual ~ ArduinoDH(); + /* This header code contains the definition of the structures of data + * (Temperature, Environemntal, Orientation) in which the sensors data are stored. + * These structures are defined in the Arduino IDE code developed for the sensor board. + * The Arduino is the responsible of the management of sensors devices and data. + * Furthermore, the vectors and arrays necessary for the code execution are here + * defined. + */ + /* Definiton of data structure for SPC communication. Three different structures are defined for measurements of: * - Temperature data, * - Environmental data, @@ -99,26 +161,26 @@ public: } }; - // Three vectors are defined to store the three type of classes sequentially - // during the phase of reading copying data from the buffers + /* Three vectors are defined to store the three type of classes sequentially + * during the phase of reading copying data from the buffers + */ std::vector vecTemp; std::vector vecEnv; std::vector vecOrnt; - // Three dummy child structures are defined. They are used to store the three - // different types of data during the measurement loop and then the data are - // copied in the vectors above. - // Then, they are overwritten by the data of next iteration and the process is - // repeated ,until all the data from the buffer are copied to the three vectors - // using the three different structures. + /* Three dummy child structures are defined. They are used to store the three + * different types of data during the measurement loop and then the data are + * copied in the vectors above. + * Then, they are overwritten by the data of next iteration and the process is + * repeated ,until all the data from the buffer are copied to the three vectors + * using the three different structures. + */ Temperature Temp_ch; Environmental Env_ch; Orientation Ornt_ch; protected: - //#define BUFFER_ID(id, value, msg); - // DeviceHandlerBase inherited functions. virtual void doStartUp() override; virtual void doShutDown() override; @@ -137,6 +199,11 @@ protected: const uint8_t *packet) override; virtual void setNormalDatapoolEntriesInvalid() override; + // Dataset initialized. It is used for copying the data to the datapool. + DataSet ArduinoDataSet; + // Here the datapool variables are defined. The needed data will be stored inside them. + PoolVector TempValueVec; + PoolVector TempTimeVec; }; #endif /* MISSION_DEVICEHANDLER_ARDUINODEVICEHANDLER_H_ */