Skip to content

Commit

Permalink
LUA : report aircraft configuration info
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradeep-Carbonix committed Jan 14, 2025
1 parent 71e46cd commit 61eb981
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,45 @@ assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 1), 'could not add '
--]]
local PREARM_BYPASS = bind_add_param('PREARM_DIS', 1, 0)

-- fetches the aircraft configuration from the config file, if it exists
local function get_aircraft_config(file_name)
local model = nil
local model_version = nil

-- Open file try and read header
local file = io.open(file_name,"r")
if not file then
cx_msg:send(cx_msg.MAV_SEVERITY.INFO, "config file not found")
return
end
while true do
local line = file:read()
if not line then
-- empty file or reached end of file
cx_msg:send(cx_msg.MAV_SEVERITY.INFO, "missing model info in cfg")
break
end

-- Extract model using pattern matching
if string.match(line, "<model>(.-)</model>") then
model = string.match(line, "<model>(.-)</model>")
end
-- Extract model_version using pattern matching
if string.match(line, "<model_version>(.-)</model_version>") then
model_version = string.match(line, "<model_version>(.-)</model_version>")
end

if model and model_version then
cx_msg:send(cx_msg.MAV_SEVERITY.INFO, "config (" .. model .. "_" .. model_version .. ".xml)")
return
end
end
end

-- initialize function
local function init()
get_aircraft_config("@ROMFS/AircraftConfiguration.xml")

-- initialize all subsystems that are part of constructor
for _, subsystem in pairs(subsystems) do
subsystem:init()
Expand Down

0 comments on commit 61eb981

Please sign in to comment.