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 */
107  /* aggregate values */
110  /* extend this list as needed */
111 };
112 
134 typedef struct {
135  int16_t val[PHYDAT_DIM];
136  uint8_t unit;
137  int8_t scale;
138 } phydat_t;
139 
143 #define PHYDAT_MIN (INT16_MIN)
144 
148 #define PHYDAT_MAX (INT16_MAX)
149 
156 void phydat_dump(phydat_t *data, uint8_t dim);
157 
166 const char *phydat_unit_to_str(uint8_t unit);
167 
179 char phydat_prefix_from_scale(int8_t scale);
180 
213 uint8_t phydat_fit(phydat_t *dat, long value, unsigned int index, uint8_t prescale);
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* PHYDAT_H */
220 
#define PHYDAT_DIM
The fixed number of dimensions we work with.
Definition: phydat.h:55
out of 100
Definition: phydat.h:104
grams - not using the SI unit (kg) here to make scale handling simpler
Definition: phydat.h:91
the 3 dimensions contain days, months and years
Definition: phydat.h:109
Volts.
Definition: phydat.h:95
Lux (lx)
Definition: phydat.h:82
const char * phydat_unit_to_str(uint8_t unit)
Convert the given unit to a string.
Beer?
Definition: phydat.h:98
gravitational force
Definition: phydat.h:88
Pascal.
Definition: phydat.h:99
part per million
Definition: phydat.h:106
Generic data structure for expressing physical values.
Definition: phydat.h:134
Ampere.
Definition: phydat.h:94
char phydat_prefix_from_scale(int8_t scale)
Convert the given scale factor to an SI prefix.
cubic meters
Definition: phydat.h:86
unit undefined
Definition: phydat.h:75
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:136
out of 1000
Definition: phydat.h:105
degree Celsius
Definition: phydat.h:78
the three dimensions contain sec, min, and hours
Definition: phydat.h:108
int8_t scale
the scale factor, 10^*scale*
Definition: phydat.h:137
gauss
Definition: phydat.h:96
degree Fahrenheit
Definition: phydat.h:79
square meters
Definition: phydat.h:85
Candela.
Definition: phydat.h:101
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.
boolean value [0|1]
Definition: phydat.h:103
meters
Definition: phydat.h:84
Kelvin.
Definition: phydat.h:80
data has no physical unit
Definition: phydat.h:76
degree per second
Definition: phydat.h:89