eive-obsw/mission/devices/StarTrackerHandler.h

252 lines
8.2 KiB
C
Raw Normal View History

2021-07-07 12:12:01 +02:00
#ifndef MISSION_DEVICES_STARTRACKERHANDLER_H_
#define MISSION_DEVICES_STARTRACKERHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
2021-11-26 09:14:41 +01:00
#include <fsfw/src/fsfw/serialize/SerializeAdapter.h>
2021-07-07 12:12:01 +02:00
#include <mission/devices/devicedefinitions/StarTrackerDefinitions.h>
#include <thirdparty/arcsec_star_tracker/common/SLIP.h>
2021-11-27 19:40:52 +01:00
#include <fsfw/datapool/PoolReadGuard.h>
2021-07-07 12:12:01 +02:00
/**
* @brief This is the device handler for the star tracker from arcsec.
*
* @details Datasheet: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/
* Arbeitsdaten/08_Used%20Components/ArcSec_KULeuven_Startracker/
* Sagitta%201.0%20Datapack&fileid=659181
* @author J. Meier
*/
class StarTrackerHandler: public DeviceHandlerBase {
public:
/**
* @brief Constructor
*
* @param objectId
* @param comIF
* @param comCookie
* @param gpioComIF Pointer to gpio communication interface
* @param enablePin GPIO connected to the enable pin of the reaction wheels. Must be pulled
* to high to enable the device.
*/
StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie);
virtual ~StarTrackerHandler();
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;
/**
* @brief Overwritten here to always read all available data from the UartComIF.
*/
virtual size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HANDLER;
//! [EXPORT] : [COMMENT] Received reply is too short
static const ReturnValue_t REPLY_TOO_SHORT = MAKE_RETURN_CODE(0xB0);
//! [EXPORT] : [COMMENT] Received reply with invalid CRC
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xB0);
2021-07-07 12:12:01 +02:00
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HANDLER;
2021-11-27 19:40:52 +01:00
//! [EXPORT] : [COMMENT] Status in temperature reply signals error
static const ReturnValue_t TEMPERATURE_REQ_FAILED = MAKE_RETURN_CODE(0xA0);
2021-11-26 13:16:05 +01:00
//! [EXPORT] : [COMMENT] Ping command failed
static const ReturnValue_t PING_FAILED = MAKE_RETURN_CODE(0xA1);
2021-11-27 19:40:52 +01:00
//! [EXPORT] : [COMMENT] Status in version reply signals error
static const ReturnValue_t VERSION_REQ_FAILED = MAKE_RETURN_CODE(0xA3);
//! [EXPORT] : [COMMENT] Status in interface reply signals error
static const ReturnValue_t INTERFACE_REQ_FAILED = MAKE_RETURN_CODE(0xA4);
//! [EXPORT] : [COMMENT] Status in power reply signals error
static const ReturnValue_t POWER_REQ_FAILED = MAKE_RETURN_CODE(0xA5);
//! [EXPORT] : [COMMENT] Status of reply to parameter set command signals error
static const ReturnValue_t SET_PARAM_FAILED = MAKE_RETURN_CODE(0xA6);
//! [EXPORT] : [COMMENT] Status of reply to action command signals error
static const ReturnValue_t ACTION_FAILED = MAKE_RETURN_CODE(0xA7);
static const uint8_t STATUS_OFFSET = 2;
static const uint8_t TICKS_OFFSET = 3;
static const uint8_t TIME_OFFSET = 7;
static const uint8_t TM_DATA_FIELD_OFFSET = 15;
static const uint8_t PARAMETER_ID_OFFSET = 1;
static const uint8_t ACTION_ID_OFFSET = 1;
2021-11-26 09:14:41 +01:00
// Ping request will reply ping with this ID (data field)
static const uint32_t PING_ID = 0x55;
2021-11-27 19:40:52 +01:00
static const uint32_t BOOT_REGION_ID = 1;
2021-07-07 12:12:01 +02:00
static const MutexIF::TimeoutType TIMEOUT_TYPE= MutexIF::TimeoutType::WAITING;
static const uint32_t MUTEX_TIMEOUT = 20;
2021-07-07 12:12:01 +02:00
StarTracker::TemperatureSet temperatureSet;
2021-11-26 15:24:52 +01:00
StarTracker::VersionSet versionSet;
2021-11-27 19:40:52 +01:00
StarTracker::PowerSet powerSet;
StarTracker::InterfaceSet interfaceSet;
StarTracker::TimeSet timeSet;
StarTracker::SolutionSet solutionSet;
2021-07-07 12:12:01 +02:00
uint8_t commandBuffer[StarTracker::MAX_FRAME_SIZE];
uint8_t rxBuffer[StarTracker::MAX_FRAME_SIZE];
uint8_t decodedFrame[StarTracker::MAX_FRAME_SIZE];
2021-07-07 12:12:01 +02:00
/** Size of buffer derived from the egse source code */
uint8_t encBuffer[StarTracker::MAX_FRAME_SIZE * 2 + 2];
2021-07-07 12:12:01 +02:00
slip_decode_state slipInfo;
2021-07-07 12:12:01 +02:00
enum class InternalState {
TEMPERATURE_REQUEST
};
InternalState internalState = InternalState::TEMPERATURE_REQUEST;
/**
* @brief This function initializes the serial link ip protocol struct slipInfo.
*/
void slipInit();
2021-11-27 19:40:52 +01:00
ReturnValue_t scanForActionReply(DeviceCommandId_t *foundId);
ReturnValue_t scanForSetParameterReply(DeviceCommandId_t *foundId);
ReturnValue_t scanForTmReply(DeviceCommandId_t *foundId);
2021-11-26 09:14:41 +01:00
/**
* @brief Fills command buffer with data to ping the star tracker
*/
void preparePingRequest();
2021-11-26 13:16:05 +01:00
2021-11-27 19:40:52 +01:00
/**
* @brief Fills command buffer with data to request the time telemetry.
*/
void prepareTimeRequest();
/**
* @brief Fills command buffer with data to boot image (works only when star tracker is
* in bootloader mode).
*/
void prepareBootCommand();
2021-11-26 15:24:52 +01:00
/**
* @brief Fills command buffer with data to request the version telemetry packet
*/
void prepareVersionRequest();
2021-11-27 19:40:52 +01:00
/**
* @brief Fills the command buffer with data to request the interface telemetry packet.
*/
void prepareInterfaceRequest();
/**
* @brief Fills the command buffer with data to request the power telemetry packet.
*/
void preparePowerRequest();
2021-11-26 13:16:05 +01:00
/**
* @brief Fills command buffer with data to reboot star tracker.
*/
void prepareRebootCommand();
2021-11-27 19:40:52 +01:00
/**
* @brief Fills command buffer with data to subscribe to a telemetry packet.
*
* @param tmId The ID of the telemetry packet to subscribe to
*/
void prepareSubscriptionCommand(const uint8_t* tmId);
/**
* @brief Fills command buffer with data to request solution telemtry packet (contains
* attitude information)
*/
void prepareSolutionRequest();
2021-11-26 09:14:41 +01:00
/**
* @brief Fills command buffer with data to request temperature from star tracker
*/
void prepareTemperatureRequest();
2021-07-07 12:12:01 +02:00
2021-11-27 19:40:52 +01:00
/**
* @brief Default function to handle action replies
*/
ReturnValue_t handleActionReply();
/**
* @brief Handles all set parameter replies
*/
ReturnValue_t handleSetParamReply();
2021-11-26 13:16:05 +01:00
ReturnValue_t handlePingReply();
2021-11-27 19:40:52 +01:00
/**
* @brief Fills the time set with the data of the time request reply.
*/
ReturnValue_t handleTimeTm();
/**
* @brief Handles reply data of solution request.
*/
ReturnValue_t handleSolutionTm();
2021-07-07 12:12:01 +02:00
/**
* @brief This function handles the telemetry reply of a temperature request.
*/
2021-11-26 13:16:05 +01:00
ReturnValue_t handleTemperatureTm();
2021-11-26 15:24:52 +01:00
/**
* @brief This function handles the telemetry reply of a version request.
*/
ReturnValue_t handleVersionTm();
2021-11-27 19:40:52 +01:00
/**
* @brief Handles reply to request interface telemetry command.
*/
ReturnValue_t handleInterfaceTm();
/**
* @brief Handles reply to request power telemetry command.
*/
ReturnValue_t handlePowerTm();
/**
* @brief Extracts the header data of a received telemetry frame
*/
void getTmHeaderData(uint8_t* status, uint32_t* ticks, uint64_t* time);
/**
* @brief This function deserializes 8 bytes into a 32 bit unsigned integer.
*
* @param buffer Pointer to buffer holding the data to deserialize
*
* @return The 32-bit unsigned integer.
*
* @note Deserialization will be performed in little endian byte order
*/
uint32_t deserializeUint32(uint8_t* buffer);
/**
* @brief This function deserializes 8 bytes into a 64 bit unsigned integer.
*
* @param buffer Pointer to buffer holding the data to deserialize
*
* @return The 64-bit unsigned integer.
*
* @note Deserialization will be performed in little endian byte order
*/
uint64_t deserializeUint64(uint8_t* buffer);
2021-07-07 12:12:01 +02:00
};
#endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */