Device Handler has been modified in both the Communication Interface and in DH object. The ScanForReply and InterpreteForReply are fixed. The reading and printing of data is correct. It is still needed to fix the save in datapool and do documentation of the code.
This commit is contained in:
parent
d366b3ca22
commit
a8e498ad3a
@ -18,3 +18,5 @@ In conclusion it is firstly necessary to know the name of the computer serial po
|
|||||||
This name should be substituted in line 52 of mission/DeviceHandler/ArduinoComIF.cpp as:
|
This name should be substituted in line 52 of mission/DeviceHandler/ArduinoComIF.cpp as:
|
||||||
int serial_port = open("WRITE_SERIAL_PORT_NAME", O_RDWR);
|
int serial_port = open("WRITE_SERIAL_PORT_NAME", O_RDWR);
|
||||||
Finally the command described here above must be inserted in the terminal.
|
Finally the command described here above must be inserted in the terminal.
|
||||||
|
|
||||||
|
RMK! ==> Now the port should be just renamed with the correct name in the code, there is no need anymore of write the open command in the terminal.
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -111,7 +111,7 @@ void InitMission::createTasks(){
|
|||||||
|
|
||||||
FixedTimeslotTaskIF* arduinoTask = TaskFactory::instance()->
|
FixedTimeslotTaskIF* arduinoTask = TaskFactory::instance()->
|
||||||
createFixedTimeslotTask("ARDUINO_TASK",40,
|
createFixedTimeslotTask("ARDUINO_TASK",40,
|
||||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, nullptr);
|
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8/*6.4*/, nullptr);
|
||||||
result = pollingSequenceArduinoFunction(arduinoTask);
|
result = pollingSequenceArduinoFunction(arduinoTask);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
sif::error << "InitMission::createTasks:ArduinoPST initialization failed!"
|
sif::error << "InitMission::createTasks:ArduinoPST initialization failed!"
|
||||||
@ -120,7 +120,7 @@ void InitMission::createTasks(){
|
|||||||
|
|
||||||
PeriodicTaskIF* controllerTask = TaskFactory::instance()->
|
PeriodicTaskIF* controllerTask = TaskFactory::instance()->
|
||||||
createPeriodicTask("CONTROLLER_TASK",40,
|
createPeriodicTask("CONTROLLER_TASK",40,
|
||||||
PeriodicTaskIF::MINIMUM_STACK_SIZE, 3, nullptr);
|
PeriodicTaskIF::MINIMUM_STACK_SIZE, 2, nullptr);
|
||||||
//result = pollingSequenceControllerFunction(controllerTask);
|
//result = pollingSequenceControllerFunction(controllerTask);
|
||||||
result = controllerTask->addComponent(objects::THERMAL_CONTROLLER);
|
result = controllerTask->addComponent(objects::THERMAL_CONTROLLER);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
@ -150,8 +150,8 @@ void InitMission::createTasks(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Main thread sleep
|
//Main thread sleep
|
||||||
sif::debug << "Starting Tasks in 3.2 seconds" << std::endl;
|
sif::debug << "Starting Tasks in 2 seconds" << std::endl;
|
||||||
TaskFactory::delayTask(1600);
|
TaskFactory::delayTask(2400);
|
||||||
distributerTask->startTask();
|
distributerTask->startTask();
|
||||||
udpBridgeTask->startTask();
|
udpBridgeTask->startTask();
|
||||||
udpPollingTask->startTask();
|
udpPollingTask->startTask();
|
||||||
|
@ -17,9 +17,9 @@ ReturnValue_t pollingSequenceArduinoFunction(
|
|||||||
uint32_t length = thisSequence->getPeriodMs();
|
uint32_t length = thisSequence->getPeriodMs();
|
||||||
|
|
||||||
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0, 0);
|
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0, 0);
|
||||||
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.2, 1);
|
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.1, 1);
|
||||||
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.3, 2);
|
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.15, 2);
|
||||||
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.5, 3);
|
thisSequence->addSlot(objects::ARDUINO_DEVICE_HANDLER, length * 0.75, 3);
|
||||||
|
|
||||||
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
|
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
@ -44,6 +44,8 @@ ReturnValue_t DeviceHandlerFailureIsolation::eventReceived(EventMessage* event)
|
|||||||
break;
|
break;
|
||||||
case DeviceHandlerIF::DEVICE_INTERPRETING_REPLY_FAILED:
|
case DeviceHandlerIF::DEVICE_INTERPRETING_REPLY_FAILED:
|
||||||
case DeviceHandlerIF::DEVICE_READING_REPLY_FAILED:
|
case DeviceHandlerIF::DEVICE_READING_REPLY_FAILED:
|
||||||
|
sif::debug<<"DH_FDIR: event received REPLY"<<std::endl;
|
||||||
|
break;
|
||||||
case DeviceHandlerIF::DEVICE_UNREQUESTED_REPLY:
|
case DeviceHandlerIF::DEVICE_UNREQUESTED_REPLY:
|
||||||
case DeviceHandlerIF::DEVICE_UNKNOWN_REPLY: //Some DH's generate generic reply-ids.
|
case DeviceHandlerIF::DEVICE_UNKNOWN_REPLY: //Some DH's generate generic reply-ids.
|
||||||
case DeviceHandlerIF::DEVICE_BUILDING_COMMAND_FAILED:
|
case DeviceHandlerIF::DEVICE_BUILDING_COMMAND_FAILED:
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#ifndef TCS_DATA_CONFIG_H_
|
#ifndef TCS_DATA_CONFIG_H_
|
||||||
#define TCS_DATA_CONFIG_H_
|
#define TCS_DATA_CONFIG_H_
|
||||||
|
|
||||||
#define TEMPERATURE_SENSOR_CONFIG ArduinoTCSTemperatureSensor::Parameters({-999.0,999.0})
|
#define TEMPERATURE_SENSOR_CONFIG ArduinoTCSTemperatureSensor::Parameters({-1000.0,1000.0})
|
||||||
|
|
||||||
#define HEATER_ON_DEFAULT 3
|
#define HEATER_ON_DEFAULT 3
|
||||||
#define HEATER_HYSTERESIS_DEFAULT 3
|
#define HEATER_HYSTERESIS_DEFAULT 3
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ArduinoComIF.cpp
|
* ArduinoComIF.cpp
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -76,8 +76,8 @@ ReturnValue_t ArduinoComIF::initializeInterface(CookieIF *cookie) {
|
|||||||
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
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
|
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
||||||
|
|
||||||
tty.c_cc[VTIME] = 16; // Wait for up to 16 ds (Arduino measurement cycle time), returning as soon as any data is received.
|
tty.c_cc[VTIME] = 0; // No blocking time (Arduino complete measurement cycle time is 16 ds)
|
||||||
tty.c_cc[VMIN] = 255; // limit number of bytes which can be read in one time by Linux serial port
|
tty.c_cc[VMIN] = 255; // Limit number of bytes which can be read in one time by Linux serial port
|
||||||
|
|
||||||
// Set in/out baud rate to be 115200 bps (same of Arduino)
|
// Set in/out baud rate to be 115200 bps (same of Arduino)
|
||||||
cfsetispeed(&tty, B115200);
|
cfsetispeed(&tty, B115200);
|
||||||
@ -116,36 +116,50 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
uint8_t **buffer, size_t *size) {
|
uint8_t **buffer, size_t *size) {
|
||||||
ArduinoCookie *Cookie = dynamic_cast<ArduinoCookie*>(cookie);
|
ArduinoCookie *Cookie = dynamic_cast<ArduinoCookie*>(cookie);
|
||||||
|
|
||||||
// The buffer array to store the data read are initialized.
|
/* Afterward, the buffer array to store the data read are initialized.
|
||||||
// The whole data packet to be read is 2580 bytes, but the limit for one reading (VMAX) is 255 bytes.
|
* The whole data packet to be read is 2580 bytes, the limit for one reading (VMAX) is 255 bytes.
|
||||||
// Therefore the reading is divided in 11 separate stages which employ 11 different buffer array.
|
* In order to avoid problems during the acquisition of data in the framework, the buffer is set to
|
||||||
// At the end these 11 arrays are concatenated in the main buffer array read_buf.
|
* be 3 times the needed dimension: 7740 bytes.
|
||||||
uint8_t read_buf[2580]; // 2580 bytes from SPC serial output
|
* Exploiting then some control loop, the beginning of a full and complete buffer is identified.
|
||||||
uint8_t read_buf1[255]; // 255 bytes
|
* Since the acquisition limit for one reading is of 255 bytes, as mentioned above,
|
||||||
uint8_t read_buf2[255]; // 255 bytes
|
* the reading is divided in 31 separate stages which employ 31 different buffer array.
|
||||||
uint8_t read_buf3[255]; // 255 bytes
|
* At the end these 31 arrays are concatenated in the main buffer array read_buf.
|
||||||
uint8_t read_buf4[255]; // 255 bytes
|
*/
|
||||||
uint8_t read_buf5[255]; // 255 bytes
|
uint8_t read_buf[7740]; // 7740 bytes from SPC serial output
|
||||||
uint8_t read_buf6[255]; // 255 bytes
|
// Intermediate buffers (limit for one single read call is 255 bytes)
|
||||||
uint8_t read_buf7[255]; // 255 bytes
|
uint8_t read_buf1[255]; uint8_t read_buf2[255]; uint8_t read_buf3[255];
|
||||||
uint8_t read_buf8[255]; // 255 bytes
|
uint8_t read_buf4[255]; uint8_t read_buf5[255]; uint8_t read_buf6[255];
|
||||||
uint8_t read_buf9[255]; // 255 bytes
|
uint8_t read_buf7[255]; uint8_t read_buf8[255]; uint8_t read_buf9[255];
|
||||||
uint8_t read_buf10[255]; // 255 bytes
|
uint8_t read_buf10[255]; uint8_t read_buf11[255]; uint8_t read_buf12[255];
|
||||||
uint8_t read_buf11[30]; // 30 bytes
|
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 initially set to 0.
|
||||||
memset(&read_buf, '\0', sizeof(read_buf));
|
memset(&read_buf, '\0', sizeof(read_buf));
|
||||||
memset(&read_buf1, '\0', sizeof(read_buf1));
|
memset(&read_buf1, '\0', 255); memset(&read_buf2, '\0', 255); memset(&read_buf3, '\0', 255);
|
||||||
memset(&read_buf2, '\0', sizeof(read_buf2));
|
memset(&read_buf4, '\0', 255); memset(&read_buf5, '\0', 255); memset(&read_buf6, '\0', 255);
|
||||||
memset(&read_buf3, '\0', sizeof(read_buf3));
|
memset(&read_buf7, '\0', 255); memset(&read_buf8, '\0', 255); memset(&read_buf9, '\0', 255);
|
||||||
memset(&read_buf4, '\0', sizeof(read_buf4));
|
memset(&read_buf10, '\0', 255); memset(&read_buf11, '\0', 255); memset(&read_buf12, '\0', 255);
|
||||||
memset(&read_buf5, '\0', sizeof(read_buf5));
|
memset(&read_buf13, '\0', 255); memset(&read_buf14, '\0', 255); memset(&read_buf15, '\0', 255);
|
||||||
memset(&read_buf6, '\0', sizeof(read_buf6));
|
memset(&read_buf16, '\0', 255); memset(&read_buf17, '\0', 255); memset(&read_buf18, '\0', 255);
|
||||||
memset(&read_buf7, '\0', sizeof(read_buf7));
|
memset(&read_buf19, '\0', 255); memset(&read_buf20, '\0', 255); memset(&read_buf21, '\0', 255);
|
||||||
memset(&read_buf8, '\0', sizeof(read_buf8));
|
memset(&read_buf22, '\0', 255); memset(&read_buf23, '\0', 255); memset(&read_buf24, '\0', 255);
|
||||||
memset(&read_buf9, '\0', sizeof(read_buf9));
|
memset(&read_buf25, '\0', 255); memset(&read_buf26, '\0', 255); memset(&read_buf27, '\0', 255);
|
||||||
memset(&read_buf10, '\0', sizeof(read_buf10));
|
memset(&read_buf28, '\0', 255); memset(&read_buf29, '\0', 255); memset(&read_buf30, '\0', 255);
|
||||||
memset(&read_buf11, '\0', sizeof(read_buf11));
|
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?)
|
// 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.
|
// depends on the configuration settings above, specifically VMIN and VTIME.
|
||||||
@ -160,9 +174,61 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
int num_bytes9 = read(Cookie->Serial_port_number, &read_buf9, sizeof(read_buf9));
|
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_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_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
|
int num_bytes = num_bytes1 + num_bytes2 + num_bytes3 + num_bytes4
|
||||||
+ num_bytes5 + num_bytes6 + num_bytes7 + num_bytes8
|
+ num_bytes5 + num_bytes6 + num_bytes7 + num_bytes8
|
||||||
+ num_bytes9 + num_bytes10 + num_bytes11;
|
+ 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;*/
|
||||||
|
|
||||||
// The 11 buffer arrays are here concatenated in one single vector.
|
// The 11 buffer arrays are here concatenated in one single vector.
|
||||||
std::copy(read_buf1, read_buf1 + 255, read_buf);
|
std::copy(read_buf1, read_buf1 + 255, read_buf);
|
||||||
@ -175,7 +241,48 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
std::copy(read_buf8, read_buf8 + 255, read_buf + 7 * 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_buf9, read_buf9 + 255, read_buf + 8 * 255);
|
||||||
std::copy(read_buf10, read_buf10 + 255, read_buf + 9 * 255);
|
std::copy(read_buf10, read_buf10 + 255, read_buf + 9 * 255);
|
||||||
std::copy(read_buf11, read_buf11 + 30, read_buf + 10 * 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 + 255, read_buf + 20 * 255);
|
||||||
|
std::copy(read_buf22, read_buf22 + 255, read_buf + 21 * 255);
|
||||||
|
std::copy(read_buf23, read_buf23 + 255, read_buf + 22 * 255);
|
||||||
|
std::copy(read_buf24, read_buf24 + 255, read_buf + 23 * 255);
|
||||||
|
std::copy(read_buf25, read_buf25 + 255, read_buf + 24 * 255);
|
||||||
|
std::copy(read_buf26, read_buf26 + 255, read_buf + 25 * 255);
|
||||||
|
std::copy(read_buf27, read_buf27 + 255, read_buf + 26 * 255);
|
||||||
|
std::copy(read_buf28, read_buf28 + 255, read_buf + 27 * 255);
|
||||||
|
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).
|
// num_bytes is the number of bytes read (n=0: no bytes received, n=-1: error).
|
||||||
if (num_bytes < 0) {
|
if (num_bytes < 0) {
|
||||||
@ -185,9 +292,48 @@ ReturnValue_t ArduinoComIF::readReceivedMessage(CookieIF *cookie,
|
|||||||
|
|
||||||
printf("Read %i bytes.\n", num_bytes);
|
printf("Read %i bytes.\n", num_bytes);
|
||||||
|
|
||||||
|
// Loop to define the adress of the buffer start
|
||||||
|
int first_index = 0;
|
||||||
|
while (first_index < 7740) {
|
||||||
|
if (read_buf[first_index] == 91){
|
||||||
|
if (read_buf[first_index + 3] == 83) {
|
||||||
|
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) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
first_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Definition of buffer array and buffer size to return after reading.
|
// Definition of buffer array and buffer size to return after reading.
|
||||||
*size = 2580;
|
*size = num_bytes;
|
||||||
*buffer = read_buf;
|
*buffer = &read_buf[first_index];
|
||||||
|
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Title: ArduinoComIF.h
|
* Title: ArduinoComIF.h
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -9,14 +9,11 @@
|
|||||||
#ifndef MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_
|
#ifndef MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_
|
||||||
#define MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_
|
#define MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_
|
||||||
|
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
#include <fsfw/ipc/MessageQueueIF.h>
|
#include <fsfw/ipc/MessageQueueIF.h>
|
||||||
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
|
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -24,9 +21,13 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Used to simply return sent data from device handler
|
* @brief Used to initialize the communication Interface (USB connector, serial port) and
|
||||||
* @details Assign this com IF in the factory when creating the device handler
|
* to perform the 4 periodical function described in the DeviceCommunicationIF.
|
||||||
* @ingroup test
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ArduinoComIF: public DeviceCommunicationIF, public SystemObject {
|
class ArduinoComIF: public DeviceCommunicationIF, public SystemObject {
|
||||||
@ -38,12 +39,11 @@ public:
|
|||||||
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData,
|
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData,
|
||||||
size_t sendLen) override;
|
size_t sendLen) override;
|
||||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie,
|
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen)
|
||||||
size_t requestLen) override;
|
override;
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||||
size_t *size) override;
|
size_t *size) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_ */
|
#endif /* MISSION_DEVICEHANDLER_ARDUINOCOMIF_H_ */
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* ArduinoCookie.cpp
|
* ArduinoCookie.cpp
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mission/DeviceHandler/ArduinoCookie.h>
|
#include <mission/DeviceHandler/ArduinoCookie.h>
|
||||||
|
|
||||||
//The cookie tells to device handler which is the device to communicate with if more
|
//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 motherboard, is
|
// devices are connected. In this case only one device, the Arduino board, is
|
||||||
// connected. Therefore the cookie adress and MaxLen are set to default.
|
// connected.
|
||||||
|
|
||||||
ArduinoCookie::ArduinoCookie() {}
|
ArduinoCookie::ArduinoCookie() {
|
||||||
ArduinoCookie::~ArduinoCookie() {}
|
}
|
||||||
|
ArduinoCookie::~ArduinoCookie() {
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* ArduinoCookie.h
|
* ArduinoCookie.h
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -9,21 +9,24 @@
|
|||||||
#ifndef MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_
|
#ifndef MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_
|
||||||
#define MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_
|
#define MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_
|
||||||
|
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/CookieIF.h>
|
#include <fsfw/devicehandlers/CookieIF.h>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Simple cookie which initialize the variables
|
* @brief Simple cookie which initialize the variables
|
||||||
* for the Linux serial port.
|
* for the Linux serial port.
|
||||||
|
* @details The ArduinoCookie is instantiated in the generic factory.
|
||||||
|
* @author: Marco Modè
|
||||||
|
* @ingroup mission/DeviceHandler
|
||||||
*/
|
*/
|
||||||
class ArduinoCookie: public CookieIF {
|
class ArduinoCookie: public CookieIF {
|
||||||
public:
|
public:
|
||||||
ArduinoCookie();
|
ArduinoCookie();
|
||||||
virtual ~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.
|
||||||
int Serial_port_number;
|
int Serial_port_number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_ */
|
#endif /* MISSION_DEVICEHANDLER_ARDUINOCOOKIE_H_ */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* DeviceHandler.cpp
|
* DeviceHandler.cpp
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -12,6 +12,8 @@
|
|||||||
#include <fsfw/datapool/PoolVector.h>
|
#include <fsfw/datapool/PoolVector.h>
|
||||||
#include <bsp_linux/fsfwconfig/datapool/dataPoolInit.h>
|
#include <bsp_linux/fsfwconfig/datapool/dataPoolInit.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <map>
|
||||||
|
//#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
ArduinoDH::ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie) :
|
ArduinoDH::ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie) :
|
||||||
@ -41,6 +43,7 @@ ReturnValue_t ArduinoDH::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
|||||||
|
|
||||||
void ArduinoDH::doTransition(Mode_t modeFrom, Submode_t submodeFrom) {
|
void ArduinoDH::doTransition(Mode_t modeFrom, Submode_t submodeFrom) {
|
||||||
if (mode == _MODE_TO_NORMAL) {
|
if (mode == _MODE_TO_NORMAL) {
|
||||||
|
setMode(_MODE_TO_NORMAL);
|
||||||
std::cout<<"Arduino device is in Normal mode"<<std::endl;
|
std::cout<<"Arduino device is in Normal mode"<<std::endl;
|
||||||
} else {
|
} else {
|
||||||
setMode(_MODE_TO_NORMAL);
|
setMode(_MODE_TO_NORMAL);
|
||||||
@ -58,43 +61,51 @@ void ArduinoDH::fillCommandAndReplyMap() {}
|
|||||||
ReturnValue_t ArduinoDH::scanForReply(const uint8_t *start, size_t len,
|
ReturnValue_t ArduinoDH::scanForReply(const uint8_t *start, size_t len,
|
||||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||||
|
|
||||||
//Unless a command was sent explicitely, we don't expect any replies and ignore
|
// In this case the data are sent from the Arduino board without any command.
|
||||||
//the packet. On a real device, there might be replies which are sent without a previous
|
// No replies of data received are required.
|
||||||
//command.
|
// This function checks the validity of the data packet received.
|
||||||
|
|
||||||
*foundLen = 2580;
|
//*foundLen = 2580;
|
||||||
|
//*foundId = 0xFFFFFF; // assigned here as test
|
||||||
|
*foundLen = len;
|
||||||
|
//DeviceCommandId_t *foundId = 0xFFFFFF;
|
||||||
|
std::map <DeviceCommandId_t, size_t> id {{*foundId, len}};
|
||||||
|
//*foundId = id;
|
||||||
|
|
||||||
// check validity
|
// check validity
|
||||||
if (len == *foundLen){
|
if (len == *foundLen){
|
||||||
// start character: '['
|
// start character: '['
|
||||||
if (*start == 91 ){
|
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;
|
return APERIODIC_REPLY;
|
||||||
} else {
|
} else {
|
||||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return IGNORE_REPLY_DATA;
|
return IGNORE_REPLY_DATA;
|
||||||
}
|
}
|
||||||
/*if (len == *foundLen){
|
|
||||||
// start character: '['
|
|
||||||
if (*start == 91 ){
|
|
||||||
if (*start + 9 == 49) {
|
|
||||||
return APERIODIC_REPLY;
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
return DeviceHandlerIF::LENGTH_MISSMATCH;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return IGNORE_REPLY_DATA;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id,
|
ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id,
|
||||||
const uint8_t *packet) {
|
const uint8_t *packet) {
|
||||||
|
|
||||||
|
DataSet ArduinoDataSet;
|
||||||
|
|
||||||
//sif::debug<<"DEBUG_DH: interprete for reply"<<std::endl;
|
//sif::debug<<"DEBUG_DH: interprete for reply"<<std::endl;
|
||||||
// The data stored in the read buffer are here copied in the variables with the SPC format.
|
// The data stored in the read buffer are here copied in the variables with the SPC format.
|
||||||
// After copying, the data of temperature, environment and accelerometer are stored in three separated vectors.
|
// After copying, the data of temperature, environment and accelerometer are stored in three separated vectors.
|
||||||
|
printf(
|
||||||
|
"\n***********************************************************************************************\n");
|
||||||
|
printf("TEMPERATURE parameters are: ");
|
||||||
for (int i = 0; i < 36; i++) {
|
for (int i = 0; i < 36; i++) {
|
||||||
memcpy(&Temp_ch.start_string, &packet[27 * i + 0], 8);
|
memcpy(&Temp_ch.start_string, &packet[27 * i + 0], 8);
|
||||||
memcpy(&Temp_ch.Typ, &packet[27 * i + 8], 1);
|
memcpy(&Temp_ch.Typ, &packet[27 * i + 8], 1);
|
||||||
@ -103,8 +114,19 @@ ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
memcpy(&Temp_ch.temperature, &packet[27 * i + 11], 4);
|
memcpy(&Temp_ch.temperature, &packet[27 * i + 11], 4);
|
||||||
memcpy(&Temp_ch.Timestamp, &packet[27 * i + 15], 4);
|
memcpy(&Temp_ch.Timestamp, &packet[27 * i + 15], 4);
|
||||||
memcpy(&Temp_ch.end_string, &packet[27 * i + 19], 8);
|
memcpy(&Temp_ch.end_string, &packet[27 * i + 19], 8);
|
||||||
|
// The data are here printed (useful for tests).
|
||||||
|
printf("\n\nStart: %7s", Temp_ch.start_string);
|
||||||
|
printf("\nTyp: %u", Temp_ch.Typ);
|
||||||
|
printf("\nSPCChNumber: %u", Temp_ch.SPCChNumber);
|
||||||
|
printf("\nValue_Cnt: %u", Temp_ch.Value_Cnt);
|
||||||
|
printf("\nTemperature: %f", Temp_ch.temperature);
|
||||||
|
printf("\nTimestamp: %u", Temp_ch.Timestamp);
|
||||||
|
printf("\nEnd: %7s", Temp_ch.end_string);
|
||||||
vecTemp.emplace_back(Temp_ch);
|
vecTemp.emplace_back(Temp_ch);
|
||||||
}
|
}
|
||||||
|
printf(
|
||||||
|
"\n\n***********************************************************************************************\n");
|
||||||
|
printf("ENVIRONMENTAL parameters are: ");
|
||||||
for (int j = 0; j < 9; j++) {
|
for (int j = 0; j < 9; j++) {
|
||||||
memcpy(&Env_ch.start_string, &packet[27 * (36 + j) + 0], 8);
|
memcpy(&Env_ch.start_string, &packet[27 * (36 + j) + 0], 8);
|
||||||
memcpy(&Env_ch.Typ, &packet[27 * (36 + j) + 8], 1);
|
memcpy(&Env_ch.Typ, &packet[27 * (36 + j) + 8], 1);
|
||||||
@ -113,136 +135,85 @@ ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
memcpy(&Env_ch.Value, &packet[27 * (36 + j) + 11], 4);
|
memcpy(&Env_ch.Value, &packet[27 * (36 + j) + 11], 4);
|
||||||
memcpy(&Env_ch.Timestamp, &packet[27 * (36 + j) + 15], 4);
|
memcpy(&Env_ch.Timestamp, &packet[27 * (36 + j) + 15], 4);
|
||||||
memcpy(&Env_ch.end_string, &packet[27 * (36 + j) + 19], 8);
|
memcpy(&Env_ch.end_string, &packet[27 * (36 + j) + 19], 8);
|
||||||
vecEnv.emplace_back(Env_ch);
|
// The data are here printed (useful for tests).
|
||||||
}
|
if (j == 0 || j == 3 || j == 6){
|
||||||
for (int k = 0; k < 15; k++) {
|
|
||||||
memcpy(&Acc_ch.start_string, &packet[27 * (36 + 9) + 91 * k + 0], 8);
|
|
||||||
memcpy(&Acc_ch.Typ, &packet[27 * (36 + 9) + 91 * k + 8], 1);
|
|
||||||
memcpy(&Acc_ch.SPCChNumber, &packet[27 * (36 + 9) + 91 * k + 9], 1);
|
|
||||||
memcpy(&Acc_ch.Value_Cnt, &packet[27 * (36 + 9) + 91 * k + 10], 1);
|
|
||||||
memcpy(&Acc_ch.Value, &packet[27 * (36 + 9) + 91 * k + 11], 36);
|
|
||||||
memcpy(&Acc_ch.Timestamp, &packet[27 * (36 + 9) + 91 * k + 47], 36);
|
|
||||||
memcpy(&Acc_ch.end_string, &packet[27 * (36 + 9) + 91 * k + 83], 8);
|
|
||||||
vecAcc.emplace_back(Acc_ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
// All data are here printed to monitor from the three vectors of data measurements.
|
|
||||||
/*printf(
|
|
||||||
"\n***********************************************************************************************\n");
|
|
||||||
printf("TEMPERATURE parameters are: ");
|
|
||||||
|
|
||||||
for (int i = 0; i < 36; i++) {
|
|
||||||
printf("\n\nStart: %7s", vecTemp[i].start_string);
|
|
||||||
printf("\nTyp: %u", vecTemp[i].Typ);
|
|
||||||
printf("\nSPCChNumber: %u", vecTemp[i].SPCChNumber);
|
|
||||||
printf("\nValue_Cnt: %u", vecTemp[i].Value_Cnt);
|
|
||||||
printf("\nTemperature: %f", vecTemp[i].temperature);
|
|
||||||
printf("\nTimestamp: %u", vecTemp[i].Timestamp);
|
|
||||||
printf("\nEnd: %7s", vecTemp[i].end_string);
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
"\n\n***********************************************************************************************\n");
|
|
||||||
printf("ENVIRONMENTAL parameters are: ");
|
|
||||||
|
|
||||||
for (int j = 0; j < 3; j++) {
|
|
||||||
printf("\n\nHUMIDITY: ");
|
printf("\n\nHUMIDITY: ");
|
||||||
printf("\nStart: %7s", vecEnv[3 * j].start_string);
|
}
|
||||||
printf("\nTyp: %u", vecEnv[3 * j].Typ);
|
else if (j == 1 || j == 4 || j == 7) {
|
||||||
printf("\nSPCChNumber: %u", vecEnv[3 * j].SPCChNumber);
|
|
||||||
printf("\nValue_Cnt: %u", vecEnv[3 * j].Value_Cnt);
|
|
||||||
printf("\nValue: %f", vecEnv[3 * j].Value);
|
|
||||||
printf("\nTimestamp: %u", vecEnv[3 * j].Timestamp);
|
|
||||||
printf("\nEnd: %7s", vecEnv[3 * j].end_string);
|
|
||||||
|
|
||||||
printf("\n\nPRESSURE: ");
|
printf("\n\nPRESSURE: ");
|
||||||
printf("\nStart: %7s", vecEnv[3 * j + 1].start_string);
|
}
|
||||||
printf("\nTyp: %u", vecEnv[3 * j + 1].Typ);
|
else {
|
||||||
printf("\nSPCChNumber: %u", vecEnv[3 * j + 1].SPCChNumber);
|
|
||||||
printf("\nValue_Cnt: %u", vecEnv[3 * j + 1].Value_Cnt);
|
|
||||||
printf("\nValue: %f", vecEnv[3 * j + 1].Value);
|
|
||||||
printf("\nTimestamp: %u", vecEnv[3 * j + 1].Timestamp);
|
|
||||||
printf("\nEnd: %7s", vecEnv[3 * j + 1].end_string);
|
|
||||||
|
|
||||||
printf("\n\nTEMPERATURE: ");
|
printf("\n\nTEMPERATURE: ");
|
||||||
printf("\nStart: %7s", vecEnv[3 * j + 2].start_string);
|
}
|
||||||
printf("\nTyp: %u", vecEnv[3 * j + 2].Typ);
|
printf("\n\nStart: %7s", Env_ch.start_string);
|
||||||
printf("\nSPCChNumber: %u", vecEnv[3 * j + 2].SPCChNumber);
|
printf("\nTyp: %u", Env_ch.Typ);
|
||||||
printf("\nValue_Cnt: %u", vecEnv[3 * j + 2].Value_Cnt);
|
printf("\nSPCChNumber: %u", Env_ch.SPCChNumber);
|
||||||
printf("\nValue: %f", vecEnv[3 * j + 2].Value);
|
printf("\nValue_Cnt: %u", Env_ch.Value_Cnt);
|
||||||
printf("\nTimestamp: %u", vecEnv[3 * j + 2].Timestamp);
|
printf("\nTemperature: %f", Env_ch.Value);
|
||||||
printf("\nEnd: %7s", vecEnv[3 * j + 2].end_string);
|
printf("\nTimestamp: %u", Env_ch.Timestamp);
|
||||||
|
printf("\nEnd: %7s", Env_ch.end_string);
|
||||||
|
vecEnv.emplace_back(Env_ch);
|
||||||
}
|
}
|
||||||
printf(
|
printf(
|
||||||
"\n\n***********************************************************************************************\n");
|
"\n\n***********************************************************************************************\n");
|
||||||
printf("ACCELEROMETER parameters are: ");
|
printf("ACCELEROMETER parameters are: ");
|
||||||
|
for (int k = 0; k < 15; k++) {
|
||||||
for (int k = 0; k < 5; k++) {
|
memcpy(&Ornt_ch.start_string, &packet[27 * (36 + 9) + 91 * k + 0], 8);
|
||||||
|
memcpy(&Ornt_ch.Typ, &packet[27 * (36 + 9) + 91 * k + 8], 1);
|
||||||
|
memcpy(&Ornt_ch.SPCChNumber, &packet[27 * (36 + 9) + 91 * k + 9], 1);
|
||||||
|
memcpy(&Ornt_ch.Value_Cnt, &packet[27 * (36 + 9) + 91 * k + 10], 1);
|
||||||
|
memcpy(&Ornt_ch.Value, &packet[27 * (36 + 9) + 91 * k + 11], 36);
|
||||||
|
memcpy(&Ornt_ch.Timestamp, &packet[27 * (36 + 9) + 91 * k + 47], 36);
|
||||||
|
memcpy(&Ornt_ch.end_string, &packet[27 * (36 + 9) + 91 * k + 83], 8);
|
||||||
|
// The data are here printed (useful for tests).
|
||||||
switch (k) {
|
switch (k) {
|
||||||
case 0:
|
case 0:
|
||||||
printf("\n\nACCELERATION: ");
|
printf("\n\nACCELERATION: ");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 3:
|
||||||
printf("\n\nGYROSCOPE: ");
|
printf("\n\nGYROSCOPE: ");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 6:
|
||||||
printf("\n\nMAGNETOMETER: ");
|
printf("\n\nMAGNETOMETER: ");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 9:
|
||||||
printf("\n\nLINEAR ACCELERATION: ");
|
printf("\n\nLINEAR ACCELERATION: ");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 12:
|
||||||
printf("\n\nEULER ANGLES: ");
|
printf("\n\nEULER ANGLES: ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (k == 0 || k == 3 || k == 6 || k == 9 || k == 12){
|
||||||
printf("\n\nX ==> ");
|
printf("\n\nX ==> ");
|
||||||
printf("\nStart: %7s", vecAcc[3 * k].start_string);
|
|
||||||
printf("\nTyp: %u", vecAcc[3 * k].Typ);
|
|
||||||
printf("\nSPCChNumber: %u", vecAcc[3 * k].SPCChNumber);
|
|
||||||
printf("\nValue_Cnt: %u", vecAcc[3 * k].Value_Cnt);
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
printf("\nMeasurement number: %d", i);
|
|
||||||
printf("\nValue: %f", vecAcc[3 * k].Value[i]);
|
|
||||||
printf("\nTimestamp: %u", vecAcc[3 * k].Timestamp[i]);
|
|
||||||
}
|
}
|
||||||
printf("\nEnd: %7s", vecAcc[3 * k].end_string);
|
else if (k == 1 || k == 4 || k == 7 || k == 10 || k == 13) {
|
||||||
|
|
||||||
printf("\n\nY ==> ");
|
printf("\n\nY ==> ");
|
||||||
printf("\nStart: %7s", vecAcc[3 * k + 1].start_string);
|
|
||||||
printf("\nTyp: %u", vecAcc[3 * k + 1].Typ);
|
|
||||||
printf("\nSPCChNumber: %u", vecAcc[3 * k + 1].SPCChNumber);
|
|
||||||
printf("\nValue_Cnt: %u", vecAcc[3 * k + 1].Value_Cnt);
|
|
||||||
for (int i = 0; i < 9; i++) {
|
|
||||||
printf("\nMeasurement number: %d", i);
|
|
||||||
printf("\nValue: %f", vecAcc[3 * k + 1].Value[i]);
|
|
||||||
printf("\nTimestamp: %u", vecAcc[3 * k + 1].Timestamp[i]);
|
|
||||||
}
|
}
|
||||||
printf("\nEnd: %7s", vecAcc[3 * k + 1].end_string);
|
else {
|
||||||
|
|
||||||
printf("\n\nZ ==> ");
|
printf("\n\nZ ==> ");
|
||||||
printf("\nStart: %7s", vecAcc[3 * k + 2].start_string);
|
}
|
||||||
printf("\nTyp: %u", vecAcc[3 * k + 2].Typ);
|
printf("\nStart: %7s", Ornt_ch.start_string);
|
||||||
printf("\nSPCChNumber: %u", vecAcc[3 * k + 2].SPCChNumber);
|
printf("\nTyp: %u", Ornt_ch.Typ);
|
||||||
printf("\nValue_Cnt: %u", vecAcc[3 * k + 2].Value_Cnt);
|
printf("\nSPCChNumber: %u", Ornt_ch.SPCChNumber);
|
||||||
|
printf("\nValue_Cnt: %u", Ornt_ch.Value_Cnt);
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
printf("\nMeasurement number: %d", i);
|
printf("\nMeasurement number: %d", i);
|
||||||
printf("\nValue: %f", vecAcc[3 * k + 2].Value[i]);
|
printf("\nValue: %f", Ornt_ch.Value[i]);
|
||||||
printf("\nTimestamp: %u", vecAcc[3 * k + 2].Timestamp[i]);
|
printf("\nTimestamp: %u", Ornt_ch.Timestamp[i]);
|
||||||
}
|
}
|
||||||
printf("\nEnd: %7s", vecAcc[3 * k + 2].end_string);
|
printf("\nEnd: %7s", Ornt_ch.end_string);
|
||||||
}*/
|
vecOrnt.emplace_back(Ornt_ch);
|
||||||
|
}//*/
|
||||||
|
|
||||||
std::cout << "\n\nEnd reading data.\n" << std::endl;
|
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
|
// The data are here written to the data pool where they would be available to be used for other objects
|
||||||
|
|
||||||
DataSet ArduinoDataSet;
|
/*PoolVector <float, 36> TempValueVec(datapool::Temperature_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
||||||
|
|
||||||
PoolVector <float, 36> TempValueVec(datapool::Temperature_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
|
||||||
for (int i = 0; i < 36; i++) {
|
for (int i = 0; i < 36; i++) {
|
||||||
memcpy(&TempValueVec[i], &vecTemp[i].temperature, 4);
|
memcpy(&TempValueVec[i], &vecTemp[i].temperature, 4);
|
||||||
}
|
}
|
||||||
ArduinoDataSet.commit(PoolVariableIF::VALID);
|
ArduinoDataSet.commit(PoolVariableIF::VALID);*/
|
||||||
|
|
||||||
|
|
||||||
/*PoolVector <unsigned int, 36> TempTimeVec(datapool::Temperature_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
/*PoolVector <unsigned int, 36> TempTimeVec(datapool::Temperature_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
||||||
@ -269,14 +240,14 @@ ReturnValue_t ArduinoDH::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
|
|
||||||
PoolVector <float, 15> AccValueVec(datapool::Accelerometer_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
PoolVector <float, 15> AccValueVec(datapool::Accelerometer_value, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
||||||
for (int k = 0; k < 15; k++) {
|
for (int k = 0; k < 15; k++) {
|
||||||
memcpy(&AccValueVec[k], &vecAcc[k].Value, 36);
|
memcpy(&AccValueVec[k], &vecOrnt[k].Value, 36);
|
||||||
}
|
}
|
||||||
ArduinoDataSet.commit(PoolVariableIF::VALID);
|
ArduinoDataSet.commit(PoolVariableIF::VALID);
|
||||||
sif::debug<<"\nDEBUG_DHk1: End of copy to datapool"<<std::endl;
|
sif::debug<<"\nDEBUG_DHk1: End of copy to datapool"<<std::endl;
|
||||||
|
|
||||||
PoolVector <unsigned int, 15> AccTimeVec(datapool::Accelerometer_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
PoolVector <unsigned int, 15> AccTimeVec(datapool::Accelerometer_Timestamp, &ArduinoDataSet, PoolVariableIF::VAR_WRITE);
|
||||||
for (int k = 0; k < 15; k++) {
|
for (int k = 0; k < 15; k++) {
|
||||||
memcpy(&AccTimeVec[k], &vecAcc[k].Timestamp, 36);
|
memcpy(&AccTimeVec[k], &vecOrnt[k].Timestamp, 36);
|
||||||
}
|
}
|
||||||
ArduinoDataSet.commit(PoolVariableIF::VALID);
|
ArduinoDataSet.commit(PoolVariableIF::VALID);
|
||||||
sif::debug<<"\nDEBUG_DHk2: End of copy to datapool"<<std::endl;*/
|
sif::debug<<"\nDEBUG_DHk2: End of copy to datapool"<<std::endl;*/
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* DeviceHandler.h
|
* DeviceHandler.h
|
||||||
*
|
*
|
||||||
* Created on: 02/06/2021
|
* Last Modify: 20/09/2021
|
||||||
* Author: Marco Modè
|
* Author: Marco Modè
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -15,19 +15,13 @@
|
|||||||
#include <fsfw/timemanager/Countdown.h>
|
#include <fsfw/timemanager/Countdown.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Basic device handler to test device commanding without a physical device.
|
* @brief Basic device handler to manage the communication with the Arduino sensor board.
|
||||||
* @details
|
* The data are sent to the serial port of the computer from the Arduino board.
|
||||||
* This test device handler provided a basic demo for the device handler object.
|
* The device handler read and manages these data exploiting the ComIF and the
|
||||||
* It can also be commanded with the following PUS services, using
|
* DeviceHandlerBase functions.
|
||||||
* the specified object ID of the test device handler.
|
* @details The ArduinoDH object is instantiated in the generic factory.
|
||||||
*
|
* @author Marco Modè
|
||||||
* 1. PUS Service 8 - Functional commanding
|
* @ingroup mission/DeviceHandler
|
||||||
* 2. PUS Service 2 - Device access, raw commanding
|
|
||||||
* 3. PUS Service 20 - Parameter Management
|
|
||||||
* 4. PUS Service 3 - Housekeeping
|
|
||||||
|
|
||||||
* @author R. Mueller
|
|
||||||
* @ingroup devices
|
|
||||||
*/
|
*/
|
||||||
class ArduinoDH: public DeviceHandlerBase {
|
class ArduinoDH: public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
@ -44,10 +38,11 @@ public:
|
|||||||
ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie);
|
ArduinoDH(object_id_t objectId, object_id_t comIF, CookieIF *cookie);
|
||||||
virtual ~ ArduinoDH();
|
virtual ~ ArduinoDH();
|
||||||
|
|
||||||
// Definiton of data structure for SPC communication. Three different structures are defined for measurements of:
|
/* Definiton of data structure for SPC communication. Three different structures are defined for measurements of:
|
||||||
// - Temperature,
|
* - Temperature data,
|
||||||
// - Environmental data,
|
* - Environmental data,
|
||||||
// - Accelerometer data.
|
* - Orientation data.
|
||||||
|
*/
|
||||||
struct Temperature {
|
struct Temperature {
|
||||||
char start_string[8];
|
char start_string[8];
|
||||||
uint8_t Typ;
|
uint8_t Typ;
|
||||||
@ -84,7 +79,7 @@ public:
|
|||||||
strncpy(end_string, _end_string, sizeof(end_string) - 1);
|
strncpy(end_string, _end_string, sizeof(end_string) - 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct Accelerometer {
|
struct Orientation {
|
||||||
char start_string[8];
|
char start_string[8];
|
||||||
uint8_t Typ;
|
uint8_t Typ;
|
||||||
uint8_t SPCChNumber;
|
uint8_t SPCChNumber;
|
||||||
@ -92,8 +87,8 @@ public:
|
|||||||
float Value[9]; //max buffer
|
float Value[9]; //max buffer
|
||||||
unsigned int Timestamp[9]; //max buffer
|
unsigned int Timestamp[9]; //max buffer
|
||||||
char end_string[8];
|
char end_string[8];
|
||||||
Accelerometer() = default;
|
Orientation() = default;
|
||||||
Accelerometer(const char *_start_string, uint8_t _Typ,
|
Orientation(const char *_start_string, uint8_t _Typ,
|
||||||
uint8_t _SPCChNumber, uint8_t _Value_Cnt, const float *_Value,
|
uint8_t _SPCChNumber, uint8_t _Value_Cnt, const float *_Value,
|
||||||
const unsigned int *_Timestamp, const char *_end_string) :
|
const unsigned int *_Timestamp, const char *_end_string) :
|
||||||
Typ(_Typ), SPCChNumber(_SPCChNumber), Value_Cnt(_Value_Cnt) {
|
Typ(_Typ), SPCChNumber(_SPCChNumber), Value_Cnt(_Value_Cnt) {
|
||||||
@ -108,7 +103,7 @@ public:
|
|||||||
// during the phase of reading copying data from the buffers
|
// during the phase of reading copying data from the buffers
|
||||||
std::vector<Temperature> vecTemp;
|
std::vector<Temperature> vecTemp;
|
||||||
std::vector<Environmental> vecEnv;
|
std::vector<Environmental> vecEnv;
|
||||||
std::vector<Accelerometer> vecAcc;
|
std::vector<Orientation> vecOrnt;
|
||||||
|
|
||||||
// Three dummy child structures are defined. They are used to store the three
|
// 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
|
// different types of data during the measurement loop and then the data are
|
||||||
@ -118,11 +113,13 @@ public:
|
|||||||
// using the three different structures.
|
// using the three different structures.
|
||||||
Temperature Temp_ch;
|
Temperature Temp_ch;
|
||||||
Environmental Env_ch;
|
Environmental Env_ch;
|
||||||
Accelerometer Acc_ch;
|
Orientation Ornt_ch;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
//#define BUFFER_ID(id, value, msg);
|
||||||
|
|
||||||
|
// DeviceHandlerBase inherited functions.
|
||||||
virtual void doStartUp() override;
|
virtual void doStartUp() override;
|
||||||
virtual void doShutDown() override;
|
virtual void doShutDown() override;
|
||||||
virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id)
|
virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id)
|
||||||
|
Loading…
Reference in New Issue
Block a user