|
KPN Things Device SDK
|
#include <senml_pack.h>
Public Member Functions | |
| SenMLPack () | |
| SenMLPack (const char *baseName) | |
| SenMLPack (const char *baseName, SenMLUnit baseUnit) | |
| SenMLPack (const char *baseName, SenMLUnit baseUnit, double baseTime) | |
| SenMLPack (PACK_ACTUATOR_SIGNATURE) | |
| SenMLPack (const char *baseName, PACK_ACTUATOR_SIGNATURE) | |
| SenMLPack (const char *baseName, SenMLUnit baseUnit, PACK_ACTUATOR_SIGNATURE) | |
| SenMLPack (const char *baseName, SenMLUnit baseUnit, double baseTime, PACK_ACTUATOR_SIGNATURE) | |
| ~SenMLPack () | |
| void | setBaseName (const char *name) |
| const char * | getBaseName () |
| void | setBaseUnit (SenMLUnit unit) |
| SenMLUnit | getBaseUnit () |
| void | setBaseTime (double time) |
| void | setBaseTimeSilently (double time) |
| double | getBaseTime () |
| virtual int | fieldsToJson () |
| virtual int | fieldsToCbor () |
Public Member Functions inherited from SenMLBasePack | |
| 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 () |
| SenMLBase * | getFirst () |
| 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 () | |
| SenMLBase * | getNext () |
| SenMLBase * | getRoot () |
| virtual void | adjustToBaseTime (double prev, double time) |
| virtual int | fieldsToJson ()=0 |
| virtual int | fieldsToCbor ()=0 |
Protected Member Functions | |
| bool | isActuator () |
| void | actuate (const char *pack, const char *record, const void *value, int valueLength, SenMLDataType dataType) |
| virtual int | getFieldLength () |
Protected Member Functions inherited from SenMLBasePack | |
| 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) |
| SenMLBase * | getPrev () |
| virtual bool | isPack () |
| virtual int | contentToCbor ()=0 |
| virtual int | getArrayLength () |
| virtual int | getFieldLength ()=0 |
Friends | |
| class | SenMLJsonListener |
| class | SenMLCborParser |
SenMLPack represents a single senml document that can be sent or received.
A senmlPack object has SenMLRecords and/or other SenMLPack objects as children. These represent the data that the object contains. A SenMLRecord represents a single value, while child SenMLPacks represent data of other devices. When a SenMLPack contains other SenMLPack objects, the root object represents a gateway.
A SenMLPack object is able to render and parse the data to/from a json string or to/from binary CBOR data. Both rendering and parsing can be done either directly from a stream (like an UART connected to a modem), or from a memory buffer. Rendering to and parsing from a stream is useful for devices that have extreme low memory available. Almost no buffers are used in this case. Error handling is limited in this case though. The parser and generator are able to render in the native format (strings for json, binary data for cbor) and as a hex string. This is especially useful when directly working on a stream: some modems (ex lora) accept instructions with data in HEX format.
example:
|
inline |
create a SenMLPack object.
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
| baseUnit | the unit name that will be used by default if the record doesnt not define one. |
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
| baseUnit | the unit name that will be used by default if the record doesnt not define one. |
| baseTime | the time that will be added to each record. When specified, each record that does not specify a time, will receive this time. When the record does have a time, the baseTime of the pack is added to it, so the time of the record becomes relative to that of the pack. |
|
inline |
create a SenMLPack object.
| callback | a function that will be called while parsing incomming data, when no record can be found that matches any of the defined ones in the object. The parameters of the callback must be: const char* packName the name of the pack that the record belongs to. The data is for a child SenMLPack when this field is different then the name of the root pack. const char* recordName the name of the record const void* value a pointer to the memory blob that contains the actual value. int size the size of the memory blobl SenMLDataType dataType: defines how to interprete the memory blob (ex: pointer to integer,..) |
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
| callback | a function that will be called while parsing incomming data, when no record can be found that matches any of the defined ones in the object. The parameters of the callback must be: const char* packName the name of the pack that the record belongs to. The data is for a child SenMLPack when this field is different then the name of the root pack. const char* recordName the name of the record const void* value a pointer to the memory blob that contains the actual value. int size the size of the memory blobl SenMLDataType dataType: defines how to interprete the memory blob (ex: pointer to integer,..) |
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
| baseUnit | the unit name that will be used by default if the record doesnt not define one. |
| callback | a function that will be called while parsing incomming data, when no record can be found that matches any of the defined ones in the object. The parameters of the callback must be: const char* packName the name of the pack that the record belongs to. The data is for a child SenMLPack when this field is different then the name of the root pack. const char* recordName the name of the record const void* value a pointer to the memory blob that contains the actual value. int size the size of the memory blobl SenMLDataType dataType: defines how to interprete the memory blob (ex: pointer to integer,..) |
|
inline |
create a SenMLPack object.
| baseName | the string that will be prepended to all records in this pack. Is used to represent the name of the device. |
| baseUnit | the unit name that will be used by default if the record doesnt not define one. |
| baseTime | the time that will be added to each record. When specified, each record that does not specify a time, will receive this time. When the record does have a time, the baseTime of the pack is added to it, so the time of the record becomes relative to that of the pack. |
| callback | a function that will be called while parsing incomming data, when no record can be found that matches any of the defined ones in the object. The parameters of the callback must be: const char* packName the name of the pack that the record belongs to. The data is for a child SenMLPack when this field is different then the name of the root pack. const char* recordName the name of the record const void* value a pointer to the memory blob that contains the actual value. int size the size of the memory blobl SenMLDataType dataType: defines how to interprete the memory blob (ex: pointer to integer,..) |
|
inline |
destroys the SenMLPack object.
|
inlineprotected |
|
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.
Implements SenMLBasePack.
Reimplemented in SenMLDoublePack, and SenMLIntPack.
|
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.
Implements SenMLBasePack.
Reimplemented in SenMLDoublePack, and SenMLIntPack.
|
virtual |
Get the base name. see the spec on base fields for more info.
Reimplemented from SenMLBasePack.
|
inline |
Get the base time. see the spec on base fields for more info.
|
inlinevirtual |
Get the base unit. see the spec on base fields for more info.
Reimplemented from SenMLBasePack.
|
protectedvirtual |
Reimplemented from SenMLBasePack.
|
inlineprotectedvirtual |
Reimplemented from SenMLBasePack.
| void SenMLPack::setBaseName | ( | const char * | name | ) |
assign a basename to the SenMLPack object. This represents the name of the device. see the spec on base fields 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.
| name | an immutable string that will be used to represent the name of the device. An internal copy of the value will be made. |
| void SenMLPack::setBaseTime | ( | double | time | ) |
Set the base time. see the spec on base fields for more info.
| time | the value to use as base time. set bt to NaN if the field should not be included in the output. |
| void SenMLPack::setBaseTimeSilently | ( | double | time | ) |
Set the base time without adjusting all it's records. see the spec on basefields for more info.
| time | the value to use as base time. set bt to NaN if the field should not be included in the output. |
| void SenMLPack::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. see the spec on base fields for more info. Set to SENML_UNIT_NONE for ommiting the base unit from the output (default).
| unit | the unit to use as default. See SenMLUnit for all supported unit names. |
|
friend |
|
friend |