atMETEO
An ATmega based weather station
Files | Classes | Enumerations

Sensors::Sensor is the base class for sensor specific data decoding. More...

Collaboration diagram for Sensor:

Files

file  sensor.h
 Sensors::Sensor is the base class for sensor specific data decoding.
 

Classes

class  Sensors::Sensor< TSensor >
 Base class for sensor implementations. More...
 

Enumerations

enum  Sensors::SensorStatus : uint8_t { Sensors::SensorStatus::Complete = 0, Sensors::SensorStatus::Incomplete, Sensors::SensorStatus::TooMuchData, Sensors::SensorStatus::InvalidData }
 Sensor status returned from Sensor::setData() and Sensor::addByte(). More...
 

Detailed Description

Sensors::Sensor is the base class for sensor specific data decoding.


Class Documentation

◆ Sensors::Sensor

class Sensors::Sensor

template<typename TSensor>
class Sensors::Sensor< TSensor >

Base class for sensor implementations.

Usage:

using namespace Sensors;
MySensor mySensor;
Sensor &sensor = mySensor;
while (...) {
switch (sensor.addByte(byte)) {
break;
handle_complete_sensor_data(mySensor.getData());
break;
default:
sensor.reset();
break;
}
}

Accessing sensor data is specific to the sensor therefore there is no generic API defined.

The Sensor API has to be implemented by specific sensor decoders:

class MySensor : public Sensor<MySensor> {
friend class Sensor<MySensor>;
// ...
SensorStatus internalSetData(uint8_t *data, size_t length);
SensorStatus internalAddByte(uint8_t byte);
void internalReset();
// ...
};
Template Parameters
TSensorThe specific sensor decoder.
Attention
This class must not be used directly, it only serves as super class for specific sensors.

Public Member Functions

SensorStatus setData (uint8_t *data, size_t length)
 Sets the sensor state to the given data buffer. More...
 
SensorStatus addByte (uint8_t byte)
 Adds the byte to the sensor state. More...
 
void reset ()
 Resets the state of the sensor decoder for receiving a new data set. More...
 

Member Function Documentation

◆ setData()

template<typename TSensor>
SensorStatus Sensors::Sensor< TSensor >::setData ( uint8_t *  data,
size_t  length 
)
inline

Sets the sensor state to the given data buffer.

Parameters
dataSensor data buffer.
lengthLength of the data buffer.
Returns
Sensor state after setting the data buffer.

◆ addByte()

template<typename TSensor>
SensorStatus Sensors::Sensor< TSensor >::addByte ( uint8_t  byte)
inline

Adds the byte to the sensor state.

Parameters
byteByte to add.
Returns
Sensor state after adding the byte.

◆ reset()

template<typename TSensor>
void Sensors::Sensor< TSensor >::reset ( )
inline

Resets the state of the sensor decoder for receiving a new data set.

Enumeration Type Documentation

◆ SensorStatus

enum Sensors::SensorStatus : uint8_t
strong

Sensor status returned from Sensor::setData() and Sensor::addByte().

Enumerator
Complete 

The Sensor data is complete. The decoded data can be accessed using sensor specific methods.

Incomplete 

The Sensor data is incomplete. More bytes have to be added using Sensor::addByte() before the data can be accessed.

TooMuchData 

The Sensor data is invalid. Too many bytes have been added. Typically Sensor::reset() needs to be called to start a fresh decoder run.

InvalidData 

The Sensor data is invalid. The parsing failed. Typically Sensor::reset() needs to be called to start a fresh decoder run.