KPN Things Device SDK
SenMLBasePack Class Referenceabstract

#include <senml_basepack.h>

Inheritance diagram for SenMLBasePack:
SenMLBase SenMLPack SenMLSimplePack SenMLPackTemplate< double > SenMLPackTemplate< int > SenMLPackTemplate< T > SenMLDoublePack SenMLIntPack

Public Member Functions

 SenMLBasePack ()
 
 ~SenMLBasePack ()
 
int toJson (Stream &dest, SenMLStreamMethod format=SENML_RAW)
 
int toJson (char *dest, int length, SenMLStreamMethod format=SENML_RAW)
 
int toCbor (Stream &dest, SenMLStreamMethod format=SENML_RAW)
 
int toCbor (char *dest, int length, SenMLStreamMethod format=SENML_RAW)
 
void fromJson (Stream &source, SenMLStreamMethod format=SENML_RAW)
 
void fromJson (const char *source)
 
void fromCbor (Stream &source, SenMLStreamMethod format=SENML_RAW)
 
void fromCbor (char *source, int length, SenMLStreamMethod format)
 
bool add (SenMLBase &item)
 
bool clear ()
 
SenMLBasegetFirst ()
 
virtual int getCount ()
 
virtual int fieldsToJson ()=0
 
virtual int fieldsToCbor ()=0
 
virtual const char * getBaseName ()
 
virtual SenMLUnit getBaseUnit ()
 
- 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 bool isPack ()
 
virtual bool isActuator ()
 
void setLast (SenMLBase &value)
 
virtual int contentToCbor ()
 
virtual int contentToJson ()
 
virtual int getArrayLength ()
 
virtual int getFieldLength ()
 
virtual void setupStreamCtx (char *dest, int length, SenMLStreamMethod format)
 
virtual void setupStreamCtx (Stream *dest, SenMLStreamMethod format)
 
- 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 SenMLJsonListener
 
class SenMLCborParser
 
class SenMLPack
 
class SenMLBase
 

Detailed Description

SenMLBasePack represents a single senml document that can be sent or received.

Constructor & Destructor Documentation

◆ SenMLBasePack()

SenMLBasePack::SenMLBasePack ( )
inline

◆ ~SenMLBasePack()

SenMLBasePack::~SenMLBasePack ( )
inline

Member Function Documentation

◆ add()

bool SenMLBasePack::add ( SenMLBase item)

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.

◆ clear()

bool SenMLBasePack::clear ( )

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)

◆ contentToCbor()

int SenMLBasePack::contentToCbor ( )
protectedvirtual

Implements SenMLBase.

◆ contentToJson()

int SenMLBasePack::contentToJson ( )
protectedvirtual

Implements SenMLBase.

◆ fieldsToCbor()

virtual int SenMLBasePack::fieldsToCbor ( )
pure 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.

Implemented in SenMLDoublePack, SenMLIntPack, SenMLPack, and SenMLSimplePack.

◆ fieldsToJson()

virtual int SenMLBasePack::fieldsToJson ( )
pure 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.

Implemented in SenMLDoublePack, SenMLIntPack, SenMLPack, and SenMLSimplePack.

◆ fromCbor() [1/2]

void SenMLBasePack::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. 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

◆ fromCbor() [2/2]

void SenMLBasePack::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. 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

◆ fromJson() [1/2]

void SenMLBasePack::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. 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

◆ fromJson() [2/2]

void SenMLBasePack::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. 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

◆ getArrayLength()

int SenMLBasePack::getArrayLength ( )
protectedvirtual

Reimplemented from SenMLBase.

◆ getBaseName()

virtual const char * SenMLBasePack::getBaseName ( )
inlinevirtual

Reimplemented in SenMLPack.

◆ getBaseUnit()

virtual SenMLUnit SenMLBasePack::getBaseUnit ( )
inlinevirtual

Reimplemented in SenMLPack.

◆ getCount()

int SenMLBasePack::getCount ( )
virtual
Returns
the number of items this pack contains.

◆ getFieldLength()

virtual int SenMLBasePack::getFieldLength ( )
inlineprotectedvirtual

Implements SenMLBase.

Reimplemented in SenMLPack, and SenMLSimplePack.

◆ getFirst()

SenMLBase * SenMLBasePack::getFirst ( )
inline

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.

◆ isActuator()

virtual bool SenMLBasePack::isActuator ( )
inlineprotectedvirtual

Reimplemented in SenMLPack.

◆ isPack()

virtual bool SenMLBasePack::isPack ( )
inlineprotectedvirtual

Reimplemented from SenMLBase.

◆ setLast()

void SenMLBasePack::setLast ( SenMLBase value)
protected

◆ setupStreamCtx() [1/2]

void SenMLBasePack::setupStreamCtx ( char *  dest,
int  length,
SenMLStreamMethod  format 
)
protectedvirtual

Reimplemented in SenMLDoublePack, and SenMLIntPack.

◆ setupStreamCtx() [2/2]

void SenMLBasePack::setupStreamCtx ( Stream dest,
SenMLStreamMethod  format 
)
protectedvirtual

Reimplemented in SenMLDoublePack, and SenMLIntPack.

◆ toCbor() [1/2]

int SenMLBasePack::toCbor ( char *  dest,
int  length,
SenMLStreamMethod  format = SENML_RAW 
)

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

◆ toCbor() [2/2]

int SenMLBasePack::toCbor ( Stream dest,
SenMLStreamMethod  format = SENML_RAW 
)

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

◆ toJson() [1/2]

int SenMLBasePack::toJson ( char *  dest,
int  length,
SenMLStreamMethod  format = SENML_RAW 
)

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
nr of bytes that were rendered

◆ toJson() [2/2]

int SenMLBasePack::toJson ( Stream dest,
SenMLStreamMethod  format = SENML_RAW 
)

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
nr of bytes that were rendered

Friends And Related Function Documentation

◆ SenMLBase

friend class SenMLBase
friend

◆ SenMLCborParser

friend class SenMLCborParser
friend

◆ SenMLJsonListener

friend class SenMLJsonListener
friend

◆ SenMLPack

friend class SenMLPack
friend

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