mirror of https://github.com/rusefi/RomRaider.git
support begun for ecu on/off switches
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@251 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
4dc1ee30ef
commit
55d60b33f4
|
@ -41,6 +41,7 @@ public class Settings implements Serializable {
|
|||
private String loggerPort = "COM4";
|
||||
private String loggerProtocol = "SSM";
|
||||
private String loggerConfigFilePath = "./logger.xml";
|
||||
private File loggerOutputDir = new File(".");
|
||||
|
||||
public Settings() {
|
||||
//center window by default
|
||||
|
@ -282,4 +283,8 @@ public class Settings implements Serializable {
|
|||
public String getLoggerConfigFilePath() {
|
||||
return loggerConfigFilePath;
|
||||
}
|
||||
|
||||
public File getLoggerOutputDir() {
|
||||
return loggerOutputDir;
|
||||
}
|
||||
}
|
|
@ -1,18 +1,20 @@
|
|||
package enginuity.logger;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.definition.EcuDataLoader;
|
||||
import enginuity.logger.definition.EcuDataLoaderImpl;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuParameterLoaderImpl;
|
||||
import enginuity.logger.definition.EcuSwitch;
|
||||
import enginuity.logger.ui.LoggerDataTableModel;
|
||||
import enginuity.logger.ui.ParameterListTableModel;
|
||||
import enginuity.logger.ui.ParameterRegistrationBroker;
|
||||
import enginuity.logger.ui.ParameterRegistrationBrokerImpl;
|
||||
import enginuity.logger.ui.handler.DashboardUpdateHandler;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManager;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManagerImpl;
|
||||
import enginuity.logger.ui.handler.FileUpdateHandler;
|
||||
import enginuity.logger.ui.handler.GraphUpdateHandler;
|
||||
import enginuity.logger.ui.handler.LiveDataUpdateHandler;
|
||||
import enginuity.logger.ui.handler.ParameterUpdateHandlerManager;
|
||||
import enginuity.logger.ui.handler.ParameterUpdateHandlerManagerImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import static javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
|
||||
|
@ -34,7 +36,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
private final JComboBox portsComboBox = new JComboBox();
|
||||
private final LoggerDataTableModel dataTableModel = new LoggerDataTableModel();
|
||||
private final JPanel graphPanel = new JPanel();
|
||||
private final ParameterUpdateHandlerManager handlerManager = new ParameterUpdateHandlerManagerImpl();
|
||||
private final DataUpdateHandlerManager handlerManager = new DataUpdateHandlerManagerImpl();
|
||||
private final ParameterRegistrationBroker broker = new ParameterRegistrationBrokerImpl(handlerManager, settings);
|
||||
private final ParameterListTableModel paramListTableModel = new ParameterListTableModel(broker);
|
||||
|
||||
|
@ -68,11 +70,16 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
private void loadEcuParamsFromConfig() {
|
||||
//TODO: handle errors here better!
|
||||
try {
|
||||
EcuParameterLoaderImpl parameterLoader = new EcuParameterLoaderImpl();
|
||||
List<EcuParameter> ecuParams = parameterLoader.loadFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol());
|
||||
EcuDataLoader dataLoader = new EcuDataLoaderImpl();
|
||||
dataLoader.loadFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol());
|
||||
List<EcuParameter> ecuParams = dataLoader.getEcuParameters();
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
paramListTableModel.addParam(ecuParam);
|
||||
}
|
||||
List<EcuSwitch> ecuSwitches = dataLoader.getEcuSwitches();
|
||||
for (EcuSwitch ecuSwitch : ecuSwitches) {
|
||||
paramListTableModel.addParam(ecuSwitch);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -9,9 +9,9 @@ public interface LoggerController {
|
|||
|
||||
List<String> listSerialPorts();
|
||||
|
||||
void addLogger(EcuParameter ecuParam, LoggerCallback callback);
|
||||
void addLogger(EcuData ecuData, LoggerCallback callback);
|
||||
|
||||
void removeLogger(EcuParameter ecuParam);
|
||||
void removeLogger(EcuData ecuData);
|
||||
|
||||
void start();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package enginuity.logger;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.io.serial.SerialPortDiscoverer;
|
||||
import enginuity.logger.io.serial.SerialPortDiscovererImpl;
|
||||
import enginuity.logger.manager.QueryManager;
|
||||
|
@ -33,16 +33,16 @@ public final class LoggerControllerImpl implements LoggerController {
|
|||
return portNames;
|
||||
}
|
||||
|
||||
public void addLogger(EcuParameter ecuParam, LoggerCallback callback) {
|
||||
checkNotNull(ecuParam, callback);
|
||||
System.out.println("Adding logger: " + ecuParam.getName());
|
||||
queryManager.addQuery(ecuParam, callback);
|
||||
public void addLogger(EcuData ecuData, LoggerCallback callback) {
|
||||
checkNotNull(ecuData, callback);
|
||||
System.out.println("Adding logger: " + ecuData.getName());
|
||||
queryManager.addQuery(ecuData, callback);
|
||||
}
|
||||
|
||||
public void removeLogger(EcuParameter ecuParam) {
|
||||
checkNotNull(ecuParam, "ecuParam");
|
||||
System.out.println("Removing logger: " + ecuParam.getName());
|
||||
queryManager.removeQuery(ecuParam);
|
||||
public void removeLogger(EcuData ecuData) {
|
||||
checkNotNull(ecuData, "ecuParam");
|
||||
System.out.println("Removing logger: " + ecuData.getName());
|
||||
queryManager.removeQuery(ecuData);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface EcuData {
|
||||
|
||||
String getName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String[] getAddresses();
|
||||
|
||||
EcuDataConvertor getConvertor();
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface EcuParameterConvertor {
|
||||
public interface EcuDataConvertor {
|
||||
|
||||
double convert(byte[] bytes);
|
||||
|
||||
String getUnits();
|
||||
|
||||
String format(double value);
|
||||
|
||||
String getUnits();
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EcuDataLoader {
|
||||
|
||||
void loadFromXml(String loggerConfigFilePath, String protocol);
|
||||
|
||||
List<EcuParameter> getEcuParameters();
|
||||
|
||||
List<EcuSwitch> getEcuSwitches();
|
||||
|
||||
}
|
|
@ -9,11 +9,14 @@ import java.io.BufferedInputStream;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class EcuParameterLoaderImpl implements EcuParameterLoader {
|
||||
public final class EcuDataLoaderImpl implements EcuDataLoader {
|
||||
private List<EcuParameter> ecuParameters = new ArrayList<EcuParameter>();
|
||||
private List<EcuSwitch> ecuSwitches = new ArrayList<EcuSwitch>();
|
||||
|
||||
public List<EcuParameter> loadFromXml(String loggerConfigFilePath, String protocol) {
|
||||
public void loadFromXml(String loggerConfigFilePath, String protocol) {
|
||||
checkNotNullOrEmpty(loggerConfigFilePath, "loggerConfigFilePath");
|
||||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(loggerConfigFilePath)));
|
||||
|
@ -21,7 +24,8 @@ public final class EcuParameterLoaderImpl implements EcuParameterLoader {
|
|||
SAXParser parser = getSaxParserFactory().newSAXParser();
|
||||
LoggerDefinitionHandler handler = new LoggerDefinitionHandler(protocol);
|
||||
parser.parse(inputStream, handler);
|
||||
return handler.getEcuParameters();
|
||||
ecuParameters = handler.getEcuParameters();
|
||||
ecuSwitches = handler.getEcuSwitches();
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
|
@ -30,6 +34,14 @@ public final class EcuParameterLoaderImpl implements EcuParameterLoader {
|
|||
}
|
||||
}
|
||||
|
||||
public List<EcuParameter> getEcuParameters() {
|
||||
return ecuParameters;
|
||||
}
|
||||
|
||||
public List<EcuSwitch> getEcuSwitches() {
|
||||
return ecuSwitches;
|
||||
}
|
||||
|
||||
private SAXParserFactory getSaxParserFactory() {
|
||||
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
|
||||
parserFactory.setNamespaceAware(false);
|
|
@ -1,13 +1,7 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface EcuParameter {
|
||||
public interface EcuParameter extends EcuData {
|
||||
|
||||
String getName();
|
||||
|
||||
String getDescription();
|
||||
|
||||
String[] getAddresses();
|
||||
|
||||
EcuParameterConvertor getConvertor();
|
||||
EcuDataConvertor getConvertor();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
|||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public final class EcuParameterConvertorImpl implements EcuParameterConvertor {
|
||||
public final class EcuParameterConvertorImpl implements EcuDataConvertor {
|
||||
private final String units;
|
||||
private final String expression;
|
||||
private final DecimalFormat format;
|
||||
|
|
|
@ -7,9 +7,9 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
private String name;
|
||||
private String description;
|
||||
private String[] addresses;
|
||||
private EcuParameterConvertor convertor;
|
||||
private EcuDataConvertor convertor;
|
||||
|
||||
public EcuParameterImpl(String name, String description, String[] address, EcuParameterConvertor convertor) {
|
||||
public EcuParameterImpl(String name, String description, String[] address, EcuDataConvertor convertor) {
|
||||
checkNotNullOrEmpty(name, "name");
|
||||
checkNotNull(description, "description");
|
||||
checkNotNullOrEmpty(address, "addresses");
|
||||
|
@ -32,7 +32,7 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
return addresses;
|
||||
}
|
||||
|
||||
public EcuParameterConvertor getConvertor() {
|
||||
public EcuDataConvertor getConvertor() {
|
||||
return convertor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EcuParameterLoader {
|
||||
|
||||
List<EcuParameter> loadFromXml(String loggerConfigFilePath, String protocol);
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface EcuSwitch extends EcuData {
|
||||
|
||||
EcuDataConvertor getConvertor();
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public final class EcuSwitchConvertorImpl implements EcuDataConvertor {
|
||||
private final int bit;
|
||||
|
||||
public EcuSwitchConvertorImpl(int bit) {
|
||||
checkBit(bit);
|
||||
this.bit = bit;
|
||||
}
|
||||
|
||||
public double convert(byte[] bytes) {
|
||||
return (bytes[0] & (1 << bit)) > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String format(double value) {
|
||||
return value > 0 ? "On" : "Off";
|
||||
}
|
||||
|
||||
private void checkBit(int bit) {
|
||||
if (bit < 0 || bit > 7) {
|
||||
throw new IllegalArgumentException("Bit must be between 0 and 7 inclusive.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
public final class EcuSwitchImpl implements EcuSwitch {
|
||||
private String name;
|
||||
private String description;
|
||||
private String[] addresses;
|
||||
private EcuDataConvertor convertor;
|
||||
|
||||
public EcuSwitchImpl(String name, String description, String[] address, EcuDataConvertor convertor) {
|
||||
checkNotNullOrEmpty(name, "name");
|
||||
checkNotNull(description, "description");
|
||||
checkNotNullOrEmpty(address, "addresses");
|
||||
checkNotNull(convertor, "convertor");
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.addresses = address;
|
||||
this.convertor = convertor;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public EcuDataConvertor getConvertor() {
|
||||
return convertor;
|
||||
}
|
||||
}
|
|
@ -15,16 +15,21 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
private static final String TAG_CONVERTOR = "convertor";
|
||||
private static final String TAG_METRIC = "metric";
|
||||
private static final String TAG_BYTE = "byte";
|
||||
private static final String TAG_SWITCH = "switch";
|
||||
private static final String ATTR_ID = "id";
|
||||
private static final String ATTR_DESC = "desc";
|
||||
private static final String ATTR_UNITS = "units";
|
||||
private static final String ATTR_EXPRESSION = "expr";
|
||||
private static final String ATTR_FORMAT = "format";
|
||||
private static final String ATTR_BYTE = "byte";
|
||||
private static final String ATTR_BIT = "bit";
|
||||
private List<EcuParameter> params;
|
||||
private String paramName;
|
||||
private String paramDesc;
|
||||
private List<EcuSwitch> switches;
|
||||
private String name;
|
||||
private String desc;
|
||||
private List<String> addressList;
|
||||
private EcuParameterConvertor convertor;
|
||||
private int bit;
|
||||
private EcuDataConvertor convertor;
|
||||
private StringBuilder charBuffer;
|
||||
private String protocol;
|
||||
private boolean parseProtocol;
|
||||
|
@ -36,19 +41,26 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
|
||||
public void startDocument() {
|
||||
params = new ArrayList<EcuParameter>();
|
||||
switches = new ArrayList<EcuSwitch>();
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (TAG_PROTOCOL.equals(qName) && protocol.equalsIgnoreCase(attributes.getValue(ATTR_ID))) {
|
||||
parseProtocol = true;
|
||||
if (TAG_PROTOCOL.equals(qName)) {
|
||||
parseProtocol = protocol.equalsIgnoreCase(attributes.getValue(ATTR_ID));
|
||||
} else if (parseProtocol) {
|
||||
if (TAG_PARAMETER.equals(qName)) {
|
||||
paramName = attributes.getValue(ATTR_ID);
|
||||
paramDesc = attributes.getValue(ATTR_DESC);
|
||||
name = attributes.getValue(ATTR_ID);
|
||||
desc = attributes.getValue(ATTR_DESC);
|
||||
addressList = new ArrayList<String>();
|
||||
} else if (TAG_METRIC.equals(qName)) {
|
||||
convertor = new EcuParameterConvertorImpl(attributes.getValue(ATTR_UNITS), attributes.getValue(ATTR_EXPRESSION),
|
||||
attributes.getValue(ATTR_FORMAT));
|
||||
} else if (TAG_SWITCH.equals(qName)) {
|
||||
name = attributes.getValue(ATTR_ID);
|
||||
desc = attributes.getValue(ATTR_DESC);
|
||||
addressList = new ArrayList<String>();
|
||||
addressList.add(attributes.getValue(ATTR_BYTE));
|
||||
bit = Integer.valueOf(attributes.getValue(ATTR_BIT));
|
||||
}
|
||||
}
|
||||
charBuffer = new StringBuilder();
|
||||
|
@ -69,8 +81,13 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
} else if (TAG_PARAMETER.equals(qName)) {
|
||||
String[] addresses = new String[addressList.size()];
|
||||
addressList.toArray(addresses);
|
||||
EcuParameter param = new EcuParameterImpl(paramName, paramDesc, addresses, convertor);
|
||||
EcuParameter param = new EcuParameterImpl(name, desc, addresses, convertor);
|
||||
params.add(param);
|
||||
} else if (TAG_SWITCH.equals(qName)) {
|
||||
String[] addresses = new String[addressList.size()];
|
||||
addressList.toArray(addresses);
|
||||
EcuSwitch ecuSwitch = new EcuSwitchImpl(name, desc, addresses, new EcuSwitchConvertorImpl(bit));
|
||||
switches.add(ecuSwitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,4 +96,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
return params;
|
||||
}
|
||||
|
||||
public List<EcuSwitch> getEcuSwitches() {
|
||||
return switches;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package enginuity.logger.manager;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
|
||||
public interface QueryManager extends Runnable {
|
||||
|
||||
void addQuery(EcuParameter ecuParam, LoggerCallback callback);
|
||||
void addQuery(EcuData ecuData, LoggerCallback callback);
|
||||
|
||||
void removeQuery(EcuParameter ecuParam);
|
||||
void removeQuery(EcuData ecuData);
|
||||
|
||||
void stop();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.manager;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.logger.query.RegisteredQueryImpl;
|
||||
|
@ -14,9 +14,9 @@ import java.util.Map;
|
|||
|
||||
@SuppressWarnings({"FieldCanBeLocal"})
|
||||
public final class QueryManagerImpl implements QueryManager {
|
||||
private final Map<EcuParameter, RegisteredQuery> queryMap = Collections.synchronizedMap(new HashMap<EcuParameter, RegisteredQuery>());
|
||||
private final Map<EcuData, RegisteredQuery> queryMap = Collections.synchronizedMap(new HashMap<EcuData, RegisteredQuery>());
|
||||
private final List<RegisteredQuery> addList = new ArrayList<RegisteredQuery>();
|
||||
private final List<EcuParameter> removeList = new ArrayList<EcuParameter>();
|
||||
private final List<EcuData> removeList = new ArrayList<EcuData>();
|
||||
private final TransmissionManager txManager;
|
||||
private boolean stop = false;
|
||||
|
||||
|
@ -25,13 +25,13 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
this.txManager = txManager;
|
||||
}
|
||||
|
||||
public synchronized void addQuery(EcuParameter ecuParam, LoggerCallback callback) {
|
||||
checkNotNull(ecuParam, callback);
|
||||
addList.add(new RegisteredQueryImpl(ecuParam, callback));
|
||||
public synchronized void addQuery(EcuData ecuData, LoggerCallback callback) {
|
||||
checkNotNull(ecuData, callback);
|
||||
addList.add(new RegisteredQueryImpl(ecuData, callback));
|
||||
}
|
||||
|
||||
public synchronized void removeQuery(EcuParameter ecuParam) {
|
||||
removeList.add(ecuParam);
|
||||
public synchronized void removeQuery(EcuData ecuData) {
|
||||
removeList.add(ecuData);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
@ -71,14 +71,14 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
|
||||
private void addQueries() {
|
||||
for (RegisteredQuery registeredQuery : addList) {
|
||||
queryMap.put(registeredQuery.getEcuParam(), registeredQuery);
|
||||
queryMap.put(registeredQuery.getEcuData(), registeredQuery);
|
||||
}
|
||||
addList.clear();
|
||||
}
|
||||
|
||||
private void removeQueries() {
|
||||
for (EcuParameter ecuParam : removeList) {
|
||||
queryMap.remove(ecuParam);
|
||||
for (EcuData ecuData : removeList) {
|
||||
queryMap.remove(ecuData);
|
||||
}
|
||||
removeList.clear();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.query;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
public interface RegisteredQuery {
|
||||
|
||||
|
@ -12,5 +12,5 @@ public interface RegisteredQuery {
|
|||
|
||||
void setResponse(byte[] response);
|
||||
|
||||
EcuParameter getEcuParam();
|
||||
EcuData getEcuData();
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
package enginuity.logger.query;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import static enginuity.util.HexUtil.asBytes;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
public final class RegisteredQueryImpl implements RegisteredQuery {
|
||||
private final EcuParameter ecuParam;
|
||||
private final EcuData ecuData;
|
||||
private final LoggerCallback callback;
|
||||
private final byte[] bytes;
|
||||
|
||||
public RegisteredQueryImpl(EcuParameter ecuParam, LoggerCallback callback) {
|
||||
checkNotNull(ecuParam, callback);
|
||||
this.ecuParam = ecuParam;
|
||||
public RegisteredQueryImpl(EcuData ecuData, LoggerCallback callback) {
|
||||
checkNotNull(ecuData, callback);
|
||||
this.ecuData = ecuData;
|
||||
this.callback = callback;
|
||||
bytes = getAddressBytes(ecuParam);
|
||||
bytes = getAddressBytes(ecuData);
|
||||
}
|
||||
|
||||
public EcuParameter getEcuParam() {
|
||||
return ecuParam;
|
||||
public EcuData getEcuData() {
|
||||
return ecuData;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return ecuParam.getAddresses();
|
||||
return ecuData.getAddresses();
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
|
@ -37,8 +37,8 @@ public final class RegisteredQueryImpl implements RegisteredQuery {
|
|||
callback.callback(response);
|
||||
}
|
||||
|
||||
private byte[] getAddressBytes(EcuParameter ecuParam) {
|
||||
String[] addresses = ecuParam.getAddresses();
|
||||
private byte[] getAddressBytes(EcuData ecuData) {
|
||||
String[] addresses = ecuData.getAddresses();
|
||||
byte[] bytes = new byte[0];
|
||||
for (String address : addresses) {
|
||||
byte[] tmp1 = asBytes(address);
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
public final class LoggerDataRow {
|
||||
private final EcuParameter ecuParam;
|
||||
private final EcuData ecuData;
|
||||
private double minValue;
|
||||
private double maxValue;
|
||||
private double currentValue;
|
||||
private boolean updated = false;
|
||||
|
||||
public LoggerDataRow(EcuParameter ecuParam) {
|
||||
checkNotNull(ecuParam, "ecuParam");
|
||||
this.ecuParam = ecuParam;
|
||||
public LoggerDataRow(EcuData ecuData) {
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
this.ecuData = ecuData;
|
||||
}
|
||||
|
||||
public EcuParameter getEcuParam() {
|
||||
return ecuParam;
|
||||
public EcuData getEcuData() {
|
||||
return ecuData;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return ecuParam.getName();
|
||||
return ecuData.getName();
|
||||
}
|
||||
|
||||
public String getMinValue() {
|
||||
return ecuParam.getConvertor().format(minValue);
|
||||
return ecuData.getConvertor().format(minValue);
|
||||
}
|
||||
|
||||
public String getMaxValue() {
|
||||
return ecuParam.getConvertor().format(maxValue);
|
||||
return ecuData.getConvertor().format(maxValue);
|
||||
}
|
||||
|
||||
public String getCurrentValue() {
|
||||
return ecuParam.getConvertor().format(currentValue);
|
||||
return ecuData.getConvertor().format(currentValue);
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return ecuParam.getConvertor().getUnits();
|
||||
return ecuData.getConvertor().getUnits();
|
||||
}
|
||||
|
||||
public void updateValue(byte[] bytes) {
|
||||
currentValue = ecuParam.getConvertor().convert(bytes);
|
||||
currentValue = ecuData.getConvertor().convert(bytes);
|
||||
if (currentValue < minValue || !updated) {
|
||||
minValue = currentValue;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import static java.util.Collections.synchronizedList;
|
||||
|
@ -11,9 +11,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
public final class LoggerDataTableModel extends AbstractTableModel {
|
||||
private final String[] columnNames = {"ECU Parameter", "Min Value", "Current Value", "Max Value", "Units"};
|
||||
private final List<EcuParameter> registeredEcuParams = synchronizedList(new LinkedList<EcuParameter>());
|
||||
private final Map<EcuParameter, LoggerDataRow> dataRowMap = synchronizedMap(new LinkedHashMap<EcuParameter, LoggerDataRow>());
|
||||
private final String[] columnNames = {"ECU Data", "Min Value", "Current Value", "Max Value", "Units"};
|
||||
private final List<EcuData> registeredEcuData = synchronizedList(new LinkedList<EcuData>());
|
||||
private final Map<EcuData, LoggerDataRow> dataRowMap = synchronizedMap(new LinkedHashMap<EcuData, LoggerDataRow>());
|
||||
|
||||
public synchronized int getRowCount() {
|
||||
return dataRowMap.size();
|
||||
|
@ -32,7 +32,7 @@ public final class LoggerDataTableModel extends AbstractTableModel {
|
|||
}
|
||||
|
||||
public synchronized Object getValueAt(int row, int col) {
|
||||
LoggerDataRow dataRow = dataRowMap.get(registeredEcuParams.get(row));
|
||||
LoggerDataRow dataRow = dataRowMap.get(registeredEcuData.get(row));
|
||||
switch (col) {
|
||||
case 0:
|
||||
return dataRow.getName();
|
||||
|
@ -49,25 +49,25 @@ public final class LoggerDataTableModel extends AbstractTableModel {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void addParam(EcuParameter ecuParam) {
|
||||
if (!registeredEcuParams.contains(ecuParam)) {
|
||||
dataRowMap.put(ecuParam, new LoggerDataRow(ecuParam));
|
||||
registeredEcuParams.add(ecuParam);
|
||||
public synchronized void addParam(EcuData ecuData) {
|
||||
if (!registeredEcuData.contains(ecuData)) {
|
||||
dataRowMap.put(ecuData, new LoggerDataRow(ecuData));
|
||||
registeredEcuData.add(ecuData);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void removeParam(EcuParameter ecuParam) {
|
||||
registeredEcuParams.remove(ecuParam);
|
||||
dataRowMap.remove(ecuParam);
|
||||
public synchronized void removeParam(EcuData ecuData) {
|
||||
registeredEcuData.remove(ecuData);
|
||||
dataRowMap.remove(ecuData);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public synchronized void updateParam(EcuParameter ecuParam, byte[] bytes) {
|
||||
LoggerDataRow dataRow = dataRowMap.get(ecuParam);
|
||||
public synchronized void updateParam(EcuData ecuData, byte[] bytes) {
|
||||
LoggerDataRow dataRow = dataRowMap.get(ecuData);
|
||||
if (dataRow != null) {
|
||||
dataRow.updateValue(bytes);
|
||||
int index = registeredEcuParams.indexOf(ecuParam);
|
||||
int index = registeredEcuData.indexOf(ecuData);
|
||||
fireTableRowsUpdated(index, index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import static java.util.Collections.synchronizedList;
|
||||
|
@ -11,9 +11,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
public final class ParameterListTableModel extends AbstractTableModel {
|
||||
private final String[] columnNames = {"Selected?", "ECU Parameter"};
|
||||
private final List<EcuParameter> registeredEcuParams = synchronizedList(new LinkedList<EcuParameter>());
|
||||
private final Map<EcuParameter, ParameterRow> paramRowMap = synchronizedMap(new LinkedHashMap<EcuParameter, ParameterRow>());
|
||||
private final String[] columnNames = {"Selected?", "ECU Data"};
|
||||
private final List<EcuData> registeredEcuData = synchronizedList(new LinkedList<EcuData>());
|
||||
private final Map<EcuData, ParameterRow> paramRowMap = synchronizedMap(new LinkedHashMap<EcuData, ParameterRow>());
|
||||
private final ParameterRegistrationBroker broker;
|
||||
|
||||
public ParameterListTableModel(ParameterRegistrationBroker broker) {
|
||||
|
@ -37,26 +37,26 @@ public final class ParameterListTableModel extends AbstractTableModel {
|
|||
}
|
||||
|
||||
public synchronized Object getValueAt(int row, int col) {
|
||||
ParameterRow paramRow = paramRowMap.get(registeredEcuParams.get(row));
|
||||
ParameterRow paramRow = paramRowMap.get(registeredEcuData.get(row));
|
||||
switch (col) {
|
||||
case 0:
|
||||
return paramRow.getSelected();
|
||||
case 1:
|
||||
return paramRow.getEcuParam().getName();
|
||||
return paramRow.getEcuData().getName();
|
||||
default:
|
||||
return "Error!";
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setValueAt(Object value, int row, int col) {
|
||||
ParameterRow paramRow = paramRowMap.get(registeredEcuParams.get(row));
|
||||
ParameterRow paramRow = paramRowMap.get(registeredEcuData.get(row));
|
||||
if (col == 0 && paramRow != null) {
|
||||
Boolean selected = (Boolean) value;
|
||||
paramRow.setSelected(selected);
|
||||
if (selected) {
|
||||
broker.registerEcuParameterForLogging(paramRow.getEcuParam());
|
||||
broker.registerEcuParameterForLogging(paramRow.getEcuData());
|
||||
} else {
|
||||
broker.deregisterEcuParameterFromLogging(paramRow.getEcuParam());
|
||||
broker.deregisterEcuParameterFromLogging(paramRow.getEcuData());
|
||||
}
|
||||
fireTableRowsUpdated(row, row);
|
||||
}
|
||||
|
@ -66,10 +66,10 @@ public final class ParameterListTableModel extends AbstractTableModel {
|
|||
return getValueAt(0, col).getClass();
|
||||
}
|
||||
|
||||
public synchronized void addParam(EcuParameter ecuParam) {
|
||||
if (!registeredEcuParams.contains(ecuParam)) {
|
||||
paramRowMap.put(ecuParam, new ParameterRow(ecuParam));
|
||||
registeredEcuParams.add(ecuParam);
|
||||
public synchronized void addParam(EcuData ecuData) {
|
||||
if (!registeredEcuData.contains(ecuData)) {
|
||||
paramRowMap.put(ecuData, new ParameterRow(ecuData));
|
||||
registeredEcuData.add(ecuData);
|
||||
fireTableDataChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterRegistrationBroker {
|
||||
void registerEcuParameterForLogging(EcuParameter ecuParam);
|
||||
|
||||
void deregisterEcuParameterFromLogging(EcuParameter ecuParam);
|
||||
void registerEcuParameterForLogging(EcuData ecuData);
|
||||
|
||||
void deregisterEcuParameterFromLogging(EcuData ecuData);
|
||||
|
||||
List<String> listSerialPorts();
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ package enginuity.logger.ui;
|
|||
import enginuity.Settings;
|
||||
import enginuity.logger.LoggerController;
|
||||
import enginuity.logger.LoggerControllerImpl;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
import enginuity.logger.ui.handler.ParameterUpdateHandlerManager;
|
||||
import enginuity.logger.ui.handler.DataUpdateHandlerManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -13,43 +13,43 @@ import java.util.List;
|
|||
|
||||
public final class ParameterRegistrationBrokerImpl implements ParameterRegistrationBroker {
|
||||
private final LoggerController controller;
|
||||
private final ParameterUpdateHandlerManager handlerManager;
|
||||
private final List<EcuParameter> registeredEcuParameters = Collections.synchronizedList(new ArrayList<EcuParameter>());
|
||||
private final DataUpdateHandlerManager handlerManager;
|
||||
private final List<EcuData> registeredEcuParameters = Collections.synchronizedList(new ArrayList<EcuData>());
|
||||
private long loggerStartTime = 0;
|
||||
|
||||
public ParameterRegistrationBrokerImpl(ParameterUpdateHandlerManager handlerManager, Settings settings) {
|
||||
public ParameterRegistrationBrokerImpl(DataUpdateHandlerManager handlerManager, Settings settings) {
|
||||
this.handlerManager = handlerManager;
|
||||
this.controller = new LoggerControllerImpl(settings);
|
||||
}
|
||||
|
||||
public synchronized void registerEcuParameterForLogging(final EcuParameter ecuParam) {
|
||||
if (!registeredEcuParameters.contains(ecuParam)) {
|
||||
public synchronized void registerEcuParameterForLogging(final EcuData ecuData) {
|
||||
if (!registeredEcuParameters.contains(ecuData)) {
|
||||
// register param with handlers
|
||||
handlerManager.registerParam(ecuParam);
|
||||
handlerManager.registerData(ecuData);
|
||||
|
||||
// add logger and setup callback
|
||||
controller.addLogger(ecuParam, new LoggerCallback() {
|
||||
controller.addLogger(ecuData, new LoggerCallback() {
|
||||
public void callback(byte[] value) {
|
||||
// update handlers
|
||||
handlerManager.handleParamUpdate(ecuParam, value, System.currentTimeMillis() - loggerStartTime);
|
||||
handlerManager.handleDataUpdate(ecuData, value, System.currentTimeMillis() - loggerStartTime);
|
||||
}
|
||||
});
|
||||
|
||||
// add to registered parameters list
|
||||
registeredEcuParameters.add(ecuParam);
|
||||
registeredEcuParameters.add(ecuData);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void deregisterEcuParameterFromLogging(EcuParameter ecuParam) {
|
||||
if (registeredEcuParameters.contains(ecuParam)) {
|
||||
public synchronized void deregisterEcuParameterFromLogging(EcuData ecuData) {
|
||||
if (registeredEcuParameters.contains(ecuData)) {
|
||||
// remove logger
|
||||
controller.removeLogger(ecuParam);
|
||||
controller.removeLogger(ecuData);
|
||||
|
||||
// deregister param from handlers
|
||||
handlerManager.deregisterParam(ecuParam);
|
||||
handlerManager.deregisterData(ecuData);
|
||||
|
||||
// remove from registered list
|
||||
registeredEcuParameters.remove(ecuParam);
|
||||
registeredEcuParameters.remove(ecuData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package enginuity.logger.ui;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
public final class ParameterRow {
|
||||
private final EcuParameter ecuParam;
|
||||
private final EcuData ecuData;
|
||||
private boolean selected = false;
|
||||
|
||||
public ParameterRow(EcuParameter ecuParam) {
|
||||
checkNotNull(ecuParam, "ecuParam");
|
||||
this.ecuParam = ecuParam;
|
||||
public ParameterRow(EcuData ecuData) {
|
||||
checkNotNull(ecuData, "ecuData");
|
||||
this.ecuData = ecuData;
|
||||
}
|
||||
|
||||
public EcuParameter getEcuParam() {
|
||||
return ecuParam;
|
||||
public EcuData getEcuData() {
|
||||
return ecuData;
|
||||
}
|
||||
|
||||
public Boolean getSelected() {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
public final class DashboardUpdateHandler implements ParameterUpdateHandler {
|
||||
public final class DashboardUpdateHandler implements DataUpdateHandler {
|
||||
|
||||
public void registerParam(EcuParameter ecuParam) {
|
||||
public void registerData(EcuData ecuData) {
|
||||
}
|
||||
|
||||
public void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp) {
|
||||
public void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp) {
|
||||
}
|
||||
|
||||
public void deregisterParam(EcuParameter ecuParam) {
|
||||
public void deregisterData(EcuData ecuData) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
public interface DataUpdateHandler {
|
||||
|
||||
void registerData(EcuData ecuData);
|
||||
|
||||
void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp);
|
||||
|
||||
void deregisterData(EcuData ecuData);
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
public interface DataUpdateHandlerManager extends DataUpdateHandler {
|
||||
|
||||
void addHandler(DataUpdateHandler handler);
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class DataUpdateHandlerManagerImpl implements DataUpdateHandlerManager {
|
||||
private final List<DataUpdateHandler> handlers = new ArrayList<DataUpdateHandler>();
|
||||
|
||||
public synchronized void addHandler(DataUpdateHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
public synchronized void registerData(EcuData ecuData) {
|
||||
for (DataUpdateHandler handler : handlers) {
|
||||
handler.registerData(ecuData);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp) {
|
||||
for (DataUpdateHandler handler : handlers) {
|
||||
handler.handleDataUpdate(ecuData, value, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void deregisterData(EcuData ecuData) {
|
||||
for (DataUpdateHandler handler : handlers) {
|
||||
handler.deregisterData(ecuData);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +1,81 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.definition.EcuDataConvertor;
|
||||
|
||||
public final class FileUpdateHandler implements ParameterUpdateHandler {
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//TODO: finish log to file: detect start file-logging switch; add header line to log when params change; only process updates when file logging has been started
|
||||
|
||||
public final class FileUpdateHandler implements DataUpdateHandler {
|
||||
private final Settings settings;
|
||||
private final List<EcuData> ecuDatas = new LinkedList<EcuData>();
|
||||
private Line currentLine = new Line(ecuDatas);
|
||||
|
||||
public FileUpdateHandler(Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void registerParam(EcuParameter ecuParam) {
|
||||
public void registerData(EcuData ecuData) {
|
||||
ecuDatas.add(ecuData);
|
||||
currentLine = new Line(ecuDatas);
|
||||
}
|
||||
|
||||
public void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp) {
|
||||
public void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp) {
|
||||
currentLine.updateParamValue(ecuData, value, timestamp);
|
||||
if (currentLine.isFull()) {
|
||||
System.out.println(currentLine.toString());
|
||||
currentLine = new Line(ecuDatas);
|
||||
}
|
||||
}
|
||||
|
||||
public void deregisterParam(EcuParameter ecuParam) {
|
||||
public void deregisterData(EcuData ecuData) {
|
||||
ecuDatas.remove(ecuData);
|
||||
currentLine = new Line(ecuDatas);
|
||||
}
|
||||
|
||||
private static final class Line {
|
||||
private static final char DELIMITER = ',';
|
||||
private final Map<EcuData, byte[]> ecuDataValues;
|
||||
private long lastTimestamp;
|
||||
|
||||
public Line(List<EcuData> ecuParams) {
|
||||
this.ecuDataValues = new LinkedHashMap<EcuData, byte[]>();
|
||||
for (EcuData ecuParam : ecuParams) {
|
||||
ecuDataValues.put(ecuParam, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateParamValue(EcuData ecuData, byte[] value, long timestamp) {
|
||||
if (ecuDataValues.containsKey(ecuData)) {
|
||||
ecuDataValues.put(ecuData, value);
|
||||
lastTimestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
for (EcuData ecuData : ecuDataValues.keySet()) {
|
||||
if (ecuDataValues.get(ecuData) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(lastTimestamp);
|
||||
for (EcuData ecuData : ecuDataValues.keySet()) {
|
||||
byte[] value = ecuDataValues.get(ecuData);
|
||||
EcuDataConvertor convertor = ecuData.getConvertor();
|
||||
buffer.append(DELIMITER).append(convertor.format(convertor.convert(value)));
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import static enginuity.logger.ui.SpringUtilities.makeCompactGrid;
|
||||
import org.jfree.chart.ChartFactory;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
|
@ -15,42 +15,42 @@ import static java.util.Collections.synchronizedMap;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class GraphUpdateHandler implements ParameterUpdateHandler {
|
||||
public final class GraphUpdateHandler implements DataUpdateHandler {
|
||||
private final JPanel graphPanel;
|
||||
private final Map<EcuParameter, ChartPanel> chartMap = synchronizedMap(new HashMap<EcuParameter, ChartPanel>());
|
||||
private final Map<EcuParameter, XYSeries> seriesMap = synchronizedMap(new HashMap<EcuParameter, XYSeries>());
|
||||
private final Map<EcuData, ChartPanel> chartMap = synchronizedMap(new HashMap<EcuData, ChartPanel>());
|
||||
private final Map<EcuData, XYSeries> seriesMap = synchronizedMap(new HashMap<EcuData, XYSeries>());
|
||||
private int loggerCount = 0;
|
||||
|
||||
public GraphUpdateHandler(JPanel graphPanel) {
|
||||
this.graphPanel = graphPanel;
|
||||
}
|
||||
|
||||
public void registerParam(EcuParameter ecuParam) {
|
||||
public void registerData(EcuData ecuData) {
|
||||
// add to charts
|
||||
final XYSeries series = new XYSeries(ecuParam.getName());
|
||||
final XYSeries series = new XYSeries(ecuData.getName());
|
||||
//TODO: Make chart max item count configurable via settings
|
||||
series.setMaximumItemCount(1000);
|
||||
series.setMaximumItemCount(100);
|
||||
final XYDataset xyDataset = new XYSeriesCollection(series);
|
||||
final JFreeChart chart = ChartFactory.createXYLineChart(ecuParam.getName(), "Time (sec)", ecuParam.getName()
|
||||
+ " (" + ecuParam.getConvertor().getUnits() + ")", xyDataset, VERTICAL, false, true, false);
|
||||
final JFreeChart chart = ChartFactory.createXYLineChart(ecuData.getName(), "Time (sec)", ecuData.getName()
|
||||
+ " (" + ecuData.getConvertor().getUnits() + ")", xyDataset, VERTICAL, false, true, false);
|
||||
ChartPanel chartPanel = new ChartPanel(chart, false, true, true, true, true);
|
||||
graphPanel.add(chartPanel);
|
||||
seriesMap.put(ecuParam, series);
|
||||
chartMap.put(ecuParam, chartPanel);
|
||||
seriesMap.put(ecuData, series);
|
||||
chartMap.put(ecuData, chartPanel);
|
||||
makeCompactGrid(graphPanel, ++loggerCount, 1, 10, 10, 20, 20);
|
||||
repaintGraphPanel(2);
|
||||
}
|
||||
|
||||
public void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp) {
|
||||
public void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp) {
|
||||
// update chart
|
||||
XYSeries series = seriesMap.get(ecuParam);
|
||||
series.add(timestamp / 1000.0, ecuParam.getConvertor().convert(value));
|
||||
XYSeries series = seriesMap.get(ecuData);
|
||||
series.add(timestamp / 1000.0, ecuData.getConvertor().convert(value));
|
||||
}
|
||||
|
||||
public void deregisterParam(EcuParameter ecuParam) {
|
||||
public void deregisterData(EcuData ecuData) {
|
||||
// remove from charts
|
||||
graphPanel.remove(chartMap.get(ecuParam));
|
||||
chartMap.remove(ecuParam);
|
||||
graphPanel.remove(chartMap.get(ecuData));
|
||||
chartMap.remove(ecuData);
|
||||
makeCompactGrid(graphPanel, --loggerCount, 1, 10, 10, 20, 20);
|
||||
repaintGraphPanel(1);
|
||||
}
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuData;
|
||||
import enginuity.logger.ui.LoggerDataTableModel;
|
||||
|
||||
public final class LiveDataUpdateHandler implements ParameterUpdateHandler {
|
||||
public final class LiveDataUpdateHandler implements DataUpdateHandler {
|
||||
private final LoggerDataTableModel dataTableModel;
|
||||
|
||||
public LiveDataUpdateHandler(LoggerDataTableModel dataTableModel) {
|
||||
this.dataTableModel = dataTableModel;
|
||||
}
|
||||
|
||||
public void registerParam(EcuParameter ecuParam) {
|
||||
public void registerData(EcuData ecuData) {
|
||||
// add to datatable
|
||||
dataTableModel.addParam(ecuParam);
|
||||
dataTableModel.addParam(ecuData);
|
||||
}
|
||||
|
||||
public void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp) {
|
||||
public void handleDataUpdate(EcuData ecuData, byte[] value, long timestamp) {
|
||||
// update data table
|
||||
dataTableModel.updateParam(ecuParam, value);
|
||||
dataTableModel.updateParam(ecuData, value);
|
||||
}
|
||||
|
||||
public void deregisterParam(EcuParameter ecuParam) {
|
||||
public void deregisterData(EcuData ecuData) {
|
||||
// remove from datatable
|
||||
dataTableModel.removeParam(ecuParam);
|
||||
dataTableModel.removeParam(ecuData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
|
||||
public interface ParameterUpdateHandler {
|
||||
|
||||
void registerParam(EcuParameter ecuParam);
|
||||
|
||||
void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp);
|
||||
|
||||
void deregisterParam(EcuParameter ecuParam);
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
public interface ParameterUpdateHandlerManager extends ParameterUpdateHandler {
|
||||
|
||||
void addHandler(ParameterUpdateHandler handler);
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package enginuity.logger.ui.handler;
|
||||
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ParameterUpdateHandlerManagerImpl implements ParameterUpdateHandlerManager {
|
||||
private final List<ParameterUpdateHandler> handlers = new ArrayList<ParameterUpdateHandler>();
|
||||
|
||||
public synchronized void addHandler(ParameterUpdateHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
public synchronized void registerParam(EcuParameter ecuParam) {
|
||||
for (ParameterUpdateHandler handler : handlers) {
|
||||
handler.registerParam(ecuParam);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void handleParamUpdate(EcuParameter ecuParam, byte[] value, long timestamp) {
|
||||
for (ParameterUpdateHandler handler : handlers) {
|
||||
handler.handleParamUpdate(ecuParam, value, timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void deregisterParam(EcuParameter ecuParam) {
|
||||
for (ParameterUpdateHandler handler : handlers) {
|
||||
handler.deregisterParam(ecuParam);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue