Innovate Serial protocol

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Intel
Posts: 11
Joined: Tue Jan 17, 2017 7:07 pm

Innovate Serial protocol

Post by Intel »

So our Lemons team already had 4 of these Innovate Gauges daisy chained together. Looking to leverage this and input it into our Racecapture mk3

Trying to just get an initial connection/look at the output data as it comes from the serial stream.

http://www.innovatemotorsports.com/supp ... llog-2.pdf


8 data bits
1 stop bit
no parity
19.2 kBaud.

Code: Select all

--initialize Aux serial port to 19200, 8, N, 1
initSer&#40;4,19200, 8, 0, 1&#41;

function onTick&#40;&#41;
 --read a line from the aux serial port with a 100ms timeout
 value = readSer&#40;4, 200&#41;
 if value ~= nil then
  println&#40;'read value&#58; ' ..value&#41;
 end
end
It is returning a blank read value over and over which seems to at least point to the connection taking place. Is there something easy I am missing here?

Currently I am just hooked up to one of these gauges on the out port. Once I get that one configured I will be adding the other 2 and the LC-2 wideband.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

It's hard to say without seeing the protocol directly, and we don't have experience with that protocol.

What I would recommend is using a basic script like you have, and then connecting it to your computer using a USB to serial adapter. Then, if you open a terminal program, like HyperTerminal or RealTerminal (both windows apps) - and then press a Key, like "A" - you should receive an "A" in the Lua script.

Once you can prove you can receive data correctly, then you can implement the innovate serial protocol.

Good luck!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

gizmodo
Posts: 138
Joined: Mon Aug 05, 2013 10:22 pm

Post by gizmodo »

Just a word of caution here. I did the same thing with my Zeitronix ZT-2 and I found that even setting the tick rate at 30 it wasn't fast enough to keep up. Everything looked good with the car idling but revving and letting off the gas showed a noticeable lag in the data being output to the RaceCapture app vs the Zeitronix app and LCD. You might have better luck or I was doing something wrong, but that's what I saw.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

It really does depend on how the script is written. For example, if on every tick only one character is processed, it would be slower than having the script block until every character representing a message is received on the port - then that message can be parsed for values and virtual channels set.

Post the script as you make progress, we'll put an eye on it!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

gizmodo
Posts: 138
Joined: Mon Aug 05, 2013 10:22 pm

Post by gizmodo »

Looking at the pdf it looks like you might be running into the same thing as I did at first. The readSer function assumes that each packet ends with a carriage return, which I don't see called out in the documentation. For my application the header is marked by the first three characters, which are always 0,1,2 and that sequence is guaranteed not to occur in each packet. The while loop is looking for those characters. I'd suggest just using readCSer to see if that gets you something meaningful.

Code: Select all

if initSer&#40;4, 9600, 8, 0, 1&#41; == true then
  println&#40;'initialized'&#41;
else
  println&#40;'failed to initialize'&#41;
end
setTickRate&#40;30&#41;

function onTick&#40;&#41;
	headerFound = false
	while headerFound == false
	do
		first = readCSer&#40;4, 10&#41;
		if first == 0 then
			second = readCSer&#40;4, 10&#41;
			if second == 1 then
				third = readCSer&#40;4, 10&#41;
				if third == 2 then
					afr = readCSer&#40;4, 10&#41;
					egtLow = readCSer&#40;4, 10&#41;
					egtHigh = readCSer&#40;4, 10&#41;
					rpmLow = readCSer&#40;4, 10&#41;
					rpmHigh = readCSer&#40;4, 10&#41;
					mapLow = readCSer&#40;4, 10&#41;
					mapHigh = readCSer&#40;4, 10&#41;
					tps = readCSer&#40;4, 10&#41;
					user1 = readCSer&#40;4, 10&#41;
					config1 = readCSer&#40;4, 10&#41;
					config2 = readCSer&#40;4, 10&#41;
					--user2Low = readCSer&#40;4, 10&#41;
					--user2High = readCSer&#40;4, 10&#41;
					--user2Config = readCSer&#40;4, 10&#41;
					afrValue = afr / 10
					egtValue = egtLow + egtHigh * 256
					rpmValue = &#40;&#40;1000000 / &#40;rpmLow + &#40;rpmHigh * 256&#41; &#41; &#41; * 4.59 &#41; / 4 -- 4 = number of cylinders
					mapValue = &#40;mapLow + mapHigh * 256&#41; / 10
					user1Value = &#40;&#40;5 / 256&#41; * user1&#41; * 37.5 - 18.7  -- values = 0 to 255, which correspond to 0Volts to 5Volts
					println&#40;first ..', ' ..second ..', ' ..third ..', AFR&#58; ' ..afrValue ..', EGT&#58; ' ..egtValue ..', RPM&#58; ' ..rpmValue ..', MAP&#58; ' ..mapValue ..', TPS&#58; ' ..tps ..', Fuel Pressure&#58; ' ..user1Value ..', Config1&#58; ' ..config1 ..', config2&#58; ' ..config2&#41;
					headerFound = true
				end
			end
		end
	end
end

lightningrod
Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Post by lightningrod »

It looks like I'm a couple of years too late to be helpful in getting ready for Lemons.
The aux serial port for my rcpMk3 is 6.
I expect this code should work at much slower tickRates than 60, but I haven't done much testing yet. It is designed to run with minimal delays at high tickRates, so never waits, nor needs to wait for serial input. While serial data is ready, it reads it all, so even at low tickRates it should keep up fine. I think 10 will be enough to keep up. It will depend on the size of the internal serial buffer. But it looks the Innovate AFM only generates about 6 bytes per update and looks like its going at about 10hz, so 60 bytes per second.

I'm tossing out all the data except the air fuel ratio, so if your Innovate is logging more data, you'll have to add code to read that.

I'm pretty new to lua, so feel free to offer suggestions for improvements.

Code: Select all


-- documentation for RCP serial interface here&#58; https&#58;//wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting
-- documentation for ISP2 here&#58; http&#58;//www.innovatemotorsports.com/support/downloads/Seriallog-2.pdf
afSerNum=6
afInitd=false
afChan=-1

function afInit&#40;&#41;
  afInitd = initSer&#40;afSerNum, 19200, 8, 0, 1&#41;
  if afInitd then
    println&#40;'serial initialized'&#41;
    ispInit&#40;&#41;
  else
    println&#40;'failed to initialize serial'&#41;
  end
end

-- identify header with bits 15,13,9,7
hMaskH=0xA2
hMaskL=0x80

ispAFR = nil

-- this is a non-blocking implementation of the isp2 reader.
-- the following functions, when triggered will put the subsequent function
-- into the ispNextByteHandler variable, so when everything goes smoothly they will each find the
-- byte they are expecting.
-- the ispHandleHh function is responsible for consuming any unused packets &#40;there is  packet count
-- detected, but I am ignoring it for now.  If you expect or need more packets, you'll need to add
-- functions to this sequence to process them.

function ispInit&#40;&#41;
  ispHl = nil
  ispHh = nil
  ispNextByteHandler = ispHandleHh
end

function ispHandleHh&#40; h &#41;
  if bit.band&#40;h,hMaskH&#41; == hMaskH then
    ispHh = h
    ispNextByteHandler = ispHandleHl
  end
end

function ispHandleHl&#40; l &#41;
  if  bit.band&#40;l,hMaskL&#41; == hMaskL then
   ispHl = l
    ispNextByteHandler = ispHandleAFh
    ispPkt = bit.band&#40;l,0x7F&#41; + 0x80*bit.band&#40;ispHh,1&#41;
  else
    ispInit&#40;&#41;
  end
end

function ispHandleAFh&#40; h &#41;
  ispAFh = h
  ispNextByteHandler = ispHandleAFl
end

function ispHandleAFl&#40; l &#41;
  ispAFl = l
  ispNextByteHandler = ispHandleLh
end

function ispHandleLh&#40; h &#41;
  ispLh = h
  ispNextByteHandler = ispHandleLl
end

function ispHandleLl&#40; l &#41;
  ispLl = l

  local func = bit.band&#40;bit.rshift&#40;ispAFh,2&#41;,7&#41;
  -- this is the afr multiplier &#40;not the afr&#41;
  local af = bit.band&#40; ispAFh, 1&#41; * 0x80 +
       bit.band&#40; ispAFl, 0x7F&#41;
  local lambda = bit.band&#40;ispLh,0x7F&#41;*0x80 + bit.band&#40;ispLl,0x7F&#41;

  if func == 0 then
    ispAFR = &#40;lambda+500&#41;*af/10000
  else
    println&#40; "afr&#58; func"..func.." mult&#58;"..af.." lambda&#58;"..lambda &#41;
  end

  ispInit&#40;&#41;
end

function afReadISP2nb&#40;serPort&#41;
  c = readCSer&#40; serPort,0 &#41;
  while c ~= nil do
    ispNextByteHandler&#40; c &#41;
    c = readCSer&#40; serPort,0 &#41;
  end
  if ispAFR ~= nil then
    setChannel&#40; afChan, ispAFR &#41;
    ispAFR = nil
  end
end


function onTick&#40;&#41;
  if afInitd then
    afReadISP2nb&#40; afSerNum &#41;
 end
end

afInit&#40;&#41;
afChan=addChannel&#40;"AFR",10,1,8,23,"%"&#41;
setTickRate&#40;60&#41;


brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Nice job! I'm sure people will find this handy.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

lightningrod
Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Post by lightningrod »

After wrestling with memory issue while trying to integrate this module with some others, here is a slimmed down version. I apologise for the loss in legibility, but the memory footprint reduction is significant over the previous listing. The original was 2500 bytes (1350 after lua minifier). This version is 647 bytes (630 after minifier). It also uses less memory when loaded due to a reduction in function declarations. I'm happy to share my original code if anyone wants to use/modify it, but it may not be very usable without my hacky pipeline. This version has been run through cpp and my own very simplified cleaning code to remove the cpp clutter, comments and whitespace as well as reduce variable names from meaningful to single characters. (You can save another 17 bytes by running this through lua minifier, and a few more bytes I haven't counted by removing the check and print around the initSer call).

Code: Select all

A=nil
B=nil
C=nil
function G&#40;&#41;
local b=readCSer&#40;6,0&#41;
while b~=nil do
D=D+1
if D==1 and bit.band&#40;b,&#40;0xA2&#41;&#41;==&#40;0xA2&#41;then
elseif D==2 and bit.band&#40;b,&#40;0x80&#41;&#41;==&#40;0x80&#41;then
elseif D==4 then
E=bit.band&#40;bit.rshift&#40;B,2&#41;,7&#41;
C=bit.band&#40;B,1&#41;*0x80+
bit.band&#40;b,0x7F&#41;
elseif D==6 then
local F=bit.band&#40;B,0x7F&#41;*0x80+bit.band&#40;b,0x7F&#41;
if E==0 then
A=&#40;F+500.0&#41;*C*0.0001
elseif E==1 then
A=F*0.1
else
end
D=0
elseif D~=3 and D~=5 then
D=0
end
B=b
b=readCSer&#40;6,0&#41;
end
if A~=nil then
setChannel&#40;afChan,A&#41;
A=nil
end
end
if initSer&#40;6,19200,8,0,1&#41;then else println&#40;'initSer failed&#58;port'..6&#41;end afChan=addChannel&#40;"AFR",10,1,8,23&#41;D=0
function onTick&#40;&#41;
G&#40;&#41;
end
setTickRate&#40;60&#41;

Post Reply