eive-obsw/mission/devices/RwHandler.h

153 lines
5.4 KiB
C
Raw Normal View History

2021-06-21 09:50:26 +02:00
#ifndef MISSION_DEVICES_RWHANDLER_H_
#define MISSION_DEVICES_RWHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
2022-04-22 11:29:51 +02:00
#include <fsfw_hal/common/gpio/gpioDefinitions.h>
2023-02-15 17:02:22 +01:00
#include <mission/devices/devicedefinitions/rwHelpers.h>
2021-06-21 09:50:26 +02:00
#include <string.h>
2022-09-14 13:44:43 +02:00
#include "events/subsystemIdRanges.h"
#include "returnvalues/classIds.h"
2023-02-14 18:41:43 +01:00
static constexpr bool ACTUATION_WIRETAPPING = false;
2023-02-10 13:16:50 +01:00
2022-04-22 11:29:51 +02:00
class GpioIF;
2021-06-21 09:50:26 +02:00
/**
* @brief This is the device handler for the reaction wheel from nano avionics.
*
* @details Datasheet: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/
* Arbeitsdaten/08_Used%20Components/Nanoavionics_Reactionwheels&fileid=181622
*
* @note Values are transferred in little endian format.
*
* @author J. Meier
*/
2022-01-17 15:58:27 +01:00
class RwHandler : 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.
*/
2022-04-22 11:29:51 +02:00
RwHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, GpioIF* gpioComIF,
2023-02-14 18:41:43 +01:00
gpioId_t enableGpio, uint8_t rwIdx);
2022-04-26 10:37:25 +02:00
void setDebugMode(bool enable);
2022-01-17 15:58:27 +01:00
virtual ~RwHandler();
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;
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
2023-02-16 16:54:58 +01:00
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
2022-01-17 15:58:27 +01:00
private:
//! [EXPORT] : [COMMENT] Action Message with invalid speed was received. Valid speeds must be in
//! the range of [-65000; 1000] or [1000; 65000]
static const ReturnValue_t INVALID_SPEED = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Action Message with invalid ramp time was received.
static const ReturnValue_t INVALID_RAMP_TIME = MAKE_RETURN_CODE(0xA1);
//! [EXPORT] : [COMMENT] Received set speed command has invalid length. Should be 6.
static const ReturnValue_t SET_SPEED_COMMAND_INVALID_LENGTH = MAKE_RETURN_CODE(0xA2);
//! [EXPORT] : [COMMENT] Command execution failed
static const ReturnValue_t EXECUTION_FAILED = MAKE_RETURN_CODE(0xA3);
//! [EXPORT] : [COMMENT] Reaction wheel reply has invalid crc
static const ReturnValue_t CRC_ERROR = MAKE_RETURN_CODE(0xA4);
2023-02-17 02:10:08 +01:00
static const ReturnValue_t VALUE_NOT_READ = MAKE_RETURN_CODE(0xA5);
2022-01-17 15:58:27 +01:00
2022-04-22 11:29:51 +02:00
GpioIF* gpioComIF = nullptr;
2022-01-17 15:58:27 +01:00
gpioId_t enableGpio = gpio::NO_GPIO;
2022-04-26 10:37:25 +02:00
bool debugMode = false;
2022-01-17 15:58:27 +01:00
2023-02-15 17:02:22 +01:00
rws::StatusSet statusSet;
rws::LastResetSatus lastResetStatusSet;
rws::TmDataset tmDataset;
rws::RwSpeedActuationSet rwSpeedActuationSet;
2022-01-17 15:58:27 +01:00
2023-02-16 14:10:59 +01:00
uint8_t commandBuffer[32];
2023-02-14 18:41:43 +01:00
uint8_t rwIdx;
2022-01-17 15:58:27 +01:00
2023-02-14 18:41:43 +01:00
PoolEntry<int32_t> rwSpeed = PoolEntry<int32_t>({0});
PoolEntry<uint16_t> rampTime = PoolEntry<uint16_t>({10});
2023-02-09 17:11:23 +01:00
enum class InternalState {
2023-02-16 14:10:59 +01:00
DEFAULT,
GET_TM,
INIT_RW_CONTROLLER,
RESET_MCU,
// GET_RESET_STATUS,
// CLEAR_RESET_STATUS,
// READ_TEMPERATURE,
// SET_SPEED,
// GET_RW_SATUS
};
2022-01-17 15:58:27 +01:00
2023-02-16 14:10:59 +01:00
InternalState internalState = InternalState::DEFAULT;
2022-01-17 15:58:27 +01:00
/**
* @brief This function can be used to build commands which do not contain any data apart
* from the command id and the CRC.
* @param commandId The command id of the command to build.
*/
2023-02-16 14:10:59 +01:00
// void prepareSimpleCommand(DeviceCommandId_t id);
2022-01-17 15:58:27 +01:00
/**
* @brief This function checks if the receiced speed and ramp time to set are in a valid
* range.
2022-08-24 17:27:47 +02:00
* @return returnvalue::OK if successful, otherwise error code.
2022-01-17 15:58:27 +01:00
*/
2023-02-10 13:16:50 +01:00
ReturnValue_t checkSpeedAndRampTime();
2022-01-17 15:58:27 +01:00
/**
2023-02-10 13:16:50 +01:00
* @brief This function prepares the set speed command from the dataSet received with
* an action message or set in the software.
* @return returnvalue::OK if successful, otherwise error code.
2022-01-17 15:58:27 +01:00
*/
2023-02-16 14:10:59 +01:00
// ReturnValue_t prepareSetSpeedCmd();
2022-01-17 15:58:27 +01:00
/**
* @brief This function writes the last reset status retrieved with the get last reset status
* command into the reset status dataset.
*
* @param packet Pointer to the buffer holding the reply data.
*/
void handleResetStatusReply(const uint8_t* packet);
/**
* @brief This function handles the reply of the get temperature command.
*
* @param packet Pointer to the reply data
*/
void handleTemperatureReply(const uint8_t* packet);
/**
* @brief This function fills the status set with the data from the get-status-reply.
*/
void handleGetRwStatusReply(const uint8_t* packet);
/**
* @brief This function fills the tmDataset with the reply data requested with get telemetry
* command.
*/
void handleGetTelemetryReply(const uint8_t* packet);
2021-06-21 09:50:26 +02:00
};
#endif /* MISSION_DEVICES_RWHANDLER_H_ */