AIM SmartyCam CAN: Difference between revisions
(→Integration Script: added script for extended channels) |
|||
Line 17: | Line 17: | ||
--AIM Smarty Cam Stream For Race Capture | --AIM Smarty Cam Stream For Race Capture | ||
--how frequently we poll for CAN messages | --how frequently we poll for CAN messages | ||
tickRate = 30 | tickRate = 30 | ||
--the CAN baud rate | --the CAN baud rate | ||
CAN_baud = 1000000 | CAN_baud = 1000000 | ||
--CAN channel to listen on. 0=first CAN channel, 1=second | --CAN channel to listen on. 0=first CAN channel, 1=second | ||
CAN_chan = 0 | CAN_chan = 0 | ||
--1 for Big Endian (MSB) mode; 0 for Little Endian mode (LSB) | --1 for Big Endian (MSB) mode; 0 for Little Endian mode (LSB) | ||
be_mode = 0 | be_mode = 0 | ||
--add your virtual channels here | --add your virtual channels here | ||
tpsId = addChannel("TPS", 10, 0, 0, 100, "%") | tpsId = addChannel("TPS", 10, 0, 0, 100, "%") | ||
tempId = addChannel("EngineTemp", 1, 0, 0, | tempId = addChannel("EngineTemp", 1, 0, 0, 120, 'C') | ||
oilTempId = addChannel("OilTemp", 1, 0, 0, | oilTempId = addChannel("OilTemp", 1, 0, 0, 170, 'C') | ||
rpmId = addChannel("RPM", 10, 0, 0, 10000, 'RPM') | rpmId = addChannel("RPM", 10, 0, 0, 10000, 'RPM') | ||
oilPresId = addChannel("OilPress", 10, 2, 0, 10, 'B') | |||
fuellevelId = addChannel("FuelLevel", 1, 0, 0, 120, "L") | |||
temp1Id = addChannel ("Temp1" , 1, 0, 0, 170, 'C') | |||
--customize here for CAN channel mapping | temp2Id = addChannel ("Temp2" , 1, 0, 0, 170, 'C') | ||
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>) | ch1Id = addChannel ("Ch1", 1, 0, 0, 170, "C") | ||
ch2Id = addChannel ("Ch2", 1, 0, 0, 170, "C") | |||
ch3Id = addChannel ("Ch3", 1, 0, 0, 170, "C") | |||
ch4Id = addChannel ("Ch4", 1, 0, 0, 170, "C") | |||
ch5Id = addChannel ("Ch5", 1, 0, 0, 170, "C") | |||
ch6Id = addChannel ("Ch6", 1, 0, 0, 170, "C") | |||
ch7Id = addChannel ("Ch7", 1, 0, 0, 170, "C") | |||
fuelPresId = addChannel ("FuelPress", 10, 2, 0, 10, "B") | |||
gearId = addChannel ("Gear", 10, 0, 0, 7, "#") | |||
--customize here for CAN channel mapping | |||
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>) | |||
CAN_map = { | CAN_map = { | ||
[1056] = function(data) map_chan(rpmId, data, 0, 2, 1, 0) map_chan(tempId, data, 6, 2, 0.1, 0) end, | [1056] = function(data) map_chan(rpmId, data, 0, 2, 1, 0) map_chan(gearId, data, 4, 2, 1, 0) map_chan_le(tempId, data, 6, 2, 0.1, 0) end, | ||
[1057] = function(data) map_chan(oilTempId, data, 4, 2, 0.1, 0) | [1057] = function(data) map_chan(temp1Id, data, 0, 2, 0.1, 0) map_chan(temp2Id, data, 2, 2, 0.1, 0) map_chan(oilTempId, data, 4, 2, 0.1, 0) map_chan_le(oilPresId, data, 6, 2, 0.01, 0) end, | ||
[1058] = function(data) map_chan(tpsId, data, 2, 1, 1, 0) end , | [1058] = function(data) map_chan(ch3Id, data, 0, 2, 0.01, 0) map_chan(tpsId, data, 2, 2, 1, 0) map_chan(ch1Id, data, 4, 2, 1, 0) map_chan(ch2Id, data, 6, 2, 1, 0) end | ||
[ | , | ||
[1059] = function(data) map_chan(ch4Id, data, 0, 2, 1, 0) map_chan(ch5Id, data, 2, 2, 0.01, 0) map_chan(ch6Id, data, 4, 2, 0.01, 0) map_chan(ch7Id, data, 6, 2, 0.01, 0) end, | |||
[1060] = function(data) map_chan(fuellevelId, data, 0, 2, 1, 0) map_chan(fuelPresId, data, 2, 2, 0.1, 0) end | |||
} | } | ||
function onTick() | function onTick() | ||
processCAN(CAN_chan) | processCAN(CAN_chan) | ||
end | end | ||
Line 54: | Line 69: | ||
local map = CAN_map[id] | local map = CAN_map[id] | ||
if map ~= nil then | if map ~= nil then | ||
map(data) | map(data) | ||
end | end | ||
end | end |
Revision as of 22:32, 14 April 2016
Introduction
This CAN bus integration maps CAN bus data from AIM systems normally directed to AIM's SmartyCam camera system.
Since the SmartyCam protocol is standard across AIM products, connecting RaceCapture/Pro to the CAN interface of an AIM product compatible with SmartyCam, communications can be intercepted and data can be mapped to RaceCapture/Pro telemetry channels.
Pictures
Connections
CAN database
Integration Script
--AIM Smarty Cam Stream For Race Capture --how frequently we poll for CAN messages tickRate = 30 --the CAN baud rate CAN_baud = 1000000 --CAN channel to listen on. 0=first CAN channel, 1=second CAN_chan = 0 --1 for Big Endian (MSB) mode; 0 for Little Endian mode (LSB) be_mode = 0 --add your virtual channels here tpsId = addChannel("TPS", 10, 0, 0, 100, "%") tempId = addChannel("EngineTemp", 1, 0, 0, 120, 'C') oilTempId = addChannel("OilTemp", 1, 0, 0, 170, 'C') rpmId = addChannel("RPM", 10, 0, 0, 10000, 'RPM') oilPresId = addChannel("OilPress", 10, 2, 0, 10, 'B') fuellevelId = addChannel("FuelLevel", 1, 0, 0, 120, "L") temp1Id = addChannel ("Temp1" , 1, 0, 0, 170, 'C') temp2Id = addChannel ("Temp2" , 1, 0, 0, 170, 'C') ch1Id = addChannel ("Ch1", 1, 0, 0, 170, "C") ch2Id = addChannel ("Ch2", 1, 0, 0, 170, "C") ch3Id = addChannel ("Ch3", 1, 0, 0, 170, "C") ch4Id = addChannel ("Ch4", 1, 0, 0, 170, "C") ch5Id = addChannel ("Ch5", 1, 0, 0, 170, "C") ch6Id = addChannel ("Ch6", 1, 0, 0, 170, "C") ch7Id = addChannel ("Ch7", 1, 0, 0, 170, "C") fuelPresId = addChannel ("FuelPress", 10, 2, 0, 10, "B") gearId = addChannel ("Gear", 10, 0, 0, 7, "#") --customize here for CAN channel mapping --format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>) CAN_map = { [1056] = function(data) map_chan(rpmId, data, 0, 2, 1, 0) map_chan(gearId, data, 4, 2, 1, 0) map_chan_le(tempId, data, 6, 2, 0.1, 0) end, [1057] = function(data) map_chan(temp1Id, data, 0, 2, 0.1, 0) map_chan(temp2Id, data, 2, 2, 0.1, 0) map_chan(oilTempId, data, 4, 2, 0.1, 0) map_chan_le(oilPresId, data, 6, 2, 0.01, 0) end, [1058] = function(data) map_chan(ch3Id, data, 0, 2, 0.01, 0) map_chan(tpsId, data, 2, 2, 1, 0) map_chan(ch1Id, data, 4, 2, 1, 0) map_chan(ch2Id, data, 6, 2, 1, 0) end , [1059] = function(data) map_chan(ch4Id, data, 0, 2, 1, 0) map_chan(ch5Id, data, 2, 2, 0.01, 0) map_chan(ch6Id, data, 4, 2, 0.01, 0) map_chan(ch7Id, data, 6, 2, 0.01, 0) end, [1060] = function(data) map_chan(fuellevelId, data, 0, 2, 1, 0) map_chan(fuelPresId, data, 2, 2, 0.1, 0) end } function onTick() processCAN(CAN_chan) end --===========do not edit below=========== function processCAN(chan) repeat local id, e, data = rxCAN(chan) if id ~= nil then local map = CAN_map[id] if map ~= nil then map(data) end end until id == nil end --Map CAN channel, little endian format function map_chan_le(cid, data, offset, len, mult, add) offset = offset + 1 local value = 0 local shift = 1 while len > 0 do value = value + (data[offset] * shift) shift = shift * 256 offset = offset + 1 len = len - 1 end setChannel(cid, (value * mult) + add) end --Map CAN channel, big endian format function map_chan_be(cid, data, offset, len, mult, add) offset = offset + 1 local value = 0 while len > 0 do value = (value * 256) + data[offset] offset = offset + 1 len = len - 1 end setChannel(cid, (value * mult) + add) end map_chan = (be_mode == 1) and map_chan_be or map_chan_le initCAN(CAN_chan, CAN_baud) setTickRate(tickRate)