VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
vitroio::sdk::MeasurementApi< MaxParams > Class Template Reference

Class is responsible for cycling readings of measurement data using registered sensors. More...

#include <measurement_api.h>

Inheritance diagram for vitroio::sdk::MeasurementApi< MaxParams >:
Collaboration diagram for vitroio::sdk::MeasurementApi< MaxParams >:

Public Types

typedef Callback< void(SensorParameterValue *, int)> OnNewValuesCallback
 Type defines signature of callback function which is to be called when a new measurement values are read. More...
 

Public Member Functions

 MeasurementApi (EventQueue *targetQueue, uint32_t eventQueueSize=VITROIO_MEASUREMENT_API_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor chains an internal event queue to the targetQueue. More...
 
 MeasurementApi (osPriority priority=osPriorityNormal, uint32_t eventQueueSize=VITROIO_MEASUREMENT_API_DEFAULT_EVENT_QUEUE_SIZE)
 Contructor creates internal event loop using thread with priority priority. More...
 
 ~MeasurementApi ()
 Destructor frees resources and stops event loop. More...
 
bool isValid () const
 Function allows to check whether the object is in valid state. More...
 
bool registerSensor (AbstractSensorInterface *sensorIf)
 Function registers sensor from which the measurement data is to be read. More...
 
void setPollTime (unsigned int seconds)
 Function sets interval between readings of measurement values. More...
 
void setOnNewValuesCallback (OnNewValuesCallback callback)
 Function sets callback which will be called when the new values are read. More...
 
void startMeasurements ()
 Function starts cycling reading of measurement values. More...
 
void stopMeasurements ()
 Function stops reading of measurements values. More...
 

Detailed Description

template<uint32_t MaxParams>
class vitroio::sdk::MeasurementApi< MaxParams >

Class is responsible for cycling readings of measurement data using registered sensors.

The class uses an event loop for handling events. The event queue can be managed by external queue specified by user or by internal queue with thread of specified priority.

Template Parameters
MaxParamsSpecifies maximum number of sensors parameters that can be handled

Member Typedef Documentation

◆ OnNewValuesCallback

template<uint32_t MaxParams>
typedef Callback<void(SensorParameterValue*, int)> vitroio::sdk::MeasurementApi< MaxParams >::OnNewValuesCallback

Type defines signature of callback function which is to be called when a new measurement values are read.

Constructor & Destructor Documentation

◆ MeasurementApi() [1/2]

template<uint32_t MaxParams>
vitroio::sdk::MeasurementApi< MaxParams >::MeasurementApi ( EventQueue *  targetQueue,
uint32_t  eventQueueSize = VITROIO_MEASUREMENT_API_DEFAULT_EVENT_QUEUE_SIZE 
)
explicit

Contructor chains an internal event queue to the targetQueue.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

The contructor uses mbed::EventQueue::chain method for connection to targetQueue.

Note
Thread which handles targetQueue must be run before usage of this class (construction of the object can be done earlier).
Parameters
targetQueueExternal event queue to which the internal queue is to be chained
eventQueueSizeSize of internal event queue

◆ MeasurementApi() [2/2]

template<uint32_t MaxParams>
vitroio::sdk::MeasurementApi< MaxParams >::MeasurementApi ( osPriority  priority = osPriorityNormal,
uint32_t  eventQueueSize = VITROIO_MEASUREMENT_API_DEFAULT_EVENT_QUEUE_SIZE 
)
explicit

Contructor creates internal event loop using thread with priority priority.

There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.

Parameters
priorityPriority of thread for handling internal event queue
eventQueueSizeSize of internal event queue

◆ ~MeasurementApi()

template<uint32_t MaxParams>
vitroio::sdk::MeasurementApi< MaxParams >::~MeasurementApi ( )

Destructor frees resources and stops event loop.

Member Function Documentation

◆ isValid()

template<uint32_t MaxParams>
bool vitroio::sdk::MeasurementApi< MaxParams >::isValid ( ) const

Function allows to check whether the object is in valid state.

Note
This method should be called always after creation of the object.
Returns
Function returns true if the object is valid or false otherwise.

◆ registerSensor()

template<uint32_t MaxParams>
bool vitroio::sdk::MeasurementApi< MaxParams >::registerSensor ( AbstractSensorInterface sensorIf)

Function registers sensor from which the measurement data is to be read.

Parameters
sensorIfPointer to sensor interface to register
Returns
Function returns true on success or false if parameters count exceeded MaxParams.

◆ setOnNewValuesCallback()

template<uint32_t MaxParams>
void vitroio::sdk::MeasurementApi< MaxParams >::setOnNewValuesCallback ( OnNewValuesCallback  callback)

Function sets callback which will be called when the new values are read.

Note
Callback set by this method will be executed in another thread (event loop).

◆ setPollTime()

template<uint32_t MaxParams>
void vitroio::sdk::MeasurementApi< MaxParams >::setPollTime ( unsigned int  seconds)

Function sets interval between readings of measurement values.

Parameters
secondsInterval in seconds

◆ startMeasurements()

template<uint32_t MaxParams>
void vitroio::sdk::MeasurementApi< MaxParams >::startMeasurements ( )

Function starts cycling reading of measurement values.

Note
Function is not blocking. When new values are read the callback set by client will be executed in another thread.

◆ stopMeasurements()

template<uint32_t MaxParams>
void vitroio::sdk::MeasurementApi< MaxParams >::stopMeasurements ( )

Function stops reading of measurements values.