forked from Martin-P/OpenV2G
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_commandlineinterface.c
1656 lines (1527 loc) · 73.2 KB
/
main_commandlineinterface.c
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
/*******************************************************************
* Command line interface for OpenV2G
* Maintained in http:https://github.com/uhi22/OpenV2Gx, a fork of https://github.com/Martin-P/OpenV2G
*
********************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "EXITypes.h"
#include "appHandEXIDatatypes.h"
#include "appHandEXIDatatypesEncoder.h"
#include "appHandEXIDatatypesDecoder.h"
/* Activate support for DIN */
#include "dinEXIDatatypes.h"
#if DEPLOY_DIN_CODEC == SUPPORT_YES
#include "dinEXIDatatypesEncoder.h"
#include "dinEXIDatatypesDecoder.h"
#endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
/* Activate support for XMLDSIG */
#include "xmldsigEXIDatatypes.h"
#if DEPLOY_XMLDSIG_CODEC == SUPPORT_YES
#include "xmldsigEXIDatatypesEncoder.h"
#include "xmldsigEXIDatatypesDecoder.h"
#endif /* DEPLOY_XMLDSIG_CODEC == SUPPORT_YES */
/* Activate support for ISO1 */
#include "iso1EXIDatatypes.h"
#if DEPLOY_ISO1_CODEC == SUPPORT_YES
#include "iso1EXIDatatypesEncoder.h"
#include "iso1EXIDatatypesDecoder.h"
#endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
/* Activate support for ISO2 */
#include "iso2EXIDatatypes.h"
#if DEPLOY_ISO2_CODEC == SUPPORT_YES
#include "iso2EXIDatatypesEncoder.h"
#include "iso2EXIDatatypesDecoder.h"
#endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
#include "v2gtp.h"
struct appHandEXIDocument aphsDoc;
struct dinEXIDocument dinDoc;
struct iso1EXIDocument iso1Doc;
struct iso2EXIDocument iso2Doc;
#define BUFFER_SIZE 256
uint8_t mybuffer[BUFFER_SIZE];
bitstream_t global_stream1;
size_t global_pos1;
int g_errn;
char gMessageName[200];
char gResultString[4096];
char gInfoString[4096];
char gErrorString[4096];
char gPropertiesString[10000];
char gDebugString[20000];
char s[1000];
char gAdditionalParamList[1000];
#define NUM_OF_ADDITIONAL_PARAMS 5
char gAdditionalParam[NUM_OF_ADDITIONAL_PARAMS][100];
uint8_t nNumberOfFoundAdditionalParameters;
#define LEN_OF_SESSION_ID 8 /* session ID has 8 bytes (may be longer, but the Ioniq uses 8 bytes) */
uint8_t gSessionID[LEN_OF_SESSION_ID]={1, 2, 3, 4, 5, 6, 7, 8}; /* default value in case we are the charger. May be overwritten by command line. */
#define ERROR_UNEXPECTED_REQUEST_MESSAGE -601
#define ERROR_UNEXPECTED_SESSION_SETUP_RESP_MESSAGE -602
#define ERROR_UNEXPECTED_SERVICE_DISCOVERY_RESP_MESSAGE -602
#define ERROR_UNEXPECTED_SERVICE_DETAILS_RESP_MESSAGE -603
#define ERROR_UNEXPECTED_PAYMENT_SERVICE_SELECTION_RESP_MESSAGE -604
#define ERROR_UNEXPECTED_PAYMENT_DETAILS_RESP_MESSAGE -605
#define ERROR_UNEXPECTED_AUTHORIZATION_RESP_MESSAGE -606
#define ERROR_UNEXPECTED_CHARGE_PARAMETER_DISCOVERY_RESP_MESSAGE -607
#define ERROR_UNEXPECTED_POWER_DELIVERY_RESP_MESSAGE -608
#define ERROR_UNEXPECTED_CHARGING_STATUS_RESP_MESSAGE -609
#define ERROR_UNEXPECTED_METERING_RECEIPT_RESP_MESSAGE -610
#define ERROR_UNEXPECTED_SESSION_STOP_RESP_MESSAGE -611
#define ERROR_UNEXPECTED_CABLE_CHECK_RESP_MESSAGE -612
#define ERROR_UNEXPECTED_PRE_CHARGE_RESP_MESSAGE -612
#define ERROR_UNEXPECTED_CURRENT_DEMAND_RESP_MESSAGE -613
#define ERROR_UNEXPECTED_WELDING_DETECTION_RESP_MESSAGE -614
void debugAddStringAndInt(char *s, int i) {
char sTmp[1000];
sprintf(sTmp, "%s%d", s, i);
strcat(gDebugString, sTmp);
}
/*
static int writeStringToEXIString(char* string, exi_string_character_t* exiString) {
int pos = 0;
while(string[pos]!='\0')
{
exiString[pos] = string[pos];
pos++;
}
return pos;
}
*/
static void printASCIIString(exi_string_character_t* string, uint16_t len) {
unsigned int i;
char strShort[10];
strcpy(s, "");
for(i=0; i<len; i++) {
sprintf(strShort, "%c",(char)string[i]);
strcat(s, strShort);
}
//printf("\n");
}
/*
static void printBinaryArray(uint8_t* byte, uint16_t len) {
unsigned int i;
for(i=0; i<len; i++) {
printf("%d ",byte[i]);
}
printf("\n");
}
*/
/*
static void copyBytes(uint8_t* from, uint16_t len, uint8_t* to) {
int i;
for(i=0; i<len; i++) {
to[i] = from[i];
}
}
*/
/* prepare an empty stream */
static void prepareGlobalStream(void) {
global_stream1.size = BUFFER_SIZE;
global_stream1.data = mybuffer;
global_stream1.pos = &global_pos1;
*(global_stream1.pos) = 0; /* start adding data at position 0 */
}
/* print the global stream into the result string */
void printGlobalStream(void) {
int i;
char strTmp[10];
if (g_errn!=0) {
sprintf(gErrorString, "encoding failed %d", g_errn);
} else {
strcpy(gResultString, "");
/* byte per byte, write a two-character-hex value into the result string */
for (i=0; i<*global_stream1.pos; i++) {
sprintf(strTmp, "%02x", global_stream1.data[i]);
strcat(gResultString, strTmp);
}
}
}
void initProperties(void) {
strcpy(gPropertiesString, "");
}
/* add to the JSON properties string a new line with name and value, e.g.
, "responseCode": "ok"
*/
void addProperty(char *strPropertyName, char *strPropertyValue) {
strcat(gPropertiesString, ",\n\"");
strcat(gPropertiesString, strPropertyName);
strcat(gPropertiesString, "\": \"");
strcat(gPropertiesString, strPropertyValue);
strcat(gPropertiesString, "\"");
}
void addMessageName(char *messagename) {
strcpy(gMessageName, messagename);
}
/* parsing of command line argument, extracting the single parameters. */
/* Examples for command lines:
(1) OpenV2G.exe EDg_350
(2) OpenV2G.exe EDx_380_2_something_
Input: The parameter list, in the examples "_350" or "_380_2_something_".
The parameter must be separated by underscores.
Output: Array of strings containing the paramters, and the number of parameters in nNumberOfFoundAdditionalParameters
*/
void parseAdditionalParameters(void) {
int i,k, iParamNumber;
int a, b;
char s[1000];
nNumberOfFoundAdditionalParameters = 0;
if (gAdditionalParamList[strlen(gAdditionalParamList)-1]!='_') {
strcat(gAdditionalParamList, "_");
}
for (iParamNumber=0; iParamNumber<NUM_OF_ADDITIONAL_PARAMS; iParamNumber++) {
a=-1;
b=-1;
for (i=0; i<strlen(gAdditionalParamList); i++) {
if ((gAdditionalParamList[i]=='_') && (a>=0) && (b==-1)) b=i; /* the index of the second underscore */
if ((gAdditionalParamList[i]=='_') && (a==-1)) a=i; /* the index of the first underscore */
}
//printf("parameter search indexes %d %d\n", a, b);
if ((a>=0) && (b>a+1)) {
/* we have a valid start index and end index. Means: we have a parameter. */
nNumberOfFoundAdditionalParameters++;
k=0;
for (i=a+1; i<b; i++) { /* copy the parameter from the list to a local string */
s[k]=gAdditionalParamList[i];
k++;
}
s[k]=0; /* add terminating zero */
gAdditionalParamList[a] = ' '; /* replace the leading underscore of the current parameter by blank, so it will be skipped in the next round. */
strcpy(gAdditionalParam[iParamNumber], s);
//printf("Parameter is >%s<\n", s);
}
}
//printf("We have %d additional parameters.\n", nNumberOfFoundAdditionalParameters);
for (i=0; i<nNumberOfFoundAdditionalParameters; i++) {
sprintf(s, "parameter%d", i);
addProperty(s, gAdditionalParam[i]);
}
}
/* Get the element k of the gAdditionalParam, and convert it into int. */
/* In case the element is not available, we return value 0 and set the gErrorString. */
/* In case the element is no number, we return 0. */
int getIntParam(uint8_t k) {
int retval;
if (k>=nNumberOfFoundAdditionalParameters) {
sprintf(gErrorString, "Too less parameters to handle getIntParam(%d)", k);
return 0;
}
retval = atoi(gAdditionalParam[k]);
//printf("getIntParam %d returns %d\n", k, retval);
return retval;
}
/* If we are PEV, we need to use the sessionID which was decided by the charger.
This sessionID must be given on command line for each relevant message.
Here, we check whether the parameter has the correct format and if yes, we transfer
the sessionID to a global variable, which will later be used to fill the encoder input structure. */
void useSessionIdFromCommandLine(void) {
char s3[3];
int i;
uint8_t x;
/* for the case, that the command line does not provide a valid sessionID, we set here a marker to detect the issue */
gSessionID[0] = 0xDE;
gSessionID[1] = 0xAD;
gSessionID[2] = 0xBE;
gSessionID[3] = 0xEF;
gSessionID[4] = 0xDE;
gSessionID[5] = 0xAD;
gSessionID[6] = 0xBE;
gSessionID[7] = 0xEF;
if (nNumberOfFoundAdditionalParameters>0) {
if (strlen(gAdditionalParam[0])==16) { /* for 8 bytes SessionID we expect 16 hex characters */
for (i=0; i<8; i++) { /* run through 8 bytes */
/* take 2 characters from the parameter, and convert them into a byte */
s3[0] = gAdditionalParam[0][2*i];
s3[1] = gAdditionalParam[0][2*i+1];
s3[2] = 0;
x = strtol(s3, NULL, 16); /* convert the two-character hex to a uint8. If this fails, we get 0. Good enough. */
//printf("%02x, ", x);
gSessionID[i]=x;
}
} else {
sprintf(gErrorString, "useSessionIdFromCommandLine: wrong length of sessionID in first parameter. Expected 16 hex characters.");
}
} else {
sprintf(gErrorString, "useSessionIdFromCommandLine: too less parameters");
}
}
/*********************************************************************************************************
* Decoder --> JSON
**********************************************************************************************************
* This chapter contains the four functions, to translate the C structs, which are filled by
* the decoder, into JSON. Why four function? Because one for each schema: Handshake, Din, Iso1, Iso2.
*********************************************************************************************************/
/* translate the struct aphsDoc into JSON, to have it ready to give it over stdout to the caller application. */
void translateDocAppHandToJson(void) {
int i;
initProperties();
addProperty("schema", "appHandshake");
if (aphsDoc.supportedAppProtocolReq_isUsed) {
/* it is a request */
/* EVSE side: List of application handshake protocols of the EV */
addMessageName("supportedAppProtocolReq");
sprintf(s, "Vehicle supports %d protocols. ", aphsDoc.supportedAppProtocolReq.AppProtocol.arrayLen);
strcat(gResultString, s);
for(i=0;i<aphsDoc.supportedAppProtocolReq.AppProtocol.arrayLen;i++) {
sprintf(s, "ProtocolEntry#%d ",(i+1));
strcat(gResultString, s);
sprintf(s, "ProtocolNamespace=");
strcat(gResultString, s);
printASCIIString(aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].ProtocolNamespace.characters, aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].ProtocolNamespace.charactersLen);
strcat(gResultString, s);
sprintf(s, " Version=%d.%d ", aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].VersionNumberMajor, aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].VersionNumberMinor);
strcat(gResultString, s);
sprintf(s, "SchemaID=%d ", aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].SchemaID);
strcat(gResultString, s);
sprintf(s, "Priority=%d ", aphsDoc.supportedAppProtocolReq.AppProtocol.array[i].Priority);
strcat(gResultString, s);
}
}
if (aphsDoc.supportedAppProtocolRes_isUsed) {
/* it is a response */
addMessageName("supportedAppProtocolRes");
sprintf(gResultString, "ResponseCode %d, SchemaID_isUsed %d, SchemaID %d",
aphsDoc.supportedAppProtocolRes.ResponseCode,
aphsDoc.supportedAppProtocolRes.SchemaID_isUsed,
aphsDoc.supportedAppProtocolRes.SchemaID);
//if (aphsDoc.supportedAppProtocolRes.SchemaID_isUsed) {
// SchemaID
//}
}
}
void translateDinHeaderToJson(void) {
char sTmp[40], s2[30];
int i, n;
#define h dinDoc.V2G_Message.Header
n = h.SessionID.bytesLen;
//sprintf(sTmp, "%d", n); addProperty("header.SessionID.byteLen", sTmp);
strcpy(sTmp,"");
for (i=0; (i<n)&&(i<30); i++) {
sprintf(s2, "%02x", h.SessionID.bytes[i]);
strcat(sTmp, s2);
}
addProperty("header.SessionID", sTmp);
sprintf(sTmp, "%d", h.Notification_isUsed); addProperty("header.Notification_isUsed", sTmp);
sprintf(sTmp, "%d", h.Signature_isUsed); addProperty("header.Signature_isUsed", sTmp);
}
void translateUnitToJson(char *property, int unit) {
char sTmp[40];
strcpy(sTmp, "UNKNOWN_UNIT");
switch (unit) {
case dinunitSymbolType_h: strcpy(sTmp, "h"); break;
case dinunitSymbolType_m: strcpy(sTmp, "m"); break;
case dinunitSymbolType_s: strcpy(sTmp, "s"); break;
case dinunitSymbolType_A: strcpy(sTmp, "A"); break;
case dinunitSymbolType_Ah: strcpy(sTmp, "Ah"); break;
case dinunitSymbolType_V: strcpy(sTmp, "V"); break;
case dinunitSymbolType_VA: strcpy(sTmp, "VA"); break;
case dinunitSymbolType_W: strcpy(sTmp, "W"); break;
case dinunitSymbolType_W_s: strcpy(sTmp, "W_s"); break;
case dinunitSymbolType_Wh: strcpy(sTmp, "Wh"); break;
}
addProperty(property, sTmp);
}
void translateDinResponseCodeToJson(dinresponseCodeType rc) {
char sLoc[40];
strcpy(sLoc, "UNKNOWN_ERROR_CODE");
switch (rc) {
case dinresponseCodeType_OK: strcpy(sLoc, "OK"); break;
case dinresponseCodeType_OK_NewSessionEstablished: strcpy(sLoc, "OK_NewSessionEstablished"); break;
case dinresponseCodeType_OK_OldSessionJoined: strcpy(sLoc, "OK_OldSessionJoined"); break;
case dinresponseCodeType_OK_CertificateExpiresSoon: strcpy(sLoc, "OK_CertificateExpiresSoon"); break;
case dinresponseCodeType_FAILED: strcpy(sLoc, "FAILED"); break;
case dinresponseCodeType_FAILED_SequenceError: strcpy(sLoc, "FAILED_SequenceError"); break;
case dinresponseCodeType_FAILED_ServiceIDInvalid: strcpy(sLoc, "FAILED_ServiceIDInvalid"); break;
case dinresponseCodeType_FAILED_UnknownSession: strcpy(sLoc, "FAILED_UnknownSession"); break;
case dinresponseCodeType_FAILED_ServiceSelectionInvalid: strcpy(sLoc, "FAILED_ServiceSelectionInvalid"); break;
case dinresponseCodeType_FAILED_PaymentSelectionInvalid: strcpy(sLoc, "FAILED_PaymentSelectionInvalid"); break;
case dinresponseCodeType_FAILED_CertificateExpired: strcpy(sLoc, "FAILED_CertificateExpired"); break;
case dinresponseCodeType_FAILED_SignatureError: strcpy(sLoc, "FAILED_SignatureError"); break;
case dinresponseCodeType_FAILED_NoCertificateAvailable: strcpy(sLoc, "FAILED_NoCertificateAvailable"); break;
case dinresponseCodeType_FAILED_CertChainError: strcpy(sLoc, "FAILED_CertChainError"); break;
case dinresponseCodeType_FAILED_ChallengeInvalid: strcpy(sLoc, "FAILED_ChallengeInvalid"); break;
case dinresponseCodeType_FAILED_ContractCanceled: strcpy(sLoc, "FAILED_ContractCanceled"); break;
case dinresponseCodeType_FAILED_WrongChargeParameter: strcpy(sLoc, "FAILED_WrongChargeParameter"); break;
case dinresponseCodeType_FAILED_PowerDeliveryNotApplied: strcpy(sLoc, "FAILED_PowerDeliveryNotApplied"); break;
case dinresponseCodeType_FAILED_TariffSelectionInvalid: strcpy(sLoc, "FAILED_TariffSelectionInvalid"); break;
case dinresponseCodeType_FAILED_ChargingProfileInvalid: strcpy(sLoc, "FAILED_ChargingProfileInvalid"); break;
case dinresponseCodeType_FAILED_EVSEPresentVoltageToLow: strcpy(sLoc, "FAILED_EVSEPresentVoltageToLow"); break;
case dinresponseCodeType_FAILED_MeteringSignatureNotValid: strcpy(sLoc, "FAILED_MeteringSignatureNotValid"); break;
case dinresponseCodeType_FAILED_WrongEnergyTransferType: strcpy(sLoc, "FAILED_WrongEnergyTransferType"); break;
}
addProperty("ResponseCode", sLoc);
}
/* translate the struct dinDoc into JSON, to have it ready to give it over stdout to the caller application. */
void translateDocDinToJson(void) {
char sTmp[30];
char s2[30];
int i,n;
initProperties();
addProperty("schema", "DIN");
sprintf(sTmp, "%d", g_errn);
addProperty("g_errn", sTmp);
/* unclear, which is the correct flag:
dinDoc.SessionSetupReq_isUsed or
dinDoc.V2G_Message.Body.SessionSetupReq_isUsed. <-- This works with the example EXI 809a0011d00000.
*/
translateDinHeaderToJson();
if (dinDoc.V2G_Message.Body.SessionSetupReq_isUsed) {
addMessageName("SessionSetupReq");
n=dinDoc.V2G_Message.Body.SessionSetupReq.EVCCID.bytesLen;
sprintf(sTmp, "%d", n); addProperty("EVCCID.bytesLen", sTmp);
strcpy(sTmp,"");
for (i=0; (i<n)&&(i<20); i++) {
/* this is no ASCII, at least not at the Ioniq. Show just Hex. */
sprintf(s2, "%02x", dinDoc.V2G_Message.Body.SessionSetupReq.EVCCID.bytes[i]);
strcat(sTmp, s2);
}
addProperty("EVCCID", sTmp);
}
if (dinDoc.V2G_Message.Body.SessionSetupRes_isUsed) {
addMessageName("SessionSetupRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.SessionSetupRes.ResponseCode);
n=dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen;
sprintf(sTmp, "%d", n); addProperty("EVSEID.bytesLen", sTmp);
strcpy(sTmp,"");
for (i=0; (i<n)&&(i<20); i++) {
/* this is no ASCII, at least not at the Ioniq. Show just Hex. */
sprintf(s2, "%02x", dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[i]);
strcat(sTmp, s2);
}
addProperty("EVSEID", sTmp);
}
if (dinDoc.V2G_Message.Body.ServiceDiscoveryReq_isUsed) {
addMessageName("ServiceDiscoveryReq");
#define m dinDoc.V2G_Message.Body.ServiceDiscoveryReq
if (m.ServiceScope_isUsed) {
addProperty("ServiceScope_isUsed", "True");
n = m.ServiceScope.charactersLen;
sprintf(sTmp, "%d", n); addProperty("ServiceScope.charactersLen", sTmp);
}
if (m.ServiceCategory_isUsed) {
addProperty("ServiceCategory_isUsed", "True");
}
#undef m
}
if (dinDoc.V2G_Message.Body.ServiceDiscoveryRes_isUsed) {
addMessageName("ServiceDiscoveryRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode);
}
if (dinDoc.V2G_Message.Body.ServicePaymentSelectionReq_isUsed) {
addMessageName("ServicePaymentSelectionReq");
#define m dinDoc.V2G_Message.Body.ServicePaymentSelectionReq
if (m.SelectedPaymentOption==dinpaymentOptionType_Contract) { addProperty("SelectedPaymentOption", "Contract"); }
if (m.SelectedPaymentOption==dinpaymentOptionType_ExternalPayment) { addProperty("SelectedPaymentOption", "ExternalPayment"); }
n = m.SelectedServiceList.SelectedService.arrayLen;
sprintf(sTmp, "%d", n); addProperty("SelectedService.arrayLen", sTmp);
for (i=0; i<n; i++) {
sprintf(sTmp, "%d:%d", i, m.SelectedServiceList.SelectedService.array[i].ServiceID); addProperty("SelectedService.array", sTmp);
}
// ParameterSetID_isUsed
// ParameterSetID
#undef m
}
if (dinDoc.V2G_Message.Body.ServicePaymentSelectionRes_isUsed) {
addMessageName("ServicePaymentSelectionRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.ServicePaymentSelectionRes.ResponseCode);
}
/* not supported in DIN
if (dinDoc.V2G_Message.Body.AuthorizationReq_isUsed) {
addProperty("msgName", "AuthorizationReq");
}
if (dinDoc.V2G_Message.Body.AuthorizationRes_isUsed) {
addProperty("msgName", "AuthorizationRes");
}
*/
if (dinDoc.V2G_Message.Body.ContractAuthenticationReq_isUsed) {
addMessageName("ContractAuthenticationReq");
}
if (dinDoc.V2G_Message.Body.ContractAuthenticationRes_isUsed) {
addMessageName("ContractAuthenticationRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.ContractAuthenticationRes.ResponseCode);
#define processing dinDoc.V2G_Message.Body.ContractAuthenticationRes.EVSEProcessing
if (processing==dinEVSEProcessingType_Finished) {
addProperty("EVSEProcessing", "Finished");
}
if (processing==dinEVSEProcessingType_Ongoing) {
addProperty("EVSEProcessing", "Ongoing");
}
#undef processing
}
if (dinDoc.V2G_Message.Body.ChargeParameterDiscoveryReq_isUsed) {
addMessageName("ChargeParameterDiscoveryReq");
#define m dinDoc.V2G_Message.Body.ChargeParameterDiscoveryReq
sprintf(sTmp, "%d", m.EVRequestedEnergyTransferType); addProperty("EVRequestedEnergyTransferType", sTmp);
sprintf(sTmp, "%d", m.DC_EVChargeParameter_isUsed); addProperty("DC_EVChargeParameter_isUsed", sTmp);
if (m.DC_EVChargeParameter_isUsed) {
sprintf(sTmp, "%d", m.DC_EVChargeParameter.DC_EVStatus.EVRESSSOC); addProperty("DC_EVStatus.EVRESSSOC", sTmp);
sprintf(sTmp, "%d", m.DC_EVChargeParameter.DC_EVStatus.EVReady); addProperty("DC_EVStatus.EVReady", sTmp);
// todo EVMaximumCurrentLimit
}
#undef m
}
if (dinDoc.V2G_Message.Body.ChargeParameterDiscoveryRes_isUsed) {
addMessageName("ChargeParameterDiscoveryRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.ChargeParameterDiscoveryRes.ResponseCode);
#define processing dinDoc.V2G_Message.Body.ChargeParameterDiscoveryRes.EVSEProcessing
if (processing==dinEVSEProcessingType_Finished) {
addProperty("EVSEProcessing", "Finished");
}
if (processing==dinEVSEProcessingType_Ongoing) {
addProperty("EVSEProcessing", "Ongoing");
}
#undef processing
// todo maybe: EVSEChargeParameter_isUsed
// todo for AC: AC_EVSEChargeParameter_isUsed
if (dinDoc.V2G_Message.Body.ChargeParameterDiscoveryRes.DC_EVSEChargeParameter_isUsed) {
//DC_EVSEChargeParameter
// DC_EVSEStatus
#define cp dinDoc.V2G_Message.Body.ChargeParameterDiscoveryRes.DC_EVSEChargeParameter
#define v1 cp.DC_EVSEStatus.EVSEIsolationStatus
#define v2 cp.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 cp.DC_EVSEStatus.EVSEStatusCode
#define v4 cp.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 cp.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
// EVSEMaximumCurrentLimit
sprintf(sTmp, "%d", cp.EVSEMaximumCurrentLimit.Multiplier); addProperty("EVSEMaximumCurrentLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", cp.EVSEMaximumCurrentLimit.Value); addProperty("EVSEMaximumCurrentLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumCurrentLimit.Unit", cp.EVSEMaximumCurrentLimit.Unit);
// EVSEMaximumPowerLimit
// EVSEMaximumPowerLimit_isUsed
sprintf(sTmp, "%d", cp.EVSEMaximumPowerLimit_isUsed); addProperty("EVSEMaximumPowerLimit_isUsed", sTmp);
sprintf(sTmp, "%d", cp.EVSEMaximumPowerLimit.Multiplier); addProperty("EVSEMaximumPowerLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", cp.EVSEMaximumPowerLimit.Value); addProperty("EVSEMaximumPowerLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumPowerLimit.Unit", cp.EVSEMaximumPowerLimit.Unit);
// EVSEMaximumVoltageLimit
sprintf(sTmp, "%d", cp.EVSEMaximumVoltageLimit.Multiplier); addProperty("EVSEMaximumVoltageLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", cp.EVSEMaximumVoltageLimit.Value); addProperty("EVSEMaximumVoltageLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumVoltageLimit.Unit", cp.EVSEMaximumVoltageLimit.Unit);
// EVSEMinimumCurrentLimit
sprintf(sTmp, "%d", cp.EVSEMinimumCurrentLimit.Multiplier); addProperty("EVSEMinimumCurrentLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", cp.EVSEMinimumCurrentLimit.Value); addProperty("EVSEMinimumCurrentLimit.Value", sTmp);
translateUnitToJson("EVSEMinimumCurrentLimit.Unit", cp.EVSEMinimumCurrentLimit.Unit);
// EVSEMinimumVoltageLimit
sprintf(sTmp, "%d", cp.EVSEMinimumVoltageLimit.Multiplier); addProperty("EVSEMinimumVoltageLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", cp.EVSEMinimumVoltageLimit.Value); addProperty("EVSEMinimumVoltageLimit.Value", sTmp);
translateUnitToJson("EVSEMinimumVoltageLimit.Unit", cp.EVSEMinimumVoltageLimit.Unit);
// EVSECurrentRegulationTolerance
// EVSECurrentRegulationTolerance_isUsed
// EVSEPeakCurrentRipple
// EVSEEnergyToBeDelivered
// EVSEEnergyToBeDelivered_isUsed
//xxx
#undef cp
}
}
if (dinDoc.V2G_Message.Body.CableCheckReq_isUsed) {
addMessageName("CableCheckReq");
#define m dinDoc.V2G_Message.Body.CableCheckReq
sprintf(sTmp, "%d", m.DC_EVStatus.EVRESSSOC); addProperty("DC_EVStatus.EVRESSSOC", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVReady); addProperty("DC_EVStatus.EVReady", sTmp);
#undef m
}
if (dinDoc.V2G_Message.Body.CableCheckRes_isUsed) {
addMessageName("CableCheckRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.CableCheckRes.ResponseCode);
#define m dinDoc.V2G_Message.Body.CableCheckRes
#define v1 m.DC_EVSEStatus.EVSEIsolationStatus
#define v2 m.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 m.DC_EVSEStatus.EVSEStatusCode
#define v4 m.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 m.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
if (m.EVSEProcessing==dinEVSEProcessingType_Finished) {
addProperty("EVSEProcessing", "Finished");
}
if (m.EVSEProcessing==dinEVSEProcessingType_Ongoing) {
addProperty("EVSEProcessing", "Ongoing");
}
#undef m
}
if (dinDoc.V2G_Message.Body.PreChargeReq_isUsed) {
addMessageName("PreChargeReq");
#define m dinDoc.V2G_Message.Body.PreChargeReq
sprintf(sTmp, "%d", m.DC_EVStatus.EVReady); addProperty("DC_EVStatus.EVReady", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVErrorCode); addProperty("DC_EVStatus.EVErrorCode", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVRESSSOC); addProperty("DC_EVStatus.EVRESSSOC", sTmp);
sprintf(sTmp, "%d", m.EVTargetVoltage.Multiplier); addProperty("EVTargetVoltage.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVTargetVoltage.Value); addProperty("EVTargetVoltage.Value", sTmp);
translateUnitToJson("EVTargetVoltage.Unit", m.EVTargetVoltage.Unit);
sprintf(sTmp, "%d", m.EVTargetCurrent.Multiplier); addProperty("EVTargetCurrent.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVTargetCurrent.Value); addProperty("EVTargetCurrent.Value", sTmp);
translateUnitToJson("EVTargetCurrent.Unit", m.EVTargetCurrent.Unit);
#undef m
}
if (dinDoc.V2G_Message.Body.PreChargeRes_isUsed) {
addMessageName("PreChargeRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.PreChargeRes.ResponseCode);
#define m dinDoc.V2G_Message.Body.PreChargeRes
#define v1 m.DC_EVSEStatus.EVSEIsolationStatus
#define v2 m.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 m.DC_EVSEStatus.EVSEStatusCode
#define v4 m.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 m.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Multiplier); addProperty("EVSEPresentVoltage.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Value); addProperty("EVSEPresentVoltage.Value", sTmp);
translateUnitToJson("EVSEPresentVoltage.Unit", m.EVSEPresentVoltage.Unit); /* todo: why is this shown as 0???? */
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
#undef m
}
if (dinDoc.V2G_Message.Body.PowerDeliveryReq_isUsed) {
addMessageName("PowerDeliveryReq");
sprintf(sTmp, "%d", dinDoc.V2G_Message.Body.PowerDeliveryReq.ReadyToChargeState); addProperty("ReadyToChargeState", sTmp);
if (dinDoc.V2G_Message.Body.PowerDeliveryReq.ReadyToChargeState==0) { addProperty("ReadyToChargeState_Text", "START"); }
if (dinDoc.V2G_Message.Body.PowerDeliveryReq.ReadyToChargeState==1) { addProperty("ReadyToChargeState_Text", "STOP"); }
if (dinDoc.V2G_Message.Body.PowerDeliveryReq.ReadyToChargeState==2) { addProperty("ReadyToChargeState_Text", "Renegotiate"); }
sprintf(sTmp, "%d", dinDoc.V2G_Message.Body.PowerDeliveryReq.ChargingProfile_isUsed); addProperty("ChargingProfile_isUsed", sTmp);
sprintf(sTmp, "%d", dinDoc.V2G_Message.Body.PowerDeliveryReq.EVPowerDeliveryParameter_isUsed); addProperty("EVPowerDeliveryParameter_isUsed", sTmp);
sprintf(sTmp, "%d", dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter_isUsed); addProperty("DC_EVPowerDeliveryParameter_isUsed", sTmp);
if (dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter_isUsed) {
#define v1 dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter.DC_EVStatus.EVReady
#define v2 dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter.DC_EVStatus.EVErrorCode
#define v3 dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter.DC_EVStatus.EVRESSSOC
#define v4 dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter.BulkChargingComplete
#define v5 dinDoc.V2G_Message.Body.PowerDeliveryReq.DC_EVPowerDeliveryParameter.ChargingComplete
sprintf(sTmp, "%d", v1); addProperty("EVReady", sTmp);
sprintf(sTmp, "%d", v2); addProperty("EVErrorCode", sTmp);
switch (v2) {
case dinDC_EVErrorCodeType_NO_ERROR:
addProperty("EVErrorCodeText", "NO_ERROR");
break;
case dinDC_EVErrorCodeType_FAILED_ChargingSystemIncompatibility:
addProperty("EVErrorCodeText", "FAILED_ChargingSystemIncompatibility");
break;
case dinDC_EVErrorCodeType_FAILED_ChargerConnectorLockFault:
addProperty("EVErrorCodeText", "FAILED_ChargerConnectorLockFault");
break;
default:
addProperty("EVErrorCodeText", "otherError");
/* todo add more error texts */
}
sprintf(sTmp, "%d", v3); addProperty("EVRESSSOC", sTmp);
sprintf(sTmp, "%d", v4); addProperty("BulkChargingComplete", sTmp);
sprintf(sTmp, "%d", v5); addProperty("ChargingComplete", sTmp);
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
}
}
if (dinDoc.V2G_Message.Body.PowerDeliveryRes_isUsed) {
addMessageName("PowerDeliveryRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.PowerDeliveryRes.ResponseCode);
#define m dinDoc.V2G_Message.Body.PowerDeliveryRes
if (m.DC_EVSEStatus_isUsed) {
#define v1 m.DC_EVSEStatus.EVSEIsolationStatus
#define v2 m.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 m.DC_EVSEStatus.EVSEStatusCode
#define v4 m.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 m.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
#undef m
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
}
}
if (dinDoc.V2G_Message.Body.CurrentDemandReq_isUsed) {
addMessageName("CurrentDemandReq");
#define m dinDoc.V2G_Message.Body.CurrentDemandReq
sprintf(sTmp, "%d", m.DC_EVStatus.EVReady); addProperty("DC_EVStatus.EVReady", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVErrorCode); addProperty("DC_EVStatus.EVErrorCode", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVRESSSOC); addProperty("DC_EVStatus.EVRESSSOC", sTmp);
sprintf(sTmp, "%d", m.EVTargetCurrent.Multiplier); addProperty("EVTargetCurrent.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVTargetCurrent.Value); addProperty("EVTargetCurrent.Value", sTmp);
translateUnitToJson("EVTargetCurrent.Unit", m.EVTargetCurrent.Unit);
sprintf(sTmp, "%d", m.EVMaximumVoltageLimit_isUsed); addProperty("EVMaximumVoltageLimit_isUsed", sTmp);
if (m.EVMaximumVoltageLimit_isUsed) {
sprintf(sTmp, "%d", m.EVMaximumVoltageLimit.Multiplier); addProperty("EVMaximumVoltageLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVMaximumVoltageLimit.Value); addProperty("EVMaximumVoltageLimit.Value", sTmp);
translateUnitToJson("EVMaximumVoltageLimit.Unit", m.EVMaximumVoltageLimit.Unit);
}
sprintf(sTmp, "%d", m.EVMaximumCurrentLimit_isUsed); addProperty("EVMaximumCurrentLimit_isUsed", sTmp);
if (m.EVMaximumCurrentLimit_isUsed) {
sprintf(sTmp, "%d", m.EVMaximumCurrentLimit.Multiplier); addProperty("EVMaximumCurrentLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVMaximumCurrentLimit.Value); addProperty("EVMaximumCurrentLimit.Value", sTmp);
translateUnitToJson("EVMaximumCurrentLimit.Unit", m.EVMaximumCurrentLimit.Unit);
}
sprintf(sTmp, "%d", m.EVMaximumPowerLimit_isUsed); addProperty("EVMaximumPowerLimit_isUsed", sTmp);
if (m.EVMaximumPowerLimit_isUsed) {
sprintf(sTmp, "%d", m.EVMaximumPowerLimit.Multiplier); addProperty("EVMaximumPowerLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVMaximumPowerLimit.Value); addProperty("EVMaximumPowerLimit.Value", sTmp);
translateUnitToJson("EVMaximumPowerLimit.Unit", m.EVMaximumPowerLimit.Unit);
}
//m.BulkChargingComplete_isUsed
//m.BulkChargingComplete
sprintf(sTmp, "%d", m.ChargingComplete); addProperty("ChargingComplete", sTmp);
sprintf(sTmp, "%d", m.EVTargetVoltage.Multiplier); addProperty("EVTargetVoltage.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVTargetVoltage.Value); addProperty("EVTargetVoltage.Value", sTmp);
translateUnitToJson("EVTargetVoltage.Unit", m.EVTargetVoltage.Unit);
#undef m
}
if (dinDoc.V2G_Message.Body.CurrentDemandRes_isUsed) {
addMessageName("CurrentDemandRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.CurrentDemandRes.ResponseCode);
#define m dinDoc.V2G_Message.Body.CurrentDemandRes
#define v1 m.DC_EVSEStatus.EVSEIsolationStatus
#define v2 m.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 m.DC_EVSEStatus.EVSEStatusCode
#define v4 m.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 m.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Multiplier); addProperty("EVSEPresentVoltage.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Value); addProperty("EVSEPresentVoltage.Value", sTmp);
translateUnitToJson("EVSEPresentVoltage.Unit", m.EVSEPresentVoltage.Unit);
sprintf(sTmp, "%d", m.EVSEPresentCurrent.Multiplier); addProperty("EVSEPresentCurrent.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentCurrent.Value); addProperty("EVSEPresentCurrent.Value", sTmp);
translateUnitToJson("EVSEPresentCurrent.Unit", m.EVSEPresentCurrent.Unit);
sprintf(sTmp, "%d", m.EVSECurrentLimitAchieved); addProperty("EVSECurrentLimitAchieved", sTmp);
sprintf(sTmp, "%d", m.EVSEVoltageLimitAchieved); addProperty("EVSEVoltageLimitAchieved", sTmp);
sprintf(sTmp, "%d", m.EVSEPowerLimitAchieved); addProperty("EVSEPowerLimitAchieved", sTmp);
sprintf(sTmp, "%d", m.EVSEMaximumVoltageLimit.Multiplier); addProperty("EVSEMaximumVoltageLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEMaximumVoltageLimit.Value); addProperty("EVSEMaximumVoltageLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumVoltageLimit.Unit", m.EVSEMaximumVoltageLimit.Unit);
if (m.EVSEMaximumCurrentLimit_isUsed) {
sprintf(sTmp, "%d", m.EVSEMaximumCurrentLimit.Multiplier); addProperty("EVSEMaximumCurrentLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEMaximumCurrentLimit.Value); addProperty("EVSEMaximumCurrentLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumCurrentLimit.Unit", m.EVSEMaximumCurrentLimit.Unit);
}
if (m.EVSEMaximumPowerLimit_isUsed) {
sprintf(sTmp, "%d", m.EVSEMaximumPowerLimit.Multiplier); addProperty("EVSEMaximumPowerLimit.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEMaximumPowerLimit.Value); addProperty("EVSEMaximumPowerLimit.Value", sTmp);
translateUnitToJson("EVSEMaximumPowerLimit.Unit", m.EVSEMaximumPowerLimit.Unit);
}
#undef m
}
if (dinDoc.V2G_Message.Body.SessionStopReq_isUsed) {
addMessageName("SessionStopReq");
}
if (dinDoc.V2G_Message.Body.SessionStopRes_isUsed) {
addMessageName("SessionStopRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.SessionStopRes.ResponseCode);
}
if (dinDoc.V2G_Message.Body.WeldingDetectionReq_isUsed) {
addMessageName("WeldingDetectionReq");
#define m dinDoc.V2G_Message.Body.WeldingDetectionReq
sprintf(sTmp, "%d", m.DC_EVStatus.EVReady); addProperty("DC_EVStatus.EVReady", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVErrorCode); addProperty("DC_EVStatus.EVErrorCode", sTmp);
sprintf(sTmp, "%d", m.DC_EVStatus.EVRESSSOC); addProperty("DC_EVStatus.EVRESSSOC", sTmp);
#undef m
}
if (dinDoc.V2G_Message.Body.WeldingDetectionRes_isUsed) {
addMessageName("WeldingDetectionRes");
translateDinResponseCodeToJson(dinDoc.V2G_Message.Body.WeldingDetectionRes.ResponseCode);
#define m dinDoc.V2G_Message.Body.WeldingDetectionRes
#define v1 m.DC_EVSEStatus.EVSEIsolationStatus
#define v2 m.DC_EVSEStatus.EVSEIsolationStatus_isUsed
#define v3 m.DC_EVSEStatus.EVSEStatusCode
#define v4 m.DC_EVSEStatus.NotificationMaxDelay /* expected time until the PEV reacts on the below mentioned notification. Not relevant. */
#define v5 m.DC_EVSEStatus.EVSENotification
sprintf(sTmp, "%d", v1); addProperty("DC_EVSEStatus.EVSEIsolationStatus", sTmp);
sprintf(sTmp, "%d", v2); addProperty("DC_EVSEStatus.EVSEIsolationStatus_isUsed", sTmp);
sprintf(sTmp, "%d", v3); addProperty("DC_EVSEStatus.EVSEStatusCode", sTmp);
sprintf(sTmp, "%d", v4); addProperty("DC_EVSEStatus.NotificationMaxDelay", sTmp);
sprintf(sTmp, "%d", v5); addProperty("DC_EVSEStatus.EVSENotification", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Multiplier); addProperty("EVSEPresentVoltage.Multiplier", sTmp);
sprintf(sTmp, "%d", m.EVSEPresentVoltage.Value); addProperty("EVSEPresentVoltage.Value", sTmp);
translateUnitToJson("EVSEPresentVoltage.Unit", m.EVSEPresentVoltage.Unit);
#undef v1
#undef v2
#undef v3
#undef v4
#undef v5
#undef m
}
}
/*********************************************************************************************************
* Encoder
**********************************************************************************************************
*********************************************************************************************************/
static void encodeSupportedAppProtocolResponse(void) {
/* The :supportedAppProtocolRes contains only two fields:
ResponseCode
SchemaID (optional) It is not clear, in which cases the SchemaID can be left empty. Maybe if the list has only one enty. Or
maybe always, to just select the first entry. */
init_appHandEXIDocument(&aphsDoc);
aphsDoc.supportedAppProtocolRes_isUsed = 1u;
aphsDoc.supportedAppProtocolRes.ResponseCode = appHandresponseCodeType_OK_SuccessfulNegotiation;
aphsDoc.supportedAppProtocolRes.SchemaID = 1; /* todo: fill with one of the SchemaIDs of the request. The Ioniq uses schema 1 as one-and-only. */
aphsDoc.supportedAppProtocolRes.SchemaID_isUsed = 1u; /* todo: shall we try without SchemaID? */
prepareGlobalStream();
g_errn = encode_appHandExiDocument(&global_stream1, &aphsDoc);
printGlobalStream();
sprintf(gInfoString, "encodeSupportedAppProtocolResponse finished");
}
static void encodeSessionSetupRequest(void) {
dinDoc.V2G_Message_isUsed = 1u;
init_dinMessageHeaderType(&dinDoc.V2G_Message.Header);
init_dinBodyType(&dinDoc.V2G_Message.Body);
dinDoc.V2G_Message.Body.SessionSetupReq_isUsed = 1u;
init_dinSessionSetupReqType(&dinDoc.V2G_Message.Body.SessionSetupReq);
/* In the session setup request, the session ID zero means: create a new session.
The format (len 8, all zero) is taken from the original Ioniq behavior. */
dinDoc.V2G_Message.Header.SessionID.bytes[0] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[1] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[2] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[3] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[4] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[5] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[6] = 0;
dinDoc.V2G_Message.Header.SessionID.bytes[7] = 0;
dinDoc.V2G_Message.Header.SessionID.bytesLen = 8;
prepareGlobalStream();
g_errn = encode_dinExiDocument(&global_stream1, &dinDoc);
printGlobalStream();
sprintf(gInfoString, "encodeSessionSetupRequest finished");
}
static void init_dinMessageHeaderWithSessionID(void) {
int i;
dinDoc.V2G_Message_isUsed = 1u;
/* generate an "unique" sessionID */
init_dinMessageHeaderType(&dinDoc.V2G_Message.Header);
/* When receiving the SessionSetupReq with the parameter SessionID equal to zero (0), the
SECC shall generate a new (not stored) SessionID value different from zero (0) and return this
value in the SessionSetupRes message header.
We can use the following simplification if we are SECC/EVSE: We set always the same SessionID, with non-zero value. */
/* Todo: In PEV, we need to extract the session ID from the SessionSetupResponse, store it in the upper layers and
use it in the headers of all subsequent request messages. */
for (i=0; i<LEN_OF_SESSION_ID; i++) {
dinDoc.V2G_Message.Header.SessionID.bytes[i] = gSessionID[i];
}
dinDoc.V2G_Message.Header.SessionID.bytesLen = LEN_OF_SESSION_ID;
}
static void encodeSessionSetupResponse(void) {
/* This is the place, where we, as charger, decide about the new session ID. */
/* As simplification, we always use the same session ID, so we have no need to transfer
the number via command line interface to the upper layers in case we are the charger.
On the other hand, if we are the car, then we need to use the sessionID which was decided
by the charger, and we need to transfer it to and from the upper layers. */
init_dinMessageHeaderWithSessionID();
init_dinBodyType(&dinDoc.V2G_Message.Body);
dinDoc.V2G_Message.Body.SessionSetupRes_isUsed = 1u;
init_dinSessionSetupResType(&dinDoc.V2G_Message.Body.SessionSetupRes);
/* If the SECC receives a SessionSetupReq including a SessionID value which is not equal to
zero (0) and not equal to the SessionID value stored from the preceding V2G Communication
Session, it shall send a SessionID value in the SessionSetupRes message that is unequal to
"0" and unequal to the SessionID value stored from the preceding V2G Communication
Session and indicate the new V2G Communication Session with the ResponseCode set to
"OK_NewSessionEstablished"
*/
dinDoc.V2G_Message.Body.SessionSetupRes.ResponseCode = dinresponseCodeType_OK_NewSessionEstablished;
/* EVSEID has min length 7, max length 37 for ISO. In DIN decoder we find maxsize 32. */
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[0] = 'Z';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[1] = 'Z';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[2] = '0';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[3] = '0';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[4] = '0';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[5] = '0';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytes[6] = '0';
dinDoc.V2G_Message.Body.SessionSetupRes.EVSEID.bytesLen = 7;
//dinDoc.V2G_Message.Body.SessionSetupRes.EVSETimeStamp_isUsed = 0u;
//dinDoc.V2G_Message.Body.SessionSetupRes.EVSETimeStamp = 123456789;
prepareGlobalStream();
g_errn = encode_dinExiDocument(&global_stream1, &dinDoc);
printGlobalStream();
sprintf(gInfoString, "encodeSessionSetupResponse finished");
}
static void encodeServiceDiscoveryRequest(void) {
useSessionIdFromCommandLine();
init_dinMessageHeaderWithSessionID();
dinDoc.V2G_Message_isUsed = 1u;
init_dinMessageHeaderType(&dinDoc.V2G_Message.Header);
init_dinBodyType(&dinDoc.V2G_Message.Body);
dinDoc.V2G_Message.Body.ServiceDiscoveryReq_isUsed = 1u;
init_dinServiceDiscoveryReqType(&dinDoc.V2G_Message.Body.ServiceDiscoveryReq);
prepareGlobalStream();
g_errn = encode_dinExiDocument(&global_stream1, &dinDoc);
printGlobalStream();
sprintf(gInfoString, "encodeServiceDiscoveryRequest finished");
}
void encodeServiceDiscoveryResponse(void) {
init_dinMessageHeaderWithSessionID();
init_dinBodyType(&dinDoc.V2G_Message.Body);
dinDoc.V2G_Message.Body.ServiceDiscoveryRes_isUsed = 1u;
init_dinServiceDiscoveryResType(&dinDoc.V2G_Message.Body.ServiceDiscoveryRes);
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ResponseCode = dinresponseCodeType_OK;
/* the mandatory fields in the ISO are PaymentOptionList and ChargeService.
But in the DIN, this is different, we find PaymentOptions, ChargeService and optional ServiceList */
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.array[0] = dinpaymentOptionType_ExternalPayment; /* EVSE handles the payment */
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.PaymentOptions.PaymentOption.arrayLen = 1; /* just one single payment option in the table */
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceID = 1; /* todo: not clear what this means */
//dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceName
//dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceName_isUsed
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceCategory = dinserviceCategoryType_EVCharging;
//dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceScope
//dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.ServiceTag.ServiceScope_isUsed
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.FreeService = 0; /* what ever this means. Just from example. */
/* dinEVSESupportedEnergyTransferType, e.g.
dinEVSESupportedEnergyTransferType_DC_combo_core or
dinEVSESupportedEnergyTransferType_DC_core or
dinEVSESupportedEnergyTransferType_DC_extended
dinEVSESupportedEnergyTransferType_AC_single_phase_core.
DC_extended means "extended pins of an IEC 62196-3 Configuration FF connector", which is
the normal CCS connector https://en.wikipedia.org/wiki/IEC_62196#FF) */
dinDoc.V2G_Message.Body.ServiceDiscoveryRes.ChargeService.EnergyTransferType = dinEVSESupportedEnergyTransferType_DC_extended;
prepareGlobalStream();
g_errn = encode_dinExiDocument(&global_stream1, &dinDoc);
printGlobalStream();
sprintf(gInfoString, "encodeServiceDiscoveryResponse finished");
}