|
10 | 10 | import unittest, sys, traceback |
11 | 11 | from xbee.tests.Fake import FakeDevice, FakeReadDevice |
12 | 12 | from xbee.ieee import XBee |
| 13 | +from xbee.frame import APIFrame |
13 | 14 | from xbee.python2to3 import byteToInt, intToByte, stringToBytes |
14 | 15 |
|
15 | 16 | class InitXBee(unittest.TestCase): |
@@ -561,6 +562,72 @@ def test_read_at_params(self): |
561 | 562 | 'parameter':b'\x00\x00\x00'} |
562 | 563 | self.assertEqual(info, expected_info) |
563 | 564 |
|
| 565 | + def test_is_response_parsed_as_io(self): |
| 566 | + """ |
| 567 | + I/O data in a AT response for an IS command is parsed. |
| 568 | + """ |
| 569 | + ## Build IO data |
| 570 | + # One sample, ADC 0 enabled |
| 571 | + # DIO 1,3,5,7 enabled |
| 572 | + header = b'\x01\x02\xAA' |
| 573 | + |
| 574 | + # First 7 bits ignored, DIO8 low, DIO 0-7 alternating |
| 575 | + # ADC0 value of 255 |
| 576 | + sample = b'\x00\xAA\x00\xFF' |
| 577 | + data = header + sample |
| 578 | + |
| 579 | + device = FakeReadDevice( |
| 580 | + APIFrame(data = b'\x88DIS\x00' + data).output() |
| 581 | + ) |
| 582 | + |
| 583 | + xbee = XBee(device) |
| 584 | + |
| 585 | + info = xbee.wait_read_frame() |
| 586 | + expected_info = {'id':'at_response', |
| 587 | + 'frame_id':b'D', |
| 588 | + 'command':b'IS', |
| 589 | + 'status':b'\x00', |
| 590 | + 'parameter':[{'dio-1':True, |
| 591 | + 'dio-3':True, |
| 592 | + 'dio-5':True, |
| 593 | + 'dio-7':True, |
| 594 | + 'adc-0':255}]} |
| 595 | + self.assertEqual(info, expected_info) |
| 596 | + |
| 597 | + def test_is_remote_response_parsed_as_io(self): |
| 598 | + """ |
| 599 | + I/O data in a Remote AT response for an IS command is parsed. |
| 600 | + """ |
| 601 | + ## Build IO data |
| 602 | + # One sample, ADC 0 enabled |
| 603 | + # DIO 1,3,5,7 enabled |
| 604 | + header = b'\x01\x02\xAA' |
| 605 | + |
| 606 | + # First 7 bits ignored, DIO8 low, DIO 0-7 alternating |
| 607 | + # ADC0 value of 255 |
| 608 | + sample = b'\x00\xAA\x00\xFF' |
| 609 | + data = header + sample |
| 610 | + |
| 611 | + device = FakeReadDevice( |
| 612 | + APIFrame(data = b'\x97D\x00\x13\xa2\x00@oG\xe4v\x1aIS\x00' + data).output() |
| 613 | + ) |
| 614 | + |
| 615 | + xbee = XBee(device) |
| 616 | + |
| 617 | + info = xbee.wait_read_frame() |
| 618 | + expected_info = {'id':'remote_at_response', |
| 619 | + 'frame_id':b'D', |
| 620 | + 'source_addr_long': b'\x00\x13\xa2\x00@oG\xe4', |
| 621 | + 'source_addr': b'v\x1a', |
| 622 | + 'command':b'IS', |
| 623 | + 'status':b'\x00', |
| 624 | + 'parameter':[{'dio-1':True, |
| 625 | + 'dio-3':True, |
| 626 | + 'dio-5':True, |
| 627 | + 'dio-7':True, |
| 628 | + 'adc-0':255}]} |
| 629 | + self.assertEqual(info, expected_info) |
| 630 | + |
564 | 631 | def test_read_io_data(self): |
565 | 632 | """ |
566 | 633 | XBee class should properly read and parse incoming IO data |
|
0 commit comments