MycilaJSY
13.0.0
Arduino / ESP32 library for the JSY1031, JSY-MK-163, JSY-MK-193, JSY-MK-194, JSY-MK-227, JSY-MK-229, JSY-MK-333 families single-phase and three-phase AC bidirectional meters from Shenzhen Jiansiyan Technologies Co, Ltd.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
MycilaJSYData.cpp
1
// SPDX-License-Identifier: MIT
2
/*
3
* Copyright (C) Mathieu Carbou
4
*/
5
#include "MycilaJSY.h"
6
7
void
Mycila::JSY::Data::clear() {
8
address = MYCILA_JSY_ADDRESS_UNKNOWN;
9
model = MYCILA_JSY_MK_UNKNOWN;
10
_metrics[0].clear();
11
_metrics[1].clear();
12
_metrics[2].clear();
13
aggregate.clear();
14
}
15
16
bool
Mycila::JSY::Data::operator==(
const
Mycila::JSY::Data& other)
const
{
17
return
address == other.address &&
18
model == other.model &&
19
_metrics[0] == other._metrics[0] &&
20
_metrics[1] == other._metrics[1] &&
21
_metrics[2] == other._metrics[2] &&
22
aggregate == other.aggregate;
23
}
24
25
void
Mycila::JSY::Data::operator=(
const
Mycila::JSY::Data& other) {
26
address = other.address;
27
model = other.model;
28
_metrics[0] = other._metrics[0];
29
_metrics[1] = other._metrics[1];
30
_metrics[2] = other._metrics[2];
31
aggregate = other.aggregate;
32
}
33
34
#ifdef MYCILA_JSON_SUPPORT
35
void
Mycila::JSY::Data::toJson(
const
JsonObject& root)
const
{
36
root[
"address"
] = address;
37
root[
"model"
] = model;
38
root[
"model_name"
] = Mycila::JSY::getModelName(model);
39
40
switch
(model) {
41
{
42
case
MYCILA_JSY_MK_1031:
43
case
MYCILA_JSY_MK_163:
44
case
MYCILA_JSY_MK_227:
45
case
MYCILA_JSY_MK_229:
46
_metrics[0].toJson(root);
47
break
;
48
49
case
MYCILA_JSY_MK_193:
50
case
MYCILA_JSY_MK_194:
51
aggregate.toJson(root[
"aggregate"
].to<JsonObject>());
52
_metrics[0].toJson(root[
"channel1"
].to<JsonObject>());
53
_metrics[1].toJson(root[
"channel2"
].to<JsonObject>());
54
break
;
55
56
case
MYCILA_JSY_MK_333:
57
aggregate.toJson(root[
"aggregate"
].to<JsonObject>());
58
_metrics[0].toJson(root[
"phaseA"
].to<JsonObject>());
59
_metrics[1].toJson(root[
"phaseB"
].to<JsonObject>());
60
_metrics[2].toJson(root[
"phaseC"
].to<JsonObject>());
61
break
;
62
63
default
:
64
break
;
65
}
66
}
67
}
68
#endif
Generated by
1.17.0