diff options
author | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2010-04-24 13:15:30 +0000 |
---|---|---|
committer | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2010-04-24 13:15:30 +0000 |
commit | 3a22b83633fe07ff0b689284433a53c20ea58466 (patch) | |
tree | 46896edcfdcad0425fd10e07ee3ec69dae6b94e6 /ebus/__init__.py | |
parent | 7a1542162fe2c2f06f808b3b628e028576a28114 (diff) | |
download | ebus-alt-3a22b83633fe07ff0b689284433a53c20ea58466.tar.gz ebus-alt-3a22b83633fe07ff0b689284433a53c20ea58466.zip |
word, data1b
git-svn-id: http://10.2.2.13/svn/common/ebus@1668 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
Diffstat (limited to 'ebus/__init__.py')
-rw-r--r-- | ebus/__init__.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/ebus/__init__.py b/ebus/__init__.py index e92a74e..65f47a1 100644 --- a/ebus/__init__.py +++ b/ebus/__init__.py @@ -17,6 +17,21 @@ class fields: def value(self,data): raise NotImplemented() + class Data1b(DataField): + """ + Beispiel für die Berechnung: + if ((x & 80h) == 80h) // y negativ + y = - [dez(!x) + 1] + else + y = dez(x) + """ + def value(self,data): + x=ord(data[self.offset]) + if x & 0x80 == 0x80: + return (-1) * (0xff^x + 1) + else: + return x + class Data1c(DataField): def value(self,data): return ord(data[self.offset])/2.0 @@ -57,6 +72,11 @@ class fields: class Bit(DataField): def value(self, data): return ord(data[self.offset]) == 0x1 + + class Word(DataField): + def value(self, data): + lb, hb = data[self.offset], data[self.offset+1] + return ord(lb) + (ord(hb)<<8) class Bcd(DataField): """ @@ -124,9 +144,13 @@ class EbusXMLMixin(object): if not name: continue elif field.tag == "bit": - yield fields.Bit( name, int(offset)) + yield fields.Bit( name, int(offset) ) elif field.tag == "byte": - yield fields.Byte( name, int(offset)) + yield fields.Byte( name, int(offset) ) + elif field.tag == "word": + yield fields.Word( name, int(offset) ) + elif field.tag == "data1b": + yield fields.Data1b( name, int(offset) ) elif field.tag == "data1c": yield fields.Data1c( name, int(offset) ) elif field.tag == "data2b": @@ -177,6 +201,8 @@ class EbusMasterSlave(EbusPacket): self.request = request self.response = response + self.data = self.request #XXX + class EbusBroadcast(EbusPacket): def __init__(self, source, destination, primary_command, secondary_command, data): EbusPacket.__init__(self, source, destination, primary_command, secondary_command) @@ -245,16 +271,17 @@ class EbusReader(asynchat.async_chat): p = None if sourceType == 'master' and destinationType == 'master': p = EbusMasterMaster(source, destination, primaryCommand, secondaryCommand, payload) + self.handle_ebus(p) elif sourceType == 'master' and destinationType == 'slave': p = EbusMasterSlave(source, destination, primaryCommand, secondaryCommand, payload, None) #FIXME + print >>sys.stderr, "SKIP MASTER-SLAVE" elif sourceType == 'master' and destinationType == 'broadcast': p = EbusBroadcast(source, destination, primaryCommand, secondaryCommand, payload) + self.handle_ebus(p) else: print >>sys.stderr, "KOMISCHES ZEUG" print >>sys.stderr, "source=%s sourceType=%s destination=%s destType=%s" % \ (source, sourceType, destination, destinationType) - return - self.handle_ebus(p) def handle_ebus(self,ebus_packet): print >>sys.stderr, "unhandled ebus_packet" |