mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-12 10:31:51 +00:00
Add entrypoint to get GPS data from ModemManager API
This commit is contained in:
parent
11d48ae4f5
commit
e135cb4261
1 changed files with 41 additions and 0 deletions
41
modemmanager/files/usr/libexec/rpcd/modemmanager
Normal file → Executable file
41
modemmanager/files/usr/libexec/rpcd/modemmanager
Normal file → Executable file
|
@ -143,6 +143,19 @@ function mm_get_modem_status(modem)
|
|||
table.insert(status["modem"], mstatus["modem"])
|
||||
end
|
||||
|
||||
function mm_get_modem_gps(modem)
|
||||
location = {}
|
||||
mstatus = {}
|
||||
mm_get_modem_location(modem)
|
||||
if (next(location) ~= nil) then
|
||||
mstatus["location"] = location
|
||||
else
|
||||
mstatus["location"] = {}
|
||||
end
|
||||
|
||||
table.insert(gps["modem"], mstatus["location"])
|
||||
end
|
||||
|
||||
function aquire_data_modemmanager()
|
||||
|
||||
local command = string.format("/usr/bin/mmcli --list-modems --output-json 2>/dev/null")
|
||||
|
@ -167,6 +180,30 @@ function aquire_data_modemmanager()
|
|||
end
|
||||
end
|
||||
|
||||
function aquire_data_gps()
|
||||
|
||||
local command = string.format("/usr/bin/mmcli --list-modems --output-json 2>/dev/null")
|
||||
|
||||
local handle = io.popen(command)
|
||||
local output = handle:read("*a")
|
||||
handle:close()
|
||||
|
||||
local ok, modems = pcall(function()
|
||||
return json.decode(output)
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
return
|
||||
end
|
||||
|
||||
entry_cache = {}
|
||||
gps = {}
|
||||
gps["modem"] = {}
|
||||
for k, v in ipairs(modems["modem-list"]) do
|
||||
mm_get_modem_gps(modems["modem-list"][k])
|
||||
end
|
||||
end
|
||||
|
||||
function aquire_data_info()
|
||||
aquire_data_modemmanager()
|
||||
|
||||
|
@ -200,6 +237,7 @@ function main(cmd, call)
|
|||
if cmd == "list" then
|
||||
print(json.encode({
|
||||
dump = {},
|
||||
gps = {},
|
||||
info = {}
|
||||
}))
|
||||
elseif cmd == "call" then
|
||||
|
@ -209,6 +247,9 @@ function main(cmd, call)
|
|||
elseif call == "info" then
|
||||
aquire_data_info()
|
||||
print(json.encode(info))
|
||||
elseif call == "gps" then
|
||||
aquire_data_gps()
|
||||
print(json.encode(gps))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue