50 lines
1.0 KiB
Plaintext
50 lines
1.0 KiB
Plaintext
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
|
|
|
|
function getTwoBytesLSB(data, offset, factor)
|
|
return (data[offset + 2] * 256 + data[offset + 1]) * factor
|
|
end
|
|
|
|
function onSensorData(bus, id, dlc, data)
|
|
if data[8] ~= 0xDE then
|
|
print ("invalid data: " ..arrayToString(data))
|
|
return
|
|
end
|
|
-- print ("valid data: " ..arrayToString(data))
|
|
local pressureBar = getTwoBytesLSB(data, 0, 10)
|
|
sensor : set(pressureBar)
|
|
print ("valid pressureBar: " ..pressureBar)
|
|
end
|
|
|
|
-- bus index '1' on most rusEFI boards, '1' or '2' on Proteus
|
|
canRxAdd(2, 0xBB26, onSensorData)
|
|
|
|
function onTick()
|
|
end
|