KPN IoT / senml

Fork of kpn_senml by KPN IoT

Embed: (wiki syntax)

« Back to documentation index

SenMLDoublePack Class Reference

SenMLDoublePack Class Reference

An implimentation of the SenMLPack template that stores double base value and base-sum. More...

#include <senml_double_pack.h>

Inherits SenMLPackTemplate< double >.

Public Member Functions

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.
double getBaseSum ()
 Get the base-sum assigned to this pack object.
bool setBaseSum (doublevalue)
 Store the base-sum in the pack object.
double getBaseValue ()
 Get the base-value assigned to this pack object.
bool setBaseValue (doublevalue)
 Store the base-value in the pack object.
void toJson (Stream *dest, SenMLStreamMethod format=SENML_RAW)
 render the content of the current object to json data (string).
void toJson (char *dest, int length, SenMLStreamMethod format=SENML_RAW)
 render the content of the current object to json data (string).
int toCbor (Stream *dest, SenMLStreamMethod format=SENML_RAW)
 render the content of the current object to cbor data (binary).
int toCbor (char *dest, int length, SenMLStreamMethod format=SENML_RAW)
 render the content of the current object to cbor data (binary).
void fromJson (Stream *source, SenMLStreamMethod format=SENML_RAW)
 read and parse a senml json string from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.
void fromJson (const char *source)
 parse a senml json string from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.
void fromCbor (Stream *source, SenMLStreamMethod format=SENML_RAW)
 read and parse senml cbor from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.
void fromCbor (char *source, int length, SenMLStreamMethod format)
 parse senml cbor from the specified memory and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.
void setBaseName (const char *name)
 assign a basename to the SenMLPack object.
const char * getBaseName ()
 Get the base name.
void setBaseUnit (SenMLUnit unit)
 Set the base unit that will be used as the default unit for all records that don't define their own unit.
SenMLUnit getBaseUnit ()
 Get the base unit.
void setBaseTime (double time)
 Set the base time.
double getBaseTime ()
 Get the base time.
bool add (SenMLBase *item)
 Adds the specified SenML object to the document.
bool clear ()
 Clear out the document and remove all the children.
SenMLBasegetFirst ()
 get the first recrod of in this pack element.
SenMLBasegetNext ()
 get the next item in the list.
SenMLBasegetRoot ()
 Get the root object of this list.

Detailed Description

An implimentation of the SenMLPack template that stores double base value and base-sum.

Definition at line 22 of file senml_double_pack.h.


Member Function Documentation

bool add ( SenMLBase item ) [inherited]

Adds the specified SenML object to the document.

The item will be appended to the end of the linked list. The item being added, can be a regular SenMLRecord or another SenMLPack object if you want to send data for multiple devices in 1 SenML message. Check the result of the function to see if the operation was successful or not. Possible reasons for failure:

  • if the item being added is already part of a document.
    Parameters:
    itema pointer to a SenMlRecord or SenMLPack that needs to be added to the document.
    Returns:
    true upon success, otherwise false.

Definition at line 64 of file senml_pack.cpp.

bool clear (  ) [inherited]

Clear out the document and remove all the children.

Children aren't destroyed, this is up to the developer.

Returns:
true (at the moment, the function does not yet return false as it doesn't detect any errors)

Definition at line 84 of file senml_pack.cpp.

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.

Reimplemented from SenMLPack.

Definition at line 54 of file senml_double_pack.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

Reimplemented from SenMLPack.

Definition at line 36 of file senml_double_pack.cpp.

void fromCbor ( char *  source,
int  length,
SenMLStreamMethod  format 
) [inherited]

parse senml cbor from the specified memory and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.

This method takes a memory blob as input. The data must be fully defined.

Parameters:
sourcethe source data to use as input.
lengththe length of the source data.
formatdetermins how the data will be read (ex: as normal binary or in HEX format). See SenMLStreamMethod for possible methods.
Returns:
none

Definition at line 153 of file senml_pack.cpp.

void fromCbor ( Stream *  source,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

read and parse senml cbor from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.

This method is ideal for devices with very littel ram memory. It will block on most decices if there is no more input to be read from the stream and the end of the cbor structure is not yet reached. Note: on mbed systems, the blocking nature is not garanteed. Instead, if no more data is available before the end is reached, parsing will fail.

Parameters:
sourcethe source stream to read the data from.
formatdetermins how the data will be read (ex: as normal binary or in HEX format). See SenMLStreamMethod for possible methods.
Returns:
none

Definition at line 147 of file senml_pack.cpp.

void fromJson ( Stream *  source,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

read and parse a senml json string from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.

This method is ideal for devices with very littel ram memory. It will block on most devices if there is no more input to be read from the stream and the end of the json structure is not yet reached. Note: on mbed systems, the blocking nature is not garanteed. Instead, if no more data is available before the end is reached, parsing will fail.

Parameters:
sourcethe source stream to read the data from.
formatdetermins how the data will be read (ex: as normal text or in HEX format). See SenMLStreamMethod for possible methods.
Returns:
none

Definition at line 102 of file senml_pack.cpp.

void fromJson ( const char *  source ) [inherited]

parse a senml json string from the specified source and, for each registered actuator, call the appropriate event on the actuator itself, for others, the callback function PACK_ACTUATOR_SIGNATURE will be called, if present.

This method takes a string stored in memory as input. The json must be fully defined. It is up to the caller to transform it to a regular text string, if needed (ex: lora devices might send it in hex format).

Parameters:
sourcethe source string to use as input. This must be null terminated.
Returns:
none

Definition at line 135 of file senml_pack.cpp.

const char * getBaseName (  ) [inherited]

Get the base name.

see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info.

Returns:
the name of the device as an immutable string.

Definition at line 32 of file senml_pack.cpp.

double getBaseSum (  ) [inherited]

Get the base-sum assigned to this pack object.

Returns:
: the base-sum.

Definition at line 49 of file senml_pack_t.h.

double getBaseTime (  ) [inherited]

Get the base time.

see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info.

Returns:
a double value that is used as the default unit for records that don't define a unit of their own. if no base time is set, NaN will be returned.

Definition at line 361 of file senml_pack.h.

SenMLUnit getBaseUnit (  ) [inherited]

Get the base unit.

see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info.

Returns:
a SenMLUnit enum value that is used as the default unit for records that don't define a unit of their own.

Definition at line 346 of file senml_pack.h.

double getBaseValue (  ) [inherited]

Get the base-value assigned to this pack object.

Returns:
: the base-value.

Definition at line 61 of file senml_pack_t.h.

SenMLBase* getFirst (  ) [inherited]

get the first recrod of in this pack element.

Returns:
null when this object is empty (has no children), otherwise, the first item (SenMLRecord or SenMLPack) of the list.

Definition at line 385 of file senml_pack.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.

void setBaseName ( const char *  name ) [inherited]

assign a basename to the SenMLPack object.

This represents the name of the device. see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info. Every SenMLPack object must have a basename. This field will always be rendered in the output, even if the string is empty.

Parameters:
namean immutable string that will be used to represent the name of the device. An internal copy of the value will be made.
Returns:
none

Definition at line 27 of file senml_pack.cpp.

bool setBaseSum ( double  value ) [inherited]

Store the base-sum in the pack object.

Returns:
: true (returns a value to support possible future extentions)

Definition at line 55 of file senml_pack_t.h.

void setBaseTime ( double  time ) [inherited]

Set the base time.

see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info.

Parameters:
timethe value to use as base time. set bt to NaN if the field should not be included in the output.
Returns:
none

Definition at line 43 of file senml_pack.cpp.

void setBaseUnit ( SenMLUnit  unit ) [inherited]

Set the base unit that will be used as the default unit for all records that don't define their own unit.

see the spec on [base fields](https://tools.ietf.org/html/draft-ietf-core-senml-13#section-4.1) for more info. Set to SENML_UNIT_NONE for ommiting the base unit from the output (default).

Parameters:
unitthe unit to use as default. See SenMLUnit for all supported unit names.
Returns:
none

Definition at line 37 of file senml_pack.cpp.

bool setBaseValue ( double  value ) [inherited]

Store the base-value in the pack object.

Returns:
: true (returns a value to support possible future extentions)

Definition at line 67 of file senml_pack_t.h.

int toCbor ( Stream *  dest,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

render the content of the current object to cbor data (binary).

This function is ideal for devices with low memory usage but offers less control over the rendering process.

Parameters:
destthe destination stream to where the data will be rendered without buffering it in memory
formatdetermins how the data will be rendered. See SenMLStreamMethod for possible methods.
Returns:
nr of bytes that were rendered

Definition at line 246 of file senml_pack.cpp.

int toCbor ( char *  dest,
int  length,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

render the content of the current object to cbor data (binary).

This function renders the data to a memory buffer. If the buffer is full before the entire object is rendered, an error will be written to the debug stream.

Parameters:
desta memory buffer to which the data will be rendred.
lengththe length of the memory buffer.
formatdetermins how the data will be rendered. See SenMLStreamMethod for possible methods.
Returns:
nr of bytes that were rendered

Definition at line 256 of file senml_pack.cpp.

void toJson ( char *  dest,
int  length,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

render the content of the current object to json data (string).

This function renders the data to a memory buffer. If the buffer is full before the entire object is rendered, an error will be written to the debug stream.

Parameters:
desta memory buffer to which the data will be rendred.
lengththe length of the memory buffer.
formatdetermins how the data will be rendered. See SenMLStreamMethod for possible methods.
Returns:
none

Definition at line 168 of file senml_pack.cpp.

void toJson ( Stream *  dest,
SenMLStreamMethod  format = SENML_RAW 
) [inherited]

render the content of the current object to json data (string).

This function is ideal for devices with low memory usage but offers less control over the rendering process.

Parameters:
destthe destination stream to where the data will be rendered without buffering it in memory
formatdetermins how the data will be rendered. See SenMLStreamMethod for possible methods.
Returns:
none

Definition at line 160 of file senml_pack.cpp.