DHB refactoring complete
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
@ -27,11 +27,12 @@ RwHandler::RwHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCooki
|
||||
RwHandler::~RwHandler() {}
|
||||
|
||||
void RwHandler::doStartUp() {
|
||||
internalState = InternalState::GET_RESET_STATUS;
|
||||
internalState = InternalState::DEFAULT;
|
||||
|
||||
if (gpioComIF->pullHigh(enableGpio) != returnvalue::OK) {
|
||||
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to high";
|
||||
}
|
||||
updatePeriodicReply(true, rws::REPLY_ID);
|
||||
setMode(_MODE_TO_ON);
|
||||
}
|
||||
|
||||
@ -39,32 +40,37 @@ void RwHandler::doShutDown() {
|
||||
if (gpioComIF->pullLow(enableGpio) != returnvalue::OK) {
|
||||
sif::debug << "RwHandler::doStartUp: Failed to pull enable gpio to low";
|
||||
}
|
||||
internalState = InternalState::DEFAULT;
|
||||
updatePeriodicReply(false, rws::REPLY_ID);
|
||||
setMode(_MODE_POWER_DOWN);
|
||||
}
|
||||
|
||||
ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
||||
switch (internalState) {
|
||||
case InternalState::SET_SPEED:
|
||||
*id = rws::SET_SPEED;
|
||||
internalState = InternalState::GET_RESET_STATUS;
|
||||
break;
|
||||
case InternalState::GET_RESET_STATUS:
|
||||
*id = rws::GET_LAST_RESET_STATUS;
|
||||
internalState = InternalState::READ_TEMPERATURE;
|
||||
break;
|
||||
case InternalState::READ_TEMPERATURE:
|
||||
*id = rws::GET_TEMPERATURE;
|
||||
internalState = InternalState::GET_RW_SATUS;
|
||||
break;
|
||||
case InternalState::GET_RW_SATUS:
|
||||
*id = rws::GET_RW_STATUS;
|
||||
internalState = InternalState::CLEAR_RESET_STATUS;
|
||||
break;
|
||||
case InternalState::CLEAR_RESET_STATUS:
|
||||
*id = rws::CLEAR_LAST_RESET_STATUS;
|
||||
/** After reset status is cleared, reset status will be polled again for verification */
|
||||
internalState = InternalState::GET_RESET_STATUS;
|
||||
case InternalState::DEFAULT: {
|
||||
*id = rws::REQUEST_ID;
|
||||
break;
|
||||
}
|
||||
// case InternalState::SET_SPEED:
|
||||
// *id = rws::SET_SPEED;
|
||||
// internalState = InternalState::GET_RESET_STATUS;
|
||||
// break;
|
||||
// case InternalState::GET_RESET_STATUS:
|
||||
// *id = rws::GET_LAST_RESET_STATUS;
|
||||
// internalState = InternalState::READ_TEMPERATURE;
|
||||
// break;
|
||||
// case InternalState::READ_TEMPERATURE:
|
||||
// *id = rws::GET_TEMPERATURE;
|
||||
// internalState = InternalState::GET_RW_SATUS;
|
||||
// break;
|
||||
// case InternalState::GET_RW_SATUS:
|
||||
// *id = rws::GET_RW_STATUS;
|
||||
// internalState = InternalState::CLEAR_RESET_STATUS;
|
||||
// break;
|
||||
// case InternalState::CLEAR_RESET_STATUS:
|
||||
// *id = rws::CLEAR_LAST_RESET_STATUS;
|
||||
// /** After reset status is cleared, reset status will be polled again for verification
|
||||
// */ internalState = InternalState::GET_RESET_STATUS; break;
|
||||
default:
|
||||
sif::debug << "RwHandler::buildNormalDeviceCommand: Invalid internal step" << std::endl;
|
||||
break;
|
||||
@ -82,27 +88,7 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
|
||||
switch (deviceCommand) {
|
||||
case (rws::RESET_MCU): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::GET_LAST_RESET_STATUS): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::CLEAR_LAST_RESET_STATUS): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::GET_RW_STATUS): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::INIT_RW_CONTROLLER): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::SET_SPEED): {
|
||||
case (rws::REQUEST_ID): {
|
||||
if (commandData != nullptr && commandDataLen != 6) {
|
||||
sif::error << "RwHandler::buildCommandFromCommand: Received set speed command with"
|
||||
<< " invalid length" << std::endl;
|
||||
@ -133,17 +119,94 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = prepareSetSpeedCmd();
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case (rws::GET_TEMPERATURE): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
case (rws::RESET_MCU): {
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::RESET_MCU);
|
||||
internalState = InternalState::RESET_MCU;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
case (rws::INIT_RW_CONTROLLER): {
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::INIT_RW_CONTROLLER);
|
||||
internalState = InternalState::INIT_RW_CONTROLLER;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (rws::GET_TM): {
|
||||
prepareSimpleCommand(deviceCommand);
|
||||
commandBuffer[0] = false;
|
||||
commandBuffer[7] = static_cast<uint8_t>(rws::SpecialRwRequest::GET_TM);
|
||||
internalState = InternalState::GET_TM;
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
// case (rws::GET_LAST_RESET_STATUS): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
// case (rws::CLEAR_LAST_RESET_STATUS): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
// case (rws::GET_RW_STATUS): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
// case (rws::INIT_RW_CONTROLLER): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
// case (rws::SET_SPEED): {
|
||||
// if (commandData != nullptr && commandDataLen != 6) {
|
||||
// sif::error << "RwHandler::buildCommandFromCommand: Received set speed command with"
|
||||
// << " invalid length" << std::endl;
|
||||
// return SET_SPEED_COMMAND_INVALID_LENGTH;
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// PoolReadGuard pg(&rwSpeedActuationSet);
|
||||
// // 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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (ACTUATION_WIRETAPPING) {
|
||||
// int32_t speed = 0;
|
||||
// uint16_t rampTime = 0;
|
||||
// rwSpeedActuationSet.getRwSpeed(speed, rampTime);
|
||||
// sif::debug << "Actuating RW " << static_cast<int>(rwIdx) << " with speed = " <<
|
||||
// speed
|
||||
// << " and rampTime = " << rampTime << std::endl;
|
||||
// }
|
||||
// result = checkSpeedAndRampTime();
|
||||
// if (result != returnvalue::OK) {
|
||||
// return result;
|
||||
// }
|
||||
// result = prepareSetSpeedCmd();
|
||||
// return result;
|
||||
// }
|
||||
// case (rws::GET_TEMPERATURE): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
// case (rws::GET_TM): {
|
||||
// prepareSimpleCommand(deviceCommand);
|
||||
// return returnvalue::OK;
|
||||
// }
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
@ -151,7 +214,13 @@ ReturnValue_t RwHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand
|
||||
}
|
||||
|
||||
void RwHandler::fillCommandAndReplyMap() {
|
||||
this->insertInCommandMap(rws::RESET_MCU);
|
||||
insertInCommandMap(rws::REQUEST_ID);
|
||||
insertInReplyMap(rws::REPLY_ID, 5, nullptr, 0, true);
|
||||
|
||||
insertInCommandMap(rws::RESET_MCU);
|
||||
insertInCommandAndReplyMap(rws::INIT_RW_CONTROLLER, 5, nullptr, 0, false, true, rws::REPLY_ID);
|
||||
insertInCommandAndReplyMap(rws::GET_TM, 5, nullptr, 0, false, true, rws::REPLY_ID);
|
||||
/*
|
||||
this->insertInCommandAndReplyMap(rws::GET_LAST_RESET_STATUS, 1, &lastResetStatusSet,
|
||||
rws::SIZE_GET_RESET_STATUS);
|
||||
this->insertInCommandAndReplyMap(rws::CLEAR_LAST_RESET_STATUS, 1, nullptr,
|
||||
@ -162,103 +231,106 @@ void RwHandler::fillCommandAndReplyMap() {
|
||||
rws::SIZE_GET_TEMPERATURE_REPLY);
|
||||
this->insertInCommandAndReplyMap(rws::SET_SPEED, 1, nullptr, rws::SIZE_SET_SPEED_REPLY);
|
||||
this->insertInCommandAndReplyMap(rws::GET_TM, 1, &tmDataset, rws::SIZE_GET_TELEMETRY_REPLY);
|
||||
*/
|
||||
}
|
||||
|
||||
ReturnValue_t RwHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||
uint8_t replyByte = *start;
|
||||
switch (replyByte) {
|
||||
case (rws::GET_LAST_RESET_STATUS): {
|
||||
*foundLen = rws::SIZE_GET_RESET_STATUS;
|
||||
*foundId = rws::GET_LAST_RESET_STATUS;
|
||||
break;
|
||||
}
|
||||
case (rws::CLEAR_LAST_RESET_STATUS): {
|
||||
*foundLen = rws::SIZE_CLEAR_RESET_STATUS;
|
||||
*foundId = rws::CLEAR_LAST_RESET_STATUS;
|
||||
break;
|
||||
}
|
||||
case (rws::GET_RW_STATUS): {
|
||||
*foundLen = rws::SIZE_GET_RW_STATUS;
|
||||
*foundId = rws::GET_RW_STATUS;
|
||||
break;
|
||||
}
|
||||
case (rws::INIT_RW_CONTROLLER): {
|
||||
*foundLen = rws::SIZE_INIT_RW;
|
||||
*foundId = rws::INIT_RW_CONTROLLER;
|
||||
break;
|
||||
}
|
||||
case (rws::SET_SPEED): {
|
||||
*foundLen = rws::SIZE_SET_SPEED_REPLY;
|
||||
*foundId = rws::SET_SPEED;
|
||||
break;
|
||||
}
|
||||
case (rws::GET_TEMPERATURE): {
|
||||
*foundLen = rws::SIZE_GET_TEMPERATURE_REPLY;
|
||||
*foundId = rws::GET_TEMPERATURE;
|
||||
break;
|
||||
}
|
||||
case (rws::GET_TM): {
|
||||
*foundLen = rws::SIZE_GET_TELEMETRY_REPLY;
|
||||
*foundId = rws::GET_TM;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::warning << "RwHandler::scanForReply: Reply contains invalid command code" << std::endl;
|
||||
*foundLen = remainingSize;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
// uint8_t replyByte = *start;
|
||||
if (remainingSize > 0) {
|
||||
*foundLen = remainingSize;
|
||||
*foundId = rws::REPLY_ID;
|
||||
}
|
||||
|
||||
sizeOfReply = *foundLen;
|
||||
|
||||
// RwReplies replies(start);
|
||||
// switch (replyByte) {
|
||||
// case (rws::GET_LAST_RESET_STATUS): {
|
||||
// *foundLen = rws::SIZE_GET_RESET_STATUS;
|
||||
// *foundId = rws::GET_LAST_RESET_STATUS;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::CLEAR_LAST_RESET_STATUS): {
|
||||
// *foundLen = rws::SIZE_CLEAR_RESET_STATUS;
|
||||
// *foundId = rws::CLEAR_LAST_RESET_STATUS;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::GET_RW_STATUS): {
|
||||
// *foundLen = rws::SIZE_GET_RW_STATUS;
|
||||
// *foundId = rws::GET_RW_STATUS;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::INIT_RW_CONTROLLER): {
|
||||
// *foundLen = rws::SIZE_INIT_RW;
|
||||
// *foundId = rws::INIT_RW_CONTROLLER;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::SET_SPEED): {
|
||||
// *foundLen = rws::SIZE_SET_SPEED_REPLY;
|
||||
// *foundId = rws::SET_SPEED;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::GET_TEMPERATURE): {
|
||||
// *foundLen = rws::SIZE_GET_TEMPERATURE_REPLY;
|
||||
// *foundId = rws::GET_TEMPERATURE;
|
||||
// break;
|
||||
// }
|
||||
// case (rws::GET_TM): {
|
||||
// *foundLen = rws::SIZE_GET_TELEMETRY_REPLY;
|
||||
// *foundId = rws::GET_TM;
|
||||
// break;
|
||||
// }
|
||||
// default: {
|
||||
// sif::warning << "RwHandler::scanForReply: Reply contains invalid command code" <<
|
||||
// std::endl; *foundLen = remainingSize; return returnvalue::FAILED;
|
||||
// }
|
||||
// }
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t RwHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
|
||||
/** Check result code */
|
||||
if (*(packet + 1) == rws::STATE_ERROR) {
|
||||
sif::error << "RwHandler::interpretDeviceReply: Command execution failed. Command id: " << id
|
||||
<< std::endl;
|
||||
return EXECUTION_FAILED;
|
||||
RwReplies replies(packet);
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
auto checkPacket = [&](DeviceCommandId_t id, const uint8_t* packetPtr) {
|
||||
auto packetLen = rws::idToPacketLen(id);
|
||||
uint16_t replyCrc = (*(packet + packetLen - 1) << 8) | *(packet + packetLen - 2);
|
||||
if (CRC::crc16ccitt(packet, packetLen - 2, 0xFFFF) != replyCrc) {
|
||||
sif::error << "RwHandler::interpretDeviceReply: CRC error for ID " << id << std::endl;
|
||||
return CRC_ERROR;
|
||||
}
|
||||
if (packetPtr[1] == rws::STATE_ERROR) {
|
||||
sif::error << "RwHandler::interpretDeviceReply: Command execution failed. Command id: " << id
|
||||
<< std::endl;
|
||||
result = EXECUTION_FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
};
|
||||
checkPacket(rws::DeviceCommandId::SET_SPEED, replies.getSetSpeedReply());
|
||||
if (returnvalue::OK ==
|
||||
checkPacket(rws::DeviceCommandId::GET_RW_STATUS, replies.getRwStatusReply())) {
|
||||
handleGetRwStatusReply(replies.getRwStatusReply());
|
||||
}
|
||||
|
||||
/** Received in little endian byte order */
|
||||
uint16_t replyCrc = *(packet + sizeOfReply - 1) << 8 | *(packet + sizeOfReply - 2);
|
||||
|
||||
if (CRC::crc16ccitt(packet, sizeOfReply - 2, 0xFFFF) != replyCrc) {
|
||||
sif::error << "RwHandler::interpretDeviceReply: cRC error" << std::endl;
|
||||
return CRC_ERROR;
|
||||
if (returnvalue::OK == checkPacket(rws::DeviceCommandId::GET_LAST_RESET_STATUS,
|
||||
replies.getGetLastResetStatusReply())) {
|
||||
handleResetStatusReply(replies.getGetLastResetStatusReply());
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case (rws::GET_LAST_RESET_STATUS): {
|
||||
handleResetStatusReply(packet);
|
||||
break;
|
||||
}
|
||||
case (rws::GET_RW_STATUS): {
|
||||
handleGetRwStatusReply(packet);
|
||||
break;
|
||||
}
|
||||
case (rws::CLEAR_LAST_RESET_STATUS):
|
||||
case (rws::INIT_RW_CONTROLLER):
|
||||
case (rws::SET_SPEED):
|
||||
// no reply data expected
|
||||
break;
|
||||
case (rws::GET_TEMPERATURE): {
|
||||
handleTemperatureReply(packet);
|
||||
break;
|
||||
}
|
||||
case (rws::GET_TM): {
|
||||
handleGetTelemetryReply(packet);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "RwHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
checkPacket(rws::DeviceCommandId::CLEAR_LAST_RESET_STATUS,
|
||||
replies.getClearLastResetStatusReply());
|
||||
if (returnvalue::OK ==
|
||||
checkPacket(rws::DeviceCommandId::GET_TEMPERATURE, replies.getReadTemperatureReply())) {
|
||||
handleTemperatureReply(replies.getReadTemperatureReply());
|
||||
}
|
||||
if (internalState == InternalState::GET_TM) {
|
||||
if (returnvalue::OK == checkPacket(rws::DeviceCommandId::GET_TM, replies.getHkDataReply())) {
|
||||
handleGetTelemetryReply(replies.getHkDataReply());
|
||||
}
|
||||
internalState = InternalState::DEFAULT;
|
||||
}
|
||||
if (internalState == InternalState::INIT_RW_CONTROLLER) {
|
||||
checkPacket(rws::DeviceCommandId::INIT_RW_CONTROLLER, replies.getInitRwControllerReply());
|
||||
internalState = InternalState::DEFAULT;
|
||||
}
|
||||
if (internalState == InternalState::RESET_MCU) {
|
||||
internalState = InternalState::DEFAULT;
|
||||
}
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -312,6 +384,7 @@ ReturnValue_t RwHandler::initializeLocalDataPool(localpool::DataPool& localDataP
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
/*
|
||||
void RwHandler::prepareSimpleCommand(DeviceCommandId_t id) {
|
||||
commandBuffer[0] = static_cast<uint8_t>(id);
|
||||
uint16_t crc = CRC::crc16ccitt(commandBuffer, 1, 0xFFFF);
|
||||
@ -320,6 +393,7 @@ void RwHandler::prepareSimpleCommand(DeviceCommandId_t id) {
|
||||
rawPacket = commandBuffer;
|
||||
rawPacketLen = 3;
|
||||
}
|
||||
*/
|
||||
|
||||
ReturnValue_t RwHandler::checkSpeedAndRampTime() {
|
||||
int32_t speed = 0;
|
||||
@ -338,6 +412,7 @@ ReturnValue_t RwHandler::checkSpeedAndRampTime() {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
/*
|
||||
ReturnValue_t RwHandler::prepareSetSpeedCmd() {
|
||||
commandBuffer[0] = static_cast<uint8_t>(rws::SET_SPEED);
|
||||
uint8_t* serPtr = commandBuffer + 1;
|
||||
@ -357,13 +432,14 @@ ReturnValue_t RwHandler::prepareSetSpeedCmd() {
|
||||
rawPacketLen = 9;
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
void RwHandler::handleResetStatusReply(const uint8_t* packet) {
|
||||
PoolReadGuard rg(&lastResetStatusSet);
|
||||
uint8_t offset = 2;
|
||||
uint8_t resetStatus = packet[offset];
|
||||
if (resetStatus != 0) {
|
||||
internalState = InternalState::CLEAR_RESET_STATUS;
|
||||
// internalState = InternalState::CLEAR_RESET_STATUS;
|
||||
lastResetStatusSet.lastNonClearedResetStatus = resetStatus;
|
||||
triggerEvent(rws::RESET_OCCURED, resetStatus, 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user