-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsvedirectacdccharger.cpp
1564 lines (1493 loc) · 53.6 KB
/
csvedirectacdccharger.cpp
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************
* Copyright EoF Software Labs. All Rights Reserved.
* Copyright EoF Software Labs Authors.
* Written by B. Eschrich ([email protected])
* SPDX-License-Identifier: MIT License
**********************************************************************/
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include <QTimer>
#include <csvedirectacdccharger.h>
Q_DECLARE_METATYPE(QSerialPort::SerialPortError)
Q_DECLARE_METATYPE(QSerialPort::StopBits)
Q_DECLARE_METATYPE(QSerialPort::DataBits)
Q_DECLARE_METATYPE(QSerialPort::BaudRate)
Q_DECLARE_METATYPE(QSerialPort::FlowControl)
Q_DECLARE_METATYPE(QSerialPort::Parity)
#ifdef Q_OS_MACOS
#define PORT_DEV_CHR "cu.usbserial-B001EN2X"
#define PORT_DEV_CGX "cu.usbserial-B002XVOA"
#else
#define PORT_DEV_CHR "ttysVECHR"
#define PORT_DEV_CGX "ttysVECGX"
#endif
CSVeDirectAcDcCharger::CSVeDirectAcDcCharger(QObject* parent)
: QObject {parent}
, m_portCharger(this)
, m_configCharger()
, m_portCerbo(this)
, m_configCerbo()
, m_parserCharger(this)
, m_stateData()
, m_queue()
{
setupDefaults();
connectEvents();
}
CSVeDirectAcDcCharger::~CSVeDirectAcDcCharger()
{
}
bool CSVeDirectAcDcCharger::startVEDirect()
{
/* ..................................................
* Serial Port Cerbo GX MK2
* .................................................. */
connect(&m_portCerbo, &QSerialPort::errorOccurred, this, [this](QSerialPort::SerialPortError error) {
if (error != QSerialPort::NoError) {
qDebug() << "UART-Cerbo: errorOccurred():" << error;
if (m_portCerbo.isOpen()) {
m_portCerbo.close();
}
}
});
connect(&m_portCerbo, &QSerialPort::dataTerminalReadyChanged, this, [](bool set) {
qDebug() << "UART-Cerbo: dataTerminalReadyChanged" << set;
});
connect(&m_portCerbo, &QSerialPort::requestToSendChanged, this, [](bool set) {
qDebug() << "UART-Cerbo: requestToSendChanged" << set;
});
connect(&m_portCerbo, &QSerialPort::aboutToClose, this, [this]() {
qDebug() << "UART-Cerbo: aboutToClose" << sender();
});
connect(&m_portCerbo, &QSerialPort::readyRead, this, [this]() {
/* Cerbo GX -> to -> CarIOS, Blue Smart Charger */
veHandleInput(&m_parserCerbo, &m_portCerbo, &m_portCharger);
});
if (!openOutputPort()) {
disconnect(&m_portCerbo);
return false;
}
/* ..................................................
* Serial Port AC/DC Blue Smart Charer I/O
* .................................................. */
connect(&m_portCharger, &QSerialPort::errorOccurred, this, [this](QSerialPort::SerialPortError error) {
if (error != QSerialPort::NoError) {
qDebug() << "UART-Charger: errorOccurred():" << error;
if (m_portCerbo.isOpen()) {
m_portCerbo.close();
}
}
});
connect(&m_portCharger, &QSerialPort::dataTerminalReadyChanged, this, [](bool set) {
qDebug() << "UART-Charger: dataTerminalReadyChanged" << set;
});
connect(&m_portCharger, &QSerialPort::requestToSendChanged, this, [](bool set) {
qDebug() << "UART-Charger: requestToSendChanged" << set;
});
connect(&m_portCharger, &QSerialPort::aboutToClose, this, [this]() {
qDebug() << "UART-Charger: aboutToClose" << sender();
});
connect(&m_portCharger, &QSerialPort::readyRead, this, [this]() {
/* Charger -> to -> CarIOS, Cerbo GX */
veHandleInput(&m_parserCharger, &m_portCharger, &m_portCerbo);
});
if (!openInputPort()) {
disconnect(&m_portCharger);
disconnect(&m_portCerbo);
m_portCerbo.close();
return false;
}
return true;
}
void CSVeDirectAcDcCharger::stopVEDirect()
{
disconnect(&m_portCharger);
disconnect(&m_portCerbo);
close();
}
void CSVeDirectAcDcCharger::setPowerSupply()
{
sendSetRegister(0x0206, (quint8) 1);
}
void CSVeDirectAcDcCharger::setBatteryCharger()
{
sendSetRegister(0x0206, (quint8) 0);
}
void CSVeDirectAcDcCharger::sendGetRegister(quint16 regid)
{
CSVEDirect::ved_t ved = {};
CSVEDirect::setCommand(&ved, VED_CMD_GET);
CSVEDirect::setId(&ved, regid);
CSVEDirect::setFlags(&ved, 0);
m_queue.append(ved);
}
void CSVeDirectAcDcCharger::sendSetRegister(quint16 regid, const QString& value)
{
CSVEDirect::ved_t ved = {};
CSVEDirect::setCommand(&ved, VED_CMD_SET);
CSVEDirect::setId(&ved, regid);
CSVEDirect::setFlags(&ved, 0);
for (int i = 0; i < value.length(); i++) {
CSVEDirect::addU8(&ved, (quint8) value.at(i).cell());
}
m_queue.append(ved);
}
void CSVeDirectAcDcCharger::sendSetRegister(quint16 regid, quint8 value)
{
CSVEDirect::ved_t ved = {};
CSVEDirect::setCommand(&ved, VED_CMD_SET);
CSVEDirect::setId(&ved, regid);
CSVEDirect::setFlags(&ved, 0);
CSVEDirect::setU8(&ved, value);
m_queue.append(ved);
}
void CSVeDirectAcDcCharger::sendSetRegister(quint16 regid, quint16 value)
{
CSVEDirect::ved_t ved = {};
CSVEDirect::setCommand(&ved, VED_CMD_SET);
CSVEDirect::setId(&ved, regid);
CSVEDirect::setFlags(&ved, 0);
CSVEDirect::setU16(&ved, value);
m_queue.append(ved);
}
void CSVeDirectAcDcCharger::sendSetRegister(quint16 regid, quint32 value)
{
CSVEDirect::ved_t ved = {};
CSVEDirect::setCommand(&ved, VED_CMD_SET);
CSVEDirect::setId(&ved, regid);
CSVEDirect::setFlags(&ved, 0);
CSVEDirect::setU32(&ved, value);
m_queue.append(ved);
}
void CSVeDirectAcDcCharger::sendPing()
{
CSVEDirect::ved_t ved;
CSVEDirect::setCommand(&ved, VED_CMD_PING);
m_queue.append(ved);
}
bool CSVeDirectAcDcCharger::open()
{
return (openOutputPort() && openInputPort());
}
void CSVeDirectAcDcCharger::close()
{
if (m_portCharger.isOpen()) {
m_portCharger.flush();
m_portCharger.close();
}
if (m_portCerbo.isOpen()) {
m_portCerbo.flush();
m_portCerbo.close();
}
}
bool CSVeDirectAcDcCharger::isOpen() const
{
return m_portCharger.isOpen() /*&& m_portCerbo.isOpen()*/;
}
const CSVeDirectAcDcCharger::TVedConfig& CSVeDirectAcDcCharger::configIn() const
{
return m_configCharger;
}
void CSVeDirectAcDcCharger::setConfigIn(const TVedConfig& config)
{
m_configCharger = config;
if (m_portCharger.isOpen()) {
m_portCharger.close();
}
}
const CSVeDirectAcDcCharger::TVedConfig& CSVeDirectAcDcCharger::configOut() const
{
return m_configCerbo;
}
void CSVeDirectAcDcCharger::setConfigOut(const TVedConfig& config)
{
m_configCerbo = config;
if (m_portCerbo.isOpen()) {
m_portCerbo.close();
}
}
void CSVeDirectAcDcCharger::onVedEchoInbound(const char c)
{
if (!m_portCerbo.isOpen()) {
if (m_portCharger.isOpen()) {
m_portCharger.write(&c, 1);
m_portCharger.waitForBytesWritten();
}
}
}
const QMap<quint16, QPair<float, QVariant>>& CSVeDirectAcDcCharger::values() const
{
return m_values;
}
inline void CSVeDirectAcDcCharger::setupDefaults()
{
/* AC/DC Charger -> CarIOS
* Mac OSX /dev/cu.usbserial-B001EN2X */
m_configCharger.m_portName = PORT_DEV_CHR; // "ttyS4";
m_configCharger.m_baudRate = QSerialPort::Baud19200;
m_configCharger.m_dataBits = QSerialPort::Data8;
m_configCharger.m_stopBits = QSerialPort::OneStop;
m_configCharger.m_parity = QSerialPort::NoParity;
m_configCharger.m_flow = QSerialPort::NoFlowControl;
/* CarIOS -> Cerbo GX
* Mac OSX /dev/cu.usbserial-B002XVOA */
m_configCerbo.m_portName = PORT_DEV_CGX; //"ttyUSB5";
m_configCerbo.m_baudRate = QSerialPort::Baud19200;
m_configCerbo.m_dataBits = QSerialPort::Data8;
m_configCerbo.m_stopBits = QSerialPort::OneStop;
m_configCerbo.m_parity = QSerialPort::NoParity;
m_configCerbo.m_flow = QSerialPort::NoFlowControl;
}
inline void CSVeDirectAcDcCharger::connectEvents()
{
/* ..................................................
* Blue Smart Charger Protocol to CarIOS
* .................................................. */
// connect(&m_parserCharger, &CSVeParser::echoInbound, this, &CSVeDirectAcDcCharger::onVedEchoInbound);
connect(&m_parserCharger, &CSVeParser::errorOccured, this, [](const QByteArray& messge) {
qCritical() << "[VE.CHR]" << messge;
});
connect(&m_parserCharger, &CSVeParser::vedTextField, this, [this](const QString& f, const QByteArray& v) {
veChargerSetTextField(f, v);
});
connect(&m_parserCharger, &CSVeParser::vedHexFrame, this, [this](const CSVeParser::TVeHexFrame& frame) {
switch (frame.command) {
case VED_CMD_PING_RESPONSE: {
return;
}
/* setting value messages */
case VED_CMD_GET: {
if (veUpdateData(frame)) {
return;
}
break;
}
/* update setting messages */
case VED_CMD_SET: {
if (veDoSetData(frame)) {
return;
}
break;
}
/* broadcast value messages */
case VED_CMD_ASYNC: {
if (veUpdateData(frame)) {
return;
}
break;
}
}
QStringList finfo;
if (frame.flags & VED_FLAG_NOT_SUPPORTED) {
finfo << "not supported";
}
if (frame.flags & VED_FLAG_PARAM_ERROR) {
finfo << "parameter error";
}
if (frame.flags & VED_FLAG_UNK_ID) {
finfo << "unknown register";
}
qWarning( //
"[VE.CHR] UN-HANDLED: cmd=%2d [%s] id=%5d (0x%04X) Flags=0x%02X [%s] Size=%d %s",
frame.command,
m_parserCharger.toCmdStr(frame.command).constData(),
frame.regid,
frame.regid,
frame.flags,
finfo.join(";").toUtf8().constData(),
frame.ve_in.size,
frame.source.constData());
});
/* ..................................................
* Cerbo GX Protocol to CarIOS
* .................................................. */
// connect(&m_parserCerbo, &CSVeParser::echoInbound, this, &CSVeDirectAcDcCharger::onVedEchoInbound);
connect(&m_parserCerbo, &CSVeParser::errorOccured, this, [](const QByteArray& messge) {
qCritical() << "[VE.CGX]" << messge;
});
connect(&m_parserCerbo, &CSVeParser::vedTextField, this, [](const QString& f, const QByteArray& v) {
qDebug() << "[VE.CGX] RECV>" << f.constData() << "=>" << v.constData();
});
connect(&m_parserCerbo, &CSVeParser::vedHexFrame, this, [this](const CSVeParser::TVeHexFrame& frame) {
qDebug( //
"[VE.CGX] RECV> cmd=%2d [%s] id=%5d (0x%04X) Flags=%04d (0x%04X) %s",
frame.command,
m_parserCerbo.toCmdStr(frame.command).constData(),
frame.regid,
frame.regid,
frame.flags,
frame.flags,
frame.source.constData());
});
}
inline bool CSVeDirectAcDcCharger::openInputPort()
{
if (m_portCharger.isOpen()) {
return true;
}
m_values = {};
m_portCharger.setPortName(m_configCharger.m_portName);
m_portCharger.setBaudRate(m_configCharger.m_baudRate);
m_portCharger.setDataBits(m_configCharger.m_dataBits);
m_portCharger.setStopBits(m_configCharger.m_stopBits);
m_portCharger.setFlowControl(m_configCharger.m_flow);
m_portCharger.setParity(m_configCharger.m_parity);
if (!m_portCharger.open(QSerialPort::ReadWrite)) {
return false;
}
/* cleanup */
m_portCharger.flush();
return true;
}
inline bool CSVeDirectAcDcCharger::openOutputPort()
{
#if 0
if (m_portCerbo.isOpen()) {
return true;
}
m_portCerbo.setPortName(m_configCerbo.m_portName);
m_portCerbo.setBaudRate(m_configCerbo.m_baudRate);
m_portCerbo.setDataBits(m_configCerbo.m_dataBits);
m_portCerbo.setStopBits(m_configCerbo.m_stopBits);
m_portCerbo.setFlowControl(m_configCerbo.m_flow);
m_portCerbo.setParity(m_configCerbo.m_parity);
if (!m_portCerbo.open(QSerialPort::ReadWrite)) {
return false;
}
m_portCerbo.flush();
#endif
return true;
}
inline void CSVeDirectAcDcCharger::restartPorts()
{
QTimer::singleShot(2500, this, [this]() {
if (!openOutputPort()) {
qCritical() << "[VE.Direct] Failed to restart VE.Direct output port.";
close();
return;
}
if (!openInputPort()) {
qCritical() << "[VE.Direct] Failed to restart VE.Direct input port.";
close();
return;
}
});
}
inline void CSVeDirectAcDcCharger::setRegister(quint16 regid, float scale, const QVariant& value)
{
if (!m_values.contains(regid) || !m_values[regid].second.isValid() || m_values[regid].second != value) {
qDebug(
"[VE.CHR] SAVE regid: 0x%04X scale: %f value: %s", //
regid,
scale,
value.toString().toLocal8Bit().constData());
m_values[regid] = QPair<float, QVariant>(scale, value);
emit dataChanged(regid, m_values[regid]);
}
}
inline void CSVeDirectAcDcCharger::veHandleInput(CSVeParser* parser, QSerialPort* input, QSerialPort* output)
{
char c;
do {
if (input->read(&c, 1) < 1) {
break;
}
parser->handle(c);
if (output->isOpen()) {
output->write(&c, 1);
output->flush();
}
} while (!input->atEnd());
}
inline void CSVeDirectAcDcCharger::veChargerSetTextField(const QString& field, const QByteArray& value)
{
if (field.isEmpty()) {
return;
}
// qDebug() << "[VE.CHR] RECV> " << field << "value:" << value;
/* product id -> 0xA330 */
if (field == "PID") {
setRegister(0x00001, value.count(), value);
m_stateData.m_counter++;
}
/* firmware release 24bit -> 0342FF */
else if (field == "FWE") {
setRegister(0x00002, value.count(), value);
m_stateData.m_counter++;
}
/* serial number -> HQ2247PTFUR */
else if (field == "SER#") {
setRegister(0x00003, value.count(), value);
m_stateData.m_counter++;
}
/* voltage -> 12850mV -> 12.850V */
else if (field == "V") {
setRegister(0xED8D, 0.001f, value.toDouble());
m_stateData.m_counter++;
}
/* current 0.400A */
else if (field == "I") {
setRegister(0xED8F, 0.001f, value.toDouble());
m_stateData.m_counter++;
}
/* time? */
else if (field == "T") {
if (value.toUInt() != 0) {
setRegister(0x2009, 0.01f, value.toUInt());
}
m_stateData.m_counter++;
}
/* error code */
else if (field == "ERR") {
if (value.toInt() != 0) {
setRegister(0x2009, 1, value.toInt());
}
m_stateData.m_counter++;
}
/* work mode status */
else if (field == "CS") {
if (value.toInt() == 11) {
setRegister(0x0206, 1, 1);
}
else {
setRegister(0x0206, 1, 0);
}
setRegister(0x0201, 1, value.toInt());
m_stateData.m_counter++;
}
/* should be the last one */
else if (field == "HC#") {
setRegister(0x0004, value.count(), value);
m_stateData.m_counter++;
}
if (m_stateData.m_counter >= 9) {
m_stateData.m_counter = 0;
veSendCommandQueue();
}
}
inline void CSVeDirectAcDcCharger::veSendFrameTo(CSVEDirect::ved_t* ved, QSerialPort* port)
{
quint16 regid;
quint8 cmd, flags;
/* get before encode */
cmd = CSVEDirect::getCommand(ved);
regid = CSVEDirect::getId(ved);
flags =
(cmd == VED_CMD_GET || cmd == VED_CMD_SET || cmd == VED_CMD_ASYNC //
? CSVEDirect::getFlags(ved)
: 0);
/* encode to VE.HEX frame and send */
if (CSVEDirect::enframe(ved)) {
QByteArray outbuf((char*) ved->data, ved->size);
QByteArray oport = port->portName().toLocal8Bit();
if (ved->size) {
qDebug( //
"[VE.%s] SEND> cmd=%d [%s] id=0x%04X Flags=0x%02X %s",
oport.constData(),
cmd,
m_parserCharger.toCmdStr(cmd).constData(),
regid,
flags,
outbuf.left(outbuf.length() - 1).constData());
}
port->flush();
port->write("\n" + outbuf);
port->waitForBytesWritten();
}
}
inline void CSVeDirectAcDcCharger::veSendToCerboGx(CSVEDirect::ved_t* ved)
{
veSendFrameTo(ved, &m_portCerbo);
}
inline void CSVeDirectAcDcCharger::veSendToCharger(CSVEDirect::ved_t* ved)
{
veSendFrameTo(ved, &m_portCharger);
}
inline void CSVeDirectAcDcCharger::veSendCommandQueue()
{
if (m_queue.isEmpty()) {
return;
}
CSVEDirect::ved_t ved = m_queue.takeFirst();
veSendToCharger(&ved);
}
/* Cerbo GX to Blue Smart Charger */
inline bool CSVeDirectAcDcCharger::veDoSetData(const CSVeParser::TVeHexFrame& frame)
{
qDebug(
"[VE.CHR] SET regid: 0x%04X flags: 0x%02X size: %d", //
frame.regid,
frame.flags,
frame.ve_in.size);
if (frame.ve_in.size) {
veUpdateData(frame);
}
return true;
}
/* Blue Smart Charger Input -> CarIOS */
inline bool CSVeDirectAcDcCharger::veUpdateData(const CSVeParser::TVeHexFrame& frame)
{
CSVeParser::TVeHexFrame hf = frame;
CSVEDirect::ved_t* ved_in = &hf.ve_in;
double value = 0.0f;
float scale = 1.0f;
/* invalid frame, at least one byte data payload required */
if (ved_in->size < 5) {
qWarning() << "[VE.CHR] Data size to less. Size:" //
<< ved_in->size << "Expected: >= 5";
return false;
}
switch (frame.regid) {
/* VE_REG_GROUP_ID */
case 0x0104: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* VE_REG_IDENTIFY or VE_REG_CAN_SELECT */
case 0x010E: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* VE_REG_CHR_NUMBER_OUTPUTS */
case 0xEDDE: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* VE_REG_CAPABILITIES1 */
case 0x0140: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* VE_REG_CAPABILITIES4 */
case 0x0143: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* VE_REG_AC_IN_1_CURRENT_LIMIT */
case 0x0210: {
value = CSVEDirect::getU16(ved_in);
scale = 1 / 100;
break;
}
/* VE_REG_CHR_MIN_CURRENT */
case 0xEDC8: {
value = CSVEDirect::getU16(ved_in);
scale = 0.1f;
break;
}
/* VE_REG_LINK_NETWORK_STATUS */
case 0x200F: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* VE_REG_LINK_CHARGE_CURRENT_LIMIT */
case 0x2015: {
value = CSVEDirect::getU16(ved_in);
scale = 0.001f;
break;
}
/* VE_REG_LINK_VSENSE */
case 0x2002: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* VE_REG_LINK_TSENSE */
case 0x2003: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* VE_REG_LINK_BATTERY_CURRENT */
case 0x200A: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* VE_REG_DESCRIPTION1 */
case 0x010C: {
QByteArray buffer;
for (int i = 4; i < ved_in->size && ved_in->data[i] != 0; i++) {
buffer.append((char) ved_in->data[i]);
}
qDebug(
"[VE.CHR] SAVE regid: 0x%04X value: %s", //
frame.regid,
buffer.constData());
setRegister(frame.regid, scale, buffer);
return true;
}
/* VE_REG_HISTORY_CYCLE_SEQUENCE_NUMBER
*
* VE_REG_HISTORY_CYCLE00 VE_REG_HISTORY_CYCLE01
* VE_REG_HISTORY_CYCLE02 VE_REG_HISTORY_CYCLE03
* VE_REG_HISTORY_CYCLE04 VE_REG_HISTORY_CYCLE05
* VE_REG_HISTORY_CYCLE06 VE_REG_HISTORY_CYCLE07
* VE_REG_HISTORY_CYCLE08 VE_REG_HISTORY_CYCLE09
* VE_REG_HISTORY_CYCLE10 VE_REG_HISTORY_CYCLE11
* VE_REG_HISTORY_CYCLE12 VE_REG_HISTORY_CYCLE13
* VE_REG_HISTORY_CYCLE14 VE_REG_HISTORY_CYCLE15
* VE_REG_HISTORY_CYCLE16 VE_REG_HISTORY_CYCLE17
* VE_REG_HISTORY_CYCLE18 VE_REG_HISTORY_CYCLE19
* VE_REG_HISTORY_CYCLE20 VE_REG_HISTORY_CYCLE21
* VE_REG_HISTORY_CYCLE22 VE_REG_HISTORY_CYCLE23
* VE_REG_HISTORY_CYCLE24 VE_REG_HISTORY_CYCLE25
* VE_REG_HISTORY_CYCLE26 VE_REG_HISTORY_CYCLE27
* VE_REG_HISTORY_CYCLE28 VE_REG_HISTORY_CYCLE29
* VE_REG_HISTORY_CYCLE30 VE_REG_HISTORY_CYCLE31
* VE_REG_HISTORY_CYCLE32 VE_REG_HISTORY_CYCLE33
* VE_REG_HISTORY_CYCLE34 VE_REG_HISTORY_CYCLE35
* VE_REG_HISTORY_CYCLE36 VE_REG_HISTORY_CYCLE37
* VE_REG_HISTORY_CYCLE38 VE_REG_HISTORY_CYCLE39
* VE_REG_HISTORY_CYCLE40
*
* Sequence number for the cycle "history" which will
* change in case of a new cycle. This can be used as a
* trigger to fetch the entire cycle history.
* un32
*/
case 0x1099: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* The number of charge cycle history records.
* un8 */
case 0x106F: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* VE_REG_UPTIME un32
* uptime since boot in seconds */
case 0x0120: {
return true;
}
/* Device state un8 read-only
* 0=off
* 1=low power mode
* 2=fault
* 3=bulk
* 4=absorption
* 5=float
* 6=storage
* 7=equalize
* 8=passthru
* 9=inverting
* 10=assisting
* 11=psu (Spannungsversorgung)
* 0xFC=hub1
* 0xff=not available
*
* state 11 psu mode is NOT in the NMEA2000 specification. It is a victron
* specific value. New states should be added from the top instead of from
* the bottom. NMEA2000 equivalent: DD342 Converter Operating State as found
* in PGN 127750 (v2. 000) VE. Text equivalent: CS
*
* value=0... Ladegeraet
* value=11 Spannungsversorgung
*/
case 0x0201: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Device Function
* value=0 Charger
* value=1 Spannungsversorgung
*/
case 0x0206: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Device off reason 2
* bits[0] = "VE_REG_DEVICE_OFF_2_NO_INPUT_POWER"
* 0 = "No" 1 = "Yes" no/low mains/panel/battery power
* bits[1] = "VE_REG_DEVICE_OFF_2_HARD_POWER_SWITCH"
* 0 = "No" 1 = "Yes" physical switch
* bits[2] = "VE_REG_DEVICE_OFF_2_SOFT_POWER_SWITCH"
* 0 = "No" 1 = "Yes" remote via N device_mode and/or push-button
* bits[3] = "VE_REG_DEVICE_OFF_2_REMOTE_INPUT"
* 1 = "No" 1 = "Yes" remote input connector
* bits[4] = "VE_REG_DEVICE_OFF_2_INTERNAL_REASON"
* 0 = "No" 1 = "Yes condition" preventing start-up
* bits[5] = "VE_REG_DEVICE_OFF_2_PAYGO"
* 0 = "No" 1 = "Yes" N need token for operation
* bits[6] = "VE_REG_DEVICE_OFF_2_BMS"
* 0 = "No" 1 = "Yes ?" allow-to-charge/allow-to-discharge signals from BMS
* bits[7] = "VE_REG_DEVICE_OFF_2_ENGINE_SD_DETECTION"
* 0 = "No" 1 = "Yes" engine shutdown detected through low input voltage
* bits[8] = "VE_REG_DEVICE_OFF_2_ANALYZING_INPUT_VOLTAGE"
* 0 = "No" 1 = "Yes" converter off to check input voltage without cable losses
* bits[23] = "reserved" 0x000000 = reserved
* :A0D200000001E */
case 0x0207: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* Charger "link" network info (this reports the
* overall network activity)
*/
case 0x200D: {
value = CSVEDirect::getU16(ved_in);
break;
}
/* Charger link equalisation pending?
* VE_REG_LINK_EQUALISATION_PENDING un8
*/
case 0x2018: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Blue Power Charger - low current mode
* un8 "0:0ff" "1:on" "2:night"
*/
case 0xE001: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Blue Power Charger - low current mode time left
* night mode 8 hours w/o fan with 15A current
* counter 28800 seconds to 0 seconds
*/
case 0xE002: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* Date/time of last change of the "settings"
* in unix-timestamp format
*/
case 0xEC41: {
value = CSVEDirect::getU32(ved_in);
break;
}
/* Battery Re-bulk Offset Voltage & Level un16
* "[0.01V]" 0xFFFF = Not Available}E Set VE_REG_BAT_TYPE to 0xFF to
* use and read the user-defined setting.
* write: always writes to the user-defined setting in non-volatile memory.
* Important for mppt chargers:
* always set the @ref VE_REG_BAT_VOLTAGE register > to the correct system
* voltage before writing to this register.
*/
case 0xED2E: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Charger specific parameters
* actual charge voltage channel 1
* sn16 voltage [0.01V] read-only
*
* output voltage - same is 0xEDD5 */
case 0xED8D: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Charger specific parameters
* additional charger state info
* un8 "state" read-only
* see VE_REG_CHR_CUSTOM_STATE section for possible values
*/
case 0xEDD4: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Charger specific parameters - actual charge voltage
* un16 voltage [0.01V] read-only
* HEX protocol compat. data present in regular NMEA pgn
*
* output voltage - same is 0xED8D */
case 0xEDD5: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* VE_REG_CHR_TEMPERATURE
* Charger specific parameters -
* sn16 temperature [0.01 degrees C] read-only
* scale / 100
*
* value=3060 -> 30.6°C
*/
case 0xEDDB: {
value = (float) CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Stop at low temperature
* Abschalten bei Temperatur niedrig 5°C
* scale / 100
* value=500
*/
case 0xEDE0: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Charger battery parameters - Re-bulk Current Level
* (float/stroage -> bulk transition)
* un16 current [0.1A]
*/
case 0xEDE1: {
value = CSVEDirect::getU16(ved_in);
scale = 0.1f;
break;
}
/* Battery Re-bulk Voltage Level
* un16 [0.01V]
* 0xFFFF = Not Available
* Set VE_REG_BAT_TYPE to 0xFF to use and read the user-defined setting.
* write: always writes to the user-defined setting in non-volatile memory.
* Important for mppt chargers: always set the @ref VE_REG_BAT_VOLTAGE register
* to the correct system voltage before writing to this register.
*/
case 0xEDE2: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Battery Equalisation Time Duration
* un16 [0.01 hours]
* Set VE_REG_BAT_TYPE to 0xFF to use and read the user-defined setting.
* write: always writes to the user-defined setting in non-volatile memory.
*
* Dauer der Regenrierung hh:mm scale / 100
* value=100 value=202 -> 2:02
*/
case 0xEDE3: {
value = CSVEDirect::getU16(ved_in);
scale = 0.01f;
break;
}
/* Battery Equalisation Current Percentage
* un8 [1%]
* 0xFF = Not Available}
* Set VE_REG_BAT_TYPE to 0xFF to use and read the user-defined setting.
* write: always writes to the user-defined setting in non-volatile memory.
*
* Prozentsatz Strom regenerierung scale x1
* value=3
*/
case 0xEDE4: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Battery Equalisation Auto Stop
* un8
* 0 = No / 1 = Yes
* Set VE_REG_BAT_TYPE to 0xFF to use and read the user-defined setting.
* write: always writes to the user-defined setting in non-volatile memory.
*
* Stopp-Modus Regenerierung
* 0 = Festgelegt
* 1 = Automatisch, an Spannung
*/
case 0xEDE5: {
value = CSVEDirect::getU8(ved_in);
break;
}
/* Low-temp charge current
* un16 [0.1A]
* 0 = stop "charging"
* 0xFFFF = use maximum charger current.
* For Lithium "batteries" used below 6 degrees C
*/
case 0xEDE6: {
value = CSVEDirect::getU16(ved_in);
scale = 0.1f;
break;
}
/* Charger battery parameters - tail current
* (abs -> float transition)
* un16 current [0.1A]
*
* Schweifstrom scale x1
* value=0 -> deactivated
* value=2 -> 2A
*/
case 0xEDE7: {
value = CSVEDirect::getU16(ved_in);
scale = 0.1f;
break;
}
/* Charger battery parameters - maximum charge current
* un16 current [0.1A])
* read: the parameter as it is currently in use (set VE_REG_BAT_TYPE to
* 0xFF to use and read the user-defined setting)
* write: always writes to the user-defined setting in non-volatile memory
*
* Maximum Current A scale x10
* current => 150
* current => 300
*/
case 0xEDF0: {
value = CSVEDirect::getU16(ved_in);
scale = 0.1f;
break;
}
/* VE_REG_BAT_TYPE un8
* 0 = Normal
* 1 = Normal + Reginerierung
* 2 = Hoch
* 3 = Hoch + Regenerierung
* 4 = Li-ion
*/
case 0xEDF1: {