progress
This commit is contained in:
parent
3575962da6
commit
fa83c5cddf
|
@ -14,21 +14,25 @@ import java.util.Map;
|
||||||
public class FiringOrderTSLogic {
|
public class FiringOrderTSLogic {
|
||||||
|
|
||||||
private static final String FIRING_ORDER_PREFIX = "FO_";
|
private static final String FIRING_ORDER_PREFIX = "FO_";
|
||||||
private static final Map<Integer, String[]> ordinal2order = new HashMap<>();
|
|
||||||
private static int maxOrdinal;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
invoke("../firmware/controllers/algo/firing_order.h");
|
invoke("../firmware/controllers/algo/firing_order.h");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void invoke(String fileName) throws IOException {
|
public static String invoke(String fileName) throws IOException {
|
||||||
readFiringOrders(fileName);
|
State state = new State();
|
||||||
|
|
||||||
for (int i = 2; i <= maxOrdinal; i++)
|
readFiringOrders(fileName, state);
|
||||||
processId(i);
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 2; i <= state.maxOrdinal; i++) {
|
||||||
|
String line = processId(i, state);
|
||||||
|
sb.append(line).append("\r\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readFiringOrders(String fileName) throws IOException {
|
private static void readFiringOrders(String fileName, State state) throws IOException {
|
||||||
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
@ -39,11 +43,11 @@ public class FiringOrderTSLogic {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line = line.substring(index + FIRING_ORDER_PREFIX.length());
|
line = line.substring(index + FIRING_ORDER_PREFIX.length());
|
||||||
parseLine(line);
|
parseLine(line, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parseLine(String line) {
|
public static void parseLine(String line, State state) {
|
||||||
line = line.replaceAll("[\\s]*\\,.*", "");
|
line = line.replaceAll("[\\s]*\\,.*", "");
|
||||||
line = line.replaceAll("[\\s\\,]", "");
|
line = line.replaceAll("[\\s\\,]", "");
|
||||||
System.out.println("Processing " + line);
|
System.out.println("Processing " + line);
|
||||||
|
@ -54,16 +58,16 @@ public class FiringOrderTSLogic {
|
||||||
|
|
||||||
System.out.println("order " + Arrays.toString(order) + ": " + ordinal);
|
System.out.println("order " + Arrays.toString(order) + ": " + ordinal);
|
||||||
|
|
||||||
maxOrdinal = Math.max(ordinal, maxOrdinal);
|
state.maxOrdinal = Math.max(ordinal, state.maxOrdinal);
|
||||||
ordinal2order.put(ordinal, order);
|
state.ordinal2order.put(ordinal, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processId(int cylinderId) {
|
private static String processId(int cylinderId, State state) {
|
||||||
|
|
||||||
StringBuilder logic = new StringBuilder();
|
StringBuilder logic = new StringBuilder();
|
||||||
|
|
||||||
|
|
||||||
for (Map.Entry<Integer, String[]> e : ordinal2order.entrySet()) {
|
for (Map.Entry<Integer, String[]> e : state.ordinal2order.entrySet()) {
|
||||||
Integer ordinal = e.getKey();
|
Integer ordinal = e.getKey();
|
||||||
String[] order = e.getValue();
|
String[] order = e.getValue();
|
||||||
if (order.length % 2 != 0) {
|
if (order.length % 2 != 0) {
|
||||||
|
@ -87,9 +91,14 @@ public class FiringOrderTSLogic {
|
||||||
}
|
}
|
||||||
String result = logic.length() == 0 ? "" : "|| (" + logic + ")";
|
String result = logic.length() == 0 ? "" : "|| (" + logic + ")";
|
||||||
|
|
||||||
|
String output = "#define ignitionPin" + cylinderId + "logic" + " " + result + "";
|
||||||
|
System.out.println(output);
|
||||||
System.out.println("#define ignitionPin" + cylinderId + "logic" + " " + result + "");
|
return output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class State {
|
||||||
|
final Map<Integer, String[]> ordinal2order = new HashMap<>();
|
||||||
|
int maxOrdinal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,6 @@ import org.junit.Test;
|
||||||
public class FiringOrderTSLogicTest {
|
public class FiringOrderTSLogicTest {
|
||||||
@Test
|
@Test
|
||||||
public void parseFiringOrderLine() {
|
public void parseFiringOrderLine() {
|
||||||
FiringOrderTSLogic.parseLine("FO_1_3_4_2 = 1, // typical inline 4");
|
FiringOrderTSLogic.parseLine("FO_1_3_4_2 = 1, // typical inline 4", new FiringOrderTSLogic.State());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue