-
Notifications
You must be signed in to change notification settings - Fork 1
/
timestamp_eval_delta.py
executable file
·83 lines (65 loc) · 2.4 KB
/
timestamp_eval_delta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python3
"""
Use to verify timestamping's output.
Result is a csv file with the hardware and software RX timestamps, and the
differences between a HW timestamp with its previous, the same difference
diregarding the interval between message, and the difference between the HW
and SW timestamp.
Inputs:
--messages_per_second - interval between messages
--in - file name of timestamping test output
--out - file name to output csv to
"""
import csv
import argparse
import sys
HW_TS_EXP = "HW raw "
def ts_from_line(line, exp):
"""
convert from line printed by timestamping to numpy.longdouble, for specific value
"""
start = line.find(exp)+len(exp)
end = line.find(' ', start)
try:
if (end < 0):
sec, nanosec = line[start:].replace('\n','').split('.')#.replace('.','')
else:
sec, nanosec = line[start:end].replace('\n','').split('.')#.replace('.','')
except:
return 0, 0
return sec, nanosec
def main(in_name, out_name):
"""
args:
messages_per_second - interval between messages
in_name - file name of timestamping test output
out_name - file name to output csv to
"""
packet_num = 0
with open(in_name, 'rb') as fin, open(out_name, 'wb') as fout:
csv_writer = csv.writer(fout, delimiter=',')
csv_writer.writerow(['Packet Num', 'HW Timestamp Seconds', 'HW Timestamp Nanoseconds'])
for i, line in enumerate(fin):
if 'SOL_SOCKET' not in line:
continue
packet_num += 1
if packet_num < 4000:
continue
hw_sec, hw_nsec = ts_from_line(line, HW_TS_EXP)
csv_writer.writerow([packet_num, hw_sec, hw_nsec])
if __name__ == "__main__":
EPILOG = """
Use to verify timestamping's output.
Inputs:
--in - file name of timestamping test output
--out - file name to output csv to
"""
parser = argparse.ArgumentParser(epilog=EPILOG)
parser.add_argument('--in', dest="in_name", type=str,
default="timestamping.out",
help="name of input file")
parser.add_argument('--out', dest="out_name", type=str,
default="timestamp_eval_delta.csv",
help="name of output file")
parsed_args = parser.parse_args()
sys.exit(main(parsed_args.in_name, parsed_args.out_name))