AEM Infinity 6H

Revision as of 22:35, 10 September 2015 by Brentp (talk | contribs)

AEM Inifinity 6H ECU

setTickRate(25) initCAN(0, 500000) CAN_chan = 0

CAN_map = { [32546816] = function(data)

 map_chan(rpmId, data, 0, 2, 0.39063, 0) 
 map_chan(tpsId, data, 4, 2, 0.0015259, 0) 
 map_chan(atsId, data, 6, 1, 1, 0) 
 map_chan(ctsId, data, 7, 1, 1, 0) 

end, [32546820] = function(data)

 map_chan(fpsId, data, 3, 1, 0.580151, 0) 
 map_chan(opsId, data, 4, 1, 0.580151, 0) 

end }

rpmId = addChannel("RPM", 25, 0, 0, 10000, 'RPM') tpsId = addChannel("TPS", 10, 1, 0, 100, '%') atsId = addChannel("ATS", 10, 1, 0, 200, 'C') ctsId = addChannel("CTS", 10, 1, 0, 200, 'C') fpsId = addChannel("FPS", 10, 1, 0, 200, 'PSI') opsId = addChannel("OPS", 10, 1, 0, 200, 'PSI')

function onTick()

 processCAN() 

end

function processCAN()

 repeat 
   local id, e, data = rxCAN(0) 
   if id ~= nil then 
     local map = CAN_map[id] 
     if map ~= nil then 
       map(data) 
     end 
   end 
 until id == nil 

end

function map_chan(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