Revision: 75ae5e903e10
Branch: default
Author: Paul Malmsten <
pmal...@gmail.com>
Date: Sat Sep 21 00:00:16 2013 UTC
Log: Fix for Issue 44:
https://code.google.com/p/python-xbee/issues/detail?id=44
Thanks to Martin Erablitek for the report. The software mask of the DIO mask
value in the sample data header for XBee ZB (ZigBee) devices was incorrect;
this would lead to incorrect parsing of sample data. As a result, DIO lines
12 and 4 could never be parsed as enabled. In addition, if these were the
only enabled lines, any following ADC data would be garbage.
The fix was to update the software mask for the DIO mask value from 0x0E7F
to the proper value 0x1CFF. In addition, test cases were updated to
demonstrate correct parsing, and the changed test cases were manually
verified against the specification.
http://code.google.com/p/python-xbee/source/detail?r=75ae5e903e10
Modified:
/xbee/tests/test_zigbee.py
/xbee/zigbee.py
=======================================
--- /xbee/tests/test_zigbee.py Mon Sep 3 16:26:15 2012 UTC
+++ /xbee/tests/test_zigbee.py Sat Sep 21 00:00:16 2013 UTC
@@ -84,11 +84,14 @@
'source_addr': b'v\x1a',
'command': b'IS',
'status': b'\x00',
- 'parameter': [{'dio-10': False,
+ 'parameter': [{'adc-1': 652,
'adc-2': 918,
- 'dio-6': False,
+ 'dio-10': False,
'dio-11': True,
- 'adc-1': 652}]
+ 'dio-12': True,
+ 'dio-6': False,
+ 'dio-7': False
+ }]
}
self.assertEqual(info, expected_info)
@@ -107,11 +110,14 @@
'source_addr': b'v\x1a',
'command': b'is',
'status': b'\x00',
- 'parameter': [{'dio-10': False,
+ 'parameter': [{'adc-1': 652,
'adc-2': 918,
- 'dio-6': False,
+ 'dio-10': False,
'dio-11': True,
- 'adc-1': 652}]
+ 'dio-12': True,
+ 'dio-6': False,
+ 'dio-7': False
+ }]
}
self.assertEqual(info, expected_info)
@@ -199,6 +205,31 @@
results = self.zigbee._parse_samples(data)
self.assertEqual(results, expected_results)
+ def test_parse_samples_ticket_44(self):
+ """
+ This example is from ticket 44 on Google Code:
+
https://code.google.com/p/python-xbee/issues/detail?id=44
+
+ The author claims the given data is generated by an
+ Xbee Pro 900HP module, but I could only find a definition
+ for packet with a response type of 0x92 in the XBee ZB
+ specification.
+ """
+
+ data = (b'\x01' + # Number of samples
+ b'\x10\x00' + # Digital I/O mask (CD/DIO12 enabled)
+ b'\x0E' + # ADC 1,2,3 enabled
+ b'\x10\x00' + # DIO12 is high
+ b'\x03\xA4' + # ADC1 = 932
+ b'\x01\x31' + # ADC2 = 305
+ b'\x03\x31') # ADC3 = 817
+ expected_results = [{'dio-12': True,
+ 'adc-1': 932,
+ 'adc-2': 305,
+ 'adc-3': 817}]
+ results = self.zigbee._parse_samples(data)
+ self.assertEqual(results, expected_results)
+
def test_parse_dio_adc_supply_voltage_not_clamped(self):
"""
When bit 7 on the ADC mask is set, the supply voltage is included
@@ -213,7 +244,5 @@
"""
data = b'\x01\x00\x00\x80\x0D\x18'
expected_results = [{'adc-7':0xD18}]
- #import pdb
- #pdb.set_trace()
results = self.zigbee._parse_samples(data)
self.assertEqual(results, expected_results)
=======================================
--- /xbee/zigbee.py Wed Jun 13 19:33:44 2012 UTC
+++ /xbee/zigbee.py Sat Sep 21 00:00:16 2013 UTC
@@ -233,7 +233,7 @@
sample_count = byteToInt(io_bytes[0])
# bytes 1 and 2 are the DIO mask; bits 9 and 8 aren't used
- dio_mask = (byteToInt(io_bytes[1]) << 8 | byteToInt(io_bytes[2]))
& 0x0E7F
+ dio_mask = (byteToInt(io_bytes[1]) << 8 | byteToInt(io_bytes[2]))
& 0x1CFF
# byte 3 is the AIO mask
aio_mask = byteToInt(io_bytes[3])