steps towards Android

This commit is contained in:
rusefi 2020-07-02 22:22:50 -04:00
parent 9f179d3e34
commit ff60908526
233 changed files with 161 additions and 111 deletions

View File

@ -12,6 +12,10 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/../java_console/inifile" />
<option value="$PROJECT_DIR$/../java_console/io" />
<option value="$PROJECT_DIR$/../java_console/logging-api" />
<option value="$PROJECT_DIR$/../java_console/models" />
<option value="$PROJECT_DIR$/../java_console/shared_io" />
</set>
</option>

View File

@ -3,3 +3,9 @@ include ':shared_io'
project(':shared_io').projectDir = new File('../java_console/shared_io')
include ':io'
project(':io').projectDir = new File('../java_console/io')
include ':logging-api'
project(':logging-api').projectDir = new File('../java_console/logging-api')
include ':inifile'
project(':inifile').projectDir = new File('../java_console/inifile')
include ':models'
project(':models').projectDir = new File('../java_console/models')

View File

@ -37,10 +37,10 @@ public class AverageAnglesUtil {
AverageAngles aa = new AverageAngles();
while ((line = br.readLine()) != null) {
int index = line.indexOf(FileLog.END_OF_TIMESTAND_TAG);
int index = line.indexOf(Logger.END_OF_TIMESTAND_TAG);
if (index == -1)
continue;
line = line.substring(index + FileLog.END_OF_TIMESTAND_TAG.length());
line = line.substring(index + Logger.END_OF_TIMESTAND_TAG.length());
if (line.startsWith("time")) {
String[] f = line.split(",");

View File

@ -3,7 +3,6 @@ package com.rusefi;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.EngineState;
import com.rusefi.io.CommandQueue;
import com.rusefi.io.LinkManager;
import com.rusefi.waves.EngineChart;
import com.rusefi.waves.EngineReport;
import com.rusefi.waves.RevolutionLog;
@ -107,7 +106,7 @@ public class TestingUtils {
static EngineChart nextChart(CommandQueue commandQueue) {
long start = System.currentTimeMillis();
EngineChart chart = EngineChartParser.unpackToMap(getNextWaveChart(commandQueue));
EngineChart chart = EngineChartParser.unpackToMap(getNextWaveChart(commandQueue), FileLog.LOGGER);
FileLog.MAIN.logLine("AUTOTEST nextChart() in " + (System.currentTimeMillis() - start));
return chart;
}

View File

@ -46,7 +46,8 @@
<src path="../java_tools/enum_to_string/src"/>
<src path="io/src/main/java"/>
<src path="io/src/test/java"/>
<src path="models/src"/>
<src path="models/src/main/java"/>
<src path="models/src/test/java"/>
<src path="inifile/src/main/java"/>
<src path="inifile/src/test/java"/>
<src path="shared_ui/src"/>
@ -82,7 +83,7 @@
<fileset dir="autoupdate/src" includes="**/test/**/*Test.java"/>
<fileset dir="io/src/test/java" includes="**/test/**/*Test.java"/>
<fileset dir="inifile/src/test/java" includes="**/test/**/*Test.java"/>
<fileset dir="models/src" includes="**/test/**/*Test.java"/>
<fileset dir="models/src/test/java" includes="**/test/**/*Test.java"/>
<fileset dir="ui/src/test/java" includes="**/*Test.java"/>
<fileset dir="romraider/src" includes="**/test/**/*Test.java"/>
<fileset dir="opensr5/src" includes="**/test/**/*Test.java"/>

View File

@ -0,0 +1,10 @@
plugins {
id 'java'
}
dependencies {
implementation project(':logging-api')
implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.1'
testImplementation group: 'junit', name: 'junit', version: '4.13'
}

View File

@ -9,9 +9,8 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="junit" level="project" />
<orderEntry type="module" module-name="models" exported="" />
<orderEntry type="module" module-name="autoupdate" exported="" />
<orderEntry type="library" name="annotations" level="project" />
<orderEntry type="module" module-name="shared_io" />
<orderEntry type="library" exported="" name="annotations" level="project" />
<orderEntry type="module" module-name="shared_io" exported="" />
</component>
</module>

View File

@ -3,14 +3,11 @@ package com.rusefi.tune.xml;
import com.opensr5.ConfigurationImage;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.field.IniField;
import com.rusefi.config.generated.Fields;
import com.rusefi.shared.FileUtil;
import com.rusefi.xml.XmlUtil;
import org.jetbrains.annotations.NotNull;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -18,7 +15,6 @@ import java.util.Objects;
@XmlRootElement
public class Msq {
public static final String outputXmlFileName = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "output.msq";
public List<Page> page = new ArrayList<>();
@ -29,24 +25,25 @@ public class Msq {
}
@NotNull
public static Msq valueOf(ConfigurationImage image) {
public static Msq valueOf(ConfigurationImage image, int totalConfigSize, String tsSignature) {
IniFileModel ini = IniFileModel.getInstance();
Msq tune = create();
Msq tune = create(totalConfigSize, tsSignature);
for (String key : ini.allIniFields.keySet())
tune.loadConstant(ini, key, image);
return tune;
}
@NotNull
public static Msq create() {
public static Msq create(int totalConfigSize, String tsSignature) {
Msq tune = new Msq();
tune.versionInfo.setTsSignature(tsSignature);
tune.page.add(new Page(null, null));
tune.page.add(new Page(0, Fields.TOTAL_CONFIG_SIZE));
tune.page.add(new Page(0, totalConfigSize));
return tune;
}
public ConfigurationImage asImage(IniFileModel instance) {
ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE);
public ConfigurationImage asImage(IniFileModel instance, int totalConfigSize) {
ConfigurationImage ci = new ConfigurationImage(totalConfigSize);
Page page = findPage();
if (page == null)
@ -97,9 +94,7 @@ public class Msq {
Integer size = p.getSize();
if (size == null)
continue;
if (size == Fields.TOTAL_CONFIG_SIZE) {
return p;
}
return p;
}
return null;
}

View File

@ -1,11 +1,10 @@
package com.rusefi.tune.xml;
import com.rusefi.config.generated.Fields;
import javax.xml.bind.annotation.XmlAttribute;
public class VersionInfo {
private String firmwareInfo;
private String tsSignature;
public VersionInfo() {
}
@ -19,18 +18,26 @@ public class VersionInfo {
return "5.0";
}
@XmlAttribute
public String getFirmwareInfo() {
return firmwareInfo;
}
@XmlAttribute
public String getNPages() {
return "1";
}
@XmlAttribute
public String getFirmwareInfo() {
return firmwareInfo;
}
@XmlAttribute
public String getSignature() {
return Fields.TS_SIGNATURE;
return tsSignature;
}
public void setFirmwareInfo(String firmwareInfo) {
this.firmwareInfo = firmwareInfo;
}
public void setTsSignature(String tsSignature) {
this.tsSignature = tsSignature;
}
}

View File

@ -3,5 +3,13 @@ plugins {
}
dependencies {
implementation project(':inifile')
implementation project(':models')
implementation project(':logging-api')
implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.1'
implementation group: 'com.fazecast', name: 'jSerialComm', version: '2.6.2'
implementation group: 'net.jcip', name: 'jcip-annotations', version: '1.0'
testImplementation group: 'junit', name: 'junit', version: '4.13'
}

View File

@ -12,5 +12,6 @@
<orderEntry type="library" name="jSerialComm" level="project" />
<orderEntry type="module" module-name="opensr5" exported="" />
<orderEntry type="module" module-name="logging-api" exported="" />
<orderEntry type="module" module-name="models" />
</component>
</module>

View File

@ -9,6 +9,7 @@ import com.rusefi.Timeouts;
import com.rusefi.composite.CompositeEvent;
import com.rusefi.composite.CompositeParser;
import com.rusefi.config.generated.Fields;
import com.rusefi.core.MessagesCentral;
import com.rusefi.core.Pair;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
@ -91,6 +92,8 @@ public class BinaryProtocol implements BinaryProtocolCommands {
public boolean isClosed;
public CommunicationLoggingListener communicationLoggingListener = CommunicationLoggingListener.VOID;
public byte[] getCurrentOutputs() {
return state.getCurrentOutputs();
}
@ -108,6 +111,13 @@ public class BinaryProtocol implements BinaryProtocolCommands {
this.logger = logger;
this.stream = stream;
communicationLoggingListener = new CommunicationLoggingListener() {
@Override
public void onPortHolderMessage(Class clazz, String message) {
MessagesCentral.getInstance().postMessage(logger, clazz, message);
}
};
incomingData = createDataBuffer(stream, logger);
Runtime.getRuntime().addShutdownHook(hook);
rpmListener = value -> {
@ -148,7 +158,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
public void doSend(final String command, boolean fireEvent) throws InterruptedException {
logger.info("Sending [" + command + "]");
if (fireEvent && LinkManager.LOG_LEVEL.isDebugEnabled()) {
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]");
}
Future f = linkManager.submit(new Runnable() {
@ -347,7 +357,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
}
try {
ConfigurationImageFile.saveToFile(image, CONFIGURATION_RUSEFI_BINARY);
Msq tune = Msq.valueOf(image);
Msq tune = MsqFactory.valueOf(image);
tune.writeXmlFile(CONFIGURATION_RUSEFI_XML);
} catch (Exception e) {
System.err.println("Ignoring " + e);

View File

@ -0,0 +1,11 @@
package com.rusefi.binaryprotocol;
import com.opensr5.ConfigurationImage;
import com.rusefi.config.generated.Fields;
import com.rusefi.tune.xml.Msq;
public class MsqFactory {
public static Msq valueOf(ConfigurationImage image) {
return Msq.valueOf(image, Fields.TOTAL_CONFIG_SIZE, Fields.TS_SIGNATURE);
}
}

View File

@ -1,5 +1,6 @@
package com.rusefi.file;
import com.opensr5.Logger;
import com.rusefi.core.EngineState;
import com.rusefi.io.LinkManager;
@ -11,8 +12,8 @@ import java.util.List;
* Andrey Belomutskiy, (c) 2013-2020
*/
public class FileUtils {
public static void readFile(String filename, EngineState.EngineStateListener listener) {
readFile2(filename, new EngineState(listener));
public static void readFile(String filename, EngineState.EngineStateListener listener, Logger logger) {
readFile2(filename, new EngineState(listener, logger));
}
public static void readFile2(String filename, EngineState engineState) {

View File

@ -36,6 +36,7 @@ public class CommandQueue {
private final List<CommandQueueListener> commandListeners = new ArrayList<>();
private final Runnable runnable;
private final Logger logger;
private static boolean isSlowCommand(String cmd) {
String lc = cmd.toLowerCase();
@ -97,7 +98,7 @@ public class CommandQueue {
}
if (counter != 1)
MessagesCentral.getInstance().postMessage(CommandQueue.class, "Took " + counter + " attempts");
MessagesCentral.getInstance().postMessage(logger, CommandQueue.class, "Took " + counter + " attempts");
}
public CommandQueue(LinkManager linkManager, Logger logger) {
@ -106,7 +107,7 @@ public class CommandQueue {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
MessagesCentral.getInstance().postMessage(COMMAND_QUEUE_CLASS, "SerialIO started");
MessagesCentral.getInstance().postMessage(logger, COMMAND_QUEUE_CLASS, "SerialIO started");
while (true) {
try {
sendPendingCommand();
@ -117,6 +118,7 @@ public class CommandQueue {
}
}
};
this.logger = logger;
Thread thread = new Thread(runnable, "Commands Queue");
thread.setDaemon(true);
thread.start();
@ -134,10 +136,10 @@ public class CommandQueue {
MessagesCentral mc = MessagesCentral.getInstance();
String confirmation = LinkManager.unpackConfirmation(message);
if (confirmation == null)
mc.postMessage(CommandQueue.class, "Broken confirmation length: " + message);
mc.postMessage(logger, CommandQueue.class, "Broken confirmation length: " + message);
pendingConfirmations.add(confirmation);
if (LinkManager.LOG_LEVEL.isDebugEnabled())
mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
mc.postMessage(logger, CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size());
// FileLog.MAIN.logLine("templog got valid conf " + confirmation + " " + System.currentTimeMillis() + " " + new Date());

View File

@ -43,7 +43,7 @@ public class LinkManager {
logger.info(fullLine);
HeartBeatListeners.onDataArrived();
}
});
}, logger);
commandQueue = new CommandQueue(this, logger);
}

View File

@ -2,7 +2,6 @@ package com.rusefi.io.serial;
import com.opensr5.Logger;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.io.CommunicationLoggingHolder;
import com.rusefi.io.ConnectionStateListener;
import com.opensr5.io.DataListener;
import com.rusefi.io.IoStream;
@ -41,7 +40,7 @@ public class PortHolder {
if (port == null)
return false;
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(getClass(), "Opening port: " + port);
linkManager.getCurrentStreamState().communicationLoggingListener.onPortHolderMessage(getClass(), "Opening port: " + port);
IoStream stream = SerialIoStreamJSerialComm.openPort(port, logger);
synchronized (portLock) {

View File

@ -48,7 +48,7 @@ public class SerialConnector implements LinkConnector {
linkManager.execute(new Runnable() {
@Override
public void run() {
MessagesCentral.getInstance().postMessage(SerialConnector.this.getClass(), "Restarting serial IO");
MessagesCentral.getInstance().postMessage(logger, SerialConnector.this.getClass(), "Restarting serial IO");
portHolder.close();
portHolder.connectAndReadConfiguration();
}

View File

@ -31,6 +31,7 @@ public interface Logger {
};
String DIR = "logs/";
String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss_SSS";
String END_OF_TIMESTAND_TAG = "<EOT>: ";
static String getDate() {
return new SimpleDateFormat(DATE_PATTERN).format(new Date());

View File

@ -20,7 +20,6 @@ public enum FileLog {
public static final String OS_VERSION = "os.version";
private static final String WIKI_URL = "https://github.com/rusefi/rusefi/wiki/rusEFI-logs-folder";
public static String currentLogName;
public static final String END_OF_TIMESTAND_TAG = "<EOT>: ";
public static final Logger LOGGER = new Logger() {
@Override
public void trace(String msg) {
@ -104,7 +103,7 @@ public enum FileLog {
}
public synchronized void logLine(String fullLine) {
String withDate = Logger.getDate() + END_OF_TIMESTAND_TAG + fullLine;
String withDate = Logger.getDate() + Logger.END_OF_TIMESTAND_TAG + fullLine;
System.out.println(withDate);
if (suspendLogging)
return;

View File

@ -0,0 +1,11 @@
plugins {
id 'java'
}
dependencies {
implementation project(':inifile')
implementation project(':logging-api')
implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.1'
testImplementation group: 'junit', name: 'junit', version: '4.13'
}

View File

@ -3,7 +3,8 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View File

@ -1,10 +0,0 @@
package com.rusefi.io;
/**
* Andrey Belomutskiy, (c) 2013-2020
* 6/20/2015.
*/
public class CommunicationLoggingHolder {
public static CommunicationLoggingListener communicationLoggingListener = CommunicationLoggingListener.VOID;
}

View File

@ -1,6 +1,6 @@
package com.rusefi.core;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.LinkDecoder;
import org.jetbrains.annotations.NotNull;
@ -43,17 +43,18 @@ public class EngineState {
}
private final ResponseBuffer buffer;
private final Logger logger;
private final List<StringActionPair> actions = new ArrayList<>();
private final Set<String> keys = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
public EngineState(@NotNull final EngineStateListener listener) {
public EngineState(@NotNull final EngineStateListener listener, Logger logger) {
buffer = new ResponseBuffer(new ResponseBuffer.ResponseListener() {
public void onResponse(String response) {
if (response != null) {
// let's remove timestamp if we get content from a log file not controller
int i = response.indexOf(FileLog.END_OF_TIMESTAND_TAG);
int i = response.indexOf(Logger.END_OF_TIMESTAND_TAG);
if (i != -1)
response = response.substring(i + FileLog.END_OF_TIMESTAND_TAG.length());
response = response.substring(i + Logger.END_OF_TIMESTAND_TAG.length());
String copy = response;
listener.beforeLine(response);
while (!response.isEmpty())
@ -63,8 +64,9 @@ public class EngineState {
}
}
);
this.logger = logger;
registerStringValueAction(Fields.PROTOCOL_MSG, value -> MessagesCentral.getInstance().postMessage(ENGINE_STATE_CLASS, value));
registerStringValueAction(Fields.PROTOCOL_MSG, value -> MessagesCentral.getInstance().postMessage(logger, ENGINE_STATE_CLASS, value));
}
/**
@ -82,7 +84,7 @@ public class EngineState {
* @return null in case of error, line message if valid packed ine
* @see #packString(String)
*/
public static String unpackString(String message) {
public static String unpackString(String message, Logger logger) {
String prefix = "line" + PACKING_DELIMITER;
/**
* If we get this tag we have probably connected to the wrong port
@ -93,13 +95,13 @@ public class EngineState {
return null;
}
if (!message.startsWith(prefix)) {
FileLog.MAIN.logLine("EngineState: unexpected header: " + message + " while looking for " + prefix);
logger.info("EngineState: unexpected header: " + message + " while looking for " + prefix);
return null;
}
message = message.substring(prefix.length());
int delimiterIndex = message.indexOf(PACKING_DELIMITER);
if (delimiterIndex == -1) {
FileLog.MAIN.logLine("Delimiter not found in: " + message);
logger.info("Delimiter not found in: " + message);
return null;
}
String lengthToken = message.substring(0, delimiterIndex);
@ -107,13 +109,13 @@ public class EngineState {
try {
expectedLen = Integer.parseInt(lengthToken);
} catch (NumberFormatException e) {
FileLog.MAIN.logLine("invalid len: " + lengthToken);
logger.info("invalid len: " + lengthToken);
return null;
}
String response = message.substring(delimiterIndex + 1);
if (response.length() != expectedLen) {
FileLog.MAIN.logLine("message len does not match header: " + message);
logger.info("message len does not match header: " + message);
response = null;
}
return response;
@ -131,7 +133,7 @@ public class EngineState {
response = handleStringActionPair(response, pair, listener);
}
if (originalResponse.length() == response.length()) {
FileLog.MAIN.logLine("EngineState.unknown: " + response);
logger.info("EngineState.unknown: " + response);
int keyEnd = response.indexOf(SEPARATOR);
if (keyEnd == -1) {
// discarding invalid line
@ -144,7 +146,7 @@ public class EngineState {
return "";
}
String value = response.substring(keyEnd, valueEnd);
FileLog.MAIN.logLine("Invalid key [" + unknownKey + "] value [" + value + "]");
logger.info("Invalid key [" + unknownKey + "] value [" + value + "]");
// trying to process the rest of the line
response = response.substring(valueEnd + SEPARATOR.length());
}

View File

@ -1,11 +1,8 @@
package com.rusefi.core;
import com.rusefi.FileLog;
import com.rusefi.io.CommunicationLoggingHolder;
import com.rusefi.io.CommunicationLoggingListener;
import com.opensr5.Logger;
import javax.swing.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -20,12 +17,6 @@ public class MessagesCentral {
private final List<MessageListener> listeners = new CopyOnWriteArrayList<>();
private MessagesCentral() {
CommunicationLoggingHolder.communicationLoggingListener = new CommunicationLoggingListener() {
@Override
public void onPortHolderMessage(Class clazz, String message) {
postMessage(clazz, message);
}
};
}
public static MessagesCentral getInstance() {
@ -36,8 +27,8 @@ public class MessagesCentral {
listeners.add(listener);
}
public void postMessage(final Class clazz, final String message) {
FileLog.MAIN.logLine("postMessage " + clazz.getSimpleName() + ": " + message);
public void postMessage(Logger logger, final Class clazz, final String message) {
logger.info("postMessage " + clazz.getSimpleName() + ": " + message);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {

View File

@ -1,6 +1,5 @@
package com.rusefi.core;
import com.rusefi.core.test.ResponseBufferTest;
import com.rusefi.io.LinkDecoder;
import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,6 @@
package com.rusefi.waves;
import com.rusefi.FileLog;
import com.opensr5.Logger;
import java.util.HashMap;
import java.util.Map;
@ -15,10 +15,10 @@ public class EngineChartParser {
/**
* This method unpacks a mixed-key message into a Map of messages by key
*/
public static EngineChart unpackToMap(String value) {
public static EngineChart unpackToMap(String value, Logger logger) {
if (value == null)
throw new NullPointerException("value");
FileLog.MAIN.logLine(": " + value);
logger.info(": " + value);
String[] array = value.split(DELI);

Some files were not shown because too many files have changed in this diff Show More