-
Notifications
You must be signed in to change notification settings - Fork 2
/
Catena4430_cMeasurementLoopV2.h
174 lines (138 loc) · 5.33 KB
/
Catena4430_cMeasurementLoopV2.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
171
172
173
174
/*
Module: Catena4430_cMeasurementLoopV2.h
Function:
cMeasurementLoopV2 definitions.
Copyright:
See accompanying LICENSE file for copyright and license information.
Author:
Dhinesh Kumar Pitchai, MCCI Corporation October 2022
*/
#ifndef _Catena4430_cMeasurementLoopV2_h_
# define _Catena4430_cMeasurementLoopV2_h_
#pragma once
#include <Arduino.h>
#include <Wire.h>
#include <Catena_Mx25v8035f.h>
#include <Catena.h>
#include "Catena4430_cMeasurementLoop.h"
#include <mcciadk_baselib.h>
#include <stdlib.h>
#include <Catena-SHT3x.h>
#include <mcci_ltr_329als.h>
#include <cstdint>
extern McciCatena::Catena gCatena;
namespace McciCatena4430 {
/****************************************************************************\
|
| An object to represent the uplink activity
|
\****************************************************************************/
template <unsigned a_kMaxActivityEntries>
class cMeasurementFormatV2 : public cMeasurementBase
{
public:
static constexpr uint8_t kMessageFormatV2 = 0x36;
enum class Flags : uint8_t
{
Vbat = 1 << 0, // vBat
Version = 1 << 1, // Sketch version
CO2ppm = 1 << 2, // Carbondioxide (SCD30)
Boot = 1 << 3, // boot count
TH = 1 << 4, // temperature, humidity
Light = 1 << 5, // light (lux))
Pellets = 1 << 6, // Pellet count
Activity = 1 << 7, // Activity (min/max/avg)
};
static constexpr unsigned kMaxActivityEntries = a_kMaxActivityEntries;
static constexpr unsigned kMaxPelletEntries = 2;
static constexpr size_t kTxBufferSize = (1 + 4 + 1 + 2 + 4 + 2 + 1 + 4 + 3 + 6 + kMaxActivityEntries * 2);
// the structure of a measurement
struct Measurement
{
//----------------
// the subtypes:
//----------------
// environmental measurements
struct Env
{
// temperature (in degrees C)
float Temperature;
// humidity (in % RH)
float Humidity;
};
// ambient light measurements
struct Light
{
// light intensity
float Lux;
};
//---------------------------
// the actual members as POD
//---------------------------
// flags of entries that are valid.
Flags flags;
// environmental data
Env env;
// ambient light
Light light;
};
};
class cMeasurementLoopV2 : public cMeasurementLoop
{
public:
// some parameters
static constexpr unsigned kMaxActivityEntries = 8;
using MeasurementFormat = cMeasurementFormatV2<kMaxActivityEntries>;
using Measurement = MeasurementFormat::Measurement;
using FlagsV2 = MeasurementFormat::Flags;
static constexpr std::uint8_t kMessageFormat = MeasurementFormat::kMessageFormatV2;
// things specific to V2, including the measurement flags
// constructor
cMeasurementLoopV2() {};
// neither copyable nor movable
cMeasurementLoopV2(const cMeasurementLoopV2&) = delete;
cMeasurementLoopV2& operator=(const cMeasurementLoopV2&) = delete;
cMeasurementLoopV2(const cMeasurementLoopV2&&) = delete;
cMeasurementLoopV2& operator=(const cMeasurementLoopV2&&) = delete;
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:
McciCatenaSht3x::cSHT3x m_Sht{Wire};
Mcci_Ltr_329als::Ltr_329als m_Ltr{Wire};
Mcci_Ltr_329als_Regs::AlsContr_t m_AlsCtrl;
// set true if SHT3x is present
bool m_fSht3x : 1;
// set true if LTR329 is present
bool m_fLtr329: 1;
// set true if hardware error in LTR329
bool m_fHardError: 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 cMeasurementLoopV2::FlagsV2 operator| (const cMeasurementLoopV2::FlagsV2 lhs, const cMeasurementLoopV2::FlagsV2 rhs)
{
return cMeasurementLoopV2::FlagsV2(uint8_t(lhs) | uint8_t(rhs));
};
static constexpr cMeasurementLoopV2::FlagsV2 operator& (const cMeasurementLoopV2::FlagsV2 lhs, const cMeasurementLoopV2::FlagsV2 rhs)
{
return cMeasurementLoopV2::FlagsV2(uint8_t(lhs) & uint8_t(rhs));
};
static cMeasurementLoopV2::FlagsV2 operator|= (cMeasurementLoopV2::FlagsV2 &lhs, const cMeasurementLoopV2::FlagsV2 &rhs)
{
lhs = lhs | rhs;
return lhs;
};
} // namespace McciCatena4430
#endif /* _Catena4430_cMeasurementLoopV2_h_ */