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 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
55 #define PHYDAT_DIM (3U)
56 
60 #define PHYDAT_SCALE_STR_MAXLEN (sizeof("*E-128\0"))
61 
73 enum {
74  /* generic values */
77  /* temperature */
81  /* illuminance */
83  /* dimension */
87  /* kinetic */
90  /* weight */
93  /* electricity */
97  /* pressure */
100  /* light */
102  /* logical */
109  /* aggregate values */
112  /* extend this list as needed */
113 };
114 
136 typedef struct {
137  int16_t val[PHYDAT_DIM];
138  uint8_t unit;
139  int8_t scale;
140 } phydat_t;
141 
145 #define PHYDAT_MIN (INT16_MIN)
146 
150 #define PHYDAT_MAX (INT16_MAX)
151 
158 void phydat_dump(phydat_t *data, uint8_t dim);
159 
168 const char *phydat_unit_to_str(uint8_t unit);
169 
181 char phydat_prefix_from_scale(int8_t scale);
182 
215 uint8_t phydat_fit(phydat_t *dat, long value, unsigned int index, uint8_t prescale);
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif /* PHYDAT_H */
222 
#define PHYDAT_DIM
The fixed number of dimensions we work with.
Definition: phydat.h:55
part per billion
Definition: phydat.h:108
const char * phydat_unit_to_str(uint8_t unit)
Convert the given unit to a string.
degree Celsius
Definition: phydat.h:78
out of 100
Definition: phydat.h:105
part per million
Definition: phydat.h:107
degree Fahrenheit
Definition: phydat.h:79
gravitational force
Definition: phydat.h:88
out of 1000
Definition: phydat.h:106
boolean value [0|1]
Definition: phydat.h:103
gauss
Definition: phydat.h:96
Lux (lx)
Definition: phydat.h:82
meters
Definition: phydat.h:84
Generic data structure for expressing physical values.
Definition: phydat.h:136
the three dimensions contain sec, min, and hours
Definition: phydat.h:110
char phydat_prefix_from_scale(int8_t scale)
Convert the given scale factor to an SI prefix.
cubic meters
Definition: phydat.h:86
void phydat_dump(phydat_t *data, uint8_t dim)
Dump the given data container to STDIO.
Beer?
Definition: phydat.h:98
uint8_t unit
the (physical) unit of the data
Definition: phydat.h:138
square meters
Definition: phydat.h:85
data has no physical unit
Definition: phydat.h:76
Candela.
Definition: phydat.h:101
unit undefined
Definition: phydat.h:75
the 3 dimensions contain days, months and years
Definition: phydat.h:111
degree per second
Definition: phydat.h:89
Volts.
Definition: phydat.h:95
int8_t scale
the scale factor, 10^*scale*
Definition: phydat.h:139
Pascal.
Definition: phydat.h:99
uint8_t phydat_fit(phydat_t *dat, long value, unsigned int index, uint8_t prescale)
Scale an integer value to fit into a phydat_t.
counts
Definition: phydat.h:104
Ampere.
Definition: phydat.h:94
Kelvin.
Definition: phydat.h:80
grams - not using the SI unit (kg) here to make scale handling simpler
Definition: phydat.h:91