2021-02-17 15:54:48 +01:00
|
|
|
#ifndef MISSION_DEVICES_SYRLINKSHKHANDLER_H_
|
|
|
|
#define MISSION_DEVICES_SYRLINKSHKHANDLER_H_
|
|
|
|
|
|
|
|
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
2021-02-19 11:02:27 +01:00
|
|
|
#include <mission/devices/devicedefinitions/SyrlinksDefinitions.h>
|
2021-02-22 09:24:42 +01:00
|
|
|
#include <string.h>
|
2021-02-17 15:54:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This is the device handler for the syrlinks transceiver. It handles the command
|
|
|
|
* transmission and reading of housekeeping data via the housekeeping interface. The
|
|
|
|
* transmission of telemetry and the reception of telecommands is handled by an additional
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* @author J. Meier
|
|
|
|
*/
|
|
|
|
class SyrlinksHkHandler: public DeviceHandlerBase {
|
|
|
|
public:
|
|
|
|
|
|
|
|
SyrlinksHkHandler(object_id_t objectId, object_id_t comIF,
|
|
|
|
CookieIF * comCookie);
|
|
|
|
virtual ~SyrlinksHkHandler();
|
|
|
|
|
2021-02-22 09:24:42 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets mode to MODE_NORMAL. Can be used for debugging.
|
|
|
|
*/
|
|
|
|
void setModeNormal();
|
|
|
|
|
2021-02-17 15:54:48 +01:00
|
|
|
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;
|
|
|
|
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
|
|
|
LocalDataPoolManager& poolManager) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-02-19 15:41:50 +01:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::SYRLINKS_HANDLER;
|
|
|
|
|
|
|
|
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0);
|
|
|
|
static const ReturnValue_t UART_FRAMIN_OR_PARITY_ERROR_ACK = MAKE_RETURN_CODE(0xA1);
|
|
|
|
static const ReturnValue_t BAD_CHARACTER_ACK = MAKE_RETURN_CODE(0xA2);
|
|
|
|
static const ReturnValue_t BAD_PARAMETER_VALUE_ACK = MAKE_RETURN_CODE(0xA3);
|
|
|
|
static const ReturnValue_t BAD_END_OF_FRAME_ACK = MAKE_RETURN_CODE(0xA4);
|
|
|
|
static const ReturnValue_t UNKNOWN_COMMAND_ID_ACK = MAKE_RETURN_CODE(0xA5);
|
|
|
|
static const ReturnValue_t BAD_CRC_ACK = MAKE_RETURN_CODE(0xA6);
|
|
|
|
static const ReturnValue_t REPLY_WRONG_SIZE = MAKE_RETURN_CODE(0xA7);
|
2021-02-22 09:24:42 +01:00
|
|
|
static const ReturnValue_t MISSING_START_FRAME_CHARACTER = MAKE_RETURN_CODE(0xA8);
|
2021-02-19 15:41:50 +01:00
|
|
|
|
|
|
|
static const uint8_t CRC_INITIAL_VALUE = 0x0;
|
|
|
|
|
2021-02-18 16:16:38 +01:00
|
|
|
std::string resetCommand = "<C04:5A5A:FF41>";
|
|
|
|
std::string readRxStatusRegCommand = "<E00::825B>";
|
|
|
|
std::string setTxModeStandby = "<W04:0040:2B9E>";
|
|
|
|
/** W - write, 04 - 4 bytes in data field, 01 - value, 40 register to write value */
|
|
|
|
std::string setTxModeModulation = "<W04:0140:5D2A>";
|
|
|
|
std::string setTxModeCw = "<W04:1040:81CF>";
|
2021-02-22 09:24:42 +01:00
|
|
|
std::string readTxStatus = "<R02:40:7555>";
|
2021-02-19 15:41:50 +01:00
|
|
|
|
|
|
|
/**
|
2021-02-22 09:24:42 +01:00
|
|
|
* In some cases it is not possible to extract from the received reply the information about
|
|
|
|
* the associated command. This variable is thus used to remember the command id.
|
2021-02-19 15:41:50 +01:00
|
|
|
*/
|
2021-02-22 09:24:42 +01:00
|
|
|
DeviceCommandId_t rememberCommandId = SYRLINKS::NONE;
|
|
|
|
|
|
|
|
SYRLINKS::RxDataset rxDataset;
|
|
|
|
SYRLINKS::TxDataset txDataset;
|
|
|
|
|
|
|
|
uint8_t commandBuffer[SYRLINKS::MAX_COMMAND_SIZE];
|
2021-02-19 15:41:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function converts an uint16_t into its hexadecimal string representation.
|
|
|
|
*
|
2021-02-25 15:53:28 +01:00
|
|
|
* @param intValue The value to convert.
|
2021-02-19 15:41:50 +01:00
|
|
|
*
|
|
|
|
* @return An std::string object containing the hex representation of intValue.
|
|
|
|
*/
|
2021-02-22 09:24:42 +01:00
|
|
|
std::string convertIntToHexString(uint16_t intValue);
|
2021-02-19 15:41:50 +01:00
|
|
|
|
2021-02-25 15:53:28 +01:00
|
|
|
/**
|
|
|
|
* @brief This function converts a hex number represented by to chars to an 8-bit integer.
|
|
|
|
*
|
|
|
|
* @param twoChars Pointer to the two characters representing the hex value.
|
|
|
|
*
|
|
|
|
* @details E.g. when twoChars points to an array with the two characters "A5" then the function
|
|
|
|
* will return 0xA5.
|
|
|
|
* @return The converted integer.
|
|
|
|
*/
|
|
|
|
uint8_t convertHexStringToUint8(char* twoChars);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function converts a hex number represented by 4 chars to an uint16_t.
|
|
|
|
*
|
|
|
|
* @param Pointer to the fourCharacters representing the 16-bit integer.
|
|
|
|
*
|
|
|
|
* @return The uint16_t result.
|
|
|
|
*/
|
|
|
|
uint16_t convertHexStringToUint16(char* fourChars);
|
|
|
|
|
2021-02-19 15:41:50 +01:00
|
|
|
/**
|
|
|
|
* @brief This function parses the status reply
|
|
|
|
* @param status Pointer to the status information.
|
|
|
|
*
|
|
|
|
* @details Some commands reply with a status message giving information about the preceding
|
|
|
|
* command transmission and/or execution was successful.
|
|
|
|
*/
|
2021-02-22 09:24:42 +01:00
|
|
|
ReturnValue_t parseReplyStatus(const char* status);
|
2021-02-19 15:41:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Function verifies the received reply from the syrlinks by recalculating and
|
|
|
|
* comparing the crc.
|
|
|
|
*
|
|
|
|
* @param packet Pointer to the received reply.
|
2021-02-22 09:24:42 +01:00
|
|
|
* @param size Size of the whole packet including the crc and the packet termination
|
|
|
|
* character '>'.
|
2021-02-19 15:41:50 +01:00
|
|
|
*
|
|
|
|
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
|
|
|
|
*/
|
2021-02-22 09:24:42 +01:00
|
|
|
ReturnValue_t verifyReply(const uint8_t* packet, uint8_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function extracts the data from a rx status registers reply and writes the
|
|
|
|
* information to the status registers dataset.
|
|
|
|
* @param packet Pointer to the reply packet.
|
|
|
|
*/
|
|
|
|
void parseRxStatusRegistersReply(const uint8_t* packet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function writes the read tx status register to the txStatusDataset.
|
|
|
|
* @param packet Pointer to the received packet.
|
|
|
|
*/
|
|
|
|
void parseTxStatusReply(const uint8_t* packet);
|
2021-02-17 15:54:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MISSION_DEVICES_SYRLINKSHKHANDLER_H_ */
|