Skip to content

Commit

Permalink
C/C++ into _middle
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Sep 5, 2024
1 parent 609733c commit c336245
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion reader/src/main/java/com/rusefi/can/CANPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -27,7 +34,6 @@ public StringBuilder asLua(String arrayName) {
result.append(String.format("0x%02x", data[index]));

}
result.append("}\n");
return result;
}

Expand Down
24 changes: 21 additions & 3 deletions reader/src/main/java/com/rusefi/can/analysis/PerSidDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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() + "' " ..)
Expand All @@ -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();
}
}
Expand Down

0 comments on commit c336245

Please sign in to comment.