fix: handle modem messages
This commit is contained in:
@@ -161,38 +161,40 @@ declareCommandHandler("SCAN", handleScan,
|
|||||||
local function handleMessages(side, channel, replyChannel, message, dist)
|
local function handleMessages(side, channel, replyChannel, message, dist)
|
||||||
if channel ~= HOST_CHANNEL then return end
|
if channel ~= HOST_CHANNEL then return end
|
||||||
|
|
||||||
|
-- msg validation
|
||||||
if type(message) ~= "table" then return end
|
if type(message) ~= "table" then return end
|
||||||
if not message.header or message.header ~= MSG_HEADER then return end
|
if not message.header or message.header ~= MSG_HEADER then return end
|
||||||
if not message.data then message.data = {} end
|
if not message.data then message.data = {} end
|
||||||
|
|
||||||
|
-- cmd validation
|
||||||
|
if not message.name then
|
||||||
|
log.warning("received nameless command?")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not commands[message.name] then
|
||||||
|
log.error("unhandled command (%s)", message.name)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = commands[message.name]
|
||||||
|
for i, v in pairs(cmd.keys) do
|
||||||
|
if type(message.data[i]) ~= v and v ~= "optional" then
|
||||||
|
log.error("command %s requires key %s of type %s (was %s)", message.name, i, v, type(message[i]))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- cmd execution
|
||||||
|
local success, err = pcall(cmd.handler, message.data, message.id)
|
||||||
|
if not success then
|
||||||
|
log.error("error occurred while executing command %s: %s", message.name, err)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
declareCommandHandler("modem_message", handleMessages)
|
||||||
--[[
|
--[[
|
||||||
main
|
main
|
||||||
]]
|
]]
|
||||||
-- function pollAndProcessMessages()
|
|
||||||
-- -- command validation
|
|
||||||
-- if not message.name then
|
|
||||||
-- log.warning("received nameless message")
|
|
||||||
-- return
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- if not commands[message.name] then
|
|
||||||
-- log.error("unhandled message (%s)", message.name)
|
|
||||||
-- return
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- local cmd = commands[message.name]
|
|
||||||
-- for i, v in pairs(cmd.keys) do
|
|
||||||
-- if type(message.data[i]) ~= v and v ~= "optional" then
|
|
||||||
-- log.error("command %s requires key %s of type %s (was %s)", message.name, i, v, type(message[i]))
|
|
||||||
-- return
|
|
||||||
-- end
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- cmd.handler(message.data, message.id)
|
|
||||||
|
|
||||||
-- -- message handling
|
|
||||||
-- log.info("received command (%s)", message.name)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
log.general("tutel host init")
|
log.general("tutel host init")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user