/* * DeviceHandler.h * * Last Modify: 20/09/2021 * Author: Marco Modè * */ #ifndef MISSION_DEVICEHANDLER_ARDUINODEVICEHANDLER_H_ #define MISSION_DEVICEHANDLER_ARDUINODEVICEHANDLER_H_ #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: /** * Build the test device in the factory. * @param objectId This ID will be assigned to the test device handler. * @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(); /* Definiton of data structure for SPC communication. Three different structures are defined for measurements of: * - Temperature data, * - Environmental data, * - Orientation data. */ struct Temperature { char start_string[8]; uint8_t Typ; uint8_t SPCChNumber; uint8_t Value_Cnt; float temperature; unsigned int Timestamp; char end_string[8]; Temperature() = default; Temperature(const char *_start_string, uint8_t _Typ, uint8_t _SPCChNumber, uint8_t _Value_Cnt, float _temperature, unsigned int _Timestamp, const char *_end_string) : Typ(_Typ), SPCChNumber(_SPCChNumber), Value_Cnt(_Value_Cnt), temperature( _temperature), Timestamp(_Timestamp) { strncpy(start_string, _start_string, sizeof(start_string) - 1); strncpy(end_string, _end_string, sizeof(end_string) - 1); } }; struct Environmental { char start_string[8]; uint8_t Typ; uint8_t SPCChNumber; uint8_t Value_Cnt; float Value; unsigned int Timestamp; char end_string[8]; Environmental() = default; Environmental(const char *_start_string, uint8_t _Typ, uint8_t _SPCChNumber, uint8_t _Value_Cnt, float _Value, unsigned int _Timestamp, const char *_end_string) : Typ(_Typ), SPCChNumber(_SPCChNumber), Value_Cnt(_Value_Cnt), Value( _Value), Timestamp(_Timestamp) { strncpy(start_string, _start_string, sizeof(start_string) - 1); strncpy(end_string, _end_string, sizeof(end_string) - 1); } }; struct Orientation { char start_string[8]; uint8_t Typ; uint8_t SPCChNumber; uint8_t Value_Cnt; float Value[9]; //max buffer unsigned int Timestamp[9]; //max buffer char end_string[8]; Orientation() = default; Orientation(const char *_start_string, uint8_t _Typ, uint8_t _SPCChNumber, uint8_t _Value_Cnt, const float *_Value, const unsigned int *_Timestamp, const char *_end_string) : Typ(_Typ), SPCChNumber(_SPCChNumber), Value_Cnt(_Value_Cnt) { strncpy(start_string, _start_string, sizeof(start_string) - 1); memcpy(&Value, _Value, sizeof(Value) - 1); memcpy(&Timestamp, _Timestamp, sizeof(Timestamp) - 1); strncpy(end_string, _end_string, sizeof(end_string) - 1); } }; // 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. 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; virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override; virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override; virtual ReturnValue_t buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t *commandData, size_t commandDataLen) override; virtual void fillCommandAndReplyMap() override; virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId, size_t *foundLen) override; virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override; virtual void setNormalDatapoolEntriesInvalid() override; }; #endif /* MISSION_DEVICEHANDLER_ARDUINODEVICEHANDLER_H_ */