-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnss-tracker.jl
67 lines (54 loc) · 1.7 KB
/
gnss-tracker.jl
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
using NMEA
using Dates
save_each = Dates.Second(60)
hostname = gethostname()
fname = expanduser("~/gnss-tracker-$hostname-$(Dates.format(Dates.now(),"yyyymmddTHHMMSS")).csv")
devicename = "/dev/ttyACM0"
last_saved = typemin(DateTime)
dev = open(devicename,"r")
dev_lines = eachline(dev)
fields = [:longitude,:latitude,:fix_quality,:num_sats,:HDOP]
delim = ','
string_quote = '"'
@info "writing to $fname every $save_each"
open(fname,"w") do fout
println(fout,join(["time",string.(fields)...],delim))
for line in dev_lines
global last_saved
if isempty(line)
continue
end
@debug "parse line" line
try
record = NMEA.parse(line)
if record isa NMEA.GGA
time = Dates.now()
if time > last_saved + save_each
print(fout,time)
print(fout,delim)
for (i,f) in enumerate(fields)
field = getproperty(record,f)
if field isa Number
print(fout,field)
else
print(fout,string_quote,field,string_quote)
end
if i < length(fields)
print(fout,delim)
end
end
println(fout)
flush(fout)
last_saved = time
sleep(save_each)
end
end
catch err
if err isa ArgumentError
@debug "failing to parse record" err
else
rethrow(err)
end
end
end
end