-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPSViewer.lua
More file actions
189 lines (148 loc) · 5.44 KB
/
Copy pathGPSViewer.lua
File metadata and controls
189 lines (148 loc) · 5.44 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
--[[#############################################################################
GPS Position viewer v1.1
Copyright (C) by mosch
License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
GITHUB: https://github.com/moschotto?tab=repositories
Description:
reads the "GPSpositions.txt" log-file which was generated by the GPS.lua script.
useful if want to check the last GPS coordinates after a crash, power loss etc.
copy "GPSviewer.lua" to the /SCRIPTS/TOOLS/ folder
################################################################################]]
local toolName = "TNS|GPSTLog Viewer|TNE"
local log_filename = "/LOGS/GPSpositions.txt"
-- local datenow = getDateTime()
-- local log_filename = "/LOGS/Tracer-" .. datenow.year .. "-" .. datenow.mon .. "-" .. datenow.day .. ".csv"
local file_exist = false
local string_gmatch = string.gmatch
local coordinates = {}
local linectr = 0
local item = 0
local function splitstring(text)
if text ~= nil then
local text_split = {}
local i=0
--split by "," and store into array/table
for word in string_gmatch(text, "([^,]+)") do
text_split[i] = word
i = i + 1
end
return text_split
end
end
-- Date,Time,RSNR(dB),Dst(ft),RxBt(V),GPS,GSpd(kmh),Hdg(@),Alt(m),Sats,Rud,Ele,Thr,Ail,S1,S2,SA,SB,SC,SD,SE,SF,LSW,TxBat(V)
-- 2021-10-12,08:54:27.290,0,0,0.0,,0.0,0.00,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,0x0000000000000008,4.0
local function Viewer_Draw_LCD(item)
lcd.clear()
lcd.drawLine(0,0,0,95, SOLID, FORCE)
lcd.drawLine(127,0,127,95, SOLID, FORCE)
lcd.drawText(2,1,"GPS Position viewer v1.1" ,SMLSIZE)
lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT)
lcd.drawLine(60,8, 60, 19, SOLID, FORCE)
lcd.drawText(64,11, "Sats:",SMLSIZE)
lcd.drawLine(97,8, 97, 19, SOLID, FORCE)
lcd.drawLine(0,19, 128, 19, SOLID, FORCE)
lcd.drawText(100,11, (item + 1).."/" .. linectr,SMLSIZE)
if item < 4 then
--first 4 rows static
local line0 = splitstring(coordinates[0])
local line1 = splitstring(coordinates[1])
local line2 = splitstring(coordinates[2])
local line3 = splitstring(coordinates[3])
if item == 0 then
lcd.drawText(2,11, "Time:" .. string.gsub(line0[3], "%s+", ""), SMLSIZE)
lcd.drawText(64,11, "Sats:" .. string.gsub(line0[4], "%s+","") ,SMLSIZE)
lcd.drawText(2,24, line0[1] .."," .. line0[2] ,SMLSIZE + BLINK + INVERS)
else
lcd.drawText(2,24, line0[1] .."," .. line0[2] ,SMLSIZE)
end
if item == 1 then
lcd.drawText(2,11, "Time:" .. string.gsub(line1[3], "%s+",""), SMLSIZE)
lcd.drawText(64,11, "Sats:" .. string.gsub(line1[4], "%s+","") ,SMLSIZE)
lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE + BLINK + INVERS)
else
lcd.drawText(2,44, line1[1] .."," .. line1[2] ,SMLSIZE)
end
if item == 2 then
lcd.drawText(2,11, "Time:" .. string.gsub(line2[3], "%s+",""), SMLSIZE)
lcd.drawText(64,11, "Sats:" .. string.gsub(line2[4], "%s+","") ,SMLSIZE)
lcd.drawText(2,64, line2[1] .."," .. line2[2] ,SMLSIZE + BLINK + INVERS)
else
lcd.drawText(2,64, line2[1] .."," .. line2[2] ,SMLSIZE)
end
if item == 3 then
lcd.drawText(2,11, "Time:" .. string.gsub(line3[3], "%s+",""), SMLSIZE)
lcd.drawText(64,11, "Sats:" .. string.gsub(line3[4], "%s+","") ,SMLSIZE)
lcd.drawText(2,84, line3[1] .."," .. line3[2] ,SMLSIZE + BLINK + INVERS)
else
lcd.drawText(2,84, line3[1] .."," .. line3[2] ,SMLSIZE)
end
else
local line0 = splitstring(coordinates[item-3])
local line1 = splitstring(coordinates[item-2])
local line2 = splitstring(coordinates[item-1])
local line3 = splitstring(coordinates[item])
lcd.drawText(2,11, "Time:" .. string.gsub(line3[3], "%s+",""), SMLSIZE)
lcd.drawText(64,11, "Sats:" .. string.gsub(line3[4], "%s+","") ,SMLSIZE)
lcd.drawText(2,24, line0[1] .."," .. line0[2],SMLSIZE)
lcd.drawText(2,44, line1[1] .."," .. line1[2],SMLSIZE)
lcd.drawText(2,64, line2[1] .."," .. line2[2],SMLSIZE)
lcd.drawText(2,84, line3[1] .."," .. line3[2],SMLSIZE + BLINK + INVERS)
end
lcd.drawLine(0,95,127,95, SOLID, FORCE)
end
local function Viewer_Init()
lcd.clear()
local f2 = io.open(log_filename, "r")
--check if file exists
if f2 ~= nil then
file_exist = true
buffer = io.read(f2, 4096)
io.close(f2)
--read file contents into array/table
for line in string_gmatch(buffer, "([^\n]+)\n") do
coordinates[linectr] = line
linectr = linectr + 1
end
--draw inital screen
Viewer_Draw_LCD(0)
else
file_exist = false
end
end
-- Main
local function Viewer_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
else
if file_exist == true then
Viewer_Draw_LCD(item)
--handle scroll counter
if event == EVT_ROT_RIGHT or event == EVT_PLUS_FIRST then
if item < linectr-1 then
item = item + 1
end
end
if event == EVT_ROT_LEFT or event == EVT_MINUS_FIRST then
if item > 0 then
item = item - 1
end
end
else
--display error message
lcd.clear()
lcd.drawLine(0,0,0,64, SOLID, FORCE)
lcd.drawLine(127,0,127,64, SOLID, FORCE)
lcd.drawText(2,1,"GPS Postion viewer" ,SMLSIZE)
lcd.drawFilledRectangle(1,0, 126, 9, GREY_DEFAULT)
lcd.drawText(10,20, "Logfile does not exist", SMLSIZE)
lcd.drawText(10,30, log_filename, SMLSIZE + BLINK)
lcd.drawLine(0,62, 128, 62, SOLID, FORCE)
end
if event == EVT_VIRTUAL_EXIT then
return 2
end
end
return 0
end
return { init=Viewer_Init, run=Viewer_Run }