-
Notifications
You must be signed in to change notification settings - Fork 0
/
CayenneReferences.hpp
146 lines (137 loc) · 5.43 KB
/
CayenneReferences.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* This code is free software:
* you can redistribute it and/or modify it under the terms of a Creative
* Commons Attribution-NonCommercial 4.0 International License
* (http://creativecommons.org/licenses/by-nc/4.0/)
*
* Copyright (c) 2024 March by Klaasjan Wagenaar, Tristan Bosveld and Richard Kroesen
*/
#ifndef CAYENNE_REFERENCES_HPP
#define CAYENNE_REFERENCES_HPP
#include <stdint.h>
namespace PAYLOAD_ENCODER
{
/**
* @brief Enum class defining data types for Cayenne LPP.
*/
enum class DATA_TYPES : uint8_t
{
DIG_IN = 0, /* DIGITAL INPUT */
DIG_OUT = 1, /* DITIAL OUTPUT */
ANL_IN = 2, /* ANALOG INPUT */
ANL_OUT = 3, /* ANALOG OUTPUT */
ILLUM_SENS = 101, /* ILLUMINATION SENSOR */
PRSNC_SENS = 102, /* PRESCENCE SENSOR */
TEMP_SENS = 103, /* TEMPERATURE SENSOR */
HUM_SENS = 104, /* HUMIDITY SENSOR */
ACCRM_SENS = 113, /* ACCELEROMETER */
BARO_SENS = 115, /* BAROMETER */
GYRO_SENS = 134, /* GYROMETER */
GPS_LOC = 136 /* GPS LOCATION METER */
};
/**
* @brief Enum class defining sizes of data types for Cayenne LPP.
*/
enum class DATA_TYPES_SIZES : size_t
{
DIG_IN = 1, /* 1 bit resolution */
DIG_OUT = 1, /* 1 bit resolution */
ANL_IN = 2, /* 0.01 Signed */
ANL_OUT = 2, /* 0.01 Signed */
ILLUM_SENS = 2, /* 1 Lux Unsigned MSB */
PRSNC_SENS = 1, /* 1 bit resolution */
TEMP_SENS = 2, /* 0.1 °C Signed MSB */
HUM_SENS = 2, /* 0.1 % Unsigned */
ACCRM_SENS = 6, /* 0.001 G Signed MSB per axis */
BARO_SENS = 2, /* 0.1 hPa Unsigned MSB */
GYRO_SENS = 6, /* 0.01 °/s Signed MSB per axis */
GPS_LOC = 12 /* Latitude : 0.0001° Signed MSB
* Longitude : 0.0001° Signed MSB
* Altitude : 0.01 meter Signed MSB */
};
/**
* @brief Function to get the resolution for floating point data types.
* @param dataType The data type.
* @return The resolution of the data type.
*/
const static inline int16_t FLOATING_DATA_RESOLUTION(DATA_TYPES dataType)
{
switch (dataType)
{
case DATA_TYPES::DIG_IN:
break;
case DATA_TYPES::DIG_OUT:
break;
case DATA_TYPES::ANL_IN:
return 100; // 0.01 Signed Resolution.
case DATA_TYPES::ANL_OUT:
return 100; // 0.01 Signed Resolution.
case DATA_TYPES::ILLUM_SENS:
break;
case DATA_TYPES::PRSNC_SENS:
break;
case DATA_TYPES::TEMP_SENS:
return 10; // 0.1 °C Signed MSB Resolution.
case DATA_TYPES::HUM_SENS:
return 10; // 0.1 % Unsigned Resolution
case DATA_TYPES::ACCRM_SENS:
return 1000; // 0.001 G Signed MSB per axis
case DATA_TYPES::BARO_SENS:
return 10; // 0.1 hPa Unsigned MSB
case DATA_TYPES::GYRO_SENS:
return 100; // 0.01 °/s Signed MSB per axis
case DATA_TYPES::GPS_LOC:
return 10000; // 0.0001° Signed MSB for Lat- & Longitude
default:
return 0;
}
return 0;
}
/**
* @brief Function to create a mapping between data types reference and respective size in bytes.
* @param dataType The data type.
* @return The size of the data type in bytes.
*/
const static inline size_t getDataTypeSize(DATA_TYPES dataType)
{
switch (dataType)
{
case DATA_TYPES::DIG_IN:
return static_cast<size_t>(DATA_TYPES_SIZES::DIG_IN);
case DATA_TYPES::DIG_OUT:
return static_cast<size_t>(DATA_TYPES_SIZES::DIG_OUT);
case DATA_TYPES::ANL_IN:
return static_cast<size_t>(DATA_TYPES_SIZES::ANL_IN);
case DATA_TYPES::ANL_OUT:
return static_cast<size_t>(DATA_TYPES_SIZES::ANL_OUT);
case DATA_TYPES::ILLUM_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::ILLUM_SENS);
case DATA_TYPES::PRSNC_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::PRSNC_SENS);
case DATA_TYPES::TEMP_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::TEMP_SENS);
case DATA_TYPES::HUM_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::HUM_SENS);
case DATA_TYPES::ACCRM_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::ACCRM_SENS);
case DATA_TYPES::BARO_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::BARO_SENS);
case DATA_TYPES::GYRO_SENS:
return static_cast<size_t>(DATA_TYPES_SIZES::GYRO_SENS);
case DATA_TYPES::GPS_LOC:
return static_cast<size_t>(DATA_TYPES_SIZES::GPS_LOC);
default:
return 0;
}
return 0;
}
/**
* @brief Enum class defining error types for Cayenne LPP.
*/
enum class ERROR_TYPES : uint8_t
{
LPP_ERROR_OVERFLOW = 0, /**< No error */
LPP_ERROR_UNKOWN_TYPE = 1, /**< Buffer overflow */
LPP_ERROR_OK = 2 /**< Unknown data type */
};
} // End of PAYLOAD_ENCODER Namespace.
#endif // End of CAYENNE_REFERENCES_HPP