EvoX CAN: Difference between revisions

(Created page with "CAN Pids (requires Mode 23 ECU modification or RAX Patch v2): https://docs.google.com/spreadsheets/d/1yqwaUIeylzGy0uVFBd-uCyEtLr8FW2B52HV4m_EkDrM/edit#gid=2012713014")
 
No edit summary
Line 1: Line 1:
CAN Pids (requires Mode 23 ECU modification or RAX Patch v2): https://docs.google.com/spreadsheets/d/1yqwaUIeylzGy0uVFBd-uCyEtLr8FW2B52HV4m_EkDrM/edit#gid=2012713014
=Introduction=
 
The EvoX integration requires requires Mode 23 ECU modification or RAX Patch v2): https://docs.google.com/spreadsheets/d/1yqwaUIeylzGy0uVFBd-uCyEtLr8FW2B52HV4m_EkDrM/edit#gid=2012713014
 
==Channels Supported==
The script provides the following channels:
 
* Load
* Timing
* KnockSum
* RPM
* Boost
* WGDC
* APP
* IAT
* ECT
* MAT
 
==Script==
 
Copy and paste this into the RaceCapture scripting window - ensure you erase any existing script before writing.
 
<pre>
--======================== STEERING AND BRAKES ================================
local chBrakeMC = 0
function getBrakes()
if chBrakeMC == 0 then
chBrakeMC = addChannel("BrakeMC", 100, 2, 0, 120, "Bar")
end
 
d1,d2 = requestCAN(1924,2)
if d1==nil or d2==nil then return end
setChannel(chBrakeMC, mBytes(d1[8],d2[2]) / 100.0 )
end
 
--======================== RAX MAIN DATA =====================================
local chLoad,chTiming,chKnockSum,chRPM = 0,0,0,0
local chBarometer,chMAP,chBoost,chWGDC = 0,0,0,0
local chAPP,chIAT,chECT,chMAT = 0,0,0,0
 
d1,d2,d3,res,id,ext = 0,0,0,0,0
 
function getRAX()
if chLoad == 0 then
chLoad = addChannel("Load", 100, 0, 0, 500, "Load")
chTiming = addChannel("Timing", 100, 0, -20, 50, "deg")
chKnockSum = addChannel("KnockSum", 100, 0, 0, 50, "counts")
chRPM = addChannel("RPM", 100, 0, 0, 8500)
chBoost = addChannel("Boost", 100, 1, -14.5, 43.5, "PSI")
chWGDC = addChannel("WGDC", 100, 1, 0, 100, "%")
chAPP = addChannel("APP", 100, 0, 0, 100, "%")
chIAT = addChannel("IAT", 100, 0, 0, 200, "F")
chECT = addChannel("ECT", 100, 0, 0, 300, "F")
chMAT = addChannel("MAT", 100, 0, 0, 200, "F")
end
 
d1 = requestCAN(2016,0x8051A8,6)
if d1 ~= nil then
local load = m23Bits(d1,1,8)
setChannel(chLoad,load)
end
 
d1 = requestCAN(2016,0x8051AE,6)
if d1 ~= nil then
local timing = m23Bits(d1,25,7)-20
setChannel(chTiming,timing)
local knocksum = m23Bits(d1,32,6)
setChannel(chKnockSum,knocksum)
local rpm = m23Bits(d1,38,11)*7.8125
setChannel(chRPM,rpm)
end
 
d1 = requestCAN(2016,0x8051B4,6)
if d1 ~= nil then
local map = m23Bits(d1,1,9)*0.0964869
local baro = (m23Bits(d1,10,7)+90)*0.07251887
setChannel(chBoost,map-baro)
local wgdc = m23Bits(d1,17,8)*0.5
setChannel(chWGDC,wgdc)
end
 
d1 = requestCAN(2016,0x8051BA,6)
if d1 ~= nil then
local app = ((m23Bits(d1,25,8)-32)*129)/255
setChannel(chAPP,app)
local iat = (m23Bits(d1,33,8)*1.8)-40
setChannel(chIAT,iat)
end
 
d1 = requestCAN(2016,0x8051C0,6)
if d1 ~= nil then
local ect = (m23Bits(d1,17,8)*1.8)-40
setChannel(chECT,ect)
local mat = (m23Bits(d1,25,8)*1.8)-40
setChannel(chMAT,mat)
end
end
 
-- =========== Byte xtraction from Mode23 CAN =================================
local bits = {0x1,0x3,0x7,0xF,0x1F,0x3F,0x7F,
  0xFF,0x1FF,0x3FF,0x7FF,0xFFF,0x1FFF,
  0x3FFF,0x7FFF,0xFFFF,0x1FFFF,0x3FFFF,0x7FFFF,
  0xFFFFF,0x1FFFFF,0x3FFFFF,0x7FFFFF,0xFFFFFF}
local band, bxor, bnot = bit.band, bit.bxor, bit.bnot
local lshift, rshift = bit.lshift, bit.rshift
function m23Bits(d,startBit,length)
local shift = (8 - ((startBit+length-1) % 8)) % 8
local startByte = 3 + (startBit - 1 - ((startBit-1) % 8)) / 8
local bnumb = d[startByte]
if (length+shift) > 8 and startByte < 8 then
bnumb = d[startByte+1] + lshift(bnumb,8)
if (length+shift) > 16 and startByte < 7 then
bnumb = d[startByte+2] + lshift(bnumb,8)
end
end
 
bnumb = rshift(bnumb,shift)
bnumb = band(bnumb,bits[length])
return bnumb
end
 
--============================ 2 BYTES SIGNED CONVERSION ======================
function mBytes(byte1,byte2)
if byte1 > 127 then
return 0 - lshift(band(-bnot(0x1000+byte1),0x00FF),8) - band(-bxor(0x1000+byte2,0x0000),0x00FF) - 1
end
return lshift(byte1,8) + byte2
end
 
--============================ CAN MESSAGING ==================================
function requestCAN(address, pid, bytes)
local reqStandard = {2,33,0,255,255,255,255,255}
local reqContinue = {48,8,0,255,255,255,255,255}
local reqMode23 = {5,35,0,0,0,0,255,255}
local to = 100
 
if pid>255 then
reqMode23[3]=rshift(pid,16)
reqMode23[4]=band(rshift(pid,8),bits[8])
reqMode23[5]=band(pid,bits[8])
reqMode23[6]=bytes
res = txCAN(0, address, 0, reqMode23,to)
if res ~= 1 then return nil end
else
reqStandard[3] = pid
res = txCAN(0, address, 0, reqStandard,to)
if res ~= 1 then return nil end
end
 
id, ext, d1 = rxCAN(0,to)
if id == nil then return nil end
if d1[1] < 16 then return d1,nil,nil end
 
res = txCAN(0, address, 0, reqContinue,to)
if res ~= 1 then return nil end
id, ext, d2 = rxCAN(0,to)
if id == nil then return nil end
if(d1[2]<14) then return d1, d2, nil end
 
id, ext, d3 = rxCAN(0,to)
if id == nil then return nil end
return d1, d2, d3
 
end
 
-- ========================= MAIN CYCLE =======================================
local tickRate = 30
local chCANHz = addChannel("CANSpeed", 1, 0, 0, 300, "Hz")
initCAN(0, 500000)
setTickRate(tickRate)
 
function onTick()
local started = getUptime()
local mc = 0
repeat
getBrakes()
getRAX()
mc = mc + 1
until getUptime() > started + 1000
setChannel(chCANHz, mc)
end
</pre>

Revision as of 22:34, 27 October 2017

Introduction

The EvoX integration requires requires Mode 23 ECU modification or RAX Patch v2): https://docs.google.com/spreadsheets/d/1yqwaUIeylzGy0uVFBd-uCyEtLr8FW2B52HV4m_EkDrM/edit#gid=2012713014

Channels Supported

The script provides the following channels:

  • Load
  • Timing
  • KnockSum
  • RPM
  • Boost
  • WGDC
  • APP
  • IAT
  • ECT
  • MAT

Script

Copy and paste this into the RaceCapture scripting window - ensure you erase any existing script before writing.

--======================== STEERING AND BRAKES ================================
local chBrakeMC = 0
function getBrakes()
 	if chBrakeMC == 0 then
		chBrakeMC = addChannel("BrakeMC", 100, 2, 0, 120, "Bar")
	end

	d1,d2 = requestCAN(1924,2)
	if d1==nil or d2==nil then return end
	setChannel(chBrakeMC, mBytes(d1[8],d2[2]) / 100.0 )
end

--======================== RAX MAIN DATA =====================================
local chLoad,chTiming,chKnockSum,chRPM = 0,0,0,0
local chBarometer,chMAP,chBoost,chWGDC = 0,0,0,0
local chAPP,chIAT,chECT,chMAT = 0,0,0,0

d1,d2,d3,res,id,ext = 0,0,0,0,0

function getRAX()
	if chLoad == 0 then
		chLoad = addChannel("Load", 100, 0, 0, 500, "Load")
		chTiming = addChannel("Timing", 100, 0, -20, 50, "deg")
		chKnockSum = addChannel("KnockSum", 100, 0, 0, 50, "counts")
		chRPM = addChannel("RPM", 100, 0, 0, 8500)
		chBoost = addChannel("Boost", 100, 1, -14.5, 43.5, "PSI")
		chWGDC = addChannel("WGDC", 100, 1, 0, 100, "%")
		chAPP = addChannel("APP", 100, 0, 0, 100, "%")
		chIAT = addChannel("IAT", 100, 0, 0, 200, "F")
		chECT = addChannel("ECT", 100, 0, 0, 300, "F")
		chMAT = addChannel("MAT", 100, 0, 0, 200, "F")		
	end

	d1 = requestCAN(2016,0x8051A8,6)
	if d1 ~= nil then
		local load = m23Bits(d1,1,8)
		setChannel(chLoad,load)
	end

	d1 = requestCAN(2016,0x8051AE,6)
	if d1 ~= nil then
		local timing = m23Bits(d1,25,7)-20
		setChannel(chTiming,timing)
		local knocksum = m23Bits(d1,32,6)
		setChannel(chKnockSum,knocksum)
		local rpm = m23Bits(d1,38,11)*7.8125
		setChannel(chRPM,rpm)
	end

	d1 = requestCAN(2016,0x8051B4,6)
	if d1 ~= nil then
		local map = m23Bits(d1,1,9)*0.0964869
		local baro = (m23Bits(d1,10,7)+90)*0.07251887
		setChannel(chBoost,map-baro)		
		local wgdc = m23Bits(d1,17,8)*0.5
		setChannel(chWGDC,wgdc)
	end

	d1 = requestCAN(2016,0x8051BA,6)
	if d1 ~= nil then		
		local app = ((m23Bits(d1,25,8)-32)*129)/255
		setChannel(chAPP,app)		
		local iat = (m23Bits(d1,33,8)*1.8)-40
		setChannel(chIAT,iat)
	end

	d1 = requestCAN(2016,0x8051C0,6)
	if d1 ~= nil then
		local ect = (m23Bits(d1,17,8)*1.8)-40
		setChannel(chECT,ect)
		local mat = (m23Bits(d1,25,8)*1.8)-40
		setChannel(chMAT,mat)
	end
	
end

-- =========== Byte xtraction from Mode23 CAN =================================
local bits = {0x1,0x3,0x7,0xF,0x1F,0x3F,0x7F,
  0xFF,0x1FF,0x3FF,0x7FF,0xFFF,0x1FFF,
  0x3FFF,0x7FFF,0xFFFF,0x1FFFF,0x3FFFF,0x7FFFF,
  0xFFFFF,0x1FFFFF,0x3FFFFF,0x7FFFFF,0xFFFFFF}
local band, bxor, bnot = bit.band, bit.bxor, bit.bnot
local lshift, rshift = bit.lshift, bit.rshift
function m23Bits(d,startBit,length)
	local shift = (8 - ((startBit+length-1) % 8)) % 8
	local startByte = 3 + (startBit - 1 - ((startBit-1) % 8)) / 8
	local bnumb = d[startByte]
	if (length+shift) > 8 and startByte < 8 then
		bnumb = d[startByte+1] + lshift(bnumb,8)
		if (length+shift) > 16 and startByte < 7 then
			bnumb = d[startByte+2] + lshift(bnumb,8)
		end
	end

	bnumb = rshift(bnumb,shift)
	bnumb = band(bnumb,bits[length])
	return bnumb
end

--============================ 2 BYTES SIGNED CONVERSION ======================
function mBytes(byte1,byte2)
	if byte1 > 127 then
		return 0 - lshift(band(-bnot(0x1000+byte1),0x00FF),8) - band(-bxor(0x1000+byte2,0x0000),0x00FF) - 1
	end
	return lshift(byte1,8) + byte2
end

--============================ CAN MESSAGING ==================================
function requestCAN(address, pid, bytes)
	local reqStandard = {2,33,0,255,255,255,255,255}
	local reqContinue = {48,8,0,255,255,255,255,255}
	local reqMode23 = {5,35,0,0,0,0,255,255}
	local to = 100

	if pid>255 then
		reqMode23[3]=rshift(pid,16)
		reqMode23[4]=band(rshift(pid,8),bits[8])
		reqMode23[5]=band(pid,bits[8])
		reqMode23[6]=bytes
		
		res = txCAN(0, address, 0, reqMode23,to)
		if res ~= 1 then return nil end
	else
		reqStandard[3] = pid
		res = txCAN(0, address, 0, reqStandard,to)
		if res ~= 1 then return nil end
	end

	id, ext, d1 = rxCAN(0,to)
	if id == nil then return nil end
	if d1[1] < 16 then return d1,nil,nil end

	res = txCAN(0, address, 0, reqContinue,to)
	if res ~= 1 then return nil end
	id, ext, d2 = rxCAN(0,to)
	if id == nil then return nil end
	if(d1[2]<14) then return d1, d2, nil end
  
	id, ext, d3 = rxCAN(0,to)
	if id == nil then return nil end
	return d1, d2, d3

end

-- ========================= MAIN CYCLE =======================================
local tickRate = 30
local chCANHz = addChannel("CANSpeed", 1, 0, 0, 300, "Hz")
initCAN(0, 500000)
setTickRate(tickRate)

function onTick()
	local started = getUptime()
	local mc = 0
	repeat
		getBrakes()
		getRAX()
		mc = mc + 1
	until getUptime() > started + 1000
	setChannel(chCANHz, mc)
end