KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

SenMLRecord Class Reference

SenMLRecord Class Reference

SenMLRecord represents a single measurement. More...

#include <senml_record.h>

Inherits SenMLBase.

Inherited by SenMLBinaryRecord, SenMLRecordTemplate< T >, SenMLRecordTemplate< bool >, SenMLRecordTemplate< float >, SenMLRecordTemplate< int >, and SenMLRecordTemplate< String >.

Public Member Functions

 SenMLRecord ()
 create a SenMLRecord object.
 SenMLRecord (const char *name)
 create a SenMLRecord object.
 SenMLRecord (const char *name, SenMLUnit unit)
 create a SenMLRecord object.
double getTime ()
 returns the time assigned to this record.
bool 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.
const char * getName ()
 Get the name of the record.
void setName (const char *name)
 Assign an identifier to the record.
int getUpdateTime ()
 Get the expected timestamp at which this record will be updated again.
bool setUpdateTime (double value, bool absolute=true)
 Assign a timestamp to the record at which it is expected to update the value.
SenMLUnit getUnit ()
 Get the enum that identifies the unit name assigned to the record.
void setUnit (SenMLUnit value)
 Assigns a unit value to the record.
virtual void fieldsToJson ()
 renders all the fields to json, without the starting and ending brackets.
virtual int fieldsToCbor ()
 renders all the fields to cbor format.
SenMLBasegetNext ()
 get the next item in the list.
SenMLBasegetRoot ()
 Get the root object of this list.

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.

Definition at line 39 of file senml_record.h.


Constructor & Destructor Documentation

SenMLRecord (  )

create a SenMLRecord object.

Definition at line 48 of file senml_record.h.

SenMLRecord ( const char *  name )

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

Definition at line 20 of file senml_record.cpp.

SenMLRecord ( const char *  name,
SenMLUnit  unit 
)

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.

Definition at line 24 of file senml_record.cpp.


Member Function Documentation

int 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, SenMLFloatRecord, SenMLIntRecord, and SenMLStringRecord.

Definition at line 148 of file senml_record.cpp.

void 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:
: None

Implements SenMLBase.

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

Definition at line 95 of file senml_record.cpp.

const char* getName (  )

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.

Definition at line 98 of file senml_record.h.

SenMLBase* getNext (  ) [inherited]

get the next item in the list.

Returns:
: a pointer to the next SenMLBase object in the list or NULL when at the end of the list.

Definition at line 42 of file senml_base.h.

SenMLBase * getRoot (  ) [inherited]

Get the root object of this list.

Usually, this is a SenMLPack object. The root object is defined as the first item in the list.

Returns:
: a pointer to the first SenMLBase object in the list or NULL when there is none.

Definition at line 53 of file senml_base.cpp.

double getTime (  )

returns the time assigned to this record.

NaN represents 'no time assigned'. See [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) 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).

Definition at line 73 of file senml_record.h.

SenMLUnit getUnit (  )

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](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-12.1).

Returns:
a SenMLUnit enum value representing the unit name.

Definition at line 139 of file senml_record.h.

int getUpdateTime (  )

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).

Definition at line 114 of file senml_record.h.

void setName ( const char *  name )

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

Definition at line 107 of file senml_record.h.

bool 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](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) 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.

Definition at line 28 of file senml_record.cpp.

void setUnit ( SenMLUnit  value )

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](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-12.1).

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

Definition at line 148 of file senml_record.h.

bool setUpdateTime ( double  value,
bool  absolute = true 
)

Assign a timestamp to the record at which it is expected to update the value.

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](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) 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 update 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.

Definition at line 50 of file senml_record.cpp.