diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index f9f582e8..f5904969 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -793,7 +793,7 @@ void ObjectFactory::createSolarArrayDeploymentComponents() { void ObjectFactory::createSyrlinksComponents() { UartCookie* syrlinksUartCookie = new UartCookie(objects::SYRLINKS_HK_HANDLER, q7s::UART_SYRLINKS_DEV, UartModes::NON_CANONICAL, - uart::SYRLINKS_BAUD, SYRLINKS::MAX_REPLY_SIZE); + uart::SYRLINKS_BAUD, syrlinks::MAX_REPLY_SIZE); syrlinksUartCookie->setParityEven(); new SyrlinksHkHandler(objects::SYRLINKS_HK_HANDLER, objects::UART_COM_IF, syrlinksUartCookie, diff --git a/mission/devices/SyrlinksHkHandler.cpp b/mission/devices/SyrlinksHkHandler.cpp index 017bd53c..4ee7ec5c 100644 --- a/mission/devices/SyrlinksHkHandler.cpp +++ b/mission/devices/SyrlinksHkHandler.cpp @@ -9,17 +9,27 @@ SyrlinksHkHandler::SyrlinksHkHandler(object_id_t objectId, object_id_t comIF, Co : DeviceHandlerBase(objectId, comIF, comCookie), rxDataset(this), txDataset(this), + temperatureSet(this), powerSwitch(powerSwitch) { if (comCookie == NULL) { - sif::error << "SyrlinksHkHandler: Invalid com cookie" << std::endl; + sif::warning << "SyrlinksHkHandler: Invalid com cookie" << std::endl; } } SyrlinksHkHandler::~SyrlinksHkHandler() {} void SyrlinksHkHandler::doStartUp() { - if (mode == _MODE_START_UP) { - setMode(MODE_ON); + switch (startupState) { + case StartupState::OFF: { + startupState = StartupState::ENABLE_TEMPERATURE_PROTECTION; + break; + } + case StartupState::DONE: { + setMode(_MODE_TO_ON); + break; + } + default: + break; } } @@ -27,41 +37,41 @@ void SyrlinksHkHandler::doShutDown() { setMode(_MODE_POWER_DOWN); } ReturnValue_t SyrlinksHkHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { switch (nextCommand) { - case (SYRLINKS::READ_RX_STATUS_REGISTERS): - *id = SYRLINKS::READ_RX_STATUS_REGISTERS; - nextCommand = SYRLINKS::READ_TX_STATUS; + case (syrlinks::READ_RX_STATUS_REGISTERS): + *id = syrlinks::READ_RX_STATUS_REGISTERS; + nextCommand = syrlinks::READ_TX_STATUS; break; - case (SYRLINKS::READ_TX_STATUS): - *id = SYRLINKS::READ_TX_STATUS; - nextCommand = SYRLINKS::READ_TX_WAVEFORM; + case (syrlinks::READ_TX_STATUS): + *id = syrlinks::READ_TX_STATUS; + nextCommand = syrlinks::READ_TX_WAVEFORM; break; - case (SYRLINKS::READ_TX_WAVEFORM): - *id = SYRLINKS::READ_TX_WAVEFORM; - nextCommand = SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE; + case (syrlinks::READ_TX_WAVEFORM): + *id = syrlinks::READ_TX_WAVEFORM; + nextCommand = syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE; break; - case (SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE): - *id = SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE; - nextCommand = SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE; + case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE): + *id = syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE; + nextCommand = syrlinks::READ_TX_AGC_VALUE_LOW_BYTE; break; - case (SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE): - *id = SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE; - nextCommand = SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE; + case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE): + *id = syrlinks::READ_TX_AGC_VALUE_LOW_BYTE; + nextCommand = syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE; break; - case (SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE): - *id = SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE; - nextCommand = SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE; + case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE): + *id = syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE; + nextCommand = syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE; break; - case (SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE): - *id = SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE; - nextCommand = SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE; + case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE): + *id = syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE; + nextCommand = syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE; break; - case (SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE): - *id = SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE; - nextCommand = SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE; + case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE): + *id = syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE; + nextCommand = syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE; break; - case (SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE): - *id = SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE; - nextCommand = SYRLINKS::READ_RX_STATUS_REGISTERS; + case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE): + *id = syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE; + nextCommand = syrlinks::READ_RX_STATUS_REGISTERS; break; default: sif::debug << "SyrlinksHkHandler::buildNormalDeviceCommand: rememberCommandId has invalid" @@ -72,111 +82,123 @@ ReturnValue_t SyrlinksHkHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) } ReturnValue_t SyrlinksHkHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { - return HasReturnvaluesIF::RETURN_OK; + switch (startupState) { + case StartupState::ENABLE_TEMPERATURE_PROTECTION: { + *id = syrlinks::WRITE_LCL_CONFIG; + return HasReturnvaluesIF::RETURN_OK; + } + default: + break; + } + return NOTHING_TO_SEND; } ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, size_t commandDataLen) { switch (deviceCommand) { - case (SYRLINKS::RESET_UNIT): { + case (syrlinks::RESET_UNIT): { resetCommand.copy(reinterpret_cast(commandBuffer), resetCommand.size(), 0); rawPacketLen = resetCommand.size(); rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::SET_TX_MODE_STANDBY): { + case (syrlinks::SET_TX_MODE_STANDBY): { setTxModeStandby.copy(reinterpret_cast(commandBuffer), setTxModeStandby.size(), 0); rawPacketLen = setTxModeStandby.size(); rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::SET_TX_MODE_MODULATION): { + case (syrlinks::SET_TX_MODE_MODULATION): { setTxModeModulation.copy(reinterpret_cast(commandBuffer), setTxModeModulation.size(), 0); rawPacketLen = setTxModeModulation.size(); rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::SET_TX_MODE_CW): { + case (syrlinks::SET_TX_MODE_CW): { setTxModeCw.copy(reinterpret_cast(commandBuffer), setTxModeCw.size(), 0); rawPacketLen = setTxModeCw.size(); rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::WRITE_LCL_CONFIG): { + case (syrlinks::WRITE_LCL_CONFIG): { writeLclConfig.copy(reinterpret_cast(commandBuffer), writeLclConfig.size(), 0); rawPacketLen = writeLclConfig.size(); rawPacket = commandBuffer; + rememberCommandId = syrlinks::WRITE_LCL_CONFIG; return RETURN_OK; } - case (SYRLINKS::READ_RX_STATUS_REGISTERS): { + case (syrlinks::READ_RX_STATUS_REGISTERS): { readRxStatusRegCommand.copy(reinterpret_cast(commandBuffer), readRxStatusRegCommand.size(), 0); rawPacketLen = readRxStatusRegCommand.size(); rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::READ_LCL_CONFIG): { + case (syrlinks::READ_LCL_CONFIG): { readLclConfig.copy(reinterpret_cast(commandBuffer), readLclConfig.size(), 0); rawPacketLen = readLclConfig.size(); rawPacket = commandBuffer; - rememberCommandId = SYRLINKS::READ_LCL_CONFIG; + rememberCommandId = syrlinks::READ_LCL_CONFIG; return RETURN_OK; } - case (SYRLINKS::READ_TX_STATUS): { + case (syrlinks::READ_TX_STATUS): { readTxStatus.copy(reinterpret_cast(commandBuffer), readTxStatus.size(), 0); rawPacketLen = readTxStatus.size(); - rememberCommandId = SYRLINKS::READ_TX_STATUS; + rememberCommandId = syrlinks::READ_TX_STATUS; rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::READ_TX_WAVEFORM): { + case (syrlinks::READ_TX_WAVEFORM): { readTxWaveform.copy(reinterpret_cast(commandBuffer), readTxWaveform.size(), 0); rawPacketLen = readTxWaveform.size(); - rememberCommandId = SYRLINKS::READ_TX_WAVEFORM; + rememberCommandId = syrlinks::READ_TX_WAVEFORM; rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE): { - readTxAgcValueHighByte.copy(reinterpret_cast(commandBuffer), readTxAgcValueHighByte.size(), 0); + case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE): { + readTxAgcValueHighByte.copy(reinterpret_cast(commandBuffer), + readTxAgcValueHighByte.size(), 0); rawPacketLen = readTxAgcValueHighByte.size(); - rememberCommandId = SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE; + rememberCommandId = syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE; rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE): { - readTxAgcValueLowByte.copy(reinterpret_cast(commandBuffer), readTxAgcValueLowByte.size(), 0); + case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE): { + readTxAgcValueLowByte.copy(reinterpret_cast(commandBuffer), + readTxAgcValueLowByte.size(), 0); rawPacketLen = readTxAgcValueLowByte.size(); - rememberCommandId = SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE; + rememberCommandId = syrlinks::READ_TX_AGC_VALUE_LOW_BYTE; rawPacket = commandBuffer; return RETURN_OK; } - case (SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE): - tempPowerAmpBoardHighByte.copy(reinterpret_cast(commandBuffer), tempPowerAmpBoardHighByte.size(), - 0); + case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE): + tempPowerAmpBoardHighByte.copy(reinterpret_cast(commandBuffer), + tempPowerAmpBoardHighByte.size(), 0); rawPacketLen = tempPowerAmpBoardHighByte.size(); - rememberCommandId = SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE; + rememberCommandId = syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE; rawPacket = commandBuffer; return RETURN_OK; - case (SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE): - tempPowerAmpBoardLowByte.copy(reinterpret_cast(commandBuffer), tempPowerAmpBoardLowByte.size(), - 0); + case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE): + tempPowerAmpBoardLowByte.copy(reinterpret_cast(commandBuffer), + tempPowerAmpBoardLowByte.size(), 0); rawPacketLen = tempPowerAmpBoardLowByte.size(); - rememberCommandId = SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE; + rememberCommandId = syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE; rawPacket = commandBuffer; return RETURN_OK; - case (SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE): - tempBasebandBoardHighByte.copy(reinterpret_cast(commandBuffer), tempBasebandBoardHighByte.size(), - 0); + case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE): + tempBasebandBoardHighByte.copy(reinterpret_cast(commandBuffer), + tempBasebandBoardHighByte.size(), 0); rawPacketLen = tempBasebandBoardHighByte.size(); - rememberCommandId = SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE; + rememberCommandId = syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE; rawPacket = commandBuffer; return RETURN_OK; - case (SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE): - tempBasebandBoardLowByte.copy(reinterpret_cast(commandBuffer), tempBasebandBoardLowByte.size(), 0); + case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE): + tempBasebandBoardLowByte.copy(reinterpret_cast(commandBuffer), + tempBasebandBoardLowByte.size(), 0); rawPacketLen = tempBasebandBoardLowByte.size(); - rememberCommandId = SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE; + rememberCommandId = syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE; rawPacket = commandBuffer; return RETURN_OK; default: @@ -186,36 +208,36 @@ ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(DeviceCommandId_t devic } void SyrlinksHkHandler::fillCommandAndReplyMap() { - this->insertInCommandAndReplyMap(SYRLINKS::RESET_UNIT, 1, nullptr, SYRLINKS::ACK_SIZE, false, - true, SYRLINKS::ACK_REPLY); - this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_STANDBY, 1, nullptr, SYRLINKS::ACK_SIZE, - false, true, SYRLINKS::ACK_REPLY); - this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_MODULATION, 1, nullptr, SYRLINKS::ACK_SIZE, - false, true, SYRLINKS::ACK_REPLY); - this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_CW, 1, nullptr, SYRLINKS::ACK_SIZE, false, - true, SYRLINKS::ACK_REPLY); - this->insertInCommandAndReplyMap(SYRLINKS::WRITE_LCL_CONFIG, 1, nullptr, SYRLINKS::ACK_SIZE, - false, true, SYRLINKS::ACK_REPLY); - this->insertInCommandAndReplyMap(SYRLINKS::READ_LCL_CONFIG, 1, nullptr, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::READ_TX_STATUS, 1, &txDataset, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::READ_TX_WAVEFORM, 1, &txDataset, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE, 1, &txDataset, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE, 1, &txDataset, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE, 1, nullptr, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE, 1, nullptr, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE, 1, nullptr, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE, 1, nullptr, - SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); - this->insertInCommandAndReplyMap(SYRLINKS::READ_RX_STATUS_REGISTERS, 1, &rxDataset, - SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE); + this->insertInCommandAndReplyMap(syrlinks::RESET_UNIT, 1, nullptr, syrlinks::ACK_SIZE, false, + true, syrlinks::ACK_REPLY); + this->insertInCommandAndReplyMap(syrlinks::SET_TX_MODE_STANDBY, 1, nullptr, syrlinks::ACK_SIZE, + false, true, syrlinks::ACK_REPLY); + this->insertInCommandAndReplyMap(syrlinks::SET_TX_MODE_MODULATION, 1, nullptr, syrlinks::ACK_SIZE, + false, true, syrlinks::ACK_REPLY); + this->insertInCommandAndReplyMap(syrlinks::SET_TX_MODE_CW, 1, nullptr, syrlinks::ACK_SIZE, false, + true, syrlinks::ACK_REPLY); + this->insertInCommandAndReplyMap(syrlinks::WRITE_LCL_CONFIG, 1, nullptr, syrlinks::ACK_SIZE, + false, true, syrlinks::ACK_REPLY); + this->insertInCommandAndReplyMap(syrlinks::READ_LCL_CONFIG, 1, nullptr, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::READ_TX_STATUS, 1, &txDataset, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::READ_TX_WAVEFORM, 1, &txDataset, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE, 1, &txDataset, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::READ_TX_AGC_VALUE_LOW_BYTE, 1, &txDataset, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE, 1, nullptr, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE, 1, nullptr, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE, 1, nullptr, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE, 1, nullptr, + syrlinks::READ_ONE_REGISTER_REPLY_SIE); + this->insertInCommandAndReplyMap(syrlinks::READ_RX_STATUS_REGISTERS, 1, &rxDataset, + syrlinks::RX_STATUS_REGISTERS_REPLY_SIZE); } ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t* start, size_t remainingSize, @@ -223,25 +245,25 @@ ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t* start, size_t remai ReturnValue_t result = RETURN_OK; if (*start != '<') { - sif::error << "SyrlinksHkHandler::scanForReply: Missing start frame character" << std::endl; + sif::warning << "SyrlinksHkHandler::scanForReply: Missing start frame character" << std::endl; return MISSING_START_FRAME_CHARACTER; } switch (*(start + 1)) { case ('A'): - *foundLen = SYRLINKS::ACK_SIZE; - *foundId = SYRLINKS::ACK_REPLY; + *foundLen = syrlinks::ACK_SIZE; + *foundId = syrlinks::ACK_REPLY; break; case ('E'): - *foundLen = SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE; - *foundId = SYRLINKS::READ_RX_STATUS_REGISTERS; + *foundLen = syrlinks::RX_STATUS_REGISTERS_REPLY_SIZE; + *foundId = syrlinks::READ_RX_STATUS_REGISTERS; break; case ('R'): *foundId = rememberCommandId; - *foundLen = SYRLINKS::READ_ONE_REGISTER_REPLY_SIE; + *foundLen = syrlinks::READ_ONE_REGISTER_REPLY_SIE; break; default: - sif::error << "SyrlinksHkHandler::scanForReply: Unknown reply identifier" << std::endl; + sif::warning << "SyrlinksHkHandler::scanForReply: Unknown reply identifier" << std::endl; result = IGNORE_REPLY_DATA; break; } @@ -262,124 +284,142 @@ ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id, cons ReturnValue_t result; switch (id) { - case (SYRLINKS::ACK_REPLY): - result = verifyReply(packet, SYRLINKS::ACK_SIZE); + case (syrlinks::ACK_REPLY): { + result = verifyReply(packet, syrlinks::ACK_SIZE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Acknowledgment reply has " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Acknowledgment reply has " "invalid crc" << std::endl; return CRC_FAILURE; } - result = - parseReplyStatus(reinterpret_cast(packet + SYRLINKS::MESSAGE_HEADER_SIZE)); + result = handleAckReply(packet); if (result != RETURN_OK) { return result; } break; - case (SYRLINKS::READ_RX_STATUS_REGISTERS): - result = verifyReply(packet, SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE); + } + case (syrlinks::READ_RX_STATUS_REGISTERS): { + result = verifyReply(packet, syrlinks::RX_STATUS_REGISTERS_REPLY_SIZE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read rx status registers reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read rx status registers reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseRxStatusRegistersReply(packet); break; - case (SYRLINKS::READ_LCL_CONFIG): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::READ_LCL_CONFIG): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read config lcl reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read config lcl reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseLclConfigReply(packet); break; - case (SYRLINKS::READ_TX_STATUS): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::READ_TX_STATUS): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx status reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx status reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseTxStatusReply(packet); break; - case (SYRLINKS::READ_TX_WAVEFORM): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::READ_TX_WAVEFORM): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx waveform reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx waveform reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseTxWaveformReply(packet); break; - case (SYRLINKS::READ_TX_AGC_VALUE_HIGH_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC high byte reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC high byte reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseAgcHighByte(packet); break; - case (SYRLINKS::READ_TX_AGC_VALUE_LOW_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC low byte reply " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC low byte reply " << "has invalid crc" << std::endl; return CRC_FAILURE; } parseAgcLowByte(packet); break; - case (SYRLINKS::TEMP_BASEBAND_BOARD_HIGH_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board " << "high byte reply has invalid crc" << std::endl; return CRC_FAILURE; } rawTempBasebandBoard = convertHexStringToUint8(reinterpret_cast( - packet + SYRLINKS::MESSAGE_HEADER_SIZE)) + packet + syrlinks::MESSAGE_HEADER_SIZE)) << 8; break; - case (SYRLINKS::TEMP_BASEBAND_BOARD_LOW_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board" + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board" " low byte reply has invalid crc" << std::endl; return CRC_FAILURE; } rawTempBasebandBoard |= convertHexStringToUint8( - reinterpret_cast(packet + SYRLINKS::MESSAGE_HEADER_SIZE)); + reinterpret_cast(packet + syrlinks::MESSAGE_HEADER_SIZE)); tempBasebandBoard = calcTempVal(rawTempBasebandBoard); - sif::info << "Syrlinks temperature baseband board: " << tempBasebandBoard << " °C" - << std::endl; + temperatureSet.temperatureBasebandBoard = tempBasebandBoard; + PoolReadGuard rg(&temperatureSet); + if (debug) { + sif::info << "Syrlinks temperature baseband board: " << tempBasebandBoard << " °C" + << std::endl; + } break; - case (SYRLINKS::TEMP_POWER_AMPLIFIER_HIGH_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier " + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier " << "board high byte reply has invalid crc" << std::endl; return CRC_FAILURE; } rawTempPowerAmplifier = 0; rawTempPowerAmplifier = convertHexStringToUint8(reinterpret_cast( - packet + SYRLINKS::MESSAGE_HEADER_SIZE)) - << 8; + packet + syrlinks::MESSAGE_HEADER_SIZE)) + << 8; break; - case (SYRLINKS::TEMP_POWER_AMPLIFIER_LOW_BYTE): - result = verifyReply(packet, SYRLINKS::READ_ONE_REGISTER_REPLY_SIE); + } + case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE): { + result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE); if (result != RETURN_OK) { - sif::error << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier" + sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier" << " board low byte reply has invalid crc" << std::endl; return CRC_FAILURE; } rawTempPowerAmplifier |= convertHexStringToUint8( - reinterpret_cast(packet + SYRLINKS::MESSAGE_HEADER_SIZE)); + reinterpret_cast(packet + syrlinks::MESSAGE_HEADER_SIZE)); tempPowerAmplifier = calcTempVal(rawTempPowerAmplifier); - sif::info << "Syrlinks temperature power amplifier board: " << tempPowerAmplifier << " °C" - << std::endl; + PoolReadGuard rg(&temperatureSet); + temperatureSet.temperaturePowerAmplifier = tempPowerAmplifier; + if (debug) { + sif::info << "Syrlinks temperature power amplifier board: " << tempPowerAmplifier + << " °C" << std::endl; + } break; + } default: { sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Unknown device reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; @@ -394,8 +434,10 @@ LocalPoolDataSetBase* SyrlinksHkHandler::getDataSetHandle(sid_t sid) { return &rxDataset; } else if (sid == txDataset.getSid()) { return &txDataset; + } else if (sid == temperatureSet.getSid()) { + return &temperatureSet; } else { - sif::error << "SyrlinksHkHandler::getDataSetHandle: Invalid sid" << std::endl; + sif::warning << "SyrlinksHkHandler::getDataSetHandle: Invalid sid" << std::endl; return nullptr; } } @@ -479,11 +521,11 @@ ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size int result = 0; /* Calculate crc from received packet */ uint16_t crc = - CRC::crc16ccitt(packet, size - SYRLINKS::SIZE_CRC_AND_TERMINATION, CRC_INITIAL_VALUE); + CRC::crc16ccitt(packet, size - syrlinks::SIZE_CRC_AND_TERMINATION, CRC_INITIAL_VALUE); std::string recalculatedCrc = convertUint16ToHexString(crc); const char* startOfCrc = - reinterpret_cast(packet + size - SYRLINKS::SIZE_CRC_AND_TERMINATION); + reinterpret_cast(packet + size - syrlinks::SIZE_CRC_AND_TERMINATION); const char* endOfCrc = reinterpret_cast(packet + size - 1); std::string replyCrc(startOfCrc, endOfCrc); @@ -497,7 +539,7 @@ ReturnValue_t SyrlinksHkHandler::verifyReply(const uint8_t* packet, uint8_t size void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) { PoolReadGuard readHelper(&rxDataset); - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; rxDataset.rxStatus = convertHexStringToUint8(reinterpret_cast(packet + offset)); offset += 2; rxDataset.rxSensitivity = @@ -531,7 +573,7 @@ void SyrlinksHkHandler::parseRxStatusRegistersReply(const uint8_t* packet) { } void SyrlinksHkHandler::parseLclConfigReply(const uint8_t* packet) { - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; uint8_t lclConfig = convertHexStringToUint8(reinterpret_cast(packet + offset)); sif::info << "SyrlinksHkHandler::parseRxStatusRegistersReply: Lcl config: " << static_cast(lclConfig) << std::endl; @@ -539,7 +581,7 @@ void SyrlinksHkHandler::parseLclConfigReply(const uint8_t* packet) { void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) { PoolReadGuard readHelper(&txDataset); - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; txDataset.txStatus = convertHexStringToUint8(reinterpret_cast(packet + offset)); #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SYRLINKS == 1 sif::info << "Syrlinks TX Status: 0x" << std::hex << (unsigned int)txDataset.txStatus.value @@ -549,7 +591,7 @@ void SyrlinksHkHandler::parseTxStatusReply(const uint8_t* packet) { void SyrlinksHkHandler::parseTxWaveformReply(const uint8_t* packet) { PoolReadGuard readHelper(&txDataset); - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; txDataset.txWaveform = convertHexStringToUint8(reinterpret_cast(packet + offset)); #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SYRLINKS == 1 sif::info << "Syrlinks TX Waveform: 0x" << std::hex << (unsigned int)txDataset.txWaveform.value @@ -559,7 +601,7 @@ void SyrlinksHkHandler::parseTxWaveformReply(const uint8_t* packet) { void SyrlinksHkHandler::parseAgcLowByte(const uint8_t* packet) { PoolReadGuard readHelper(&txDataset); - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; txDataset.txAgcValue = agcValueHighByte << 8 | convertHexStringToUint8(reinterpret_cast(packet + offset)); #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_SYRLINKS == 1 @@ -569,7 +611,7 @@ void SyrlinksHkHandler::parseAgcLowByte(const uint8_t* packet) { void SyrlinksHkHandler::parseAgcHighByte(const uint8_t* packet) { PoolReadGuard readHelper(&txDataset); - uint16_t offset = SYRLINKS::MESSAGE_HEADER_SIZE; + uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE; agcValueHighByte = convertHexStringToUint8(reinterpret_cast(packet + offset)); } @@ -579,18 +621,18 @@ uint32_t SyrlinksHkHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(SYRLINKS::RX_STATUS, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_SENSITIVITY, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_FREQUENCY_SHIFT, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_IQ_POWER, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_AGC_VALUE, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_DEMOD_EB, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_DEMOD_N0, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::RX_DATA_RATE, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_STATUS, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_SENSITIVITY, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_FREQUENCY_SHIFT, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_IQ_POWER, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_AGC_VALUE, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_DEMOD_EB, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_DEMOD_N0, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::RX_DATA_RATE, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::TX_STATUS, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::TX_WAVEFORM, new PoolEntry({0})); - localDataPoolMap.emplace(SYRLINKS::TX_AGC_VALUE, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::TX_STATUS, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::TX_WAVEFORM, new PoolEntry({0})); + localDataPoolMap.emplace(syrlinks::TX_AGC_VALUE, new PoolEntry({0})); return HasReturnvaluesIF::RETURN_OK; } @@ -598,3 +640,14 @@ ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& lo void SyrlinksHkHandler::setModeNormal() { mode = MODE_NORMAL; } float SyrlinksHkHandler::calcTempVal(uint16_t raw) { return 0.126984 * raw - 67.87; } + +ReturnValue_t SyrlinksHkHandler::handleAckReply(const uint8_t* packet) { + ReturnValue_t result = + parseReplyStatus(reinterpret_cast(packet + syrlinks::MESSAGE_HEADER_SIZE)); + if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result != RETURN_OK) { + startupState = StartupState::OFF; + } else if (rememberCommandId == syrlinks::WRITE_LCL_CONFIG and result == RETURN_OK) { + startupState = StartupState::DONE; + } + return result; +} diff --git a/mission/devices/SyrlinksHkHandler.h b/mission/devices/SyrlinksHkHandler.h index 9b9e05c2..b330f151 100644 --- a/mission/devices/SyrlinksHkHandler.h +++ b/mission/devices/SyrlinksHkHandler.h @@ -80,10 +80,11 @@ class SyrlinksHkHandler : public DeviceHandlerBase { * In some cases it is not possible to extract from the received reply the information about * the associated command. This variable is thus used to remember the command id. */ - DeviceCommandId_t rememberCommandId = SYRLINKS::NONE; + DeviceCommandId_t rememberCommandId = syrlinks::NONE; - SYRLINKS::RxDataset rxDataset; - SYRLINKS::TxDataset txDataset; + syrlinks::RxDataset rxDataset; + syrlinks::TxDataset txDataset; + syrlinks::TemperatureSet temperatureSet; const power::Switch_t powerSwitch = power::NO_SWITCH; @@ -93,13 +94,23 @@ class SyrlinksHkHandler : public DeviceHandlerBase { float tempPowerAmplifier = 0; float tempBasebandBoard = 0; - uint8_t commandBuffer[SYRLINKS::MAX_COMMAND_SIZE]; + uint8_t commandBuffer[syrlinks::MAX_COMMAND_SIZE]; + + enum class StartupState { + OFF, + ENABLE_TEMPERATURE_PROTECTION, + DONE + }; + + StartupState startupState = StartupState::OFF; + + bool debug = false; /** * This object is used to store the id of the next command to execute. This controls the * read out of multiple registers which can not be fetched with one single command. */ - DeviceCommandId_t nextCommand = SYRLINKS::READ_RX_STATUS_REGISTERS; + DeviceCommandId_t nextCommand = syrlinks::READ_RX_STATUS_REGISTERS; /** * @brief This function converts an uint16_t into its hexadecimal string representation. @@ -192,6 +203,8 @@ class SyrlinksHkHandler : public DeviceHandlerBase { * @brief Calculates temperature in degree celcius form raw value */ float calcTempVal(uint16_t); + + ReturnValue_t handleAckReply(const uint8_t* packet); }; #endif /* MISSION_DEVICES_SYRLINKSHKHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SyrlinksDefinitions.h b/mission/devices/devicedefinitions/SyrlinksDefinitions.h index affebff7..e8973621 100644 --- a/mission/devices/devicedefinitions/SyrlinksDefinitions.h +++ b/mission/devices/devicedefinitions/SyrlinksDefinitions.h @@ -1,7 +1,7 @@ #ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_ #define MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_ -namespace SYRLINKS { +namespace syrlinks { static const DeviceCommandId_t NONE = 0; static const DeviceCommandId_t RESET_UNIT = 1; @@ -36,6 +36,7 @@ static const uint8_t READ_ONE_REGISTER_REPLY_SIE = 13; static const uint8_t RX_DATASET_ID = 0x1; static const uint8_t TX_DATASET_ID = 0x2; +static const uint8_t TEMPERATURE_SET_ID = 0x3; static const size_t MAX_REPLY_SIZE = RX_STATUS_REGISTERS_REPLY_SIZE; static const size_t MAX_COMMAND_SIZE = 15; @@ -44,6 +45,7 @@ static const size_t CRC_FIELD_SIZE = 4; static const uint8_t RX_DATASET_SIZE = 8; static const uint8_t TX_DATASET_SIZE = 3; +static const uint8_t TEMPERATURE_SET_SIZE = 3; enum SyrlinksPoolIds : lp_id_t { RX_STATUS, @@ -60,6 +62,8 @@ enum SyrlinksPoolIds : lp_id_t { TX_WAVEFORM, TX_PCM_INDEX, TX_AGC_VALUE, + TEMP_POWER_AMPLIFIER, + TEMP_BASEBAND_BOARD }; class RxDataset : public StaticLocalDataSet { @@ -89,6 +93,18 @@ class TxDataset : public StaticLocalDataSet { lp_var_t txAgcValue = lp_var_t(sid.objectId, TX_AGC_VALUE, this); }; -} // namespace SYRLINKS +class TemperatureSet : public StaticLocalDataSet { + public: + TemperatureSet(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, TEMPERATURE_SET_ID) {} + + TemperatureSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, TEMPERATURE_SET_ID)) {} + + lp_var_t temperaturePowerAmplifier = + lp_var_t(sid.objectId, TEMP_POWER_AMPLIFIER, this); + lp_var_t temperatureBasebandBoard = + lp_var_t(sid.objectId, TEMP_BASEBAND_BOARD, this); +}; + +} // namespace syrlinks #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SYRLINKSDEFINITIONS_H_ */