-
Notifications
You must be signed in to change notification settings - Fork 19
/
ht_discode.py
executable file
·4379 lines (3941 loc) · 199 KB
/
ht_discode.py
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
#! /usr/bin/python3
#
#################################################################
## Copyright (c) 2013 Norbert S. <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#################################################################
# Ver:0.1.8 / Datum 07.02.2016 new modul based on:
# ht3_dispatch.py Ver:0.1.7.1/ Datum 04.03.2015
# and
# ht3_decode.py Ver:0.1.7.1/ Datum 04.03.2015
# additonal modifications are:
# 'new telegram 88 00 2a 00' added (TR-10F)
# 'new telegram 90 08 1a 00' added (FW/FR1x0)
# 'new telegram 88 10 16 00' added (heater-details)
# message:88001800 with length:=31 or 33
# message:9000ff00 with length:=29 added
# 'IPM_LastschaltmodulMsg' buscoding assigned to a0...af
# message:9000ff00 with length:=29 and 32 Byte added
# HeizkreisMsg_ID677_max33byte added for CWxyz handling
# Heating-circuit assignment corrected (6F...72).
# Ver:0.1.8.1/ Datum 10.02.2016 Methode: HeizkreisMsg_ID677_max33byte()
# 'Tsoll_HK' assigned to Byte12
# 'Vbetriebs_art' assigned to Byte27
# Ver:0.1.8.2/ Datum 22.02.2016 'IPM_LastschaltmodulWWModeMsg()'.
# fix for wrong msg-detection: 'a1 00 34 00'
# 'IPM_LastschaltmodulMsg()' fixed wrong HK-circuit assignment
# Ver:0.1.9 / Datum 27.04.2016 'HeizkreisMsg_ID677_max33byte()' corrected.
# 'msg_88002a00()' betriebsart assignment deleted
# 'HeizkreisMsg_FW100_200_xybyte()' entfaellt.
# Ver:0.1.10 / Datum 22.08.2016 Redesign of modul for MsgID-messageshandling.
# 'SolarMsg()' modified for msgID866 and
# for msgID910
# Display- and cause-code added for error-reports
# 'SolarMsg()' corrected
# message-ID handling added
# "Vbetriebs_art" replaced with "Voperation_status"
# Heater active time changed from minutes to hours.
# Ver:0.2 / Datum 29.08.2016 Fkt.doc added, minor debugtext-changes.
# Ver:0.2.2 / Datum 14.10.2016 CW100:=157 added on MsgID 2.
# no decoding of 'T_Soll' anymore at msgID:=53.
# 'msgID_259_Solar()' modified, 3-bytes for solarpump-runtime.
# 'msgID_51_DomesticHotWater()' added.
# 'msgID_296_ErrorMsg()' added.
# 'msgID_188_Hybrid()' corrected.
# Ver:0.2.3 / Datum 17.01.2017 'msgID_52_DomesticHotWater()' corrected.
# MsgID:24 for device:(10)hex added, see:
# https://www.mikrocontroller.net/topic/324673#4864801
# Ver:0.3 / Datum 19.06.2017 now debug-output in _search_4_transceiver_message().
# controller- and bus-type handling added.
# Ver:0.3.1 / Datum 18.01.2019 modified 'deviceadr_2msgid_blacklist[]'
# modified msgID_22_Heaterdevice()
# msgID_26_HeatingCircuit_HK1() updated and renamed
# msgID_30_T_HydraulischeWeiche() THydr.Device added
# msgID_35_HydraulischeWeiche() updated with hc_pump
# msgID_51_DomesticHotWater() saving data on target:= 0 only
# msgID_596_HeatingCircuit() added
# msgID_597_HeatingCircuit() added
# msgID_697_704_HeatingCircuit() Tsoll_HK
# msgID_727_734_HeatingCircuit() added
# msgID_737_744_HeatingCircuit() added
# msgID_747_754_HeatingCircuit() Frostdanger added
# _IsRequestCall() and _RequestCall() added
# msgID_569_HeatingCircuit() added
# msgID_52_DomesticHotWater() modified for tempsensor failure detection
# msgID_30_T_HydraulischeWeiche() modified for 'ch_Thdrylic_switch'
# using logitem HG:V_spare2.
# msgID_25_Heaterdevice() 'ch_Thdrylic_switch' (V_spare2) added.
# update of display errorcode-handling.
# modified 'msgID_260_Solar()', SO:V_spare_1 & SO:V_spare_2 used now.
# SO:'V_ertrag_sum_calc' used now for SO:'Ertrag Summe'
# msgID_52_DomesticHotWater() storing data only if valid.
# Ver:0.3.2 / Datum 08.09.2020 modified 'msgID_51_DomesticHotWater' for storing 'T-Soll max'
# no decoding if length is <= 8 for EMS2 heating-circuit messages.
# 'msgID_52_DomesticHotWater()' modified handling for not available sensor-values.
# Ver:0.3.3 / 2022-01-23 added devices 0x40 and 0x41 to 'deviceaddress_white_list[]'
# activated '_remove_black_sequences()' handling.
# see URL: https://www.mikrocontroller.net/topic/324673?page=single#6579738.
# In msgID_26_HeatingCircuit() 'i_tvorlauf_soll' now independant from 'IPM_MM_Modul_Flag'.
# In msgID_367_370_HeatingCircuit() 'i_TsolarSupport' not saved to database anymore.
# 'msgID_191_194_ErrorCodeDetails()' added for msgID's:191 to 194.
# Ver:0.4 / 2023-03-12 BusmodulAdr - handling added, msgID_190_DisplayAndCauseCode() modified for remote controller.
# 0x1b added to deviceaddress_white_list[]
# msgID_2 new busmember-numbers added.
# msgID_870_Solar() added.
# in 'black_sequence'- and 'deviceadr_2msgid_blacklist'-list values added.
# issues #18 and #20
# Ver:0.5 / 2023-04-22 Display- and Error-Code extract from MsgID: 190
# issue #21
# msgID_16_19_DisplayErrorCodeMsg() added.
# pressure activated.
# Ver:0.5.1 / 2023-06-07 tempfile handling added in cht_decode()__init__() and
# cht_discode()__init__()
# Ver:0.6 / 2023-10-06 issue:#28 solaroption handling added
# issue:#21, msgID_296_ErrorMsg() modified.
# msgID_257_Solar(), msgID_856_Solar() and msgID_858_Solar() added.
# msgID_937_Solar() & msgID_938_Solar() added.
# msgID_874_Solar() PS2/3 set on/off using Byte 7.
# msgID_874_Solar() PS7 set on/off using Byte 17.
# msgID_857_Solar() and msgID_862_864_865_Solar() added.
# __Setheatercircuits_amount() added.
# GetMessageID() modified.
# Ver:0.6.1 / 2023-10-21 issue:#28 modified MsgID:866 (TS4->TS8)
import tempfile
import serial
import data
import db_sqlite
import ht_utils
import ht_const
import ht_proxy_if
__author__ = "junky-zs"
__status__ = "draft"
class cht_decode(ht_utils.cht_utils):
"""
class cht_decode for decoding heatronic heater-messages.
"""
oldcrc_8800bc = 0
def __init__(self, gdata, logger=None):
ht_utils.cht_utils.__init__(self)
try:
# init/setup logging-file
if logger == None:
ht_utils.clog.__init__(self)
filepath = os.path.join(tempfile.gettempdir(),"cht_decode.log")
self._logging = ht_utils.clog.create_logfile(self, logfilepath=filepath, loggertag="cht_decode")
else:
self._logging = logger
except:
errorstr = "cht_decode();Error;could not create logfile"
print(errorstr)
raise EnvironmentError(errorstr)
#check first the parameter
if not isinstance(gdata, data.cdata):
errorstr = 'cht_decode();TypeError;Parameter "gdata" has wrong type'
self._logging.critical(errorstr)
raise TypeError(errorstr)
self.__info_datum = "--.--.----"
self.__info_zeit = "--:--:--"
# save data-object
self.__gdata = gdata
# setup data to already available logging-object
self.__gdata.setlogger(self._logging)
self.__currentHK_nickname = "HK1"
# set default-values read from configuration
self.__gdata.setall_values2default()
def __IsInRange(self, nickname, item, value):
"""
returns True if 'value' is in valid range, defined in config else False.
"""
maxvalue = 0.0
defaultvalue = 0.0
if self.__gdata.maxvalue(nickname, item) != None:
maxvalue = float(self.__gdata.maxvalue(nickname, item))
if self.__gdata.defaultvalue(nickname, item) != None:
defaultvalue = float(self.__gdata.defaultvalue(nickname, item))
return self.IsTempInRange(value, maxvalue, defaultvalue)
def __Check4MaxValue(self, nickname, item, value):
"""
returns the 'value' itself, if it is less then maxvalue defined in configuration,
else the default value from configuration.
"""
if self.__gdata.maxvalue(nickname, item) != None:
if value > self.__gdata.maxvalue(nickname, item):
return self.__gdata.defaultvalue(nickname, item)
else:
return value
else:
return value
def __DeviceIsModem(self, device_address):
"""
returns True if the device-address in defined for 'modems', else False.
"""
rtnvalue = False
if (device_address & 0x7f) in [0x0a, 0x0b, 0x0c, 0x0d, 0x38, 0x48]:
rtnvalue = True
return rtnvalue
def __CreateHexdump(self, msgtuple, nickname, message, length):
"""
returns formated hex-string from message-input.
"""
(msgid, offset) = msgtuple
rtnvalue = ""
if isinstance(message, list) and len(message) >= length:
hexstr = ""
for x in range(0, length):
hexstr += format(message[x], "02x") + " "
rtnvalue = "{0:4}_{1:<2};{2:3}:{3}".format(msgid, offset, nickname, hexstr)
return rtnvalue
def __Debuglog(self, msgtuple, nickname, debugstring, message=None):
"""
writes the debugstring to the logger.
"""
(msgid, offset) = msgtuple
if len(debugstring) > 0:
tempstring = ""
# search for ';' in debugstring on first position, if not add one
if debugstring.find(';') != 0:
debugstring = ';' + debugstring
if message != None and isinstance(message, list):
source = (message[0] & 0x7F)
target = (message[1] & 0x7F)
tempstring = "{0:4}_{1:<2};{2};S{3:02x};T{4:02x}{5}".format(msgid, offset, nickname, source, target, debugstring)
else:
tempstring = "{0:4}_{1:<2};{2};S{3:02x};T{4:02x}{5}".format(msgid, offset, nickname, 0, 0, debugstring)
# write to logger in debug-mode
self._logging.debug(tempstring)
def __Setheatercircuits_amount(self, sourcetarget_tuple, circuit_nr):
""" set the amount of heatercircuits if message is broadcasted """
(source, target) = sourcetarget_tuple
# set only, if message is broadcast to all := 0
if not self.__DeviceIsModem(source) and target == 0:
self.__gdata.heatercircuits_amount(circuit_nr)
def GetMessageID(self, payloadheader):
"""
returns the messageID for the payload
decoded from the first bytes of the payload.
return-value is a tuple of: (msgid, offset)
"""
msgid = 0
ems2_byte = 0
if len(payloadheader) > 7:
# Is EMS-typed message ?
if payloadheader[2] >= 0xf0:
if payloadheader[2] == 0xff:
ems2_byte = int(payloadheader[2] + 1)
if (payloadheader[5]) == 0xff:
# special case handling for byte5
# EMS msg.; take Byte6 as multiplicator and add Byte7
# (byte6 + 1)*256 + byte7
msgid = ems2_byte + int(payloadheader[6]) * 256 + int(payloadheader[7])
else:
# EMS msg.; take Byte5 as multiplicator and add Byte6
# (byte5 + 1)*256 + byte6
msgid = ems2_byte + int(payloadheader[5]) * 256 + int(payloadheader[6])
if payloadheader[4] < 0xf0:
# EMS msg.; take Byte4 as multiplicator and add Byte5
# (byte4 + 1)*256 + byte5
msgid = ems2_byte + int(payloadheader[4]) * 256 + int(payloadheader[5])
else:
# handling for payloadheader[2] in range 0xf0...0xfe
# msgid forced to zero
msgid = 0
else:
# normal msg.; take Byte:2 as msg-type
msgid = int(payloadheader[2])
# take Byte 3 as msg-offset
# Is message-request forced ?
if payloadheader[1] & 0x80:
# msgid forced to zero
msgid = 0
return (msgid, payloadheader[3])
def _IsRequestCall(self, buffer):
"""
returns True if requestflag is set on TargetDevice-Byte, else False
"""
# if request-flag set, then make only hexdump
if (buffer[1] & 0x80) > 0:
return True
else:
return False
def _RequestCall(self, msgtuple, buffer, length):
"""
hexdump is created and returns (nickname,values) -tuple
"""
nickname = "DT"
(msgid, offset) = msgtuple
hexstr = self.__CreateHexdump(msgtuple, "req", buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
values = self.__gdata.values(nickname)
return (nickname, values)
def msgID_2_BusInfo(self, msgtuple, buffer, length):
"""
decoding of msgID:2 -> Businformation.
"""
nickname = "DT"
(msgid, offset) = msgtuple
if self._IsRequestCall(buffer):
return self._RequestCall(msgtuple, buffer, length)
debugstr = ""
first_payload_index = 4
# length > first index + crc-byte + break-byte
if length > first_payload_index + 2:
# init values
raw_index = offset + first_payload_index
msg_bytecount = length - first_payload_index - 2
sourcedevice = buffer[0] & 0x7f
targetdevice = buffer[1] & 0x7f
for buffer_index in range(first_payload_index, length - 2):
# read values from buffer and assign them
if raw_index == 4 and msg_bytecount >= 1:
i_busteilnehmer = buffer[buffer_index]
if i_busteilnehmer == 1:
str_busteilnehmer = "RC20"
elif i_busteilnehmer == 2:
str_busteilnehmer = "RC35"
elif i_busteilnehmer == 64:
str_busteilnehmer = "UBA3"
elif i_busteilnehmer == 65:
str_busteilnehmer = "RC10"
elif i_busteilnehmer == 66:
str_busteilnehmer = "RC20"
elif i_busteilnehmer == 67:
str_busteilnehmer = "RC30"
elif i_busteilnehmer == 68:
str_busteilnehmer = "BC10"
elif i_busteilnehmer == 69:
str_busteilnehmer = "MM10"
elif i_busteilnehmer == 70:
str_busteilnehmer = "Gaswaermepumpe"
elif i_busteilnehmer == 71:
str_busteilnehmer = "WM10"
elif i_busteilnehmer == 72:
str_busteilnehmer = "MC10"
elif i_busteilnehmer == 73:
str_busteilnehmer = "SM10"
elif i_busteilnehmer == 74:
str_busteilnehmer = "EM10"
elif i_busteilnehmer == 75:
str_busteilnehmer = "Brennerautomat"
elif i_busteilnehmer == 76:
str_busteilnehmer = "Regler ES73"
elif i_busteilnehmer == 77:
str_busteilnehmer = "Schaltmodul M300"
elif i_busteilnehmer == 78:
str_busteilnehmer = "M400"
elif i_busteilnehmer == 79:
str_busteilnehmer = "M100"
elif i_busteilnehmer == 80:
str_busteilnehmer = "M200"
elif i_busteilnehmer == 81:
str_busteilnehmer = "Kaskadenmodul CM10"
elif i_busteilnehmer == 82:
str_busteilnehmer = "Schaltmodul VM10"
elif i_busteilnehmer == 83:
str_busteilnehmer = "ServiceKey"
elif i_busteilnehmer == 84:
str_busteilnehmer = "Controller DBA"
elif i_busteilnehmer == 85:
str_busteilnehmer = "Easycom"
elif i_busteilnehmer == 86:
str_busteilnehmer = "Regler RC34"
elif i_busteilnehmer == 87:
str_busteilnehmer = "Easycom Pro"
elif i_busteilnehmer == 88:
str_busteilnehmer = "Gateway"
elif i_busteilnehmer == 89:
str_busteilnehmer = "BC10USA"
elif i_busteilnehmer == 90:
str_busteilnehmer = "RC10USA"
elif i_busteilnehmer == 91:
str_busteilnehmer = "RC10USA"
elif i_busteilnehmer == 92:
str_busteilnehmer = "UM10"
elif i_busteilnehmer == 93:
str_busteilnehmer = "Funkregler RC20F"
elif i_busteilnehmer == 94:
str_busteilnehmer = "Funkregler RFM20"
elif i_busteilnehmer == 95:
str_busteilnehmer = "Heatronic3"
elif i_busteilnehmer == 96:
str_busteilnehmer = "Funkregler RT10"
elif i_busteilnehmer == 97:
str_busteilnehmer = "TD200"
elif i_busteilnehmer == 98:
str_busteilnehmer = "AM10"
elif i_busteilnehmer == 99:
str_busteilnehmer = "ZR01"
elif i_busteilnehmer == 100:
str_busteilnehmer = "IPM1"
elif i_busteilnehmer == 101:
str_busteilnehmer = "ISM1"
elif i_busteilnehmer == 102:
str_busteilnehmer = "IPM2"
elif i_busteilnehmer == 103:
str_busteilnehmer = "ISM2"
elif i_busteilnehmer == 104:
str_busteilnehmer = "IUM1"
elif i_busteilnehmer == 105:
str_busteilnehmer = "FW100"
elif i_busteilnehmer == 106:
str_busteilnehmer = "FW200"
elif i_busteilnehmer == 107:
str_busteilnehmer = "FR100"
elif i_busteilnehmer == 108:
str_busteilnehmer = "FR110"
elif i_busteilnehmer == 109:
str_busteilnehmer = "FB10"
elif i_busteilnehmer == 110:
str_busteilnehmer = "FB100"
elif i_busteilnehmer == 111:
str_busteilnehmer = "FR10"
elif i_busteilnehmer == 112:
str_busteilnehmer = "RC10V2"
elif i_busteilnehmer == 113:
str_busteilnehmer = "RC20V2"
elif i_busteilnehmer == 114:
str_busteilnehmer = "BC15"
elif i_busteilnehmer == 115:
str_busteilnehmer = "UBA3_50"
elif i_busteilnehmer == 116:
str_busteilnehmer = "FW500"
elif i_busteilnehmer == 117:
str_busteilnehmer = "ModulinkReceiver"
elif i_busteilnehmer == 118:
str_busteilnehmer = "BRM10"
elif i_busteilnehmer == 119:
str_busteilnehmer = "FR110FRM"
elif i_busteilnehmer == 120:
str_busteilnehmer = "FR110FEM"
elif i_busteilnehmer == 121:
str_busteilnehmer = "MCC"
elif i_busteilnehmer == 122:
str_busteilnehmer = "Cux-Steuergerät CBN"
elif i_busteilnehmer == 123:
str_busteilnehmer = "Cux-Steuergerät CBS"
elif i_busteilnehmer == 124:
str_busteilnehmer = "Bedieneiheit im CUX-Steuergerät HIN"
elif i_busteilnehmer == 125:
str_busteilnehmer = "Cux-Steuergerät mit Trim Design HIS"
elif i_busteilnehmer == 126:
str_busteilnehmer = "Heatronic III für Buderusprodukte"
elif i_busteilnehmer == 127:
str_busteilnehmer = "IGM1"
elif i_busteilnehmer == 128:
str_busteilnehmer = "UBA H3"
elif i_busteilnehmer == 129:
str_busteilnehmer = "IEM"
elif i_busteilnehmer == 130:
str_busteilnehmer = "Wärmerückgewinnungseinheit HRU"
elif i_busteilnehmer == 147:
str_busteilnehmer = "FR50"
elif i_busteilnehmer == 157:
str_busteilnehmer = "CW100"
elif i_busteilnehmer == 158:
str_busteilnehmer = "CW400"
elif i_busteilnehmer == 163:
str_busteilnehmer = "MS100"
elif i_busteilnehmer == 164:
str_busteilnehmer = "MS200"
elif i_busteilnehmer == 189:
str_busteilnehmer = "Modem(MBLAN/NetCom)"
elif i_busteilnehmer == 191:
str_busteilnehmer = "FR120"
elif i_busteilnehmer == 192:
str_busteilnehmer = "FW120"
else:
str_busteilnehmer = ""
if len(str_busteilnehmer) == 0:
str_busteilnehmer = str(i_busteilnehmer)
# setup controller-type if response is from controller (source: 90h of 18h)
if sourcedevice == 0x10 or sourcedevice == 0x18:
self.__gdata.controller_type_nr(i_busteilnehmer)
self.__gdata.controller_type(str_busteilnehmer)
if (sourcedevice == 0x08 or sourcedevice == 0x09) and i_busteilnehmer == 95:
self.__gdata.bus_type(str_busteilnehmer)
debugstr += ";Bus-Response Source:{0:02x}(h) to Target:{1:02x}(h)".format(sourcedevice, targetdevice)
debugstr += " ;1.Busteilnehmer:{0};Typ:{1}".format(i_busteilnehmer, str_busteilnehmer)
if raw_index == 5 and msg_bytecount >= 1:
i_softwarefamilie = buffer[buffer_index]
debugstr += ";Softwarefamilie:{0}".format(i_softwarefamilie)
if raw_index == 6 and msg_bytecount >= 1:
i_softwareversion = buffer[buffer_index]
debugstr += ";Softwareversion:{0}\n".format(i_softwareversion)
if raw_index == 7 and msg_bytecount >= 1:
i_busteilnehmer = buffer[buffer_index]
debugstr += " ;2.Busteilnehmer:{0}".format(i_busteilnehmer)
if raw_index == 8 and msg_bytecount >= 1:
i_major = buffer[buffer_index]
debugstr += ";2.Major Version:{0}".format(i_major)
if raw_index == 9 and msg_bytecount >= 1:
i_minor = buffer[buffer_index]
debugstr += ";2.Minor Version:{0}\n".format(i_minor)
if raw_index == 10 and msg_bytecount >= 1:
i_busteilnehmer = buffer[buffer_index]
debugstr += " ;3.Busteilnehmer:{0}".format(i_busteilnehmer)
if raw_index == 11 and msg_bytecount >= 1:
i_major = buffer[buffer_index]
debugstr += ";3.Major Version:{0}".format(i_major)
if raw_index == 12 and msg_bytecount >= 1:
i_minor = buffer[buffer_index]
debugstr += ";3.Minor Version:{0}\n".format(i_minor)
if raw_index == 13 and msg_bytecount >= 1:
i_marke = buffer[buffer_index]
if i_marke == 0:
strmarke = "None"
elif i_marke == 1:
strmarke = "Bosch"
elif i_marke == 2:
strmarke = "Junkers"
elif i_marke == 3:
strmarke = "Buderus"
else:
strmarke = str(i_marke)
debugstr += " ;Markenzeichen:{0}".format(strmarke)
raw_index += 1
hexstr = self.__CreateHexdump(msgtuple, "bus", buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
self.__Debuglog(msgtuple, "bus", debugstr, buffer)
self.__Debuglog(msgtuple, "bus", hexstr, buffer)
values = self.__gdata.values(nickname)
return (nickname, values)
else:
return ("", None)
def msgID_5_SystemInfo(self, msgtuple, buffer, length):
"""
decoding of msgID:5 -> Systeminformation.
"""
nickname = "DT"
(msgid, offset) = msgtuple
hexstr = self.__CreateHexdump(msgtuple, "sys", buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
values = self.__gdata.values(nickname)
return (nickname, values)
# ## Date / Time ##
def msgID_6_datetime(self, msgtuple, buffer, length):
"""
decoding of msgID:6 -> Daten and Time.
"""
nickname = "DT"
(msgid, offset) = msgtuple
first_payload_index = 4
# length > first index + crc-byte + break-byte
if length > first_payload_index + 2:
# init values
raw_index = offset + first_payload_index
msg_bytecount = length - first_payload_index - 2
for buffer_index in range(first_payload_index, length - 2):
# read values from buffer and assign them
if raw_index == 4 and msg_bytecount >= 7:
iyear = int(buffer[buffer_index] + 2000)
imonth = int(buffer[buffer_index + 1])
ihour = int(buffer[buffer_index + 2])
iday = int(buffer[buffer_index + 3])
iminute = int(buffer[buffer_index + 4])
isecond = int(buffer[buffer_index + 5])
idayofweek = int(buffer[buffer_index + 6])
self.__info_datum = """{day:02}.{month:02}.{year:4}""".format(day=iday,
month=imonth,
year=iyear)
self.__info_zeit = """{hour:02}:{minute:02}:{second:02}""".format(hour=ihour,
minute=iminute,
second=isecond)
# update values
self.__gdata.update(nickname, "Date", self.__info_datum)
self.__gdata.update(nickname, "Time", self.__info_zeit)
raw_index += 1
hexstr = self.__CreateHexdump(msgtuple, nickname, buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
return (nickname, self.__gdata.values(nickname))
else:
return ("", None)
def msgID_7_TokenStati(self, msgtuple, buffer, length):
"""
decoding of msgID:7 -> Bus-Tokenstatus.
"""
nickname = "DT"
(msgid, offset) = msgtuple
if self._IsRequestCall(buffer):
return self._RequestCall(msgtuple, buffer, length)
first_payload_index = 4
# check if source-device-adr | 0x80 := buffer[0]
if (buffer[0] == 0x88):
nickname = "HG"
hexdump_nickname = nickname
else:
nickname = "DT"
hexdump_nickname = "sys"
# create busmodul-ID string from byte-infos
deviceID_str=""
for x in range(first_payload_index, length-2):
bit = 0x01
for y in range(0, 8):
if((buffer[x] & bit) == bit):
deviceID = y + 8*(x - 3)
deviceID_str += format(deviceID, "02x") + " "
bit <<= 1
self.__gdata.busmodulAdr(deviceID_str)
hexstr = self.__CreateHexdump(msgtuple, hexdump_nickname, buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
values = self.__gdata.values(nickname)
return (nickname, values)
############################
# ### Heater Device ##
############################
def msgID_22_Heaterdevice(self, msgtuple, buffer, length):
"""
decoding of msgID:22 -> Heaterdevice message.
"""
(msgid, offset) = msgtuple
Sourcedevice = buffer[0]
Targetdevice = buffer[1]
TargetdeviceNr = (Targetdevice & 0x7f)
# if request-flag set, then make only hexdump
if self._IsRequestCall(buffer):
return self._RequestCall(msgtuple, buffer, length)
nickname = "HG"
self.__currentHK_nickname = nickname
debugstr = ""
first_payload_index = 4
# length > first index + crc-byte + break-byte
if length > first_payload_index + 2:
# init values
raw_index = offset + first_payload_index
msg_bytecount = length - first_payload_index - 2
for buffer_index in range(first_payload_index, length - 2):
# read values from buffer and assign them
if raw_index == 4 and msg_bytecount >= 1:
heater_enable = buffer[buffer_index]
heater_enable_str="Off"
if (heater_enable == 255):
heater_enable_str="On"
debugstr += ";heat_enable:{0};TargetDevice(dez.):{1}".format(heater_enable_str, Targetdevice)
if raw_index == 5 and msg_bytecount >= 1:
i_heater_maxtempvorlauf = int(buffer[buffer_index])
debugstr += ";MaxT_Vorlauf:{0}".format(i_heater_maxtempvorlauf)
if raw_index == 6 and msg_bytecount >= 1:
i_heater_maxpower = int(buffer[buffer_index])
debugstr += ";heatmaxp:{0}".format(i_heater_maxpower)
if raw_index == 7 and msg_bytecount >= 1:
i_heat_limit = int(buffer[buffer_index])
debugstr += ";heatlimit_enable:{0}".format(i_heat_limit)
if raw_index == 8 and msg_bytecount >= 1:
i_heater_offhysterese = int(buffer[buffer_index])
debugstr += ";offhys:{0}".format(i_heater_offhysterese)
if raw_index == 9 and msg_bytecount >= 1:
i_heater_onhysterese = int(buffer[buffer_index]) - 255
debugstr += ";offhys:{0}".format(i_heater_onhysterese)
if raw_index == 10 and msg_bytecount >= 1:
i_heater_taktsperre_time = int(buffer[buffer_index])
debugstr += ";Time_taktsperre:{0}".format(i_heater_taktsperre_time)
if raw_index == 11 and msg_bytecount >= 1:
i_heater_pumpmodus = int(buffer[buffer_index])
debugstr += ";pumpmodus:{0}".format(i_heater_pumpmodus)
if raw_index == 12 and msg_bytecount >= 1:
i_nachlaufzeit_pumpe = int(buffer[buffer_index])
debugstr += ";pump_nachlaufzeit:{0}".format(i_nachlaufzeit_pumpe)
if raw_index == 13 and msg_bytecount >= 1:
i_heater_maxpumppower = int(buffer[buffer_index])
debugstr += ";pumpmaxpow:{0}".format(i_heater_maxpumppower)
if raw_index == 14 and msg_bytecount >= 1:
i_heater_minpumppower = int(buffer[buffer_index])
debugstr += ";pumpminpow:{0}".format(i_heater_minpumppower)
raw_index += 1
hexstr = self.__CreateHexdump(msgtuple, nickname, buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
self.__Debuglog(msgtuple, nickname, debugstr, buffer)
values = self.__gdata.values(nickname)
return (nickname, values)
else:
return ("", None)
def msgID_24_Heaterdevice(self, msgtuple, buffer, length):
"""
decoding of msgID:24 -> Heaterdevice message.
"""
nickname = "HG"
(msgid, offset) = msgtuple
debugstr = ""
first_payload_index = 4
# length > first index + crc-byte + break-byte
if length > first_payload_index + 2:
# init values
raw_index = offset + first_payload_index
msg_bytecount = length - first_payload_index - 2
i_tvorlauf_soll = 0
f_tvorlauf_ist = 0.0
i_leistung = 0
i_betriebsmodus = 0
f_ionisationstrom = 0
f_tverbrennungsluft = 0
for buffer_index in range(first_payload_index, length - 2):
if raw_index == 4 and msg_bytecount >= 1:
i_tvorlauf_soll = int(buffer[buffer_index])
self.__gdata.update(nickname, "Tvorlauf_soll", self.__Check4MaxValue(nickname, "Tvorlauf_soll", i_tvorlauf_soll))
if raw_index == 5 and msg_bytecount >= 2:
f_tvorlauf_ist = float(buffer[buffer_index] * 256 + buffer[buffer_index + 1]) / 10
self.__gdata.update(nickname, "Tvorlauf_ist", self.__Check4MaxValue(nickname, "Tvorlauf_ist", f_tvorlauf_ist))
if raw_index == 8 and msg_bytecount >= 1:
i_leistung = int(buffer[buffer_index])
self.__gdata.update(nickname, "Vleistung", i_leistung)
if raw_index == 9 and msg_bytecount >= 1:
i_betriebsmodus = int(buffer[buffer_index] & 0x03)
self.__gdata.update(nickname, "Vmodus", i_betriebsmodus)
# Extract Bitfeld von RAW-Byte 9
# Bitfeld: (Bits von rechts LSB gezaehlt - beginnt mit 1)
#
# Bit8: Status Wartungsanforderung := 0/1
# Bit7: Status blockierender Fehler := 0/1
# Bit6: Status verriegelnder Fehler := 0/1
# Bit5: Status Aufheizphase d. HG := 0/1
# Bit4: Brennerflamme an := 0/1
# Bit3: Status Servicebetrieb := 0/1
# Bit2: Warmwasser-Mode deaktiv/aktiv := 0/1
# Bit1: Heizungs -Mode deaktiv/aktiv := 0/1
b_brennerflamme = 1 if bool((buffer[buffer_index] & 0x08)) else 0
self.__gdata.update(nickname, "Vbrenner_flamme", b_brennerflamme)
if raw_index == 10 and msg_bytecount >= 1:
# Extract Bitfeld von Byte 10
#
# Bitfeld: (Bits von rechts LSB gezaehlt - beginnt mit 1)
# Bit8: Status Waermeanforderung im Test-modus
# Bit7: Status Waermeanforderung
# Bit6: Status WWErkennung
# Bit5: Status interne Waermeanforderung bei WW
# Bit4: Status Waermeanforderung fuer WW bei BArt:=Frost
# Bit3: Status Waermeanforderung bei BArt:=Frost
# Bit2: Status Waermeanforderung am Schalter
# Bit1: Status Waermeanforderung im Heizbetrieb
i_statusByte10 = int(buffer[buffer_index])
debugstr += ";Byte10:{0}".format(i_statusByte10)
if raw_index == 11 and msg_bytecount >= 1:
# Extract Bitfeld von Byte 11
#
# Bitfeld: (Bits von rechts LSB gezaehlt - beginnt mit 1)
# Bit8: Status Zirkulationspumpe Warmwasser
# Bit7: Status des 3-Wege Ventils 1 := Warmwasser
# Bit6: Status Heizungspumpe
# Bit5: Status des Oelvorwaermer (Gas := 0)
# Bit4: Zuendung des Brenners
# Bit3: Status des Luefter;
# Bit2: 2. Brennstufe
# Bit1: 1. Brennstufe; waehrend Verbrennung 1 mit kurzem Vor- und Nachlauf
b_brenner = 1 if(buffer[buffer_index] & 0x01) else 0
b_heizungspumpe = 1 if(buffer[buffer_index] & 0x20) else 0
b_3WegeVentil = 1 if(buffer[buffer_index] & 0x40) else 0
b_zirkulationspumpe = 1 if(buffer[buffer_index] & 0x80) else 0
self.__gdata.update(nickname, "Vbrenner_motor", b_brenner)
self.__gdata.update(nickname, "Vheizungs_pumpe", b_heizungspumpe)
self.__gdata.update(nickname, "Vspeicher_pumpe", b_3WegeVentil)
self.__gdata.update(nickname, "Vzirkula_pumpe", b_zirkulationspumpe)
if raw_index == 13 and msg_bytecount >= 2:
# current temperatur on storage-cell temp-sensor1
f_tmischer = float(buffer[buffer_index] * 256 + buffer[buffer_index + 1]) / 10
self.__gdata.update(nickname, "Tmischer", self.__Check4MaxValue(nickname, "Tmischer", f_tmischer))
if raw_index == 15 and msg_bytecount >= 2:
# current temperatur on storage-cell temp-sensor2
i_t2_storagecell = buffer[buffer_index] * 256 + buffer[buffer_index + 1]
debugstr += ";WW-buffer temp2:"
if self.IsSensorAvailable(i_t2_storagecell):
debugstr += "{0}".format(float(i_t2_storagecell / 10))
else:
debugstr += "->NA"
if raw_index == 17 and msg_bytecount >= 2:
i_truecklauf = buffer[buffer_index] * 256 + buffer[buffer_index + 1]
if self.IsSensorAvailable(i_truecklauf):
f_truecklauf = float(i_truecklauf) / 10
self.__gdata.update(nickname, "Truecklauf", self.__Check4MaxValue(nickname, "Truecklauf", f_truecklauf))
if raw_index == 19 and msg_bytecount >= 2:
debugstr += ";I-current:"
i_ionisationstrom = buffer[19] * 256 + buffer[20]
if self.IsSensorAvailable(i_ionisationstrom):
debugstr += "{0}".format(float(i_ionisationstrom / 10))
else:
debugstr += "->NA"
if raw_index == 21 and msg_bytecount >= 1:
i_systempressure = buffer[buffer_index]
f_systempressure = float(i_systempressure) / 10
debugstr += ";pressure:"
if self.IsSensorAvailable(i_systempressure):
self.__gdata.update(nickname, "V_pressure", f_systempressure)
if self.__IsInRange(nickname, "V_pressure", f_systempressure):
debugstr += "{0} bar".format(f_systempressure)
else:
debugstr += "->!out of range!"
else:
debugstr += "->NA"
if raw_index == 22 and msg_bytecount >= 2:
displaycode = buffer[buffer_index] * 256 + buffer[buffer_index + 1]
debugstr += ";displaycode:{}".format(displaycode)
if raw_index == 24 and msg_bytecount >= 2:
causecode = int((buffer[buffer_index] * 256) + buffer[buffer_index + 1])
debugstr += ";causecode:{}".format(causecode)
if raw_index == 26 and msg_bytecount >= 1:
i_WWflow = int(buffer[buffer_index])
debugstr += ";WW-flow:{0}".format(i_WWflow)
if raw_index == 27 and msg_bytecount >= 1:
# Extract Bitfeld von Byte 10
#
# Bitfeld: (Bits von rechts LSB gezaehlt - beginnt mit 1)
# Bit8: Status --
# Bit7: Status --
# Bit6: Status Brenner Relais
# Bit5: Status Zirkulationspumpe
# Bit4: Status Relais im UM
# Bit3: Status Waermepumpe
# Bit2: Status Magnetventil
# Bit1: Status Speicherladepumpe
i_statusByte27 = int(buffer[buffer_index])
debugstr += ";Byte27:{0}".format(i_statusByte27)
if raw_index == 28 and msg_bytecount >= 1:
# Extract Bitfeld von Byte 10
#
# Bitfeld: (Bits von rechts LSB gezaehlt - beginnt mit 1)
# Bit8: Status Tastensprerre
# Bit7: test active
# Bit6: Status heater blocked
# Bit5: Status burner start
# Bit4: Status burner enable
# Bit3: Status burner blocking
# Bit2: Status Schaltmodul UM
# Bit1: Status Fuellfunktion
i_statusByte28 = int(buffer[buffer_index])
debugstr += ";Byte28:{0}".format(i_statusByte28)
if raw_index == 29 and msg_bytecount >= 2:
f_tverbrennungsluft = float(buffer[29] * 256 + buffer[30]) / 10
debugstr += ";TAbgass:{0}".format(f_tverbrennungsluft)
raw_index += 1
hexstr = self.__CreateHexdump(msgtuple, nickname, buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
self.__Debuglog(msgtuple, nickname, debugstr, buffer)
self.__Debuglog(msgtuple, nickname, hexstr, buffer)
values = self.__gdata.values(nickname)
return (nickname, values)
else:
return ("", None)
def msgID_25_Heaterdevice(self, msgtuple, buffer, length):
"""
decoding of msgID:25 -> Heaterdevice message.
"""
nickname = "HG"
(msgid, offset) = msgtuple
debugstr = ""
first_payload_index = 4
# length > first index + crc-byte + break-byte
if length > first_payload_index + 2:
# init values
raw_index = offset + first_payload_index
msg_bytecount = length - first_payload_index - 2
i_betriebtotal_minuten = 0
i_betriebheizung_minuten = 0
i_brenner_gesamt_ein = 0
i_brenner_heizung_ein = 0
for buffer_index in range(first_payload_index, length - 2):
# read values from buffer and assign them
if raw_index == 4 and msg_bytecount >= 2:
if buffer[buffer_index] != 255:
f_tAussen = float(buffer[buffer_index] * 256 + buffer[buffer_index + 1]) / 10
else:
f_tAussen = float(255-buffer[buffer_index + 1]) / (-10)
self.__gdata.update(nickname, "Taussen", self.__Check4MaxValue(nickname, "Taussen", f_tAussen))
# Rev.: 0.1.7 https://www.mikrocontroller.net/topic/324673#3970615
if raw_index == 13 and msg_bytecount >= 1:
i_pumpenleistung = int(buffer[buffer_index])
self.__gdata.update(nickname, "Vch_pump_power", i_pumpenleistung)
if raw_index == 14 and msg_bytecount >= 3:
i_brenner_gesamt_ein = int(buffer[buffer_index] * 65536 + buffer[buffer_index + 1] * 256 + buffer[buffer_index + 2])
self.__gdata.update(nickname, "Cbrenner_gesamt", i_brenner_gesamt_ein)
if raw_index == 17 and msg_bytecount >= 3:
i_betriebtotal_minuten = int(buffer[buffer_index] * 65536 + buffer[buffer_index + 1] * 256 + buffer[buffer_index + 2])
f_betriebtotal_stunden = float(i_betriebtotal_minuten / 60)
self.__gdata.update(nickname, "Cbetrieb_gesamt", f_betriebtotal_stunden)
if raw_index == 20 and msg_bytecount >= 3:
i_betriebszeit_2stufe = int(buffer[buffer_index] * 65536 + buffer[buffer_index + 1] * 256 + buffer[buffer_index + 2])
# not yet written to database, only for debug-purposes
debugstr += ";betriebszeit_2.Stufe:{}".format(i_betriebszeit_2stufe)
if raw_index == 23 and msg_bytecount >= 3:
i_betriebheizung_minuten = int(buffer[buffer_index] * 65536 + buffer[buffer_index + 1] * 256 + buffer[buffer_index + 2])
f_betriebheizung_stunden = float(i_betriebheizung_minuten / 60)
self.__gdata.update(nickname, "Cbetrieb_heizung", f_betriebheizung_stunden)
if raw_index == 26 and msg_bytecount >= 3:
i_brenner_heizung_ein = int(buffer[buffer_index] * 65536 + buffer[buffer_index + 1] * 256 + buffer[buffer_index + 2])
self.__gdata.update(nickname, "Cbrenner_heizung", i_brenner_heizung_ein)
if raw_index == 29 and msg_bytecount >= 2:
# TIst an der hydraulischen Weiche
i_THydrWeiche = buffer[buffer_index] * 256 + buffer[buffer_index + 1]
f_THydrWeiche = float(i_THydrWeiche) / 10
debugstr += ";T-Hydr.Weiche:{}".format(f_THydrWeiche)
if self.IsSensorAvailable(i_THydrWeiche):
self.__gdata.update(nickname, "T_hyd_switch", self.__Check4MaxValue(nickname, "T_hyd_switch", f_THydrWeiche))
# setup flag for Hydraulic Switch available, used in GUI
self.__gdata.IsTempSensor_Hydrlic_Switch(True)
else:
# Hydr.Weiche not available
self.__gdata.IsTempSensor_Hydrlic_Switch(False)
raw_index += 1
hexstr = self.__CreateHexdump(msgtuple, nickname, buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)
self.__Debuglog(msgtuple, nickname, debugstr, buffer)
values = self.__gdata.values(nickname)
return (nickname, values)
else:
return ("", None)
def msgID_28_Service(self, msgtuple, buffer, length):
"""
decoding of msgID:28 -> Service message.
"""
nickname = "DT"
(msgid, offset) = msgtuple
hexstr = self.__CreateHexdump(msgtuple, "sys", buffer, length)
self.__gdata.update(nickname, "hexdump", hexstr)