1
0
Fork 0
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:
Ycarus (Yannick Chabanois) 2024-10-31 14:42:18 +01:00
parent 11d48ae4f5
commit e135cb4261

41
modemmanager/files/usr/libexec/rpcd/modemmanager Normal file → Executable file
View file

@ -143,6 +143,19 @@ function mm_get_modem_status(modem)
table.insert(status["modem"], mstatus["modem"]) table.insert(status["modem"], mstatus["modem"])
end 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() function aquire_data_modemmanager()
local command = string.format("/usr/bin/mmcli --list-modems --output-json 2>/dev/null") local command = string.format("/usr/bin/mmcli --list-modems --output-json 2>/dev/null")
@ -167,6 +180,30 @@ function aquire_data_modemmanager()
end end
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() function aquire_data_info()
aquire_data_modemmanager() aquire_data_modemmanager()
@ -200,6 +237,7 @@ function main(cmd, call)
if cmd == "list" then if cmd == "list" then
print(json.encode({ print(json.encode({
dump = {}, dump = {},
gps = {},
info = {} info = {}
})) }))
elseif cmd == "call" then elseif cmd == "call" then
@ -209,6 +247,9 @@ function main(cmd, call)
elseif call == "info" then elseif call == "info" then
aquire_data_info() aquire_data_info()
print(json.encode(info)) print(json.encode(info))
elseif call == "gps" then
aquire_data_gps()
print(json.encode(gps))
end end
end end
end end