forked from Eba-M/E3DC-Control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRscpExampleMain.cpp
executable file
·2893 lines (2539 loc) · 129 KB
/
RscpExampleMain.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
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include "RscpProtocol.h"
#include "RscpTags.h"
#include "SocketConnection.h"
#include "AES.h"
#include <time.h>
#include "E3DC_CONF.h"
#include "SunriseCalc.hpp"
#include "awattar.hpp"
//#include "MQTTClient.h"
//#include "json.hpp"
// for convenience test4
// using json = nlohmann::json;
#define AES_KEY_SIZE 32
#define AES_BLOCK_SIZE 32
// json j;
static int iSocket = -1;
static int iAuthenticated = 0;
static int iBattPowerStatus = 0; // Status, ob schon mal angefragt,
static int iWBStatus = 0; // Status, WB schon mal angefragt, 0 inaktiv, 1 aktiv, 2 regeln
static int iLMStatus = 0; // Status, Load Management negativer Wert in Sekunden = Anforderung + Warten bis zur nächsten Anforderung, der angeforderte Wert steht in iE3DC_Req_Load
static int iLMStatus2 = 0; // Status, Load Management Peakshaving > 0 ist aktiv
static float fAvBatterie,fAvBatterie900;
static int iAvBatt_Count = 0;
static int iAvBatt_Count900 = 0;
static uint8_t WBToggel;
static uint8_t WBchar[8];
static uint8_t WBchar6[6]; // Steuerstring zur Wallbox
const uint16_t iWBLen = 6;
static AES aesEncrypter;
static AES aesDecrypter;
static uint8_t ucEncryptionIV[AES_BLOCK_SIZE];
static uint8_t ucDecryptionIV[AES_BLOCK_SIZE];
// static int32_t iPower_Grid;
static uint8_t iCurrent_WB;
static uint8_t iCurrent_Set_WB;
static float fPower_Grid;
static float fAvPower_Grid,fAvPower_Grid3600,fAvPower_Grid600,fAvPower_Grid60; // Durchschnitt ungewichtete Netzleistung der letzten 10sec
static int iAvPower_GridCount = 0;
static float fPower_WB;
static int32_t iPower_PV, iPower_PV_E3DC;
static int32_t iPower_Bat;
static uint8_t iPhases_WB;
static uint8_t iCyc_WB;
static int32_t iBattLoad;
static int iPowerBalance,iPowerHome;
static uint8_t iNotstrom = 0;
static time_t tE3DC, tWBtime;
static int hh,mm,ss;
static int32_t iFc, iMinLade,iMinLade2; // Mindestladeladeleistung des E3DC Speichers
static float_t fL1V=230,fL2V=230,fL3V=230;
static int iDischarge = -1;
static bool bDischarge = true,bDischargeDone; // Wenn false, wird das Entladen blockiert, unabhängig von dem vom Portal gesetzen wert
char cWBALG;
static bool bWBLademodus; // Lademodus der Wallbox; z.B. Sonnenmodus
static bool bWBChanged; // Lademodus der Wallbox; wurde extern geändertz.B. Sonnenmodus
static bool bWBConnect; // True = Dose ist verriegelt x08
static bool bWBStart; // True Laden ist gestartet x10
static bool bWBCharge; // True Laden ist gestartet x20
static bool bWBSonne; // Sonnenmodus x80
static bool bWBStopped; // Laden angehalten x40
static bool bWBmaxLadestrom,bWBmaxLadestromSave; // Ladestrom der Wallbox per App eingestellt.; 32=ON 31 = OFF
static int iWBSoll,iWBIst; // Soll = angeforderter Ladestrom, Ist = aktueller Ladestrom
static int32_t iE3DC_Req_Load,iE3DC_Req_Load_alt,iE3DC_Req_LoadMode=0; // Leistung, mit der der E3DC-Seicher geladen oder entladen werden soll
int sunriseAt; // Sonnenaufgang
int sunsetAt; // Sonnenuntergang
std::vector<watt_s> ch; //charge hour
FILE * pFile;
e3dc_config_t e3dc_config;
char Log[300];
int WriteLog()
{
static time_t t,t_alt = 0;
int day,hour;
char fname[127];
time(&t);
FILE *fp;
struct tm * ptm;
ptm = gmtime(&t);
day = (t%(24*3600*4))/(24*3600);
hour = (t%(24*3600))/(3600*4)*4;
if (e3dc_config.debug) {
if (hour!=t_alt) // neuer Tag
{
// int tt = (t%(24*3600)+12*3600);
sprintf(fname,"%s.%i.%i.txt",e3dc_config.logfile,day,hour);
fp = fopen(fname,"w"); // altes logfile löschen
fclose(fp);
}
sprintf(fname,"%s.%i.%i.txt",e3dc_config.logfile,day,hour);
fp = fopen(fname, "a");
if(!fp)
fp = fopen(fname, "w");
if(fp)
fprintf(fp,"%s\n",Log);
fclose(fp);}
t_alt = hour;
;
return(0);
}
int MQTTsend(char buffer[127])
{
char cbuf[127];
if (e3dc_config.openWB) {
sprintf(cbuf, "mosquitto_pub -r -h %s -t %s", e3dc_config.openWBhost,buffer);
system(cbuf);
}
return(0);
}
int ControlLoadData(SRscpFrameBuffer * frameBuffer,int32_t Power,int32_t Mode ) {
RscpProtocol protocol;
SRscpValue rootValue;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
// Power = Power*-1;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER);
protocol.appendValue(&PMContainer, TAG_EMS_REQ_SET_POWER_MODE,Mode);
if (Mode > 0)
protocol.appendValue(&PMContainer, TAG_EMS_REQ_SET_POWER_VALUE,Power);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int ControlLoadData2(SRscpFrameBuffer * frameBuffer,int32_t iPower) {
RscpProtocol protocol;
SRscpValue rootValue;
uint32_t uPower;
if (iPower < 0) uPower = 0; else if (iPower>e3dc_config.maximumLadeleistung) uPower = e3dc_config.maximumLadeleistung; else uPower = iPower;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER_SETTINGS);
protocol.appendValue(&PMContainer, TAG_EMS_POWER_LIMITS_USED,true);
protocol.appendValue(&PMContainer, TAG_EMS_MAX_CHARGE_POWER,uPower);
// protocol.appendValue(&PMContainer, TAG_EMS_MAX_DISCHARGE_POWER,300);
// protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,70);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int Control_MAX_DISCHARGE(SRscpFrameBuffer * frameBuffer,int32_t iPower) {
RscpProtocol protocol;
SRscpValue rootValue;
uint32_t uPower;
if (iPower < 0) uPower = 0; else if (iPower>e3dc_config.maximumLadeleistung) uPower = e3dc_config.maximumLadeleistung; else uPower = iPower;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER_SETTINGS);
protocol.appendValue(&PMContainer, TAG_EMS_POWER_LIMITS_USED,true);
if (uPower < 65)
protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,uPower);
else
protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,uint32_t(65));
protocol.appendValue(&PMContainer, TAG_EMS_MAX_DISCHARGE_POWER,uPower);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int createRequestWBData(SRscpFrameBuffer * frameBuffer) {
RscpProtocol protocol;
SRscpValue rootValue;
iWBStatus=12;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue WBContainer;
SRscpValue WB2Container;
// request Wallbox data
protocol.createContainerValue(&WBContainer, TAG_WB_REQ_DATA) ;
// add index 0 to select first wallbox
protocol.appendValue(&WBContainer, TAG_WB_INDEX,0);
protocol.createContainerValue(&WB2Container, TAG_WB_REQ_SET_EXTERN);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,6);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar6,iWBLen);
iWBSoll = WBchar6[1]; // angeforderte Ladestromstärke;
WBToggel = WBchar6[4];
protocol.appendValue(&WBContainer, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WB2Container);
// append sub-container to root container
protocol.appendValue(&rootValue, WBContainer);
// protocol.appendValue(&rootValue, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WBContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int createRequestWBData2(SRscpFrameBuffer * frameBuffer) {
RscpProtocol protocol;
SRscpValue rootValue;
iWBStatus=12;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue WBContainer;
SRscpValue WB2Container;
// request Wallbox data
protocol.createContainerValue(&WBContainer, TAG_WB_REQ_DATA) ;
// add index 0 to select first wallbox
protocol.appendValue(&WBContainer, TAG_WB_INDEX,0);
protocol.createContainerValue(&WB2Container, TAG_WB_REQ_SET_PARAM_1);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,8);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar,8);
iWBSoll = WBchar[2]; // angeforderte Ladestromstärke;
protocol.appendValue(&WBContainer, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WB2Container);
// append sub-container to root container
protocol.appendValue(&rootValue, WBContainer);
// protocol.appendValue(&rootValue, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WBContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
static float fBatt_SOC, fBatt_SOC_alt;
static float fSavedtoday, fSavedyesderday,fSavedtotal,fSavedWB; // Überschussleistung
static int32_t iDiffLadeleistung, iDiffLadeleistung2;
static time_t tLadezeit_alt,tLadezeitende_alt,tE3DC_alt;
static time_t t = 0;
static time_t tm_CONF_dt;
static bool bCheckConfig;
bool CheckConfig()
{
struct stat stats;
time_t tm_dt;
stat(e3dc_config.conffile,&stats);
tm_dt = *(&stats.st_mtime);
if (tm_dt==tm_CONF_dt)
return false; else return true;
}
bool GetConfig()
{
// ermitteln location der conf-file
// get conf parameters
bool fpread=false;
struct stat stats;
FILE *fp;
fp = fopen(e3dc_config.conffile, "r");
if(!fp) {
sprintf(e3dc_config.conffile,"%s",CONF_FILE);
fp = fopen(CONF_FILE, "r");
}
if(fp) {
FILE *sfp;
char fbuf[127];
bool bf;
sprintf(fbuf,"%s.check",e3dc_config.conffile);
sfp = fopen(fbuf, "w");
stat(e3dc_config.conffile,&stats);
tm_CONF_dt = *(&stats.st_mtime);
char var[128], value[128], line[256];
e3dc_config.wallbox = false;
e3dc_config.openWB = false;
e3dc_config.ext1 = false;
e3dc_config.ext2 = false;
e3dc_config.ext3 = false;
e3dc_config.ext7 = false;
sprintf(e3dc_config.logfile,"logfile");
sprintf(e3dc_config.openWBhost,"%s",OPENWB);
e3dc_config.debug = false;
e3dc_config.wurzelzaehler = 0;
e3dc_config.untererLadekorridor = UNTERERLADEKORRIDOR;
e3dc_config.obererLadekorridor = OBERERLADEKORRIDOR;
e3dc_config.minimumLadeleistung = MINIMUMLADELEISTUNG;
e3dc_config.maximumLadeleistung = MAXIMUMLADELEISTUNG;
e3dc_config.wrleistung = WRLEISTUNG;
e3dc_config.speichergroesse = SPEICHERGROESSE;
e3dc_config.winterminimum = WINTERMINIMUM;
e3dc_config.sommermaximum = SOMMERMAXIMUM;
e3dc_config.sommerladeende = SOMMERLADEENDE;
e3dc_config.einspeiselimit = EINSPEISELIMIT;
e3dc_config.ladeschwelle = LADESCHWELLE;
e3dc_config.ladeende = LADEENDE;
e3dc_config.ladeende2 = LADEENDE2;
e3dc_config.unload = 100;
e3dc_config.ht = 0;
e3dc_config.htsat = false;
e3dc_config.htsun = false;
e3dc_config.hton = 0;
e3dc_config.htoff = 24*3600; // in Sekunden
e3dc_config.htsockel = 0;
e3dc_config.peakshave = 0;
e3dc_config.wbmode = 4;
e3dc_config.wbminlade = 1000;
e3dc_config.wbminSoC = 10;
e3dc_config.hoehe = 50;
e3dc_config.laenge = 10;
e3dc_config.aWATTar = false;
e3dc_config.Avhourly = 10; // geschätzter stündlicher Verbrauch in %
e3dc_config.AWDiff = 100; // Differenzsockel in €/MWh
e3dc_config.AWAufschlag = 1.2;
e3dc_config.AWtest = 0;
bf = true;
while (fgets(line, sizeof(line), fp)) {
fpread = true;
memset(var, 0, sizeof(var));
memset(value, 0, sizeof(value));
if(sscanf(line, "%[^ \t=]%*[\t ]=%*[\t ]%[^\n]", var, value) == 2) {
if(strcmp(var, "server_ip") == 0)
strcpy(e3dc_config.server_ip, value);
else if(strcmp(var, "server_port") == 0)
e3dc_config.server_port = atoi(value);
else if(strcmp(var, "e3dc_user") == 0)
strcpy(e3dc_config.e3dc_user, value);
else if(strcmp(var, "e3dc_password") == 0)
strcpy(e3dc_config.e3dc_password, value);
else if(strcmp(var, "aes_password") == 0)
strcpy(e3dc_config.aes_password, value);
else if(strcmp(var, "openWBhost") == 0)
strcpy(e3dc_config.openWBhost, value);
else if(strcmp(var, "wurzelzaehler") == 0)
e3dc_config.wurzelzaehler = atoi(value);
else if((strcmp(var, "wallbox") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.wallbox = true;
else if((strcmp(var, "openWB") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.openWB = true;
else if((strcmp(var, "ext1") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext1 = true;
else if((strcmp(var, "ext2") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext2 = true;
else if((strcmp(var, "ext3") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext3 = true;
else if((strcmp(var, "ext7") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext7 = true;
else if(strcmp(var, "logfile") == 0)
strcpy(e3dc_config.logfile, value);
else if((strcmp(var, "debug") == 0)&&
(strcmp(value, "true") == 0))
{e3dc_config.debug = true;
}
else if(strcmp(var, "untererLadekorridor") == 0)
e3dc_config.untererLadekorridor = atoi(value);
else if(strcmp(var, "obererLadekorridor") == 0)
e3dc_config.obererLadekorridor = atoi(value);
else if(strcmp(var, "minimumLadeleistung") == 0)
e3dc_config.minimumLadeleistung = atoi(value);
else if(strcmp(var, "maximumLadeleistung") == 0)
e3dc_config.maximumLadeleistung = atoi(value);
else if(strcmp(var, "wrleistung") == 0)
e3dc_config.wrleistung = atoi(value);
else if(strcmp(var, "speichergroesse") == 0)
e3dc_config.speichergroesse = atof(value);
else if(strcmp(var, "winterminimum") == 0)
e3dc_config.winterminimum = atof(value);
else if(strcmp(var, "sommermaximum") == 0)
e3dc_config.sommermaximum = atof(value);
else if(strcmp(var, "sommerladeende") == 0)
e3dc_config.sommerladeende = atof(value);
else if(strcmp(var, "einspeiselimit") == 0)
e3dc_config.einspeiselimit = atof(value);
else if(strcmp(var, "ladeschwelle") == 0)
e3dc_config.ladeschwelle = atoi(value);
else if(strcmp(var, "ladeende") == 0)
e3dc_config.ladeende = atoi(value);
else if(strcmp(var, "ladeende2") == 0)
e3dc_config.ladeende2 = atoi(value);
else if(strcmp(var, "unload") == 0)
e3dc_config.unload = atoi(value);
else if(strcmp(var, "htmin") == 0)
e3dc_config.ht = atoi(value);
else if(strcmp(var, "htsockel") == 0)
e3dc_config.htsockel = atoi(value);
else if(strcmp(var, "wbmode") == 0)
e3dc_config.wbmode = atoi(value);
else if(strcmp(var, "wbminlade") == 0)
e3dc_config.wbminlade = atoi(value);
else if(strcmp(var, "wbminSoC") == 0)
e3dc_config.wbminSoC = atof(value);
else if(strcmp(var, "hoehe") == 0)
e3dc_config.hoehe = atof(value);
else if(strcmp(var, "laenge") == 0)
e3dc_config.laenge = atof(value);
else if(strcmp(var, "peakshave") == 0)
e3dc_config.peakshave = atoi(value); // in Watt
else if(strcmp(var, "hton") == 0)
e3dc_config.hton = atof(value)*3600; // in Sekunden
else if(strcmp(var, "htoff") == 0)
e3dc_config.htoff = atof(value)*3600; // in Sekunden
else if((strcmp(var, "htsat") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.htsat = true;
else if((strcmp(var, "htsun") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.htsun = true;
else if((strcmp(var, "aWATTar") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.aWATTar = true;
else if(strcmp(var, "Avhourly") == 0)
e3dc_config.Avhourly = atof(value); // % der SoC
else if(strcmp(var, "AWDiff") == 0)
e3dc_config.AWDiff = atof(value)*10; // % der SoC
else if(strcmp(var, "AWAufschlag") == 0)
e3dc_config.AWAufschlag = 1 + atof(value)/100; // % der SoC
else if(strcmp(var, "AWtest") == 0)
e3dc_config.AWtest = atoi(value); // Testmodus 0 = Idel, 1 = Entlade, 2 = Netzladen mit Begrenzung 3 = Netzladen ohne Begrenzung
else
bf = false;
if (bf)
fprintf(sfp,"%s = %s\n",var,value);
else
bf = true;
}
}
// printf("e3dc_user %s\n",e3dc_config.e3dc_user);
// printf("e3dc_password %s\n",e3dc_config.e3dc_password);
// printf("aes_password %s\n",e3dc_config.aes_password);
fclose(fp);
fclose(sfp);
}
if ((!fp)||not (fpread)) printf("Configurationsdatei %s nicht gefunden",CONF_FILE);
return fpread;
}
time_t tLadezeitende,tLadezeitende1,tLadezeitende2,tLadezeitende3; // dynamische Ladezeitberechnung aus dem Cosinus des lfd Tages. 23 Dez = Minimum, 23 Juni = Maximum
int LoadDataProcess(SRscpFrameBuffer * frameBuffer) {
// const int cLadezeitende1 = 12.5*3600; // Sommerzeit -2h da GMT = MEZ - 2
printf("\n");
tm *ts;
ts = gmtime(&tE3DC);
hh = t % (24*3600)/3600;
mm = t % (3600)/60;
ss = t % (60);
static float fstrompreis;
if (((tE3DC % (24*3600))+12*3600)<t) {
// Erstellen Statistik, Eintrag Logfile
GetConfig(); //Lesen Parameter aus e3dc.config.txt
sprintf(Log,"Time %s U:%0.04f td:%0.04f yd:%0.04f WB%0.04f", strtok(asctime(ts),"\n"),fSavedtotal/3600000,fSavedtoday/3600000,fSavedyesderday/3600000,fSavedWB/3600000);
WriteLog();
if (fSavedtoday > 0)
{
FILE *fp;
fp = fopen("savedtoday.txt", "a");
if(!fp)
fp = fopen("savedtoday.txt", "w");
if(fp){
fprintf(fp,"%s\n",Log);
fclose(fp);}
}
fSavedyesderday=fSavedtoday; fSavedtoday=0;
fSavedtotal=0; fSavedWB=0;
}
t = tE3DC % (24*3600);
static time_t t_config = tE3DC;
if ((tE3DC-t_config) > 10)
{
if (CheckConfig()) // Config-Datei hat sich geändert;
{
// printf("Config geändert");
GetConfig();
bCheckConfig = true;
// printf("Config neu eingelesen");
}
t_config = tE3DC;
}
#
float fLadeende = e3dc_config.ladeende;
float fLadeende2 = e3dc_config.ladeende2;
float fLadeende3 = e3dc_config.unload;
if (cos((ts->tm_yday+9)*2*3.14/365) > 0)
{
fLadeende = (cos((ts->tm_yday+9)*2*3.14/365))*((100+e3dc_config.ladeende2)/2-fLadeende)+fLadeende;
fLadeende2 = (cos((ts->tm_yday+9)*2*3.14/365))*(100-fLadeende2)+fLadeende2;
fLadeende3 = (cos((ts->tm_yday+9)*2*3.14/365))*(100-fLadeende3)+fLadeende3;
}
int cLadezeitende1 = (e3dc_config.winterminimum+(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
int cLadezeitende2 = (e3dc_config.winterminimum+0.5+(e3dc_config.sommerladeende-e3dc_config.winterminimum-0.5)/2)*3600; // eine halbe Stunde Später
int cLadezeitende3 = (e3dc_config.winterminimum-(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600; //Unload
int32_t tZeitgleichung;
tLadezeitende1 = cLadezeitende1+cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
tLadezeitende2 = cLadezeitende2+cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommerladeende-e3dc_config.winterminimum-0.5)/2)*3600;
tLadezeitende3 = cLadezeitende3-cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
// float fht = e3dc_config.ht * cos((ts->tm_yday+9)*2*3.14/365);
float fht = e3dc_config.htsockel + (e3dc_config.ht-e3dc_config.htsockel) * cos((ts->tm_yday+9)*2*3.14/365);
// HT Endeladeleistung freigeben
// Mo-Fr wird während der Hochtarif der Speicher zwischen hton und htoff endladen
// Samstag und Sonntag nur wenn htsat und htsun auf true gesetzt sind.
// Damit kann gleich eine intelligente Notstromreserve realisiert werden.
// Die in ht eingestellte Reserve wird zwischen diesem Wert und 0% zur Tag-Nachtgleiche gesetzt
// Die Notstromreserve im System ist davon unberührt
if (iLMStatus == 1)
{
int ret; // Steuerung Netzladen = 2, Entladen = 1
ret = CheckaWATTar(sunriseAt,sunsetAt,fBatt_SOC,fht,e3dc_config.Avhourly,e3dc_config.AWDiff,e3dc_config.AWAufschlag,e3dc_config.maximumLadeleistung/e3dc_config.speichergroesse/10,1,fstrompreis); // Ladeleistung in %
switch (e3dc_config.AWtest) // Testfunktion
{
case 2:
if (fBatt_SOC > fht-1) break; // do nothink
case 3: ret = 2; break;
case 1: ret = 1;
}
if (ret == 2)
{
iE3DC_Req_Load = e3dc_config.maximumLadeleistung*1.9;
// printf("Netzladen an");
// iE3DC_Req_Load = e3dc_config.maximumLadeleistung*0.8;
iLMStatus = -7;
bDischargeDone = false;
return 0;
}
ts = gmtime(&tE3DC);
if ( // Das Entladen aus dem Speicher
( // wird freigegeben nach den ht/nt Regeln oder aWATTat
( // ht Regel
(ts->tm_wday>0&&ts->tm_wday<6) || // Montag - Freitag
((ts->tm_wday==0)&&e3dc_config.htsun) // Sonntag ohne Sperre
||
((ts->tm_wday==6)&&e3dc_config.htsat)
)&& // Samstag ohne Sperre
(
((e3dc_config.hton > e3dc_config.htoff) && // außerhalb der ht sperrzeiten
((e3dc_config.hton < t) ||
(e3dc_config.htoff > t )))
||
((e3dc_config.hton < e3dc_config.htoff) &&
(e3dc_config.hton < t && e3dc_config.htoff > t ))
) // Das Entladen wird durch hton/htoff zugelassen
) //
// || (CheckaWATTar(sunriseAt,sunsetAt,fBatt_SOC,e3dc_config.Avhourly,e3dc_config.AWDiff)==1) // Rückgabewert aus CheckaWattar
|| (ret==1) // Rückgabewert aus CheckaWattar
// Das Entladen wird zu den h mit den höchsten Börsenpreisen entladen
||
(fht<fBatt_SOC) // Wenn der SoC > der berechneten Reserve liegt
||(iNotstrom==1) //Notstrom
||(iNotstrom==4) //Inselbetrieb
){
// ENdladen einschalten)
if ((iPower_Bat == 0)&&(fPower_Grid>100)&&fBatt_SOC>0.5)
{ sprintf(Log,"BAT %s %0.02f %i %i% 0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();
iLMStatus = 10;
}
bDischarge = true;
/*
if (iDischarge < e3dc_config.maximumLadeleistung) {
Control_MAX_DISCHARGE(frameBuffer,e3dc_config.maximumLadeleistung);
iBattPowerStatus = 0;
iLMStatus = 5;
sprintf(Log,"Ein %s %0.02f %0.02f %i", strtok(asctime(ts),"\n"),fht,fBatt_SOC, iE3DC_Req_Load);
WriteLog();
}
*/
} else {
bDischarge = false;
/* // Endladen ausschalten
if (iDischarge >1)
// Ausschalten nur wenn nicht im Notstrom/Inselbetrieb
{ Control_MAX_DISCHARGE(frameBuffer,0);
iBattPowerStatus = 0;
iLMStatus = 5;
sprintf(Log,"AUS %s %0.02f %0.02f %i", strtok(asctime(ts),"\n"),fht,fBatt_SOC, iE3DC_Req_Load);
WriteLog();
;}
*/
}
// printf("ret %i",ret);
// if (ret<2)
if (not bDischarge) // Entladen soll unterdrückt werden
{ if ((fPower_Grid < -100)&&(iPower_Bat==0)) // es wird eingespeist Entladesperre solange aufheben
{
iE3DC_Req_Load = fPower_Grid*-1; // Es wird eingespeist
iLMStatus = -7;
printf("Batterie laden zulassen ");
// return 0;
} else
// if (((iPower_Bat < -100)||((iPower_Bat==0)&&(fPower_Grid>100)))&&((fPower_WB==0)||(iPower_PV<100))) // Entladen zulassen wenn WB geladen wird
// if (((iPower_Bat < -100)||((iPower_Bat==0)&&(fPower_Grid>100)))) // Entladen zulassen wenn WB
if (((iPower_Bat < -100)||((iPower_Bat<=0)&&(fPower_Grid>100)))) // Entladen zulassen wenn WB
{
iE3DC_Req_Load = 0; // Sperren
if (iPower_PV > 0)
iE3DC_Req_LoadMode = -2; //Entlademodus \n
// printf("\nEntladen stoppen ");
iLMStatus = -7;
// return 0;
}
}
else // Entladen ok
if ((fPower_Grid > 100)&&(iPower_Bat ==0)&&fBatt_SOC>0.5) // es wird Strom bezogen Entladesperre solange aufheben
{
iE3DC_Req_Load = fPower_Grid*-1; //Automatik anstossen
// if (iE3DC_Req_Load < e3dc_config.maximumLadeleistung*-1) //Auf maximumLadeleistung begrenzen
// iE3DC_Req_Load = e3dc_config.maximumLadeleistung*-1; //Automatik anstossen
printf("Entladen starten ");
iLMStatus = -7;
// return 0;
}
}
// HT Endeladeleistung freigeben ENDE
// Berechnung freie Ladekapazität bis 90% bzw. Ladeende
tZeitgleichung = (-0.171*sin(0.0337 * ts->tm_yday + 0.465) - 0.1299*sin(0.01787 * ts->tm_yday - 0.168))*3600;
tLadezeitende1 = tLadezeitende1 - tZeitgleichung;
tLadezeitende2 = tLadezeitende2 - tZeitgleichung;
tLadezeitende3 = tLadezeitende3 - tZeitgleichung;
tLadezeitende = tLadezeitende1;
printf("RB %2ld:%2ld %0.1f%% ",tLadezeitende3/3600,tLadezeitende3%3600/60,fLadeende3);
printf("RE %2ld:%2ld %0.1f%% ",tLadezeitende1/3600,tLadezeitende1%3600/60,fLadeende);
printf("LE %2ld:%2ld %0.1f%% ",tLadezeitende2/3600,tLadezeitende2%3600/60,fLadeende2);
if (e3dc_config.aWATTar) printf("%.2f",fstrompreis);
printf("\n");
// Überwachungszeitraum für das Überschussladen übschritten und Speicher > Ladeende
// Dann wird langsam bis Abends der Speicher bis 93% geladen und spätestens dann zum Vollladen freigegeben.
if (t < tLadezeitende3) {
// tLadezeitende = tLadezeitende3;
// Vor Regelbeginn. Ist der SoC > fLadeende3 wird entladen
// wenn die Abweichung vom SoC < 0.3% ist wird als Ziel der aktuelle SoC genommen
// damit wird ein Wechsel von Laden/Endladen am Ende der Periode verhindert
if ((fBatt_SOC-fLadeende3) > 0){
if ((fBatt_SOC-fLadeende3) < 0.6)
fLadeende = fBatt_SOC; else
// Es wird bis tLadezeitende3 auf fLadeende3 entladen
fLadeende = fLadeende3;
tLadezeitende = tLadezeitende3;}
}
else
if ((t >= tLadezeitende)&&(fBatt_SOC>=fLadeende)) {
tLadezeitende = tLadezeitende2;
if (fLadeende < fLadeende2)
fLadeende = fLadeende2;
}
if (t < tLadezeitende2)
// Berechnen der linearen Ladeleistung bis tLadezeitende2 = Sommerladeende
{iMinLade2 = ((fLadeende2 - fBatt_SOC)*e3dc_config.speichergroesse*10*3600)/(tLadezeitende2-t);
if (iMinLade2>e3dc_config.maximumLadeleistung)
iMinLade2=e3dc_config.maximumLadeleistung;
}
else
if (fLadeende2 <= fBatt_SOC) iMinLade2 = 0;
else iMinLade2 = e3dc_config.maximumLadeleistung;
if (t < tLadezeitende)
{
if ((fBatt_SOC!=fBatt_SOC_alt)||(t-tLadezeit_alt>300)||(tLadezeitende!=tLadezeitende_alt)||(iFc == 0)||bCheckConfig)
// Neuberechnung der Ladeleistung erfolgt, denn der SoC sich ändert oder
// tLadezeitende sich ändert oder nach Ablauf von höchstens 5 Minuten
{
fBatt_SOC_alt=fBatt_SOC; // bei Änderung SOC neu berechnen
bCheckConfig=false;
tLadezeitende_alt = tLadezeitende; // Auswertungsperiode
tLadezeit_alt=t; // alle 300sec Berechnen
// Berechnen der Ladeleistung bis zum nächstliegenden Zeitpunkt
iFc = (fLadeende - fBatt_SOC)*e3dc_config.speichergroesse*10*3600;
if ((tLadezeitende-t) > 300)
iFc = iFc / (tLadezeitende-t); else
iFc = iFc / (300);
if (iFc > e3dc_config.maximumLadeleistung)
iMinLade = e3dc_config.maximumLadeleistung;
else
iMinLade = iFc;
// iFc = (iFc-900)*5;
if (iFc >= e3dc_config.untererLadekorridor)
iFc = (iFc-e3dc_config.untererLadekorridor);
else
if (abs(iFc) >= e3dc_config.untererLadekorridor)
iFc = (iFc+e3dc_config.untererLadekorridor);
else
iFc = 0;
iFc = iFc*(float(e3dc_config.maximumLadeleistung)/(e3dc_config.obererLadekorridor-e3dc_config.untererLadekorridor));
if (iFc > e3dc_config.maximumLadeleistung) iFc = e3dc_config.maximumLadeleistung;
if (abs(iFc) > e3dc_config.maximumLadeleistung) iFc = e3dc_config.maximumLadeleistung*-1;
if (abs(iFc) < e3dc_config.minimumLadeleistung) iFc = 0;
}
}
else
{ iFc = e3dc_config.maximumLadeleistung;
if (fBatt_SOC < fLadeende)
iMinLade = iFc;
else
iMinLade = 0;
}
// Laden auf 100% nach 15:30
if (iMinLade == iMinLade2)
printf("ML1 %i RQ %i ",iMinLade,iFc);
else
printf("ML1 %i ML2 %i RQ %i ",iMinLade, iMinLade2,iFc);
printf("GMT %2ld:%2ld ZG %d ",tLadezeitende/3600,tLadezeitende%3600/60,tZeitgleichung);
printf("E3DC: %s", asctime(ts));
int iPower = 0;
if (iLMStatus == 0){
iLMStatus = 5;
tLadezeit_alt = 0;
// iBattLoad = e3dc_config.maximumLadeleistung;
// iBattLoad = 100;
// fAvBatterie = e3dc_config.untererLadekorridor;
// ControlLoadData2(frameBuffer,iBattLoad);
}
if (iAvBatt_Count < 120) iAvBatt_Count++;
fAvBatterie = fAvBatterie*(iAvBatt_Count-1)/iAvBatt_Count;
fAvBatterie = fAvBatterie + (float(iPower_Bat)/iAvBatt_Count);
if (iAvBatt_Count900 < 900) iAvBatt_Count900++;
fAvBatterie900 = fAvBatterie900*(iAvBatt_Count900-1)/iAvBatt_Count900;
fAvBatterie900 = fAvBatterie900 + (float(iPower_Bat)/iAvBatt_Count900);
// Überschussleistung=iPower ermitteln
iPower = (-iPower_Bat + int32_t(fPower_Grid) - e3dc_config.einspeiselimit*-1000)*-1;
// die PV-leistung kann die WR-Leistung überschreiten. Überschuss in den Speicher laden;
if ((iPower_PV_E3DC - e3dc_config.wrleistung) > iPower)
iPower = (iPower_PV_E3DC - e3dc_config.wrleistung);
// if (iPower < 50) iPower = 0;
// else
// if (iPower > e3dc_config.maximumLadeleistung) iPower = e3dc_config.maximumLadeleistung;
// else
// if (iPower <100) iPower = 100;
// Ermitteln Überschuss/gesicherte Leistungen
if (iPower > 0)
{if (iPower >iPower_Bat)
fSavedtoday = fSavedtoday + iPower_Bat;
else
fSavedtoday = fSavedtoday + iPower;}
if (iPower_PV > e3dc_config.einspeiselimit*1000)
{fSavedtotal = iPower_PV - e3dc_config.einspeiselimit*1000 + fSavedtotal;
if (fPower_WB>0)
if ((fPower_WB-fPower_Grid+iPower_Bat)>e3dc_config.einspeiselimit*1000)
fSavedWB = fSavedWB+fPower_WB-fPower_Grid+iPower_Bat-e3dc_config.einspeiselimit*1000;
}
if (((fBatt_SOC > e3dc_config.ladeschwelle)&&(t<tLadezeitende))||(fBatt_SOC > e3dc_config.ladeende))
{
// Überprüfen ob vor RE der SoC > tLadeende2 ist, dann entladen was möglich
if ((t>tLadezeitende3)&&(t<tLadezeitende1)&&(fBatt_SOC>fLadeende2))
iFc = e3dc_config.maximumLadeleistung*-1;
if (iPower<iFc)
{ iPower = iFc;
if ((iPower>0)&&(iPower > fAvBatterie900)) iPower = iPower + pow((iPower-fAvBatterie900),2)/20;
// Nur wenn positive Werte angefordert werden, wird dynamisiert
if (iPower > e3dc_config.maximumLadeleistung) iPower = e3dc_config.maximumLadeleistung;
}
} else
// if (fBatt_SOC < cLadeende) iPower = 3000;
// else iPower = 0;
iPower = e3dc_config.maximumLadeleistung;
if (e3dc_config.wallbox&&(bWBStart||bWBConnect)&&(bWBStopped||(iWBStatus>1))&&(e3dc_config.wbmode>1)
&&(((t<tLadezeitende1)&&(e3dc_config.ladeende>fBatt_SOC))||
((t>tLadezeitende1)&&(e3dc_config.ladeende2>fBatt_SOC)))
&&
((tE3DC-tWBtime)<7200)&&((tE3DC-tWBtime)>10))
// Wenn Wallbox vorhanden und das letzte Laden liegt nicht länger als 900sec zurück
// und wenn die Wallbox gestoppt wurde, dann wird für bis zu 2h weitergeladen
// oder bis der SoC ladeende2 erreicht hat
// oder solange iWBStatus > 1 ist
iPower = e3dc_config.maximumLadeleistung; // mit voller Leistung E3DC Speicher laden
// if (((abs( int(iPower - iPower_Bat)) > 30)||(t%3600==0))&&(iLMStatus == 1))
// if (((abs( int(iPower - iBattLoad)) > 30)||(abs(t-tE3DC_alt)>3600*3))&&(iLMStatus == 1))
if (iLMStatus == 1)
{
{
if (iBattLoad > (iPower_Bat-iDiffLadeleistung))
iDiffLadeleistung = iBattLoad-iPower_Bat+iDiffLadeleistung;
if ((iDiffLadeleistung < 0 )||(abs(iBattLoad)<=100)) iDiffLadeleistung = 0;
if (iDiffLadeleistung > 100 )iDiffLadeleistung = 100; //Maximal 100W vorhalten
if (abs(iPower+iDiffLadeleistung) > e3dc_config.maximumLadeleistung) iDiffLadeleistung = 0;
/* if (iLMStatus == 1) {
iBattLoad = iPower;
tE3DC_alt = t;
ControlLoadData2(frameBuffer,(iBattLoad+iDiffLadeleistung));
iLMStatus = 7;
}
*/
// Steuerung direkt über vorgabe der Batterieladeleistung
// -iPower_Bat + int32_t(fPower_Grid)
if (iLMStatus == 1) {
// Es wird nur Morgens bis zum Winterminimum auf ladeende entladen;
// Danach wird nur bis auf ladeende2 entladen.
if ((iPower < 0)&&((t>e3dc_config.winterminimum*3600)&&(fBatt_SOC<e3dc_config.ladeende2)))
iPower = 0;
// Wenn der SoC > >e3dc_config.ladeende2 wird mit der Speicher max verfügbaren Leistung entladen
// if ((iPower < 0)&&((t>tLadezeitende1)&&(fBatt_SOC>e3dc_config.ladeende2)))
// iPower = e3dc_config.maximumLadeleistung*-1;
iBattLoad = iPower;
tE3DC_alt = t;
{
if ((iPower<e3dc_config.maximumLadeleistung)&&(iPower > ((iPower_Bat - int32_t(fPower_Grid))/2)))
// die angeforderte Ladeleistung liegt über der verfügbaren Ladeleistung
{if ((fPower_Grid > 100)&&(iE3DC_Req_Load_alt<(e3dc_config.maximumLadeleistung-1)))
// es liegt Netzbezug vor und System war nicht im Freilauf
{iPower = iPower_Bat - int32_t(fPower_Grid);
// Einspeichern begrenzen oder Ausspeichern anfordern, begrenzt auf e3dc_config.maximumLadeleistung
if (iPower < e3dc_config.maximumLadeleistung*-1)
iPower = e3dc_config.maximumLadeleistung*-1;
}
else
iPower = e3dc_config.maximumLadeleistung;}
// Wenn die angeforderte Leistung großer ist als die vorhandene Leistung
// wird auf Automatik umgeschaltet, d.h. Anforderung Maximalleistung;
// if (iPower >0)
// ControlLoadData(frameBuffer,(iPower+iDiffLadeleistung),3);
// Es wird nur die Variable mit dem Sollwert gefüllt
// die Variable wird im Mainloop überprüft und im E3DC gesetzt
// wenn iLMStatus einen negativen Wert hat
if (iPower > e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung-1; else
iE3DC_Req_Load = iPower+iDiffLadeleistung;
if (iE3DC_Req_Load >e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung;
if (iPower_PV>0) // Nur wenn die Sonne scheint
{
static int iLastReq;
if (((iE3DC_Req_Load_alt) >= (e3dc_config.maximumLadeleistung-1))&&(iE3DC_Req_Load>=(e3dc_config.maximumLadeleistung-1)))
// Wenn der aktuelle Wert >= e3dc_config.maximumLadeleistung-1 ist
// und der zuletzt angeforderte Werte auch >= e3dc_config.maximumLadeleistung-1
// war, bleibt der Freilauf erhalten
{ iLMStatus = 3;
if (iLastReq>0)
{sprintf(Log,"CTL %s %0.02f %i %i %0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();
iLastReq--;}
}
else
{
// testweise kein Freilauf
if (iE3DC_Req_Load == e3dc_config.maximumLadeleistung)
{iLMStatus = 3;
iE3DC_Req_Load_alt = iE3DC_Req_Load;
}else
iLMStatus = -6;
iLastReq = 6;
sprintf(Log,"CTL %s %0.02f %i %i %0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();}