Skip to content

Commit

Permalink
Initial commit for ERLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
maxha651 committed Apr 22, 2015
1 parent 8a5cfc7 commit dc4961f
Show file tree
Hide file tree
Showing 31 changed files with 1,928 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clients/ERLogger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IDEA stuff
.idea/
*.iws
workspace.xml
tasks.xml

# Java stuff
*.class

# Binaries
out/
13 changes: 13 additions & 0 deletions clients/ERLogger/ERLogger.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Libs" level="project" />
</component>
</module>

11 changes: 11 additions & 0 deletions clients/ERLogger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ERLogger #

ELiTH Racing logging software

## History ##
- 2013/2014
Development began by Jakob Lövhall. Resulted in a more or less complete logging and visualisation solution.
- 2014/2015
Integrated in the yamsLog project by Max Halldén. Previous graphing solution was scrapped in favour of JFreeChart.


16 changes: 16 additions & 0 deletions clients/ERLogger/src/common/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package common;

import dataSource.Loader;
import dataSource.MetaLoader;
import dataSource.ProtobufLoader;

/**
* Created by max on 2014-11-17.
*/
public class Config {
public static String SERVER_HOST = "localhost";
public static int SERVER_PORT = 2001;
public static final Loader DATA_LOADER = new ProtobufLoader();
public static final MetaLoader META_LOADER = (MetaLoader) DATA_LOADER;
public static final String UNKNOWN_SENSOR_NAME = "Unknown";
}
199 changes: 199 additions & 0 deletions clients/ERLogger/src/common/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
package common;

import dataSource.Loader;
import org.jfree.data.UnknownKeyException;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created with IntelliJ IDEA.
* User: Jakob lövhall
* Date: 2013-10-01
* Time: 17:09
*
* Data API. Singleton.
*/

public class Data {

private static Data _mySelf = null;
private float _currentTime;
private List<DataListener> _listeners;
private ERDataField[] _cur = new ERDataField[0]; // used for the serialization of the data.
private Map<String, XYSeriesCollection> xySeriesCollectionMap = new HashMap<>();

/**
* singleton getter for this object to make sure that the same configuration is use throe out the program.
* @return a single (all ways the same) instance of this class
*/
public static Data getInstance(){
if(_mySelf == null)
_mySelf = new Data();

return _mySelf;
}

private Data() {
_currentTime = 0;

_listeners = new ArrayList<>();
}

/**
* get a new set of data
* @param newDataFields the new data
*/
public void setNewDataFields(ERDataField[] newDataFields){
_cur = newDataFields;
}

public List<String> getSensorNames() {
return Config.META_LOADER.getSensorNames();
}

public List<String> getAttributeNames(String sensor) {
return Config.META_LOADER.getAttributeNames(sensor);
}

public List<String> getProjectNames() {
return Config.META_LOADER.getProjectNames();
}

public String getCurrentProject() {
return Config.META_LOADER.getCurrentProject();
}

public void setCurrentProject(String name) {
Config.META_LOADER.changeProject(name);
}

/**
* @return a string with sensor names and converted values
*/
public String toString(){
StringBuilder sb=new StringBuilder();

for(ERDataField field : _cur){
sb.append(field.getSensor());
sb.append(" ");
sb.append(field.getValue());
sb.append(" ");
}
sb.append("\n");
return sb.toString();
}

public XYSeriesCollection getXySeriesCollection(ERSensorConfig[] sensorConf)
{
XYSeriesCollection newCollection = new XYSeriesCollection();
for (ERSensorConfig conf : sensorConf) {
XYSeriesCollection coll = getXySeriesCollection(conf);
for (int i = 0; i < coll.getSeriesCount(); ++i) {
coll.addSeries(coll.getSeries(i));
}
}

return newCollection;
}

public XYSeriesCollection getXySeriesCollection(ERSensorConfig sensorConf)
{
XYSeriesCollection newCollection = new XYSeriesCollection();
if (!xySeriesCollectionMap.containsKey(sensorConf.sensor)) {
xySeriesCollectionMap.put(sensorConf.sensor, new XYSeriesCollection());
}
XYSeriesCollection seriesCollection = xySeriesCollectionMap.get(sensorConf.sensor);
for (String attr : sensorConf) {
XYSeries xySeries;
int idx = seriesCollection.getSeriesIndex(attr);
if (idx == -1) {
// Couldn't find
xySeries = new XYSeries(attr);
seriesCollection.addSeries(xySeries);
}
else {
xySeries = seriesCollection.getSeries(idx);
}
newCollection.addSeries(xySeries);
}
return newCollection;
}

@Deprecated
public XYSeriesCollection getXySeriesCollection(String sensor) {
if (!xySeriesCollectionMap.containsKey(sensor)) {
xySeriesCollectionMap.put(sensor, new XYSeriesCollection());
}
return xySeriesCollectionMap.get(sensor);
}

public void setCurrentTime(float time){
_currentTime = time;
}

// TODO Get from data instead ( should be first ? )
public float getCurrentTime(){
return _currentTime;
}

public void readInput(){
if(Config.DATA_LOADER == null){ return; }

ERDataField[] _latestData = Config.DATA_LOADER.readPackage();

if(_latestData != null){
for (ERDataField dataField : _latestData) {
addERDataField(_mySelf.getCurrentTime(), dataField, getXySeriesCollection(dataField.getSensor()));
}
_mySelf.setNewDataFields(_latestData);
notifyListeners();
}
}

public void purgeData() {
_cur = null;
xySeriesCollectionMap.clear();
}

public void addListener(DataListener d){
_listeners.add(d);
}

public void removeListener(DataListener d){
_listeners.remove(d);
}

private void notifyListeners(){
for(DataListener d : _listeners)
d.dataUpdated(Data.getInstance());
}

private void addERDataField(double time, ERDataField dataField, XYSeriesCollection collection) {
if (dataField != null) {
XYSeries series;
try {
series = collection.getSeries(dataField.getAttribute());
} catch (UnknownKeyException e) {
if (dataField.getAttribute().equals("time")) {
/* FIXME: This only works since it's the first value */
if (dataField.getValue() < getCurrentTime()) {
/* Time has been reset, remove old data */
purgeData();
}
setCurrentTime(dataField.getValue());
return;
}
series = new XYSeries(dataField.getAttribute());
collection.addSeries(series);
}
if (series != null) {
series.add(time, dataField.getValue());
}
}
}
}
11 changes: 11 additions & 0 deletions clients/ERLogger/src/common/DataListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package common;

/**
* Created with IntelliJ IDEA.
* User: liten
* Date: 2013-10-01
* Time: 16:49
*/
public interface DataListener {
void dataUpdated(Data data);
}
39 changes: 39 additions & 0 deletions clients/ERLogger/src/common/ERDataField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package common;

/**
* Used for passing data around.
*
* @author jonasbromo
* edited by jakob lövhall
*/
public class ERDataField {
private float value = 0;

private final String _attribute;
private final String _sensor;

public ERDataField(String sensor, String attribute) {
_sensor = sensor;
_attribute = attribute;
}

public void setValue(short n) {
value = n;
}

public void setValue(float n) {
value = n;
}

public float getValue() {
return value;
}

public String getSensor() {
return _sensor;
}

public String getAttribute() {
return _attribute;
}
}
67 changes: 67 additions & 0 deletions clients/ERLogger/src/common/ERLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package common;

import gui.ERLoggerFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
*
* @author jonasbromo
* edited by Jakob lövhall
*/
public class ERLogger implements ActionListener {

private Timer timer;

public ERLogger() {
int delay=100;

// Make sure Data singleton is created
Data.getInstance();
new ERLoggerFrame();

timer = new Timer(delay, this);
timer.start();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException |
IllegalAccessException | UnsupportedLookAndFeelException ex) {
/*java.util.logging.Logger.getLogger(ERJFrame.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);*/
}

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ERLogger();
}
});
}

/**
* Timer action. Read new input.
*/
@Override
public void actionPerformed(ActionEvent ae) {
Data.getInstance().readInput();
}
}
Loading

0 comments on commit dc4961f

Please sign in to comment.