2023-01-24 19:11:17 +01:00
|
|
|
#ifndef MISSION_DEVICES_SYRLINKSHANDLER_H_
|
|
|
|
#define MISSION_DEVICES_SYRLINKSHANDLER_H_
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2022-04-07 09:57:52 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2022-03-30 09:19:30 +02:00
|
|
|
#include "devices/powerSwitcherList.h"
|
|
|
|
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
2022-04-01 09:20:35 +02:00
|
|
|
#include "fsfw/timemanager/Countdown.h"
|
2022-04-07 09:57:52 +02:00
|
|
|
#include "fsfw_hal/linux/gpio/Gpio.h"
|
2023-01-26 14:00:39 +01:00
|
|
|
#include "mission/comDefs.h"
|
2022-04-07 09:57:52 +02:00
|
|
|
#include "mission/devices/devicedefinitions/SyrlinksDefinitions.h"
|
2022-09-14 13:44:43 +02:00
|
|
|
#include "returnvalues/classIds.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
|
|
|
|
*/
|
2023-01-24 19:11:17 +01:00
|
|
|
class SyrlinksHandler : public DeviceHandlerBase {
|
2022-01-17 15:58:27 +01:00
|
|
|
public:
|
2023-01-24 19:11:17 +01:00
|
|
|
SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
|
2023-01-24 19:40:27 +01:00
|
|
|
power::Switch_t powerSwitch, FailureIsolationBase* customFdir);
|
2023-01-24 19:11:17 +01:00
|
|
|
virtual ~SyrlinksHandler();
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sets mode to MODE_NORMAL. Can be used for debugging.
|
|
|
|
*/
|
|
|
|
void setModeNormal();
|
|
|
|
|
2022-04-26 10:37:25 +02:00
|
|
|
void setDebugMode(bool enable);
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
protected:
|
|
|
|
void doStartUp() override;
|
|
|
|
void doShutDown() override;
|
2023-01-24 19:40:27 +01:00
|
|
|
void doTransition(Mode_t modeFrom, Submode_t subModeFrom) override;
|
2023-01-25 17:02:46 +01:00
|
|
|
ReturnValue_t isModeCombinationValid(Mode_t mode, Submode_t submode) override;
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
|
|
|
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
|
|
|
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
|
|
|
size_t commandDataLen) override;
|
2022-03-30 09:19:30 +02:00
|
|
|
void fillCommandAndReplyMap() override;
|
2022-01-17 15:58:27 +01:00
|
|
|
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;
|
2022-03-30 09:19:30 +02:00
|
|
|
ReturnValue_t getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) override;
|
2022-01-17 15:58:27 +01:00
|
|
|
void setNormalDatapoolEntriesInvalid() override;
|
|
|
|
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
|
|
|
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
|
|
|
LocalDataPoolManager& poolManager) override;
|
|
|
|
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
|
|
|
|
|
2023-01-26 14:39:23 +01:00
|
|
|
// Parameter IF
|
2023-01-26 14:42:13 +01:00
|
|
|
ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper,
|
|
|
|
const ParameterWrapper* newValues, uint16_t startAtIndex) override;
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
private:
|
|
|
|
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);
|
|
|
|
static const ReturnValue_t MISSING_START_FRAME_CHARACTER = MAKE_RETURN_CODE(0xA8);
|
|
|
|
|
|
|
|
static const uint8_t CRC_INITIAL_VALUE = 0x0;
|
|
|
|
|
2022-03-30 11:25:03 +02:00
|
|
|
// Uses CRC-16/XMODEM
|
2022-01-17 15:58:27 +01:00
|
|
|
std::string resetCommand = "<C04:5A5A:FF41>";
|
|
|
|
std::string readRxStatusRegCommand = "<E00::825B>";
|
|
|
|
std::string setTxModeStandby = "<W04:4000:7E58>";
|
|
|
|
/** W - write, 04 - 4 bytes in data field, 01 - value, 40 register to write value */
|
|
|
|
std::string setTxModeModulation = "<W04:4001:4D69>";
|
2022-04-04 14:58:35 +02:00
|
|
|
std::string configBPSK = "<W04:4007:E7CF>";
|
|
|
|
std::string configOQPSK = "<W04:400B:1063>";
|
2022-06-15 10:37:00 +02:00
|
|
|
std::string setTxModeCw = "<W04:4002:183A>";
|
2022-03-30 16:29:58 +02:00
|
|
|
std::string writeLclConfig = "<W04:0707:3FE4>";
|
2022-04-01 14:15:42 +02:00
|
|
|
std::string setWaveformOQPSK = "<W04:4403:E1FA>";
|
|
|
|
std::string setWaveformBPSK = "<W04:4406:1E0F>";
|
2022-01-17 15:58:27 +01:00
|
|
|
std::string readTxStatus = "<R02:40:7555>";
|
|
|
|
std::string readTxWaveform = "<R02:44:B991>";
|
|
|
|
std::string readTxAgcValueHighByte = "<R02:46:DFF3>";
|
|
|
|
std::string readTxAgcValueLowByte = "<R02:47:ECC2>";
|
2022-03-30 16:29:58 +02:00
|
|
|
std::string readLclConfig = "<R02:07:3002>";
|
2022-03-31 09:11:01 +02:00
|
|
|
std::string tempPowerAmpBoardHighByte = "<R02:C0:28CD>";
|
|
|
|
std::string tempPowerAmpBoardLowByte = "<R02:C1:1BFC>";
|
|
|
|
std::string tempBasebandBoardHighByte = "<R02:C2:4EAF>";
|
|
|
|
std::string tempBasebandBoardLowByte = "<R02:C3:7D9E>";
|
2022-01-17 15:58:27 +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.
|
|
|
|
*/
|
2022-03-31 17:44:29 +02:00
|
|
|
DeviceCommandId_t rememberCommandId = syrlinks::NONE;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2022-03-31 17:44:29 +02:00
|
|
|
syrlinks::RxDataset rxDataset;
|
|
|
|
syrlinks::TxDataset txDataset;
|
|
|
|
syrlinks::TemperatureSet temperatureSet;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2022-03-30 09:19:30 +02:00
|
|
|
const power::Switch_t powerSwitch = power::NO_SWITCH;
|
2023-01-26 14:39:23 +01:00
|
|
|
// Use uint8_t for compatibility with parameter interface
|
|
|
|
uint8_t datarateCfgRaw = static_cast<uint8_t>(com::Datarate::LOW_RATE_MODULATION_BPSK);
|
2023-01-26 14:42:13 +01:00
|
|
|
// com::Datarate datarateCfg = com::Datarate::LOW_RATE_MODULATION_BPSK;
|
2022-03-30 09:19:30 +02:00
|
|
|
|
2022-04-26 10:37:25 +02:00
|
|
|
bool debugMode = false;
|
2022-03-31 09:11:01 +02:00
|
|
|
uint8_t agcValueHighByte = 0;
|
|
|
|
uint16_t rawTempPowerAmplifier = 0;
|
|
|
|
uint16_t rawTempBasebandBoard = 0;
|
|
|
|
float tempPowerAmplifier = 0;
|
|
|
|
float tempBasebandBoard = 0;
|
2023-01-24 19:40:27 +01:00
|
|
|
bool commandExecuted = false;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2022-03-31 17:44:29 +02:00
|
|
|
uint8_t commandBuffer[syrlinks::MAX_COMMAND_SIZE];
|
|
|
|
|
2023-01-24 19:40:27 +01:00
|
|
|
enum class InternalState {
|
|
|
|
OFF,
|
|
|
|
ENABLE_TEMPERATURE_PROTECTION,
|
2023-01-26 12:21:49 +01:00
|
|
|
SELECT_MODULATION_BPSK,
|
|
|
|
SELECT_MODULATION_0QPSK,
|
2023-01-24 19:40:27 +01:00
|
|
|
SET_TX_MODULATION,
|
|
|
|
SET_TX_CW,
|
|
|
|
SET_TX_STANDBY,
|
|
|
|
IDLE
|
|
|
|
};
|
2022-03-31 17:44:29 +02:00
|
|
|
|
2023-01-24 19:40:27 +01:00
|
|
|
InternalState internalState = InternalState::OFF;
|
2022-03-31 17:44:29 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
/**
|
|
|
|
* This object is used to store the id of the next command to execute. This controls the
|
|
|
|
* read out of multiple registers which can not be fetched with one single command.
|
|
|
|
*/
|
2022-03-31 17:44:29 +02:00
|
|
|
DeviceCommandId_t nextCommand = syrlinks::READ_RX_STATUS_REGISTERS;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function converts an uint16_t into its hexadecimal string representation.
|
|
|
|
*
|
|
|
|
* @param intValue The value to convert.
|
|
|
|
*
|
|
|
|
* @return An std::string object containing the hex representation of intValue.
|
|
|
|
*/
|
|
|
|
std::string convertUint16ToHexString(uint16_t intValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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(const 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(const char* fourChars);
|
|
|
|
|
|
|
|
/**
|
2023-01-23 16:18:06 +01:00
|
|
|
* @brief Function converts a hex number represented by 6 or 8 characters to an uint32_t or
|
|
|
|
* int32_t, depending on the template parameter.
|
2022-01-17 15:58:27 +01:00
|
|
|
*
|
|
|
|
* @param characters Pointer to the hex characters array.
|
|
|
|
* @param numberOfChars Number of characters representing the hex value. Must be 6 or 8.
|
|
|
|
*
|
2023-01-23 16:18:06 +01:00
|
|
|
* @return The value.
|
2022-01-17 15:58:27 +01:00
|
|
|
*/
|
2023-01-23 15:35:43 +01:00
|
|
|
template <typename T>
|
2023-01-23 16:18:06 +01:00
|
|
|
T convertHexStringTo32bit(const char* characters, uint8_t numberOfChars);
|
2022-01-17 15:58:27 +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.
|
|
|
|
*/
|
|
|
|
ReturnValue_t parseReplyStatus(const char* status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Function verifies the received reply from the syrlinks by recalculating and
|
|
|
|
* comparing the crc.
|
|
|
|
*
|
|
|
|
* @param packet Pointer to the received reply.
|
|
|
|
* @param size Size of the whole packet including the crc and the packet termination
|
|
|
|
* character '>'.
|
|
|
|
*
|
2022-08-24 17:27:47 +02:00
|
|
|
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED.
|
2022-01-17 15:58:27 +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);
|
|
|
|
|
2022-03-30 16:29:58 +02:00
|
|
|
void parseLclConfigReply(const uint8_t* packet);
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function writes the received waveform configuration to the txDataset.
|
|
|
|
*/
|
|
|
|
void parseTxWaveformReply(const uint8_t* packet);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The agc value is split over two registers. The parse agc functions are used to get
|
|
|
|
* the values from the received reply and write them into the txDataset.
|
|
|
|
*/
|
|
|
|
void parseAgcLowByte(const uint8_t* packet);
|
|
|
|
void parseAgcHighByte(const uint8_t* packet);
|
2022-03-31 09:11:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculates temperature in degree celcius form raw value
|
|
|
|
*/
|
|
|
|
float calcTempVal(uint16_t);
|
2022-03-31 17:44:29 +02:00
|
|
|
|
|
|
|
ReturnValue_t handleAckReply(const uint8_t* packet);
|
2022-04-04 14:58:35 +02:00
|
|
|
|
|
|
|
void prepareCommand(std::string command, DeviceCommandId_t commandId);
|
2021-02-17 15:54:48 +01:00
|
|
|
};
|
|
|
|
|
2023-01-23 15:35:43 +01:00
|
|
|
template <typename T>
|
2023-01-24 19:11:17 +01:00
|
|
|
T SyrlinksHandler::convertHexStringTo32bit(const char* characters, uint8_t numberOfChars) {
|
2023-01-23 16:18:06 +01:00
|
|
|
if (sizeof(T) < 4) {
|
|
|
|
sif::error << "SyrlinksHkHandler::convertHexStringToRaw: Only works for 32-bit conversion"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2023-01-23 15:35:43 +01:00
|
|
|
T value = 0;
|
|
|
|
|
|
|
|
switch (numberOfChars) {
|
|
|
|
case 6:
|
2023-01-23 16:18:06 +01:00
|
|
|
// The bitshift trickery required is necessary when creating an int32_t from a
|
|
|
|
// 24 bit signed value.
|
2023-01-23 15:35:43 +01:00
|
|
|
value = ((convertHexStringToUint8(characters) << 24) |
|
2023-01-23 16:18:06 +01:00
|
|
|
(convertHexStringToUint8(characters + 2) << 16) |
|
|
|
|
(convertHexStringToUint8(characters + 4) << 8)) >>
|
|
|
|
8;
|
2023-01-23 15:35:43 +01:00
|
|
|
return value;
|
|
|
|
case 8:
|
|
|
|
value = convertHexStringToUint8(characters) << 24 |
|
|
|
|
convertHexStringToUint8(characters + 2) << 16 |
|
|
|
|
convertHexStringToUint8(characters + 4) << 8 |
|
|
|
|
convertHexStringToUint8(characters + 4);
|
|
|
|
return value;
|
|
|
|
default:
|
|
|
|
sif::debug << "SyrlinksHkHandler::convertHexStringToUint32: Invalid number of characters. "
|
|
|
|
<< "Must be either 6 or 8" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2023-01-24 19:11:17 +01:00
|
|
|
#endif /* MISSION_DEVICES_SYRLINKSHANDLER_H_ */
|