From e316889ca9bb68fa270ca76c7dd08481a99b4a63 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Fri, 23 Dec 2022 19:01:08 -0500 Subject: [PATCH] tp 2.0 --- firmware/controllers/lua/examples/vwtp.txt | 83 ++++++++++++++++------ 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/firmware/controllers/lua/examples/vwtp.txt b/firmware/controllers/lua/examples/vwtp.txt index e105bedbe9..b835fd734a 100644 --- a/firmware/controllers/lua/examples/vwtp.txt +++ b/firmware/controllers/lua/examples/vwtp.txt @@ -1,8 +1,19 @@ -- this controls onCanRx rate as well! -setTickRate(100) +setTickRate(300) + +timeout = 3000 + +cltSensor = Sensor.new("clt") +cltSensor : setTimeout(timeout) + +iatSensor = Sensor.new("iat") +iatSensor : setTimeout(timeout) + +rpmSensor = Sensor.new("rpm") +rpmSensor : setTimeout(timeout) mapSensor = Sensor.new("map") -mapSensor:setTimeout(3000) +mapSensor : setTimeout(timeout) hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" } @@ -50,7 +61,11 @@ local sendCounter = 2 local packetCounter = 1 local payLoadIndex = 0 -local groupId = 2 +local groups = { 2, 4 } +-- todo: smarter array size calculation? +local groupsSize = 2 + +local groupIndex = 1 function onCanTester(bus, id, dlc, data) -- here we handle 300 packets @@ -61,9 +76,16 @@ function onCanTester(bus, id, dlc, data) -- print ("Keep-alive") txCan(1, ecuId, 0, { 0xA1, 0x0F, 0x8A, 0xFF, 0x4A, 0xFF }) - -- request group 1 + groupIndex = groupIndex + 1 + if groupIndex > groupsSize then + groupIndex = 1 + end + groupId = groups[groupIndex] + print (groupIndex .." " ..groupId) + + reqFirst = 0x10 + sendCounter - print("Requesting group X again with counter " ..sendCounter) + print("Requesting next group " ..groupId .." with counter " ..sendCounter) txCan(1, ecuId, 0, { reqFirst, 0x00, 0x02, 0x21, groupId }) sendCounter = sendCounter + 1 @@ -90,8 +112,8 @@ function onCanTester(bus, id, dlc, data) ackPacket = 0xB0 + packetCounter print ("Sending ACK B1 " ..ackPacket) txCan(1, ecuId, 0, { ackPacket }) - -- request group groupId - txCan(1, ecuId, 0, { 0x11, 0x00, 0x02, 0x21, groupId }) + -- request first group from array + txCan(1, ecuId, 0, { 0x11, 0x00, 0x02, 0x21, groups[1] }) return end @@ -106,26 +128,43 @@ function onCanTester(bus, id, dlc, data) print ("Looks like payload index " ..payLoadIndex ..": " ..arrayToString(data)) if groupId == 2 and payLoadIndex == 0 then - rpmL = data[7] - rpmH = data[8] - rpm = rpmH * rpmL / 5 - print(rpmL .. " " .. rpmH .. " " .. rpm) + rpmL = data[7] + rpmH = data[8] + rpm = rpmH * rpmL / 5 + print(rpmL .." " ..rpmH .." " ..rpm) + rpmSensor : set(rpm) end if groupId == 2 and payLoadIndex == 1 then - elL = data[3] - elH = data[4] - el = 100 * elH / elL - print(elL .. " " .. elH .. " " .. el) - end + elL = data[3] + elH = data[4] + el = 100 * elH / elL + print(elL .." " ..elH .." " ..el) + end if groupId == 2 and payLoadIndex == 2 then - mapL = data[2] - mapH = data[3] - map = 1000.0 * mapH / mapL - print(mapL .. " " .. mapH .. " " .. map) - mapSensor : set(map / 10) - end + mapL = data[2] + mapH = data[3] + map = 1000.0 * mapH / mapL + print(mapL .." " ..mapH .." " ..map) + mapSensor : set(map / 10) + end + + if groupId == 4 and payLoadIndex == 1 then + cltL = data[6] + cltH = data[7] + clt = cltL * (cltH - 100) / 10 + print(cltL .." " ..cltH .." " ..clt) + cltSensor : set(clt) + end + + if groupId == 4 and payLoadIndex == 2 then + iatL = data[2] + iatH = data[3] + iat = iatL * (iatH - 100) / 10 + print(iatL .." " ..iatH .." " ..iat) + iatSensor : set(iat) + end payLoadIndex = payLoadIndex + 1