XML tune export progress
This commit is contained in:
parent
18798f06a2
commit
dfd9ff3616
|
@ -23,7 +23,7 @@ public class IniFileMetaInfo {
|
|||
|
||||
public IniFileMetaInfo(RawIniFile file) {
|
||||
|
||||
nPages = file.getSimpleIntegerProperty("nPages");
|
||||
nPages = file.getSimpleIntegerProperty("nPages", 1);
|
||||
|
||||
blockingFactor = file.getSimpleIntegerProperty("blockingFactor", DEFAULT_BLOCKING_FACTOR);
|
||||
|
||||
|
|
|
@ -12,6 +12,11 @@ import java.util.*;
|
|||
public class IniFileModel {
|
||||
public static final String RUSEFI_INI_PREFIX = "rusefi";
|
||||
public static final String RUSEFI_INI_SUFFIX = ".ini";
|
||||
private static final String SECTION_PAGE = "page";
|
||||
private static final String FIELD_TYPE_SCALAR = "scalar";
|
||||
private static final String FIELD_TYPE_STRING = "string";
|
||||
private static final String FIELD_TYPE_ARRAY = "array";
|
||||
private static final String FIELD_TYPE_BITS = "bits";
|
||||
|
||||
private static IniFileModel INSTANCE;
|
||||
private String dialogId;
|
||||
|
@ -27,7 +32,8 @@ public class IniFileModel {
|
|||
System.out.println(IniFileModel.getInstance("..").dialogs);
|
||||
}
|
||||
|
||||
static boolean isInSettingContextHelp = false;
|
||||
private boolean isInSettingContextHelp = false;
|
||||
private boolean isInsidePageDefinition;
|
||||
|
||||
public void readIniFile(String iniFilePath) {
|
||||
String fileName = findMetaInfoFile(iniFilePath);
|
||||
|
@ -42,12 +48,15 @@ public class IniFileModel {
|
|||
System.out.println("Reading " + fileName);
|
||||
RawIniFile content = IniFileReader.read(input);
|
||||
|
||||
readIniFile(content);
|
||||
}
|
||||
|
||||
public IniFileModel readIniFile(RawIniFile content) {
|
||||
for (RawIniFile.Line line : content.getLines()) {
|
||||
handleLine(line);
|
||||
}
|
||||
|
||||
finishDialog();
|
||||
return this;
|
||||
}
|
||||
|
||||
private String findMetaInfoFile(String iniFilePath) {
|
||||
|
@ -78,6 +87,11 @@ public class IniFileModel {
|
|||
try {
|
||||
LinkedList<String> list = new LinkedList<>(Arrays.asList(line.getTokens()));
|
||||
|
||||
if (!list.isEmpty() && list.get(0).equals(SECTION_PAGE)) {
|
||||
isInsidePageDefinition = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// todo: use TSProjectConsumer constant
|
||||
if (isInSettingContextHelp) {
|
||||
// todo: use TSProjectConsumer constant
|
||||
|
@ -88,6 +102,7 @@ public class IniFileModel {
|
|||
tooltips.put(list.get(0), list.get(1));
|
||||
return;
|
||||
} else if (rawTest.contains("SettingContextHelp")) {
|
||||
isInsidePageDefinition = false;
|
||||
isInSettingContextHelp = true;
|
||||
return;
|
||||
}
|
||||
|
@ -99,8 +114,13 @@ public class IniFileModel {
|
|||
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
String first = list.getFirst();
|
||||
|
||||
if (isInsidePageDefinition) {
|
||||
handleFieldDefinition(list);
|
||||
return;
|
||||
}
|
||||
|
||||
String first = list.getFirst();
|
||||
|
||||
if ("dialog".equals(first)) {
|
||||
handleDialog(list);
|
||||
|
@ -112,6 +132,19 @@ public class IniFileModel {
|
|||
}
|
||||
}
|
||||
|
||||
private void handleFieldDefinition(LinkedList<String> list) {
|
||||
if (list.get(1).equals(FIELD_TYPE_SCALAR)) {
|
||||
|
||||
} else if (list.get(1).equals(FIELD_TYPE_STRING)) {
|
||||
} else if (list.get(1).equals(FIELD_TYPE_ARRAY)) {
|
||||
} else if (list.get(1).equals(FIELD_TYPE_BITS)) {
|
||||
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected " + list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleField(LinkedList<String> list) {
|
||||
list.removeFirst(); // "field"
|
||||
|
||||
|
@ -134,16 +167,13 @@ public class IniFileModel {
|
|||
|
||||
@Nullable
|
||||
public DialogModel.Field getField(String key) {
|
||||
DialogModel.Field field = allFields.get(key);
|
||||
return field;
|
||||
return allFields.get(key);
|
||||
}
|
||||
|
||||
private void handleDialog(LinkedList<String> list) {
|
||||
finishDialog();
|
||||
State state;
|
||||
list.removeFirst(); // "dialog"
|
||||
state = State.DIALOG;
|
||||
// trim(list);
|
||||
// trim(list);
|
||||
String keyword = list.removeFirst();
|
||||
// trim(list);
|
||||
String name = list.isEmpty() ? null : list.removeFirst();
|
||||
|
|
|
@ -55,7 +55,7 @@ public class IniFileReader {
|
|||
}
|
||||
|
||||
/**
|
||||
* Just grabs an collecton of lines, no parsing logic here
|
||||
* Just grabs an collection of lines, no parsing logic here
|
||||
*/
|
||||
public static RawIniFile read(InputStream in) {
|
||||
List<RawIniFile.Line> lines = new ArrayList<>();
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.opensr5.ini.test;
|
||||
|
||||
import com.opensr5.ini.IniFileMetaInfo;
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.IniFileReader;
|
||||
import com.opensr5.ini.RawIniFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -14,6 +16,9 @@ import static org.junit.Assert.assertEquals;
|
|||
* 3/1/2017
|
||||
*/
|
||||
public class IniFileReaderTest {
|
||||
private static final String PAGE_READ = " pageReadCommand = \"X\", \"X\", \"X\"\n\n\n\n";
|
||||
private static final String SIGNATURE_UNIT_TEST = " signature = \"unit test\"\n";
|
||||
|
||||
@Test
|
||||
public void testSplit() {
|
||||
{
|
||||
|
@ -61,14 +66,12 @@ public class IniFileReaderTest {
|
|||
@Test
|
||||
public void testTotalPagesSize() {
|
||||
String string = " nPages = 3\n" +
|
||||
" signature = \"unit test\"\n" +
|
||||
" pageReadCommand = \"X\", \"X\", \"X\"\n\n\n\n" +
|
||||
SIGNATURE_UNIT_TEST +
|
||||
PAGE_READ +
|
||||
" pageSize = 288, 64, 288\n";
|
||||
|
||||
|
||||
RawIniFile content = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||
|
||||
IniFileMetaInfo meta = new IniFileMetaInfo(content);
|
||||
IniFileMetaInfo meta = new IniFileMetaInfo(fromString(string));
|
||||
|
||||
assertEquals(3, meta.getnPages());
|
||||
assertEquals(IniFileMetaInfo.DEFAULT_BLOCKING_FACTOR, meta.getBlockingFactor());
|
||||
|
@ -78,4 +81,33 @@ public class IniFileReaderTest {
|
|||
assertEquals(64, meta.getPageSize(1));
|
||||
assertEquals("X", meta.getPageReadCommand(1));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private RawIniFile fromString(String string) {
|
||||
return IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEasyFields() {
|
||||
String string = "page = 1\n" +
|
||||
"primingSquirtDurationMs\t\t\t= scalar, F32,\t96,\t\"*C\", 1, 0, -40, 200, 1\n" +
|
||||
"\tiat_adcChannel\t\t\t\t = bits, U08, 312, [0:7] \"PA0\", \"PA1\", \"PA2\", \"PA3\", \"PA4\", \"PA5\", \"PA6\", \"PA7\", \"PB0\", \"PB1\", \"PC0\", \"PC1\", \"PC2\", \"PC3\", \"PC4\", \"PC5\", \"Disabled\", \"PB12\", \"PB13\", \"PC14\", \"PC15\", \"PC16\", \"PC17\", \"PD3\", \"PD4\", \"PE2\", \"PE6\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\"\n";
|
||||
|
||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||
|
||||
assertEquals(0, model.getAllFields().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCurveField() {
|
||||
String string =
|
||||
" \tmap_samplingAngleBins\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
|
||||
|
||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||
|
||||
assertEquals(0, model.getAllFields().size());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue