forked from cschleifenbaum/qleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleafchademoport.cpp
More file actions
124 lines (104 loc) · 7.57 KB
/
leafchademoport.cpp
File metadata and controls
124 lines (104 loc) · 7.57 KB
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
#include "leafchademoport.h"
#include <QDebug>
#include <QTimer>
#include "openinverter/params.h"
LeafChademoPort::LeafChademoPort(QCanBusDevice* canBusDevice, quint32 frameId, QObject* parent)
: CanBusNode(canBusDevice, 0, frameId, parent)
{
qDebug() << "Adding Leaf Chademo port";
m_fields[0x100] = CanMessageUtils::parseFields(QStringLiteral("SG_ MaximumBatteryVoltage : 39|16@0+ (1,0) [0|600] \"V\" Vector__XXX\n"
"SG_ ConstantOfChargingRateIndication : 48|8@1+ (1,0) [0|100] \"%\" Vector__XXX\n"
"SG_ MinimumChargeCurrent : 0|8@1+ (1,0) [0|255] \"A\" Vector__XXX"));
m_fields[0x101] = CanMessageUtils::parseFields(QStringLiteral("SG_ MaxChargingTime10sBit : 8|8@1+ (10,0) [0|2540] \"seconds\" Vector__XXX\n"
"SG_ MaxChargingTime1minBit : 16|8@1+ (1,0) [0|255] \"minutes\" Vector__XXX\n"
"SG_ EstimatedChargingTime : 24|8@1+ (1,0) [0|254] \"minutes\" Vector__XXX\n"
"SG_ RatedBatteryCapacity : 47|16@0+ (0.11,0) [0|100] \"kWh\" Vector__XXX"));
m_fields[0x102] = CanMessageUtils::parseFields(QStringLiteral("SG_ ControlProtocolNumberEV : 0|8@1+ (1,0) [0|255] \"-\" Vector__XXX\n"
"SG_ TargetBatteryVoltage : 15|16@0+ (1,0) [0|600] \"V\" Vector__XXX\n"
"SG_ ChargingCurrentRequest : 24|8@1+ (1,0) [0|255] \"A\" Vector__XXX\n"
"SG_ FaultBatteryVoltageDeviation : 36|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultHighBatteryTemperature : 35|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultBatteryCurrentDeviation : 34|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultBatteryUndervoltage : 33|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultBatteryOvervoltage : 32|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusNormalStopRequest : 44|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusVehicle : 43|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusChargingSystem : 42|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusVehicleShifterPosition : 41|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusVehicleCharging : 40|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ ChargingRate : 48|8@1+ (1,0) [0|100] \"%\" Vector__XXX"));
m_fields[0x108] = CanMessageUtils::parseFields(QStringLiteral("SG_ EVContactorWeldingDetection : 0|8@1+ (1,0) [0|1] "" Vector__XXX\n"
"SG_ AvailableOutputVoltage : 15|16@0+ (1,0) [0|600] \"V\" Vector__XXX\n"
"SG_ AvailableOutputCurrent : 24|8@1+ (1,0) [0|255] \"A\" Vector__XXX\n"
"SG_ ThresholdVoltage : 39|16@0+ (1,0) [0|600] \"V\" Vector__XXX"));
m_fields[0x109] = CanMessageUtils::parseFields(QStringLiteral("SG_ ControlProtocolNumberQC : 0|8@1+ (1,0) [0|255] \"-\" Vector__XXX\n"
"SG_ OutputVoltage : 15|16@0+ (1,0) [0|600] \"V\" Vector__XXX\n"
"SG_ OutputCurrent : 24|8@1+ (1,0) [0|255] \"A\" Vector__XXX\n"
"SG_ StatusChargerStopControl : 45|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultChargingSystemMalfunction : 44|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultBatteryIncompatibility : 43|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusVehicleConnectorLock : 42|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ FaultStationMalfunction : 41|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ StatusStation : 40|1@1+ (1,0) [0|1] \"status\" Vector__XXX\n"
"SG_ RemainingChargingTime10sBit : 48|8@1+ (10,0) [0|2540] \"seconds\" Vector__XXX\n"
"SG_ RemainingChargingTime1minBit : 56|8@1+ (1,0) [0|255] \"minutes\" Vector__XXX"));
QTimer* t = new QTimer(this);
connect(t, &QTimer::timeout, this, &LeafChademoPort::prepareAndSendFrame);
t->start(100);
}
LeafChademoPort::~LeafChademoPort()
{
Param::SetInt(Param::CHAdeMO_Ireq, 0);
}
void LeafChademoPort::receiveFrame(quint32 frameId, const QByteArray& data)
{
if (frameId == 0x100)
{
m_thresholdVoltage = CanMessageUtils::readField(data, m_fields[0x100]["MaximumBatteryVoltage"]);
}
else if (frameId == 0x102)
{
m_chargingCurrentRequest = CanMessageUtils::readField(data, m_fields[0x102]["ChargingCurrentRequest"]);
Param::SetInt(Param::CHAdeMO_Ireq, m_chargingCurrentRequest);
}
}
void LeafChademoPort::prepareAndSendFrame()
{
if (!Param::GetBool(Param::PlugDet)) // no CCS plug - this is a real Chademo charge - keep our fingers away
return;
int ccs_state = Param::GetInt(Param::CCS_State);
bool statusChargerStopControl = ccs_state > 6; // stop if true
bool statusStation = true; // Charging
bool statusVehicleConnectorLock = ccs_state < 8; // Locked if true
quint16 availableOutputVoltage = 500;
quint8 availableOutputCurrent = 125;
quint16 batteryVoltage = Param::GetInt(Param::udc);
if (batteryVoltage != 0)
m_batteryVoltage = batteryVoltage;
quint16 outputVoltage = statusVehicleConnectorLock ? m_batteryVoltage : 0;
quint8 outputCurrent = m_chargingCurrentRequest;
QByteArray data(8, '\0');
data[0] = 1; // EVContactorWeldingDetection: Supporting vehicle welding detection
data[1] = availableOutputVoltage & 0xff;
data[2] = availableOutputVoltage >> 8;
data[3] = availableOutputCurrent;
data[4] = m_thresholdVoltage & 0xff;
data[5] = m_thresholdVoltage >> 8;
sendFrame(0x108, data);
data = QByteArray(8, '\0');
data[0] = 2; // ControlProtocolNumberQC
data[1] = outputVoltage & 0xff;
data[2] = outputVoltage >> 8;
data[3] = outputCurrent;
data[4] = 0;
data[5] = (statusChargerStopControl ? 0x20 : 0) |
(statusStation ? 0x01 : 0) |
(statusVehicleConnectorLock ? 4 : 0);
data[6] = 0; // remaining charge time 10s
data[7] = 60; // remaining charge time min
sendFrame(0x109, data);
}
QVector<quint32> LeafChademoPort::receivingFrameIds() const
{
return { 0x100, 0x101, 0x102, 0x200 };
}