2021-03-17 11:14:48 +01:00
# ifndef MISSION_DEVICES_IMTQHANDLER_H_
# define MISSION_DEVICES_IMTQHANDLER_H_
# include <fsfw/devicehandlers/DeviceHandlerBase.h>
# include <mission/devices/devicedefinitions/IMTQHandlerDefinitions.h>
# include <string.h>
/**
* @ brief This is the device handler for the ISIS Magnetorquer iMTQ .
*
* @ author J . Meier
*/
class IMTQHandler : public DeviceHandlerBase {
public :
2021-03-26 13:55:32 +01:00
IMTQHandler ( object_id_t objectId , object_id_t comIF , CookieIF * comCookie ) ;
2021-03-17 11:14:48 +01:00
virtual ~ IMTQHandler ( ) ;
/**
* @ brief Sets mode to MODE_NORMAL . Can be used for debugging .
*/
void setModeNormal ( ) ;
protected :
void doStartUp ( ) override ;
void doShutDown ( ) override ;
ReturnValue_t buildNormalDeviceCommand ( DeviceCommandId_t * id ) override ;
ReturnValue_t buildTransitionDeviceCommand ( DeviceCommandId_t * id ) override ;
void fillCommandAndReplyMap ( ) override ;
ReturnValue_t buildCommandFromCommand ( DeviceCommandId_t deviceCommand ,
const uint8_t * commandData , size_t commandDataLen ) override ;
ReturnValue_t scanForReply ( const uint8_t * start , size_t remainingSize ,
DeviceCommandId_t * foundId , size_t * foundLen ) override ;
ReturnValue_t interpretDeviceReply ( DeviceCommandId_t id ,
const uint8_t * packet ) override ;
void setNormalDatapoolEntriesInvalid ( ) override ;
2021-06-12 15:45:24 +02:00
virtual LocalPoolDataSetBase * getDataSetHandle ( sid_t sid ) override ;
2021-03-17 11:14:48 +01:00
uint32_t getTransitionDelayMs ( Mode_t modeFrom , Mode_t modeTo ) override ;
ReturnValue_t initializeLocalDataPool ( localpool : : DataPool & localDataPoolMap ,
LocalDataPoolManager & poolManager ) override ;
private :
static const uint8_t INTERFACE_ID = CLASS_ID : : IMTQ_HANDLER ;
static const ReturnValue_t INVALID_COMMAND_CODE = MAKE_RETURN_CODE ( 0xA0 ) ;
static const ReturnValue_t PARAMETER_MISSING = MAKE_RETURN_CODE ( 0xA1 ) ;
static const ReturnValue_t PARAMETER_INVALID = MAKE_RETURN_CODE ( 0xA2 ) ;
static const ReturnValue_t CC_UNAVAILABLE = MAKE_RETURN_CODE ( 0xA3 ) ;
static const ReturnValue_t INTERNAL_PROCESSING_ERROR = MAKE_RETURN_CODE ( 0xA4 ) ;
static const ReturnValue_t REJECTED_WITHOUT_REASON = MAKE_RETURN_CODE ( 0xA5 ) ;
static const ReturnValue_t CMD_ERR_UNKNOWN = MAKE_RETURN_CODE ( 0xA6 ) ;
2021-06-11 11:53:43 +02:00
//! [EXPORT] : [COMMENT] The status reply to a self test command was received but no self test command has been sent. This should normally never happen.
static const ReturnValue_t UNEXPECTED_SELF_TEST_REPLY = MAKE_RETURN_CODE ( 0xA7 ) ;
2021-03-17 11:14:48 +01:00
2021-06-04 16:45:54 +02:00
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID : : IMTQ_HANDLER ;
//! [EXPORT] : [COMMENT] Get self test result returns I2C failure
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_I2C_FAILURE = MAKE_EVENT ( 1 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns SPI failure. This concerns the MTM connectivity.
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_SPI_FAILURE = MAKE_EVENT ( 2 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns failure in measurement of current and temperature.
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_ADC_FAILURE = MAKE_EVENT ( 3 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns PWM failure which concerns the coil actuation.
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_PWM_FAILURE = MAKE_EVENT ( 4 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns TC failure (system failure)
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_TC_FAILURE = MAKE_EVENT ( 5 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns failure that MTM values were outside of the expected range.
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_MTM_RANGE_FAILURE = MAKE_EVENT ( 6 , severity : : LOW ) ;
//! [EXPORT] : [COMMENT] Get self test result returns failure indicating that the coil current was outside of the expected range
//! P1: Indicates on which axis the failure occurred. 0 -> INIT, 1 -> +X, 2 -> -X, 3 -> +Y, 4 -> -Y, 5 -> +Z, 6 -> -Z, 7 -> FINA
static const Event SELF_TEST_COIL_CURRENT_FAILURE = MAKE_EVENT ( 7 , severity : : LOW ) ;
2021-06-11 11:53:43 +02:00
//! [EXPORT] : [COMMENT] Received invalid error byte. This indicates an error of the communication link between IMTQ and OBC.
static const Event INVALID_ERROR_BYTE = MAKE_EVENT ( 8 , severity : : LOW ) ;
2021-03-17 11:14:48 +01:00
IMTQ : : EngHkDataset engHkDataset ;
2021-04-26 07:56:02 +02:00
IMTQ : : CalibratedMtmMeasurementSet calMtmMeasurementSet ;
IMTQ : : RawMtmMeasurementSet rawMtmMeasurementSet ;
2021-06-11 11:53:43 +02:00
IMTQ : : PosXselfTestSet posXselfTestDataset ;
2021-03-17 11:14:48 +01:00
uint8_t commandBuffer [ IMTQ : : MAX_COMMAND_SIZE ] ;
2021-04-26 07:56:02 +02:00
enum class CommunicationStep {
GET_ENG_HK_DATA ,
START_MTM_MEASUREMENT ,
GET_CAL_MTM_MEASUREMENT ,
GET_RAW_MTM_MEASUREMENT
} ;
CommunicationStep communicationStep = CommunicationStep : : GET_ENG_HK_DATA ;
2021-06-04 16:45:54 +02:00
enum class StartupStep {
2021-06-09 12:00:41 +02:00
NONE ,
2021-06-04 16:45:54 +02:00
COMMAND_SELF_TEST ,
GET_SELF_TEST_RESULT
} ;
StartupStep startupStep = StartupStep : : COMMAND_SELF_TEST ;
2021-06-09 12:00:41 +02:00
bool selfTestPerformed = false ;
2021-06-04 16:45:54 +02:00
2021-06-11 11:53:43 +02:00
/**
* @ brief In case of a status reply to a single axis self test command , this function
* searches for the actual pending command .
*/
ReturnValue_t getSelfTestCommandId ( DeviceCommandId_t * id ) ;
2021-03-17 11:14:48 +01:00
/**
* @ brief Each reply contains a status byte giving information about a request . This function
* parses this byte and returns the associated failure message .
*
* @ param packet Pointer to the received message containing the status byte .
*
* @ return The return code derived from the received status byte .
*/
ReturnValue_t parseStatusByte ( const uint8_t * packet ) ;
/**
* @ brief This function fills the engineering housekeeping dataset with the received data .
* @ param packet Pointer to the received data .
*
*/
void fillEngHkDataset ( const uint8_t * packet ) ;
2021-04-26 07:56:02 +02:00
/**
* @ brief This function sends a command reply to the requesting queue .
*
* @ param data Pointer to the data to send .
* @ param dataSize Size of the data to send .
* @ param relplyId Reply id which will be inserted at the beginning of the action message .
*/
void handleDeviceTM ( const uint8_t * data , size_t dataSize , DeviceCommandId_t replyId ) ;
/**
* @ brief This function handles the reply containing the commanded dipole .
*
* @ param packet Pointer to the reply data .
*/
void handleGetCommandedDipoleReply ( const uint8_t * packet ) ;
/**
* @ brief This function parses the reply containing the calibrated MTM measurement and writes
* the values to the appropriate dataset .
* @ param packet Pointer to the reply data .
*/
void fillCalibratedMtmDataset ( const uint8_t * packet ) ;
/**
* @ brief This function copies the raw MTM measurements to the MTM raw dataset .
* @ param packet Pointer to the reply data requested with the GET_RAW_MTM_MEASUREMENTS
* command .
*/
void fillRawMtmDataset ( const uint8_t * packet ) ;
2021-06-04 16:45:54 +02:00
/**
2021-06-11 11:53:43 +02:00
* @ brief This function handles all self test results . This comprises parsing the error byte
* and step byte and calling the function to fill the respective dataset .
2021-06-04 16:45:54 +02:00
*/
void handleSelfTestReply ( const uint8_t * packet ) ;
2021-06-11 11:53:43 +02:00
/**
* @ brief The following functions fill the respective dataset of the single axis self tests .
* @ param packet Pointer to the reply data holding the self test result .
*/
void handlePositiveXSelfTestReply ( const uint8_t * packet ) ;
2021-06-04 16:45:54 +02:00
/**
* @ brief This function checks the error byte of a self test measurement .
*
* @ param errorByte The received error byte to check
* @ param step The step of the error byte .
*/
void checkErrorByte ( const uint8_t errorByte , const uint8_t step ) ;
std : : string makeStepString ( const uint8_t step ) ;
2021-03-17 11:14:48 +01:00
} ;
# endif /* MISSION_DEVICES_IMTQHANDLER_H_ */