From 86c167acc082328cae11ae5f845d41967689e184 Mon Sep 17 00:00:00 2001 From: Random Hacker Date: Mon, 5 Mar 2012 23:12:07 +0100 Subject: ebus-python: fix data2c parser --- ebus/model/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'ebus/model') diff --git a/ebus/model/__init__.py b/ebus/model/__init__.py index 1e2d080..f6a44b9 100644 --- a/ebus/model/__init__.py +++ b/ebus/model/__init__.py @@ -36,12 +36,16 @@ class Data2c(DataField): + dez(Low_ Nibble (Low Byte (x))) / 16 """ def value(self,data): - highByte = ord(data[self.offset+1]) - lowByte= ord(data[self.offset]) + lowByte = ord(data[self.offset]) + highByte = ord(data[self.offset+1]) + n_highByte = 0xff ^ highByte + n_lowByte = 0xff ^ lowByte + n_lowByteHighNibble = n_lowByte >> 4 + n_lowByteLowNibble = 0x0f & n_lowByte if (0x8000 & (highByte<<8 | lowByte)) == 0x8000: - return (-1) * ( (0xff^highByte)*16 + (0xff^(lowByte>>4)) + (0x0ff^(0xf&lowByte) + 1)/16.0 ) + return (-1) * ( (n_highByte<<4 + n_lowByteHighNibble + (n_lowByteLowNibble+1)) / 16.0 ) else: - return highByte*16 + (lowByte>>4) + (lowByte&0xf)/16.0 + return highByte*16 + (lowByte>>4) + (0x0f & lowByte)/16.0 class Data2b(DataField): """ @@ -52,9 +56,11 @@ class Data2b(DataField): """ def value(self,data): highByte = ord(data[self.offset+1]) - lowByte= ord(data[self.offset]) + lowByte = ord(data[self.offset]) + n_highByte = 0xff ^ highByte + n_lowByte = 0xff ^ lowByte if (0x8000 & (highByte<<8 | lowByte)) == 0x8000: - return (-1) * ((0xff^highByte) + (0xff^lowByte+1)/256.0) + return (-1) * (n_highByte + (n_lowByte+1)/256.0) else: return highByte + lowByte/256.0 -- cgit v1.2.1