KPN Things Device SDK
SenMLRecord Class Reference

#include <senml_record.h>

Inheritance diagram for SenMLRecord:
SenMLBase SenMLRecordTemplate< double > SenMLRecordTemplate< float > SenMLRecordTemplate< int > SenMLRecordTemplate< const char * > SenMLBinaryRecord SenMLBoolRecord SenMLRecordTemplate< T > SenMLDoubleRecord SenMLFloatRecord SenMLHalfFloatRecord SenMLIntRecord SenMLStringRecord SenMLBinaryActuator SenMLBoolActuator SenMLDoubleActuator SenMLFloatActuator SenMLHalfFloatActuator SenMLIntActuator SenMLStringActuator

Public Member Functions

 SenMLRecord ()
 
 SenMLRecord (const char *name)
 
 SenMLRecord (ThingsMLMeasurementIndex index)
 
 SenMLRecord (const char *name, SenMLUnit unit)
 
double getTime ()
 
bool setTime (double value, bool absolute=true)
 
void setTimeDirect (double value)
 
const char * getName ()
 
ThingsMLMeasurementIndex getIndex ()
 
void setName (const char *name)
 
double getUpdateTime ()
 
bool setUpdateTime (double value, bool absolute=true)
 
SenMLUnit getUnit ()
 
void setUnit (SenMLUnit value)
 
virtual int fieldsToJson ()
 
virtual int fieldsToCbor ()
 
- Public Member Functions inherited from SenMLBase
 SenMLBase ()
 
 ~SenMLBase ()
 
SenMLBasegetNext ()
 
SenMLBasegetRoot ()
 
virtual void adjustToBaseTime (double prev, double time)
 
virtual int fieldsToJson ()=0
 
virtual int fieldsToCbor ()=0
 

Protected Member Functions

virtual int contentToJson ()
 
virtual int contentToCbor ()
 
virtual void adjustToBaseTime (double prev, double time)
 
virtual void actuate (const void *value, int dataLength, SenMLDataType dataType)
 
int getFieldLength ()
 
- Protected Member Functions inherited from SenMLBase
virtual int contentToJson ()=0
 
void setNext (SenMLBase *value)
 
void setPrev (SenMLBase *value)
 
SenMLBasegetPrev ()
 
virtual bool isPack ()
 
virtual int contentToCbor ()=0
 
virtual int getArrayLength ()
 
virtual int getFieldLength ()=0
 

Friends

class SenMLCborParser
 
class SenMLJsonListener
 

Detailed Description

SenMLRecord represents a single measurement. Besides the value, it also stores the name, optional unit, timestamp and update time.

This is the base class for all record types, you can not work directly with this class. Instead, use one of it's derivatives such as SenMLBinaryRecord, SenMLBoolRecord, SenMLFloatRecord, SenMLIntRecord or SenMLStringRecord. Alternatively, you can create your own records by inheriting from this class, or SenMLRecordTemplate, a convenience template which allows you to create records for different data types.

Although a record object can be used by itself, usually record objects are added to SenMLPack objects.

Constructor & Destructor Documentation

◆ SenMLRecord() [1/4]

SenMLRecord::SenMLRecord ( )
inline

create a SenMLRecord object.

◆ SenMLRecord() [2/4]

SenMLRecord::SenMLRecord ( const char *  name)
inline

create a SenMLRecord object.

Parameters
namethe identifier for this record. This is a free-form string, but a set of predefined names, supported by the KPN network can be found in senml_enums.h

◆ SenMLRecord() [3/4]

SenMLRecord::SenMLRecord ( ThingsMLMeasurementIndex  index)
inline

◆ SenMLRecord() [4/4]

SenMLRecord::SenMLRecord ( const char *  name,
SenMLUnit  unit 
)
inline

create a SenMLRecord object.

Parameters
namethe string that will be prepended to all records in this pack. Is used to represent the name of the device.
unitthe unit that should be included in the output. See the SenMLUnit enum for supported unit types.

Member Function Documentation

◆ actuate()

void SenMLRecord::actuate ( const void *  value,
int  dataLength,
SenMLDataType  dataType 
)
protectedvirtual

◆ adjustToBaseTime()

void SenMLRecord::adjustToBaseTime ( double  prev,
double  time 
)
protectedvirtual

Reimplemented from SenMLBase.

◆ contentToCbor()

int SenMLRecord::contentToCbor ( )
protectedvirtual

Implements SenMLBase.

◆ contentToJson()

int SenMLRecord::contentToJson ( )
protectedvirtual

Implements SenMLBase.

◆ fieldsToCbor()

int SenMLRecord::fieldsToCbor ( )
virtual

renders all the fields to cbor format. renders all the fields of the object without the length info at the beginning note: this is public so that custom implementations for the record object can use other objects internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt.

Returns
: The number of bytes that were written.

Implements SenMLBase.

Reimplemented in SenMLBinaryRecord, SenMLBoolRecord, SenMLDoubleRecord, SenMLFloatRecord, SenMLHalfFloatRecord, SenMLIntRecord, and SenMLStringRecord.

◆ fieldsToJson()

int SenMLRecord::fieldsToJson ( )
virtual

renders all the fields to json, without the starting and ending brackets. Inheriters can extend this function if they want to add extra fields to the json output note: this is public so that custom implementations for the record object can use other objects internally and render to json using this function (ex: coordinatesRecord using 3 floatRecrods for lat, lon & alt.

Returns
: The number of bytes that were written.

Implements SenMLBase.

Reimplemented in SenMLBinaryRecord, SenMLBoolRecord, SenMLDoubleRecord, SenMLFloatRecord, SenMLHalfFloatRecord, SenMLIntRecord, and SenMLStringRecord.

◆ getFieldLength()

int SenMLRecord::getFieldLength ( )
protectedvirtual

Implements SenMLBase.

◆ getIndex()

ThingsMLMeasurementIndex SenMLRecord::getIndex ( )
inline

◆ getName()

const char * SenMLRecord::getName ( )
inline

Get the name of the record.

Returns
the name of the record as an immutable string. Don't delete this pointer, it refers to the internal buffer of the object and is managed by the record.

◆ getTime()

double SenMLRecord::getTime ( )
inline

returns the time assigned to this record. NaN represents 'no time assigned'. See base fields for more info on the time value.

Returns
the timestamp assigned to the record, expressed in unix epoch, relative to the parent SenMLPack object's base time (if any).

◆ getUnit()

SenMLUnit SenMLRecord::getUnit ( )
inline

Get the enum that identifies the unit name assigned to the record. The value SENML_UNIT_NONE means that no unit will be generated in the output. Senml defines a fixed set of supported unit names.

Returns
a SenMLUnit enum value representing the unit name.

◆ getUpdateTime()

double SenMLRecord::getUpdateTime ( )
inline

Get the expected timestamp at which this record will be updated again. NaN represents 'no time assigned'.

Returns
a unix epoch time, relative to the parent SenMLPack object's base time (if any).

◆ setName()

void SenMLRecord::setName ( const char *  name)
inline

Assign an identifier to the record. This is a free-form string, but a set of predefined names, supported by the KPN network can be found in senml_enums.h

Parameters
namea string that represents the identifier for the record. A copy of the value is made.
Returns
none

◆ setTime()

bool SenMLRecord::setTime ( double  value,
bool  absolute = true 
)

set the time, expressed as a unix epoch time, absolute or relative to the base time of the parent SenMLPack object.. when absolute is true (default behaviour), the time value will be made relative to the base time of the pack object, if it has a base time. See base fields for more info on the time value. Possible reasons for failure:

  • if there is a root object, but it is not a SenMLPack
  • if absolute is false, but there is no parent SenMLPack object.
    Parameters
    valuethe unix epoch time value to assign to the record
    absoluteWhen true (default), the value will be interpreted as an absolute time stamp. If there is a parent SenMLPack, the value will be made relative to the pack's base time, if there is any. When false, no conversion is done, but a parent SenMLPack has to be present.
    Returns
    true upon success, otherwise false.

◆ setTimeDirect()

void SenMLRecord::setTimeDirect ( double  value)
inline

set the time, expressed as a unix epoch time. This assigns the value directly without taking the parent senml pack into consideration. Use this only when you are calculating the values in a way that is not compatible with the functionality of setTime(); See base fields for more info on the time value.

Parameters
valuethe unix epoch time value to assign to the record

◆ setUnit()

void SenMLRecord::setUnit ( SenMLUnit  value)
inline

Assigns a unit value to the record. The value SENML_UNIT_NONE means that no unit will be generated in the output. Senml defines a fixed set of supported unit names.

Parameters
valuea SenMLUnit enum value representing the unit name.
Returns
none

◆ setUpdateTime()

bool SenMLRecord::setUpdateTime ( double  value,
bool  absolute = true 
)

Assign a timestamp to the record at which it is expected to update the value. See base fields for more info on the time

Note: previously update time was interpreted as being relative, however this is not in line with the spec. the optional paramter absolute will now be ignored and true will always be returned.

Parameters
valuethe unix epoch update time value to assign to the record
absoluteignored. previously updatetime was interpreted as being relative to basetime, this is not in line with the spec however.
Returns
always returns true

Friends And Related Function Documentation

◆ SenMLCborParser

friend class SenMLCborParser
friend

◆ SenMLJsonListener

friend class SenMLJsonListener
friend

The documentation for this class was generated from the following files: