8 |
8 |
9 This file can be exectued as a python script. Use '-h' for more informations. |
9 This file can be exectued as a python script. Use '-h' for more informations. |
10 """ |
10 """ |
11 import struct |
11 import struct |
12 import numpy |
12 import numpy |
13 from HP3562A import format_header, decode_float, decode_string, decode_header |
13 from HP3562A import format_header, decode_float, decode_string, decode_header, read_trace |
14 from HP3562A.enum_types import * |
14 from HP3562A.enum_types import * |
15 |
15 |
16 |
16 |
17 HEADER = [ ("Display function", EDSP, 'h', 2), |
17 HEADER = [ ("Display function", EDSP, 'h', 2), |
18 ('Number of elements', int, 'h', 2), |
18 ('Number of elements', int, 'h', 2), |
59 ('Trig delay chan 2', decode_float, None, 4), |
59 ('Trig delay chan 2', decode_float, None, 4), |
60 ('Start freq value', decode_float, None, 8), |
60 ('Start freq value', decode_float, None, 8), |
61 ('Start data value', decode_float, None, 8), |
61 ('Start data value', decode_float, None, 8), |
62 ] |
62 ] |
63 |
63 |
64 def decode_trace(data): |
64 def decode_trace(data, idx=0): |
65 """ |
65 """ |
66 Decode the data (as generated by the HP3562A DSA in response to a |
66 Decode the data (as generated by the HP3562A DSA in response to a |
67 "DDBN" command), and returns a couple (header, values). |
67 "DDBN" command), and returns a couple (header, values). |
68 |
68 |
69 header is the dictionnary of the header of the dumped data block, |
69 header is the dictionnary of the header of the dumped data block, |
70 value is a numpy array holding the trace (vector of float or |
70 value is a numpy array holding the trace (vector of float or |
71 complex values). |
71 complex values). |
72 """ |
72 """ |
73 header, idx = decode_header(data, HEADER) |
73 header, idx = decode_header(data, HEADER, idx) |
74 resu = [] |
74 return header, read_trace(data, idx, header["Number of elements"]) |
75 for i in range(header["Number of elements"]): |
|
76 resu.append(decode_float(data[idx: idx+4])) |
|
77 idx += 4 |
|
78 return header, numpy.array(resu, dtype=float) |
|
79 |
|
80 |
|
81 |
75 |
82 def main(): |
76 def main(): |
83 import sys |
77 import sys |
84 import optparse |
78 import optparse |
85 opt = optparse.OptionParser("A simple tool for tracing a dumped trace") |
79 opt = optparse.OptionParser("A simple tool for tracing a dumped trace") |