2021-03-22 13:09:06 +01:00
|
|
|
#include <fsfw/datapool/PoolReadGuard.h>
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <fsfw/globalfunctions/CRC.h>
|
2023-03-24 19:37:03 +01:00
|
|
|
#include <mission/com/SyrlinksHandler.h>
|
2023-01-24 19:40:27 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
#include "OBSWConfig.h"
|
2023-01-27 18:38:36 +01:00
|
|
|
#include "mission/config/comCfg.h"
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
SyrlinksHandler::SyrlinksHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
|
2023-01-24 19:40:27 +01:00
|
|
|
power::Switch_t powerSwitch, FailureIsolationBase* customFdir)
|
2022-04-28 15:29:57 +02:00
|
|
|
: DeviceHandlerBase(objectId, comIF, comCookie, customFdir),
|
2022-03-30 09:19:30 +02:00
|
|
|
rxDataset(this),
|
|
|
|
txDataset(this),
|
2022-03-31 17:44:29 +02:00
|
|
|
temperatureSet(this),
|
2022-04-01 14:15:42 +02:00
|
|
|
powerSwitch(powerSwitch) {
|
2022-04-05 08:38:36 +02:00
|
|
|
if (comCookie == nullptr) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler: Invalid com cookie" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:40:27 +01:00
|
|
|
SyrlinksHandler::~SyrlinksHandler() = default;
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::doStartUp() {
|
2023-01-26 14:00:39 +01:00
|
|
|
if (internalState == InternalState::OFF) {
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-26 14:00:39 +01:00
|
|
|
internalState = InternalState::ENABLE_TEMPERATURE_PROTECTION;
|
|
|
|
commandExecuted = false;
|
2023-01-26 12:21:49 +01:00
|
|
|
}
|
2023-01-26 14:00:39 +01:00
|
|
|
if (internalState == InternalState::ENABLE_TEMPERATURE_PROTECTION) {
|
|
|
|
if (commandExecuted) {
|
2023-01-26 16:33:11 +01:00
|
|
|
// Go to normal mode immediately and disable transmitter on startup.
|
2023-01-26 13:00:03 +01:00
|
|
|
setMode(_MODE_TO_NORMAL);
|
2023-01-26 12:21:49 +01:00
|
|
|
internalState = InternalState::IDLE;
|
2023-01-24 19:40:27 +01:00
|
|
|
commandExecuted = false;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::doShutDown() {
|
2023-01-26 16:16:23 +01:00
|
|
|
// In any case, always disable TX first.
|
2023-01-26 16:33:11 +01:00
|
|
|
if (internalState != InternalState::SET_TX_STANDBY) {
|
|
|
|
internalState = InternalState::SET_TX_STANDBY;
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-26 16:16:23 +01:00
|
|
|
commandExecuted = false;
|
2023-01-26 16:33:11 +01:00
|
|
|
}
|
|
|
|
if (internalState == InternalState::SET_TX_STANDBY) {
|
|
|
|
if (commandExecuted) {
|
|
|
|
temperatureSet.setValidity(false, true);
|
|
|
|
internalState = InternalState::OFF;
|
|
|
|
commandExecuted = false;
|
|
|
|
setMode(_MODE_POWER_DOWN);
|
|
|
|
}
|
2023-01-26 16:16:23 +01:00
|
|
|
}
|
2023-01-23 15:35:43 +01:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (nextCommand) {
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_RX_STATUS_REGISTERS):
|
|
|
|
*id = syrlinks::READ_RX_STATUS_REGISTERS;
|
|
|
|
nextCommand = syrlinks::READ_TX_STATUS;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_STATUS):
|
|
|
|
*id = syrlinks::READ_TX_STATUS;
|
|
|
|
nextCommand = syrlinks::READ_TX_WAVEFORM;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_WAVEFORM):
|
|
|
|
*id = syrlinks::READ_TX_WAVEFORM;
|
|
|
|
nextCommand = syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE):
|
|
|
|
*id = syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE;
|
|
|
|
nextCommand = syrlinks::READ_TX_AGC_VALUE_LOW_BYTE;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE):
|
|
|
|
*id = syrlinks::READ_TX_AGC_VALUE_LOW_BYTE;
|
|
|
|
nextCommand = syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE;
|
2022-03-31 11:50:33 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE):
|
|
|
|
*id = syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE;
|
|
|
|
nextCommand = syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE;
|
2022-03-31 11:50:33 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE):
|
|
|
|
*id = syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE;
|
|
|
|
nextCommand = syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE;
|
2022-03-31 11:50:33 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE):
|
|
|
|
*id = syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE;
|
|
|
|
nextCommand = syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE;
|
2022-03-31 11:50:33 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE):
|
|
|
|
*id = syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE;
|
|
|
|
nextCommand = syrlinks::READ_RX_STATUS_REGISTERS;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
2021-03-01 12:23:39 +01:00
|
|
|
default:
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::buildNormalDeviceCommand: rememberCommandId has invalid"
|
|
|
|
<< "command id" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2022-04-05 08:38:36 +02:00
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
|
2023-01-24 19:40:27 +01:00
|
|
|
switch (internalState) {
|
|
|
|
case InternalState::ENABLE_TEMPERATURE_PROTECTION: {
|
2022-03-31 17:44:29 +02:00
|
|
|
*id = syrlinks::WRITE_LCL_CONFIG;
|
2022-04-05 08:38:36 +02:00
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
2023-01-24 19:40:27 +01:00
|
|
|
case InternalState::SET_TX_MODULATION: {
|
|
|
|
*id = syrlinks::SET_TX_MODE_MODULATION;
|
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
|
|
|
}
|
2023-01-26 12:21:49 +01:00
|
|
|
case InternalState::SELECT_MODULATION_BPSK: {
|
|
|
|
*id = syrlinks::SET_WAVEFORM_BPSK;
|
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
|
|
|
}
|
|
|
|
case InternalState::SELECT_MODULATION_0QPSK: {
|
|
|
|
*id = syrlinks::SET_WAVEFORM_0QPSK;
|
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
|
|
|
}
|
2023-01-24 19:40:27 +01:00
|
|
|
case InternalState::SET_TX_CW: {
|
|
|
|
*id = syrlinks::SET_TX_MODE_CW;
|
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
|
|
|
}
|
|
|
|
case InternalState::SET_TX_STANDBY: {
|
|
|
|
*id = syrlinks::SET_TX_MODE_STANDBY;
|
|
|
|
return buildCommandFromCommand(*id, nullptr, 0);
|
|
|
|
}
|
2023-03-31 12:11:31 +02:00
|
|
|
default: {
|
2022-03-31 17:44:29 +02:00
|
|
|
break;
|
2023-03-31 12:11:31 +02:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
return NOTHING_TO_SEND;
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
2023-01-24 19:40:27 +01:00
|
|
|
const uint8_t* commandData,
|
|
|
|
size_t commandDataLen) {
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (deviceCommand) {
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::RESET_UNIT): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(resetCommand, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::SET_TX_MODE_STANDBY): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(setTxModeStandby, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::SET_TX_MODE_MODULATION): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(setTxModeModulation, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::SET_TX_MODE_CW): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(setTxModeCw, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::WRITE_LCL_CONFIG): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(writeLclConfig, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-03-30 11:25:03 +02:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_RX_STATUS_REGISTERS): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readRxStatusRegCommand, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_LCL_CONFIG): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readLclConfig, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-03-30 16:29:58 +02:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_STATUS): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readTxStatus, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_WAVEFORM): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readTxWaveform, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readTxAgcValueHighByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(readTxAgcValueLowByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-04-04 14:58:35 +02:00
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE): {
|
|
|
|
prepareCommand(tempPowerAmpBoardHighByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE): {
|
|
|
|
prepareCommand(tempPowerAmpBoardLowByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE): {
|
|
|
|
prepareCommand(tempBasebandBoardHighByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE): {
|
|
|
|
prepareCommand(tempBasebandBoardLowByte, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
2023-01-26 12:21:49 +01:00
|
|
|
case (syrlinks::SET_WAVEFORM_BPSK): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(configBPSK, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
2023-01-26 12:21:49 +01:00
|
|
|
case (syrlinks::SET_WAVEFORM_0QPSK): {
|
2022-04-04 14:58:35 +02:00
|
|
|
prepareCommand(configOQPSK, deviceCommand);
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::ENABLE_DEBUG): {
|
2022-04-26 10:37:25 +02:00
|
|
|
debugMode = true;
|
2022-04-05 08:38:36 +02:00
|
|
|
rawPacketLen = 0;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::DISABLE_DEBUG): {
|
2022-04-26 10:37:25 +02:00
|
|
|
debugMode = false;
|
2022-04-05 08:38:36 +02:00
|
|
|
rawPacketLen = 0;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-04-04 14:58:35 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
default:
|
|
|
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::fillCommandAndReplyMap() {
|
2022-03-31 17:44:29 +02:00
|
|
|
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);
|
2023-01-26 14:00:39 +01:00
|
|
|
this->insertInCommandAndReplyMap(syrlinks::SET_WAVEFORM_BPSK, 1, nullptr, syrlinks::ACK_SIZE,
|
|
|
|
false, true, syrlinks::ACK_REPLY);
|
|
|
|
this->insertInCommandAndReplyMap(syrlinks::SET_WAVEFORM_0QPSK, 1, nullptr, syrlinks::ACK_SIZE,
|
|
|
|
false, true, syrlinks::ACK_REPLY);
|
2022-04-04 14:58:35 +02:00
|
|
|
this->insertInCommandMap(syrlinks::ENABLE_DEBUG);
|
|
|
|
this->insertInCommandMap(syrlinks::DISABLE_DEBUG);
|
2022-03-31 17:44:29 +02:00
|
|
|
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);
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
2023-01-24 19:40:27 +01:00
|
|
|
DeviceCommandId_t* foundId, size_t* foundLen) {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
|
|
|
if (*start != '<') {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::scanForReply: Missing start frame character" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return MISSING_START_FRAME_CHARACTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*(start + 1)) {
|
|
|
|
case ('A'):
|
2022-03-31 17:44:29 +02:00
|
|
|
*foundLen = syrlinks::ACK_SIZE;
|
|
|
|
*foundId = syrlinks::ACK_REPLY;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
|
|
|
case ('E'):
|
2022-03-31 17:44:29 +02:00
|
|
|
*foundLen = syrlinks::RX_STATUS_REGISTERS_REPLY_SIZE;
|
|
|
|
*foundId = syrlinks::READ_RX_STATUS_REGISTERS;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
|
|
|
case ('R'):
|
|
|
|
*foundId = rememberCommandId;
|
2022-03-31 17:44:29 +02:00
|
|
|
*foundLen = syrlinks::READ_ONE_REGISTER_REPLY_SIE;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
|
|
|
default:
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::scanForReply: Unknown reply identifier" << std::endl;
|
2023-02-18 01:18:36 +01:00
|
|
|
result = IGNORE_FULL_PACKET;
|
2022-01-17 15:58:27 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-02-22 09:24:42 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
return result;
|
2021-02-17 15:54:48 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches) {
|
2022-03-30 09:19:30 +02:00
|
|
|
if (powerSwitch == power::NO_SWITCH) {
|
|
|
|
return DeviceHandlerBase::NO_SWITCH;
|
|
|
|
}
|
|
|
|
*numberOfSwitches = 1;
|
|
|
|
*switches = &powerSwitch;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2022-03-30 09:19:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t result;
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (id) {
|
2022-03-31 17:44:29 +02:00
|
|
|
case (syrlinks::ACK_REPLY): {
|
|
|
|
result = verifyReply(packet, syrlinks::ACK_SIZE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Acknowledgment reply has "
|
2022-04-04 14:58:35 +02:00
|
|
|
"invalid crc"
|
|
|
|
<< std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
result = handleAckReply(packet);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-01-17 15:58:27 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_RX_STATUS_REGISTERS): {
|
|
|
|
result = verifyReply(packet, syrlinks::RX_STATUS_REGISTERS_REPLY_SIZE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read rx status registers reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseRxStatusRegistersReply(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_LCL_CONFIG): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read config lcl reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-03-30 16:29:58 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseLclConfigReply(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_TX_STATUS): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx status reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseTxStatusReply(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_TX_WAVEFORM): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx waveform reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseTxWaveformReply(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_HIGH_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC high byte reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseAgcHighByte(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::READ_TX_AGC_VALUE_LOW_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read tx AGC low byte reply "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "has invalid crc" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
parseAgcLowByte(packet);
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_HIGH_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "high byte reply has invalid crc" << std::endl;
|
2022-03-31 09:11:01 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
rawTempBasebandBoard = convertHexStringToUint8(reinterpret_cast<const char*>(
|
2022-03-31 17:44:29 +02:00
|
|
|
packet + syrlinks::MESSAGE_HEADER_SIZE))
|
2022-03-31 09:11:01 +02:00
|
|
|
<< 8;
|
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_BASEBAND_BOARD_LOW_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature baseband board"
|
2022-04-04 14:58:35 +02:00
|
|
|
" low byte reply has invalid crc"
|
|
|
|
<< std::endl;
|
2022-03-31 09:11:01 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
|
|
|
rawTempBasebandBoard |= convertHexStringToUint8(
|
2022-03-31 17:44:29 +02:00
|
|
|
reinterpret_cast<const char*>(packet + syrlinks::MESSAGE_HEADER_SIZE));
|
2022-03-31 09:11:01 +02:00
|
|
|
tempBasebandBoard = calcTempVal(rawTempBasebandBoard);
|
2022-03-31 17:44:29 +02:00
|
|
|
PoolReadGuard rg(&temperatureSet);
|
2022-06-03 18:03:25 +02:00
|
|
|
temperatureSet.temperatureBasebandBoard = tempBasebandBoard;
|
2023-01-23 15:35:43 +01:00
|
|
|
temperatureSet.temperatureBasebandBoard.setValid(true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-04 14:58:35 +02:00
|
|
|
sif::info << "Syrlinks temperature baseband board: " << tempBasebandBoard << " °C"
|
|
|
|
<< std::endl;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
2022-03-31 09:11:01 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_HIGH_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier "
|
2022-04-04 14:58:35 +02:00
|
|
|
<< "board high byte reply has invalid crc" << std::endl;
|
2022-03-31 09:11:01 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
2022-03-31 11:50:33 +02:00
|
|
|
rawTempPowerAmplifier = 0;
|
|
|
|
rawTempPowerAmplifier = convertHexStringToUint8(reinterpret_cast<const char*>(
|
2022-03-31 17:44:29 +02:00
|
|
|
packet + syrlinks::MESSAGE_HEADER_SIZE))
|
|
|
|
<< 8;
|
2022-03-31 09:11:01 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
|
|
|
case (syrlinks::TEMP_POWER_AMPLIFIER_LOW_BYTE): {
|
|
|
|
result = verifyReply(packet, syrlinks::READ_ONE_REGISTER_REPLY_SIE);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::interpretDeviceReply: Read temperature power amplifier"
|
2022-04-04 14:58:35 +02:00
|
|
|
<< " board low byte reply has invalid crc" << std::endl;
|
2022-03-31 09:11:01 +02:00
|
|
|
return CRC_FAILURE;
|
|
|
|
}
|
2022-03-31 11:50:33 +02:00
|
|
|
rawTempPowerAmplifier |= convertHexStringToUint8(
|
2022-03-31 17:44:29 +02:00
|
|
|
reinterpret_cast<const char*>(packet + syrlinks::MESSAGE_HEADER_SIZE));
|
2022-03-31 11:50:33 +02:00
|
|
|
tempPowerAmplifier = calcTempVal(rawTempPowerAmplifier);
|
2022-03-31 17:44:29 +02:00
|
|
|
PoolReadGuard rg(&temperatureSet);
|
|
|
|
temperatureSet.temperaturePowerAmplifier = tempPowerAmplifier;
|
2023-01-23 15:35:43 +01:00
|
|
|
temperatureSet.temperaturePowerAmplifier.setValid(true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-04 14:58:35 +02:00
|
|
|
sif::info << "Syrlinks temperature power amplifier board: " << tempPowerAmplifier << " °C"
|
|
|
|
<< std::endl;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
2022-03-31 09:11:01 +02:00
|
|
|
break;
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
2022-01-17 15:58:27 +01:00
|
|
|
default: {
|
|
|
|
sif::debug << "SyrlinksHkHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
|
|
|
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-02-19 15:41:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
LocalPoolDataSetBase* SyrlinksHandler::getDataSetHandle(sid_t sid) {
|
2022-01-17 15:58:27 +01:00
|
|
|
if (sid == rxDataset.getSid()) {
|
|
|
|
return &rxDataset;
|
|
|
|
} else if (sid == txDataset.getSid()) {
|
|
|
|
return &txDataset;
|
2022-03-31 17:44:29 +02:00
|
|
|
} else if (sid == temperatureSet.getSid()) {
|
|
|
|
return &temperatureSet;
|
2022-01-17 15:58:27 +01:00
|
|
|
} else {
|
2022-03-31 17:44:29 +02:00
|
|
|
sif::warning << "SyrlinksHkHandler::getDataSetHandle: Invalid sid" << std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2021-02-27 11:07:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
std::string SyrlinksHandler::convertUint16ToHexString(uint16_t intValue) {
|
2022-01-17 15:58:27 +01:00
|
|
|
std::stringstream stream;
|
|
|
|
stream << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << intValue;
|
|
|
|
return stream.str();
|
2021-02-19 15:41:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
uint8_t SyrlinksHandler::convertHexStringToUint8(const char* twoChars) {
|
2022-01-17 15:58:27 +01:00
|
|
|
uint32_t value;
|
|
|
|
std::string hexString(twoChars, 2);
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << std::hex << hexString;
|
|
|
|
stream >> value;
|
|
|
|
return static_cast<uint8_t>(value);
|
2021-02-25 15:53:28 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
uint16_t SyrlinksHandler::convertHexStringToUint16(const char* fourChars) {
|
2022-01-17 15:58:27 +01:00
|
|
|
uint16_t value = 0;
|
|
|
|
value = convertHexStringToUint8(fourChars) << 8 | convertHexStringToUint8(fourChars + 2);
|
|
|
|
return value;
|
2021-02-25 18:15:57 +01:00
|
|
|
}
|
2021-02-25 15:53:28 +01:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::parseReplyStatus(const char* status) {
|
2022-01-17 15:58:27 +01:00
|
|
|
switch (*status) {
|
2021-02-19 15:41:50 +01:00
|
|
|
case '0':
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '1':
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Uart framing or parity error"
|
|
|
|
<< std::endl;
|
2022-01-17 15:58:27 +01:00
|
|
|
return UART_FRAMIN_OR_PARITY_ERROR_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '2':
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Bad character detected" << std::endl;
|
|
|
|
return BAD_CHARACTER_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '3':
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Bad parameter value (unexpected value "
|
|
|
|
<< "detected" << std::endl;
|
|
|
|
return BAD_PARAMETER_VALUE_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '4':
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Bad end of frame" << std::endl;
|
|
|
|
return BAD_END_OF_FRAME_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '5':
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Unknown command id or attempt to access"
|
|
|
|
<< " a protected register" << std::endl;
|
|
|
|
return UNKNOWN_COMMAND_ID_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
case '6':
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Bad CRC" << std::endl;
|
|
|
|
return BAD_CRC_ACK;
|
2021-02-19 15:41:50 +01:00
|
|
|
default:
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::debug << "SyrlinksHkHandler::parseReplyStatus: Status reply contains an invalid "
|
|
|
|
<< "status id" << std::endl;
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2021-02-19 15:41:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::verifyReply(const uint8_t* packet, uint8_t size) {
|
2022-01-17 15:58:27 +01:00
|
|
|
int result = 0;
|
|
|
|
/* Calculate crc from received packet */
|
|
|
|
uint16_t crc =
|
2022-03-31 17:44:29 +02:00
|
|
|
CRC::crc16ccitt(packet, size - syrlinks::SIZE_CRC_AND_TERMINATION, CRC_INITIAL_VALUE);
|
2022-01-17 15:58:27 +01:00
|
|
|
std::string recalculatedCrc = convertUint16ToHexString(crc);
|
|
|
|
|
|
|
|
const char* startOfCrc =
|
2022-03-31 17:44:29 +02:00
|
|
|
reinterpret_cast<const char*>(packet + size - syrlinks::SIZE_CRC_AND_TERMINATION);
|
2022-01-17 15:58:27 +01:00
|
|
|
const char* endOfCrc = reinterpret_cast<const char*>(packet + size - 1);
|
|
|
|
|
|
|
|
std::string replyCrc(startOfCrc, endOfCrc);
|
|
|
|
|
|
|
|
result = recalculatedCrc.compare(replyCrc);
|
|
|
|
if (result != 0) {
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::FAILED;
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-02-19 15:41:50 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseRxStatusRegistersReply(const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
PoolReadGuard readHelper(&rxDataset);
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
rxDataset.rxStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
|
|
|
offset += 2;
|
|
|
|
rxDataset.rxSensitivity =
|
2023-01-23 16:18:06 +01:00
|
|
|
convertHexStringTo32bit<uint32_t>(reinterpret_cast<const char*>(packet + offset), 6);
|
2022-01-17 15:58:27 +01:00
|
|
|
offset += 6;
|
|
|
|
rxDataset.rxFrequencyShift =
|
2023-01-23 16:18:06 +01:00
|
|
|
convertHexStringTo32bit<int32_t>(reinterpret_cast<const char*>(packet + offset), 6);
|
2022-01-17 15:58:27 +01:00
|
|
|
offset += 6;
|
|
|
|
rxDataset.rxIqPower = convertHexStringToUint16(reinterpret_cast<const char*>(packet + offset));
|
|
|
|
offset += 4;
|
|
|
|
rxDataset.rxAgcValue = convertHexStringToUint16(reinterpret_cast<const char*>(packet + offset));
|
|
|
|
offset += 4;
|
|
|
|
offset += 2; // reserved register
|
2023-01-23 16:18:06 +01:00
|
|
|
rxDataset.rxDemodEb =
|
|
|
|
convertHexStringTo32bit<uint32_t>(reinterpret_cast<const char*>(packet + offset), 6);
|
2022-01-17 15:58:27 +01:00
|
|
|
offset += 6;
|
2023-01-23 16:18:06 +01:00
|
|
|
rxDataset.rxDemodN0 =
|
|
|
|
convertHexStringTo32bit<uint32_t>(reinterpret_cast<const char*>(packet + offset), 6);
|
2022-01-17 15:58:27 +01:00
|
|
|
offset += 6;
|
|
|
|
rxDataset.rxDataRate = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2021-02-25 18:15:57 +01:00
|
|
|
|
2023-01-23 15:35:43 +01:00
|
|
|
rxDataset.setValidity(true, true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::info << "Syrlinks RX Status: 0x" << std::hex << (unsigned int)rxDataset.rxStatus.value
|
|
|
|
<< std::endl;
|
|
|
|
sif::info << "Syrlinks RX Sensitivity: " << std::dec << rxDataset.rxSensitivity << std::endl;
|
|
|
|
sif::info << "Syrlinks RX Frequency Shift: " << rxDataset.rxFrequencyShift << std::endl;
|
|
|
|
sif::info << "Syrlinks RX IQ Power: " << rxDataset.rxIqPower << std::endl;
|
|
|
|
sif::info << "Syrlinks RX AGC Value: " << rxDataset.rxAgcValue << std::endl;
|
|
|
|
sif::info << "Syrlinks RX Demod Eb: " << rxDataset.rxDemodEb << std::endl;
|
|
|
|
sif::info << "Syrlinks RX Demod N0: " << rxDataset.rxDemodN0 << std::endl;
|
|
|
|
sif::info << "Syrlinks RX Datarate: " << (unsigned int)rxDataset.rxDataRate.value << std::endl;
|
2021-02-25 18:15:57 +01:00
|
|
|
#endif
|
2022-04-26 10:37:25 +02:00
|
|
|
}
|
2021-02-22 09:24:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseLclConfigReply(const uint8_t* packet) {
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-03-30 16:29:58 +02:00
|
|
|
uint8_t lclConfig = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::info << "SyrlinksHkHandler::parseRxStatusRegistersReply: Lcl config: "
|
|
|
|
<< static_cast<unsigned int>(lclConfig) << std::endl;
|
2022-04-05 08:38:36 +02:00
|
|
|
}
|
2022-03-30 16:29:58 +02:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseTxStatusReply(const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
PoolReadGuard readHelper(&txDataset);
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
txDataset.txStatus = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2023-01-23 15:35:43 +01:00
|
|
|
txDataset.txStatus.setValid(true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::info << "Syrlinks TX Status: 0x" << std::hex << (unsigned int)txDataset.txStatus.value
|
|
|
|
<< std::endl;
|
2022-04-05 08:38:36 +02:00
|
|
|
}
|
2021-02-27 11:07:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseTxWaveformReply(const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
PoolReadGuard readHelper(&txDataset);
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
txDataset.txWaveform = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2023-01-23 15:35:43 +01:00
|
|
|
txDataset.txWaveform.setValid(true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::info << "Syrlinks TX Waveform: 0x" << std::hex << (unsigned int)txDataset.txWaveform.value
|
|
|
|
<< std::endl;
|
2022-04-05 08:38:36 +02:00
|
|
|
}
|
2021-02-27 11:07:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseAgcLowByte(const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
PoolReadGuard readHelper(&txDataset);
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
txDataset.txAgcValue = agcValueHighByte << 8 |
|
|
|
|
convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2023-01-23 15:35:43 +01:00
|
|
|
txDataset.txAgcValue.setValid(true);
|
2022-04-26 10:37:25 +02:00
|
|
|
if (debugMode) {
|
2022-04-07 09:57:52 +02:00
|
|
|
sif::info << "Syrlinks TX AGC Value: " << txDataset.txAgcValue << std::endl;
|
2022-04-05 08:38:36 +02:00
|
|
|
}
|
2021-02-22 09:24:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::parseAgcHighByte(const uint8_t* packet) {
|
2022-01-17 15:58:27 +01:00
|
|
|
PoolReadGuard readHelper(&txDataset);
|
2022-03-31 17:44:29 +02:00
|
|
|
uint16_t offset = syrlinks::MESSAGE_HEADER_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
agcValueHighByte = convertHexStringToUint8(reinterpret_cast<const char*>(packet + offset));
|
2021-03-01 12:23:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::setNormalDatapoolEntriesInvalid() {}
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2023-01-27 20:23:55 +01:00
|
|
|
uint32_t SyrlinksHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 2500; }
|
2021-02-17 15:54:48 +01:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
2023-01-24 19:40:27 +01:00
|
|
|
LocalDataPoolManager& poolManager) {
|
2022-03-31 17:44:29 +02:00
|
|
|
localDataPoolMap.emplace(syrlinks::RX_STATUS, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::RX_SENSITIVITY, new PoolEntry<uint32_t>({0}));
|
2023-01-23 15:35:43 +01:00
|
|
|
localDataPoolMap.emplace(syrlinks::RX_FREQUENCY_SHIFT, new PoolEntry<int32_t>({0}));
|
2022-03-31 17:44:29 +02:00
|
|
|
localDataPoolMap.emplace(syrlinks::RX_IQ_POWER, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::RX_AGC_VALUE, new PoolEntry<uint16_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::RX_DEMOD_EB, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::RX_DEMOD_N0, new PoolEntry<uint32_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::RX_DATA_RATE, new PoolEntry<uint8_t>({0}));
|
|
|
|
|
|
|
|
localDataPoolMap.emplace(syrlinks::TX_STATUS, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::TX_WAVEFORM, new PoolEntry<uint8_t>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::TX_AGC_VALUE, new PoolEntry<uint16_t>({0}));
|
2022-06-10 10:39:43 +02:00
|
|
|
localDataPoolMap.emplace(syrlinks::TEMP_BASEBAND_BOARD, new PoolEntry<float>({0}));
|
|
|
|
localDataPoolMap.emplace(syrlinks::TEMP_POWER_AMPLIFIER, new PoolEntry<float>({0}));
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-03-26 15:28:00 +02:00
|
|
|
bool enableHkSets = false;
|
|
|
|
#if OBSW_ENABLE_PERIODIC_HK == 1
|
|
|
|
enableHkSets = true;
|
|
|
|
#endif
|
2022-08-15 11:57:57 +02:00
|
|
|
poolManager.subscribeForDiagPeriodicPacket(
|
2023-03-26 15:28:00 +02:00
|
|
|
subdp::DiagnosticsHkPeriodicParams(txDataset.getSid(), enableHkSets, 60.0));
|
2022-08-15 11:57:57 +02:00
|
|
|
poolManager.subscribeForDiagPeriodicPacket(
|
2023-03-26 15:28:00 +02:00
|
|
|
subdp::DiagnosticsHkPeriodicParams(rxDataset.getSid(), enableHkSets, 60.0));
|
2022-08-15 11:57:57 +02:00
|
|
|
poolManager.subscribeForRegularPeriodicPacket(
|
2023-03-26 15:28:00 +02:00
|
|
|
subdp::RegularHkPeriodicParams(temperatureSet.getSid(), enableHkSets, 20.0));
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-02-22 09:24:42 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::setModeNormal() { setMode(MODE_NORMAL); }
|
2022-03-31 09:11:01 +02:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
float SyrlinksHandler::calcTempVal(uint16_t raw) { return 0.126984 * raw - 67.87; }
|
2022-03-31 17:44:29 +02:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::handleAckReply(const uint8_t* packet) {
|
2022-03-31 17:44:29 +02:00
|
|
|
ReturnValue_t result =
|
|
|
|
parseReplyStatus(reinterpret_cast<const char*>(packet + syrlinks::MESSAGE_HEADER_SIZE));
|
2023-01-24 19:40:27 +01:00
|
|
|
switch (rememberCommandId) {
|
|
|
|
case (syrlinks::WRITE_LCL_CONFIG): {
|
2023-01-26 14:42:13 +01:00
|
|
|
if (isTransitionalMode()) {
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
internalState = InternalState::OFF;
|
|
|
|
} else if (result == returnvalue::OK) {
|
|
|
|
commandExecuted = true;
|
|
|
|
}
|
2023-01-24 19:40:27 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-26 14:00:39 +01:00
|
|
|
case (syrlinks::SET_WAVEFORM_BPSK):
|
|
|
|
case (syrlinks::SET_WAVEFORM_0QPSK):
|
2023-01-26 12:21:49 +01:00
|
|
|
case (syrlinks::SET_TX_MODE_STANDBY):
|
|
|
|
case (syrlinks::SET_TX_MODE_MODULATION):
|
2023-01-24 19:40:27 +01:00
|
|
|
case (syrlinks::SET_TX_MODE_CW): {
|
2023-01-26 12:21:49 +01:00
|
|
|
if (result == returnvalue::OK and isTransitionalMode()) {
|
2023-01-24 19:40:27 +01:00
|
|
|
commandExecuted = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-03-31 12:11:31 +02:00
|
|
|
default: {
|
|
|
|
sif::error << "Syrlinks: Unexpected ACK reply" << std::endl;
|
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
}
|
2023-01-26 16:45:28 +01:00
|
|
|
switch (rememberCommandId) {
|
|
|
|
case (syrlinks::SET_TX_MODE_STANDBY): {
|
|
|
|
triggerEvent(syrlinks::TX_OFF, 0, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case (syrlinks::SET_TX_MODE_MODULATION):
|
|
|
|
case (syrlinks::SET_TX_MODE_CW): {
|
2023-01-27 18:38:36 +01:00
|
|
|
triggerEvent(syrlinks::TX_ON, getSubmode(), static_cast<uint8_t>(com::getCurrentDatarate()));
|
2023-01-26 16:45:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-03-31 17:44:29 +02:00
|
|
|
return result;
|
|
|
|
}
|
2022-04-04 14:58:35 +02:00
|
|
|
|
2023-01-25 17:02:46 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) {
|
|
|
|
if (mode == HasModesIF::MODE_ON or mode == DeviceHandlerIF::MODE_NORMAL) {
|
2023-01-27 14:44:40 +01:00
|
|
|
if (submode >= com::Submode::NUM_SUBMODES) {
|
2023-01-25 17:02:46 +01:00
|
|
|
return HasModesIF::INVALID_SUBMODE;
|
|
|
|
}
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
|
|
|
return DeviceHandlerBase::isModeCombinationValid(mode, submode);
|
|
|
|
}
|
|
|
|
|
2023-01-26 14:39:23 +01:00
|
|
|
ReturnValue_t SyrlinksHandler::getParameter(uint8_t domainId, uint8_t uniqueId,
|
2023-01-26 14:42:13 +01:00
|
|
|
ParameterWrapper* parameterWrapper,
|
|
|
|
const ParameterWrapper* newValues,
|
|
|
|
uint16_t startAtIndex) {
|
|
|
|
return DeviceHandlerBase::getParameter(domainId, uniqueId, parameterWrapper, newValues,
|
|
|
|
startAtIndex);
|
2023-01-26 14:39:23 +01:00
|
|
|
}
|
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::prepareCommand(std::string command, DeviceCommandId_t commandId) {
|
2022-04-05 08:38:36 +02:00
|
|
|
command.copy(reinterpret_cast<char*>(commandBuffer), command.size(), 0);
|
2022-04-04 14:58:35 +02:00
|
|
|
rawPacketLen = command.size();
|
|
|
|
rememberCommandId = commandId;
|
|
|
|
rawPacket = commandBuffer;
|
|
|
|
}
|
2022-04-26 10:37:25 +02:00
|
|
|
|
2023-01-24 19:11:17 +01:00
|
|
|
void SyrlinksHandler::setDebugMode(bool enable) { this->debugMode = enable; }
|
2023-01-24 19:40:27 +01:00
|
|
|
|
|
|
|
void SyrlinksHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) {
|
|
|
|
Mode_t tgtMode = getBaseMode(getMode());
|
2023-01-25 17:02:46 +01:00
|
|
|
auto commandDone = [&]() {
|
|
|
|
setMode(tgtMode);
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-25 17:02:46 +01:00
|
|
|
internalState = InternalState::IDLE;
|
|
|
|
};
|
2023-01-26 14:00:39 +01:00
|
|
|
auto txOnHandler = [&](InternalState selMod) {
|
|
|
|
if (internalState == InternalState::IDLE) {
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-26 14:00:39 +01:00
|
|
|
commandExecuted = false;
|
|
|
|
internalState = selMod;
|
|
|
|
}
|
|
|
|
// Select modulation first (BPSK or 0QPSK).
|
|
|
|
if (internalState == selMod) {
|
|
|
|
if (commandExecuted) {
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-26 14:00:39 +01:00
|
|
|
internalState = InternalState::SET_TX_MODULATION;
|
|
|
|
commandExecuted = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now go into modulation mode.
|
|
|
|
if (internalState == InternalState::SET_TX_MODULATION) {
|
|
|
|
if (commandExecuted) {
|
|
|
|
commandDone();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2023-01-26 14:52:58 +01:00
|
|
|
auto txStandbyHandler = [&]() {
|
|
|
|
if (internalState == InternalState::IDLE) {
|
2023-03-31 12:11:31 +02:00
|
|
|
transitionCommandPending = false;
|
2023-01-26 14:52:58 +01:00
|
|
|
internalState = InternalState::SET_TX_STANDBY;
|
|
|
|
commandExecuted = false;
|
|
|
|
}
|
|
|
|
if (internalState == InternalState::SET_TX_STANDBY) {
|
|
|
|
if (commandExecuted) {
|
|
|
|
commandDone();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-01-24 19:40:27 +01:00
|
|
|
if (tgtMode == HasModesIF::MODE_ON or tgtMode == DeviceHandlerIF::MODE_NORMAL) {
|
|
|
|
switch (getSubmode()) {
|
2023-01-27 14:44:40 +01:00
|
|
|
case (com::Submode::RX_AND_TX_DEFAULT_DATARATE): {
|
2023-01-27 18:38:36 +01:00
|
|
|
auto currentDatarate = com::getCurrentDatarate();
|
|
|
|
if (currentDatarate == com::Datarate::LOW_RATE_MODULATION_BPSK) {
|
2023-01-26 14:00:39 +01:00
|
|
|
if (txOnHandler(InternalState::SELECT_MODULATION_BPSK)) {
|
|
|
|
return;
|
2023-01-25 17:02:46 +01:00
|
|
|
}
|
2023-01-27 18:38:36 +01:00
|
|
|
} else if (currentDatarate == com::Datarate::HIGH_RATE_MODULATION_0QPSK) {
|
2023-01-26 14:00:39 +01:00
|
|
|
if (txOnHandler(InternalState::SELECT_MODULATION_0QPSK)) {
|
2023-01-25 17:02:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-27 14:44:40 +01:00
|
|
|
case (com::Submode::RX_AND_TX_LOW_DATARATE): {
|
2023-01-26 14:00:39 +01:00
|
|
|
if (txOnHandler(InternalState::SELECT_MODULATION_BPSK)) {
|
|
|
|
return;
|
2023-01-25 17:02:46 +01:00
|
|
|
}
|
2023-01-26 14:00:39 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-27 14:44:40 +01:00
|
|
|
case (com::Submode::RX_AND_TX_HIGH_DATARATE): {
|
2023-01-26 14:00:39 +01:00
|
|
|
if (txOnHandler(InternalState::SELECT_MODULATION_0QPSK)) {
|
|
|
|
return;
|
2023-01-24 19:40:27 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-01-27 14:44:40 +01:00
|
|
|
case (com::Submode::RX_ONLY): {
|
2023-01-26 14:52:58 +01:00
|
|
|
txStandbyHandler();
|
|
|
|
return;
|
2023-01-24 19:40:27 +01:00
|
|
|
}
|
2023-01-27 14:44:40 +01:00
|
|
|
case (com::Submode::RX_AND_TX_CW): {
|
2023-01-25 17:02:46 +01:00
|
|
|
if (internalState == InternalState::IDLE) {
|
|
|
|
internalState = InternalState::SET_TX_STANDBY;
|
|
|
|
commandExecuted = false;
|
|
|
|
}
|
2023-01-24 19:40:27 +01:00
|
|
|
if (commandExecuted) {
|
2023-01-25 17:02:46 +01:00
|
|
|
commandDone();
|
2023-01-24 19:40:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2023-01-25 17:02:46 +01:00
|
|
|
commandDone();
|
2023-01-24 19:40:27 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-26 16:16:23 +01:00
|
|
|
} else if (tgtMode == HasModesIF::MODE_OFF) {
|
|
|
|
txStandbyHandler();
|
2023-01-24 19:40:27 +01:00
|
|
|
}
|
|
|
|
}
|