logicdata2c

This commit is contained in:
Matthew Kennedy 2023-04-13 00:52:19 -07:00
parent bc70cd552a
commit 176c047827
6 changed files with 0 additions and 88 deletions

View File

@ -24,7 +24,6 @@
<option value="$PROJECT_DIR$/bin2header" />
<option value="$PROJECT_DIR$/configuration_definition" />
<option value="$PROJECT_DIR$/enum_to_string" />
<option value="$PROJECT_DIR$/logicdata2c" />
</set>
</option>
</GradleProjectSettings>

View File

@ -1,2 +0,0 @@
input.csv
output.c

View File

@ -1,20 +0,0 @@
plugins {
id 'java-library'
}
defaultTasks 'jar'
apply from: '../../java_tools/dependencies.gradle'
dependencies {
testImplementation global_libs.junit
}
jar {
destinationDirectory = file( '$rootDir/../..' )
manifest {
attributes(
'Main-Class': 'com.rusefi.LogicData2C'
)
}
}

View File

@ -1 +0,0 @@
java -jar ../logicdata2c.jar

View File

@ -1,62 +0,0 @@
package com.rusefi;
import java.io.*;
public class LogicData2C {
private final static int NUMBER_OF_CHANNELS = 2;
public static void main(String[] args) throws IOException {
System.out.println("This tool reads .csv file produced by Logic software and produces C code based on it");
if (args.length == 0)
System.err.println("Input file parameter not specified, using default input file name");
String inputFileName = args.length == 0 ? "input.csv" : args[0];
System.out.println("Reading from " + inputFileName);
BufferedReader br = new BufferedReader(new FileReader(inputFileName));
BufferedWriter bw = new BufferedWriter(new FileWriter("output.c"));
int lineCounter = 0;
String line;
boolean currentStates[] = new boolean[NUMBER_OF_CHANNELS];
while ((line = br.readLine()) != null) {
lineCounter++;
if (lineCounter == 1) {
// skipping header line
continue;
}
line = line.replace(" ", "");
System.out.println("Got [" + line + "]");
String[] values = line.split(",");
double timestamp = Double.parseDouble(values[0]);
boolean channel0 = values[1].equals("0");
boolean channel1 = values[2].equals("0");
if (lineCounter > 2) {
if (currentStates[0] != channel0) {
System.out.println(lineCounter + ": Update 0 " + timestamp);
printEvent(bw, lineCounter, timestamp, channel0, 0);
}
if (currentStates[1] != channel1) {
System.out.println(lineCounter + ": Update 1 " + timestamp);
printEvent(bw, lineCounter, timestamp, channel0, 1);
}
}
currentStates[0] = channel0;
currentStates[1] = channel1;
}
bw.close();
}
private static void printEvent(BufferedWriter bw, int lineCounter, double timestamp, boolean value, int index) throws IOException {
bw.write("/*line=" + lineCounter + "*/ EVENT(/* timestamp*/" + timestamp + ", /*index*/" + index + ", /*value*/" + value + ");\n");
}
}

View File

@ -6,8 +6,6 @@ include ':logging-api'
project(':logging-api').projectDir = new File('../java_console/logging-api')
include ':enum_to_string'
project(':enum_to_string').projectDir = new File('enum_to_string')
include ':logicdata2c'
project(':logicdata2c').projectDir = new File('logicdata2c')
include ':bin2header'
project(':bin2header').projectDir = new File('bin2header')
include ':config_definition_base'