From c336245c021c882a576f6bedfc76f3a6ebf63d20 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Wed, 4 Sep 2024 22:26:51 -0400 Subject: [PATCH] C/C++ into _middle --- .../main/java/com/rusefi/can/CANPacket.java | 8 ++++++- .../com/rusefi/can/analysis/PerSidDump.java | 24 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/reader/src/main/java/com/rusefi/can/CANPacket.java b/reader/src/main/java/com/rusefi/can/CANPacket.java index 81c6120..b803fcf 100644 --- a/reader/src/main/java/com/rusefi/can/CANPacket.java +++ b/reader/src/main/java/com/rusefi/can/CANPacket.java @@ -17,6 +17,13 @@ public StringBuilder asLua(String arrayName) { StringBuilder result = new StringBuilder(); result.append(arrayName + " = {"); + result.append(arrayToCode()); + result.append("}\n"); + return result; + } + + public StringBuilder arrayToCode() { + StringBuilder result = new StringBuilder(); byte[] data = getData(); // System.out.println(String.format("Got ECU 0x%x", getId()) + " " + data.length); @@ -27,7 +34,6 @@ public StringBuilder asLua(String arrayName) { result.append(String.format("0x%02x", data[index])); } - result.append("}\n"); return result; } diff --git a/reader/src/main/java/com/rusefi/can/analysis/PerSidDump.java b/reader/src/main/java/com/rusefi/can/analysis/PerSidDump.java index 5d93b94..78ea8f9 100644 --- a/reader/src/main/java/com/rusefi/can/analysis/PerSidDump.java +++ b/reader/src/main/java/com/rusefi/can/analysis/PerSidDump.java @@ -56,7 +56,8 @@ public static void handle(DbcFile dbc, String reportDestinationFolder, String si String decAndHex = middlePacket.getId() + "_" + Integer.toHexString(middlePacket.getId()); String payloadVariableName = "payload" + (packet == null ? decAndHex : packet.getName()); String variableName = packet == null ? "CAN_" + decAndHex : packet.getName(); - String methodName = "on" + (packet == null ? ("Can" + decAndHex) : packet.getName()); + String methodNameSuffix = packet == null ? ("Can" + decAndHex) : packet.getName(); + String rxMethodName = "on" + methodNameSuffix; StringBuilder payloadLine = middlePacket.asLua(payloadVariableName); @@ -67,7 +68,7 @@ public static void handle(DbcFile dbc, String reportDestinationFolder, String si middle.println(); middle.println(counterVariable + " = 0"); - middle.println("function " + methodName + "(bus, id, dlc, data)"); + middle.println("function " + rxMethodName + "(bus, id, dlc, data)"); middle.println("\t" + counterVariable + " = (" + counterVariable + " + 1) % 256"); middle.println("\t" + payloadVariableName + "[x] = " + counterVariable); //middle.println("\tprint ('MOTOR_" + middlePacket.getId() + "' " ..) @@ -77,13 +78,30 @@ public static void handle(DbcFile dbc, String reportDestinationFolder, String si middle.println("end"); middle.println(); - middle.println("canRxAdd(ECU_BUS, " + variableName + ", " + methodName + ")"); + middle.println("canRxAdd(ECU_BUS, " + variableName + ", " + rxMethodName + ")"); middle.println("canRxAdd(ECU_BUS, " + variableName + ", " + "drop" + ")"); middle.println("canRxAdd(ECU_BUS, " + variableName + ", " + "drop" + ")"); middle.println(); middle.println(middlePacket.getBytesAsString()); + + String txMethodName = "send" + methodNameSuffix; + + middle.println(); + middle.println(); + middle.println("static void " + txMethodName + "() {"); + middle.println("static uint8_t " + payloadVariableName + "[] = {" + middlePacket.arrayToCode() + "};"); + middle.println("static int " + counterVariable + ";"); + + if (packet != null) { + middle.println("\tCanTxMessage msg(CanCategory::NBC, " + packet.getName() + ");"); + middle.println("\tmsg.setArray(" + payloadVariableName + ", 8);"); + + + } + middle.println("}"); + middle.close(); } }