rad sensor working

This commit is contained in:
Jakob Meier 2021-05-03 13:35:16 +02:00
parent 8d2993f88d
commit 80b32331c9
2 changed files with 81 additions and 50 deletions

View File

@ -31,7 +31,24 @@ void RadiationSensorHandler::doShutDown(){
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
*id = RAD_SENSOR::PERFORM_CONVERSION;
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);
}
@ -57,9 +74,16 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
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;
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;
@ -77,7 +101,8 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
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);
}
@ -91,7 +116,7 @@ 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: {
case RAD_SENSOR::READ_CONVERSIONS: {
PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3));

View File

@ -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;