Hondata KPro4: Difference between revisions

(Created page with "The following script adapts the Hondata KPro4 CAN to RaceCapture/Pro Image:Hondata_KPro4.jpg <pre> --This example adopted to Hondata KPro4 CAN output --how frequently we ...")
 
(updated with latest.)
Line 15: Line 15:
be_mode = 1  
be_mode = 1  


--add your virtual channels here
function toF(value)
rpmId = addChannel("RPM", 10, 0, 0, 9000, "RPM")  
return value * 1.8 + 32
vltId = addChannel("VLT", 10, 1, 0, 20, "volts")
end
iatId = addChannel("IAT", 1, 0, 0, 100, "C")
 
ectId = addChannel("ECT", 1, 0, 0, 150, "C")
function toAFR(value)
tpsId = addChannel("TPS", 10, 0, 0, 100, "%")  
return value * 14.7
mapId = addChannel("MAP", 10, 1, 0, 15, "PSI")
end
injId = addChannel("INJ", 10, 3, 0, 100, "ms")
ignId = addChannel("IGN", 10, 0, -20, 20, "D")
lmdId = addChannel("LMD", 10, 3, 0, 2, "lambda")
knkId = addChannel("KNK", 1, 0, 0, 15, "count")
camId = addChannel("CAM", 10, 0, -20, 20, "D")


--customize here for CAN channel mapping
--offset/length in bytes?
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>)
CAN_map = {  
CAN_map = {  
--did not bother logging gear speed and target cam angle
[1632] = function(data)  
[1632] = function(data) map_chan(rpmId, data, 0, 2, 1, 0) map_chan(vltId, data, 5, 1, 0.1, 0) end,  
  map_chan(rpmId, data, 0, 2, 1, 0)  
[1633] = function(data) map_chan(iatId, data, 0, 2, 1, 0) map_chan(ectId, data, 2, 2, 1, 0) end,  
  map_chan(speedId, data, 2, 2, 0.621371, 0)
[1634] = function(data) map_chan(tpsId, data, 0, 2, 1, 0) map_chan(mapId, data, 2, 2, 0.0145037738, 0) end,  
  map_chan(vltId, data, 5, 1, 0.1, 0)  
[1635] = function(data) map_chan(injId, data, 0, 2, 0.001, 0) map_chan(ignId, data, 2, 2, 1, 0) end,  
end,  
[1636] = function(data) map_chan(lmdId, data, 0, 2, 0.00003051757, 0) end,  
[1633] = function(data)  
[1637] = function(data) map_chan(knkId, data, 0, 2, 1, 0) end,  
  map_chan(iatId, data, 0, 2, 1, 0, toF)  
[1638] = function(data) map_chan(camId, data, 2, 2, 1, 0) end  
  map_chan(ectId, data, 2, 2, 1, 0, toF)  
end,  
[1634] = function(data)  
  map_chan(tpsId, data, 0, 2, 1, 0)  
  map_chan(mapId, data, 2, 2, 0.1, 0)  
end,  
[1635] = function(data)  
  map_chan(injId, data, 0, 2, 0.001, 0)  
  map_chan(ignId, data, 2, 2, 1, 0)  
end,  
[1636] = function(data)  
  map_chan(afrId, data, 0, 2, 0.00003051757, 0, toAFR)  
end,  
[1637] = function(data)  
  map_chan(knkId, data, 0, 2, 1, 0)  
end,  
[1638] = function(data)  
  map_chan(camId, data, 2, 2, 1, -20)
end,
[1639] = function(data)
  map_chan(anv1Id, data, 0, 2, 4096, 0)
  map_chan(anv2Id, data, 2, 2, 4096, 0)
  map_chan(anv3Id, data, 0, 4, 4096, 0)  
  map_chan(anv4Id, data, 0, 6, 4096, 0)
end,
[1640] = function(data)
  map_chan(anv5Id, data, 0, 2, 4096, 0)
  map_chan(anv6Id, data, 2, 2, 4096, 0)
  map_chan(anv7Id, data, 0, 4, 4096, 0)
  map_chan(anv8Id, data, 0, 6, 4096, 0)
end
}  
}  


function onTick()
    processCAN(CAN_chan)
end


--===========do not edit below===========  
rpmId = addChannel("RPM", 25, 0, 0, 9000, "RPM")
function processCAN(chan)  
speed_id = addChannel ("RoadSpeed", 5, 0, 0, 200, "MPH")
    repeat
vltId = addChannel("EcuVolts", 10, 1, 0, 20, "volts")
        local id, e, data = rxCAN(chan)  
iatId = addChannel("IAT", 1, 1, 0, 100, "C")
        if id ~= nil then
coolantId = addChannel("Coolant", 1, 1, -30, 400, "F")
            local map = CAN_map[id]
tpsId = addChannel("TPS", 10, 1, 0, 100, "%")
            if map ~= nil then
mapId = addChannel("MAP", 10, 1, 0, 15, "PSI")
                map(data)        
injId = addChannel("InjectorPW", 10, 3, 0, 100, "ms")
            end
ignId = addChannel("IgnTiming", 10, 1, -20, 20, "D")
        end
afrId = addChannel("AFR", 10, 1, 5, 40, "AFR")
     until id == nil
knkId = addChannel("Knock", 1, 0, 0, 15, "count")
end  
camId = addChannel("CamTiming", 10, 1, -40, 40, "D")
anv1Id = addChannel("Anv1", 1, 2, 0, 5, "V")
anv2Id = addChannel("Anv2", 1, 2, 0, 5, "V")
anv3Id = addChannel("Anv3", 1, 2, 0, 5, "V")
anv4Id = addChannel("Anv4", 10, 2, 0, 5, "V")
anv5Id = addChannel("Anv5", 1, 2, 0, 5, "V")
anv6Id = addChannel("Anv6", 10, 2, 0, 5, "V")
anv7Id = addChannel("Anv7", 1, 2, 0, 5, "V")
anv8Id = addChannel("Anv8", 1, 2, 0, 5, "V")
 
function onTick()
     processCAN(CAN_chan)
end


--Map CAN channel, little endian format
--===========do not edit below===========
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 processCAN(chan)
function map_chan_be(cid, data, offset, len, mult, add)  
     repeat
     offset = offset + 1
        local id, e, data = rxCAN(chan)
    local value = 0
        if id ~= nil then
    while len > 0 do
            local map = CAN_map[id]
        value = (value * 256) + data[offset]  
            if map ~= nil then
        offset = offset + 1
                map(data)          
         len = len - 1
            end
    end  
        end
     setChannel(cid, (value * mult) + add)
     until id == nil
end  
end


map_chan = (be_mode == 1) and map_chan_be or map_chan_le  
--Map CAN channel, little endian format
initCAN(CAN_chan, CAN_baud)  
function map_chan_le(cid, data, offset, len, mult, add, filter)
    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
local cv = (value + add) * mult
if filter ~= nil then cv = filter(cv) end
    setChannel(cid, cv)
end
 
--Map CAN channel, big endian format
function map_chan_be(cid, data, offset, len, mult, add, filter)
    offset = offset + 1
    local value = 0
    while len > 0 do
        value = (value * 256) + data[offset]
        offset = offset + 1
        len = len - 1
    end
local cv = (value + add) * mult
if filter ~= nil then cv = filter(cv) end
    setChannel(cid, cv)
end
 
map_chan = (be_mode == 1) and map_chan_be or map_chan_le
initCAN(CAN_chan, CAN_baud)
setTickRate(tickRate)
setTickRate(tickRate)
</pre>
</pre>

Revision as of 18:40, 9 October 2015

The following script adapts the Hondata KPro4 CAN to RaceCapture/Pro

Hondata KPro4.jpg

--This example adopted to Hondata KPro4 CAN output 

--how frequently we poll for CAN messages, 30Hz is the max 
tickRate = 30 
--the CAN baud rate 
CAN_baud = 250000 
--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 = 1 

function toF(value)
 return value * 1.8 + 32
end

function toAFR(value)
 return value * 14.7
end

CAN_map = { 
[1632] = function(data) 
  map_chan(rpmId, data, 0, 2, 1, 0) 
  map_chan(speedId, data, 2, 2, 0.621371, 0) 
  map_chan(vltId, data, 5, 1, 0.1, 0) 
end, 
[1633] = function(data) 
  map_chan(iatId, data, 0, 2, 1, 0, toF) 
  map_chan(ectId, data, 2, 2, 1, 0, toF) 
end, 
[1634] = function(data) 
  map_chan(tpsId, data, 0, 2, 1, 0) 
  map_chan(mapId, data, 2, 2, 0.1, 0) 
end, 
[1635] = function(data) 
  map_chan(injId, data, 0, 2, 0.001, 0) 
  map_chan(ignId, data, 2, 2, 1, 0) 
end, 
[1636] = function(data) 
  map_chan(afrId, data, 0, 2, 0.00003051757, 0, toAFR) 
end, 
[1637] = function(data) 
  map_chan(knkId, data, 0, 2, 1, 0) 
end, 
[1638] = function(data) 
  map_chan(camId, data, 2, 2, 1, -20) 
end,
[1639] = function(data) 
  map_chan(anv1Id, data, 0, 2, 4096, 0) 
  map_chan(anv2Id, data, 2, 2, 4096, 0) 
  map_chan(anv3Id, data, 0, 4, 4096, 0) 
  map_chan(anv4Id, data, 0, 6, 4096, 0) 
end,
[1640] = function(data) 
  map_chan(anv5Id, data, 0, 2, 4096, 0) 
  map_chan(anv6Id, data, 2, 2, 4096, 0) 
  map_chan(anv7Id, data, 0, 4, 4096, 0) 
  map_chan(anv8Id, data, 0, 6, 4096, 0) 
end
} 


rpmId = addChannel("RPM", 25, 0, 0, 9000, "RPM") 
speed_id = addChannel ("RoadSpeed", 5, 0, 0, 200, "MPH")
vltId = addChannel("EcuVolts", 10, 1, 0, 20, "volts") 
iatId = addChannel("IAT", 1, 1, 0, 100, "C") 
coolantId = addChannel("Coolant", 1, 1, -30, 400, "F") 
tpsId = addChannel("TPS", 10, 1, 0, 100, "%") 
mapId = addChannel("MAP", 10, 1, 0, 15, "PSI") 
injId = addChannel("InjectorPW", 10, 3, 0, 100, "ms") 
ignId = addChannel("IgnTiming", 10, 1, -20, 20, "D") 
afrId = addChannel("AFR", 10, 1, 5, 40, "AFR") 
knkId = addChannel("Knock", 1, 0, 0, 15, "count") 
camId = addChannel("CamTiming", 10, 1, -40, 40, "D") 
anv1Id = addChannel("Anv1", 1, 2, 0, 5, "V")
anv2Id = addChannel("Anv2", 1, 2, 0, 5, "V")
anv3Id = addChannel("Anv3", 1, 2, 0, 5, "V")
anv4Id = addChannel("Anv4", 10, 2, 0, 5, "V")
anv5Id = addChannel("Anv5", 1, 2, 0, 5, "V")
anv6Id = addChannel("Anv6", 10, 2, 0, 5, "V")
anv7Id = addChannel("Anv7", 1, 2, 0, 5, "V")
anv8Id = addChannel("Anv8", 1, 2, 0, 5, "V")

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, filter)
    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
 local cv = (value + add) * mult
 if filter ~= nil then cv = filter(cv) end
    setChannel(cid, cv)
end

--Map CAN channel, big endian format
function map_chan_be(cid, data, offset, len, mult, add, filter)
    offset = offset + 1
    local value = 0
    while len > 0 do
        value = (value * 256) + data[offset]
        offset = offset + 1
        len = len - 1
    end
 local cv = (value + add) * mult
 if filter ~= nil then cv = filter(cv) end
    setChannel(cid, cv)
end

map_chan = (be_mode == 1) and map_chan_be or map_chan_le
initCAN(CAN_chan, CAN_baud)
setTickRate(tickRate)