only:GDI lua

This commit is contained in:
rusefillc 2025-02-23 19:13:47 -05:00
parent abf8ea8753
commit 68aba455fe
3 changed files with 33 additions and 50 deletions

View File

@ -1,3 +1,5 @@
-- scriptname gdi4-communication.lua
-- communication with https://github.com/rusefi/rusefi-hardware/tree/main/GDI-4ch/firmware
-- hpfpbench
@ -7,31 +9,8 @@ busIndex = 1
GDI4_BASE_ADDRESS = 0xBB20
GDI_CHANGE_ADDRESS = GDI4_BASE_ADDRESS + 0x10
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
function toHexString(num)
if num == 0 then
return '0'
end
local result = ""
while num > 0 do
local n = num % 16
result = hexstr[n + 1] ..result
num = math.floor(num / 16)
end
return result
end
function arrayToString(arr)
local str = ""
local index = 1
while arr[index] ~= nil do
str = str.." "..toHexString(arr[index])
index = index + 1
end
return str
end
-- include print-array.lua
-- endinclude
function printPacket(bus, id, dlc, data)
-- print('Received status packet ' ..arrayToString(data))

View File

@ -1,31 +1,10 @@
-- scriptname gdi8-pressure-input.lua
sensor = Sensor.new("FuelPressureHigh")
sensor : setTimeout(1000)
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
function toHexString(num)
if num == 0 then
return '0'
end
local result = ""
while num > 0 do
local n = num % 16
result = hexstr[n + 1] ..result
num = math.floor(num / 16)
end
return result
end
function arrayToString(arr)
local str = ""
local index = 1
while arr[index] ~= nil do
str = str.." "..toHexString(arr[index])
index = index + 1
end
return str
end
-- include print-array.lua
-- endinclude
function getTwoBytesLSB(data, offset, factor)
return (data[offset + 2] * 256 + data[offset + 1]) * factor

View File

@ -0,0 +1,25 @@
hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
function toHexString(num)
if num == 0 then
return '0'
end
local result = ""
while num > 0 do
local n = num % 16
result = hexstr[n + 1] ..result
num = math.floor(num / 16)
end
return result
end
function arrayToString(arr)
local str = ""
local index = 1
while arr[index] ~= nil do
str = str.." "..toHexString(arr[index])
index = index + 1
end
return str
end