added second reaction wheel

This commit is contained in:
Martin Zietz
2021-06-28 14:07:37 +02:00
parent 516ef34b21
commit 23731e367c
7 changed files with 76 additions and 30 deletions

View File

@ -20,12 +20,19 @@ RwHandler::~RwHandler() {
}
void RwHandler::doStartUp() {
if (!startupPerformed) {
return;
}
if(gpioComIF->pullHigh(enableGpio) != RETURN_OK) {
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high";
switch (startupStep) {
case StartupStep::ENABLE_RW: {
if(gpioComIF->pullHigh(enableGpio) != RETURN_OK) {
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high";
}
return;
}
case StartupStep::STARTUP_COMPLETE:
break;
default:
return;
}
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
setMode(MODE_NORMAL);
#else
@ -37,7 +44,8 @@ void RwHandler::doShutDown() {
if(gpioComIF->pullLow(enableGpio) != RETURN_OK) {
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to low";
}
startupPerformed = false;
/** Reset startup step for next doStartUp routine */
startupStep = StartupStep::ENABLE_RW;
}
ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) {
@ -64,7 +72,7 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) {
ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t * id) {
switch (startupStep) {
case StartupStep::GET_RESET_STATUS:
case StartupStep::ENABLE_RW:
*id = RwDefinitions::GET_LAST_RESET_STATUS;
startupStep = StartupStep::CLEAR_RESET_STATUS;
break;
@ -74,9 +82,10 @@ ReturnValue_t RwHandler::buildTransitionDeviceCommand(DeviceCommandId_t * id) {
break;
case StartupStep::INIT_RW:
*id = RwDefinitions::INIT_RW_CONTROLLER;
startupStep = StartupStep::GET_RESET_STATUS;
startupPerformed = true;
startupStep = StartupStep::STARTUP_COMPLETE;
break;
case StartupStep::STARTUP_COMPLETE:
break;
default:
sif::debug << "RwHandler::buildTransitionDeviceCommand: Invalid startup step"
<< std::endl;
@ -136,17 +145,19 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand
}
void RwHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(RwDefinitions::RESET_MCU);
this->insertInCommandAndReplyMap(RwDefinitions::GET_LAST_RESET_STATUS, 1, &lastResetStatusSet,
RwDefinitions::SIZE_GET_RESET_STATUS);
this->insertInCommandMap(RwDefinitions::CLEAR_LAST_RESET_STATUS);
this->insertInCommandAndReplyMap(RwDefinitions::GET_RW_STATUS, 1, &statusSet,
RwDefinitions::SIZE_GET_RW_STATUS);
this->insertInCommandMap(RwDefinitions::INIT_RW_CONTROLLER);
this->insertInCommandAndReplyMap(RwDefinitions::GET_TEMPERATURE, 1, &temperatureSet,
RwDefinitions::SIZE_GET_TEMPERATURE_REPLY);
this->insertInCommandAndReplyMap(RwDefinitions::SET_SPEED, 1, nullptr,
RwDefinitions::SIZE_SET_SPEED_REPLY);
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);
this->insertInCommandAndReplyMap(RwDefinitions::GET_TEMPERATURE, 1, &temperatureSet,
RwDefinitions::SIZE_GET_TEMPERATURE_REPLY);
this->insertInCommandAndReplyMap(RwDefinitions::SET_SPEED, 1, nullptr,
RwDefinitions::SIZE_SET_SPEED_REPLY);
}
ReturnValue_t RwHandler::scanForReply(const uint8_t *start, size_t remainingSize,
@ -158,11 +169,21 @@ ReturnValue_t RwHandler::scanForReply(const uint8_t *start, size_t remainingSize
*foundId = RwDefinitions::GET_LAST_RESET_STATUS;
break;
}
case (static_cast<uint8_t>(RwDefinitions::CLEAR_LAST_RESET_STATUS)): {
*foundLen = RwDefinitions::SIZE_CLEAR_RESET_STATUS;
*foundId = RwDefinitions::CLEAR_LAST_RESET_STATUS;
break;
}
case (static_cast<uint8_t>(RwDefinitions::GET_RW_STATUS)): {
*foundLen = RwDefinitions::SIZE_GET_RW_STATUS;
*foundId = RwDefinitions::GET_RW_STATUS;
break;
}
case (static_cast<uint8_t>(RwDefinitions::INIT_RW_CONTROLLER)): {
*foundLen = RwDefinitions::SIZE_INIT_RW;
*foundId = RwDefinitions::INIT_RW_CONTROLLER;
break;
}
case (static_cast<uint8_t>(RwDefinitions::SET_SPEED)): {
*foundLen = RwDefinitions::SIZE_SET_SPEED_REPLY;
*foundId = RwDefinitions::SET_SPEED;
@ -189,6 +210,8 @@ ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_
/** Check result code */
if (*(packet + 1) == RwDefinitions::ERROR) {
sif::error << "RwHandler::interpretDeviceReply: Command execution failed. Command id: "
<< id << std::endl;
return EXECUTION_FAILED;
}
@ -209,6 +232,8 @@ ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_
handleGetRwStatusReply(packet);
break;
}
case (RwDefinitions::CLEAR_LAST_RESET_STATUS):
case (RwDefinitions::INIT_RW_CONTROLLER):
case (RwDefinitions::SET_SPEED):
// no reply data expected
break;
@ -230,7 +255,7 @@ void RwHandler::setNormalDatapoolEntriesInvalid() {
}
uint32_t RwHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
return 5000;
return 15000;
}
ReturnValue_t RwHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,