eive-obsw/mission/acs/SusHandler.h
meggert 665b7d95f7
All checks were successful
EIVE/eive-obsw/pipeline/pr-main This commit looks good
actually lets keep this
2023-10-18 13:35:18 +02:00

85 lines
3.2 KiB
C++

#ifndef MISSION_DEVICES_SusHandler_H_
#define MISSION_DEVICES_SusHandler_H_
#include <eive/eventSubsystemIds.h>
#include <eive/resultClassIds.h>
#include <mission/acs/susMax1227Helpers.h>
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
#include "mission/acs/acsBoardPolling.h"
class SusHandler : public DeviceHandlerBase {
public:
static constexpr DeviceCommandId_t REQUEST = 0x70;
static constexpr DeviceCommandId_t REPLY = 0x77;
static const uint8_t INTERFACE_ID = CLASS_ID::SUS_HANDLER;
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SUS_HANDLER;
//! [EXPORT] : [COMMENT] Detected invalid values, starting invalid message counting
static constexpr Event TEMPERATURE_ALL_ONES_START =
event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM);
//! [EXPORT] : [COMMENT] Detected valid values for a prolonged time again, resetting all counters.
//! P1: Number of periods with invalid messages.
//! P2: Maximum invalid message counter.
static constexpr Event TEMPERATURE_ALL_ONES_RECOVERY =
event::makeEvent(SUBSYSTEM_ID, 1, severity::INFO);
SusHandler(uint32_t objectId, uint8_t susIdx, object_id_t deviceCommunication,
CookieIF *comCookie);
virtual ~SusHandler();
void enablePeriodicPrintouts(bool enable, uint8_t divider);
void setToGoToNormalMode(bool enable);
protected:
/** DeviceHandlerBase overrides */
void doShutDown() override;
void doStartUp() override;
uint32_t getTransitionDelayMs(Mode_t from, Mode_t to) override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
size_t commandDataLen) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t len, DeviceCommandId_t *foundId,
size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) override;
void fillCommandAndReplyMap() override;
void modeChanged(void) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) override;
LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override;
private:
susMax1227::SusDataset dataset;
acs::SusRequest request{};
uint8_t susIdx;
// After 1 minute, trigger the event for the invalid messages.
Countdown invalidMsgCountdown = Countdown(60000);
bool waitingForRecovery = true;
uint32_t invalidMsgCounter = 0;
uint32_t invalidMsgCounterMax = 0;
uint32_t invalidMsgPeriodCounter = 0;
uint32_t transitionDelay = 1000;
bool goToNormalMode = false;
PoolEntry<float> tempC = PoolEntry<float>({0.0});
PoolEntry<uint16_t> channelVec = PoolEntry<uint16_t>({0, 0, 0, 0, 0, 0});
enum class InternalState {
NONE,
STARTUP,
SHUTDOWN,
};
InternalState internalState = InternalState::NONE;
bool commandExecuted = false;
ReturnValue_t prepareRequest(acs::SimpleSensorMode mode);
};
#endif /* MISSION_DEVICES_SusHandler_H_ */