Browse Source

Alpha für 16/C

PulsCounter2
Harald Wolff 5 years ago
parent
commit
0ee2da6a61
  1. 5
      .classpath
  2. 5
      .gitignore
  3. 7
      .settings/org.eclipse.jdt.core.prefs
  4. 0
      postgresql-9.1-901.jdbc4.jar
  5. 10
      src/org/hwo/pulscounter/AbstractPulsCounterApplicationListener.java
  6. 203
      src/org/hwo/pulscounter/ExportSetting.java
  7. 20
      src/org/hwo/pulscounter/NewPulsCounterDevice.java
  8. 305
      src/org/hwo/pulscounter/PulsCounter.java
  9. 182
      src/org/hwo/pulscounter/PulsCounter2Application.java
  10. 10
      src/org/hwo/pulscounter/PulsCounterApplicationListener.java
  11. 211
      src/org/hwo/pulscounter/SnapShot.java
  12. 321
      src/org/hwo/pulscounter/SnapshotManager.java
  13. 32
      src/org/hwo/pulscounter/TriggerType.java
  14. 4
      src/org/hwo/pulscounter/elements/WorkShiftRecord.java
  15. 490
      src/org/hwo/pulscounter/ui/AppSettingsFrame.java
  16. 2
      src/org/hwo/pulscounter/ui/AppSettingsListener.java
  17. 63
      src/org/hwo/pulscounter/ui/BatchRunner.java
  18. 278
      src/org/hwo/pulscounter/ui/ChannelDisplay.java
  19. 8
      src/org/hwo/pulscounter/ui/ChannelDisplayListener.java
  20. 302
      src/org/hwo/pulscounter/ui/CheckWorkshiftRecords.java
  21. 508
      src/org/hwo/pulscounter/ui/DeviceConfiguration.java
  22. 366
      src/org/hwo/pulscounter/ui/DeviceTestFrame.java
  23. 181
      src/org/hwo/pulscounter/ui/ExportFilesFrame.java
  24. 346
      src/org/hwo/pulscounter/ui/ExportSettingsEditorDialog.java
  25. 122
      src/org/hwo/pulscounter/ui/InspectionMainFrame.java
  26. 120
      src/org/hwo/pulscounter/ui/JBitSetter.java
  27. 401
      src/org/hwo/pulscounter/ui/LiveViewFrame.java
  28. 98
      src/org/hwo/pulscounter/ui/MainWindow.java
  29. 913
      src/org/hwo/pulscounter/ui/NewMainWindow.java
  30. 1038
      src/org/hwo/pulscounter/ui/PulsCounterWindow.java
  31. BIN
      src/org/hwo/pulscounter/ui/sym_a_aktiv.png
  32. BIN
      src/org/hwo/pulscounter/ui/sym_a_passiv.png
  33. BIN
      src/org/hwo/pulscounter/ui/sym_e_aktiv.png
  34. BIN
      src/org/hwo/pulscounter/ui/sym_e_passiv.png
  35. BIN
      src/org/hwo/pulscounter/ui/sym_p2_aktiv.png
  36. BIN
      src/org/hwo/pulscounter/ui/sym_p2_passiv.png
  37. BIN
      src/org/hwo/pulscounter/ui/sym_p_aktiv.png
  38. BIN
      src/org/hwo/pulscounter/ui/sym_p_passiv.png

5
.classpath

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo"/>
<classpathentry kind="lib" path="postgresql-9.1-901.jdbc4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.ui"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.servicelink"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.hwo.platform"/>
<classpathentry kind="output" path="bin"/>
</classpath>

5
.gitignore

@ -2,4 +2,7 @@
bin/**
/bin
live.csv
chnames.prop
chnames.prop
*.dat
*.log
*.old

7
.settings/org.eclipse.jdt.core.prefs

@ -1,11 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7

0
postgresql-9.1-901.jdbc4.jar

10
src/org/hwo/pulscounter/AbstractPulsCounterApplicationListener.java

@ -0,0 +1,10 @@
package org.hwo.pulscounter;
public abstract class AbstractPulsCounterApplicationListener implements PulsCounterApplicationListener {
@Override
public void serialPortChanged() {
}
}

203
src/org/hwo/pulscounter/ExportSetting.java

@ -0,0 +1,203 @@
package org.hwo.pulscounter;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import org.hwo.configuration.ConfigurableAttribute;
import org.hwo.configuration.ConfigurableObject;
import org.hwo.csv.CSV;
import org.hwo.csv.CSVRecord;
import org.hwo.interactiveobjects.InteractiveObject;
import org.hwo.interactiveobjects.ObjectEditorUI;
import org.hwo.models.TableMapper.TableColumn;
import org.hwo.pulscounter.ui.ExportSettingsEditorDialog;
@ObjectEditorUI(editor=ExportSettingsEditorDialog.class)
@ConfigurableObject
public class ExportSetting {
@ConfigurableAttribute
private String name;
@ConfigurableAttribute
private TriggerType triggerType;
@ConfigurableAttribute
private Integer triggerSource;
@ConfigurableAttribute
private String fileName;
@ConfigurableAttribute
private String path;
@ConfigurableAttribute
private Boolean extended;
@ConfigurableAttribute
private Boolean autostart;
@ConfigurableAttribute
private Boolean recordDelta;
private SimpleDateFormat dateFormat;
public ExportSetting() {
this.dateFormat = new SimpleDateFormat();
this.name = "unbenannt";
this.path = ".";
this.fileName = "synololog.csv";
this.triggerType = triggerType.ALL;
this.triggerSource = 0;
this.extended = false;
this.autostart = false;
this.recordDelta = false;
}
@TableColumn(label="Benennung",firstColumn=true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@TableColumn(label="Auslöser")
public TriggerType getTriggerType() {
return triggerType;
}
public void setTriggerType(TriggerType triggerType) {
this.triggerType = triggerType;
}
@TableColumn(label="Dateiname")
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
@TableColumn(label="Verzeichnis")
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public Integer getTriggerSource() {
return triggerSource;
}
public void setTriggerSource(Integer triggerSource) {
this.triggerSource = triggerSource;
}
public Boolean getExtended() {
return extended;
}
public void setExtended(Boolean extended) {
this.extended = extended;
}
@TableColumn(label="Autostart",after="Auslöser")
public Boolean getAutostart() {
return autostart;
}
public void setAutostart(Boolean autostart) {
this.autostart = autostart;
}
public Boolean getRecordDelta() {
return recordDelta;
}
public void setRecordDelta(Boolean recordDelta) {
this.recordDelta = recordDelta;
}
private String calculateFileName(String filename,SnapShot ss){
Date d = new Date(((long)ss.getTimestamp())*1000);
Calendar c = Calendar.getInstance();
c.setTime(d);
return filename
.replaceAll("\\%Y", String.format("%04d", new Integer(c.get(Calendar.YEAR))))
.replaceAll("\\%M", String.format("%02d", new Integer(c.get(Calendar.MONTH)+1)))
.replaceAll("\\%D", String.format("%02d", new Integer(c.get(Calendar.DAY_OF_MONTH))));
}
public void export(){
SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManager();
Hashtable<String, CSV> hash = new Hashtable<String, CSV>();
for (int n=0;n<ssm.size();n++){
SnapShot ss = ssm.loadSnapShot(n);
String fn = calculateFileName(fileName, ss);
if ((triggerType==TriggerType.ALL)||(ss.getTriggerType()==triggerType)){
if (triggerSource.equals(-1) || triggerSource.equals(ss.getSource())){
if (!hash.containsKey(fn)){
hash.put(fn, new CSV());
if (extended){
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
"Zeitstempel", "Datum/Zeit", "Trigger", "Quelle",
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
} else {
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
"Datum/Zeit",
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
}
}
hash.get(fn).getRecords().add(ss.getCSVRecord(extended));
}
}
}
for (String fn: hash.keySet()){
if (recordDelta){
CSV csv = hash.get(fn);
if (!csv.getRecords().isEmpty()){
Iterator<CSVRecord> iter = csv.getRecords().iterator();
iter.next();
CSVRecord n = iter.next();
Integer[] vals = new Integer[32];
for (int i=0;i<32;i++){
vals[i] = n.getIntegerValue(extended ? i + 4 : i + 1 );
}
while (iter.hasNext()){
n = iter.next();
for (int i=0;i<32;i++){
Integer v = n.getIntegerValue(extended ? i + 4 : i + 1 );
n.setValue(extended ? i + 4 : i + 1 , v - vals[i]);
vals[i] = v;
}
}
csv.getRecords().remove(1);
}
}
hash.get(fn).saveToFile(new File(path,fn));
}
}
}

20
src/org/hwo/pulscounter/NewPulsCounterDevice.java

@ -17,9 +17,10 @@ import java.util.Random;
import org.hwo.bitfields.BitField;
import org.hwo.io.SerialPort;
import org.hwo.io.SerialPortExeption;
import org.hwo.io.servicelink.ServiceLink;
import org.hwo.io.servicelink.ServiceLinkException;
import org.hwo.io.servicelink.ServiceLinkRequestFailedException;
import org.hwo.io.NewSerialPort.NewSerialPort;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
public class NewPulsCounterDevice implements IPulsCounter {
private ServiceLink serviceLink;
@ -64,7 +65,7 @@ public class NewPulsCounterDevice implements IPulsCounter {
if (!serviceLink.isOpen())
try {
serviceLink.open();
serviceLink.getSerialPort().setTimeout(250);
serviceLink.getSerialPort().setTimeOut(250);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
@ -86,11 +87,11 @@ public class NewPulsCounterDevice implements IPulsCounter {
return new Date();
}
public SerialPort getSerialPort() {
public NewSerialPort getSerialPort() {
return serviceLink.getSerialPort();
}
public void setSerialPort(SerialPort serialPort) throws ServiceLinkException {
public void setSerialPort(NewSerialPort serialPort) throws ServiceLinkException {
if (this.serviceLink == null)
this.serviceLink = new ServiceLink(serialPort);
@ -100,7 +101,7 @@ public class NewPulsCounterDevice implements IPulsCounter {
this.serviceLink.setSerialPort(serialPort);;
this.serviceLink.open();
this.serviceLink.getSerialPort().setTimeout(500);
this.serviceLink.getSerialPort().setTimeOut(500);
/* try {
this.serviceLink.readInt((byte)0, (byte)0, 0);
@ -219,9 +220,8 @@ public class NewPulsCounterDevice implements IPulsCounter {
saveProps();
if ((this.serviceLink == null) || (serviceLink.getSerialPort() == null)) {
SerialPort sport = SerialPort.newInstance();
sport.setPortName(interfaceName);
setSerialPort(sport);
NewSerialPort nsp = new NewSerialPort(interfaceName);
setSerialPort(nsp);
} else {
serviceLink.getSerialPort().setPortName(interfaceName);
}

305
src/org/hwo/pulscounter/PulsCounter.java

@ -1,305 +0,0 @@
package org.hwo.pulscounter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import org.hwo.beacon.Beacon;
import org.hwo.beacon.Beacon.BeaconSender;
import org.hwo.csv.CSV;
import org.hwo.io.SerialPortExeption;
import org.hwo.os.OsDetect;
import org.hwo.os.OsDetect.OsType;
import org.hwo.pulscounter.application.InspectorApplication;
import org.hwo.pulscounter.service.PulsCounterService;
import org.hwo.pulscounter.ui.PulsCounterWindow;
import org.hwo.rpc.json.RPCAdapter;
import org.hwo.rpc.simple.SimpleRPCServer;
import org.hwo.rpc.simple.SimpleRPCService;
public class PulsCounter {
static private Preferences prefs;
public static Preferences getPrefs() {
return prefs;
}
static private PulsCounterService localService;
public static PulsCounterService getLocalService(){
return localService;
}
static private InspectorApplication inspectorApplication;
static public InspectorApplication getInspectorApplication() {
if (inspectorApplication == null)
inspectorApplication = new InspectorApplication();
return inspectorApplication;
}
static String logFile;
static boolean serverMode = false;
static boolean guiMode = true;
static boolean batchMode = false;
static boolean batchConvert = false;
static boolean startLocalService = false;
static String batchFilename = null;
static String networkName = null;
static String batchConvertTarget = null;
static boolean debugMode = false;
public static void main(String args[])
{
File cwd = new File(".");
/* System.err.println("Starting on OS: " + System.getProperty("os.name"));
System.err.println("Current Directory: " + cwd.getAbsolutePath());
System.err.println("Library Path: " + System.getProperty("java.library.path"));
*/
Logger rootLogger = LogManager.getLogManager().getLogger("");
if (rootLogger != null){
rootLogger.setLevel(Level.SEVERE);
}
prefs = Preferences.userRoot();
if (OsDetect.getOperatingSystem() == OsType.LINUX)
{
// System.err.println("Linux erkannt. Patche java.library.path");
// System.setProperty("java.library.path",String.format(".:%s",System.getProperty("java.library.path")));
Field fieldSysPath;
try {
fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" );
fieldSysPath.setAccessible( true );
fieldSysPath.set( null, null );
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.err.println("Library Path: " + System.getProperty("java.library.path"));
}
/* TODO: Load serverMode default from local preferences */
startLocalService = prefs.getBoolean("pulscounter.local.enabled", false);
Iterator<String> options = Arrays.asList(args).iterator();
while (options.hasNext()) {
String no = options.next();
if (no.equals("-s")) {
serverMode = true;
guiMode = false;
} else if (no.equals("-bo")) {
serverMode = false;
startLocalService = false;
} else if (no.equals("-b")) {
batchMode = true;
} else if (no.equals("-c")) {
batchConvert = true;
batchConvertTarget = options.next();
} else if (no.equals("-f")){
batchFilename = options.next();
} else if (no.equals("-n")){
networkName = options.next();
startLocalService = false;
} else if (no.equals("-l")){
logFile = options.next();
} else if (no.equals("-u")){
startLocalService = true;
} else if (no.equals("-d")){
debugMode = true;
}
}
if (logFile != null){
try {
PrintStream logStream = new PrintStream(new FileOutputStream(logFile, true));
System.setErr(logStream);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (batchMode)
guiMode = false;
localService = new PulsCounterService();
if (startLocalService){
localService.start();
}
if (batchMode) {
batchrun();
} else if (guiMode){
PulsCounterWindow window = new PulsCounterWindow();
window.setVisible(true);
}
if (batchConvert) {
batchConvert(batchFilename,batchConvertTarget);
}
}
private static void batchrun(){
if (networkName == null) {
// TODO: Use UUID from preferences to select network service
} else {
Beacon clientBeacon = new Beacon(44556);
clientBeacon.setClientOnly(true);
clientBeacon.start();
for (int i=0;i<120;i++){
if (clientBeacon.getSenderByName(networkName) != null)
break;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
BeaconSender sender = clientBeacon.getSenderByName(networkName);
if (sender == null) {
System.err.println("Networknode: " + networkName + " is offline.");
clientBeacon.exit();
return;
}
IPulsCounter ipc = createProxyFromBeaconSender(sender);
Date d = new Date();
String time = String.format("%04d-%02d-%02d %02d:%02d:%02d",d.getYear()+1900,d.getMonth()+1,d.getDate(),d.getHours(),d.getMinutes(),d.getSeconds());
try {
CounterChannel[] channels = new CounterChannel[ ipc.getChannels() ];
int[] values = ipc.getChannelCounters();
try {
File csvfile = new File(batchFilename);
boolean newfile = !csvfile.exists();
BufferedWriter writer = new BufferedWriter(new FileWriter(csvfile,true));
if (newfile){
writer.write("Zeitpunkt");
for (int i=0;i<values.length;i++){
writer.write("\t");
writer.write(ipc.getChannelName(i));
}
writer.write("\r\n");
}
writer.write(time + "\t");
for (int i=0;i<values.length;i++){
if (i>0)
writer.write("\t");
writer.write(String.format("%d",values[i]));
}
writer.write("\r\n");
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (SerialPortExeption sex){
System.err.println(sex);
sex.printStackTrace();
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
clientBeacon.exit();
}
}
public static void batchConvert(String source,String target){
CSV csv = new CSV();
csv.setSeparator('\t');
csv.readFromFile(source);
for (int i=csv.getRecords().size()-1;i>1;--i){
for (int j=1;j<csv.getRecord(i).size();j++){
int last = csv.getRecord(i-1).getIntegerValue(j);
int actual = csv.getRecord(i).getIntegerValue(j);
csv.getRecord(i).setValue(j, actual - last);
}
}
csv.getRecords().remove(1);
csv.saveToFile(batchConvertTarget);
}
public static IPulsCounter createProxyFromBeaconSender(BeaconSender sender){
int port = Integer.decode(sender.getProperties().getProperty("rpc.simple.port"));
SimpleRPCService service = new SimpleRPCService(sender.getInetAddress(), port);
IPulsCounter ipc = service.createProxy(IPulsCounter.class);
return ipc;
}
}

182
src/org/hwo/pulscounter/PulsCounter2Application.java

@ -1,13 +1,23 @@
package org.hwo.pulscounter;
import java.io.FileNotFoundException;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.hwo.configuration.ConfigurableObjects;
import org.hwo.io.SerialPort;
import org.hwo.io.servicelink.ServiceLink;
import org.hwo.io.NewSerialPort.NewSerialPort;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkListener;
import org.hwo.tasklet.TaskletManager;
import org.hwo.pulscounter.SnapshotManager.Notification;
import org.hwo.pulscounter.ui.AppSettingsListener;
import org.hwo.scheduler.Scheduler;
public class PulsCounter2Application {
public class PulsCounter2Application implements ServiceLinkListener{
static PulsCounter2Application _application;
public static PulsCounter2Application getApplication(){
@ -17,14 +27,42 @@ public class PulsCounter2Application {
return _application;
}
SerialPort serialPort;
ServiceLink serviceLink;
private NewSerialPort serialPort;
private ServiceLink serviceLink;
List<AppSettingsListener> appSettingsListeners;
private List<AppSettingsListener> appSettingsListeners;
private List<PulsCounterApplicationListener> applicationListeners;
public PulsCounter2Application(){
private boolean snapshotLock;
private Vector<String> unseenMessages;
private SnapshotManager snapshotManager;
private List<ExportSetting> exportSettings;
private Scheduler scheduler;
public PulsCounter2Application() {
appSettingsListeners = new LinkedList<AppSettingsListener>();
applicationListeners = new LinkedList<PulsCounterApplicationListener>();
unseenMessages = new Vector<String>();
exportSettings = new LinkedList<ExportSetting>();
scheduler = new Scheduler();
loadPrefs();
try {
snapshotManager = new SnapshotManager();
snapshotManager.notify(Notification.INITIALIZE);
} catch (FileNotFoundException e){
e.printStackTrace();
}
}
public void addAppSettingsListener(AppSettingsListener listener){
appSettingsListeners.add(listener);
@ -33,31 +71,78 @@ public class PulsCounter2Application {
appSettingsListeners.remove(listener);
}
private void fireServiceLinkChanged(){
public void addPulsCounterApplicationListener(PulsCounterApplicationListener listener){
applicationListeners.add(listener);
}
public void removePulsCounterApplicationListener(PulsCounterApplicationListener listener){
applicationListeners.remove(listener);
}
public void fireServiceLinkChanged(){
for (AppSettingsListener l: appSettingsListeners){
l.ServiceLinkChanged(serviceLink);
}
}
public synchronized SerialPort getSerialPort() {
public void fireSerialPortChanged(){
for (PulsCounterApplicationListener listener: applicationListeners){
listener.serialPortChanged();
}
}
public void fireConnectionStateChanged(){
fireConnectionStateChanged(getServiceLink().isOpen());
}
public void fireConnectionStateChanged(Boolean connected){
for (PulsCounterApplicationListener listener: applicationListeners){
listener.connectionStateChanged(connected);
}
}
public void message(String message){
if (applicationListeners.size() == 0){
unseenMessages.addElement(message);
} else {
while (!unseenMessages.isEmpty()){
String msg = unseenMessages.remove(0);
for (PulsCounterApplicationListener listener: applicationListeners){
listener.messageArrived(msg);
}
}
for (PulsCounterApplicationListener listener: applicationListeners){
listener.messageArrived(message);
}
};
}
public synchronized NewSerialPort getSerialPort() {
if (serialPort == null){
serialPort = new NewSerialPort("COM1:");
}
return serialPort;
}
public synchronized void setSerialPort(SerialPort serialPort) {
public synchronized void setSerialPort(NewSerialPort serialPort) {
if (serviceLink != null){
serviceLink.close();
serviceLink = null;
}
this.serialPort = serialPort;
getServiceLink();
fireServiceLinkChanged();
fireSerialPortChanged();
}
public synchronized ServiceLink getServiceLink() {
if (serviceLink == null){
if (serialPort != null){
serviceLink = new ServiceLink(serialPort);
serviceLink.getSerialPort().setTimeout(200);
}
serviceLink = new ServiceLink(getSerialPort());
serviceLink.getSerialPort().setTimeOut(200);
serviceLink.addServiceLinkListener(this);
}
return serviceLink;
}
@ -70,6 +155,77 @@ public class PulsCounter2Application {
fireServiceLinkChanged();
}
private Preferences getPreferencesNode(){
return Preferences.userNodeForPackage(getClass());
}
public void savePrefs(){
Preferences prefs = getPreferencesNode();
if (serialPort != null)
prefs.put("io.port", serialPort.getPortName());
System.out.println(String.format("savePrefs(): %d exportSettings werden gesichert.", exportSettings.size()));
if (exportSettings.size()>0)
{
for (int n=0;n<exportSettings.size();n++){
prefs.put(String.format("export.configuration.%d", n), ConfigurableObjects.getConfiguration(exportSettings.get(n)));
}
prefs.putInt("export.configurations", exportSettings.size());
};
try {
prefs.flush();
} catch (BackingStoreException e)
{
e.printStackTrace();
}
}
private void loadPrefs(){
Preferences prefs = getPreferencesNode();
String sn = prefs.get("io.port", null);
if (sn != null){
NewSerialPort nsp = new NewSerialPort(sn);
setSerialPort(nsp);
}
exportSettings.clear();
int nESC = prefs.getInt("export.configurations", 0);
for (int n=0;n<nESC;n++){
ExportSetting es = new ExportSetting();
ConfigurableObjects.setConfiguration(es, prefs.get(String.format("export.configuration.%d", n), ""));
exportSettings.add(es);
}
System.out.println(String.format("loadPrefs(): %d exportSettings geladen.", nESC));
}
@Override
public void connectionStateChanged(Boolean connected) {
fireConnectionStateChanged(connected);
}
public SnapshotManager getSnapshotManager() {
return snapshotManager;
}
public List<ExportSetting> getExportSettings() {
return exportSettings;
}
public void shutdown(){
System.err.println("Shutting down...");
this.scheduler.shutdown();
this.snapshotManager.doShutdown();
TaskletManager.instance().shutdown();
this.getServiceLink().close();
}
}

10
src/org/hwo/pulscounter/PulsCounterApplicationListener.java

@ -0,0 +1,10 @@
package org.hwo.pulscounter;
public interface PulsCounterApplicationListener {
void serialPortChanged();
void connectionStateChanged(Boolean connected);
void messageArrived(String message);
}

211
src/org/hwo/pulscounter/SnapShot.java

@ -0,0 +1,211 @@
package org.hwo.pulscounter;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import org.hwo.csv.CSVRecord;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkException;
public class SnapShot {
Integer timestamp;
Integer field0;
Integer[] values;
Integer[] analog;
Integer inputmask,
outputmask,
pullupmask,
invertmask,
triggermask;
public SnapShot(){
this.values = new Integer[32];
this.analog = new Integer[8];
}
public SnapShot(byte[] bytes){
this.values = new Integer[32];
this.analog = new Integer[8];
fromBytes(bytes);
}
public void setField0(Integer field0) {
this.field0 = field0;
}
public Integer getField0() {
return field0;
}
public void setTimestamp(Integer timestamp) {
this.timestamp = timestamp;
}
public Integer getTimestamp() {
return timestamp;
}
public Integer getInputmask() {
return inputmask;
}
public void setInputmask(Integer inputmask) {
this.inputmask = inputmask;
}
public Integer getOutputmask() {
return outputmask;
}
public void setOutputmask(Integer outputmask) {
this.outputmask = outputmask;
}
public Integer getPullupmask() {
return pullupmask;
}
public void setPullupmask(Integer pullupmask) {
this.pullupmask = pullupmask;
}
public Integer getInvertmask() {
return invertmask;
}
public void setInvertmask(Integer invertmask) {
this.invertmask = invertmask;
}
public Integer getTriggermask() {
return triggermask;
}
public void setTriggermask(Integer triggermask) {
this.triggermask = triggermask;
}
public void setValue(Integer ch,Integer value){
if ((ch >= 0) && (ch<32)){
this.values[ch] = value;
}
}
public Integer getValue(Integer ch){
if ((ch >= 0) && (ch<32)){
return this.values[ch];
}
return null;
}
public Integer[] getValues(){
return Arrays.copyOf(this.values, this.values.length);
}
public void setAnalog(Integer ch,Integer value){
if ((ch >= 0) && (ch<8)){
this.analog[ch] = value;
}
}
public Integer getAnalog(Integer ch){
if ((ch >= 0) && (ch<8)){
return this.analog[ch];
}
return null;
}
public Integer[] getAnalog(){
return Arrays.copyOf(this.analog, this.analog.length);
}
public long getHashCode(){
return ((long)timestamp << 32) | field0;
}
public TriggerType getTriggerType(){
return TriggerType.get(this.field0 & 0xff);
}
public int getSource(){
return (field0 >> 8) & 0xff;
}
public byte[] toBytes(){
byte[] buffer = new byte[256];
ByteBuffer bb = ByteBuffer.wrap(buffer);
Arrays.fill(buffer, (byte)0);
bb.putInt(0, timestamp);
bb.putInt(4, field0);
bb.putInt(8, inputmask);
bb.putInt(12, outputmask);
bb.putInt(16, pullupmask);
bb.putInt(20, invertmask);
bb.putInt(24, triggermask);
for (int i=0;i<32;i++){
bb.putInt(32 + (i<<2), values[i]);
}
for (int i=0;i<8;i++){
bb.putInt(160 + (i<<2), analog[i]);
}
return buffer;
}
private void fromBytes(byte[] bytes){
ByteBuffer bb = ByteBuffer.wrap(bytes);
timestamp = bb.getInt(0);
field0 = bb.getInt(4);
inputmask = bb.getInt(8);
outputmask = bb.getInt(12);
pullupmask = bb.getInt(16);
invertmask = bb.getInt(20);
triggermask = bb.getInt(24);
for (int i=0;i<32;i++){
values[i] = bb.getInt(32 + (i<<2));
}
for (int i=0;i<8;i++){
analog[i] = bb.getInt(160 + (i<<2));
}
}
public CSVRecord getCSVRecord(){
return getCSVRecord(false);
}
public CSVRecord getCSVRecord(Boolean extended){
CSVRecord record = new CSVRecord();
if (extended)
record.appendValue(timestamp);
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
record.appendValue(df.format(new Date(((long)timestamp)*1000)));
if (extended){
record.appendValue("TRIGGER");
record.appendValue("QUELLE");
}
for (int n=0;n<32;n++)
record.appendValue( values[n]);
for (int n=0;n<8;n++)
record.appendValue( analog[n]);
return record;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("SnapShot(");
sb.append(this.timestamp);
sb.append(":");
for (int i=0;i<32;i++){
if (i>0)
sb.append(",");
sb.append(this.values[i]);
}
sb.append(")");
return sb.toString();
}
}

321
src/org/hwo/pulscounter/SnapshotManager.java

@ -0,0 +1,321 @@
package org.hwo.pulscounter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.util.Hashtable;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
import org.hwo.tasklet.Tasklet;
import org.hwo.tasklet.TaskletManager;
public class SnapshotManager {
public enum Notification { INITIALIZE, SHUTDOWN, SYNC, FULLSYNC };
private RandomAccessFile file;
private Hashtable<Long,Integer> hashList;
private Integer lastNewest,
snapshotSize;
public SnapshotManager() throws FileNotFoundException {
this.file = new RandomAccessFile("snapshots.dat", "rws");
this.initialize();
}
public SnapshotManager(File file) throws FileNotFoundException {
this.file = new RandomAccessFile(file, "rws");
this.initialize();
}
private synchronized void initialize(){
hashList = new Hashtable<Long, Integer>();
}
private PulsCounter2Application application(){
return PulsCounter2Application.getApplication();
}
public synchronized void notify(Notification notification){
switch (notification){
case INITIALIZE:
TaskletManager.instance().enqueue(new Tasklet("SnapShot Manager initialisieren") {
@Override
public void run() {
doInitialize();
}
});
break;
case SHUTDOWN:
doShutdown();
return;
case FULLSYNC:
TaskletManager.instance().enqueue(new Tasklet("Volle Synchronisation") {
@Override
public void run() {
doFullSync();
}
});
break;
case SYNC:
TaskletManager.instance().enqueue(new Tasklet("Schnelle Synchronisation") {
@Override
public void run() {
doSync();
}
});
break;
}
}
public synchronized void doInitialize(){
try {
byte[] buffer = new byte[256];
ByteBuffer bb = ByteBuffer.wrap(buffer);
Integer ind = 0;
application().message("SnapShotManager: Initialisieren");
hashList.clear();
file.seek(0);
while (file.read(buffer)==256){
Integer timestamp,field0;
Long hash;
timestamp = bb.getInt(0);
field0 = bb.getInt(4);
hash = ((long)timestamp << 32) | field0;
hashList.put(hash, ind++);
}
application().message(String.format("SnapShotManager: %d SnapShots lokal", hashList.size()));
} catch (Exception e){
e.printStackTrace();
application().message("SnapShotManager meldet Fehler: " + e.toString());
}
}
public synchronized void doShutdown(){
}
public synchronized void doFullSync(){
Integer ind_oldest,ind_newest,ind;
int n = 0;
application().message("SnapShotManager: Beginne volle synchronisation");
try {
try {
snapshotSize = application().getServiceLink().readInt(13, 0, 0x0582);
} catch (ServiceLinkRequestFailedException e){
snapshotSize = 512;
}
ind_oldest = application().getServiceLink().readInt(13, 0, 0x0580);
ind_newest = application().getServiceLink().readInt(13, 0, 0x0581);
lastNewest = ind_newest;
System.out.println(String.format("ind_oldest: %d", ind_oldest));
System.out.println(String.format("ind_newest: %d", ind_newest));
ind = ind_oldest;
do {
TaskletManager.instance().setProgress(String.format("%d / %d", n++, snapshotSize));
Integer id;
try {
application().getServiceLink().writeInt(13, 0, 0x0500, ind);
id = application().getServiceLink().readInt(13, 0, 0x0500);
if (!id.equals(ind)){
System.out.println(String.format("bus_snapshot_id: %d != %d",ind,id));
} else {
Integer ts,f0;
ts = application().getServiceLink().readInt(13, 0, 0x0501);
f0 = application().getServiceLink().readInt(13, 0, 0x0502);
Long hash = ((long)ts<<32) | f0;
if (!hashList.containsKey(hash)){
SnapShot snap = snapshotFromDevice(ind);
if (snap != null){
Integer find = snapshotToFile(snap);
if (find != -1){
hashList.put(snap.getHashCode(), find);
} else {
application().message("Snapshot konnte nicht gespeichert werden!");
}
};
};
};
if (ind.equals(ind_newest))
break;
} catch (ServiceLinkRequestFailedException failed){
failed.printStackTrace();
};
ind++;
if (ind > snapshotSize){
ind = 0;
}
} while (!ind.equals(ind_oldest));
} catch (Exception e){
e.printStackTrace();
}
application().message(String.format("SnapShotManager: %d bekannte Snapshots nach FullSync", hashList.size()));
}
private synchronized void doSync(){
Integer ind_oldest,ind_newest,ind;
int n,c;
try {
ind_newest = application().getServiceLink().readInt(13, 0, 0x0581);
if (ind_newest == lastNewest)
return;
ind = lastNewest;
c = ind_newest - lastNewest;
if (c < 0)
c+=snapshotSize;
n = 0;
if (c == 0){
return;
}
do {
TaskletManager.instance().setProgress(String.format("%d / %d", n,c));
ind ++;
ind &= 0x1FF;
n++;
SnapShot snap = snapshotFromDevice(ind);
if (snap != null){
Integer ind_file = snapshotToFile(snap);
hashList.put(snap.getHashCode(), ind_file);
}
} while (!ind.equals(ind_newest));
lastNewest = ind_newest;
application().message(String.format("%d neue Snapshots", n));
} catch (ServiceLinkRequestFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceLinkException e) {
e.printStackTrace();
}
}
public synchronized SnapShot loadSnapShot(int ind){
byte[] bytes = new byte[256];
try {
file.seek(ind * 256);
file.read(bytes);
return new SnapShot(bytes);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public synchronized Integer size(){
try {
return ((int)(file.length())/256);
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
private synchronized Integer snapshotToFile(SnapShot snap){
Long find;
try {
find = file.length()/256;
file.seek(find * 256);
file.write(snap.toBytes());
return find.intValue();
} catch (IOException e) {
e.printStackTrace();
return -1;
}
}
private SnapShot snapshotFromDevice(Integer ind){
SnapShot ss = new SnapShot();
Integer id;
try {
application().getServiceLink().writeInt(13, 0, 0x0500, ind);
id = application().getServiceLink().readInt(13, 0, 0x0500);
if (!id.equals(ind)){
System.out.println(String.format("bus_snapshot_id: %d != %d",ind,id));
return null;
};
ss.setTimestamp( application().getServiceLink().readInt(13, 0, 0x0501));
ss.setField0( application().getServiceLink().readInt(13, 0, 0x0502));
ss.setInputmask( application().getServiceLink().readInt(13, 0, 0x0503));
ss.setOutputmask( application().getServiceLink().readInt(13, 0, 0x0504));
ss.setPullupmask( application().getServiceLink().readInt(13, 0, 0x0505));
ss.setInvertmask( application().getServiceLink().readInt(13, 0, 0x0506));
ss.setTriggermask( application().getServiceLink().readInt(13, 0, 0x0507));
for (int i=0;i<32;i++){
ss.setValue(i, application().getServiceLink().readInt(13, 0, 0x0510 + i));
}
for (int i=0;i<8;i++){
ss.setAnalog(i, application().getServiceLink().readInt(13, 0, 0x0508 + i));
}
} catch (Exception e){
e.printStackTrace();
return null;
}
System.out.print(String.format("Snapshot from Device: %s\n", ss.toString()));
return ss;
}
}

32
src/org/hwo/pulscounter/TriggerType.java

@ -0,0 +1,32 @@
package org.hwo.pulscounter;
public enum TriggerType {
Intervall(1),Trigger(2),Timer(4),Manual(8),ALL(-1),UNKOWN(-2);
TriggerType(int n){
this.n = n;
}
public static TriggerType get(int n){
switch (n){
case 1:
return TriggerType.Intervall;
case 2:
return TriggerType.Trigger;
case 4:
return TriggerType.Timer;
case 8:
return TriggerType.Manual;
default:
return TriggerType.UNKOWN;
}
}
Integer n;
public Integer getValue(){
return this.n;
}
}

4
src/org/hwo/pulscounter/elements/WorkShiftRecord.java

@ -10,7 +10,6 @@ import java.util.List;
import org.hwo.datetime.Date;
import org.hwo.datetime.DateTime;
import org.hwo.pulscounter.PulsCounter;
public class WorkShiftRecord {
@ -86,7 +85,7 @@ public class WorkShiftRecord {
}
void loadRecords(){
try {
/* try {
PreparedStatement stat = PulsCounter.getInspectorApplication().getConnection().prepareStatement("SELECT tstamp,channel,chvalue FROM rawvalues WHERE tstamp >= ? AND tstamp < ? ORDER BY channel,tstamp");
stat.setTimestamp(1, workShift.getShiftBegins(date).getTimeStamp());
@ -119,6 +118,7 @@ public class WorkShiftRecord {
} catch (SQLException e) {
e.printStackTrace();
}
*/
}
public Integer[] getChannels(){

490
src/org/hwo/pulscounter/ui/AppSettingsFrame.java

@ -1,8 +1,10 @@
package org.hwo.pulscounter.ui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.EventQueue;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
@ -21,27 +23,65 @@ import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JButton;
import org.hwo.csv.CSV;
import org.hwo.io.SerialPort;
import org.hwo.io.SerialPortChooser;
import org.hwo.io.NewSerialPort.NewSerialPort;
import org.hwo.pulscounter.PulsCounter2Application;
import org.hwo.pulscounter.SnapShot;
import org.hwo.pulscounter.SnapshotManager;
import org.hwo.servicelink.ServiceLink;
import org.hwo.servicelink.ServiceLinkException;
import org.hwo.servicelink.ServiceLinkRequestFailedException;
import org.hwo.ui.dialog.SerialPortChooser;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.ActionEvent;
import java.awt.Dialog.ModalityType;
import javax.swing.border.TitledBorder;
import javax.swing.JSpinner;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
public class AppSettingsFrame extends JFrame {
public class AppSettingsFrame extends JDialog {
private JPanel contentPane;
private JTextField tfInterface;
private SerialPort selectedSerialPort;
private NewSerialPort selectedSerialPort,formerSerialPort;
private JTextField timeComputer;
private JTextField timeSynololog;
private JSpinner spTrimm;
private Timer timer;
private Calendar calendar = Calendar.getInstance();
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private JTabbedPane tabbedPane;
private JPanel debugPanel;
private JLabel lHeapDec;
private JLabel lHeapHex;
private JLabel lSStackDec;
private JLabel lSStackHex;
private JEditorPane msgExc;
/**
* Create the frame.
*/
public AppSettingsFrame() {
setModalityType(ModalityType.APPLICATION_MODAL);
setModal(true);
setTitle("Einstellungen");
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 603, 447);
contentPane = new JPanel();
@ -49,7 +89,7 @@ public class AppSettingsFrame extends JFrame {
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
contentPane.add(tabbedPane, BorderLayout.CENTER