1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/include/senml/saul.h
Silke Hofstra 9d61bdbb06 sys/senml: add SenML modules
Add a basic SenML module and submodules with support for:

- Encoding SenML values as CBOR using NanoCBOR.
- Converting from Phydat to SenML.
- Reading and encoding SAUL sensors.
2022-02-11 12:38:21 +01:00

77 lines
2.0 KiB
C

/*
* Copyright (C) 2021 Silke Hofstra
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_senml_saul SenML SAUL
* @ingroup sys_senml
* @brief Functionality for reading @ref drivers_saul sensors as @ref sys_senml
*
* The `senml_saul` module contains functions for reading sensors using
* @ref drivers_saul and converting them to @ref sys_senml_cbor.
*
* @{
*
* @file
* @brief Functionality for reading @ref drivers_saul sensors as @ref sys_senml
*
* @author Silke Hofstra <silke@slxh.eu>
*/
#ifndef SENML_SAUL_H
#define SENML_SAUL_H
#include <stdint.h>
#include "nanocbor/nanocbor.h"
#include "saul_reg.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Use floats instead of decimal types when encoding SAUL measurements.
*
* If this is set to `1` the @ref phydat_t values from SAUL are converted to
* @ref senml_numeric_t using @ref phydat_to_senml_float.
* Values are converted using @ref phydat_to_senml_decimal otherwise.
*/
#ifndef CONFIG_SENML_SAUL_USE_FLOATS
#define CONFIG_SENML_SAUL_USE_FLOATS 0
#endif
/**
* @brief Encode a single @ref drivers_saul sensor as senml+cbor.
*
* @param enc NanoCBOR encoder.
* @param dev SAUL sensor to encode.
*
* @return Number of dimensions encoded. Less or equal to 0 on error.
*/
int senml_saul_reg_encode_cbor(nanocbor_encoder_t *enc, saul_reg_t *dev);
/**
* @brief Encode all sensors from a @ref drivers_saul registry as senml+cbor.
*
* This functions reads all @ref drivers_saul sensors in a registry and encodes
* the values as SenML/CBOR.
*
* @param buf Buffer to store the CBOR in.
* @param len Length of the buffer.
* @param reg SAUL registry to encode.
*
* @return Size of the encoded data.
*/
size_t senml_saul_encode_cbor(uint8_t *buf, size_t len, saul_reg_t *reg);
#ifdef __cplusplus
}
#endif
#endif /* SENML_SAUL_H */
/** @} */