diff --git a/B6-temp.md b/B6-temp.md index c7f69072..55b26161 100644 --- a/B6-temp.md +++ b/B6-temp.md @@ -103,22 +103,22 @@ function arrayToString(arr) end totalEcuMessages = 0 -totalTcuMessages = 0 motor1Data = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } motorBreData={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } motor2Data = { 0x8A, 0x8D, 0x10, 0x04, 0x00, 0x4C, 0xDC, 0x87 } motor2mux = {0x8A, 0xE8, 0x2C, 0x64} -canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 } -canMotorInfo1= { 0x99, 0x14, 0x00, 0x7F, 0x00, 0xF0, 0x47, 0x01 } -canMotorInfo3= { 0x9B, 0x14, 0x00, 0x11, 0x1F, 0xE0, 0x0C, 0x46 } canMotor3 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } motor5Data = { 0x1C, 0x08, 0xF3, 0x55, 0x19, 0x00, 0x00, 0xAD } motor6Data = { 0x00, 0x00, 0x00, 0x7E, 0xFE, 0xFF, 0xFF, 0x00 } -motor7Data = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 } accGraData = { 0x00, 0x00, 0x08, 0x00, 0x1A, 0x00, 0x02, 0x01 } +canMotorInfo = { 0x00, 0x00, 0x00, 0x14, 0x1C, 0x93, 0x48, 0x14 } +canMotorInfo1= { 0x99, 0x14, 0x00, 0x7F, 0x00, 0xF0, 0x47, 0x01 } +canMotorInfo3= { 0x9B, 0x14, 0x00, 0x11, 0x1F, 0xE0, 0x0C, 0x46 } +motor7Data = { 0x1A, 0x66, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00 } function onMotor1(bus, id, dlc, data) + totalEcuMessages = totalEcuMessages + 1 rpm = getBitRange(data, 16, 16) * 0.25 tps = getBitRange(data, 40, 8) * 0.4 @@ -150,7 +150,36 @@ function onMotor1(bus, id, dlc, data) txCan(TCU_BUS, id, 0, motor1Data) end +motorBreCounter = 0 +function onMotorBre(bus, id, dlc, data) + motorBreCounter = (motorBreCounter + 1) % 16 + + setBitRange(motorBreData, 8, 4, motorBreCounter) + xorChecksum(motorBreData, 1) + + txCan(TCU_BUS, id, 0, motorBreData) +end + +motor2counter = 0 +function onMotor2(bus, id, dlc, data) + motor2counter = (motor2counter + 1) % 16 + + minTorque = fakeTorque / 2 + motor2Data[7] = math.floor(minTorque / 0.39) + +--print ( "brake " .. getBitRange(data, 16, 2) .. " " .. rpm) + + brakeBit = rpm < 2000 and 1 or 0 + setBitRange(motor2Data, 16, 1, brakeBit) + + motor2Data[1] = motor2mux[math.floor(motor2counter / 4)] + +-- txCan(TCU_BUS, id, 0, data) + txCan(TCU_BUS, id, 0, motor2Data) +end + function onMotor3(bus, id, dlc, data) + totalEcuMessages = totalEcuMessages + 1 iat = getBitRange(data, 8, 8) * 0.75 - 48 pps = getBitRange(data, 16, 8) * 0.40 tps = getBitRange(data, 56, 8) * 0.40 @@ -193,71 +222,40 @@ function onMotor6(bus, id, dlc, data) txCan(TCU_BUS, id, 0, motor6Data) end -canMotorInfoCounter = 0 -function onMotorInfo(bus, id, dlc, data) --- print("Relaying to TCU " .. id) - - - canMotorInfoCounter = (canMotorInfoCounter + 1) % 16 - canMotorInfo[1] = 0x90 + (canMotorInfoCounter) - canMotorInfo1[1] = 0x90 + (canMotorInfoCounter) - canMotorInfo3[1] = 0x90 + (canMotorInfoCounter) --- mod4 = canMotorInfoCounter % 4 - mod4 = data[1] - - - if (mod4 == 0 or mod4 == 2) then - txCan(1, MOTOR_INFO, 0, canMotorInfo) - elseif (mod4 == 1) then - txCan(1, MOTOR_INFO, 0, canMotorInfo1) - else - txCan(1, MOTOR_INFO, 0, canMotorInfo3) - end -end - -motorBreCounter = 0 -function onMotorBre(bus, id, dlc, data) - motorBreCounter = (motorBreCounter + 1) % 16 - - setBitRange(motorBreData, 8, 4, motorBreCounter) - xorChecksum(motorBreData, 1) - - txCan(TCU_BUS, id, 0, motorBreData) -- relay non-TCU message to TCU -end - -motor2counter = 0 -function onMotor2(bus, id, dlc, data) - motor2counter = (motor2counter + 1) % 16 - - minTorque = fakeTorque / 2 - motor2Data[7] = math.floor(minTorque / 0.39) - ---print ( "brake " .. getBitRange(data, 16, 2) .. " " .. rpm) - -brakeBit = rpm < 2000 and 1 or 0 -setBitRange(motor2Data, 16, 1, brakeBit) - - motor2Data[1] = motor2mux[math.floor(motor2counter / 4)] - --- txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU - txCan(TCU_BUS, id, 0, motor2Data) -end - -function onMotor7(bus, id, dlc, data) --- print("Relaying to TCU " .. id) --- txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU - txCan(TCU_BUS, id, 0, motor7Data) -end - accGraCounter = 0 function onAccGra(bus, id, dlc, data) accGraCounter = (accGraCounter + 1) % 16 setBitRange(accGraData, 60, 4, accGraCounter) xorChecksum(accGraData, 1) --- print("Relaying to TCU " .. id) --- txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU - txCan(TCU_BUS, id, 0, accGraData) +-- txCan(TCU_BUS, id, 0, accGraData) + txCan(TCU_BUS, id, 0, data) +end + +canMotorInfoCounter = 0 +function onMotorInfo(bus, id, dlc, data) + canMotorInfoCounter = (canMotorInfoCounter + 1) % 16 + canMotorInfo[1] = 0x90 + (canMotorInfoCounter) + canMotorInfo1[1] = 0x90 + (canMotorInfoCounter) + canMotorInfo3[1] = 0x90 + (canMotorInfoCounter) + mod4 = canMotorInfoCounter % 4 + + + if (mod4 == 0 or mod4 == 2) then +-- txCan(1, MOTOR_INFO, 0, canMotorInfo) + txCan(TCU_BUS, id, 0, data) + elseif (mod4 == 1) then +-- txCan(1, MOTOR_INFO, 0, canMotorInfo1) + txCan(TCU_BUS, id, 0, data) + else +-- txCan(1, MOTOR_INFO, 0, canMotorInfo3) + txCan(TCU_BUS, id, 0, data) + end +end + +function onMotor7(bus, id, dlc, data) +-- txCan(TCU_BUS, id, 0, motor7Data) + txCan(TCU_BUS, id, 0, data) end canRxAdd(ECU_BUS, MOTOR_1, onMotor1) @@ -286,13 +284,10 @@ function onTick() if everySecondTimer : getElapsedSeconds() > 1 then everySecondTimer : reset() - print("Total from ECU " ..totalEcuMessages .." from TCU " ..totalTcuMessages) - + print("Total from ECU " ..totalEcuMessages) motor5FuelCounter = motor5FuelCounter + 20 - end end - ```