Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
Created January 25, 2016 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentpicasso/601f303863c792a7c57a to your computer and use it in GitHub Desktop.
Save brentpicasso/601f303863c792a7c57a to your computer and use it in GitHub Desktop.
Simulator script for E46
setTickRate(30)
function encodeWheel(value)
low_byte = bit.band(value, 0xFF)
high_byte = bit.rshift(bit.band(value, 0x1F00), 5)
return low_byte, high_byte
end
lf_wheel = 0
rf_wheel = 0
lr_wheel = 0
rr_wheel = 0
function send_496()
local lf_low, lf_high = encodeWheel(lf_wheel)
local rf_low, rf_high = encodeWheel(rf_wheel)
local lr_low, lr_high = encodeWheel(lr_wheel)
local rr_low, rr_high = encodeWheel(rr_wheel)
data={lf_low, lf_high, rf_low, rf_high, lr_low, lr_high, rr_low, rr_high}
txCAN(0, 496, 0, data)
lf_wheel = lf_wheel + 1
if lf_wheel > 0x1FFF then lf_wheel = 0 end
rf_wheel = rf_wheel + 1
if rf_wheel > 0x1FFF then rf_wheel = 0 end
lr_wheel = lr_wheel + 1
if lr_wheel > 0x1FFF then lr_wheel = 0 end
rr_wheel = rr_wheel + 1
if rr_wheel > 0x1FFF then rr_wheel = 0 end
end
clutch = 0
tps = 0
engineTemp = 0
function send_809()
local data = {0x00, 0x00, 0x00, clutch, 0x00, tps}
txCAN(0, 809, 0, data)
if clutch == 0 then clutch = 0x80 else clutch = 0 end
tps = tps + 1
if tps > 255 then tps = 0 end
end
gearboxTemp = 0
function send_1083()
local data = {gearboxTemp}
txCAN(0, 1083, 0, data)
gearboxTemp = gearboxTemp + 1
if gearboxTemp > 255 then gearboxTemp = 0 end
end
brakeSw = 0
function send_339()
txCAN(0, 339, 0, {brakeSw})
if brakeSw == 0 then brakeSw = 0x8 else brakeSw = 0 end
end
brakePress = 0
function send_504()
data={0x00, 0x00, brakePress}
txCAN(0, 504, 0, data)
brakePress = brakePress + 1
if brakePress > 255 then brakePress = 0 end
end
rpm = 0
function send_790()
rpm_low = bit.band(rpm, 0xFF)
rpm_high = bit.rshift(rpm, 8)
data={0x00, 0x00, rpm_low, rpm_high}
txCAN(0, 790, 0, data)
rpm = rpm + 1
if rpm > 65535 then rpm = 0 end
end
extTemp = 0
function send_1557()
data={0, 0, 0, extTemp}
txCAN(0, 1557, 0, data)
extTemp = extTemp +1
if extTemp > 255 then extTemp = 0 end
end
function onTick()
send_496() --wheel speed data
send_809() --engine temp, clutch switch, TPS
send_1083() --gearbox temp
send_339() --brake switch
send_504() --brake pressure
send_790() --send RPM
send_1557() --ext temp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment