diff options
author | Random Hacker <random_hacker@xapek.org> | 2012-03-05 23:12:07 +0100 |
---|---|---|
committer | Random Hacker <random_hacker@xapek.org> | 2012-03-05 23:13:02 +0100 |
commit | 86c167acc082328cae11ae5f845d41967689e184 (patch) | |
tree | aff3ed90d7d94b090bf0a10c4670fd9e2addcf36 | |
parent | 119d7aa5338dcbf5b5ce5b75bf5b625502bd1780 (diff) | |
download | ebus-alt-86c167acc082328cae11ae5f845d41967689e184.tar.gz ebus-alt-86c167acc082328cae11ae5f845d41967689e184.zip |
ebus-python: fix data2c parser
-rw-r--r-- | ebus/model/__init__.py | 18 |
1 files changed, 12 insertions, 6 deletions
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 |