HP3562A/read_trace.py

Mon, 17 Dec 2007 18:59:45 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 17 Dec 2007 18:59:45 +0100
changeset 13
78e3e839658b
parent 11
3ccb0023cf41
permissions
-rw-r--r--

some forgotten added files

0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 import struct
10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
4 import numpy
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 def decode_float(s):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 assert len(s) in [4,8]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 # exponential term
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 e = ord(s[-1])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 if e & 0x80:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 e = e - 256
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 # mantissa
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15 m = [ord(x) for x in s[:-1]]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 M = 0.
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 for i in range(len(s)-1):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18 #M += m[i]<<(i*8)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 M += float(m[i])/2**((i+1)*8)
6
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
20 # XXX how do we deal negative numbers?
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 #if m[0] & 0x80:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 # M = M - 2^(len(s))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 return M * 2**(e+1)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25 def decode_string(s):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 nb = ord(s[0])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 s = s[1:nb+2]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 r = ""
6
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
29 # XXX why do we need to do this? It's not described in the manual...
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 for c in s:
6
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
31 r += chr(ord(c) & 0x7F)
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32 return r
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 EDSP = {0: "No data",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 1: "Frequency response",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 2: "Power spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 3: "Power spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 4: "Coherence",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 5: "Cross spectrum",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 6: "Input time 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41 7: "Input time 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 8: "Input linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 9: "Input linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 10: "Impulse response",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 11: "Cross correlation",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 12: "Auto correlation 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47 13: "Auto correlation 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 14: "Histogram 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49 15: "Histogram 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 16: "Cumulative density function 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 17: "Cumulative density function 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52 18: "Probability density function 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53 19: "Probability density function 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 20: "Average linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55 21: "Average linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56 22: "Average time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 23: "Average time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 24: "Synthesis pole-zeros",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 25: "Synthesis pole-residue",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60 26: "Synthesis polynomial",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 27: "Synthesis constant",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62 28: "Windowed time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 29: "Windowed time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64 30: "Windowed linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 31: "Windowed linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 32: "Filtered time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67 33: "Filtered time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 34: "Filtered linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 35: "Filtered linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 36: "Time capture buffer",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 37: "Captured linear spectrum",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 38: "Captured time record",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 39: "Throughput time record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 40: "Throughput time record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75 41: "Curve fit",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 42: "Weighted function",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 43: "Not used",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 44: "Orbits",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79 45: "Demodulation polar",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 46: "Preview demod record 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81 47: "Preview demod record 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 48: "Preview demod linear spectrum 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 49: "Preview demod linear spectrum 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 ECH = {0: "Channel 1",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87 1: "Channel 2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88 2: "Channel 1&2",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 3: "No channel",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
90 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
91
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92 EOVR = ECH
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 EDOM = {0: 'Time',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95 1: 'Frequency',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 2: 'Voltage (amplitude)',
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99 EVLT = {0: "Peak",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100 1: "RMS",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 2: "Volt (indicates peak only)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 EAMP = {0: "Volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105 1: "Volts squared",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106 2: "PSD (V²/Hz)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
107 3: "ESD (V²s/Hz)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
108 4: "PSD¹² (V/Hz¹²)",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
109 5: "No unit",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
110 6: "Unit volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
111 7: "Unit volts²",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
112 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
113
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
114 EXAXIS= {0: "No units",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
115 1: "Hertz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
116 2: "RPM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
117 3: "Orders",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
118 4: "Seconds",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
119 5: "Revs",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
120 6: "Degrees",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
121 7: "dB",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
122 8: "dBV",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
123 9: "Volts",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
124 10: "V Hz¹²",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
125 11: "Hz/s",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
126 12: "V/EU",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
127 13: "Vrms",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
128 14: "V²/Hz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
129 15: "%",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
130 16: "Points",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
131 17: "Records",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
132 18: "Ohms",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
133 19: "Hertz/octave",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
134 20: "Pulse/Rev",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
135 21: "Decades",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
136 22: "Minutes",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
137 23: "V²s/Hz",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
138 24: "Octave",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
139 25: "Seconds/Decade",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
140 26: "Seconds/Octave",
6
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
141 27: "Hz/Point",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
142 28: "Points/Sweep",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
143 29: "Points/Decade",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
144 30: "Points/Octave",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
145 31: "V/Vrms",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
146 32: "V²",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
147 33: "EU referenced to chan 1",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
148 34: "EU referenced to chan 2",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
149 35: "EU value",
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
150 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
151
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
152 EMEAS = {0: "Linear resolution",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
153 1: "Log resolution",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
154 2: "Swept sine",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
155 3: "Time capture",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
156 4: "Linear resolution throughput",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
157 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
158
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
159 EDEMOD1 = {45: "AM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
160 46: "FM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
161 47: "PM",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
162 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
163
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
164 EDEMOD2 = EDEMOD1
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
165
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
166 EAVG = {0: "No data",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
167 1: "Not averaged",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
168 2: "Averaged",}
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
169
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
170
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
171
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
172 EWIN = {0: "N/A",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
173 1: "Hann",
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
174 2: "Flat top",
6
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
175 3: "Uniforme",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
176 4: "Exponential",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
177 5: "Force",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
178 6: "Force chan 1/expon chan 2",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
179 7: "Expon chan 1/force chan 2",
6b6dc68588b2 completed missing constants
David Douard <david.douard@logilab.fr>
parents: 0
diff changeset
180 8: "User",
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
181 }
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
182
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
183 HEADER = [ ("Display function", EDSP, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
184 ('Number of elements', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
185 ('Displayed elements', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
186 ('Number of averages', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
187 ('Channel selection', ECH, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
188 ('Overflow status', EOVR, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
189 ('Overlap percentage', int, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
190 ('Domain', EDOM, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
191 ('Volts peak/rms', EVLT, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
192 ('Amplitude units', EAMP, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
193 ('X axis units', EXAXIS, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
194 ('Auto math label', str, 's', 14),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
195 ('Trace label', str, 's', 22),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
196 ('EU label 1', str, 's', 6),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
197 ('EU label 2', str, 's', 6),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
198 ('Float/Interger', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
199 ('Complex/Real', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
200 ('Live/Recalled', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
201 ('Math result', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
202 ('Real/Complex input', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
203 ('Log/Linear data', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
204 ('Auto math', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
205 ('Real time status', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
206 ('Measurement mode', EMEAS, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
207 ('Window', EWIN, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
208 ('Demod type channel 1', EDEMOD1, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
209 ('Demod type channel 2', EDEMOD2, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
210 ('Demod active channel 1', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
211 ('Demod active channel 2', bool, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
212 ('Average status', EAVG, 'h', 2),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
213 ('Not used', int, 'hh', 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
214 ('Samp freq/2 (real)', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
215 ('Samp freq/2 (imag)', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
216 ('Not used', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
217 ('Delta X-axis', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
218 ('Max range', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
219 ('Start time value', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
220 ('Expon wind const 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
221 ('Expon wind const 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
222 ('EU value chan 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
223 ('EU value chan 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
224 ('Trig delay chan 1', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
225 ('Trig delay chan 2', decode_float, None, 4),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
226 ('Start freq value', decode_float, None, 8),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
227 ('Start data value', decode_float, None, 8),
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
228 ]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
229
10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
230 def decode_trace(data):
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
231 d = data
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
232
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
233 typ = d[:2]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
234 assert typ == "#A"
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
235
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
236 totlen = struct.unpack('>h', d[2:4])[0]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
237 idx = 4
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
238 tt=0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
239 header = {}
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
240 for i, (nam, dtype, fmt, nbytes) in enumerate(HEADER):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
241 if dtype == str:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
242 val = decode_string(d[idx:])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
243 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
244 if fmt:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
245 v = struct.unpack('>'+fmt, d[idx: idx+nbytes])[0]
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
246 if isinstance(dtype, dict):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
247 val = dtype.get(int(v), "N/A")
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
248 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
249 val = dtype(v)
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
250 else:
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
251 val = dtype(d[idx: idx+nbytes])
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
252 header[nam] = val
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
253 idx += nbytes
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
254 resu = []
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
255 for i in range(header["Number of elements"]):
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
256 resu.append(decode_float(d[idx: idx+4]))
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
257 idx += 4
10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
258 return header, numpy.array(resu, dtype=float)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
259
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
260 def format_header(header, head_struct, columns=80):
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
261 todisp = []
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
262 for row in head_struct:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
263 key = row[0]
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
264 val = header.get(key, "N/A")
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
265 if isinstance(val, basestring):
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
266 val = repr(val)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
267 else:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
268 val = str(val)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
269 todisp.append((key+":", val))
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
270 maxk = max([len(k) for k, v in todisp])
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
271 maxv = max([len(v) for k, v in todisp])
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
272 fmt = "%%-%ds %%-%ds"%(maxk, maxv)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
273 w = maxk+maxv+4
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
274 ncols = columns/w
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
275 nrows = len(todisp)/ncols
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
276 print "w=", w
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
277 print "ncols=", ncols
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
278 print "nrows=", nrows
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
279 res = ""
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
280 for i in range(nrows):
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
281 res += "| ".join([fmt%todisp[j*nrows+i] for j in range(ncols)]) + "\n"
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
282 return res
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
283
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
284
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
285 if __name__ == "__main__":
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
286 import sys
10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
287 import optparse
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
288 opt = optparse.OptionParser("A simple tool for tracing a dumped trace")
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
289 opt.add_option('-f', '--filename', default=None,
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
290 dest='filename',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
291 help='Output filename. If not set, read from stdin')
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
292 opt.add_option('-m', '--mode', default='binary',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
293 dest='mode',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
294 help='Dumping mode (may be "binary" [default], "ascii" or "ansi")',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
295 )
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
296 opt.add_option('-d', '--display-header', default=False,
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
297 action="store_true",
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
298 dest="displayheader",
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
299 help="Display the trace header")
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
300 opt.add_option('-P', '--noplot-trace', default=True,
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
301 action="store_false",
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
302 dest="plot",
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
303 help="Do not display the plot of the trace")
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
304 opt.add_option('-x', '--xmode', default='lin',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
305 dest='xmode',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
306 help='X coordinate mode (may be "lin" [default] or "log")')
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
307 opt.add_option('-y', '--ymode', default='lin',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
308 dest='ymode',
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
309 help='Y coordinate mode (may be "lin" [default], "log" or "db")')
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
310
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
311 options, argv = opt.parse_args(sys.argv)
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
312
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
313
10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
314 if options.filename is None:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
315 print "Can't deal stdin for now..."
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
316 sys.exit(1)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
317 try:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
318 header, data = decode_trace(open(options.filename, 'rb').read())
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
319 except Exception, e:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
320 print "ERROR: can't read %s an interpret it as a HP3562 trace"%options.filename
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
321 print e
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
322 sys.exit(1)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
323
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
324 if options.displayheader:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
325 print format_header(header, HEADER, 100)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
326 if options.plot:
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
327 f0 = header['Start freq value']
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
328 dx = header['Delta X-axis']
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
329 n = header['Number of elements']
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
330 x = numpy.linspace(f0, f0+dx*n, len(data))
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
331 y = data.copy()
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
332
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
333 import pylab
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
334 if options.ymode != "lin":
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
335 minv = min(y[y>0])
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
336 y[y==0] = minv
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
337 y = numpy.log10(y)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
338 if options.ymode == "db":
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
339 y = y*10
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
340 pylab.ylabel('db')
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
341 pylab.grid()
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
342 pylab.plot(x, y)
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
343 pylab.xlabel('frequency')
2999318b49a2 many improvements in the read/dump trace tools.
David Douard <david.douard@logilab.fr>
parents: 6
diff changeset
344 pylab.show()
0
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
345
9af1509775b6 initial import
David Douard <david.douard@logilab.fr>
parents:
diff changeset
346

mercurial