forked from gtjoseph/mt3339-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epoinfo
executable file
·88 lines (74 loc) · 2.34 KB
/
epoinfo
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
84
85
86
87
88
#!/usr/bin/python -uO
import sys
import io
import struct
import time
import argparse
PREAMBLE = 0x2404
COMMAND = 0x02d2
EOW = 0x0a0d
UART_CMD = 253
SATS_PER_EPO = 32
SECONDS_PER_HOUR = 3600
GPS_OFFSET_SECONDS = 315964786
SECONDS_PER_WEEK = 604800
HOURS_PER_WEEK = 168
def Convert2UTC(GPSHour):
GPSHour *= SECONDS_PER_HOUR
GPSHour += GPS_OFFSET_SECONDS
tm = time.gmtime(GPSHour)
return time.strftime("%Y-%m-%d %H:%M:%S", tm)
def Convert2Local(GPSHour):
GPSHour *= SECONDS_PER_HOUR
GPSHour += GPS_OFFSET_SECONDS
tm = time.localtime(GPSHour)
return time.strftime("%Y-%m-%d %H:%M:%S", tm)
def crc8(d):
crc = 0
for b in bytearray(d):
crc ^= (b & 0xff)
return crc
def convert_arg_line_to_args(arg_line):
for arg in arg_line.split():
if not arg.strip():
continue
yield arg
def main():
parser = argparse.ArgumentParser(fromfile_prefix_chars='@',
description="Prints EPO file information",
epilog="You can use '@filename' to read arguments from a file.")
parser.convert_arg_line_to_args = convert_arg_line_to_args
parser.add_argument("input_file", metavar="<EPO_File>", help="EPO data file")
args = parser.parse_args()
fi = io.open(args.input_file, mode="rb")
header = fi.read(75)
if header[0:3] == header[60:63]:
print("Opening EPO Type I file")
EPO_SET_SIZE = 1920
elif header[0:3] == header[72:75]:
print("Opening EPO Type II file")
EPO_SET_SIZE = 2304;
else:
print("Unknown file type.")
return 1
fi.close()
fi = io.open(args.input_file, mode="rb")
sets = 0
while True:
epo_set = fi.read(EPO_SET_SIZE)
if len(epo_set) == 0:
break
sets += 1
epo_start = struct.unpack("<i", epo_set[0:3]+b'\0')[0]
if sets == 1:
start = epo_start
print("Set: %4d. GPS Wk: %4d Hr: %3d Sec: %6d %s to %s UTC" % (
sets, (epo_start / HOURS_PER_WEEK), (epo_start % HOURS_PER_WEEK),
(epo_start % HOURS_PER_WEEK) * SECONDS_PER_HOUR,
Convert2UTC(epo_start), Convert2UTC(epo_start + 6)))
fi.close()
print("%4d EPO sets. Valid from %s to %s UTC\n" % (sets,
Convert2UTC(start), Convert2UTC(epo_start + 6)))
return 0
if __name__ == "__main__":
sys.exit(main() or 0)