-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvedirectacdccharger.h
135 lines (113 loc) · 4.13 KB
/
csvedirectacdccharger.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
/*********************************************************************
* Copyright EoF Software Labs. All Rights Reserved.
* Copyright EoF Software Labs Authors.
* Written by B. Eschrich ([email protected])
* SPDX-License-Identifier: MIT License
**********************************************************************/
#pragma once
#include <QMap>
#include <QObject>
#include <QSerialPort>
#include <QSharedData>
#include <csvedirect.h>
class CSVeDirectAcDcCharger: public QObject
{
Q_OBJECT
public:
class TVedConfig: public QSharedData
{
public:
QString m_portName = "";
QSerialPort::BaudRate m_baudRate = QSerialPort::BaudRate::Baud19200;
QSerialPort::DataBits m_dataBits = QSerialPort::DataBits::Data8;
QSerialPort::StopBits m_stopBits = QSerialPort::StopBits::OneStop;
QSerialPort::Parity m_parity = QSerialPort::Parity::NoParity;
QSerialPort::FlowControl m_flow = QSerialPort::FlowControl::NoFlowControl;
bool m_enabled = false;
explicit TVedConfig()
: QSharedData()
{
}
TVedConfig(const TVedConfig& other)
: QSharedData()
{
if (&other == this) {
return;
}
ref = other.ref;
m_portName = other.m_portName;
m_baudRate = other.m_baudRate;
m_dataBits = other.m_dataBits;
m_stopBits = other.m_stopBits;
m_parity = other.m_parity;
m_flow = other.m_flow;
}
inline const TVedConfig& operator=(const TVedConfig& other)
{
if (&other == this) {
return (*this);
}
m_portName = other.m_portName;
m_baudRate = other.m_baudRate;
m_dataBits = other.m_dataBits;
m_stopBits = other.m_stopBits;
m_parity = other.m_parity;
m_flow = other.m_flow;
return (*this);
}
};
typedef struct {
uint m_counter;
} TStateData;
explicit CSVeDirectAcDcCharger(QObject* parent = nullptr);
~CSVeDirectAcDcCharger();
bool startVEDirect();
void stopVEDirect();
void setPowerSupply();
void setBatteryCharger();
void sendGetRegister(quint16 regid);
void sendSetRegister(quint16 regid, const QString& value);
void sendSetRegister(quint16 regid, quint8 value);
void sendSetRegister(quint16 regid, quint16 value);
void sendSetRegister(quint16 regid, quint32 value);
void sendPing();
const TVedConfig& configOut() const;
const TVedConfig& configIn() const;
const QMap<quint16, QPair<float, QVariant>>& values() const;
void setConfigOut(const CSVeDirectAcDcCharger::TVedConfig& newConfigOut);
void setConfigIn(const CSVeDirectAcDcCharger::TVedConfig& newConfigIn);
signals:
void dataChanged(uint regid, const QPair<float, QVariant>&);
protected:
bool open();
void close();
bool isOpen() const;
private slots:
void onVedEchoInbound(const char c);
private:
QSerialPort m_portCharger;
TVedConfig m_configCharger;
QSerialPort m_portCerbo;
TVedConfig m_configCerbo;
CSVeParser m_parserCharger;
CSVeParser m_parserCerbo;
QMap<quint16, QPair<float, QVariant>> m_values;
TStateData m_stateData;
QList<CSVEDirect::ved_t> m_queue;
private:
inline void setupDefaults();
inline void connectEvents();
inline bool openInputPort();
inline bool openOutputPort();
inline void restartPorts();
inline void setRegister(quint16 regid, float scale, const QVariant& value);
inline void veHandleInput(CSVeParser* parser, QSerialPort* input, QSerialPort* output);
inline void veChargerSetTextField(const QString& field, const QByteArray& value);
inline void veSendCommandQueue();
inline void veSendToCharger(CSVEDirect::ved_t* ve_out);
inline void veSendToCerboGx(CSVEDirect::ved_t* ve_out);
inline void veSendFrameTo(CSVEDirect::ved_t* ved, QSerialPort* port);
inline bool veDoSetData(const CSVeParser::TVeHexFrame& frame);
inline bool veUpdateData(const CSVeParser::TVeHexFrame& frame);
};
Q_DECLARE_METATYPE(CSVeDirectAcDcCharger::TVedConfig)