RW fixes and test
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include <fsfw/globalfunctions/CRC.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
#include <fsfw_hal/common/gpio/GpioIF.h>
|
||||
#include <mission/acs/defs.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
@ -23,7 +24,9 @@ RwHandler::RwHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCooki
|
||||
if (gpioComIF == nullptr) {
|
||||
sif::error << "RwHandler: Invalid gpio communication interface" << std::endl;
|
||||
}
|
||||
currentRequest.rwIdx = rwIdx;
|
||||
}
|
||||
|
||||
RwHandler::~RwHandler() {}
|
||||
|
||||
void RwHandler::doStartUp() {
|
||||
@ -32,6 +35,7 @@ void RwHandler::doStartUp() {
|
||||
if (gpioComIF->pullHigh(enableGpio) != returnvalue::OK) {
|
||||
sif::error << "RW Handler " << rwIdx << ": Failed to pull ENABLE pin high for startup";
|
||||
}
|
||||
currentRequest.mode = acs::SimpleSensorMode::NORMAL;
|
||||
updatePeriodicReply(true, rws::REPLY_ID);
|
||||
statusSet.setReportingEnabled(true);
|
||||
setMode(_MODE_TO_ON);
|
||||
@ -40,11 +44,11 @@ void RwHandler::doStartUp() {
|
||||
void RwHandler::doShutDown() {
|
||||
if (internalState != InternalState::SHUTDOWN) {
|
||||
internalState = InternalState::SHUTDOWN;
|
||||
commandExecuted = false;
|
||||
shutdownState = ShutdownState::SET_SPEED_ZERO;
|
||||
offTransitionCountdown.resetTimer();
|
||||
}
|
||||
if (((internalState == InternalState::SHUTDOWN) and commandExecuted) or
|
||||
offTransitionCountdown.hasTimedOut()) {
|
||||
if ((internalState == InternalState::SHUTDOWN) and
|
||||
(shutdownState == ShutdownState::DONE or offTransitionCountdown.hasTimedOut())) {
|
||||
if (gpioComIF->pullLow(enableGpio) != returnvalue::OK) {
|
||||
sif::error << "RW Handler " << rwIdx << ": Failed to pull ENABLE pin low for shutdown";
|
||||
}
|
||||
@ -61,8 +65,8 @@ void RwHandler::doShutDown() {
|
||||
PoolReadGuard pg(&tmDataset);
|
||||
tmDataset.setValidity(false, true);
|
||||
}
|
||||
commandExecuted = false;
|
||||
internalState = InternalState::DEFAULT;
|
||||
shutdownState = ShutdownState::NONE;
|
||||
// The power switch is handled by the assembly, so we can go off here directly.
|
||||
setMode(MODE_OFF);
|
||||
}
|
||||
@ -83,12 +87,18 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
|
||||
ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
||||
if (internalState == InternalState::SHUTDOWN) {
|
||||
{
|
||||
PoolReadGuard pg(&rwSpeedActuationSet);
|
||||
rwSpeedActuationSet.setRwSpeed(0, 10);
|
||||
if (shutdownState == ShutdownState::SET_SPEED_ZERO) {
|
||||
{
|
||||
PoolReadGuard pg(&rwSpeedActuationSet);
|
||||
rwSpeedActuationSet.setRwSpeed(0, 10);
|
||||
}
|
||||
*id = rws::REQUEST_ID;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
} else if (shutdownState == ShutdownState::STOP_POLLING) {
|
||||
currentRequest.mode = acs::SimpleSensorMode::OFF;
|
||||
*id = rws::REQUEST_ID;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
*id = rws::REQUEST_ID;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
return NOTHING_TO_SEND;
|
||||
}
|
||||
@ -132,32 +142,36 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand
|
||||
return result;
|
||||
}
|
||||
// set speed flag.
|
||||
commandBuffer[0] = true;
|
||||
rawPacketLen = 1;
|
||||
uint8_t* currentCmdBuf = commandBuffer + 1;
|
||||
rwSpeedActuationSet.serialize(¤tCmdBuf, &rawPacketLen, sizeof(commandBuffer),
|
||||
SerializeIF::Endianness::MACHINE);
|
||||
commandBuffer[rawPacketLen++] = static_cast<uint8_t>(rws::SpecialRwRequest::REQUEST_NONE);
|
||||
rawPacket = commandBuffer;
|
||||
currentRequest.setSpeed = true;
|
||||
rwSpeedActuationSet.getRwSpeed(currentRequest.currentRwSpeed, currentRequest.currentRampTime);
|
||||
currentRequest.specialRequest = rws::SpecialRwRequest::REQUEST_NONE;
|
||||
rawPacket = reinterpret_cast<uint8_t*>(¤tRequest);
|
||||
rawPacketLen = sizeof(rws::RwRequest);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::RESET_MCU): {
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::RESET_MCU);
|
||||
currentRequest.setSpeed = false;
|
||||
currentRequest.specialRequest = rws::SpecialRwRequest::RESET_MCU;
|
||||
internalState = InternalState::RESET_MCU;
|
||||
rawPacket = reinterpret_cast<uint8_t*>(¤tRequest);
|
||||
rawPacketLen = sizeof(rws::RwRequest);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
case (rws::INIT_RW_CONTROLLER): {
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::INIT_RW_CONTROLLER);
|
||||
currentRequest.setSpeed = false;
|
||||
currentRequest.specialRequest = rws::SpecialRwRequest::INIT_RW_CONTROLLER;
|
||||
internalState = InternalState::INIT_RW_CONTROLLER;
|
||||
rawPacket = reinterpret_cast<uint8_t*>(¤tRequest);
|
||||
rawPacketLen = sizeof(rws::RwRequest);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::GET_TM): {
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::GET_TM);
|
||||
currentRequest.setSpeed = false;
|
||||
currentRequest.specialRequest = rws::SpecialRwRequest::GET_TM;
|
||||
internalState = InternalState::GET_TM;
|
||||
rawPacket = reinterpret_cast<uint8_t*>(¤tRequest);
|
||||
rawPacketLen = sizeof(rws::RwRequest);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
default:
|
||||
@ -185,6 +199,9 @@ ReturnValue_t RwHandler::scanForReply(const uint8_t* start, size_t remainingSize
|
||||
*foundLen = remainingSize;
|
||||
*foundId = rws::REPLY_ID;
|
||||
}
|
||||
if (internalState == InternalState::SHUTDOWN and shutdownState == ShutdownState::STOP_POLLING) {
|
||||
shutdownState = ShutdownState::DONE;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -394,9 +411,10 @@ void RwHandler::handleGetRwStatusReply(const uint8_t* packet) {
|
||||
|
||||
statusSet.setValidity(true, true);
|
||||
|
||||
if (internalState == InternalState::SHUTDOWN and std::abs(tmDataset.rwCurrSpeed.value) <= 2) {
|
||||
if (internalState == InternalState::SHUTDOWN and std::abs(tmDataset.rwCurrSpeed.value) <= 2 and
|
||||
shutdownState == ShutdownState::SET_SPEED_ZERO) {
|
||||
// Finish transition to off.
|
||||
commandExecuted = true;
|
||||
shutdownState = ShutdownState::STOP_POLLING;
|
||||
}
|
||||
|
||||
if (statusSet.state == rws::STATE_ERROR) {
|
||||
|
@ -75,8 +75,8 @@ class RwHandler : public DeviceHandlerBase {
|
||||
GpioIF* gpioComIF = nullptr;
|
||||
gpioId_t enableGpio = gpio::NO_GPIO;
|
||||
bool debugMode = false;
|
||||
bool commandExecuted = false;
|
||||
Countdown offTransitionCountdown = Countdown(5000);
|
||||
rws::RwRequest currentRequest;
|
||||
|
||||
rws::StatusSet statusSet;
|
||||
rws::LastResetSatus lastResetStatusSet;
|
||||
@ -90,6 +90,12 @@ class RwHandler : public DeviceHandlerBase {
|
||||
PoolEntry<uint16_t> rampTime = PoolEntry<uint16_t>({10});
|
||||
|
||||
enum class InternalState { DEFAULT, GET_TM, INIT_RW_CONTROLLER, RESET_MCU, SHUTDOWN };
|
||||
enum class ShutdownState {
|
||||
NONE,
|
||||
SET_SPEED_ZERO,
|
||||
STOP_POLLING,
|
||||
DONE,
|
||||
} shutdownState = ShutdownState::NONE;
|
||||
|
||||
InternalState internalState = InternalState::DEFAULT;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <fsfw/datapoollocal/LocalPoolVariable.h>
|
||||
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <mission/acs/defs.h>
|
||||
|
||||
#include "eive/resultClassIds.h"
|
||||
#include "events/subsystemIdRanges.h"
|
||||
@ -36,6 +37,15 @@ enum class SpecialRwRequest : uint8_t {
|
||||
NUM_REQUESTS
|
||||
};
|
||||
|
||||
struct RwRequest {
|
||||
acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF;
|
||||
bool setSpeed = true;
|
||||
int32_t currentRwSpeed = 0;
|
||||
uint16_t currentRampTime = 0;
|
||||
rws::SpecialRwRequest specialRequest = rws::SpecialRwRequest::REQUEST_NONE;
|
||||
uint8_t rwIdx = 0;
|
||||
};
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::RW_HANDLER;
|
||||
|
||||
static const ReturnValue_t SPI_WRITE_FAILURE = MAKE_RETURN_CODE(0xB0);
|
||||
|
Reference in New Issue
Block a user