#include "Max31865EiveHandler.h" Max31865EiveHandler::Max31865EiveHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie) : DeviceHandlerBase(objectId, comIF, comCookie, nullptr), sensorDataset(this, EiveMax31855::RtdCommands::EXCHANGE_SET_ID) {} void Max31865EiveHandler::doStartUp() { if (state == InternalState::NONE or state == InternalState::INACTIVE) { if (instantNormal) { state = InternalState::ACTIVE; } else { state = InternalState::ON; } transitionOk = false; } if ((state == InternalState::ON or state == InternalState::ACTIVE) and transitionOk) { if (instantNormal) { setMode(_MODE_TO_NORMAL); } else { setMode(MODE_ON); } } } void Max31865EiveHandler::doShutDown() { if (state == InternalState::NONE or state == InternalState::ACTIVE or state == InternalState::ON) { state = InternalState::INACTIVE; transitionOk = false; } else { transitionOk = true; } if (state == InternalState::INACTIVE and transitionOk) { setMode(_MODE_POWER_DOWN); } } ReturnValue_t Max31865EiveHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { *id = EiveMax31855::RtdCommands::EXCHANGE_SET_ID; return RETURN_OK; } ReturnValue_t Max31865EiveHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { if (state == InternalState::ON) { *id = EiveMax31855::RtdCommands::ON; buildCommandFromCommand(*id, nullptr, 0); } if (state == InternalState::ACTIVE) { *id = EiveMax31855::RtdCommands::ACTIVE; buildCommandFromCommand(*id, nullptr, 0); } if (state == InternalState::INACTIVE) { *id = EiveMax31855::RtdCommands::OFF; buildCommandFromCommand(*id, nullptr, 0); } return NOTHING_TO_SEND; } ReturnValue_t Max31865EiveHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData, size_t commandDataLen) { auto cmdTyped = static_cast(deviceCommand); switch (cmdTyped) { case (EiveMax31855::RtdCommands::ON): case (EiveMax31855::RtdCommands::ACTIVE): case (EiveMax31855::RtdCommands::OFF): { simpleCommand(cmdTyped); break; } case (EiveMax31855::RtdCommands::LOW_THRESHOLD): case (EiveMax31855::RtdCommands::HIGH_TRESHOLD): { break; } case (EiveMax31855::RtdCommands::CFG): { break; } default: return NOTHING_TO_SEND; } return RETURN_OK; } void Max31865EiveHandler::simpleCommand(EiveMax31855::RtdCommands cmd) { cmdBuf[0] = cmd; rawPacket = cmdBuf.data(); rawPacketLen = 1; } void Max31865EiveHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (mode == _MODE_TO_NORMAL) { state = InternalState::ACTIVE; transitionOk = false; if (transitionOk) { setMode(MODE_NORMAL); } } else { DeviceHandlerBase::doTransition(modeFrom, subModeFrom); } } void Max31865EiveHandler::fillCommandAndReplyMap() { insertInReplyMap(EiveMax31855::RtdCommands::EXCHANGE_SET_ID, 2, &sensorDataset); } ReturnValue_t Max31865EiveHandler::scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId, size_t* foundLen) { if (remainingSize != exchangeStruct.getSerializedSize()) { sif::error << "Invalid reply from RTD reader detected, reply size " << remainingSize << "not equal to exchange struct size" << exchangeStruct.getSerializedSize() << std::endl; return RETURN_FAILED; } *foundId = EiveMax31855::RtdCommands::EXCHANGE_SET_ID; *foundLen = remainingSize; return RETURN_OK; } ReturnValue_t Max31865EiveHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) { return RETURN_OK; } uint32_t Max31865EiveHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 2000; } ReturnValue_t Max31865EiveHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { localDataPoolMap.emplace(MAX31865::PoolIds::RTD_VALUE, new PoolEntry({0})); localDataPoolMap.emplace(MAX31865::PoolIds::TEMPERATURE_C, new PoolEntry({0})); localDataPoolMap.emplace(MAX31865::PoolIds::FAULT_BYTE, new PoolEntry({0})); poolManager.subscribeForPeriodicPacket(sensorDataset.getSid(), false, 30.0, false); return RETURN_OK; }