eive-obsw/mission/devices/SyrlinksHkHandler.cpp

148 lines
4.1 KiB
C++
Raw Normal View History

2021-02-17 15:54:48 +01:00
#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), dataset(
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) {
2021-02-18 16:16:38 +01:00
*id = READ_RX_STATUS_REGISTERS;
return buildCommandFromCommand(*id, NULL, 0);
2021-02-17 15:54:48 +01:00
}
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) {
2021-02-18 16:16:38 +01:00
case(RESET_UNIT): {
resetCommand.copy(rawPacket, resetCommand.size(), 0);
rawPacketLen = resetCommand.size();
return RETURN_OK;
}
case(SET_TX_MODE_STANDBY): {
setTxModeStandby.copy(rawPacket, setTxModeStandby.size(), 0);
rawPacketLen = setTxModeStandby.size();
return RETURN_OK;
}
case(SET_TX_MODE_MODULATION): {
setTxModeModulation.copy(rawPacket, setTxModeModulation.size(), 0);
rawPacketLen = setTxModeModulation.size();
return RETURN_OK;
}
case(SET_TX_MODE_CW): {
setTxModeCw.copy(rawPacket, setTxModeCw.size(), 0);
rawPacketLen = setTxModeCw.size();
2021-02-17 15:54:48 +01:00
return RETURN_OK;
}
2021-02-18 16:16:38 +01:00
case(READ_RX_STATUS_REGISTERS): {
readRxStatusRegCommand.copy(rawPacket, readRxStatusRegCommand.size(), 0);
rawPacketLen = readRxStatusRegCommand.size();
2021-02-17 15:54:48 +01:00
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void SyrlinksHkHandler::fillCommandAndReplyMap(){
2021-02-18 16:16:38 +01:00
this->insertInCommandAndReplyMap(RESET_UNIT);
this->insertInCommandAndReplyMap(SET_TX_MODE_STANDBY);
this->insertInCommandAndReplyMap(SET_TX_MODE_MODULATION);
this->insertInCommandAndReplyMap(SET_TX_MODE_CW);
this->insertInCommandAndReplyMap(READ_RX_STATUS_REGISTERS, 1, &rxStatusRegiserSet,
2021-02-17 15:54:48 +01:00
TMP1075::GET_TEMP_REPLY_SIZE);
}
ReturnValue_t SyrlinksHkHandler::scanForReply(const uint8_t *start,
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
switch(rememberCommandId) {
case(TMP1075::GET_TEMP):
*foundId = TMP1075::GET_TEMP;
*foundLen = TMP1075::GET_TEMP_REPLY_SIZE;
rememberCommandId = TMP1075::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 TMP1075::GET_TEMP: {
int16_t tempValueRaw = 0;
tempValueRaw = packet[0] << 4 | packet[1] >> 4;
float tempValue = ((static_cast<float>(tempValueRaw)) * 0.0625);
#if OBSW_VERBOSE_LEVEL >= 1
sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId()
<< ": Temperature: " << tempValue<< " °C"
<< std::endl;
#endif
ReturnValue_t result = dataset.read();
if(result == HasReturnvaluesIF::RETURN_OK) {
dataset.temperatureCelcius = tempValue;
dataset.commit();
}
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void SyrlinksHkHandler::setNormalDatapoolEntriesInvalid(){
}
void SyrlinksHkHandler::prepareAdcConversionCommand(){
cmdBuffer[0] = TMP1075::CFGR_ADDR;
cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8;
cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF;
}
void SyrlinksHkHandler::prepareGetTempCommand(){
cmdBuffer[0] = TMP1075::TEMP_REG_ADDR;
}
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;
}