rad sensor working
This commit is contained in:
parent
f708a67fa8
commit
3c6ec68faa
@ -3,12 +3,12 @@
|
||||
#include <OBSWConfig.h>
|
||||
|
||||
RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF,
|
||||
CookieIF * comCookie) :
|
||||
DeviceHandlerBase(objectId, comIF, comCookie), dataset(
|
||||
this) {
|
||||
if (comCookie == NULL) {
|
||||
sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
CookieIF * comCookie) :
|
||||
DeviceHandlerBase(objectId, comIF, comCookie), dataset(
|
||||
this) {
|
||||
if (comCookie == NULL) {
|
||||
sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
RadiationSensorHandler::~RadiationSensorHandler() {
|
||||
@ -30,54 +30,79 @@ void RadiationSensorHandler::doShutDown(){
|
||||
}
|
||||
|
||||
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(
|
||||
DeviceCommandId_t * id) {
|
||||
*id = RAD_SENSOR::PERFORM_CONVERSION;
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
DeviceCommandId_t * id) {
|
||||
|
||||
switch (communicationStep) {
|
||||
case CommunicationStep::START_CONVERSION: {
|
||||
*id = RAD_SENSOR::START_CONVERSION;
|
||||
communicationStep = CommunicationStep::READ_CONVERSIONS;
|
||||
break;
|
||||
}
|
||||
case CommunicationStep::READ_CONVERSIONS: {
|
||||
*id = RAD_SENSOR::READ_CONVERSIONS;
|
||||
communicationStep = CommunicationStep::START_CONVERSION;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication "
|
||||
<< "step" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand(
|
||||
DeviceCommandId_t * id){
|
||||
DeviceCommandId_t * id){
|
||||
if (internalState == InternalState::SETUP) {
|
||||
*id = RAD_SENSOR::WRITE_SETUP;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
return buildCommandFromCommand(*id, nullptr, 0);
|
||||
}
|
||||
|
||||
ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
|
||||
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(RAD_SENSOR::WRITE_SETUP): {
|
||||
cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
internalState = InternalState::CONFIGURED;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(RAD_SENSOR::PERFORM_CONVERSION): {
|
||||
/* Dummy bytes are written to remove old values from fifo */
|
||||
cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION;
|
||||
cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE;
|
||||
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
||||
size_t commandDataLen) {
|
||||
switch(deviceCommand) {
|
||||
case(RAD_SENSOR::WRITE_SETUP): {
|
||||
cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 1;
|
||||
internalState = InternalState::CONFIGURED;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(RAD_SENSOR::START_CONVERSION): {
|
||||
/* First the fifo will be reset here */
|
||||
cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION;
|
||||
cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = 2;
|
||||
return RETURN_OK;
|
||||
}
|
||||
case(RAD_SENSOR::READ_CONVERSIONS): {
|
||||
cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE;
|
||||
cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE;
|
||||
cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE;
|
||||
cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE;
|
||||
cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE;
|
||||
cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = RAD_SENSOR::READ_SIZE;
|
||||
return RETURN_OK;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
rawPacket = cmdBuffer;
|
||||
rawPacketLen = RAD_SENSOR::READ_SIZE;
|
||||
return RETURN_OK;
|
||||
}
|
||||
default:
|
||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
void RadiationSensorHandler::fillCommandAndReplyMap() {
|
||||
this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP);
|
||||
this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset,
|
||||
this->insertInCommandMap(RAD_SENSOR::START_CONVERSION);
|
||||
this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset,
|
||||
RAD_SENSOR::READ_SIZE);
|
||||
}
|
||||
|
||||
@ -90,12 +115,12 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start,
|
||||
|
||||
ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
const uint8_t *packet) {
|
||||
switch (id) {
|
||||
case RAD_SENSOR::PERFORM_CONVERSION: {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
|
||||
dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3));
|
||||
dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5));
|
||||
switch (id) {
|
||||
case RAD_SENSOR::READ_CONVERSIONS: {
|
||||
PoolReadGuard readSet(&dataset);
|
||||
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
|
||||
dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3));
|
||||
dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5));
|
||||
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_RAD_SENSOR
|
||||
sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C"
|
||||
<< std::endl;
|
||||
@ -104,15 +129,15 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||
sif::info << "Radiation sensor temperature ADC value channel 1: " << dataset.channel1
|
||||
<< std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl;
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl;
|
||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||
}
|
||||
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){
|
||||
@ -120,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){
|
||||
}
|
||||
|
||||
uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
|
||||
return 5000;
|
||||
return 5000;
|
||||
}
|
||||
|
||||
ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
|
@ -10,8 +10,9 @@ namespace RAD_SENSOR {
|
||||
* temperature sensor.
|
||||
*/
|
||||
static const DeviceCommandId_t WRITE_SETUP = 0x1;
|
||||
static const DeviceCommandId_t PERFORM_CONVERSION = 0x2;
|
||||
static const DeviceCommandId_t START_CONVERSION = 0x2;
|
||||
static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
|
||||
|
||||
/**
|
||||
* @brief This is the configuration byte which will be written to the setup register after
|
||||
* power on.
|
||||
@ -34,6 +35,11 @@ namespace RAD_SENSOR {
|
||||
*/
|
||||
static const uint8_t CONVERSION_DEFINITION = 0b10001001;
|
||||
|
||||
/**
|
||||
* @brief Writing this value resets the fifo of the MAX1227.
|
||||
*/
|
||||
static const uint8_t RESET_DEFINITION = 0b00011000;
|
||||
|
||||
static const uint8_t DUMMY_BYTE = 0xFF;
|
||||
|
||||
static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS;
|
||||
|
Loading…
Reference in New Issue
Block a user