eive-obsw/mission/devices/RwHandler.cpp

567 lines
26 KiB
C++
Raw Normal View History

2021-06-21 09:50:26 +02:00
#include "RwHandler.h"
#include <fsfw/datapool/PoolReadGuard.h>
2022-01-17 15:58:27 +01:00
#include <fsfw/globalfunctions/CRC.h>
2022-04-22 11:29:51 +02:00
#include <fsfw_hal/common/gpio/GpioIF.h>
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
#include "OBSWConfig.h"
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
RwHandler::RwHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
2022-04-22 11:29:51 +02:00
GpioIF* gpioComIF, gpioId_t enableGpio)
2022-01-17 15:58:27 +01:00
: DeviceHandlerBase(objectId, comIF, comCookie),
gpioComIF(gpioComIF),
enableGpio(enableGpio),
statusSet(this),
lastResetStatusSet(this),
2023-02-10 13:16:50 +01:00
tmDataset(this),
rwSpeedActuationSet(*this) {
2022-04-22 11:29:51 +02:00
if (comCookie == nullptr) {
2022-01-17 15:58:27 +01:00
sif::error << "RwHandler: Invalid com cookie" << std::endl;
}
2022-04-22 11:29:51 +02:00
if (gpioComIF == nullptr) {
2022-01-17 15:58:27 +01:00
sif::error << "RwHandler: Invalid gpio communication interface" << std::endl;
}
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
RwHandler::~RwHandler() {}
2021-06-29 16:08:20 +02:00
2022-01-17 15:58:27 +01:00
void RwHandler::doStartUp() {
internalState = InternalState::GET_RESET_STATUS;
2021-06-29 16:08:20 +02:00
2022-08-24 17:27:47 +02:00
if (gpioComIF->pullHigh(enableGpio) != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high";
}
setMode(_MODE_TO_ON);
2021-06-21 09:50:26 +02:00
}
void RwHandler::doShutDown() {
2022-08-24 17:27:47 +02:00
if (gpioComIF->pullLow(enableGpio) != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to low";
}
setMode(_MODE_POWER_DOWN);
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
switch (internalState) {
2021-06-29 16:08:20 +02:00
case InternalState::GET_RESET_STATUS:
2022-01-17 15:58:27 +01:00
*id = RwDefinitions::GET_LAST_RESET_STATUS;
internalState = InternalState::READ_TEMPERATURE;
break;
2021-06-29 16:08:20 +02:00
case InternalState::READ_TEMPERATURE:
2022-01-17 15:58:27 +01:00
*id = RwDefinitions::GET_TEMPERATURE;
internalState = InternalState::GET_RW_SATUS;
break;
2021-06-29 16:08:20 +02:00
case InternalState::GET_RW_SATUS:
2022-01-17 15:58:27 +01:00
*id = RwDefinitions::GET_RW_STATUS;
internalState = InternalState::GET_RESET_STATUS;
break;
case InternalState::CLEAR_RESET_STATUS:
*id = RwDefinitions::CLEAR_LAST_RESET_STATUS;
/** After reset status is cleared, reset status will be polled again for verification */
internalState = InternalState::GET_RESET_STATUS;
break;
2021-06-21 09:50:26 +02:00
default:
2022-01-17 15:58:27 +01:00
sif::debug << "RwHandler::buildNormalDeviceCommand: Invalid internal step" << std::endl;
break;
}
return buildCommandFromCommand(*id, NULL, 0);
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
return NOTHING_TO_SEND;
2021-06-21 09:50:26 +02:00
}
ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
2022-01-17 15:58:27 +01:00
const uint8_t* commandData,
size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
switch (deviceCommand) {
case (RwDefinitions::RESET_MCU): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
case (RwDefinitions::GET_LAST_RESET_STATUS): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
case (RwDefinitions::CLEAR_LAST_RESET_STATUS): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
}
2021-06-21 09:50:26 +02:00
case (RwDefinitions::GET_RW_STATUS): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2021-06-25 16:00:32 +02:00
case (RwDefinitions::INIT_RW_CONTROLLER): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-25 16:00:32 +02:00
}
2021-06-21 09:50:26 +02:00
case (RwDefinitions::SET_SPEED): {
2023-02-10 13:16:50 +01:00
if (commandData != nullptr && commandDataLen != 6) {
2022-01-17 15:58:27 +01:00
sif::error << "RwHandler::buildCommandFromCommand: Received set speed command with"
<< " invalid length" << std::endl;
return SET_SPEED_COMMAND_INVALID_LENGTH;
}
2023-02-10 13:16:50 +01:00
// Commands override anything which was set in the software
if (commandData != nullptr) {
rwSpeedActuationSet.setValidityBufferGeneration(false);
result = rwSpeedActuationSet.deSerialize(&commandData, &commandDataLen,
SerializeIF::Endianness::NETWORK);
rwSpeedActuationSet.setValidityBufferGeneration(true);
if (result != returnvalue::OK) {
return result;
}
} else {
// Read set rw speed value from local pool
PoolReadGuard pg(&rwSpeedActuationSet);
}
if (ACTUATION_WIRETAPPING) {
int32_t speed;
uint16_t rampTime;
rwSpeedActuationSet.getRwSpeed(speed, rampTime);
sif::debug << "Actuating RW with speed = " << speed << " and rampTime = " << rampTime
<< std::endl;
}
result = checkSpeedAndRampTime();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2021-06-21 09:50:26 +02:00
return result;
2022-01-17 15:58:27 +01:00
}
2023-02-10 13:16:50 +01:00
result = prepareSetSpeedCmd();
2022-01-17 15:58:27 +01:00
return result;
2021-06-21 09:50:26 +02:00
}
case (RwDefinitions::GET_TEMPERATURE): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2021-06-30 08:21:14 +02:00
case (RwDefinitions::GET_TM): {
2022-01-17 15:58:27 +01:00
prepareSimpleCommand(deviceCommand);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-30 08:21:14 +02:00
}
2021-06-21 09:50:26 +02:00
default:
2022-01-17 15:58:27 +01:00
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2021-06-21 09:50:26 +02:00
}
void RwHandler::fillCommandAndReplyMap() {
2022-01-17 15:58:27 +01:00
this->insertInCommandMap(RwDefinitions::RESET_MCU);
this->insertInCommandAndReplyMap(RwDefinitions::GET_LAST_RESET_STATUS, 1, &lastResetStatusSet,
RwDefinitions::SIZE_GET_RESET_STATUS);
this->insertInCommandAndReplyMap(RwDefinitions::CLEAR_LAST_RESET_STATUS, 1, nullptr,
RwDefinitions::SIZE_CLEAR_RESET_STATUS);
this->insertInCommandAndReplyMap(RwDefinitions::GET_RW_STATUS, 1, &statusSet,
RwDefinitions::SIZE_GET_RW_STATUS);
this->insertInCommandAndReplyMap(RwDefinitions::INIT_RW_CONTROLLER, 1, nullptr,
RwDefinitions::SIZE_INIT_RW);
2022-05-10 18:34:39 +02:00
this->insertInCommandAndReplyMap(RwDefinitions::GET_TEMPERATURE, 1, nullptr,
2022-01-17 15:58:27 +01:00
RwDefinitions::SIZE_GET_TEMPERATURE_REPLY);
this->insertInCommandAndReplyMap(RwDefinitions::SET_SPEED, 1, nullptr,
RwDefinitions::SIZE_SET_SPEED_REPLY);
this->insertInCommandAndReplyMap(RwDefinitions::GET_TM, 1, &tmDataset,
RwDefinitions::SIZE_GET_TELEMETRY_REPLY);
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
ReturnValue_t RwHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
uint8_t replyByte = *start;
switch (replyByte) {
2021-09-23 16:03:09 +02:00
case (RwDefinitions::GET_LAST_RESET_STATUS): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_GET_RESET_STATUS;
*foundId = RwDefinitions::GET_LAST_RESET_STATUS;
break;
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::CLEAR_LAST_RESET_STATUS): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_CLEAR_RESET_STATUS;
*foundId = RwDefinitions::CLEAR_LAST_RESET_STATUS;
break;
2021-06-28 14:07:37 +02:00
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::GET_RW_STATUS): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_GET_RW_STATUS;
*foundId = RwDefinitions::GET_RW_STATUS;
break;
2021-06-21 09:50:26 +02:00
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::INIT_RW_CONTROLLER): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_INIT_RW;
*foundId = RwDefinitions::INIT_RW_CONTROLLER;
break;
2021-06-28 14:07:37 +02:00
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::SET_SPEED): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_SET_SPEED_REPLY;
*foundId = RwDefinitions::SET_SPEED;
break;
2021-06-21 09:50:26 +02:00
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::GET_TEMPERATURE): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_GET_TEMPERATURE_REPLY;
*foundId = RwDefinitions::GET_TEMPERATURE;
break;
2021-06-21 09:50:26 +02:00
}
2021-09-23 16:03:09 +02:00
case (RwDefinitions::GET_TM): {
2022-01-17 15:58:27 +01:00
*foundLen = RwDefinitions::SIZE_GET_TELEMETRY_REPLY;
*foundId = RwDefinitions::GET_TM;
break;
2021-06-30 15:07:26 +02:00
}
2021-06-21 09:50:26 +02:00
default: {
2022-01-17 15:58:27 +01:00
sif::warning << "RwHandler::scanForReply: Reply contains invalid command code" << std::endl;
*foundLen = remainingSize;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
}
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
sizeOfReply = *foundLen;
2021-06-21 09:50:26 +02:00
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
/** Check result code */
if (*(packet + 1) == RwDefinitions::STATE_ERROR) {
sif::error << "RwHandler::interpretDeviceReply: Command execution failed. Command id: " << id
<< std::endl;
return EXECUTION_FAILED;
}
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
/** Received in little endian byte order */
uint16_t replyCrc = *(packet + sizeOfReply - 1) << 8 | *(packet + sizeOfReply - 2);
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
if (CRC::crc16ccitt(packet, sizeOfReply - 2, 0xFFFF) != replyCrc) {
sif::error << "RwHandler::interpretDeviceReply: cRC error" << std::endl;
return CRC_ERROR;
}
2021-06-21 09:50:26 +02:00
2022-01-17 15:58:27 +01:00
switch (id) {
case (RwDefinitions::GET_LAST_RESET_STATUS): {
2022-01-17 15:58:27 +01:00
handleResetStatusReply(packet);
break;
}
2021-06-21 09:50:26 +02:00
case (RwDefinitions::GET_RW_STATUS): {
2022-01-17 15:58:27 +01:00
handleGetRwStatusReply(packet);
break;
2021-06-21 09:50:26 +02:00
}
2021-06-28 14:07:37 +02:00
case (RwDefinitions::CLEAR_LAST_RESET_STATUS):
case (RwDefinitions::INIT_RW_CONTROLLER):
2021-06-21 09:50:26 +02:00
case (RwDefinitions::SET_SPEED):
2022-01-17 15:58:27 +01:00
// no reply data expected
break;
2021-06-21 09:50:26 +02:00
case (RwDefinitions::GET_TEMPERATURE): {
2022-01-17 15:58:27 +01:00
handleTemperatureReply(packet);
break;
2021-06-21 09:50:26 +02:00
}
2021-06-30 15:07:26 +02:00
case (RwDefinitions::GET_TM): {
2022-01-17 15:58:27 +01:00
handleGetTelemetryReply(packet);
break;
2021-06-30 15:07:26 +02:00
}
2021-06-21 09:50:26 +02:00
default: {
2022-01-17 15:58:27 +01:00
sif::debug << "RwHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
}
2021-06-21 09:50:26 +02:00
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2022-01-17 15:58:27 +01:00
uint32_t RwHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 5000; }
2021-06-21 09:50:26 +02:00
ReturnValue_t RwHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
2022-01-17 15:58:27 +01:00
LocalDataPoolManager& poolManager) {
2023-02-09 17:11:23 +01:00
localDataPoolMap.emplace(RwDefinitions::RW_SPEED, &rwSpeed);
2023-02-10 11:27:02 +01:00
localDataPoolMap.emplace(RwDefinitions::RAMP_TIME, &rampTime);
2023-02-09 17:11:23 +01:00
2022-01-17 15:58:27 +01:00
localDataPoolMap.emplace(RwDefinitions::TEMPERATURE_C, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::CURR_SPEED, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::REFERENCE_SPEED, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::CLC_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::LAST_RESET_STATUS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::CURRRENT_RESET_STATUS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_LAST_RESET_STATUS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_MCU_TEMPERATURE, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::PRESSURE_SENSOR_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(RwDefinitions::PRESSURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_RW_STATE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_CLC_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_RW_CURR_SPEED, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::TM_RW_REF_SPEED, new PoolEntry<int32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::INVALID_CRC_PACKETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::INVALID_LEN_PACKETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::INVALID_CMD_PACKETS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::EXECUTED_REPLIES, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::COMMAND_REPLIES, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_BYTES_WRITTEN, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_BYTES_READ, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_PARITY_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_NOISE_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_FRAME_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_REG_OVERRUN_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::UART_TOTAL_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_WRITTEN, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_READ, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::SPI_REG_OVERRUN_ERRORS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(RwDefinitions::SPI_TOTAL_ERRORS, new PoolEntry<uint32_t>({0}));
2022-08-15 11:57:57 +02:00
poolManager.subscribeForDiagPeriodicPacket(
subdp::DiagnosticsHkPeriodicParams(statusSet.getSid(), false, 5.0));
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(tmDataset.getSid(), false, 30.0));
poolManager.subscribeForRegularPeriodicPacket(
subdp::RegularHkPeriodicParams(lastResetStatusSet.getSid(), false, 30.0));
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2021-06-30 15:07:26 +02:00
void RwHandler::prepareSimpleCommand(DeviceCommandId_t id) {
2022-01-17 15:58:27 +01:00
commandBuffer[0] = static_cast<uint8_t>(id);
uint16_t crc = CRC::crc16ccitt(commandBuffer, 1, 0xFFFF);
commandBuffer[1] = static_cast<uint8_t>(crc & 0xFF);
commandBuffer[2] = static_cast<uint8_t>(crc >> 8 & 0xFF);
rawPacket = commandBuffer;
rawPacketLen = 3;
2021-06-21 09:50:26 +02:00
}
2023-02-10 13:16:50 +01:00
ReturnValue_t RwHandler::checkSpeedAndRampTime() {
int32_t speed = 0;
uint16_t rampTime = 0;
rwSpeedActuationSet.getRwSpeed(speed, rampTime);
2022-01-17 15:58:27 +01:00
if ((speed < -65000 || speed > 65000 || (speed > -1000 && speed < 1000)) && (speed != 0)) {
sif::error << "RwHandler::checkSpeedAndRampTime: Command has invalid speed" << std::endl;
return INVALID_SPEED;
}
2021-06-21 09:50:26 +02:00
if (rampTime < 10 || rampTime > 20000) {
2022-01-17 15:58:27 +01:00
sif::error << "RwHandler::checkSpeedAndRampTime: Command has invalid ramp time" << std::endl;
return INVALID_RAMP_TIME;
}
2021-06-21 09:50:26 +02:00
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2021-06-21 09:50:26 +02:00
}
2023-02-10 13:16:50 +01:00
ReturnValue_t RwHandler::prepareSetSpeedCmd() {
2022-01-17 15:58:27 +01:00
commandBuffer[0] = static_cast<uint8_t>(RwDefinitions::SET_SPEED);
2023-02-10 13:16:50 +01:00
uint8_t* serPtr = commandBuffer + 1;
size_t serSize = 1;
rwSpeedActuationSet.setValidityBufferGeneration(false);
ReturnValue_t result = rwSpeedActuationSet.serialize(&serPtr, &serSize, sizeof(commandBuffer),
SerializeIF::Endianness::LITTLE);
rwSpeedActuationSet.setValidityBufferGeneration(true);
if (result != returnvalue::OK) {
return result;
}
2022-01-17 15:58:27 +01:00
uint16_t crc = CRC::crc16ccitt(commandBuffer, 7, 0xFFFF);
commandBuffer[7] = static_cast<uint8_t>(crc & 0xFF);
2023-02-10 13:16:50 +01:00
commandBuffer[8] = static_cast<uint8_t>((crc >> 8) & 0xFF);
2022-01-17 15:58:27 +01:00
rawPacket = commandBuffer;
rawPacketLen = 9;
2023-02-10 13:16:50 +01:00
return result;
2021-06-21 09:50:26 +02:00
}
void RwHandler::handleResetStatusReply(const uint8_t* packet) {
2022-01-17 15:58:27 +01:00
PoolReadGuard rg(&lastResetStatusSet);
uint8_t offset = 2;
uint8_t resetStatus = packet[offset];
2022-05-11 15:45:38 +02:00
if (resetStatus != 0) {
2022-01-17 15:58:27 +01:00
internalState = InternalState::CLEAR_RESET_STATUS;
lastResetStatusSet.lastNonClearedResetStatus = resetStatus;
triggerEvent(RwDefinitions::RESET_OCCURED, resetStatus, 0);
2022-01-17 15:58:27 +01:00
}
2022-05-05 13:40:43 +02:00
lastResetStatusSet.currentResetStatus = resetStatus;
2022-04-26 10:37:25 +02:00
if (debugMode) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "RwHandler::handleResetStatusReply: Last reset status: "
2022-05-05 13:40:43 +02:00
<< static_cast<unsigned int>(lastResetStatusSet.lastNonClearedResetStatus.value)
<< std::endl;
2022-04-26 10:37:25 +02:00
sif::info << "RwHandler::handleResetStatusReply: Current reset status: "
2022-05-05 13:40:43 +02:00
<< static_cast<unsigned int>(lastResetStatusSet.currentResetStatus.value)
2022-04-26 10:37:25 +02:00
<< std::endl;
#endif
2022-04-26 10:37:25 +02:00
}
}
2021-06-21 09:50:26 +02:00
void RwHandler::handleGetRwStatusReply(const uint8_t* packet) {
2022-05-10 18:34:39 +02:00
PoolReadGuard rg0(&statusSet);
PoolReadGuard rg1(&tmDataset);
2022-01-17 15:58:27 +01:00
uint8_t offset = 2;
statusSet.currSpeed = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
2022-05-10 18:34:39 +02:00
tmDataset.rwCurrSpeed = statusSet.currSpeed;
tmDataset.rwCurrSpeed.setValid(true);
2022-01-17 15:58:27 +01:00
offset += 4;
statusSet.referenceSpeed = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
2022-05-10 18:34:39 +02:00
tmDataset.rwRefSpeed = statusSet.referenceSpeed;
tmDataset.rwRefSpeed.setValid(true);
2022-01-17 15:58:27 +01:00
offset += 4;
statusSet.state = *(packet + offset);
2022-05-10 18:34:39 +02:00
tmDataset.rwState = statusSet.state;
tmDataset.rwState.setValid(true);
2022-01-17 15:58:27 +01:00
offset += 1;
statusSet.clcMode = *(packet + offset);
2022-05-10 18:34:39 +02:00
tmDataset.rwClcMode = statusSet.clcMode;
tmDataset.rwClcMode.setValid(true);
statusSet.setValidity(true, true);
2022-01-17 15:58:27 +01:00
if (statusSet.state == RwDefinitions::STATE_ERROR) {
// This requires the commanding of the init reaction wheel controller command to recover
// from error state which must be handled by the FDIR instance.
triggerEvent(RwDefinitions::ERROR_STATE, statusSet.state.value, 0);
2022-01-17 15:58:27 +01:00
sif::error << "RwHandler::handleGetRwStatusReply: Reaction wheel in error state" << std::endl;
}
2021-06-29 16:08:20 +02:00
2022-04-26 10:37:25 +02:00
if (debugMode) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "RwHandler::handleGetRwStatusReply: Current speed is: " << statusSet.currSpeed
<< " * 0.1 RPM" << std::endl;
sif::info << "RwHandler::handleGetRwStatusReply: Reference speed is: "
<< statusSet.referenceSpeed << " * 0.1 RPM" << std::endl;
sif::info << "RwHandler::handleGetRwStatusReply: State is: "
<< (unsigned int)statusSet.state.value << std::endl;
sif::info << "RwHandler::handleGetRwStatusReply: clc mode is: "
<< (unsigned int)statusSet.clcMode.value << std::endl;
2021-06-21 09:50:26 +02:00
#endif
2022-04-26 10:37:25 +02:00
}
2021-06-21 09:50:26 +02:00
}
void RwHandler::handleTemperatureReply(const uint8_t* packet) {
2022-05-10 18:34:39 +02:00
PoolReadGuard rg(&statusSet);
2022-01-17 15:58:27 +01:00
uint8_t offset = 2;
2022-05-10 18:34:39 +02:00
statusSet.temperatureCelcius = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
2022-04-26 10:37:25 +02:00
if (debugMode) {
#if OBSW_VERBOSE_LEVEL >= 1
2022-05-10 18:34:39 +02:00
sif::info << "RwHandler::handleTemperatureReply: Temperature: " << statusSet.temperatureCelcius
<< " °C" << std::endl;
2021-06-21 09:50:26 +02:00
#endif
2022-04-26 10:37:25 +02:00
}
2021-06-21 09:50:26 +02:00
}
2021-06-30 15:07:26 +02:00
void RwHandler::handleGetTelemetryReply(const uint8_t* packet) {
2022-01-17 15:58:27 +01:00
PoolReadGuard rg(&tmDataset);
uint8_t offset = 2;
tmDataset.lastResetStatus = *(packet + offset);
offset += 1;
tmDataset.mcuTemperature = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.pressureSensorTemperature = *(packet + offset + 3) << 24 |
*(packet + offset + 2) << 16 | *(packet + offset + 1) << 8 |
*(packet + offset);
offset += 4;
tmDataset.pressure = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.rwState = *(packet + offset);
offset += 1;
tmDataset.rwClcMode = *(packet + offset);
offset += 1;
tmDataset.rwCurrSpeed = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.rwRefSpeed = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.numOfInvalidCrcPackets = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.numOfInvalidLenPackets = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.numOfInvalidCmdPackets = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.numOfCmdExecutedReplies = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.numOfCmdReplies = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfBytesWritten = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfBytesRead = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfParityErrors = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfNoiseErrors = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfFrameErrors = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartNumOfRegisterOverrunErrors = *(packet + offset + 3) << 24 |
*(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.uartTotalNumOfErrors = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.spiNumOfBytesWritten = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.spiNumOfBytesRead = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.spiNumOfRegisterOverrunErrors = *(packet + offset + 3) << 24 |
*(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
offset += 4;
tmDataset.spiTotalNumOfErrors = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 |
*(packet + offset + 1) << 8 | *(packet + offset);
2022-04-26 10:37:25 +02:00
if (debugMode) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "RwHandler::handleGetTelemetryReply: Last reset status: "
<< static_cast<unsigned int>(tmDataset.lastResetStatus.value) << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: MCU temperature: " << tmDataset.mcuTemperature
<< std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Pressure sensor temperature: "
<< tmDataset.pressureSensorTemperature << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Pressure " << tmDataset.pressure << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: State: "
<< static_cast<unsigned int>(tmDataset.rwState.value) << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: CLC mode: "
<< static_cast<unsigned int>(tmDataset.rwClcMode.value) << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Current speed: " << tmDataset.rwCurrSpeed
<< std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Reference speed: " << tmDataset.rwRefSpeed
<< std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Number of invalid CRC packets: "
<< tmDataset.numOfInvalidCrcPackets << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Number of invalid length packets: "
<< tmDataset.numOfInvalidLenPackets << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Number of invalid command packets: "
<< tmDataset.numOfInvalidCmdPackets << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Number of command executed replies: "
<< tmDataset.numOfCmdExecutedReplies << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: Number of command replies: "
<< tmDataset.numOfCmdReplies << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of bytes written: "
<< tmDataset.uartNumOfBytesWritten << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of bytes read: "
<< tmDataset.uartNumOfBytesRead << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of parity errors: "
<< tmDataset.uartNumOfParityErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of noise errors: "
<< tmDataset.uartNumOfNoiseErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of frame errors: "
<< tmDataset.uartNumOfFrameErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of register overrun errors: "
<< tmDataset.uartNumOfRegisterOverrunErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: UART number of total errors: "
<< tmDataset.uartTotalNumOfErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: SPI number of bytes written: "
<< tmDataset.spiNumOfBytesWritten << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: SPI number of bytes read: "
<< tmDataset.spiNumOfBytesRead << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: SPI number of register overrun errors: "
<< tmDataset.spiNumOfRegisterOverrunErrors << std::endl;
sif::info << "RwHandler::handleGetTelemetryReply: SPI number of register total errors: "
<< tmDataset.spiTotalNumOfErrors << std::endl;
2021-06-30 15:07:26 +02:00
#endif
2022-04-26 10:37:25 +02:00
}
2021-06-30 15:07:26 +02:00
}
2022-04-26 10:37:25 +02:00
void RwHandler::setDebugMode(bool enable) { this->debugMode = enable; }