annotate rsib.py @ 31:c6c86dcb54ba

Add code to automate a sitesurvey (to some degree).
author Daniel O'Connor <darius@dons.net.au>
date Wed, 21 Sep 2011 15:00:24 +0930
parents 226ea06bc050
children 91b476ebc0f2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 # Copyright (c) 2009
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 # Redistribution and use in source and binary forms, with or without
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 # modification, are permitted provided that the following conditions
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 # are met:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 # notice, this list of conditions and the following disclaimer.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 # documentation and/or other materials provided with the distribution.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 # SUCH DAMAGE.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 # Reverse engineered from the Linux library & example program at
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 # http://epsrv.astro.umk.pl/~ep/irbene/rsib/library/RSIB-Linux.zip
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 # There are 2 socket connections for some reason.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 # The first seems to do [nearly] all the work
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 # Packets to the instrument
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 # On connection:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 # -> 00 00 00 40
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 # <- 00 00 00 40 a0 04 00 00
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39 # We need to echo back the last 4 bytes of the reply to a second
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 # socket opened to the same port. I don't know what that socket is for
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 # though.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 # Send a command:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 # -> 00 00 00 05 90 00 01 2a 49 44 4e 3f .......* IDN?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 # Offs Value Meaning
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 # 00 00 ?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 # 01 00 ?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 # 02 00 ?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 # 03 05 Length
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 # 04 90 MsgID
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 # 05 00 ?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 # 06 03 Seq number
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 # 07 2a (*) Cmd byte 0
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 # 08 49 (I) Cmd byte 1
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 # 09 44 (D) Cmd byte 2
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 # 10 4a (N) Cmd byte 3
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 # 10 3f (?) Cmd byte 4
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 # Interactive program seems to cap length at 0x99 but perhaps the
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 # first 4 bytes are length.
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 # Reply to command:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 # <- 00 00 00 23 80 00 01 52 6f 68 ...
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 #
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 # Offs Value Meaning
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 # 00 00 Length 31..24
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 # 01 00 23..16
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 # 02 00 15..8
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 # 03 23 7..0
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 # 04 80 MsgID
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 # 05 00 ?
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 # 06 01 Seq number
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 MSG_HELLO = 0x40 # We send this on connect
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 MSG_CMDREP = 0x80 # Reply from the instrument to us
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 MSG_CMD = 0x90 # Command to the instrument
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
78 MSG_SRQ = 0x91 # Query SRQ
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
79
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
80 import exceptions
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 import socket
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83 class RSIBDevice(object):
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 hello = '\x00\x00\x00\x40'
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 docmd = '\x00\x00\x00\x05\x90\x00\x01'
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
87 def __init__(self, host, port = None):
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
88 if port == None:
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
89 port = 2525
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 self.host = host
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 self.port = port
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 s1 = socket.socket()
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 s1.settimeout(5)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 s1.connect((self.host, self.port))
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96 s1.send('\x00\x00\x00\x40')
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 rx = ''
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 while len(rx) < 8:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 rx = rx + s1.recv(8)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100 if rx == '':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
101 raise exceptions.IOError("EOF from device")
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 s2 = socket.socket()
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104 s2.settimeout(5)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 s2.connect((self.host, self.port))
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 s2.send(rx[4:])
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108 self.s1 = s1
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 self.s2 = s2
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 self.tag = 0
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
112 def write(self, cmd, timeout = 0.5):
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 """Send data (string) to the instrument"""
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 self.s1.settimeout(timeout)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
116 if len(cmd) > 0x99:
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
117 raise exceptions.ValueError("Command too long")
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 # Pre-increment for easy comparison in read
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 self.tag = (self.tag + 1) & 0xff
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
121 msg = '\x00\x00\x00' + chr(len(cmd)) + '\x90\x00' + chr(self.tag) + cmd
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
122 self.s1.send(msg)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 def read(self, timeout = 0.5):
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 """Read data from the device, waits for up to timeout seconds for each TCP read"""
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 self.s1.settimeout(timeout)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
129 # Fetch the header
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
130 rx = ''
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
131 while len(rx) < 7:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
132 rx = self.s1.recv(7)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 if rx == '':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
134 raise exceptions.IOError("EOF from device")
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 if self.tag != ord(rx[6]):
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
137 raise exceptions.IOError("Reply out of order, got 0x%02x expected 0x%02x" % (ord(rx[6]), self.tag))
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139 rxlen = ord(rx[0]) << 24 | ord(rx[1]) << 16 | ord(rx[2]) << 8 | ord(rx[3])
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
140 #print "Msg ID 0x%02x" % (ord(rx[4]))
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
141 if False and ord(rx[4]) != MSG_CMDREP:
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
142 raise exceptions.IOError("Unexpected Msg ID 0x%02x" % (ord(rx[4])))
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
143
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
144 if ord(rx[5]) != 0:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
145 print "Mystery byte %d != 0" % (ord(rx[5]))
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
146 # Fetch the actual reply now we know the length
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
147 reply = ''
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
148 while len(reply) < rxlen:
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
149 rx = self.s1.recv(rxlen)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
150 if rx == '':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
151 raise exceptions.IOError("EOF from device")
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 reply += rx
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 return(reply)
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
156 def queryrsb(self):
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
157 msg = '\x00\x00\x00\x00\xd1\x18\x00'
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
158 self.s2.send(msg)
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
159
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
160 reply = ''
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
161 while len(reply) < 7:
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
162 rx = self.s2.recv(7)
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
163 if rx == '':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
164 raise exceptions.IOError("EOF from device")
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
165 reply += rx
6
85dfc0babc36 Add basic RSIB parser and example program.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
167 # '\x00\x00\x00\x00\x80\x04\x01' => STB = 4
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
168 if rx[4] != '\x80':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
169 raise exceptions.IOError("Incorrect Msg ID in response to STB query")
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
170
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
171 return ord(rx[5])
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
172
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
173 def waitsrq(self):
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
174 msg = '\x00\x00\x00\x00\xb1\x00\x00'
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
175
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
176 def testsrq(self):
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
177 msg = '\x00\x00\x00\x00\x91\x00\x00'
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
178 self.s2.send(msg)
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
179 reply = ''
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
180 while len(reply) < 7:
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
181 rx = self.s2.recv(7)
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
182 if rx == '':
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
183 raise exceptions.IOError("EOF from device")
14
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
184 reply += rx
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
185
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
186 # 00 00 00 00 80 14 08 - SRQ = 0
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
187 # 00 00 00 00 a0 64 07 - SRQ = 1
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
188 if rx == '\x00\x00\x00\x00\x80\x14\x08':
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
189 return False
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
190 elif rx == '\x00\x00\x00\x00\xa0\x64\x07':
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
191 return True
55c8dae6d1db Add test code and some (not enabled) sequence checking.
Daniel O'Connor <darius@dons.net.au>
parents: 6
diff changeset
192 else:
26
226ea06bc050 Use "new" style exceptions.
Daniel O'Connor <darius@dons.net.au>
parents: 21
diff changeset
193 raise exceptions.IOError("Unknown SRQ byte sequence - " + str(map(ord, rx)))