--[[ Driver for INF_Inject EFI system https://innoflighttechnology.com/efi/ --]] local PARAM_TABLE_KEY = 43 local PARAM_TABLE_PREFIX = "EFI_INF_" local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} -- bind a parameter to a variable given local function bind_param(name) local p = Parameter() assert(p:init(name), string.format('could not find %s parameter', name)) return p end -- add a parameter and bind it to a variable local function bind_add_param(name, idx, default_value) assert(param:add_param(PARAM_TABLE_KEY, idx, name, default_value), string.format('could not add param %s', name)) return bind_param(PARAM_TABLE_PREFIX .. name) end -- setup script specific parameters assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 8), 'could not add param table') --[[ // @Param: EFI_INF_ENABLE // @DisplayName: EFI INF-Inject enable // @Description: Enable EFI INF-Inject driver // @Values: 0:Disabled,1:Enabled // @User: Standard --]] EFI_INF_ENABLE = bind_add_param("ENABLE", 1, 1) --[[ // @Param: EFI_INF_OPTIONS // @DisplayName: EFI INF-Inject options // @Description: EFI INF driver options // @Bitmask: 0:EnableLogging // @User: Standard --]] EFI_INF_OPTIONS = bind_add_param("OPTIONS", 2, 0) local OPTION_LOGGING = (1<<0) --[[ return true if an option is enabled --]] local function option_enabled(option) return (EFI_INF_OPTIONS:get() & option) ~= 0 end if EFI_INF_ENABLE:get() ~= 1 then return end local EFI_FUEL_DENS = bind_param("EFI_FUEL_DENS") local SCR_VM_I_COUNT = bind_param("SCR_VM_I_COUNT") local uart = serial:find_serial(0) -- first scripting serial if not uart then gcs:send_text(MAV_SEVERITY.ERROR, "EFI_INF: unable to find scripting serial") return end uart:begin(9600) local efi_backend = efi:get_backend(0) if not efi_backend then gcs:send_text(MAV_SEVERITY.ERROR, "EFI_INF: unable to find EFI backend") return end --[[ we need a bit more time in this driver --]] if SCR_VM_I_COUNT:get() < 50000 then gcs:send_text(MAV_SEVERITY.INFO, "EFI_INF: raising SCR_VM_I_COUNT to 50000") SCR_VM_I_COUNT:set_and_save(50000) end local state = {} state.last_read_us = uint32_t(0) state.chk0 = 0 state.chk1 = 0 state.total_fuel_g = 0.0 local file_handle = nil --[[ log a set of bytes --]] local function log_bytes(s) if not file_handle then file_handle = io.open("INF_Inject.log", "w") end if file_handle then local magic = 0x7fe53b04 local now_ms = millis():toint() local hdr = string.pack("= packet_size and not header_ok do state.chk0 = 0 state.chk1 = 0 local header0 = string.unpack("