eive-obsw/mission/devices/SyrlinksHkHandler.cpp
2021-02-19 11:02:27 +01:00

149 lines
4.6 KiB
C++

#include <mission/devices/SyrlinksHkHandler.h>
#include <fsfwconfig/OBSWConfig.h>
SyrlinksHkHandler::SyrlinksHkHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) :
DeviceHandlerBase(objectId, comIF, comCookie), rxStatusRegistersSet(this) {
if (comCookie == NULL) {
sif::error << "SyrlinksHkHandler: Invalid com cookie" << std::endl;
}
}
SyrlinksHkHandler::~SyrlinksHkHandler() {
}
void SyrlinksHkHandler::doStartUp(){
if(mode == _MODE_START_UP){
setMode(MODE_ON);
}
}
void SyrlinksHkHandler::doShutDown(){
}
ReturnValue_t SyrlinksHkHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
*id = READ_RX_STATUS_REGISTERS;
return buildCommandFromCommand(*id, NULL, 0);
}
ReturnValue_t SyrlinksHkHandler::buildTransitionDeviceCommand(
DeviceCommandId_t * id){
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SyrlinksHkHandler::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(SYRLINKS::RESET_UNIT): {
resetCommand.copy(rawPacket, resetCommand.size(), 0);
rawPacketLen = resetCommand.size();
rememberCommandId = SYRLINKS::RESET_UNIT;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_STANDBY): {
setTxModeStandby.copy(rawPacket, setTxModeStandby.size(), 0);
rawPacketLen = setTxModeStandby.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_STANDBY;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_MODULATION): {
setTxModeModulation.copy(rawPacket, setTxModeModulation.size(), 0);
rawPacketLen = setTxModeModulation.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_MODULATION;
return RETURN_OK;
}
case(SYRLINKS::SET_TX_MODE_CW): {
setTxModeCw.copy(rawPacket, setTxModeCw.size(), 0);
rawPacketLen = setTxModeCw.size();
rememberCommandId = SYRLINKS::SET_TX_MODE_CW;
return RETURN_OK;
}
case(SYRLINKS::READ_RX_STATUS_REGISTERS): {
readRxStatusRegCommand.copy(rawPacket, readRxStatusRegCommand.size(), 0);
rawPacketLen = readRxStatusRegCommand.size();
rememberCommandId = SYRLINKS::READ_RX_STATUS_REGISTERS;
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void SyrlinksHkHandler::fillCommandAndReplyMap() {
this->insertInCommandAndReplyMap(SYRLINKS::RESET_UNIT);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_STANDBY);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_MODULATION);
this->insertInCommandAndReplyMap(SYRLINKS::SET_TX_MODE_CW);
this->insertInCommandAndReplyMap(SYRLINKS::READ_RX_STATUS_REGISTERS, 1, &rxStatusRegistersSet,
SYRLINKS::RX_STATUS_REGISTERS_REPLY_SIZE);
}
ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t *start,
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
switch(rememberCommandId) {
case(SYRLINKS::RESET_UNIT):
*foundId = SYRLINKS::RESET_UNIT;
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::SET_TX_MODE_STANDBY):
*foundId = SYRLINKS::SET_TX_MODE_STANDBY;
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::SET_TX_MODE_MODULATION):
*foundId = SYRLINKS::SET_TX_MODE_MODULATION;
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::SET_TX_MODE_CW):
*foundId = SYRLINKS::SET_TX_MODE_CW;
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
break;
case(SYRLINKS::READ_RX_STATUS_REGISTERS):
*foundId = SYRLINKS::READ_RX_STATUS_REGISTERS;
*foundLen = SYRLINKS::REQUEST_STATUS_REPLY_SIZE;
rememberCommandId = SYRLINKS::NONE;
break;
default:
return IGNORE_REPLY_DATA;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t SyrlinksHkHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch (id) {
case (SYRLINKS::RESET_UNIT): {
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void SyrlinksHkHandler::setNormalDatapoolEntriesInvalid(){
}
uint32_t SyrlinksHkHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
return 500;
}
ReturnValue_t SyrlinksHkHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry<float>( { 0.0 }));
return HasReturnvaluesIF::RETURN_OK;
}