mirror of https://github.com/FOME-Tech/fome-fw.git
This commit is contained in:
parent
19addcb2ff
commit
ee90371837
|
@ -203,12 +203,34 @@ function setTwoBytes(data, offset, value)
|
||||||
data[offset + 1] = value & 0xff
|
data[offset + 1] = value & 0xff
|
||||||
end
|
end
|
||||||
|
|
||||||
function xorChecksum(data)
|
function xorChecksum(data, targetIndex)
|
||||||
return data[1] ~ data[2] ~ data[3] ~ data[4] ~ data[5] ~ data[6] ~ data[7]
|
local index = 1
|
||||||
|
local result = 0
|
||||||
|
while data[index] ~= nil do
|
||||||
|
if index ~= targetIndex then
|
||||||
|
result = result ~ data[index]
|
||||||
|
end
|
||||||
|
index = index + 1
|
||||||
|
end
|
||||||
|
data[targetIndex] = result
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function getBitRange(data, bitIndex, bitWidth)
|
||||||
|
byteIndex = bitIndex >> 3
|
||||||
|
shift = bitIndex - byteIndex * 8
|
||||||
|
value = data[1 + byteIndex]
|
||||||
|
if (shift + bitWidth > 8) then
|
||||||
|
value = value + data[2 + byteIndex] * 256
|
||||||
|
end
|
||||||
|
mask = (1 << bitWidth) - 1
|
||||||
|
return (value >> shift) & mask
|
||||||
end
|
end
|
||||||
|
|
||||||
canMotor1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
canMotor1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 }
|
canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 }
|
||||||
|
canMotor3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
|
canMotor6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
canMotor7 = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
canMotor7 = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
||||||
|
|
||||||
setTickRate(100)
|
setTickRate(100)
|
||||||
|
|
|
@ -3,18 +3,20 @@
|
||||||
#include "lua_lib.h"
|
#include "lua_lib.h"
|
||||||
|
|
||||||
// XOR of the array, skipping target index
|
// XOR of the array, skipping target index
|
||||||
#define VAG_CHECKSUM "function xorChecksum(data, targetIndex) \
|
#define VAG_CHECKSUM " \
|
||||||
|
function xorChecksum(data, targetIndex) \
|
||||||
local index = 1 \
|
local index = 1 \
|
||||||
local result = 0 \
|
local result = 0 \
|
||||||
while data[index] ~= nil do \
|
while data[index] ~= nil do \
|
||||||
if index ~= targetIndex then \
|
if index ~= targetIndex then \
|
||||||
result = result ~ data[index] \
|
result = result ~ data[index] \
|
||||||
end \
|
end \
|
||||||
index = index + 1 \
|
index = index + 1 \
|
||||||
end \
|
end \
|
||||||
data[targetIndex] = result \
|
data[targetIndex] = result \
|
||||||
return result \
|
return result \
|
||||||
end"
|
end \
|
||||||
|
"
|
||||||
|
|
||||||
|
|
||||||
TEST(LuaVag, Checksum) {
|
TEST(LuaVag, Checksum) {
|
||||||
|
|
Loading…
Reference in New Issue