-
Notifications
You must be signed in to change notification settings - Fork 2
/
Catena4430_cMeasurementLoopV1.h
170 lines (135 loc) · 5.2 KB
/
Catena4430_cMeasurementLoopV1.h
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
Module: Catena4430_cMeasurementLoopV1.h
Function:
cMeasurementLoopV1 definitions.
Copyright:
See accompanying LICENSE file for copyright and license information.
Author:
Dhinesh Kumar Pitchai, MCCI Corporation October 2022
*/
#ifndef _Catena4430_cMeasurementLoopV1_h_
# define _Catena4430_cMeasurementLoopV1_h_
#pragma once
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Catena_Si1133.h>
#include <Catena.h>
#include "Catena4430_cMeasurementLoop.h"
#include <mcciadk_baselib.h>
#include <stdlib.h>
#include <cstdint>
extern McciCatena::Catena gCatena;
namespace McciCatena4430 {
/****************************************************************************\
|
| An object to represent the uplink activity
|
\****************************************************************************/
template <unsigned a_kMaxActivityEntries>
class cMeasurementFormatV1 : public cMeasurementBase
{
public:
static constexpr uint8_t kMessageFormatV1 = 0x26;
enum class Flags : uint8_t
{
Vbat = 1 << 0, // vBat
Version = 1 << 1, // Sketch version
CO2ppm = 1 << 2, // Carbondioxide (SCD30)
Boot = 1 << 3, // boot count
TPH = 1 << 4, // temperature, pressure2, humidity
Light = 1 << 5, // light (IR, white, UV)
Pellets = 1 << 6, // Pellet count
Activity = 1 << 7, // Activity (min/max/avg)
};
static constexpr unsigned kMaxActivityEntries = a_kMaxActivityEntries;
static constexpr size_t kTxBufferSize = (1 + 4 + 1 + 2 + 4 + 2 + 1 + 6 + 2 + 6 + kMaxActivityEntries * 2);
// the structure of a measurement
struct Measurement
{
//----------------
// the subtypes:
//----------------
// environmental measurements
struct Env
{
// temperature (in degrees C)
float Temperature;
// pressure (in millibars/hPa)
float Pressure;
// humidity (in % RH)
float Humidity;
};
// ambient light measurements
struct Light
{
// "white" light, in w/m^2
float White;
};
//---------------------------
// the actual members as POD
//---------------------------
// flags of entries that are valid.
Flags flags;
// environmental data
Env env;
// ambient light
Light light;
};
};
class cMeasurementLoopV1 : public cMeasurementLoop
{
public:
// some parameters
static constexpr unsigned kMaxActivityEntries = 8;
using MeasurementFormat = cMeasurementFormatV1<kMaxActivityEntries>;
using Measurement = MeasurementFormat::Measurement;
using FlagsV1 = MeasurementFormat::Flags;
static constexpr std::uint8_t kMessageFormat = MeasurementFormat::kMessageFormatV1;
cMeasurementLoopV1() {};
// neither copyable nor movable
cMeasurementLoopV1(const cMeasurementLoopV1&) = delete;
cMeasurementLoopV1& operator=(const cMeasurementLoopV1&) = delete;
cMeasurementLoopV1(const cMeasurementLoopV1&&) = delete;
cMeasurementLoopV1& operator=(const cMeasurementLoopV1&&) = delete;
public:
// things specific to V1, including the measurement flags
Adafruit_BME280 m_BME280;
McciCatena::Catena_Si1133 m_si1133;
virtual void beginSensors(void) override;
virtual bool takeMeasurements(void) override;
virtual bool formatMeasurements(cMeasurementLoop::TxBuffer_t &b, cMeasurementLoop::Measurement const &mData) override;
virtual bool clearMeasurements(void) override;
virtual void writeVersionData(File dataFile) override;
// concrete type for uplink data buffer
using TxBuffer_t = McciCatena::AbstractTxBuffer_t<MeasurementFormat::kTxBufferSize>;
using TxBufferBase_t = McciCatena::AbstractTxBufferBase_t;
private:
// set true if BME280 is present
bool m_fBme280 : 1;
// set true if SI1133 is present
bool m_fSi1133: 1;
// the current measurement
Measurement m_data;
// the data to write to the file
Measurement m_FileData;
TxBuffer_t m_FileTxBuffer;
};
//
// operator overloads for ORing structured flags
//
static constexpr cMeasurementLoopV1::FlagsV1 operator| (const cMeasurementLoopV1::FlagsV1 lhs, const cMeasurementLoopV1::FlagsV1 rhs)
{
return cMeasurementLoopV1::FlagsV1(uint8_t(lhs) | uint8_t(rhs));
};
static constexpr cMeasurementLoopV1::FlagsV1 operator& (const cMeasurementLoopV1::FlagsV1 lhs, const cMeasurementLoopV1::FlagsV1 rhs)
{
return cMeasurementLoopV1::FlagsV1(uint8_t(lhs) & uint8_t(rhs));
};
static cMeasurementLoopV1::FlagsV1 operator|= (cMeasurementLoopV1::FlagsV1 &lhs, const cMeasurementLoopV1::FlagsV1 &rhs)
{
lhs = lhs | rhs;
return lhs;
};
} // namespace McciCatena4430
#endif /* _Catena4430_cMeasurementLoopV1_h_ */