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 <stdint.h>
39 #include <errno.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
56 #define PHYDAT_DIM (3U)
57 
61 #define PHYDAT_SCALE_STR_MAXLEN (sizeof("*E-128\0"))
62 
74 enum {
75  /* generic values */
78  /* temperature */
82  /* illuminance */
84  /* dimension */
88  /* kinetic */
91  /* weight */
94  /* electricity */
98  /* pressure */
101  /* light */
103  /* logical */
108  /* aggregate values */
111  /* extend this list as needed */
112 };
113 
135 typedef struct {
136  int16_t val[PHYDAT_DIM];
137  uint8_t unit;
138  int8_t scale;
139 } phydat_t;
140 
147 void phydat_dump(phydat_t *data, uint8_t dim);
148 
157 const char *phydat_unit_to_str(uint8_t unit);
158 
168 char phydat_scale_to_str(int8_t scale);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif /* PHYDAT_H */
175 
#define PHYDAT_DIM
The fixed number of dimensions we work with.
Definition: phydat.h:56
Volts.
Definition: phydat.h:96
Lux (lx)
Definition: phydat.h:83
const char * phydat_unit_to_str(uint8_t unit)
Convert the given unit to a string.
Beer?
Definition: phydat.h:99
Ampere.
Definition: phydat.h:95
the three dimensions contain sec, min, and hours
Definition: phydat.h:109
gauss
Definition: phydat.h:97
Pascal.
Definition: phydat.h:100
square meters
Definition: phydat.h:86
boolean value [0|1]
Definition: phydat.h:104
Kelvin.
Definition: phydat.h:81
char phydat_scale_to_str(int8_t scale)
Convert the given scale factor to a NULL terminated string.
Candela.
Definition: phydat.h:102
out of 1000
Definition: phydat.h:106
Generic data structure for expressing physical values.
Definition: phydat.h:135
degree Celsius
Definition: phydat.h:79
part per million
Definition: phydat.h:107
void phydat_dump(phydat_t *data, uint8_t dim)
Dump the given data container to STDIO.
gravitational force
Definition: phydat.h:89
uint8_t unit
the (physical) unit of the data
Definition: phydat.h:137
data has no physical unit
Definition: phydat.h:77
unit undefined
Definition: phydat.h:76
degree Fahrenheit
Definition: phydat.h:80
grams - not using the SI unit (kg) here to make scale handling simpler
Definition: phydat.h:92
int8_t scale
the scale factor, 10^*scale*
Definition: phydat.h:138
degree per second
Definition: phydat.h:90
cubic meters
Definition: phydat.h:87
the 3 dimensions contain days, months and years
Definition: phydat.h:110
out of 100
Definition: phydat.h:105
meters
Definition: phydat.h:85