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 
square meters
Definition: phydat.h:87
degree Celsius
Definition: phydat.h:80
#define PHYDAT_DIM
The fixed number of dimensions we work with.
Definition: phydat.h:57
grams per cubic meter
Definition: phydat.h:122
part per billion
Definition: phydat.h:117
const char * phydat_unit_to_str_verbose(uint8_t unit)
Return a string representation for every unit, including non-physical units like &#39;none&#39; or &#39;time&#39;...
decibel-milliwatts
Definition: phydat.h:100
gauss
Definition: phydat.h:99
const char * phydat_unit_to_str(uint8_t unit)
Convert the given unit to a string.
the three dimensions contain sec, min, and hours
Definition: phydat.h:119
counts
Definition: phydat.h:113
unit undefined
Definition: phydat.h:77
Ohm.
Definition: phydat.h:103
out of 100
Definition: phydat.h:114
data has no physical unit
Definition: phydat.h:78
Farad.
Definition: phydat.h:102
meters
Definition: phydat.h:86
count per cubic meter
Definition: phydat.h:124
pH
Definition: phydat.h:105
part per million
Definition: phydat.h:116
the 3 dimensions contain days, months and years
Definition: phydat.h:120
Candela.
Definition: phydat.h:110
Volts.
Definition: phydat.h:97
Generic data structure for expressing physical values.
Definition: phydat.h:149
boolean value [0|1]
Definition: phydat.h:112
char phydat_prefix_from_scale(int8_t scale)
Convert the given scale factor to an SI prefix.
out of 1000
Definition: phydat.h:115
degree Fahrenheit
Definition: phydat.h:81
Ampere.
Definition: phydat.h:96
Beer?
Definition: phydat.h:107
Watt.
Definition: phydat.h:98
void phydat_dump(phydat_t *data, uint8_t dim)
Dump the given data container to STDIO.
uint8_t unit
the (physical) unit of the data
Definition: phydat.h:151
coulomb
Definition: phydat.h:101
Lux (lx)
Definition: phydat.h:84
degree per second
Definition: phydat.h:91
Common macros and compiler attributes/pragmas configuration.
gravitational force
Definition: phydat.h:90
grams - not using the SI unit (kg) here to make scale handling simpler
Definition: phydat.h:93
void phydat_fit(phydat_t *dat, const int32_t *values, unsigned int dim)
Scale integer value(s) to fit into a phydat_t.
int8_t scale
the scale factor, 10^*scale*
Definition: phydat.h:152
cubic meters
Definition: phydat.h:88
Kelvin.
Definition: phydat.h:82
size_t phydat_to_json(const phydat_t *data, size_t dim, char *buf)
Convert the given phydat_t structure into a JSON string.
Pascal.
Definition: phydat.h:108