annotate sirf.py @ 5:f3547b32c7c5 default tip

Don't set timeout in parser class otherwise we can't use it for FIFO files.
author Daniel O'Connor <darius@dons.net.au>
date Fri, 02 Aug 2019 12:14:26 +0930
parents 2fde8c382dae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
1 #!/usr/bin/env python
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
2
5
f3547b32c7c5 Don't set timeout in parser class otherwise we can't use it for FIFO files.
Daniel O'Connor <darius@dons.net.au>
parents: 4
diff changeset
3 # Copyright (c) 2019
3
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
5 #
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
6 # Redistribution and use in source and binary forms, with or without
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
7 # modification, are permitted provided that the following conditions
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
8 # are met:
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
9 # 1. Redistributions of source code must retain the above copyright
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
10 # notice, this list of conditions and the following disclaimer.
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
11 # 2. Redistributions in binary form must reproduce the above copyright
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
12 # notice, this list of conditions and the following disclaimer in the
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
13 # documentation and/or other materials provided with the distribution.
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
14 #
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
25 # SUCH DAMAGE.
387e6e928567 Add 2 clause BSDL.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
26
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
27 import time, struct, os
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
28
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
29 # SiRF at 9600 baud
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
30 nmea2sirf = '$PSRF100,0,9600,8,1,0*0C\r\n'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
31
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
32 # NMEA at 4800 baud
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
33 # Use like so
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
34 # s.write(sirf.Parser.OrdLsttoStr(sirf.Parser.Encap(sirf.sirf2nmea)))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
35 sirf2nmea = [ 0x81, 0x02, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x05, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x12, 0xc0 ]
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
36
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
37 #s.write(sirf.Parser.OrdLsttoStr(sirf.Parser.Encap(sirf.getver)))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
38 getver = [ 0x84, 0x00 ]
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
39
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
40 # Messages from engine
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
41 sirfoutpktdsc = {
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
42 0x01 : "Reference Navigation Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
43 0x02 : "Measured Navigation Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
44 0x03 : "True Tracker Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
45 0x04 : "Measured Tracking Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
46 0x05 : "Raw Track Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
47 0x06 : "SW Version",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
48 0x07 : "Clock Status",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
49 0x08 : "50 BPS Subframe Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
50 0x09 : "Throughput",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
51 0x0a : "Error ID",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
52 0x0b : "Command Acknowledgment",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
53 0x0c : "Command NAcknowledgment",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
54 0x0d : "Visible List",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
55 0x0e : "Almanac Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
56 0x0f : "Ephemeris Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
57 0x10 : "Test Mode 1",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
58 0x11 : "Differential Corrections",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
59 0x12 : "OkToSend",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
60 0x13 : "Navigation Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
61 0x14 : "Test Mode 2/3/4",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
62 0x1b : "DGPS Status",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
63 0x1c : "Nav. Lib. Measurement Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
64 0x1d : "Nav. Lib. DGPS Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
65 0x1e : "Nav. Lib. SV State Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
66 0x1f : "Nav. Lib. Initialization Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
67 0x29 : "Geodetic Navigation Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
68 0x2d : "Raw DR Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
69 0x2e : "Test Mode 3",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
70 0x30 : "SiRFDRive-specific Class of Output Messages",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
71 0x31 : "Test Mode 4 for SiRFLoc v2.x only",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
72 0x32 : "SBAS Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
73 0x34 : "1 PPS Time Message",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
74 0x37 : "Test Mode 4",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
75 0x38 : "Extended Ephemeris Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
76 0xe1 : "SiRF internal message",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
77 0xff : "Development Data"
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
78 }
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
79
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
80 # Messages to engine
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
81 sirfinpktdsc = {
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
82 0x35 : "Advanced Power Management",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
83 0x80 : "Initialize Data Source",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
84 0x81 : "Switch to NMEA Protocol",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
85 0x82 : "Set Almanac (upload)",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
86 0x83 : "Handle Formatted Dump Data",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
87 0x84 : "Poll Software Version",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
88 0x85 : "DGPS Source Control",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
89 0x86 : "Set Main Serial Port",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
90 0x87 : "Switch Protocol",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
91 0x88 : "Mode Control",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
92 0x89 : "DOP Mask Control",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
93 0x8a : "DGPS Mode",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
94 0x8b : "Elevation Mask",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
95 0x8c : "Power Mask",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
96 0x8d : "Editing Residual",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
97 0x8e : "Steady-State Detection",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
98 0x8f : "Static Navigation",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
99 0x90 : "Poll Clock Status",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
100 0x91 : "Set DGPS Serial Port",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
101 0x92 : "Poll Almanac",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
102 0x93 : "Poll Ephemeris",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
103 0x94 : "Flash Update",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
104 0x95 : "Set Ephemeris (upload)",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
105 0x96 : "Switch Operating Mode",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
106 0x97 : "Set TricklePower Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
107 0x98 : "Poll Navigation Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
108 0xa5 : "Set UART Configuration",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
109 0xa6 : "Set Message Rate",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
110 0xa7 : "Set Low Power Acquisition Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
111 0xa8 : "Poll Command Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
112 0xaa : "Set SBAS Parameters",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
113 0xac : "SiRFDRive-specific",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
114 0xb4 : "Marketing Software Configuration",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
115 0xb6 : "Set UART Configuration",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
116 0xe4 : "SiRF internal message",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
117 0xe8 : "Extended Ephemeris Proprietary"
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
118 }
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
119
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
120 def fmtlatlong(x):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
121 deg = int(x)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
122 min = abs((x - deg) * 60)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
123 sec = abs((min - int(min)) * 60)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
124
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
125 return "%dd%dm%.3f" % (deg, int(min), sec)
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
126
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
127 class Parser(object):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
128 def __init__(self, s = None):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
129 self.buffer = []
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
130 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
131
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
132 self.fr_err = 0 # Framing error
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
133 self.ck_err = 0 # Checksum error
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
134 self.rx_cnt = 0 # Packet count
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
135
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
136 self.pktq = []
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
137 self.s = s
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
138
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
139 def processstr(self, data):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
140 return self.process(map(ord, data))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
141
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
142 def process(self, data):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
143 pktcount = 0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
144 for d in data:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
145 #print "Looking at 0x%02x, state = %s" % (d, self.state)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
146 if (self.state == 'init1'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
147 self.buffer = []
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
148 if (d != 0xa0):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
149 print "Start1 framing error, got 0x%02x, expected 0xa0" % d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
150 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
151 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
152
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
153 self.state = 'init2'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
154 elif (self.state == 'init2'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
155 if (d != 0xa2):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
156 print "Start2 framing error, got 0x%02x, expected 0xa2" % d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
157 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
158 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
159 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
160
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
161 self.state = 'sizemsb'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
162 elif (self.state == 'sizemsb'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
163 #print "Size1 - 0x%02x" % (d)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
164 if d > 0x7f:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
165 print "size msb too high (0x%02x)" % (d)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
166 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
167 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
168 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
169
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
170 self.sizemsb = d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
171 self.state = 'sizelsb'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
172 elif (self.state == 'sizelsb'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
173 #print "Size2 - 0x%02x" % (d)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
174 self.dataleft = self.sizemsb << 8 | d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
175 if self.dataleft < 1:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
176 print "size is too small (0x%04x)" % (self.dataleft)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
177 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
178 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
179 if self.dataleft > 1024:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
180 print "size too large (0x%04x)" % (self.dataleft)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
181 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
182 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
183 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
184 #print "Pkt size - 0x%04x" % (self.dataleft)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
185 self.state = 'data'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
186 elif (self.state == 'data'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
187 self.buffer.append(d)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
188 self.dataleft = self.dataleft - 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
189
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
190 if self.dataleft == 0:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
191 self.state = 'cksum1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
192
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
193 elif (self.state == 'cksum1'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
194 self.cksummsb = d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
195 self.state = 'cksum2'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
196 elif (self.state == 'cksum2'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
197 self.rxcksum = self.cksummsb << 8 | d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
198 self.state = 'end1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
199 elif (self.state == 'end1'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
200 if (d != 0xb0):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
201 print "End1 framing error, got 0x%02x, expected 0xb0" % d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
202 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
203 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
204 continue
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
205
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
206 self.state = 'end2'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
207 elif (self.state == 'end2'):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
208 if (d != 0xb3):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
209 print "End2 framing error, got 0x%02x, expected 0xb3" % d
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
210 self.fr_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
211 else:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
212 pktsum = reduce(lambda x, y: x + y, self.buffer) & 0x7fff
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
213 if (pktsum != self.rxcksum):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
214 print "Checksum error: got 0x%04x, expected 0x%04x" % \
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
215 (self.rxcksum, pktsum)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
216 print "buffer is %s" % (str(self.buffer))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
217 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
218 self.ck_err += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
219 else:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
220 p = Parser.Build(self.buffer)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
221 #self.pktq.append(p)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
222 pktcount += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
223 self.rx_cnt += 1
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
224
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
225 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
226 else:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
227 print "Invalid state %s! Resetting" % (self.state)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
228 self.state = 'init1'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
229
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
230 return pktcount
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
231
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
232 def dumpmsgs(self, s):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
233 while True:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
234 self.processstr(s.read(100))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
235
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
236 @classmethod
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
237 def Encap(self, data):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
238 cksum = reduce(lambda x, y: x + y, data)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
239 dlen = len(data)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
240 out = [ 0xa0, 0xa2 ]
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
241 out.append((dlen & 0xff00) >> 8)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
242 out.append(dlen & 0xff)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
243 out.extend(data)
4
2fde8c382dae SiRF uses a 15 bit checksum, see section 1-2
Daniel O'Connor <darius@dons.net.au>
parents: 3
diff changeset
244 out.append((cksum & 0x7f00) >> 8) # 15 bit checksum
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
245 out.append(cksum & 0xff)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
246 out.extend([0xb0, 0xb3])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
247 return out
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
248
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
249 @classmethod
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
250 def OrdLsttoStr(self, data):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
251 return reduce(lambda x, y: x + y, map(chr, data))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
252
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
253 @classmethod
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
254 def Build(self, data):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
255 t = time.time()
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
256 t1 = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(t))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
257 t2 = (t - int(t)) * 1e3
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
258 tfmt = "%s.%03d" % (t1, t2)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
259 if data[0] in sirfoutpktdsc:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
260 print "%s: Got out packet 0x%02x : %s" % (tfmt, data[0], sirfoutpktdsc[data[0]])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
261 elif data[0] in sirfinpktdsc:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
262 print "%s: Got in packet 0x%02x : %s" % (tfmt, data[0], sirfinpktdsc[data[0]])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
263 else:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
264 print "%s: Unknown packet type 0x%02x" % (tfmt, data[0])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
265 print "Payload - " + str(data[1:])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
266
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
267 if data[0] == 0x02:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
268 fmt = '>iiihhhBBBhIB'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
269 datastr = reduce(lambda x, y: x + y, map(chr, data[1:struct.calcsize(fmt) + 1]))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
270 (xpos, ypos, zpos, xvel, yvel, zvel, mode1, hdop, mode2, gpsweek, gpstow, nsats) = \
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
271 struct.unpack(fmt, datastr)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
272
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
273 satprn = []
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
274 for i in xrange(nsats):
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
275 satprn.append(data[struct.calcsize(fmt) - 1 + i])
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
276
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
277 xvel = float(xvel) / 8
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
278 yvel = float(yvel) / 8
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
279 zvel = float(zvel) / 8
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
280 hdop = float(hdop) / 5
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
281 gpstow = float(gpstow) / 100
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
282
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
283 print " Position: X: %d m, Y: %d m, Z: %d m" % (xpos, ypos, zpos)
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
284 print " Velocity: X: %.2f m/s, Y: %.2f m/s, Z: %.2f m/s" % (xvel, yvel, zvel)
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
285 print " HDOP: %.1f, Week: %d, TOW: %.2f seconds" % (hdop, gpsweek, gpstow)
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
286 elif data[0] == 0x06:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
287 nulidx = data.index(0)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
288 print " SW Ver : %s" % (reduce(lambda x, y: x + y, map(chr, data[1:nulidx])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
289 elif data[0] == 0x0a:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
290 errid = data[1] << 8 | data[2]
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
291 dlen = (data[3] << 8 | data[4]) * 4
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
292 print " Error ID : 0x%04x" % (errid)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
293 if dlen > 0:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
294 print " Length : 0x%04x" % (dlen)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
295 print " Payload : %s" % (data[5:])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
296 elif data[0] == 0x0b:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
297 print " Cmd Ack : 0x%02x" % (data[1])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
298 elif data[0] == 0x0c:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
299 print " Cmd NAck : 0x%02x" % (data[1])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
300 elif data[0] == 0x29:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
301 fixtype = {
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
302 0 : "none",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
303 1 : "1-SV KF",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
304 2 : "2-SV KF",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
305 3 : "3-SV KF",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
306 4 : "4+-SV KF",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
307 5 : "2D",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
308 6 : "3D",
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
309 7 : "DR"
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
310 }
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
311 fmt = '>HHHIHBBBBHIiiiiBHHHHHIIIHIIIIIHHBBB'
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
312 datastr = reduce(lambda x, y: x + y, map(chr, data[1:struct.calcsize(fmt) + 1]))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
313 (navval, navtype, ewn, tow, year, month, day, hour, minute, second, satlst,
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
314 latitude, longitude, alt_elip, alt_msl, datum, sog, cog, magvar, climbrate,
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
315 headrate, estHPE, estVPE, estTE, estHVE, clockbias, CBerr, clockdrift,
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
316 CDerr, distance, distanceErr, headErr, numsvs, hdop, addmodeinfo) = \
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
317 struct.unpack(fmt, datastr)
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
318 tow = float(tow) / 1e3
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
319 second = float(second) / 1e3
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
320 latitude = float(latitude) / 1e7
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
321 longitude = float(longitude) / 1e7
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
322 alt_elip = float(alt_elip) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
323 alt_msl = float(alt_msl) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
324 sog = float(sog) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
325 cog = float(cog) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
326 climbrate = float(climbrate) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
327 headrate = float(headrate) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
328 estHPE = float(estHPE) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
329 estVPE = float(estVPE) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
330 estTE = float(estTE) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
331 estHVE = float(estHVE) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
332 clockbias = float(clockbias) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
333 CBerr = float(CBerr) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
334 clockdrift = float(clockdrift) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
335 CDerr = float(CDerr) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
336 headErr = float(headErr) / 1e2
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
337 hdop = float(hdop) / 5
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
338
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
339 utctime = timegm((year, month, day, hour, minute, int(second)))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
340 utctime = utctime + (second - int(second))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
341 print " Fix : %s, Sats : %d, Lat: %.06f, Long: %.06f, Alt: %.02fm" % \
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
342 (fixtype[navtype & 0x7], numsvs, latitude, longitude, alt_msl)
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
343 print " Date : %04d/%02d/%02d %02d:%02d:%02d.%03d" % \
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
344 (year, month, day, hour, month, int(second), int((second - int(second)) * 1000))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
345 print " Epoch time : %.3f, Delta %.3f" % (utctime, abs(time.time() - utctime))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
346 elif data[0] == 0x34:
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
347 fmt = '>BBBBBHHIB'
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
348 datastr = reduce(lambda x, y: x + y, map(chr, data[1:struct.calcsize(fmt) + 1]))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
349 (hour, minute, second, day, month, year, offsetint, offsetfrac, status) = \
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
350 struct.unpack(fmt, datastr)
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
351 offset = offsetint + float(offsetfrac) / 1e9
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
352 print " PPS : %04d/%02d/%02d %02d:%02d:%02d, Offset : %.9f, Status : 0x%02x" % \
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
353 (year, month, day, hour, minute, second, offset, status)
0
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
354 elif data[0] == 0xa6:
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
355 print " Message rate : MID 0x%02x, rate 0x%02x" % (data[2], data[3])
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
356
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
357 def enablemsgs(s):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
358 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
359 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
360 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
361 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
362 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
363 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x29, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
364 #s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x34, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
365 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x1b, 0x01, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
366
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
367
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
368 def disablemsgs(s):
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
369 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
370 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
371 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
372 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
373 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
374 #s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
375 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
376 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
377 s.write(Parser.OrdLsttoStr(Parser.Encap([0xa6, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00])))
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
378
6503256a3fc4 Prototype code for parsing SiRF messages.
darius@Inchoate
parents:
diff changeset
379
2
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
380 def timegm(tuple):
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
381 oldtz = None
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
382 if 'TZ' in os.environ:
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
383 oldtz = os.environ['TZ']
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
384 os.environ['TZ'] = 'UTC'
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
385
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
386 t = time.mktime(tuple + (0, 0, 0))
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
387 if oldtz == None:
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
388 del os.environ['TZ']
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
389 else:
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
390 os.environ['TZ'] = oldtz
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
391
d6d9fba5464d Log more info and in a better fashion.
darius@Inchoate
parents: 0
diff changeset
392 return t