meier/master #33

Merged
muellerr merged 24 commits from meier/master into develop 2021-05-17 14:59:47 +02:00
2 changed files with 81 additions and 50 deletions
Showing only changes of commit 3c6ec68faa - Show all commits

View File

@ -31,7 +31,24 @@ void RadiationSensorHandler::doShutDown(){
ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand(
DeviceCommandId_t * id) { 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); return buildCommandFromCommand(*id, nullptr, 0);
} }
@ -57,9 +74,16 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
internalState = InternalState::CONFIGURED; internalState = InternalState::CONFIGURED;
return RETURN_OK; return RETURN_OK;
} }
case(RAD_SENSOR::PERFORM_CONVERSION): { case(RAD_SENSOR::START_CONVERSION): {
/* Dummy bytes are written to remove old values from fifo */ /* First the fifo will be reset here */
cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; 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[1] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE;
cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE;
@ -77,7 +101,8 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand(
void RadiationSensorHandler::fillCommandAndReplyMap() { void RadiationSensorHandler::fillCommandAndReplyMap() {
this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); 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); RAD_SENSOR::READ_SIZE);
} }
@ -91,7 +116,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start,
ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) { const uint8_t *packet) {
switch (id) { switch (id) {
case RAD_SENSOR::PERFORM_CONVERSION: { case RAD_SENSOR::READ_CONVERSIONS: {
PoolReadGuard readSet(&dataset); PoolReadGuard readSet(&dataset);
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3));

View File

@ -10,8 +10,9 @@ namespace RAD_SENSOR {
* temperature sensor. * temperature sensor.
*/ */
static const DeviceCommandId_t WRITE_SETUP = 0x1; 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; static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
/** /**
* @brief This is the configuration byte which will be written to the setup register after * @brief This is the configuration byte which will be written to the setup register after
* power on. * power on.
@ -34,6 +35,11 @@ namespace RAD_SENSOR {
*/ */
static const uint8_t CONVERSION_DEFINITION = 0b10001001; 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 DUMMY_BYTE = 0xFF;
static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS;