-
Notifications
You must be signed in to change notification settings - Fork 3
/
p18_query_general_status_list.h
131 lines (110 loc) · 5.14 KB
/
p18_query_general_status_list.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
#ifndef P18_QUERY_GENERAL_STATUS_LIST_H
#define P18_QUERY_GENERAL_STATUS_LIST_H
#include <QString>
#include <QByteArray>
#include <QtDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <icmdquery.h>
#include "crc.h"
#include "response_double.h"
#include "response_enum.h"
#include "response_longlong.h"
class P18QueryGeneralStatus : public iCmdQuery
{
private:
bool isValidFormat(QByteArray response) {
bool result=true;
if(! response.endsWith("\r"))
result=false;
if(! response.startsWith("^D106"))
result=false;
Crc crc;
if(! crc.checkResponse(response))
result=false;
return result;
}
public:
P18QueryGeneralStatus(QString devName) : iCmdQuery("GeneralStatus", devName) {
responseList.append(new ResponseDouble(devName, "grid_voltage", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "grid_frequency", 10.0, "Hz"));
responseList.append(new ResponseDouble(devName, "ac_output_voltage", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "ac_output_frequency", 10.0, "Hz"));
responseList.append(new ResponseDouble(devName, "ac_output_apparent_power", 10.0, "W", "power"));
responseList.append(new ResponseDouble(devName, "ac_output_active_power", 10.0, "W", "power"));
responseList.append(new ResponseDouble(devName, "output_load_percent", 1.0, "%"));
responseList.append(new ResponseDouble(devName, "battery_voltage", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "battery_voltage_scc", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "battery_voltage_scc2", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "battery_discharge_current", 1.0, "A"));
responseList.append(new ResponseDouble(devName, "battery_charge_current", 1.0, "A"));
responseList.append(new ResponseDouble(devName, "battery_capacity", 1.0, "%", "battery"));
responseList.append(new ResponseDouble(devName, "inverter_heatsink_temperature", 1.0, "°C", "temperature"));
responseList.append(new ResponseDouble(devName, "inverter_mppt1_temperature", 1.0, "°C", "temperature"));
responseList.append(new ResponseDouble(devName, "inverter_mppt2_temperature", 1.0, "°C", "temperature"));
responseList.append(new ResponseDouble(devName, "pv1_input_power", 1.0, "W", "power"));
responseList.append(new ResponseDouble(devName, "pv2_input_power", 1.0, "W", "power"));
responseList.append(new ResponseDouble(devName, "pv1_input_voltage", 10.0, "V"));
responseList.append(new ResponseDouble(devName, "pv2_input_voltage", 10.0, "V"));
QMap <int, QString> enumChanged;
enumChanged[0]="Nothing changed";
enumChanged[1]="Something changed";
responseList.append(new ResponseEnum(devName, "settings_changed",enumChanged ));
QMap <int, QString> enumMppt;
enumMppt[0]="abnormal";
enumMppt[1]="normal but not charged";
enumMppt[2]="charging";
responseList.append(new ResponseEnum(devName, "mppt1_charger_status",enumMppt ));
responseList.append(new ResponseEnum(devName, "mppt2_charger_status",enumMppt ));
QMap <int, QString> enumLoad;
enumLoad[0]="disconnected";
enumLoad[1]="connected";
responseList.append(new ResponseEnum(devName, "load_connection", enumLoad ));
QMap <int, QString> enumBatt;
enumBatt[0]="donothing";
enumBatt[1]="charge";
enumBatt[2]="discharge";
responseList.append(new ResponseEnum(devName, "battery_power_direction",enumBatt ));
QMap <int, QString> enumDCAC;
enumDCAC[0]="donothing";
enumDCAC[1]="AC-DC";
enumDCAC[2]="DC-AC";
responseList.append(new ResponseEnum(devName, "dc_ac_power_direction" ,enumDCAC));
QMap <int, QString> enumLine;
enumLine[0]="donothing";
enumLine[1]="input";
enumLine[2]="output";
responseList.append(new ResponseEnum(devName, "line_power_direction", enumLine ));
responseList.append(new ResposeLongLong(devName, "local_parallel_id" ,""));
}
virtual QByteArray getCmd() {
QByteArray cmd="^P005GS";
Crc crc;
crc.appendCrc(cmd);
cmd.append('\r');
qDebug() << cmd;
return(cmd);
}
virtual QByteArray resultToJson(QByteArray response) {
if(isValidFormat(response)) {
QByteArray temp = response.right(response.size() - 5);
temp.truncate(temp.size() - 3);
QList<QByteArray> elements = temp.split(',');
int i=0;
foreach(auto e, elements) {
responseList.at(i++)->setValue(e);
}
QJsonObject recordObject;
foreach (auto entry, responseList) {
recordObject.insert(entry->getJsonKey(), entry->getJsonValue());
}
QJsonDocument doc(recordObject);
return(doc.toJson());
} else {
qDebug() << "wrong Format";
return("");
}
return("");
}
};
#endif // P18_QUERY_GENERAL_STATUS_LIST_H