meier/master #33
@ -33,7 +33,9 @@ ReturnValue_t IMTQHandler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t * id) {
|
||||
switch (communicationStep) {
|
||||
case CommunicationStep::SELF_TEST:
|
||||
*id = IMTQ::SELF_TEST;
|
||||
// *id = IMTQ::SELF_TEST;
|
||||
//TODO: Implementing self test command. On-hold because of issue with humidity in clean
|
||||
// room
|
||||
communicationStep = CommunicationStep::GET_ENG_HK_DATA;
|
||||
break;
|
||||
case CommunicationStep::GET_ENG_HK_DATA:
|
||||
|
145
mission/devices/Max1227Handler.cpp
Normal file
145
mission/devices/Max1227Handler.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <mission/devices/Max1227Handler.h>
|
||||
#include <mission/devices/devicedefinitions/Tmp1075Definitions.h>
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
Max1227Handler::Max1227Handler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * comCookie) :
|
||||
DeviceHandlerBase(objectId, comIF, comCookie), dataset(
|
||||
this) {
|
||||
if (comCookie == NULL) {
|
||||
sif::error << "Max1227Handler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Max1227Handler::~Max1227Handler() {
|
||||
}
|
||||
|
||||
|
||||
void Max1227Handler::doStartUp(){
|
||||
if(mode == _MODE_START_UP){
|
||||
setMode(MODE_ON);
|
||||
}
|
||||
}
|
||||
|
||||
void Max1227Handler::doShutDown(){
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t Max1227Handler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t * id) {
|
||||
|
||||
if(communicationStep == CommunicationStep::START_ADC_CONVERSION) {
|
||||
*id = TMP1075::START_ADC_CONVERSION;
|
||||
communicationStep = CommunicationStep::GET_TEMPERATURE;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
else {
|
||||
*id = TMP1075::GET_TEMP;
|
||||
communicationStep = CommunicationStep::START_ADC_CONVERSION;
|
||||
return buildCommandFromCommand(*id, NULL, 0);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Max1227Handler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t * id){
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Max1227Handler::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(TMP1075::START_ADC_CONVERSION): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
prepareAdcConversionCommand();
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = TMP1075::CFGR_CMD_SIZE;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(TMP1075::GET_TEMP): {
|
||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||
prepareGetTempCommand();
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = TMP1075::POINTER_REG_SIZE;
|
||||
rememberCommandId = TMP1075::GET_TEMP;
|
||||
return RETURN_OK;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
void Max1227Handler::fillCommandAndReplyMap(){
|
||||
this->insertInCommandMap(TMP1075::START_ADC_CONVERSION);
|
||||
this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset,
|
||||
TMP1075::GET_TEMP_REPLY_SIZE);
|
||||
}
|
||||
|
||||
ReturnValue_t Max1227Handler::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 Max1227Handler::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 Max1227Handler::setNormalDatapoolEntriesInvalid(){
|
||||
|
||||
}
|
||||
|
||||
void Max1227Handler::prepareAdcConversionCommand(){
|
||||
cmdBuffer[0] = TMP1075::CFGR_ADDR;
|
||||
cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8;
|
||||
cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF;
|
||||
}
|
||||
|
||||
void Max1227Handler::prepareGetTempCommand(){
|
||||
cmdBuffer[0] = TMP1075::TEMP_REG_ADDR;
|
||||
}
|
||||
|
||||
uint32_t Max1227Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
|
||||
return 500;
|
||||
}
|
||||
|
||||
ReturnValue_t Max1227Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) {
|
||||
localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry<float>( { 0.0 }));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
64
mission/devices/Max1227Handler.h
Normal file
64
mission/devices/Max1227Handler.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef MISSION_DEVICES_MAX1227HANDLER_H_
|
||||
#define MISSION_DEVICES_MAX1227HANDLER_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
|
||||
#include <mission/devices/devicedefinitions/Tmp1075Definitions.h>
|
||||
|
||||
/**
|
||||
* @brief This is the device handler class for the MAX1227 ADC converter.
|
||||
*
|
||||
* @details Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class Max1227Handler: public DeviceHandlerBase {
|
||||
public:
|
||||
|
||||
Max1227Handler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * comCookie);
|
||||
virtual ~Max1227Handler();
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t * commandData,size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize,
|
||||
DeviceCommandId_t *foundId, size_t *foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) override;
|
||||
void setNormalDatapoolEntriesInvalid() override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Function fills cmdBuffer with command to start the adc
|
||||
* conversion for a new temperature value.
|
||||
*/
|
||||
void prepareAdcConversionCommand();
|
||||
|
||||
void prepareGetTempCommand();
|
||||
|
||||
enum class CommunicationStep {
|
||||
START_ADC_CONVERSION,
|
||||
GET_TEMPERATURE
|
||||
};
|
||||
|
||||
TMP1075::Tmp1075Dataset dataset;
|
||||
|
||||
static const uint8_t MAX_CMD_LEN = 3;
|
||||
|
||||
uint8_t rememberRequestedSize = 0;
|
||||
uint8_t rememberCommandId = TMP1075::NONE;
|
||||
uint8_t cmdBuffer[MAX_CMD_LEN];
|
||||
CommunicationStep communicationStep =
|
||||
CommunicationStep::START_ADC_CONVERSION;
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_MAX1227HANDLER_H_ */
|
47
mission/devices/devicedefinitions/Max1227Definitions.h
Normal file
47
mission/devices/devicedefinitions/Max1227Definitions.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_
|
||||
|
||||
namespace MAX1227 {
|
||||
static const uint8_t TEMP_REG_ADDR = 0x0;
|
||||
static const uint8_t CFGR_ADDR = 0x1;
|
||||
|
||||
/* Writing this information to the configuration register sets the tmp1075
|
||||
* to shutdown mode and starts a single temperature conversion */
|
||||
static const uint16_t ONE_SHOT_MODE = 0x8100;
|
||||
|
||||
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
|
||||
static const DeviceCommandId_t GET_TEMP = 0x1;
|
||||
static const DeviceCommandId_t START_ADC_CONVERSION = 0x2;
|
||||
|
||||
static const uint8_t GET_TEMP_REPLY_SIZE = 2;
|
||||
static const uint8_t CFGR_CMD_SIZE = 3;
|
||||
static const uint8_t POINTER_REG_SIZE = 1;
|
||||
|
||||
static const uint32_t TMP1075_DATA_SET_ID = GET_TEMP;
|
||||
|
||||
static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE;
|
||||
|
||||
enum Tmp1075PoolIds: lp_id_t {
|
||||
TEMPERATURE_C_TMP1075_1,
|
||||
TEMPERATURE_C_TMP1075_2
|
||||
};
|
||||
|
||||
class Tmp1075Dataset:
|
||||
public StaticLocalDataSet<sizeof(float)> {
|
||||
public:
|
||||
|
||||
Tmp1075Dataset(HasLocalDataPoolIF* owner):
|
||||
StaticLocalDataSet(owner, TMP1075_DATA_SET_ID) {
|
||||
}
|
||||
|
||||
Tmp1075Dataset(object_id_t objectId):
|
||||
StaticLocalDataSet(sid_t(objectId, TMP1075_DATA_SET_ID)) {
|
||||
}
|
||||
|
||||
lp_var_t<float> temperatureCelcius = lp_var_t<float>(sid.objectId,
|
||||
TEMPERATURE_C_TMP1075_1, this);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ */
|
2
tmtc
2
tmtc
@ -1 +1 @@
|
||||
Subproject commit e23bc116088fc673aaec45768c7a07c20d75a2f6
|
||||
Subproject commit 06750809cb52044392e0683896538a652f11a512
|
Loading…
Reference in New Issue
Block a user