-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhgps.lua
92 lines (66 loc) · 1.88 KB
/
hgps.lua
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
local hfile = require 'hfile'
local htime = require 'htime'
local hconstants = require 'hconstants'
local hexecute = require 'hexecute'
local hlog = require 'hlog'
local hgps = {
__VERSION = '1.0',
__DESCRIPTION = 'GPS methods',
}
function hgps.test()
print("hgps merge")
end
function hgps.errorFct()
print('error gps')
end
function hgps.executeGetGpsCoordinates()
local latitude = hexecute.execute('gpsctl -- latitude')
if(latitude == nil or latitude == '') then
return nil
end
hlog.logToFile('gps latitude ' .. latitude)
if(latitude == 256 or latitude == '256') then
return nil
end
local longitude = hexecute.execute('gpsctl -- longitude')
local response = latitude .. ',' .. longitude
return response
end
function hgps.tryExecuteGetGPS()
status, ret = xpcall(hgps.executeGetGpsCoordinates, hgps.errorFct)
if(ret ~= nil) then
return ret
else
return nil
end
end
function hgps.tryGetGpsCoordinates()
local gps_reouter = hgps.tryExecuteGetGPS()
if (gps_reouter ~= nil) then
hfile.writeToFile(hconstants.SETTINGS_DIRECTORY .. '/' .. hconstants.GPS_FILE, gps_reouter)
return gps_reouter
end
return hgps.readCoordinatesFromFile()
end
function hgps.writeCoordinatesToFile(coordinates)
hfile.writeToFile(hconstants.SETTINGS_DIRECTORY .. '/' .. hconstants.GPS_FILE, coordinates)
end
function hgps.readCoordinatesFromFile()
local fileContent = hfile.readFile(hconstants.SETTINGS_DIRECTORY .. '/' .. hconstants.GPS_FILE)
return fileContent or '46.76775971140317,23.553090097696654';
end
function hgps.getGpsTime()
local response = hexecute.execute('gpsctl --datetime')
return response
end
function hgps.tryGetGpsTime()
status, ret = xpcall(hgps.getGpsTime, hgps.errorFct)
-- print(status)
if(ret ~= nil) then
return ret
else
return '0:0'
end
end
-- print(hgps.tryExecuteGetGPS())
return hgps