diff options
-rw-r--r-- | ebus/__init__.py | 87 |
1 files changed, 70 insertions, 17 deletions
diff --git a/ebus/__init__.py b/ebus/__init__.py index f56a0a5..2e4ef21 100644 --- a/ebus/__init__.py +++ b/ebus/__init__.py @@ -65,6 +65,10 @@ class fields: def value(self,data): raise NotImplemented() + class Data1c(DataField): + def value(self,data): + return ord(data[self.offset])/2.0 + class Data2c(DataField): """ Beispiel für die Berechnung: @@ -79,7 +83,7 @@ class fields: highByte = ord(data[self.offset+1]) lowByte= ord(data[self.offset]) if (0x8000 & (highByte<<8 | lowByte)) == 0x8000: - return (-1) * ( (0xff^highByte)*16 + (0xf^(lowByte>>4)) + (0x0f^(0x0&flowByte) + 1)/16.0 ) + return (-1) * ( (0xff^highByte)*16 + (0xff^(lowByte>>4)) + (0x0ff^(0xf&lowByte) + 1)/16.0 ) else: return highByte*16 + (lowByte>>4) + (lowByte&0xf)/16.0 @@ -101,6 +105,19 @@ class fields: class Bit(DataField): def value(self, data): return ord(data[self.offset]) == 0x1 + + class Bcd(DataField): + """ + y = dez(High_Nibble(x))*10 + dez(Low_Nibble(x)) + """ + def value(self, data): + byte = ord(data[self.offset]) + return (byte >> 4) * 10 + (byte & 0xf) + + class Byte(DataField): + def value(self, data): + return ord(data[self.offset]) + class ByteEnum(DataField): def __init__(self, offset, values): @@ -116,7 +133,21 @@ class fields: packetDescription = [ # Service 0x05 (Brennersteuerbefehle) - {'primary':0x5, 'secondary':0x3, 'name':'Betriebsdaten des Feuerungsautomaten an den Regler Block1'}, + {'primary':0x5, 'secondary':0x3, 'name':'Betriebsdaten des Feuerungsautomaten an den Regler Block1','format': { + 'blocknumber':fields.Byte(0), + #('errorCode':fields.Byte(1), + 'stellgradKesselleistung':fields.Byte(3), + 'kesseltemperatur':fields.Data1c(4), + 'ruecklaufTemperatur':fields.Byte(5), + 'boilerTemperatur':fields.Byte(6), + 'ausenTemperatur':fields.Byte(7), + #if ord(fields.Byte(0)) == 0x01 else + #'abgasTemperatur':fields.Data2c(1), + #'BWW-Vorlauftemperatur':fields.Data1c(3), + #'momentaneRelativeKesselTemperatur':fields.Data1c(4), + #'gemeinsameVorlaufTemperatur':fields.Data1c(5)), + }}, + {'primary':0x5, 'secondary':0x7, 'name':'Betriebsdaten des Reglers an den Feuerungsautomaten','format': { 'betriebszustand':fields.ByteEnum(0, { 0x00:'Brenner Abschalten', @@ -137,12 +168,24 @@ packetDescription = [ 0x04:'Einschalten variabler Verbraucher'}), 'kesselSollwertTemperatur':fields.Data2c(2), 'kesselSollwertDruck':fields.Data2b(4), + 'stellgrad':fields.Data1c(6), + 'brauchwasserSollwert':fields.Data1c(7) }}, # Service 0x07 (Systemdatenbefehle) - {'primary':0x7, 'secondary':0x0, 'name':'Datum/Zeit - Meldung eines eBUS Masters'}, - {'primary':0x7, 'secondary':0x4, 'name':'Identifikation'}, - # Service 0x08 (Reglerbefehle) - {'primary':0x8, 'secondary':0x0, 'name':'Sollwertübertragung des Reglers an andere Regler'}, + {'primary':0x7, 'secondary':0x0, 'name':'Datum/Zeit - Meldung eines eBUS Masters','format': { + 'ausenTemperatur':fields.Data2b(0), + 'sekunden':fields.Bcd(2), + 'minuten':fields.Bcd(3), + 'stunden':fields.Bcd(4), + 'tag':fields.Bcd(5), + 'monat':fields.Bcd(6), + 'wochentag':fields.Bcd(7), + 'jahr':fields.Bcd(8)}}, + + {'primary':0x7, 'secondary':0x0, 'name':'Datum/Zeit - Meldung eines eBUS Masters'}, + {'primary':0x7, 'secondary':0x4, 'name':'Identifikation'}, + # Service 0x08 (Reglerbefehle) + {'primary':0x8, 'secondary':0x0, 'name':'Sollwertübertragung des Reglers an andere Regler'}, # Response #p[0] = Einheit (1=>Liter, 2=>Kubik) @@ -244,10 +287,24 @@ class EbusReader(asynchat.async_chat): self.buf += data[it] self.packetIndex = self.packetIndex + 1 #print "%.2x [%d]" % (ord(data[it]),self.packetIndex) - - def _parse(self,data): + + def _parse(self,dataRaw): + #0xaa bug + i = 0 + data = "" + while i < len(dataRaw): + if ord(dataRaw[i]) == 0xa9 and ord(dataRaw[i+1]) == 0x01: + data += "\xaa" + i = i + 1 + elif ord(dataRaw[i]) == 0xa9 and ord(dataRaw[i+1]) == 0x00: + data += "\xa9" + i = i + 1 + else: + data += dataRaw[i] + i = i + 1 + if len(data) < 2: - print >>sys.stderr, "GAGA" + print "GAGA" return source = ord(data[0]) destination = ord(data[1]) @@ -265,14 +322,10 @@ class EbusReader(asynchat.async_chat): primaryCommand = ord(data[2]) secondaryCommand = ord(data[3]) payloadLength = ord(data[4]) - payload = data[5:6+payloadLength] - #delete 0x50 packets for devel - #if (primaryCommand == ord("\x50")): -# return - #print "PR SC NN D0 D1 D2 D3 D4 D5 D6 D7 ..." - #print "%.2x" % (primaryCommand,) - #print "%.2x %.2x %.2x %s" % (primaryCommand,secondaryCommand,payloadLength,"bla") - #print "%.2x %.2x %.2x %s" % (primaryCommand,secondaryCommand,payloadLength,formatHex(payload)) + payload = data[5:5+payloadLength] + ### DEBUG ### + print "\033[1;31m%.2x %.2x\033[1;m \033[1;33m%.2x %.2x\033[1;m \033[1;30m%.2x\033[1;m \033[1;45m%s\033[1;m %d" % (source,destination,primaryCommand,secondaryCommand,payloadLength,formatHex(payload),len(payload)) + print "%s"%(formatHex(data)) p = None if sourceDevice[0]['type'] == 'master' and destinationDevice[0]['type'] == 'master': |