just a bit of local
This commit is contained in:
parent
79bfcfcbe0
commit
ff9099f2b4
|
@ -24,21 +24,21 @@ function setBitRange(data, totalBitIndex, bitWidth, value)
|
|||
setBitRange(data, totalBitIndex + bitsToHandleNow, bitWidth - bitsToHandleNow, value >> bitsToHandleNow)
|
||||
bitWidth = bitsToHandleNow
|
||||
end
|
||||
mask = (1 << bitWidth) - 1
|
||||
local mask = (1 << bitWidth) - 1
|
||||
data[1 + byteIndex] = data[1 + byteIndex] & (~(mask << bitInByteIndex))
|
||||
maskedValue = value & mask
|
||||
shiftedValue = maskedValue << bitInByteIndex
|
||||
local maskedValue = value & mask
|
||||
local shiftedValue = maskedValue << bitInByteIndex
|
||||
data[1 + byteIndex] = data[1 + byteIndex] | shiftedValue
|
||||
end
|
||||
|
||||
function getBitRange(data, bitIndex, bitWidth)
|
||||
byteIndex = bitIndex >> 3
|
||||
shift = bitIndex - byteIndex * 8
|
||||
local byteIndex = bitIndex >> 3
|
||||
local shift = bitIndex - byteIndex * 8
|
||||
value = data[1 + byteIndex]
|
||||
if (shift + bitWidth > 8) then
|
||||
value = value + data[2 + byteIndex] * 256
|
||||
end
|
||||
mask = (1 << bitWidth) - 1
|
||||
local mask = (1 << bitWidth) - 1
|
||||
return (value >> shift) & mask
|
||||
end
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ end
|
|||
|
||||
counter440 = 0
|
||||
function onTcu440(bus, id, dlc, data)
|
||||
isShiftActive = getBitRange(data, 0, 1)
|
||||
tcuError = getBitRange(data, 1, 1)
|
||||
EGSRequirement = getBitRange(data, 7, 1)
|
||||
local isShiftActive = getBitRange(data, 0, 1)
|
||||
local tcuError = getBitRange(data, 1, 1)
|
||||
local EGSRequirement = getBitRange(data, 7, 1)
|
||||
counter440 = counter440 + 1
|
||||
if counter440 % 40 == 0 then
|
||||
print("TCU isShiftActive=" ..isShiftActive .." tcuError=" ..tcuError .." EGSRequirement=" ..EGSRequirement)
|
||||
|
|
Loading…
Reference in New Issue