From c628e31c0a8ec417ffda5c5756041d6dcf4a7cbe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 May 2024 08:05:18 +1000 Subject: [PATCH] AP_Scripting: fixed crc and added logging to INF_Inject driver --- libraries/AP_Scripting/drivers/INF_Inject.lua | 58 +++++++++++++++++-- libraries/AP_Scripting/drivers/INF_Inject.md | 7 +++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/libraries/AP_Scripting/drivers/INF_Inject.lua b/libraries/AP_Scripting/drivers/INF_Inject.lua index 8685ba52a3..0ce9a3baad 100644 --- a/libraries/AP_Scripting/drivers/INF_Inject.lua +++ b/libraries/AP_Scripting/drivers/INF_Inject.lua @@ -34,11 +34,30 @@ assert(param:add_table(PARAM_TABLE_KEY, PARAM_TABLE_PREFIX, 8), 'could not add p --]] 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 @@ -53,12 +72,38 @@ if not efi_backend then 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("