phydat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
35 #ifndef PHYDAT_H
36 #define PHYDAT_H
37 
38 #include <stddef.h>
39 #include <stdint.h>
40 #include "kernel_defines.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
57 #define PHYDAT_DIM (3U)
58 
62 #define PHYDAT_SCALE_STR_MAXLEN (sizeof("*E-128\0"))
63 
75 enum {
76  /* generic values */
79  /* temperature */
83  /* illuminance */
85  /* dimension */
89  /* kinetic */
92  /* weight */
95  /* electricity */
104  /* electrochemical */
106  /* pressure */
109  /* light */
111  /* logical */
118  /* aggregate values */
121  /* mass concentration */
123  /* number concentration */
125  /* extend this list as needed */
126 };
127 
149 typedef struct {
150  int16_t val[PHYDAT_DIM];
151  uint8_t unit;
152  int8_t scale;
153 } phydat_t;
154 
158 #define PHYDAT_MIN (INT16_MIN)
159 
163 #define PHYDAT_MAX (INT16_MAX)
164 
171 void phydat_dump(phydat_t *data, uint8_t dim);
172 
181 const char *phydat_unit_to_str(uint8_t unit);
182 
198 const char *phydat_unit_to_str_verbose(uint8_t unit);
199 
211 char phydat_prefix_from_scale(int8_t scale);
212 
241 void phydat_fit(phydat_t *dat, const int32_t *values, unsigned int dim);
242 
286 size_t phydat_to_json(const phydat_t *data, size_t dim, char *buf);
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* PHYDAT_H */
293 
UNIT_G
@ UNIT_G
gravitational force
Definition: phydat.h:90
UNIT_GS
@ UNIT_GS
gauss
Definition: phydat.h:99
UNIT_OHM
@ UNIT_OHM
Ohm.
Definition: phydat.h:103
UNIT_TEMP_F
@ UNIT_TEMP_F
degree Fahrenheit
Definition: phydat.h:81
phydat_to_json
size_t phydat_to_json(const phydat_t *data, size_t dim, char *buf)
Convert the given phydat_t structure into a JSON string.
UNIT_UNDEF
@ UNIT_UNDEF
unit undefined
Definition: phydat.h:77
phydat_unit_to_str_verbose
const char * phydat_unit_to_str_verbose(uint8_t unit)
Return a string representation for every unit, including non-physical units like 'none' or 'time'.
phydat_unit_to_str
const char * phydat_unit_to_str(uint8_t unit)
Convert the given unit to a string.
UNIT_GR
@ UNIT_GR
grams - not using the SI unit (kg) here to make scale handling simpler
Definition: phydat.h:93
UNIT_TEMP_C
@ UNIT_TEMP_C
degree Celsius
Definition: phydat.h:80
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
PHYDAT_DIM
#define PHYDAT_DIM
The fixed number of dimensions we work with.
Definition: phydat.h:57
UNIT_M2
@ UNIT_M2
square meters
Definition: phydat.h:87
UNIT_PERMILL
@ UNIT_PERMILL
out of 1000
Definition: phydat.h:115
UNIT_BAR
@ UNIT_BAR
Beer?
Definition: phydat.h:107
UNIT_TEMP_K
@ UNIT_TEMP_K
Kelvin.
Definition: phydat.h:82
UNIT_PA
@ UNIT_PA
Pascal.
Definition: phydat.h:108
UNIT_CTS
@ UNIT_CTS
counts
Definition: phydat.h:113
phydat_t::scale
int8_t scale
the scale factor, 10^*scale*
Definition: phydat.h:152
UNIT_COULOMB
@ UNIT_COULOMB
coulomb
Definition: phydat.h:101
UNIT_PPB
@ UNIT_PPB
part per billion
Definition: phydat.h:117
UNIT_F
@ UNIT_F
Farad.
Definition: phydat.h:102
phydat_t::unit
uint8_t unit
the (physical) unit of the data
Definition: phydat.h:151
phydat_t
Generic data structure for expressing physical values.
Definition: phydat.h:149
UNIT_PH
@ UNIT_PH
pH
Definition: phydat.h:105
UNIT_V
@ UNIT_V
Volts.
Definition: phydat.h:97
phydat_prefix_from_scale
char phydat_prefix_from_scale(int8_t scale)
Convert the given scale factor to an SI prefix.
phydat_dump
void phydat_dump(phydat_t *data, uint8_t dim)
Dump the given data container to STDIO.
UNIT_DPS
@ UNIT_DPS
degree per second
Definition: phydat.h:91
UNIT_CPM3
@ UNIT_CPM3
count per cubic meter
Definition: phydat.h:124
UNIT_A
@ UNIT_A
Ampere.
Definition: phydat.h:96
UNIT_DATE
@ UNIT_DATE
the 3 dimensions contain days, months and years
Definition: phydat.h:120
UNIT_M
@ UNIT_M
meters
Definition: phydat.h:86
UNIT_BOOL
@ UNIT_BOOL
boolean value [0|1]
Definition: phydat.h:112
UNIT_PERCENT
@ UNIT_PERCENT
out of 100
Definition: phydat.h:114
UNIT_DBM
@ UNIT_DBM
decibel-milliwatts
Definition: phydat.h:100
UNIT_NONE
@ UNIT_NONE
data has no physical unit
Definition: phydat.h:78
UNIT_W
@ UNIT_W
Watt.
Definition: phydat.h:98
phydat_fit
void phydat_fit(phydat_t *dat, const int32_t *values, unsigned int dim)
Scale integer value(s) to fit into a phydat_t.
UNIT_M3
@ UNIT_M3
cubic meters
Definition: phydat.h:88
UNIT_LUX
@ UNIT_LUX
Lux (lx)
Definition: phydat.h:84
UNIT_TIME
@ UNIT_TIME
the three dimensions contain sec, min, and hours
Definition: phydat.h:119
UNIT_CD
@ UNIT_CD
Candela.
Definition: phydat.h:110
UNIT_PPM
@ UNIT_PPM
part per million
Definition: phydat.h:116
UNIT_GPM3
@ UNIT_GPM3
grams per cubic meter
Definition: phydat.h:122