Compare commits
22 Commits
Author | SHA1 | Date |
---|---|---|
Harald Christian Joachim Wolff | 098199123a | |
Harald Wolff | c0286e6a2e | |
Harald Christian Joachim Wolff | a3e32ad3e5 | |
Harald Christian Joachim Wolff | 630d79ac88 | |
Harald Wolff | beb88f1b8d | |
Harald Wolff | 4624fa0903 | |
Harald Wolff | 4332bb8a14 | |
Harald Wolff | a7e43ec0b4 | |
Harald Wolff | ccf6e4d9f7 | |
Harald Wolff | 52cac8e5d9 | |
Harald Wolff | 756f0f2d4d | |
Harald Wolff | 88c7073dcb | |
Harald Wolff | 4a1bdab688 | |
Harald Wolff | 40ef4b06f2 | |
Harald Wolff | 0582ec77e6 | |
Harald Wolff | 84e912b73e | |
haraldwolff | 246955f622 | |
haraldwolff | 610b7637f1 | |
haraldwolff | ce2d831fa2 | |
haraldwolff | e903133b95 | |
Harald Wolff | 94877bb85f | |
Harald Wolff | 876db0c37b |
|
@ -1,11 +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.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<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="lib" path="hsqldb.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -6,3 +6,5 @@ chnames.prop
|
|||
*.dat
|
||||
*.log
|
||||
*.old
|
||||
*.cfg
|
||||
synololog-hsql.*
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
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.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
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.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: org.hwo.pulscounter.Application
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>missing translations</comment>
|
||||
<entry key="tooltip.synololog.einstellen">tooltip.synololog.einstellen</entry>
|
||||
<entry key="tooltip.export.list">tooltip.export.list</entry>
|
||||
<entry key="Zähler #31">Zähler #31</entry>
|
||||
<entry key="Zähler #30">Zähler #30</entry>
|
||||
<entry key="Export Einstellungen...">Export Einstellungen...</entry>
|
||||
<entry key="Export löschen">Export löschen</entry>
|
||||
<entry key="Anschlusseinstellungen">Anschlusseinstellungen</entry>
|
||||
<entry key="tooltip.daten.exportieren"><html>\n<b>Daten exportieren</b><br/>\n<br/>\nExport definitionen bearbeiten und ausführen.<br/>\nHiermit können die Aufzeichnungsdaten in Textdateien exportiert werden.<br/>\n</html></entry>
|
||||
<entry key="Gerät">Gerät</entry>
|
||||
<entry key="tooltip.export.run">tooltip.export.run</entry>
|
||||
<entry key="Einstellungen">Einstellungen</entry>
|
||||
<entry key="Zeitstempel">Zeitstempel</entry>
|
||||
<entry key="Zähler #29">Zähler #29</entry>
|
||||
<entry key="Zähler #28">Zähler #28</entry>
|
||||
<entry key="Zähler #27">Zähler #27</entry>
|
||||
<entry key="Zähler #26">Zähler #26</entry>
|
||||
<entry key="Zähler #25">Zähler #25</entry>
|
||||
<entry key="Zähler #24">Zähler #24</entry>
|
||||
<entry key="Automatiklauf">Automatiklauf</entry>
|
||||
<entry key="Zähler #23">Zähler #23</entry>
|
||||
<entry key="Zähler #22">Zähler #22</entry>
|
||||
<entry key="Zähler #21">Zähler #21</entry>
|
||||
<entry key="tooltip.export.configuration">tooltip.export.configuration</entry>
|
||||
<entry key="Zähler #20">Zähler #20</entry>
|
||||
<entry key="Skripte">Skripte...</entry>
|
||||
<entry key="HW-Index">HW-Index</entry>
|
||||
<entry key="Verzeichnis">Verzeichnis</entry>
|
||||
<entry key="Dateiname">Dateiname</entry>
|
||||
<entry key="Synololog einstellen">Synololog einstellen</entry>
|
||||
<entry key="Cancel">abbrechen</entry>
|
||||
<entry key="Zähler #9">Zähler #9</entry>
|
||||
<entry key="Zähler #8">Zähler #8</entry>
|
||||
<entry key="Zähler #7">Zähler #7</entry>
|
||||
<entry key="Zähler #6">Zähler #6</entry>
|
||||
<entry key="Zähler #5">Zähler #5</entry>
|
||||
<entry key="Verbindung">Verbindung</entry>
|
||||
<entry key="Zähler #4">Zähler #4</entry>
|
||||
<entry key="Zähler #19">Zähler #19</entry>
|
||||
<entry key="Zähler #3">Zähler #3</entry>
|
||||
<entry key="Export hinzufügen">Export hinzufügen</entry>
|
||||
<entry key="Zähler #18">Zähler #18</entry>
|
||||
<entry key="Zähler #2">Zähler #2</entry>
|
||||
<entry key="Auslöser">Auslöser</entry>
|
||||
<entry key="Zähler #17">Zähler #17</entry>
|
||||
<entry key="Meldungen">Meldungen</entry>
|
||||
<entry key="Zähler #1">Zähler #1</entry>
|
||||
<entry key="Zähler #16">Zähler #16</entry>
|
||||
<entry key="Zähler #0">Zähler #0</entry>
|
||||
<entry key="Zähler #15">Zähler #15</entry>
|
||||
<entry key="Zähler #14">Zähler #14</entry>
|
||||
<entry key="Zähler #13">Zähler #13</entry>
|
||||
<entry key="Zähler #12">Zähler #12</entry>
|
||||
<entry key="Export ausführen">Export ausführen</entry>
|
||||
<entry key="Zähler #11">Zähler #11</entry>
|
||||
<entry key="Zähler #10">Zähler #10</entry>
|
||||
<entry key="Daten exportieren">Daten exportieren</entry>
|
||||
<entry key="schliessen">schliessen</entry>
|
||||
<entry key="Differenzieren">Differenzieren</entry>
|
||||
<entry key="Aufgezeichnete Werte verwalten">Aufgezeichnete Werte verwalten</entry>
|
||||
<entry key="tooltip.export.add">tooltip.export.add</entry>
|
||||
<entry key="Autostart">Autostart</entry>
|
||||
<entry key="tooltip.export.remove">tooltip.export.remove</entry>
|
||||
<entry key="Benennung">Benennung</entry>
|
||||
<entry key="Aufzeichnungen verwalten">Aufzeichnungen bearbeiten</entry>
|
||||
</properties>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>missing translations</comment>
|
||||
<entry key="Skripte">Scripts...</entry>
|
||||
<entry key="Cancel">cancel</entry>
|
||||
</properties>
|
Binary file not shown.
|
@ -0,0 +1,99 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>missing translations</comment>
|
||||
<entry key="Skript bearbeiten">Skript bearbeiten</entry>
|
||||
<entry key="neu...">neu...</entry>
|
||||
<entry key="Intervall 2 basiert auf Tageszeit">Intervall 2 basiert auf Tageszeit</entry>
|
||||
<entry key="Intervall 1:">Intervall 1:</entry>
|
||||
<entry key="Schnittstelle wählen...">Schnittstelle wählen...</entry>
|
||||
<entry key="5x neu">5x neu</entry>
|
||||
<entry key="Niemals">Niemals</entry>
|
||||
<entry key="auf Zähler übertragen....">auf Zähler übertragen....</entry>
|
||||
<entry key="Meldungen">Meldungen</entry>
|
||||
<entry key="Synololog einstellen">Synololog einstellen</entry>
|
||||
<entry key="ARITHEMTIK = B - 1">ARITHEMTIK = B - 1</entry>
|
||||
<entry key="tooltip.synololog.einstellen">tooltip.synololog.einstellen</entry>
|
||||
<entry key="ARITHEMTIK = A / B">ARITHEMTIK = A / B</entry>
|
||||
<entry key="Von Gerät %s geholt am %s">Von Gerät %s geholt am %s</entry>
|
||||
<entry key="A < B">A < B</entry>
|
||||
<entry key="Intervall 0:">Intervall 0:</entry>
|
||||
<entry key="Intervall 0 basiert auf Tageszeit">Intervall 0 basiert auf Tageszeit</entry>
|
||||
<entry key="Anschlusseinstellungen">Anschlusseinstellungen</entry>
|
||||
<entry key="ARITHEMTIK = B + 1">ARITHEMTIK = B + 1</entry>
|
||||
<entry key="Aufzeichnungen verwalten">Aufzeichnungen verwalten</entry>
|
||||
<entry key="Ausgang">Ausgang</entry>
|
||||
<entry key="von Zähler holen....">von Zähler holen....</entry>
|
||||
<entry key="SnapShot Speicher zurücksetzen">SnapShot Speicher zurücksetzen</entry>
|
||||
<entry key="Alle Zähler zurücksetzen">Alle Zähler zurücksetzen</entry>
|
||||
<entry key="ARITHEMTIK = A - B">ARITHEMTIK = A - B</entry>
|
||||
<entry key="A > B">A > B</entry>
|
||||
<entry key="Skripte">Skripte</entry>
|
||||
<entry key="Snapshot Index zurücksetzen">Snapshot Index zurücksetzen</entry>
|
||||
<entry key="A == B">A == B</entry>
|
||||
<entry key="ARITHEMTIK = A + B">ARITHEMTIK = A + B</entry>
|
||||
<entry key="Signalfenster">Signalfenster</entry>
|
||||
<entry key="Alle Zählerstände zurücksetzen">Alle Zählerstände zurücksetzen</entry>
|
||||
<entry key="ARITHEMTIK = A - 1">ARITHEMTIK = A - 1</entry>
|
||||
<entry key="ARITHEMTIK = A * B">ARITHEMTIK = A * B</entry>
|
||||
<entry key="tooltip.daten.exportieren">tooltip.daten.exportieren</entry>
|
||||
<entry key="LOGIK = A or B">LOGIK = A or B</entry>
|
||||
<entry key="bearbeiten...">bearbeiten...</entry>
|
||||
<entry key="ARITHEMTIK = A + 1">ARITHEMTIK = A + 1</entry>
|
||||
<entry key="A == 0">A == 0</entry>
|
||||
<entry key="Löst Snapshot aus">Löst Snapshot aus</entry>
|
||||
<entry key="Entfernen">Entfernen</entry>
|
||||
<entry key="entfernen">entfernen</entry>
|
||||
<entry key="Daten exportieren">Daten exportieren</entry>
|
||||
<entry key="Inkrement">Inkrement</entry>
|
||||
<entry key="1x neu">1x neu</entry>
|
||||
<entry key="SnapShot Speicher auf letzten bekannten SnapShot setzen">SnapShot Speicher auf letzten bekannten SnapShot setzen</entry>
|
||||
<entry key="Bedingung">Bedingung</entry>
|
||||
<entry key="Wählen Sie die Schnittstelle über die das Skript übertragen werden soll.">Wählen Sie die Schnittstelle über die das Skript übertragen werden soll.</entry>
|
||||
<entry key="<html>Diese Funktion sollte nur auf Aufforderung durch den Support ausgeführt werden.<br/>Soll der Snapshot Index auf dem Gerät wirklich zurückgesetzt werden?</html>"><html>Diese Funktion sollte nur auf Aufforderung durch den Support ausgeführt werden.<br/>Soll der Snapshot Index auf dem Gerät wirklich zurückgesetzt werden?</html></entry>
|
||||
<entry key="warning.selftest">warning.selftest</entry>
|
||||
<entry key="Intervall 3 basiert auf Tageszeit">Intervall 3 basiert auf Tageszeit</entry>
|
||||
<entry key="Z">Z</entry>
|
||||
<entry key="warning.title.selftest">warning.title.selftest</entry>
|
||||
<entry key="LOGIK = A and B">LOGIK = A and B</entry>
|
||||
<entry key="ARITHEMTIK = B">ARITHEMTIK = B</entry>
|
||||
<entry key="ARITHEMTIK = A">ARITHEMTIK = A</entry>
|
||||
<entry key="A != B">A != B</entry>
|
||||
<entry key="name">name</entry>
|
||||
<entry key="Invertiert">Invertiert</entry>
|
||||
<entry key="Kanal">Kanal</entry>
|
||||
<entry key="B">B</entry>
|
||||
<entry key="A">A</entry>
|
||||
<entry key="ARITHEMTIK = 1">ARITHEMTIK = 1</entry>
|
||||
<entry key="ARITHEMTIK = 0">ARITHEMTIK = 0</entry>
|
||||
<entry key="Immer">Immer</entry>
|
||||
<entry key="Ausgangswert Z">Ausgangswert Z</entry>
|
||||
<entry key="A != 0">A != 0</entry>
|
||||
<entry key="Beschreibung:">Beschreibung:</entry>
|
||||
<entry key="Intervall 1 basiert auf Tageszeit">Intervall 1 basiert auf Tageszeit</entry>
|
||||
<entry key="Signalfilter">Signalfilter</entry>
|
||||
<entry key="Bezeichnung">Bezeichnung</entry>
|
||||
<entry key="Intervall 3:">Intervall 3:</entry>
|
||||
<entry key="tooltip.intervall">tooltip.intervall</entry>
|
||||
<entry key="Tageszeitabhängigkeit:">Tageszeitabhängigkeit:</entry>
|
||||
<entry key="Verbindung">Verbindung</entry>
|
||||
<entry key="tooltip.tagesbasierte.intervalle">tooltip.tagesbasierte.intervalle</entry>
|
||||
<entry key="Nur nach Rücksprache mit Support:">Nur nach Rücksprache mit Support:</entry>
|
||||
<entry key="Passiver Schalter">Passiver Schalter</entry>
|
||||
<entry key="Skriptelement bearbeiten">Skriptelement bearbeiten</entry>
|
||||
<entry key="OK">OK</entry>
|
||||
<entry key="Wählen Sie die Schnittstelle über die das Skript empfangen werden soll.">Wählen Sie die Schnittstelle über die das Skript empfangen werden soll.</entry>
|
||||
<entry key="LOGIK = A xor B">LOGIK = A xor B</entry>
|
||||
<entry key="Der Selbsttest für Zähler #%d war erfolgreich.">Der Selbsttest für Zähler #%d war erfolgreich.</entry>
|
||||
<entry key="Eingangswert B">Eingangswert B</entry>
|
||||
<entry key="Eingangswert A">Eingangswert A</entry>
|
||||
<entry key="Intervall 2:">Intervall 2:</entry>
|
||||
<entry key="LOGIK = not B">LOGIK = not B</entry>
|
||||
<entry key="LOGIK = not A">LOGIK = not A</entry>
|
||||
<entry key="Formeln">Formeln</entry>
|
||||
<entry key="Es konnte kein Skript vom gerät empfangen werden.">Es konnte kein Skript vom gerät empfangen werden.</entry>
|
||||
<entry key="Operation">Operation</entry>
|
||||
<entry key="Bezeichnung:">Bezeichnung:</entry>
|
||||
<entry key="Wollen Sie wirklich alle Zählerstände auf 0 zurücksetzen?">Wollen Sie wirklich alle Zählerstände auf 0 zurücksetzen?</entry>
|
||||
<entry key="Der Selbsttest für Zähler #%d ist fehlgeschlagen.">Der Selbsttest für Zähler #%d ist fehlgeschlagen.</entry>
|
||||
</properties>
|
Binary file not shown.
|
@ -2,9 +2,6 @@ package org.hwo.pulscounter;
|
|||
|
||||
public abstract class AbstractPulsCounterApplicationListener implements PulsCounterApplicationListener {
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.hwo.pulscounter;
|
||||
|
||||
import static org.hwo.logging.Logging.log;
|
||||
|
||||
import org.hwo.logging.LogLevel;
|
||||
import org.hwo.logging.Logging;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Logging.Init(args, "synololog.log");
|
||||
|
||||
PulsCounterApplication application = new PulsCounterApplication(args);
|
||||
|
||||
log(LogLevel.INFO,"Application initialized, starting up user interface");
|
||||
|
||||
application.start();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
package org.hwo.pulscounter;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
public class DeviceTester extends Thread{
|
||||
|
||||
private IDeviceConnector device;
|
||||
|
||||
public DeviceTester(IDeviceConnector device){
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
prepare();
|
||||
|
||||
try {
|
||||
if (fullTest()){
|
||||
PulsCounterApplication.getApplication().message(String.format(
|
||||
Messages.getString("Der Selbsttest für Zähler #%d war erfolgreich."),
|
||||
device.getDeviceSerial()
|
||||
));
|
||||
} else {
|
||||
PulsCounterApplication.getApplication().message(String.format(
|
||||
Messages.getString("Der Selbsttest für Zähler #%d ist fehlgeschlagen."),
|
||||
device.getDeviceSerial()
|
||||
));
|
||||
}
|
||||
} catch (Exception e){
|
||||
log(ERROR,"Exception while testing device");
|
||||
log(e);
|
||||
}
|
||||
|
||||
unprepare();
|
||||
}
|
||||
|
||||
private void sleep(int ms){
|
||||
try {
|
||||
Thread.sleep(ms);
|
||||
} catch (InterruptedException e){
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fullTest(){
|
||||
|
||||
if (!setIncrements(1))
|
||||
return false;
|
||||
|
||||
if (!setPullups(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setOutputs(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setInverts(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setCounters(999999))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setCounters(0))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
|
||||
for (int i=0;i<10;i++){
|
||||
if (!setInverts(true))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setInverts(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
}
|
||||
|
||||
if (!checkCounters(10))
|
||||
return false;
|
||||
|
||||
for (int i=0;i<10;i++){
|
||||
if (!setPullups(true))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setPullups(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
}
|
||||
|
||||
sleep( 500 );
|
||||
|
||||
if (!checkCounters(20))
|
||||
return false;
|
||||
|
||||
if (!setPullups(true))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
for (int i=0;i<10;i++){
|
||||
if (!setOutputs(true))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
if (!setOutputs(false))
|
||||
return false;
|
||||
|
||||
sleep( 50 );
|
||||
|
||||
}
|
||||
|
||||
if (!checkCounters(30))
|
||||
return false;
|
||||
|
||||
if (!setPullups(false))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void prepare(){
|
||||
device.escape(IDeviceConnector.ESC_PREPARE_DEVICETEST, 0);
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
} catch (InterruptedException e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
public void unprepare(){
|
||||
device.escape(IDeviceConnector.ESC_UNPREPARE_DEVICETEST, 0);
|
||||
}
|
||||
|
||||
public boolean setPullups(boolean on){
|
||||
int set,act;
|
||||
|
||||
set = on ? 0xFFFFFFFF : 0;
|
||||
device.setPullups(set);
|
||||
act = device.getPullups();
|
||||
|
||||
log(INFO,"setPullups(%s): Result: %s",on,(act==set));
|
||||
return (set == act);
|
||||
}
|
||||
|
||||
public boolean setOutputs(boolean on){
|
||||
int set,act;
|
||||
|
||||
set = on ? 0xFFFFFFFF : 0;
|
||||
device.setOutputs(set);
|
||||
act = device.getOutputs();
|
||||
|
||||
log(INFO,"setOutputs(%s): Result: %s",on,(act==set));
|
||||
return (set == act);
|
||||
}
|
||||
|
||||
public boolean setInverts(boolean on){
|
||||
int set,act;
|
||||
|
||||
set = on ? 0xFFFFFFFF : 0;
|
||||
device.setInverts(set);
|
||||
act = device.getInverts();
|
||||
|
||||
log(INFO,"setInverts(%s): Result: %s",on,(act==set));
|
||||
return (set == act);
|
||||
}
|
||||
|
||||
public boolean setCounters(int set){
|
||||
boolean success = true;
|
||||
int[] _set = new int[32];
|
||||
int[] _act = new int[32];
|
||||
|
||||
Arrays.fill(_set, set);
|
||||
device.setCounters(_set);
|
||||
_act = device.getCounters();
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
if (_set[i] != _act[i]){
|
||||
success = false;
|
||||
log(INFO,"Setting Channel Counter %d failed [%d!=%d]",i,_set[i],_act[i]);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public boolean setIncrements(int set){
|
||||
boolean success = true;
|
||||
int[] _set = new int[32];
|
||||
int[] _act = new int[32];
|
||||
|
||||
Arrays.fill(_set, set);
|
||||
device.setIncrements(_set);
|
||||
_act = device.getIncrements();
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
if (_set[i] != _act[i]){
|
||||
success = false;
|
||||
log(INFO,"Setting Channel Counter Increment %d failed",i);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
public boolean checkCounters(int check){
|
||||
boolean success = true;
|
||||
int[] _check = new int[32];
|
||||
int[] _act = new int[32];
|
||||
|
||||
Arrays.fill(_check, check);
|
||||
_act = device.getCounters();
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
if (_check[i] != _act[i]){
|
||||
success = false;
|
||||
log(INFO,"Check Channel Counter %d failed (0x%08x != 0x%08x)",i,check,_act[i]);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -8,6 +8,8 @@ import java.util.Date;
|
|||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.hwo.ObjectTable;
|
||||
import org.hwo.ObjectTable.ObjectSet;
|
||||
import org.hwo.configuration.ConfigurableAttribute;
|
||||
import org.hwo.configuration.ConfigurableObject;
|
||||
import org.hwo.csv.CSV;
|
||||
|
@ -17,6 +19,10 @@ import org.hwo.interactiveobjects.ObjectEditorUI;
|
|||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.pulscounter.ui.ExportSettingsEditorDialog;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
@ObjectEditorUI(editor=ExportSettingsEditorDialog.class)
|
||||
@ConfigurableObject
|
||||
public class ExportSetting {
|
||||
|
@ -113,90 +119,82 @@ public class ExportSetting {
|
|||
this.recordDelta = recordDelta;
|
||||
}
|
||||
|
||||
private String calculateFileName(String filename,SnapShot ss){
|
||||
Date d = new Date(((long)ss.getTimestamp())*1000);
|
||||
private String calculateFileName(String filename, ObjectSet row, int deviceSerial){
|
||||
Date d = new Date(((long)row.getInteger(0))*1000);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(d);
|
||||
|
||||
return filename
|
||||
filename = filename
|
||||
.replaceAll("\\%S", String.format("%d", deviceSerial))
|
||||
.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))));
|
||||
.replaceAll("\\%D", String.format("%02d", new Integer(c.get(Calendar.DAY_OF_MONTH))))
|
||||
.replaceAll("\\%h", String.format("%02d", new Integer(c.get(Calendar.HOUR))))
|
||||
.replaceAll("\\%m", String.format("%02d", new Integer(c.get(Calendar.MINUTE))))
|
||||
.replaceAll("\\%s", String.format("%02d", new Integer(c.get(Calendar.SECOND))));
|
||||
|
||||
// log(DEBUG, "exportFileName for Snapshot %s from [%s: %04d-%02d-%02d %02d:%02d:%02d] is %s", ss, ss.getDeviceSerial(), c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND),filename);
|
||||
return filename;
|
||||
|
||||
}
|
||||
|
||||
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()){
|
||||
for (int deviceSerial: PulsCounterApplication.getApplication().getDatabase().getKnownDevices()){
|
||||
ObjectTable ot = PulsCounterApplication.getApplication().getDatabase().getSnapshotsAsTable(deviceSerial);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
PulsCounterApplication.getApplication().getDatabase().calulateTableDeltas(ot);
|
||||
}
|
||||
|
||||
Hashtable<String, CSV> hash = new Hashtable<String, CSV>();
|
||||
|
||||
int[] simpleSelection = new int[]{
|
||||
1,
|
||||
4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,
|
||||
36,37,38,39,40,41,42,43
|
||||
};
|
||||
|
||||
|
||||
for (ObjectSet row: ot.getRows()){
|
||||
String fn = calculateFileName(fileName, row, deviceSerial);
|
||||
|
||||
if ((triggerType==TriggerType.ALL)||(triggerType.getValue().equals(row.getInteger(2)))){
|
||||
if (triggerSource.equals(-1) || triggerSource.equals( row.getInteger(3) )){
|
||||
|
||||
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(new CSVRecord( extended ? row.getValues() : row.selectColums(simpleSelection)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String fn: hash.keySet()){
|
||||
hash.get(fn).saveToFile(new File(path,fn));
|
||||
}
|
||||
|
||||
hash.get(fn).saveToFile(new File(path,fn));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ import org.hwo.io.SerialPort;
|
|||
import org.hwo.io.SerialPortExeption;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkException;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkRequestFailedException;
|
||||
|
||||
public class NewPulsCounterDevice implements IPulsCounter {
|
||||
private ServiceLink serviceLink;
|
||||
|
|
|
@ -1,231 +0,0 @@
|
|||
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.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 implements ServiceLinkListener{
|
||||
|
||||
static PulsCounter2Application _application;
|
||||
public static PulsCounter2Application getApplication(){
|
||||
if (_application == null)
|
||||
_application = new PulsCounter2Application();
|
||||
|
||||
return _application;
|
||||
}
|
||||
|
||||
private NewSerialPort serialPort;
|
||||
private ServiceLink serviceLink;
|
||||
|
||||
private List<AppSettingsListener> appSettingsListeners;
|
||||
private List<PulsCounterApplicationListener> applicationListeners;
|
||||
|
||||
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);
|
||||
}
|
||||
public void removeAppSettingsListener(AppSettingsListener listener){
|
||||
appSettingsListeners.remove(listener);
|
||||
}
|
||||
|
||||
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 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(NewSerialPort serialPort) {
|
||||
if (serviceLink != null){
|
||||
serviceLink.close();
|
||||
serviceLink = null;
|
||||
}
|
||||
this.serialPort = serialPort;
|
||||
|
||||
getServiceLink();
|
||||
|
||||
fireServiceLinkChanged();
|
||||
fireSerialPortChanged();
|
||||
}
|
||||
|
||||
public synchronized ServiceLink getServiceLink() {
|
||||
if (serviceLink == null){
|
||||
serviceLink = new ServiceLink(getSerialPort());
|
||||
serviceLink.getSerialPort().setTimeOut(200);
|
||||
serviceLink.addServiceLinkListener(this);
|
||||
}
|
||||
return serviceLink;
|
||||
}
|
||||
public synchronized void setServiceLink(ServiceLink serviceLink) {
|
||||
if (serviceLink != null){
|
||||
serviceLink.close();
|
||||
}
|
||||
this.serviceLink = serviceLink;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
package org.hwo.pulscounter;
|
||||
|
||||
import static org.hwo.logging.Logging.log;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.InvalidPropertiesFormatException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.hsqldb.persist.EventLogInterface;
|
||||
import org.hwo.StringHelper;
|
||||
import org.hwo.configuration.ConfigurableObjects;
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.logging.Logging;
|
||||
import org.hwo.platform.Platform;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkListener;
|
||||
import org.hwo.pulscounter.db.PulsCounterDatabase;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.pulscounter.device.ServiceLinkDeviceConnector;
|
||||
import org.hwo.pulscounter.device.SimpleLinkDeviceConnector;
|
||||
import org.hwo.pulscounter.device.SimulatedCounter;
|
||||
import org.hwo.pulscounter.ui.AppSettingsListener;
|
||||
import org.hwo.pulscounter.ui.BatchRunner;
|
||||
import org.hwo.pulscounter.ui.NewMainWindow;
|
||||
import org.hwo.pulscounter.ui.ShutdownNotification;
|
||||
import org.hwo.scheduler.Scheduler;
|
||||
|
||||
public class PulsCounterApplication implements ServiceLinkListener{
|
||||
|
||||
static PulsCounterApplication _application;
|
||||
public static PulsCounterApplication getApplication(){
|
||||
if (_application == null)
|
||||
_application = new PulsCounterApplication(null);
|
||||
|
||||
return _application;
|
||||
}
|
||||
|
||||
private Properties applicationConfiguration,
|
||||
defaultConfiguration;
|
||||
|
||||
private Object uiSynchronization;
|
||||
private boolean uiIsFinished;
|
||||
private boolean shouldSaveConfiguration;
|
||||
|
||||
private boolean dontLoadTranslations;
|
||||
|
||||
private List<PulsCounterApplicationListener>
|
||||
applicationListeners;
|
||||
|
||||
private Vector<String> unseenMessages;
|
||||
|
||||
private List<Class<IDeviceConnector>>
|
||||
interfaceClasses;
|
||||
private List<IDeviceConnector> interfaces;
|
||||
|
||||
private PulsCounterDatabase database;
|
||||
|
||||
private List<String> batchCommands;
|
||||
|
||||
|
||||
|
||||
|
||||
private NewSerialPort serialPort;
|
||||
private ServiceLink serviceLink;
|
||||
|
||||
private List<AppSettingsListener> appSettingsListeners;
|
||||
|
||||
private boolean snapshotLock;
|
||||
|
||||
|
||||
private List<ExportSetting> exportSettings;
|
||||
|
||||
private Scheduler scheduler;
|
||||
|
||||
private String[] channelDescriptions;
|
||||
|
||||
public PulsCounterApplication(String[] args) {
|
||||
/* Initialize Logging Framework */
|
||||
logStartup();
|
||||
|
||||
/* Check... */
|
||||
if (_application != null){
|
||||
throw new InstantiationError("Only one Instance of PulsCounterApplication can exist!");
|
||||
} else {
|
||||
_application = this;
|
||||
}
|
||||
|
||||
/* Initialize fields... */
|
||||
uiIsFinished = false;
|
||||
uiSynchronization = new Object();
|
||||
applicationListeners = new LinkedList<PulsCounterApplicationListener>();
|
||||
unseenMessages = new Vector<String>();
|
||||
exportSettings = new ArrayList<>();
|
||||
|
||||
interfaceClasses = new ArrayList<>();
|
||||
interfaces = new ArrayList<>();
|
||||
|
||||
batchCommands = new ArrayList<>();
|
||||
|
||||
/* Prepare Translation Framework */
|
||||
Messages i18n = Messages.getInstance();
|
||||
i18n.setMissingKeysFileName("missing-translation.txt");
|
||||
|
||||
/* Prepare for Startup */
|
||||
loadApplicationConfiguration();
|
||||
|
||||
/* Parse Command Line Arguments */
|
||||
Iterator<String> options = Arrays.asList(args).iterator();
|
||||
|
||||
while (options.hasNext()){
|
||||
String option = options.next();
|
||||
|
||||
switch (option){
|
||||
case "--gui":
|
||||
if (!options.hasNext()){
|
||||
log(FATAL,"Argument to --gui is missing");
|
||||
throw new IllegalArgumentException("Argument to --gui is missing");
|
||||
} else {
|
||||
applicationConfiguration.setProperty("ui.class", options.next());
|
||||
}
|
||||
break;
|
||||
case "--batch":
|
||||
case "-B":
|
||||
applicationConfiguration.setProperty("ui.class", BatchRunner.class.getCanonicalName());
|
||||
break;
|
||||
case "-G":
|
||||
applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
break;
|
||||
case "--batch-execute":
|
||||
batchCommands.add( options.next() );
|
||||
break;
|
||||
case "--no-translation":
|
||||
dontLoadTranslations = true;
|
||||
break;
|
||||
default:
|
||||
log(WARN,"Unknown command line parameter: %s", option);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dontLoadTranslations){
|
||||
Messages.loadMessages(PulsCounterApplication.class);
|
||||
} else {
|
||||
log(INFO,"Translation text fragments are NOT loaded, due to command line switch (--no-translation)");
|
||||
}
|
||||
|
||||
/* Old stuff... */
|
||||
// this.initialize();
|
||||
}
|
||||
|
||||
|
||||
private Properties createDefaultApplicationConfiguration(){
|
||||
|
||||
defaultConfiguration = new Properties();
|
||||
|
||||
defaultConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
defaultConfiguration.setProperty("interface.classes", StringHelper.join(new String[]{
|
||||
ServiceLinkDeviceConnector.class.getCanonicalName(),
|
||||
SimulatedCounter.class.getCanonicalName(),
|
||||
SimpleLinkDeviceConnector.class.getCanonicalName()
|
||||
}, ","));
|
||||
|
||||
return defaultConfiguration;
|
||||
}
|
||||
|
||||
private void loadApplicationConfiguration(){
|
||||
createDefaultApplicationConfiguration();
|
||||
|
||||
applicationConfiguration = new Properties(defaultConfiguration);
|
||||
|
||||
|
||||
try {
|
||||
/* Try to load configuration from file */
|
||||
FileInputStream fis = new FileInputStream("synololog.cfg");
|
||||
applicationConfiguration.loadFromXML(fis);
|
||||
fis.close();
|
||||
|
||||
} catch (InvalidPropertiesFormatException e) {
|
||||
log(WARN,"synololog.cfg is misformated");
|
||||
} catch (FileNotFoundException e) {
|
||||
log(WARN,"synololog.cfg not found");
|
||||
} catch (IOException e) {
|
||||
log(ERROR,"I/O Error reading synololog.cfg");
|
||||
}
|
||||
|
||||
applicationConfiguration.setProperty("ui.class", NewMainWindow.class.getCanonicalName());
|
||||
|
||||
}
|
||||
|
||||
public Properties getApplicationConfiguration(){
|
||||
return this.applicationConfiguration;
|
||||
}
|
||||
|
||||
private static void logStartup(){
|
||||
log("Synololog Application Startup");
|
||||
|
||||
log("JAVA Environment: %s (%s)", System.getProperty("java.version"),
|
||||
System.getProperty("java.vendor"));
|
||||
|
||||
log("Operating System: %s [%s] %s", System.getProperty("os.name"),
|
||||
System.getProperty("os.arch"),
|
||||
System.getProperty("os.version"));
|
||||
|
||||
log("User Environment: %s (%s) (CWD:%s)", System.getProperty("user.name"),
|
||||
System.getProperty("user.home"),
|
||||
System.getProperty("user.dir"));
|
||||
|
||||
log("Hostname: %s",Platform.getHostName());
|
||||
log("OS Search Path: %s", System.getenv("PATH"));
|
||||
}
|
||||
|
||||
public String[] getBatchCommands(){
|
||||
return batchCommands.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
public void start(){
|
||||
|
||||
initialize();
|
||||
|
||||
String uiClassName = applicationConfiguration.getProperty("ui.class");
|
||||
Object ui = null;
|
||||
|
||||
try {
|
||||
Class uiClazz = PulsCounterApplication.class.getClassLoader().loadClass(uiClassName);
|
||||
|
||||
Constructor<?> constructor = uiClazz.getConstructor(PulsCounterApplication.class);
|
||||
ui = (Object) constructor.newInstance(this);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
log(FATAL,"user interface class could not be loaded [%s] %s",uiClassName,e.getMessage());
|
||||
} catch (NoSuchMethodException e) {
|
||||
log(FATAL,"user interface class misses valid constructor [%s] %s",uiClassName,e.getMessage());
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
log(FATAL,"user interface class could not be instantiated. [%s] %s",uiClassName,e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
waitUiFinished();
|
||||
|
||||
// ShutdownNotification sn = new ShutdownNotification();
|
||||
// if (Component.class.isInstance(ui)){
|
||||
// sn.setLocationRelativeTo((Component)ui);
|
||||
// }
|
||||
// sn.setVisible(true);
|
||||
|
||||
try {
|
||||
|
||||
shutdown();
|
||||
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
// sn.setVisible(false);
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
|
||||
/* Interface Classes should be merged with application well known*/
|
||||
HashSet<String> interfaceClassNames = new HashSet<>();
|
||||
for (String icn: applicationConfiguration.getProperty("interface.classes").split(",")){
|
||||
interfaceClassNames.add(icn);
|
||||
}
|
||||
for (String icn: defaultConfiguration.getProperty("interface.classes").split(",")){
|
||||
interfaceClassNames.add(icn);
|
||||
}
|
||||
|
||||
|
||||
for (String interfaceClassName: interfaceClassNames){
|
||||
|
||||
try {
|
||||
|
||||
Class<IDeviceConnector> clazz = (Class<IDeviceConnector>)PulsCounterApplication.class.getClassLoader().loadClass(interfaceClassName);
|
||||
interfaceClasses.add(clazz);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
log(ERROR,"Interface class could not be loaded: %s",interfaceClassName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Integer nIntf = Integer.parseInt(applicationConfiguration.getProperty("interfaces.n","0"));
|
||||
for (int n=0;n<nIntf;n++){
|
||||
Class<IDeviceConnector> clazz = getInterfaceClass(applicationConfiguration.getProperty(String.format("interfaces.%d.class",n)));
|
||||
addInterface(clazz, applicationConfiguration.getProperty(String.format("interfaces.%d.settings",n)));
|
||||
}
|
||||
|
||||
database = new PulsCounterDatabase();
|
||||
log(INFO,"Database Schema Version: %s", database.getSchemaVersion());
|
||||
|
||||
|
||||
String sProfiles = database.getProperty("export.profiles");
|
||||
if (sProfiles != null){
|
||||
Integer nProfiles = new Integer(sProfiles);
|
||||
for (int n=0;n<nProfiles;n++){
|
||||
String profileConf = database.getProperty(String.format("export.profiles.%d",n));
|
||||
log(INFO,"Export Profile %d: %s",n,profileConf);
|
||||
|
||||
if (profileConf != null){
|
||||
ExportSetting es = new ExportSetting();
|
||||
ConfigurableObjects.setConfiguration(es, profileConf);
|
||||
exportSettings.add(es);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void shutdown(){
|
||||
|
||||
log(INFO,"Application shutdown...");
|
||||
|
||||
for (IDeviceConnector c: interfaces){
|
||||
c.shutdown();
|
||||
}
|
||||
|
||||
|
||||
/* Dispose all left frames */
|
||||
for (Frame frame: JFrame.getFrames()){
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
if (shouldSaveConfiguration){
|
||||
|
||||
applicationConfiguration.setProperty("interfaces.n", Integer.toString(interfaces.size()));
|
||||
for (int n=0;n<interfaces.size();n++){
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.class", n), interfaces.get(n).getClass().getCanonicalName());
|
||||
applicationConfiguration.setProperty(String.format("interfaces.%d.settings", n), interfaces.get(n).getConnectionSettings());
|
||||
}
|
||||
|
||||
for (int n=0;n<exportSettings.size();n++){
|
||||
String conf = ConfigurableObjects.getConfiguration(exportSettings.get(n));
|
||||
if (conf != null){
|
||||
database.setProperty(String.format("export.profiles.%d", n), conf);
|
||||
}
|
||||
}
|
||||
database.setProperty("export.profiles", new Integer(exportSettings.size()).toString());
|
||||
|
||||
|
||||
|
||||
try {
|
||||
log(INFO,"Save application configuration");
|
||||
FileOutputStream fos = new FileOutputStream("synololog.cfg");
|
||||
applicationConfiguration.storeToXML(fos, "Synololog Application Configuration");
|
||||
fos.flush();
|
||||
fos.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
log(ERROR,"synololog.cfg could not be created/opened for writing");
|
||||
} catch (IOException e) {
|
||||
log(ERROR,"synololog.cfg could not be written");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
database.close();
|
||||
|
||||
Messages.getInstance().saveMissingStrings();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void waitUiFinished(){
|
||||
|
||||
synchronized (uiSynchronization) {
|
||||
|
||||
while (!uiIsFinished){
|
||||
try {
|
||||
uiSynchronization.wait(250);
|
||||
} catch (InterruptedException e){
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
log(INFO,"UI notified finish");
|
||||
|
||||
}
|
||||
|
||||
public void notifyUiIsFinished(boolean saveApplicationConfiguration){
|
||||
synchronized (uiSynchronization) {
|
||||
uiIsFinished = true;
|
||||
shouldSaveConfiguration = saveApplicationConfiguration;
|
||||
uiSynchronization.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Interface Types */
|
||||
public List<Class<IDeviceConnector>> getInterfaceClasses(){
|
||||
return this.interfaceClasses;
|
||||
}
|
||||
|
||||
private Class<IDeviceConnector> getInterfaceClass(String className){
|
||||
for (Class<IDeviceConnector> c:interfaceClasses){
|
||||
if (c.getCanonicalName().equals(className))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Physical Interfaces */
|
||||
public List<IDeviceConnector> getInterfaces(){
|
||||
return this.interfaces;
|
||||
}
|
||||
public void addInterface(Class<IDeviceConnector> clazz,String connectionSettings){
|
||||
|
||||
try {
|
||||
IDeviceConnector idc = clazz.newInstance();
|
||||
idc.setConnectionSettings(connectionSettings);
|
||||
interfaces.add(idc);
|
||||
fireinterfacesChanged();
|
||||
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
public void removeInterface(IDeviceConnector intf){
|
||||
interfaces.remove(intf);
|
||||
fireinterfacesChanged();
|
||||
}
|
||||
|
||||
private void fireinterfacesChanged(){
|
||||
log(INFO,"interfaces changed");
|
||||
|
||||
for (PulsCounterApplicationListener l: applicationListeners){
|
||||
l.interfacesChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
public PulsCounterDatabase getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
|
||||
/* Snapshots */
|
||||
public void checkForSnapShots(){
|
||||
|
||||
for (IDeviceConnector idc: this.interfaces){
|
||||
Integer deviceSerial = idc.getDeviceSerial();
|
||||
Integer highestIndex = database.highestSnapShot(deviceSerial);
|
||||
|
||||
log(INFO,"Highest known snapshot index for device #%d is %d", deviceSerial, highestIndex);
|
||||
|
||||
SnapShot[] snapshots = idc.readSnapShots(highestIndex+1);
|
||||
if (snapshots != null){
|
||||
getDatabase().storeSnapshots(snapshots);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void addSnapshotToDatabase(SnapShot snapShot){
|
||||
getDatabase().storeSnapshots(new SnapShot[]{ snapShot });
|
||||
}
|
||||
|
||||
|
||||
/* ToDO: Upgrade the old stuff ... */
|
||||
|
||||
/*
|
||||
private void initialize(){
|
||||
appSettingsListeners = new LinkedList<AppSettingsListener>();
|
||||
exportSettings = new LinkedList<ExportSetting>();
|
||||
scheduler = new Scheduler();
|
||||
|
||||
channelDescriptions = new String[32];
|
||||
|
||||
loadPrefs();
|
||||
|
||||
try {
|
||||
snapshotManager = new SnapshotManager();
|
||||
snapshotManager.notify(Notification.INITIALIZE);
|
||||
|
||||
} catch (FileNotFoundException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void addAppSettingsListener(AppSettingsListener listener){
|
||||
appSettingsListeners.add(listener);
|
||||
}
|
||||
public void removeAppSettingsListener(AppSettingsListener listener){
|
||||
appSettingsListeners.remove(listener);
|
||||
}
|
||||
|
||||
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 void message(String message){
|
||||
log(INFO, 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
}
|
||||
|
||||
|
||||
public List<ExportSetting> getExportSettings() {
|
||||
return exportSettings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package org.hwo.pulscounter;
|
||||
|
||||
public interface PulsCounterApplicationListener {
|
||||
|
||||
void serialPortChanged();
|
||||
void connectionStateChanged(Boolean connected);
|
||||
|
||||
void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication);
|
||||
void interfacesChanged(PulsCounterApplication pulsCounterApplication);
|
||||
|
||||
void messageArrived(String message);
|
||||
|
||||
|
|
|
@ -2,26 +2,51 @@ package org.hwo.pulscounter;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hwo.csv.CSVRecord;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.exceptions.ServiceLinkException;
|
||||
import org.hwo.ui.diagram.annotation.Plot;
|
||||
|
||||
public class SnapShot {
|
||||
UUID uuid;
|
||||
|
||||
Integer deviceSerial;
|
||||
|
||||
Integer index;
|
||||
Integer timestamp;
|
||||
Integer field0;
|
||||
|
||||
Integer[] values;
|
||||
Integer[] analog;
|
||||
Integer[] merker;
|
||||
|
||||
Integer inputmask,
|
||||
outputmask,
|
||||
pullupmask,
|
||||
invertmask,
|
||||
triggermask;
|
||||
|
||||
static SimpleDateFormat
|
||||
df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
public SnapShot(int deviceSerial){
|
||||
this.deviceSerial = deviceSerial;
|
||||
|
||||
this.values = new Integer[32];
|
||||
this.analog = new Integer[8];
|
||||
this.merker = new Integer[24];
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SnapShot(){
|
||||
this.values = new Integer[32];
|
||||
|
@ -35,6 +60,46 @@ public class SnapShot {
|
|||
fromBytes(bytes);
|
||||
}
|
||||
|
||||
public SnapShot(ResultSet rs) throws SQLException {
|
||||
this.values = new Integer[32];
|
||||
this.analog = new Integer[8];
|
||||
|
||||
this.deviceSerial = rs.getInt("device");
|
||||
this.index = rs.getInt("snap_id");
|
||||
this.timestamp = rs.getInt("timestamp");
|
||||
this.inputmask = rs.getInt("inputs");
|
||||
this.outputmask = rs.getInt("outputs");
|
||||
this.invertmask = rs.getInt("inverts");
|
||||
this.triggermask = 0;
|
||||
this.pullupmask = rs.getInt("pullups");
|
||||
this.field0 = rs.getInt("field0");
|
||||
|
||||
Object[] va = (Object[])rs.getArray("counters").getArray();
|
||||
for (int i=0;i<32;i++){
|
||||
this.values[i] = (Integer)va[i];
|
||||
}
|
||||
va = (Object[])rs.getArray("analogs").getArray();
|
||||
for (int i=0;i<8;i++){
|
||||
this.analog[i] = (Integer)va[i];
|
||||
}
|
||||
}
|
||||
|
||||
@TableColumn(label="Gerät",order=5,width=80)
|
||||
public Integer getDeviceSerial() {
|
||||
return deviceSerial;
|
||||
}
|
||||
public void setDeviceSerial(Integer deviceSerial) {
|
||||
this.deviceSerial = deviceSerial;
|
||||
}
|
||||
|
||||
@TableColumn(label="HW-Index",order=0,width=80)
|
||||
public Integer getIndex() {
|
||||
return index;
|
||||
}
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setField0(Integer field0) {
|
||||
this.field0 = field0;
|
||||
}
|
||||
|
@ -44,6 +109,7 @@ public class SnapShot {
|
|||
public void setTimestamp(Integer timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Integer getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
@ -83,12 +149,15 @@ public class SnapShot {
|
|||
this.values[ch] = value;
|
||||
}
|
||||
}
|
||||
@Plot(label="Zähler %d",instances=32)
|
||||
public Integer getValue(Integer ch){
|
||||
if ((ch >= 0) && (ch<32)){
|
||||
return this.values[ch];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@TableColumn(label="Zähler #%d",order=50,fieldlength=32, width=80)
|
||||
public Integer[] getValues(){
|
||||
return Arrays.copyOf(this.values, this.values.length);
|
||||
}
|
||||
|
@ -119,7 +188,12 @@ public class SnapShot {
|
|||
public int getSource(){
|
||||
return (field0 >> 8) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
@TableColumn(label="Zeitstempel",order=10,width=100)
|
||||
public String getTimeStampFormated(){
|
||||
return df.format(new Date(((long)timestamp)*1000));
|
||||
}
|
||||
|
||||
public byte[] toBytes(){
|
||||
byte[] buffer = new byte[256];
|
||||
|
@ -173,13 +247,12 @@ public class SnapShot {
|
|||
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");
|
||||
record.appendValue(field0 & 0x000000FF);
|
||||
record.appendValue((field0 >> 8) & 0xff);
|
||||
}
|
||||
|
||||
for (int n=0;n<32;n++)
|
||||
|
@ -192,20 +265,7 @@ public class SnapShot {
|
|||
|
||||
@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();
|
||||
return String.format("SnapShot [ Device: %d Timestamp: %d ]",this.deviceSerial,this.timestamp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,321 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package org.hwo.pulscounter.application;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.pulscounter.elements.WorkShift;
|
||||
|
||||
public class InspectorApplication {
|
||||
List<WorkShift> workShifts;
|
||||
|
||||
Connection db;
|
||||
|
||||
public InspectorApplication(){
|
||||
workShifts = new LinkedList<WorkShift>();
|
||||
/*
|
||||
workShifts.add(new WorkShift());
|
||||
workShifts.add(new WorkShift());
|
||||
|
||||
workShifts.get(0).setName("Frühschicht");
|
||||
workShifts.get(0).getBegins().setHours(6);
|
||||
workShifts.get(0).getBegins().setMinutes(0);
|
||||
workShifts.get(0).getEnds().setHours(15);
|
||||
workShifts.get(0).getEnds().setMinutes(0);
|
||||
workShifts.get(1).setName("Frühschicht");
|
||||
workShifts.get(1).getBegins().setHours(15);
|
||||
workShifts.get(1).getBegins().setMinutes(0);
|
||||
workShifts.get(1).getEnds().setHours(3);
|
||||
workShifts.get(1).getEnds().setMinutes(0);
|
||||
*/
|
||||
connect();
|
||||
|
||||
try {
|
||||
Statement stat = db.createStatement();
|
||||
ResultSet result = stat.executeQuery("SELECT * from workshifts");
|
||||
|
||||
while (result.next()){
|
||||
WorkShift shift = new WorkShift();
|
||||
shift.setName(result.getString("name"));
|
||||
shift.getBegins().setTime( result.getTime("begins"));
|
||||
shift.getEnds().setTime( result.getTime("ends"));
|
||||
workShifts.add(shift);
|
||||
}
|
||||
|
||||
result.close();
|
||||
stat.close();
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void connect(){
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
|
||||
db = DriverManager.getConnection("jdbc:postgresql://10.112.1.1/pulscounter", "haraldwolff","diekleinefeine");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public WorkShift[] getWorkShifts(){
|
||||
return workShifts.toArray(new WorkShift[0]);
|
||||
}
|
||||
|
||||
|
||||
public Connection getConnection() {
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
|
||||
properties.put("hibernate.connection.driver", "org.postgresql.Driver");
|
||||
properties.put("hibernate.connection.url", );
|
||||
***/
|
|
@ -0,0 +1,303 @@
|
|||
package org.hwo.pulscounter.db;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.sql.Array;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hsqldb.jdbc.JDBCArrayBasic;
|
||||
import org.hsqldb.types.Type;
|
||||
import org.hwo.ArrayHelper;
|
||||
import org.hwo.ObjectTable;
|
||||
import org.hwo.ObjectTable.ObjectSet;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript;
|
||||
import org.hwo.sql.Schema;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
public class PulsCounterDatabase {
|
||||
|
||||
private Connection dbConnection;
|
||||
|
||||
public PulsCounterDatabase(){
|
||||
|
||||
try {
|
||||
getClass().getClassLoader().loadClass("org.hsqldb.jdbcDriver");
|
||||
dbConnection = DriverManager.getConnection("jdbc:hsqldb:file:synololog-hsql", "SA", "");
|
||||
log(INFO,"HSQLDB Version: %s",dbConnection.getMetaData().getDatabaseProductVersion());
|
||||
|
||||
Schema schema = new Schema(dbConnection);
|
||||
schema.print();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
log(ERROR,"HyperSQL Driver could not be loaded. [%s]",e.toString());
|
||||
}
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/org/hwo/pulscounter/db/schema/schema.sql");
|
||||
|
||||
if (is == null){
|
||||
log(ERROR,"Database schema file not found");
|
||||
} else {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
do {
|
||||
String sql = br.readLine();
|
||||
if (sql == null){
|
||||
break;
|
||||
}
|
||||
|
||||
sql = sql.trim();
|
||||
|
||||
if (!sql.equals("") && !sql.startsWith("//")){
|
||||
log(sql);
|
||||
executeSimpleSQL(sql);
|
||||
}
|
||||
|
||||
}while (true);
|
||||
|
||||
} catch (IOException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close(){
|
||||
try {
|
||||
dbConnection.close();
|
||||
} catch (SQLException e) {
|
||||
log(ERROR,"Exception while closing database: %s",e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private ResultSet executeSimpleSQL(String query,Object... args){
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = dbConnection.prepareStatement(query);
|
||||
int i = 0;
|
||||
|
||||
try {
|
||||
for (i=0;i<args.length;i++){
|
||||
if (Array.class.isInstance(args[i]))
|
||||
stmt.setArray(i+1, (Array)args[i]);
|
||||
else
|
||||
stmt.setObject(i+1, args[i]);
|
||||
}
|
||||
} catch (SQLException e){
|
||||
log(ERROR,"Exception while binding: %d = %s",i,args[i]);
|
||||
throw e;
|
||||
}
|
||||
stmt.execute();
|
||||
|
||||
ResultSet result = stmt.getResultSet();
|
||||
|
||||
stmt.closeOnCompletion();
|
||||
|
||||
return result;
|
||||
|
||||
} catch (SQLException e) {
|
||||
log(ERROR,"SQL Statement failed: %s",query);
|
||||
log(e);
|
||||
if (e.getCause() != null){
|
||||
log(ERROR,"Caused-By: %s",e.getCause().toString());
|
||||
e.getCause().printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String executeVerySimpleQuery(String query,Object... args){
|
||||
ResultSet result = executeSimpleSQL(query,args);
|
||||
if (result != null){
|
||||
try {
|
||||
if (result.next()){
|
||||
return result.getString(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log(ERROR,"SQL Statement failed: %s",query);
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object executeSimpleQueryObject(String query,Object... args){
|
||||
ResultSet result = executeSimpleSQL(query,args);
|
||||
if (result != null){
|
||||
try {
|
||||
if (result.next()){
|
||||
return result.getObject(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log(ERROR,"SQL Statement failed: %s",query);
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getProperty(String name){
|
||||
return executeVerySimpleQuery("SELECT value FROM props WHERE name=?", name);
|
||||
}
|
||||
public void setProperty(String name,String value){
|
||||
executeSimpleSQL("MERGE INTO props USING (VALUES(?,?)) as p(name,value) ON props.name = p.name WHEN MATCHED THEN UPDATE SET props.value = p.value WHEN NOT MATCHED THEN INSERT VALUES uuid(), p.name, p.value", name,value);
|
||||
}
|
||||
public void removeProperty(String name){
|
||||
executeSimpleSQL("DELETE FROM props WHERE props.name = ?", name);
|
||||
}
|
||||
|
||||
public String getSchemaVersion(){
|
||||
return getProperty("db.schema.version");
|
||||
}
|
||||
|
||||
public void storeSnapshots(SnapShot[] snapShots){
|
||||
for (SnapShot snapShot: snapShots){
|
||||
storeSnapshot(snapShot);
|
||||
}
|
||||
}
|
||||
|
||||
private void storeSnapshot(SnapShot snapShot){
|
||||
log(INFO,"db store snapshot [%d]",snapShot.getIndex());
|
||||
|
||||
executeVerySimpleQuery("INSERT INTO snapshots (id,device,snap_id,timestamp,counters,analogs,inputs,outputs,pullups,inverts,field0) VALUES(uuid(),?,?,?,?,?,?,?,?,?,?)",
|
||||
snapShot.getDeviceSerial(),
|
||||
snapShot.getIndex(),
|
||||
snapShot.getTimestamp(),
|
||||
snapShot.getValues(),
|
||||
snapShot.getAnalog(),
|
||||
snapShot.getInputmask(),
|
||||
snapShot.getOutputmask(),
|
||||
snapShot.getPullupmask(),
|
||||
snapShot.getInvertmask(),
|
||||
snapShot.getField0()
|
||||
);
|
||||
}
|
||||
|
||||
public void deleteSnapshot(SnapShot snapShot){
|
||||
log(INFO,"db delete snapshot [%d]",snapShot.getIndex());
|
||||
executeVerySimpleQuery("DELETE FROM snapshots WHERE device=? AND snap_id=?", snapShot.getDeviceSerial(),snapShot.getIndex());
|
||||
}
|
||||
|
||||
|
||||
public int highestSnapShot(int deviceSerial){
|
||||
Integer ind = (Integer)executeSimpleQueryObject("SELECT max(snap_id) FROM snapshots WHERE device=? GROUP BY device", deviceSerial);
|
||||
if (ind == null){
|
||||
return -1;
|
||||
} else {
|
||||
return ind;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer[] getKnownDevices(){
|
||||
List<Integer> devices = new LinkedList<>();
|
||||
|
||||
ResultSet result = executeSimpleSQL("SELECT DISTINCT device FROM snapshots ORDER BY device");
|
||||
try {
|
||||
while (result.next()){
|
||||
devices.add( result.getInt(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log(e);
|
||||
}
|
||||
return devices.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
public SnapShot[] loadSnapshots(int fromTimestamp,int deviceSerial){
|
||||
List<SnapShot> snapshots = new LinkedList<>();
|
||||
|
||||
ResultSet result = executeSimpleSQL("SELECT id,device,snap_id,timestamp,counters,analogs,inputs,outputs,pullups,inverts,field0 FROM snapshots WHERE timestamp >= ? AND device = ? ORDER BY device,timestamp", fromTimestamp, deviceSerial);
|
||||
try {
|
||||
while (result.next()){
|
||||
|
||||
SnapShot ss = new SnapShot(result);
|
||||
snapshots.add(ss);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
return snapshots.toArray(new SnapShot[0]);
|
||||
}
|
||||
|
||||
public SimpleScript[] getSimpleScripts(){
|
||||
ResultSet result = executeSimpleSQL("SELECT id,name,description,elements FROM scripts");
|
||||
ArrayList<SimpleScript> r = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
||||
while (result.next()){
|
||||
r.add(new SimpleScript(UUID.fromString(result.getString(1)), result.getString(2), result.getString(3), ArrayHelper.cast((Object[])result.getArray(4).getArray(),new Integer[0])));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
|
||||
return r.toArray(new SimpleScript[0]);
|
||||
}
|
||||
public void removeSimpleScript(UUID id){
|
||||
executeSimpleQueryObject("DELETE FROM scripts WHERE id=?", id);
|
||||
}
|
||||
public void storeSimpleScript(SimpleScript simpleScript){
|
||||
|
||||
|
||||
/* executeSimpleQueryObject("MERGE INTO scripts USING (VALUES ?,?,?,?) AS ins(uid,name,desc,elements) ON scripts.id=ins.uid WHEN MATCHED THEN UPDATE SET scripts.name=ins.name,scripts.description=ins.desc,scripts.elements=ins.elements WHEN NOT MATCHED THEN INSERT (id,name,description,elements) VALUES(ins.uid,ins.name,ins.desc,ins.elements)",
|
||||
simpleScript.getId().toString(),
|
||||
simpleScript.getName(),
|
||||
simpleScript.getDescription(),
|
||||
simpleScript.getSimpleScriptElementsAsInt()
|
||||
);
|
||||
*/
|
||||
executeSimpleSQL("DELETE FROM scripts WHERE id=?",simpleScript.getId());
|
||||
executeSimpleSQL("INSERT INTO scripts VALUES(?,?,?,?)",
|
||||
simpleScript.getId(),
|
||||
simpleScript.getName(),
|
||||
simpleScript.getDescription(),
|
||||
simpleScript.getSimpleScriptElementsAsInteger()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ObjectTable getSnapshotsAsTable(int deviceSerial){
|
||||
ObjectTable ot = new ObjectTable();
|
||||
|
||||
for (SnapShot ss: loadSnapshots(0,deviceSerial)){
|
||||
ot.add( ss.getCSVRecord(true).getValuesAsArray() );
|
||||
|
||||
}
|
||||
return ot;
|
||||
}
|
||||
|
||||
public void calulateTableDeltas(ObjectTable objectTable){
|
||||
ObjectSet tmp = objectTable.new ObjectSet();
|
||||
|
||||
for (ObjectSet row: objectTable.getRows()){
|
||||
for (int p=4;p<36;p++){
|
||||
int i = row.getInteger(p) - tmp.getInteger(p);
|
||||
tmp.set(p,row.getInteger(p));
|
||||
row.set(p,i);;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// synololog sql database schema
|
||||
//
|
||||
// Version: 0
|
||||
//
|
||||
//
|
||||
create table if not exists props (id uuid primary key,name varchar(255) unique,value varchar(255));
|
||||
create table if not exists devices (id uuid,serial varchar(12));
|
||||
create table if not exists snapshots (id uuid,device integer,snap_id integer,timestamp integer,counters integer array[32],analogs integer array[8],inputs integer,outputs integer,pullups integer,inverts integer,field0 integer);
|
||||
|
||||
create table if not exists scripts (id uuid primary key,name varchar(128),description longvarchar,elements integer ARRAY[512] default ARRAY[]);
|
||||
|
||||
delete from props where name='db.schema.version';
|
||||
insert into props (id,name,value) values(uuid(),'db.schema.version','0');
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
|
||||
public interface IDeviceConnector {
|
||||
public static int ESC_PREPARE_DEVICETEST = 0x00000001;
|
||||
public static int ESC_UNPREPARE_DEVICETEST = 0x00000002;
|
||||
|
||||
public static int ESC_DEBUG_MASK = 0xFFFF0000;
|
||||
public static int ESC_DEBUG_SCHEDULER_BUG = 0x00010000;
|
||||
|
||||
|
||||
public Integer getDeviceSerial();
|
||||
|
||||
public boolean showConnctionSetup(Component parent);
|
||||
public String getConnectionSettings();
|
||||
public void setConnectionSettings(String connectionSettings);
|
||||
public String getConnectionSettingsText();
|
||||
|
||||
public int[] getCounters();
|
||||
public void setCounters(int[] values);
|
||||
|
||||
public int getCounter(int channel);
|
||||
public void setCounter(int channel,int counter);
|
||||
|
||||
public float[] getAnalogs();
|
||||
public float getAnalog(int channel);
|
||||
|
||||
public int[] getSimpleScript();
|
||||
public void setSimpleScript(int[] simpleScript);
|
||||
|
||||
public int getInputs();
|
||||
public int getOutputs();
|
||||
public void setOutputs(int outputs);
|
||||
public int getPullups();
|
||||
public void setPullups(int pullups);
|
||||
public int getInverts();
|
||||
public void setInverts(int inverts);
|
||||
public int getTriggers();
|
||||
public void setTriggers(int triggers);
|
||||
|
||||
public int getConfigOutputs();
|
||||
public void setConfigOutputs(int outputs);
|
||||
public int getConfigPullups();
|
||||
public void setConfigPullups(int pullups);
|
||||
public int getConfigInverts();
|
||||
public void setConfigInverts(int inverts);
|
||||
public int getConfigTriggers();
|
||||
public void setConfigTriggers(int triggers);
|
||||
|
||||
|
||||
public int[] getDebounce();
|
||||
public void setDebounce(int[] filters);
|
||||
|
||||
public int[] getWindows();
|
||||
public void setWindows(int[] windows);
|
||||
|
||||
public int[] getIncrements();
|
||||
public void setIncrements(int[] increments);
|
||||
|
||||
public int getInterval(int iNo);
|
||||
public boolean isIntervalDailyBased(int iNo);
|
||||
public void setInterval(int iNo,Integer intervall,boolean dailyBase);
|
||||
public int getDailyBaseMask();
|
||||
|
||||
|
||||
public int getHighestSnapShotIndex();
|
||||
public SnapShot[]
|
||||
readSnapShots(int startIndex);
|
||||
|
||||
public void reset(int flags);
|
||||
public int escape(int escape,int parm);
|
||||
|
||||
public void syncConfigToLive();
|
||||
|
||||
public void shutdown();
|
||||
|
||||
public void checkRealTimeClock();
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
public class NoDeviceConnectionException extends RuntimeException {
|
||||
|
||||
public NoDeviceConnectionException(){
|
||||
|
||||
}
|
||||
public NoDeviceConnectionException(Exception cause){
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,848 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement;
|
||||
import org.hwo.pulscounter.ui.DeviceConfiguration;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.exceptions.*;
|
||||
import org.hwo.ui.dialog.SerialPortChooser;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
public class ServiceLinkDeviceConnector implements IDeviceConnector {
|
||||
|
||||
private ServiceLink serviceLink;
|
||||
private Integer deviceSerial;
|
||||
|
||||
private int debugMode;
|
||||
|
||||
public ServiceLinkDeviceConnector() {
|
||||
serviceLink = new ServiceLink(new NewSerialPort("COM1:"));
|
||||
|
||||
}
|
||||
|
||||
private void checkOpen(){
|
||||
if (!serviceLink.isOpen()){
|
||||
try {
|
||||
serviceLink.open();
|
||||
serviceLink.getSerialPort().setTimeOut(250);
|
||||
} catch (ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Serial [%s]", this.serviceLink.getSerialPort().getPortName());
|
||||
}
|
||||
|
||||
public ServiceLink getServiceLink() {
|
||||
return serviceLink;
|
||||
}
|
||||
|
||||
private Integer readDeviceSerial(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0001 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDeviceSerial() {
|
||||
Integer serial = readDeviceSerial();
|
||||
deviceSerial = serial;
|
||||
return serial;
|
||||
}
|
||||
|
||||
public void setDeviceSerial(int serial) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0004, -1895890944);
|
||||
serviceLink.writeInt(13, 0, 0x0001, serial );
|
||||
serviceLink.writeInt(13, 0, 0x0004, 0x0);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConnctionSetup(Component parent) {
|
||||
NewSerialPort newSerialPort = SerialPortChooser.execute(parent,serviceLink.getSerialPort().getPortName());
|
||||
if (newSerialPort != null){
|
||||
serviceLink.close();
|
||||
serviceLink.getSerialPort().setPortName(newSerialPort.getPortName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettings() {
|
||||
return serviceLink.getSerialPort().getPortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionSettings(String connectionSettings) {
|
||||
serviceLink.close();
|
||||
serviceLink.getSerialPort().setPortName(connectionSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettingsText() {
|
||||
return String.format("Port: %s",getConnectionSettings());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getCounters() {
|
||||
int[] values = new int[32];
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
values[n] = getCounter(n);
|
||||
}
|
||||
|
||||
checkRealTimeClock();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounters(int[] values) {
|
||||
for (int n=0;n<32;n++){
|
||||
setCounter(n, values[n]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCounter(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x600 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounter(int channel, int counter) {
|
||||
checkOpen();
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0600 + channel, counter);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSimpleScript() {
|
||||
try {
|
||||
Integer l = serviceLink.readInt(13, 0, 0x0700);
|
||||
|
||||
log(DEBUG,"%d ScriptElements on Device.",l);
|
||||
|
||||
if (l<=0)
|
||||
return new int[0];
|
||||
|
||||
int[] script = new int[l];
|
||||
int p;
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x0701, 0);
|
||||
for (p=0;p<l;p++){
|
||||
script[p] = serviceLink.readInt(13, 0, 0x0702);
|
||||
SimpleScriptElement e = new SimpleScriptElement(script[p]);
|
||||
log(DEBUG,"Element: 0x%08x [A=0x%02x B=0x%02x C=0x%02x O=0x%02x Z=0x%02x]",script[p],e.getA(),e.getB(),e.getCondition(),e.getOperation(),e.getZ());
|
||||
}
|
||||
|
||||
log(INFO,"%d von %d Skript Elementen empfangen.",p,l);
|
||||
|
||||
return script;
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSimpleScript(int[] simpleScript) {
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0700, simpleScript.length);
|
||||
|
||||
for (int i=0;i<simpleScript.length;i++){
|
||||
serviceLink.writeInt(13, 0, 0x0702, simpleScript[i]);
|
||||
SimpleScriptElement e = new SimpleScriptElement(simpleScript[i]);
|
||||
log(DEBUG,"Element: 0x%08x [A=0x%02x B=0x%02x C=0x%02x O=0x%02x Z=0x%02x]",simpleScript[i],e.getA(),e.getB(),e.getCondition(),e.getOperation(),e.getZ());
|
||||
}
|
||||
|
||||
Integer p = serviceLink.readInt(13, 0, 0x0701);
|
||||
if (!p.equals(simpleScript.length)){
|
||||
log(INFO,"ServiceLinkDeviceConnector: Skript konnte nicht geschrieben werden (%d von %d Elementen erkannt)",p,simpleScript.length);
|
||||
} else {
|
||||
serviceLink.writeInt(13, 0, 0x0703, 1);
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0681 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0682 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int outputs) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0682, outputs);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPullups() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0683 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPullups(int pullups) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0683, pullups);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInverts() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0684 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverts(int inverts) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0684, inverts);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getTriggers(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x0685 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void setTriggers(int triggers){
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0685, triggers);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
float[] values = new float[32];
|
||||
|
||||
for (int n=0;n<8;n++){
|
||||
values[n] = getAnalog(n);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x8000 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return (v / 6553.60f);
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestSnapShotIndex() {
|
||||
Integer s = readDeviceSerial();
|
||||
|
||||
if (s != null){
|
||||
try {
|
||||
return serviceLink.readInt(13, 0, 0x0581);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(ERROR,"ServiceLinkDeviceConnector: getHighestSnapShotIndex(): Exception: %s",e.toString());
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot[] readSnapShots(int startIndex) {
|
||||
Integer s = readDeviceSerial();
|
||||
List<SnapShot> snapshots = new LinkedList<>();
|
||||
|
||||
if (s != null){
|
||||
Integer newest,sssize;
|
||||
int ind;
|
||||
Integer id;
|
||||
|
||||
try {
|
||||
Integer sbrk,stacklimit,cycletime,enginestate;
|
||||
|
||||
sbrk = serviceLink.readInt(13, 0, 0x0020);
|
||||
stacklimit = serviceLink.readInt(13, 0, 0x0021);
|
||||
cycletime = serviceLink.readInt(13, 0, 0x1310);
|
||||
enginestate = serviceLink.readInt(13, 0, 0x0703);
|
||||
|
||||
log(INFO,"HEAP END: 0x%04x SYS-STACK: 0x%04x",sbrk,stacklimit);
|
||||
log(INFO,"I/O cycle time: %dus",cycletime);
|
||||
log(INFO,"Engine-State: 0x%08x",enginestate);
|
||||
|
||||
newest = serviceLink.readInt(13, 0, 0x0581);
|
||||
sssize = serviceLink.readInt(13, 0, 0x0582);
|
||||
|
||||
if ((newest == null) || (sssize == null)){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (startIndex < (newest - sssize)){
|
||||
startIndex = newest - sssize;
|
||||
}
|
||||
if (startIndex < 0){
|
||||
startIndex = 0;
|
||||
}
|
||||
|
||||
log(INFO,"ServiceLinkDeviceConnector: reading snapshots [%d ... %d]",startIndex,newest);
|
||||
|
||||
for (ind = startIndex; ind <= newest; ind++){
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0500, ind);
|
||||
id = serviceLink.readInt(13, 0, 0x0500);
|
||||
if (!id.equals(ind)){
|
||||
log(WARN,"Snapshot could not be selected [%d != %d]",ind,id);
|
||||
} else {
|
||||
Integer timestamp,
|
||||
flags,
|
||||
in,
|
||||
out,
|
||||
pu,
|
||||
inv,
|
||||
trigger;
|
||||
|
||||
Integer[] counters,
|
||||
analogs;
|
||||
|
||||
timestamp = serviceLink.readInt(13, 0, 0x0501);
|
||||
flags = serviceLink.readInt(13, 0, 0x0502);
|
||||
in = serviceLink.readInt(13, 0, 0x0503);
|
||||
out = serviceLink.readInt(13, 0, 0x0504);
|
||||
pu = serviceLink.readInt(13, 0, 0x0505);
|
||||
inv = serviceLink.readInt(13, 0, 0x0506);
|
||||
trigger = serviceLink.readInt(13, 0, 0x0507);
|
||||
id = serviceLink.readInt(13, 0, 0x0530);
|
||||
|
||||
counters = new Integer[32];
|
||||
analogs = new Integer[8];
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
counters[n] = serviceLink.readInt(13, 0, 0x0510 + n);
|
||||
}
|
||||
for (int n=0;n<8;n++){
|
||||
analogs[n] = serviceLink.readInt(13, 0, 0x0508 + n);
|
||||
}
|
||||
|
||||
|
||||
SnapShot ss = new SnapShot(s);
|
||||
ss.setTimestamp(timestamp);
|
||||
ss.setIndex(id);
|
||||
ss.setField0(flags);
|
||||
ss.setInputmask(in);
|
||||
ss.setOutputmask(out);
|
||||
ss.setInvertmask(inv);
|
||||
ss.setTriggermask(trigger);
|
||||
ss.setPullupmask(pu);
|
||||
for (int i=0;i<32;i++){
|
||||
ss.setValue(i, counters[i]);
|
||||
}
|
||||
for (int i=0;i<8;i++){
|
||||
ss.setAnalog(i, analogs[i]);
|
||||
}
|
||||
|
||||
log(INFO,"Snapshot read: %s",id);
|
||||
snapshots.add(ss);
|
||||
|
||||
};
|
||||
} catch (ServiceLinkRequestFailedException e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
checkForAssertions();
|
||||
|
||||
}
|
||||
return snapshots.toArray(new SnapShot[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInterval(int iNo) {
|
||||
checkOpen();
|
||||
|
||||
iNo %= 4;
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1010 + iNo );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntervalDailyBased(int iNo) {
|
||||
iNo %= 4;
|
||||
return ((getDailyBaseMask() & (1<<iNo))!=0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInterval(int iNo, Integer intervall, boolean dailyBase) {
|
||||
checkOpen();
|
||||
|
||||
iNo %= 4;
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1003 );
|
||||
|
||||
if (dailyBase){
|
||||
v |= (1<<iNo);
|
||||
} else {
|
||||
v &= ~(1<<iNo);
|
||||
}
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x1003, v);
|
||||
serviceLink.writeInt(13, 0, 0x1010 + iNo , intervall == null ? 0 : intervall);
|
||||
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDailyBaseMask() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1003 );
|
||||
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private int getDebounce(int channel){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1020 + channel );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private void setDebounce(int channel,int value){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x1020 + channel, value );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDebounce() {
|
||||
int[] filters = new int[32];
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
filters[i] = getDebounce(i);
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebounce(int[] filters) {
|
||||
for (int i=0;i<32;i++){
|
||||
setDebounce(i,filters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private int getWindow(int channel){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1280 + channel );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private void setWindow(int channel,int value){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x1280 + channel, value );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getWindows() {
|
||||
int[] windows = new int[32];
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
windows[i] = getWindow(i);
|
||||
}
|
||||
|
||||
return windows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindows(int[] windows) {
|
||||
for (int i=0;i<32;i++){
|
||||
setWindow(i,windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncConfigToLive() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x1001, 1 );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(int flags) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0581, flags );
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigOutputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1008 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigOutputs(int outputs) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x1008, outputs);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigPullups() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x1009 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigPullups(int pullups) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x1009, pullups);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigInverts() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x100A );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigInverts(int inverts) {
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x100A, inverts);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getConfigTriggers(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = serviceLink.readInt(13, 0, 0x100B );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void setConfigTriggers(int triggers){
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x100B, triggers);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
};
|
||||
|
||||
public void checkRealTimeClock(){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
try {
|
||||
Integer deviceTime = serviceLink.readInt(13, 0, 0x001C);
|
||||
Long currentTime = (System.currentTimeMillis()/1000);
|
||||
|
||||
if (debugMode != ESC_DEBUG_SCHEDULER_BUG){
|
||||
Long delta = deviceTime - currentTime;
|
||||
if ((delta < -1) || (delta > 1)){
|
||||
log(INFO,"realtime clock has a %d seconds shift",delta);
|
||||
serviceLink.writeInt((byte)13, (byte)0, 0x001C, (int)(calendar.getTimeInMillis() / 1000L));
|
||||
log(INFO,"realtime clock has been corrected.");
|
||||
}
|
||||
} else {
|
||||
log(DEBUG,"SCHEDULER_DEBUG: DeviceTime is %s",DateFormat.getInstance().format(new Date(((long)deviceTime)*1000)));
|
||||
}
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkForAssertions(){
|
||||
Integer assert_error,assert_code;
|
||||
|
||||
try
|
||||
{
|
||||
assert_error = -1;
|
||||
for (int i=0;i<8;i++){
|
||||
assert_error = serviceLink.readInt(13, 0, 0x0026);
|
||||
assert_code = serviceLink.readInt(13, 0, 0x0025);
|
||||
|
||||
if (assert_error >= 0)
|
||||
break;
|
||||
|
||||
log(WARN,"Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff);
|
||||
serviceLink.writeInt(13, 0, 0x0025, -1);
|
||||
};
|
||||
} catch (Exception ex){
|
||||
System.err.println("Exception while checking for assertions...");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int escape(int escape, int parm) {
|
||||
if ((escape & ESC_DEBUG_MASK)!=0){
|
||||
debugMode = escape;
|
||||
}
|
||||
|
||||
switch (escape){
|
||||
case ESC_DEBUG_SCHEDULER_BUG:
|
||||
try {
|
||||
Long currentTime = (System.currentTimeMillis()/1000);
|
||||
currentTime -= currentTime % 86400;
|
||||
currentTime += -920;
|
||||
log(DEBUG,"ESC_DEBUG_SCHEDULER_BUG");
|
||||
serviceLink.writeInt((byte)13, (byte)0, 0x001C, (currentTime.intValue()));
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
case ESC_PREPARE_DEVICETEST:
|
||||
log(DEBUG,"Prepare Device for testing.");
|
||||
serviceLink.setForceSynchronousRequests(true);
|
||||
return 0;
|
||||
case ESC_UNPREPARE_DEVICETEST:
|
||||
log(DEBUG,"Un-Prepare Device after testing.");
|
||||
serviceLink.setForceSynchronousRequests(false);
|
||||
return 0;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIncrements() {
|
||||
int[] values = new int[32];
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
values[n] = getIncrement(n);
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIncrements(int[] increments) {
|
||||
for (int n=0;n<32;n++){
|
||||
setIncrement(n, increments[n]);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIncrement(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
v = serviceLink.readInt(13, 0, 0x12A0 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIncrement(int channel, int increment) {
|
||||
checkOpen();
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x12A0 + channel, increment);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
serviceLink.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,869 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.ArrayHelper;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement;
|
||||
import org.hwo.pulscounter.ui.DeviceConfiguration;
|
||||
import org.hwo.servicelink.SimpleLink;
|
||||
import org.hwo.servicelink.exceptions.*;
|
||||
import org.hwo.ui.dialog.SerialPortChooser;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
public class SimpleLinkDeviceConnector implements IDeviceConnector {
|
||||
|
||||
private SimpleLink simpleLink;
|
||||
private Integer deviceSerial;
|
||||
|
||||
private int debugMode;
|
||||
|
||||
public SimpleLinkDeviceConnector() {
|
||||
simpleLink = new SimpleLink(new NewSerialPort("COM1:"));
|
||||
|
||||
}
|
||||
|
||||
private void checkOpen(){
|
||||
if (!simpleLink.isOpen()){
|
||||
try {
|
||||
simpleLink.open();
|
||||
simpleLink.setTimeOut(1000);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Serial [%s]", this.simpleLink.getSerialPort().getPortName());
|
||||
}
|
||||
|
||||
public SimpleLink getSimpleLink() {
|
||||
return simpleLink;
|
||||
}
|
||||
|
||||
private Integer readDeviceSerial(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt(0x0001);
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDeviceSerial() {
|
||||
Integer serial = readDeviceSerial();
|
||||
deviceSerial = serial;
|
||||
return serial;
|
||||
}
|
||||
|
||||
public void setDeviceSerial(int serial) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
simpleLink.writeInt(0x0004, -1895890944);
|
||||
simpleLink.writeInt(0x0001, serial );
|
||||
simpleLink.writeInt(0x0004, 0x0);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConnctionSetup(Component parent) {
|
||||
NewSerialPort newSerialPort = SerialPortChooser.execute(parent,simpleLink.getSerialPort().getPortName());
|
||||
if (newSerialPort != null){
|
||||
simpleLink.close();
|
||||
simpleLink.getSerialPort().setPortName(newSerialPort.getPortName());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettings() {
|
||||
return simpleLink.getSerialPort().getPortName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionSettings(String connectionSettings) {
|
||||
simpleLink.close();
|
||||
simpleLink.getSerialPort().setPortName(connectionSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettingsText() {
|
||||
return String.format("Port: %s",getConnectionSettings());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getCounters() {
|
||||
checkOpen();
|
||||
|
||||
checkRealTimeClock();
|
||||
|
||||
try {
|
||||
return ArrayHelper.unbox(this.simpleLink.readInt(0x0600,32));
|
||||
} catch (ServiceLinkException | IOException e){
|
||||
log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounters(int[] values) {
|
||||
try {
|
||||
simpleLink.writeInt(0x0600, values);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCounter(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
v = simpleLink.readInt( 0x0600 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounter(int channel, int counter) {
|
||||
checkOpen();
|
||||
try {
|
||||
simpleLink.writeInt(0x0600 + channel, counter);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSimpleScript() {
|
||||
try {
|
||||
Integer l = simpleLink.readInt(0x0700);
|
||||
|
||||
log(DEBUG,"%d ScriptElements on Device.",l);
|
||||
|
||||
if (l<=0)
|
||||
return new int[0];
|
||||
|
||||
int[] script = new int[l];
|
||||
int p;
|
||||
|
||||
simpleLink.writeInt(0x0701, 0);
|
||||
for (p=0;p<l;p++){
|
||||
script[p] = simpleLink.readInt(0x0702);
|
||||
SimpleScriptElement e = new SimpleScriptElement(script[p]);
|
||||
log(DEBUG,"Element: 0x%08x [A=0x%02x B=0x%02x C=0x%02x O=0x%02x Z=0x%02x]",script[p],e.getA(),e.getB(),e.getCondition(),e.getOperation(),e.getZ());
|
||||
}
|
||||
|
||||
log(INFO,"%d von %d Skript Elementen empfangen.",p,l);
|
||||
|
||||
return script;
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSimpleScript(int[] simpleScript) {
|
||||
|
||||
try {
|
||||
simpleLink.writeInt( 0x0700, simpleScript.length);
|
||||
|
||||
for (int i=0;i<simpleScript.length;i++){
|
||||
simpleLink.writeInt( 0x0702, simpleScript[i]);
|
||||
SimpleScriptElement e = new SimpleScriptElement(simpleScript[i]);
|
||||
log(DEBUG,"Element: 0x%08x [A=0x%02x B=0x%02x C=0x%02x O=0x%02x Z=0x%02x]",simpleScript[i],e.getA(),e.getB(),e.getCondition(),e.getOperation(),e.getZ());
|
||||
}
|
||||
|
||||
Integer p = simpleLink.readInt( 0x0701);
|
||||
if (!p.equals(simpleScript.length)){
|
||||
log(INFO,"ServiceLinkDeviceConnector: Skript konnte nicht geschrieben werden (%d von %d Elementen erkannt)",p,simpleScript.length);
|
||||
} else {
|
||||
simpleLink.writeInt(0x0703, 1);
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x0681 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x0682 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int outputs) {
|
||||
try {
|
||||
simpleLink.writeInt(0x0682, outputs);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPullups() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x0683 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPullups(int pullups) {
|
||||
try {
|
||||
simpleLink.writeInt(0x0683, pullups);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInverts() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x0684 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverts(int inverts) {
|
||||
try {
|
||||
simpleLink.writeInt(0x0684, inverts);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getTriggers(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x0685 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void setTriggers(int triggers){
|
||||
try {
|
||||
simpleLink.writeInt(0x0685, triggers);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer[] values = this.simpleLink.readInt(0x8000, 8);
|
||||
float[] analogs = new float[8];
|
||||
|
||||
for (int n=0;n<8;n++){
|
||||
if (values[n] != null){
|
||||
analogs[n] = (values[n] / 6553.60f);
|
||||
}
|
||||
}
|
||||
|
||||
return analogs;
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
|
||||
try {
|
||||
v = simpleLink.readInt( 0x8000 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return (v / 6553.60f);
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestSnapShotIndex() {
|
||||
Integer s = readDeviceSerial();
|
||||
|
||||
if (s != null){
|
||||
try {
|
||||
return simpleLink.readInt(0x0581);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(ERROR,"ServiceLinkDeviceConnector: getHighestSnapShotIndex(): Exception: %s",e.toString());
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot[] readSnapShots(int startIndex) {
|
||||
Integer s = readDeviceSerial();
|
||||
List<SnapShot> snapshots = new LinkedList<>();
|
||||
|
||||
if (s != null){
|
||||
Integer newest,sssize;
|
||||
int ind;
|
||||
Integer id;
|
||||
|
||||
try {
|
||||
Integer sbrk,stacklimit,cycletime,enginestate;
|
||||
Integer[] rd = simpleLink.readInt(new int[]{0x0020,0x0021,0x1310,0x0703});
|
||||
sbrk = rd[0];
|
||||
stacklimit = rd[1];
|
||||
cycletime = rd[2];
|
||||
enginestate = rd[3];
|
||||
|
||||
log(INFO,"HEAP END: 0x%04x SYS-STACK: 0x%04x",sbrk,stacklimit);
|
||||
log(INFO,"I/O cycle time: %dus",cycletime);
|
||||
log(INFO,"Engine-State: 0x%08x",enginestate);
|
||||
|
||||
newest = simpleLink.readInt(0x0581);
|
||||
sssize = simpleLink.readInt(0x0582);
|
||||
|
||||
if ((newest == null) || (sssize == null)){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (startIndex < (newest - sssize)){
|
||||
startIndex = newest - sssize;
|
||||
}
|
||||
if (startIndex < 0){
|
||||
startIndex = 0;
|
||||
}
|
||||
|
||||
log(INFO,"ServiceLinkDeviceConnector: reading snapshots [%d ... %d]",startIndex,newest);
|
||||
|
||||
for (ind = startIndex; ind <= newest; ind++){
|
||||
try {
|
||||
simpleLink.writeInt(0x0500, ind);
|
||||
id = simpleLink.readInt(0x0500);
|
||||
if (!id.equals(ind)){
|
||||
log(WARN,"Snapshot could not be selected [%d != %d]",ind,id);
|
||||
} else {
|
||||
Integer timestamp,
|
||||
flags,
|
||||
in,
|
||||
out,
|
||||
pu,
|
||||
inv,
|
||||
trigger;
|
||||
|
||||
Integer[] counters,
|
||||
analogs;
|
||||
|
||||
timestamp = simpleLink.readInt(0x0501);
|
||||
flags = simpleLink.readInt(0x0502);
|
||||
in = simpleLink.readInt(0x0503);
|
||||
out = simpleLink.readInt(0x0504);
|
||||
pu = simpleLink.readInt(0x0505);
|
||||
inv = simpleLink.readInt(0x0506);
|
||||
trigger = simpleLink.readInt(0x0507);
|
||||
id = simpleLink.readInt(0x0530);
|
||||
|
||||
counters = new Integer[32];
|
||||
analogs = new Integer[8];
|
||||
|
||||
for (int n=0;n<32;n++){
|
||||
counters[n] = simpleLink.readInt(0x0510 + n);
|
||||
}
|
||||
for (int n=0;n<8;n++){
|
||||
analogs[n] = simpleLink.readInt(0x0508 + n);
|
||||
}
|
||||
|
||||
|
||||
SnapShot ss = new SnapShot(s);
|
||||
ss.setTimestamp(timestamp);
|
||||
ss.setIndex(id);
|
||||
ss.setField0(flags);
|
||||
ss.setInputmask(in);
|
||||
ss.setOutputmask(out);
|
||||
ss.setInvertmask(inv);
|
||||
ss.setTriggermask(trigger);
|
||||
ss.setPullupmask(pu);
|
||||
for (int i=0;i<32;i++){
|
||||
ss.setValue(i, counters[i]);
|
||||
}
|
||||
for (int i=0;i<8;i++){
|
||||
ss.setAnalog(i, analogs[i]);
|
||||
}
|
||||
|
||||
log(INFO,"Snapshot read: %s",id);
|
||||
snapshots.add(ss);
|
||||
|
||||
};
|
||||
} catch (ServiceLinkRequestFailedException e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
checkForAssertions();
|
||||
|
||||
}
|
||||
return snapshots.toArray(new SnapShot[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInterval(int iNo) {
|
||||
checkOpen();
|
||||
|
||||
iNo %= 4;
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1010 + iNo );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntervalDailyBased(int iNo) {
|
||||
iNo %= 4;
|
||||
return ((getDailyBaseMask() & (1<<iNo))!=0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInterval(int iNo, Integer intervall, boolean dailyBase) {
|
||||
checkOpen();
|
||||
|
||||
iNo %= 4;
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1003 );
|
||||
|
||||
if (dailyBase){
|
||||
v |= (1<<iNo);
|
||||
} else {
|
||||
v &= ~(1<<iNo);
|
||||
}
|
||||
|
||||
simpleLink.writeInt(0x1003, v);
|
||||
simpleLink.writeInt(0x1010 + iNo , intervall == null ? 0 : intervall);
|
||||
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDailyBaseMask() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1003 );
|
||||
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private int getDebounce(int channel){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1020 + channel );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private void setDebounce(int channel,int value){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
simpleLink.writeInt( 0x1020 + channel, value );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDebounce() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
return ArrayHelper.unbox(this.simpleLink.readInt(0x1020,32));
|
||||
} catch (ServiceLinkException | IOException e){
|
||||
log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebounce(int[] filters) {
|
||||
try {
|
||||
this.simpleLink.writeInt(0x1020, filters);
|
||||
} catch (ServiceLinkException | IOException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private int getWindow(int channel){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1280 + channel );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
private void setWindow(int channel,int value){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
simpleLink.writeInt( 0x1280 + channel, value );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getWindows() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
return ArrayHelper.unbox(this.simpleLink.readInt(0x1280,32));
|
||||
} catch (ServiceLinkException | IOException e){
|
||||
log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindows(int[] windows) {
|
||||
for (int i=0;i<32;i++){
|
||||
setWindow(i,windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncConfigToLive() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
|
||||
simpleLink.writeInt( 0x1001, 1 );
|
||||
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset(int flags) {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
simpleLink.writeInt( 0x0581, flags );
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigOutputs() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1008 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigOutputs(int outputs) {
|
||||
try {
|
||||
simpleLink.writeInt(0x1008, outputs);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigPullups() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x1009 );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigPullups(int pullups) {
|
||||
try {
|
||||
simpleLink.writeInt(0x1009, pullups);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigInverts() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x100A );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigInverts(int inverts) {
|
||||
try {
|
||||
simpleLink.writeInt(0x100A, inverts);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getConfigTriggers(){
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
Integer v = simpleLink.readInt( 0x100B );
|
||||
return v;
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void setConfigTriggers(int triggers){
|
||||
try {
|
||||
simpleLink.writeInt(0x100B, triggers);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
};
|
||||
|
||||
public void checkRealTimeClock(){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
try {
|
||||
checkOpen();
|
||||
|
||||
Integer deviceTime = simpleLink.readInt(0x001C);
|
||||
Long currentTime = (System.currentTimeMillis()/1000);
|
||||
|
||||
if (debugMode != ESC_DEBUG_SCHEDULER_BUG){
|
||||
Long delta = deviceTime - currentTime;
|
||||
if ((delta < -1) || (delta > 1)){
|
||||
log(INFO,"realtime clock has a %d seconds shift",delta);
|
||||
simpleLink.writeInt(0x001C, (int)(calendar.getTimeInMillis() / 1000L));
|
||||
log(INFO,"realtime clock has been corrected.");
|
||||
}
|
||||
} else {
|
||||
log(DEBUG,"SCHEDULER_DEBUG: DeviceTime is %s",DateFormat.getInstance().format(new Date(((long)deviceTime)*1000)));
|
||||
}
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkForAssertions(){
|
||||
Integer assert_error,assert_code;
|
||||
|
||||
try
|
||||
{
|
||||
assert_error = -1;
|
||||
for (int i=0;i<8;i++){
|
||||
assert_error = simpleLink.readInt(0x0026);
|
||||
assert_code = simpleLink.readInt(0x0025);
|
||||
|
||||
if (assert_error >= 0)
|
||||
break;
|
||||
|
||||
log(WARN,"Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff);
|
||||
simpleLink.writeInt(0x0025, -1);
|
||||
};
|
||||
} catch (Exception ex){
|
||||
System.err.println("Exception while checking for assertions...");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int escape(int escape, int parm) {
|
||||
if ((escape & ESC_DEBUG_MASK)!=0){
|
||||
debugMode = escape;
|
||||
}
|
||||
|
||||
switch (escape){
|
||||
case ESC_DEBUG_SCHEDULER_BUG:
|
||||
try {
|
||||
Long currentTime = (System.currentTimeMillis()/1000);
|
||||
currentTime -= currentTime % 86400;
|
||||
currentTime += -920;
|
||||
log(DEBUG,"ESC_DEBUG_SCHEDULER_BUG");
|
||||
simpleLink.writeInt(0x001C, (currentTime.intValue()));
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return 0;
|
||||
case ESC_PREPARE_DEVICETEST:
|
||||
log(DEBUG,"Prepare Device for testing.");
|
||||
return 0;
|
||||
case ESC_UNPREPARE_DEVICETEST:
|
||||
log(DEBUG,"Un-Prepare Device after testing.");
|
||||
return 0;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIncrements() {
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
return ArrayHelper.unbox(this.simpleLink.readInt(0x12A0,32));
|
||||
} catch (ServiceLinkException | IOException e){
|
||||
log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIncrements(int[] increments) {
|
||||
for (int n=0;n<32;n++){
|
||||
setIncrement(n, increments[n]);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIncrement(int channel) {
|
||||
Integer v = null;
|
||||
|
||||
checkOpen();
|
||||
|
||||
try {
|
||||
v = simpleLink.readInt( 0x12A0 + channel );
|
||||
} catch (Exception e) {
|
||||
throw new NoDeviceConnectionException();
|
||||
}
|
||||
if (v != null){
|
||||
return v;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIncrement(int channel, int increment) {
|
||||
checkOpen();
|
||||
try {
|
||||
simpleLink.writeInt(0x12A0 + channel, increment);
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
simpleLink.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,310 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.Random;
|
||||
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
|
||||
public class SimulatedCounter implements IDeviceConnector {
|
||||
|
||||
private int serial;
|
||||
private int[] values;
|
||||
private float[] analogs;
|
||||
|
||||
private int inputs,
|
||||
outputs,
|
||||
pullups,
|
||||
inverts;
|
||||
|
||||
private Random random;
|
||||
|
||||
private int[] scriptElements;
|
||||
|
||||
public SimulatedCounter() {
|
||||
random = new Random();
|
||||
serial = random.nextInt();
|
||||
|
||||
values = new int[32];
|
||||
analogs = new float[8];
|
||||
|
||||
for (int i=0;i<8;i++){
|
||||
analogs[i] = (float)(random.nextFloat() * 10.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Simulated Counter [%d]", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getDeviceSerial() {
|
||||
return serial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConnctionSetup(Component parent) {
|
||||
return SimulatedCounterSettingsDialog.show(parent,this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettings() {
|
||||
return String.format("%d", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectionSettings(String connectionSettings) {
|
||||
if (!connectionSettings.equals("")){
|
||||
log(INFO,"Simulated Counter changes serial %d -> %s",serial,connectionSettings);
|
||||
serial = Integer.parseInt(connectionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionSettingsText() {
|
||||
return String.format("Device Serial: %d\nSimulated Values", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getCounters() {
|
||||
int i = random.nextInt();
|
||||
|
||||
values[ i & 0x1F ] += random.nextInt() & 0x07;
|
||||
|
||||
for (i=0;i<8;i++){
|
||||
analogs[i] += (float)(random.nextFloat() * 0.6)-0.3;
|
||||
if (analogs[i] > 10.0f){
|
||||
analogs[i] = 10.0f;
|
||||
}
|
||||
if (analogs[i] < 0.0f){
|
||||
analogs[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inputs = random.nextInt();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounters(int[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCounter(int channel) {
|
||||
return values[channel];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCounter(int channel, int counter) {
|
||||
values[channel] = counter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getSimpleScript() {
|
||||
return scriptElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSimpleScript(int[] simpleScript) {
|
||||
scriptElements = simpleScript;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputs(int outputs) {
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPullups() {
|
||||
return pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPullups(int pullups) {
|
||||
this.pullups = pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInverts() {
|
||||
return inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInverts(int inverts) {
|
||||
this.inverts = inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTriggers() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void setTriggers(int triggers) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigOutputs(int outputs) {
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigPullups() {
|
||||
return pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigPullups(int pullups) {
|
||||
this.pullups = pullups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigInverts() {
|
||||
return inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigInverts(int inverts) {
|
||||
this.inverts = inverts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConfigTriggers() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void setConfigTriggers(int triggers) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public float[] getAnalogs() {
|
||||
return analogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnalog(int channel) {
|
||||
return analogs[channel];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHighestSnapShotIndex() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapShot[] readSnapShots(int startIndex) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInterval(int iNo) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntervalDailyBased(int iNo) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInterval(int iNo, Integer intervall, boolean dailyBase) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDebounce() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDebounce(int[] filters) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getWindows() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWindows(int[] windows) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDailyBaseMask() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncConfigToLive() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public void reset(int flags) {
|
||||
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public int escape(int escape, int parm) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getIncrements() {
|
||||
return new int[]{1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1};
|
||||
}
|
||||
@Override
|
||||
public void setIncrements(int[] triggers) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkRealTimeClock() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package org.hwo.pulscounter.device;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JTextField;
|
||||
import java.awt.Insets;
|
||||
|
||||
public class SimulatedCounterSettingsDialog extends JDialog {
|
||||
|
||||
public static boolean show(Component parent,SimulatedCounter counter){
|
||||
SimulatedCounterSettingsDialog dlg = new SimulatedCounterSettingsDialog();
|
||||
if (parent != null)
|
||||
dlg.setLocationRelativeTo(parent);
|
||||
|
||||
dlg.setSerial(counter.getConnectionSettings());
|
||||
dlg.setVisible(true);
|
||||
|
||||
if (dlg.accepted){
|
||||
counter.setConnectionSettings(dlg.getSerial());
|
||||
dlg.dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
private boolean accepted;
|
||||
private JTextField tfSerial;
|
||||
|
||||
public SimulatedCounterSettingsDialog() {
|
||||
setTitle("Simulierter Zähler");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JLabel lblAnschluss = new JLabel("Seriennummer:");
|
||||
GridBagConstraints gbc_lblAnschluss = new GridBagConstraints();
|
||||
gbc_lblAnschluss.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblAnschluss.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblAnschluss.gridx = 0;
|
||||
gbc_lblAnschluss.gridy = 0;
|
||||
contentPanel.add(lblAnschluss, gbc_lblAnschluss);
|
||||
}
|
||||
{
|
||||
tfSerial = new JTextField();
|
||||
GridBagConstraints gbc_tfSerial = new GridBagConstraints();
|
||||
gbc_tfSerial.anchor = GridBagConstraints.NORTH;
|
||||
gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfSerial.gridx = 1;
|
||||
gbc_tfSerial.gridy = 0;
|
||||
contentPanel.add(tfSerial, gbc_tfSerial);
|
||||
tfSerial.setColumns(10);
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
accepted = true;
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getSerial(){
|
||||
return tfSerial.getText();
|
||||
}
|
||||
public void setSerial(String serial){
|
||||
tfSerial.setText(serial);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package org.hwo.pulscounter.elements;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
public class RawValueEntry {
|
||||
|
||||
int channel;
|
||||
DateTime dateTime;
|
||||
int value;
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package org.hwo.pulscounter.elements;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.datetime.TimeOfDay;
|
||||
import org.hwo.datetime.DateTime;
|
||||
|
||||
|
||||
public class WorkShift {
|
||||
|
||||
private String name;
|
||||
private String comment;
|
||||
|
||||
private TimeOfDay begins;
|
||||
private TimeOfDay ends;
|
||||
|
||||
public WorkShift(){
|
||||
this.name = "";
|
||||
this.comment = "";
|
||||
this.begins = new TimeOfDay();
|
||||
this.ends = new TimeOfDay();
|
||||
}
|
||||
|
||||
public boolean isOverMidnight(){
|
||||
return ends.isEarlierThan(begins);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public TimeOfDay getBegins() {
|
||||
return begins;
|
||||
}
|
||||
public void setBegins(TimeOfDay begins) {
|
||||
this.begins = begins;
|
||||
}
|
||||
|
||||
public TimeOfDay getEnds() {
|
||||
return ends;
|
||||
}
|
||||
public void setEnds(TimeOfDay ends) {
|
||||
this.ends = ends;
|
||||
}
|
||||
|
||||
public DateTime getShiftBegins(Date date){
|
||||
DateTime dt = new DateTime(date, begins);
|
||||
return dt;
|
||||
}
|
||||
|
||||
public DateTime getShiftEnds(Date date){
|
||||
DateTime dt = new DateTime(date, ends);
|
||||
if (isOverMidnight()){
|
||||
dt.getDate().addDays(1);
|
||||
}
|
||||
return dt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
package org.hwo.pulscounter.elements;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Hashtable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.datetime.DateTime;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
import org.hwo.pulscounter.PulsCounter;
|
||||
>>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888
|
||||
|
||||
public class WorkShiftRecord {
|
||||
|
||||
public class ChannelRecords{
|
||||
|
||||
public class ChannelRecord
|
||||
{
|
||||
DateTime timestamp;
|
||||
Integer value;
|
||||
|
||||
public ChannelRecord(DateTime timestamp,int value){
|
||||
this.timestamp = timestamp;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public DateTime getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
public void setTimestamp(DateTime timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
int channel;
|
||||
List<ChannelRecord> values;
|
||||
|
||||
public ChannelRecords(int channel){
|
||||
this.channel = channel;
|
||||
this.values = new LinkedList<WorkShiftRecord.ChannelRecords.ChannelRecord>();
|
||||
}
|
||||
|
||||
public void addValue(DateTime timestamp,int value){
|
||||
this.values.add(new ChannelRecord(timestamp, value));
|
||||
}
|
||||
|
||||
public void sort(){
|
||||
/* List<ChannelRecord> sorted = new LinkedList<WorkShiftRecord.ChannelRecords.ChannelRecord>();
|
||||
|
||||
for (ChannelRecord r: values){
|
||||
if (values.size() == 0)
|
||||
sorted.add(r);
|
||||
}
|
||||
|
||||
this.values = sorted;
|
||||
*/
|
||||
}
|
||||
|
||||
public List<ChannelRecord> getRecords(){
|
||||
return this.values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WorkShift workShift;
|
||||
Date date;
|
||||
|
||||
Hashtable<Integer, ChannelRecords>
|
||||
records;
|
||||
|
||||
public WorkShiftRecord(WorkShift shift,Date date){
|
||||
workShift = shift;
|
||||
this.date = date;
|
||||
records = new Hashtable<Integer, WorkShiftRecord.ChannelRecords>();
|
||||
|
||||
loadRecords();
|
||||
}
|
||||
|
||||
void loadRecords(){
|
||||
<<<<<<< HEAD
|
||||
/* try {
|
||||
=======
|
||||
try {
|
||||
>>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888
|
||||
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());
|
||||
stat.setTimestamp(2, workShift.getShiftEnds(date).getTimeStamp());
|
||||
|
||||
ResultSet result = stat.executeQuery();
|
||||
|
||||
while (result.next()){
|
||||
int channel = result.getInt("channel");
|
||||
|
||||
if (!records.containsKey(channel)){
|
||||
records.put(channel, new ChannelRecords(channel));
|
||||
}
|
||||
|
||||
// System.err.println("Record: " + result.getString("tstamp") + " [" + result.getString("channel") + "] " + result.getString("chvalue") );
|
||||
|
||||
records.get(channel).addValue(new DateTime(result.getTimestamp("tstamp")),result.getInt("chvalue"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
result.close();
|
||||
stat.close();
|
||||
|
||||
for (WorkShiftRecord.ChannelRecords record: records.values().toArray(new WorkShiftRecord.ChannelRecords[0])){
|
||||
record.sort();
|
||||
}
|
||||
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
*/
|
||||
=======
|
||||
>>>>>>> a886cb917c05a82eb85921d7d9c387835aa3f888
|
||||
}
|
||||
|
||||
public Integer[] getChannels(){
|
||||
return (Integer[]) this.records.keySet().toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
public ChannelRecords getChannelRecords(int channel){
|
||||
return records.get(channel);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,349 @@
|
|||
package org.hwo.pulscounter.simplescript;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
|
||||
public class SimpleScript {
|
||||
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String description;
|
||||
private ArrayList<SimpleScriptElement> simpleScriptElements;
|
||||
|
||||
public SimpleScript(){
|
||||
id = UUID.randomUUID();
|
||||
name = "SimpleScript";
|
||||
description = "-";
|
||||
simpleScriptElements = new ArrayList<>();
|
||||
simpleScriptElements.add(new SimpleScriptElement(0));
|
||||
}
|
||||
|
||||
public SimpleScript(UUID uuid,String name,String description,SimpleScriptElement elements[]){
|
||||
this.id = uuid;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.simpleScriptElements = new ArrayList<>();
|
||||
this.simpleScriptElements.addAll(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
public SimpleScript(UUID uuid,String name,String description,Integer[] elementCodes){
|
||||
this.id = uuid;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.simpleScriptElements = new ArrayList<>();
|
||||
|
||||
for (Integer code: elementCodes){
|
||||
this.simpleScriptElements.add(new SimpleScriptElement(code));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@TableColumn(label="name",order=10,width=120)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@TableColumn(label="Bezeichnung",order=20)
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ArrayList<SimpleScriptElement> getSimpleScriptElements() {
|
||||
return simpleScriptElements;
|
||||
}
|
||||
|
||||
public int[] getSimpleScriptElementsAsInt(){
|
||||
int[] sse = new int[simpleScriptElements.size()];
|
||||
|
||||
for (int i=0;i<sse.length;i++){
|
||||
sse[i] = simpleScriptElements.get(i).getCode();
|
||||
}
|
||||
|
||||
return sse;
|
||||
}
|
||||
public Integer[] getSimpleScriptElementsAsInteger(){
|
||||
Integer[] sse = new Integer[simpleScriptElements.size()];
|
||||
|
||||
for (int i=0;i<sse.length;i++){
|
||||
sse[i] = simpleScriptElements.get(i).getCode();
|
||||
}
|
||||
|
||||
return sse;
|
||||
}
|
||||
|
||||
public void setSimpleScriptElements(SimpleScriptElement[] elements){
|
||||
this.simpleScriptElements.clear();
|
||||
this.simpleScriptElements.addAll(Arrays.asList(elements));
|
||||
}
|
||||
public void setSimpleScriptElements(int[] elements){
|
||||
this.simpleScriptElements.clear();
|
||||
for (int e: elements){
|
||||
simpleScriptElements.add(new SimpleScriptElement(e));
|
||||
}
|
||||
}
|
||||
public void setSimpleScriptElements(Integer[] elements){
|
||||
this.simpleScriptElements.clear();
|
||||
for (int e: elements){
|
||||
simpleScriptElements.add(new SimpleScriptElement(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum ScriptOperation {
|
||||
|
||||
SET_ZERO (0x00,"ARITHEMTIK = 0"),
|
||||
SET_ONE (0x01,"ARITHEMTIK = 1"),
|
||||
SET_A (0x02,"ARITHEMTIK = A"),
|
||||
SET_B (0x03,"ARITHEMTIK = B"),
|
||||
A_PLUS_B (0x04,"ARITHEMTIK = A + B"),
|
||||
A_MINUS_B (0x05,"ARITHEMTIK = A - B"),
|
||||
A_MUL_B (0x06,"ARITHEMTIK = A * B"),
|
||||
A_DIV_B (0x07,"ARITHEMTIK = A / B"),
|
||||
A_AND_B (0x08,"LOGIK = A and B"),
|
||||
A_OR_B (0x09,"LOGIK = A or B"),
|
||||
A_XOR_B (0x0A,"LOGIK = A xor B"),
|
||||
/* 0x0b..0x0f: frei */
|
||||
SET_NOT_A (0x10,"LOGIK = not A"),
|
||||
SET_NOT_B (0x11,"LOGIK = not B"),
|
||||
A_PLUS_ONE (0x12,"ARITHEMTIK = A + 1"),
|
||||
A_MINUS_ONE (0x13,"ARITHEMTIK = A - 1"),
|
||||
B_PLUS_ONE (0x14,"ARITHEMTIK = B + 1"),
|
||||
B_MINUS_ONE (0x15,"ARITHEMTIK = B - 1")
|
||||
/* 0x16..0x1f: frei */
|
||||
;
|
||||
|
||||
ScriptOperation(int n,String desc){
|
||||
this.n = n;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
static ScriptOperation operations[] = {
|
||||
SET_ZERO, // 0x00
|
||||
SET_ONE,
|
||||
SET_A,
|
||||
SET_B,
|
||||
A_PLUS_B, // 0x04
|
||||
A_MINUS_B,
|
||||
A_MUL_B,
|
||||
A_DIV_B,
|
||||
A_AND_B, // 0x08
|
||||
A_OR_B,
|
||||
A_XOR_B,
|
||||
null,
|
||||
null, // 0x0c
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
SET_NOT_A, // 0x10
|
||||
SET_NOT_B,
|
||||
A_PLUS_ONE,
|
||||
A_MINUS_ONE,
|
||||
B_PLUS_ONE, // 0x14
|
||||
B_MINUS_ONE,
|
||||
null,
|
||||
null,
|
||||
null, // 0x18
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null, // 0x1C
|
||||
null,
|
||||
null,
|
||||
null
|
||||
};
|
||||
|
||||
public static ScriptOperation get(int code){
|
||||
return operations[code];
|
||||
}
|
||||
|
||||
private int n;
|
||||
private String desc;
|
||||
|
||||
|
||||
public int getCode(){
|
||||
return this.n;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return Messages.getString(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Messages.getString(desc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ScriptCondition {
|
||||
NEVER (0x00,"Niemals"),
|
||||
ALWAYS (0x01,"Immer"),
|
||||
A_EQ_ZERO (0x02,"A == 0"),
|
||||
A_NEQ_ZERO (0x03,"A != 0"),
|
||||
A_EQ_B (0x04,"A == B"),
|
||||
A_NEQ_B (0x05,"A != B"),
|
||||
A_LT_B (0x06,"A < B"),
|
||||
A_GT_B (0x07,"A > B")
|
||||
;
|
||||
|
||||
static ScriptCondition scriptConditions[] = {
|
||||
NEVER,
|
||||
ALWAYS,
|
||||
A_EQ_ZERO,
|
||||
A_NEQ_ZERO,
|
||||
A_EQ_B,
|
||||
A_NEQ_B,
|
||||
A_LT_B,
|
||||
A_GT_B
|
||||
};
|
||||
|
||||
static ScriptCondition get(int code){
|
||||
return scriptConditions[code];
|
||||
}
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
ScriptCondition(int code,String desc){
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode(){
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return Messages.getString(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Messages.getString(desc);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleScriptElement{
|
||||
private int code;
|
||||
|
||||
public SimpleScriptElement(){
|
||||
code = 0;
|
||||
}
|
||||
public SimpleScriptElement(int code){
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public SimpleScriptElement(int a,int b,int z,ScriptCondition scriptCondition,ScriptOperation scriptOperation){
|
||||
setA(a);
|
||||
setB(b);
|
||||
setZ(z);
|
||||
setScriptCondition(scriptCondition);
|
||||
setScriptOperation(scriptOperation);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@TableColumn(label="A",order=0,width=120)
|
||||
public String getHumanA(){
|
||||
return SimpleScriptAddress.toString(getA());
|
||||
}
|
||||
|
||||
public int getA(){
|
||||
return code & 0xff;
|
||||
}
|
||||
|
||||
@TableColumn(label="B",order=10,width=120)
|
||||
public String getHumanB(){
|
||||
return SimpleScriptAddress.toString(getB());
|
||||
}
|
||||
|
||||
public int getB(){
|
||||
return (code >> 8) & 0xff;
|
||||
}
|
||||
|
||||
@TableColumn(label="Z",order=90,width=120)
|
||||
public String getHumanZ(){
|
||||
return SimpleScriptAddress.toString(getZ());
|
||||
}
|
||||
|
||||
public int getZ(){
|
||||
return (code >> 16) & 0xff;
|
||||
}
|
||||
|
||||
public int getCondition(){
|
||||
return (code >> 24) & 0x07;
|
||||
}
|
||||
public int getOperation(){
|
||||
return (code >> 27) & 0x1f;
|
||||
}
|
||||
|
||||
public void setA(int a){
|
||||
code &= ~0xff;
|
||||
code |= a & 0xff;
|
||||
}
|
||||
public void setB(int b){
|
||||
code &= ~( 0xff << 8 );
|
||||
code |= (b & 0xff) << 8;
|
||||
}
|
||||
public void setZ(int z){
|
||||
code &= ~( 0xff << 16 );
|
||||
code |= (z & 0xff) << 16;
|
||||
}
|
||||
public void setCondition(int condition){
|
||||
code &= ~( 0x07 << 24 );
|
||||
code |= (condition & 0x07) << 24;
|
||||
}
|
||||
public void setOperation(int operation){
|
||||
code &= ~( 0x1f << 27 );
|
||||
code |= (operation & 0x1F) << 27;
|
||||
}
|
||||
|
||||
@TableColumn(label="Operation",order=50,width=140)
|
||||
public ScriptOperation getScriptOperation(){
|
||||
return ScriptOperation.get(getOperation());
|
||||
}
|
||||
public void setScriptOperation(ScriptOperation scriptOperation){
|
||||
if (scriptOperation == null){
|
||||
setOperation(0);
|
||||
} else {
|
||||
setOperation(scriptOperation.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@TableColumn(label="Bedingung",order=40,width=120)
|
||||
public ScriptCondition getScriptCondition(){
|
||||
return ScriptCondition.get(getCondition());
|
||||
}
|
||||
public void setScriptCondition(ScriptCondition scriptCondition){
|
||||
if (scriptCondition == null){
|
||||
setCondition(0);
|
||||
} else {
|
||||
setCondition(scriptCondition.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package org.hwo.pulscounter.simplescript;
|
||||
|
||||
public class SimpleScriptAddress{
|
||||
private int address;
|
||||
|
||||
public SimpleScriptAddress(){
|
||||
this.address = 0;
|
||||
}
|
||||
public SimpleScriptAddress(int a){
|
||||
this.address = a;
|
||||
}
|
||||
|
||||
public int getAddress() {
|
||||
return address;
|
||||
}
|
||||
public void setAddress(int address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(address);
|
||||
}
|
||||
|
||||
public static String toString(int address) {
|
||||
if (address < 32){
|
||||
return String.format("Zählerstand %d",address);
|
||||
} else if (address < 40){
|
||||
return String.format("Analogspannung %d", address - 32);
|
||||
} else if (address < 64){
|
||||
return String.format("Merker %d", address - 40);
|
||||
} else if (address < 96){
|
||||
return String.format("PullUp %d", address - 64);
|
||||
} else if (address < 128){
|
||||
return String.format("Ausgang %d", address - 96);
|
||||
} else if (address < 160){
|
||||
return String.format("Inverter %d", address - 128);
|
||||
} else if (address < 192){
|
||||
return String.format("Eingang %d", address - 160);
|
||||
} else {
|
||||
return String.format("Variable %d", address - 192);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -26,12 +26,10 @@ import javax.swing.JButton;
|
|||
import org.hwo.csv.CSV;
|
||||
import org.hwo.io.SerialPort;
|
||||
import org.hwo.io.NewSerialPort.NewSerialPort;
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
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.servicelink.exceptions.*;
|
||||
import org.hwo.ui.dialog.SerialPortChooser;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
|
@ -52,6 +50,8 @@ import javax.swing.border.TitledBorder;
|
|||
import javax.swing.JSpinner;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class AppSettingsFrame extends JDialog {
|
||||
|
||||
|
@ -79,6 +79,12 @@ public class AppSettingsFrame extends JDialog {
|
|||
* Create the frame.
|
||||
*/
|
||||
public AppSettingsFrame() {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModal(true);
|
||||
setTitle("Einstellungen");
|
||||
|
@ -124,7 +130,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton btnWhlen = new JButton("wählen...");
|
||||
btnWhlen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
chooseSerialPort();
|
||||
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnWhlen = new GridBagConstraints();
|
||||
|
@ -231,7 +237,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton btnUpdate = new JButton("Update...");
|
||||
btnUpdate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
readDebug();
|
||||
// readDebug();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnUpdate = new GridBagConstraints();
|
||||
|
@ -250,7 +256,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton btnDumpSnapshots = new JButton("Dump Snapshots");
|
||||
btnDumpSnapshots.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dumpSnapshots();
|
||||
// dumpSnapshots();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnDumpSnapshots = new GridBagConstraints();
|
||||
|
@ -262,7 +268,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton btnResetDevice = new JButton("Reset Device");
|
||||
btnResetDevice.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doRESETDevice();
|
||||
// doRESETDevice();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnResetDevice = new GridBagConstraints();
|
||||
|
@ -274,7 +280,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton btnRckDump = new JButton("RCK Dump");
|
||||
btnRckDump.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doRCKDump();
|
||||
// doRCKDump();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnRckDump = new GridBagConstraints();
|
||||
|
@ -283,7 +289,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
panel_5.add(btnRckDump, gbc_btnRckDump);
|
||||
btnRamImage.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doRAMImage();
|
||||
// doRAMImage();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -387,9 +393,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
JButton bOK = new JButton("OK");
|
||||
bOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
accept();
|
||||
setVisible(false);
|
||||
application().savePrefs();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_bOK = new GridBagConstraints();
|
||||
|
@ -398,11 +402,12 @@ public class AppSettingsFrame extends JDialog {
|
|||
gbc_bOK.gridy = 0;
|
||||
panel_1.add(bOK, gbc_bOK);
|
||||
|
||||
initialize();
|
||||
//initialize();
|
||||
}
|
||||
|
||||
/*
|
||||
private void initialize(){
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
|
||||
|
||||
selectedSerialPort = pc2a.getSerialPort();
|
||||
formerSerialPort = selectedSerialPort;
|
||||
|
@ -452,8 +457,8 @@ public class AppSettingsFrame extends JDialog {
|
|||
tabbedPane.addTab("DEBUG", null, debugPanel, null);
|
||||
}
|
||||
|
||||
private PulsCounter2Application application(){
|
||||
return PulsCounter2Application.getApplication();
|
||||
private PulsCounterApplication application(){
|
||||
return PulsCounterApplication.getApplication();
|
||||
}
|
||||
|
||||
|
||||
|
@ -477,7 +482,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
}
|
||||
|
||||
private void chooseSerialPort(){
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
|
||||
|
||||
SerialPortChooser spc = new SerialPortChooser();
|
||||
|
||||
|
@ -494,7 +499,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
}
|
||||
|
||||
private void doRESETDevice(){
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
|
||||
ServiceLink sl = pc2a.getServiceLink();
|
||||
|
||||
try {
|
||||
|
@ -508,7 +513,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
}
|
||||
|
||||
private void doRAMImage(){
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
|
||||
ServiceLink sl = pc2a.getServiceLink();
|
||||
|
||||
try {
|
||||
|
@ -546,10 +551,6 @@ public class AppSettingsFrame extends JDialog {
|
|||
Integer i32 = sl.readInt(13, 0, 0x00ee);
|
||||
|
||||
o.write(i32 & 0xff);
|
||||
/* o.write((i32>>8) & 0xff);
|
||||
o.write((i32>>16) & 0xff);
|
||||
o.write((i32>>24) & 0xff);
|
||||
*/
|
||||
}
|
||||
|
||||
o.close();
|
||||
|
@ -569,7 +570,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
void readDebug(){
|
||||
Integer v;
|
||||
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
PulsCounterApplication pc2a = PulsCounterApplication.getApplication();
|
||||
ServiceLink sl = pc2a.getServiceLink();
|
||||
|
||||
try {
|
||||
|
@ -600,7 +601,7 @@ public class AppSettingsFrame extends JDialog {
|
|||
}
|
||||
|
||||
void dumpSnapshots(){
|
||||
SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManager();
|
||||
SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager();
|
||||
|
||||
for (int n=0;n<ssm.size();n++){
|
||||
SnapShot ss = ssm.loadSnapShot(n);
|
||||
|
@ -630,6 +631,6 @@ SnapshotManager ssm = PulsCounter2Application.getApplication().getSnapshotManage
|
|||
}
|
||||
msgExc.setText(sb.toString());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -1,61 +1,83 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import org.hwo.pulscounter.ExportSetting;
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.PulsCounterApplicationListener;
|
||||
import org.hwo.pulscounter.SnapshotManager.Notification;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.exceptions.*;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
public class BatchRunner implements PulsCounterApplicationListener{
|
||||
|
||||
public PulsCounter2Application application(){
|
||||
return PulsCounter2Application.getApplication();
|
||||
}
|
||||
private PulsCounterApplication pulsCounterApplication;
|
||||
|
||||
public BatchRunner(){
|
||||
public BatchRunner(PulsCounterApplication pulsCounterApplication){
|
||||
this.pulsCounterApplication = pulsCounterApplication;
|
||||
|
||||
application().addPulsCounterApplicationListener(this);
|
||||
pulsCounterApplication.addPulsCounterApplicationListener(this);
|
||||
|
||||
try {
|
||||
run();
|
||||
} catch (Exception e){
|
||||
log(e);
|
||||
}
|
||||
|
||||
pulsCounterApplication.notifyUiIsFinished(true);
|
||||
}
|
||||
|
||||
public void run(){
|
||||
try {
|
||||
application().getServiceLink().open();
|
||||
pulsCounterApplication.getInterfaces().get(0).checkRealTimeClock();
|
||||
|
||||
for (String cmd: pulsCounterApplication.getBatchCommands()){
|
||||
String[] tokens = cmd.split(":");
|
||||
switch (tokens[0]){
|
||||
case "output":
|
||||
|
||||
String[] s = tokens[1].split("=");
|
||||
int outputno = Integer.decode(s[0]);
|
||||
int state = Integer.decode(s[1]);
|
||||
|
||||
int outputs = pulsCounterApplication.getInterfaces().get(0).getOutputs();
|
||||
if (state != 0){
|
||||
outputs |= (1<<outputno);
|
||||
} else {
|
||||
outputs &= ~(1<<outputno);
|
||||
}
|
||||
|
||||
log(INFO,"BatchCommand: set output %d = %d",outputno,state);
|
||||
|
||||
pulsCounterApplication.getInterfaces().get(0).setOutputs(outputs);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pulsCounterApplication.getBatchCommands().length == 0){
|
||||
PulsCounterApplication.getApplication().checkForSnapShots();
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
application().getSnapshotManager().doFullSync();
|
||||
|
||||
for (ExportSetting es: application().getExportSettings()){
|
||||
for (ExportSetting es: PulsCounterApplication.getApplication().getExportSettings()){
|
||||
if (es.getAutostart()){
|
||||
es.export();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
application().shutdown();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
if (connected){
|
||||
}
|
||||
|
||||
pulsCounterApplication.notifyUiIsFinished(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String message) {
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ChannelDisplay extends JPanel {
|
|||
|
||||
private JPopupMenu popupMenu;
|
||||
private List<ChannelDisplayListener> channelDisplayListeners;
|
||||
private JTextField lName;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
|
@ -124,6 +125,20 @@ public class ChannelDisplay extends JPanel {
|
|||
add(tfCounter, gbc_tfCounter);
|
||||
tfCounter.setColumns(10);
|
||||
|
||||
tfAnalog = new JTextField();
|
||||
tfAnalog.setToolTipText("<html>\n<b>Analog Messwert</b><br/>\n<br/>\nZeigt die an diesem Kanal gemessene Spannung.\n</html>");
|
||||
tfAnalog.setEditable(false);
|
||||
tfAnalog.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
tfAnalog.setInheritsPopupMenu(true);
|
||||
GridBagConstraints gbc_tfAnalog = new GridBagConstraints();
|
||||
gbc_tfAnalog.gridwidth = 2;
|
||||
gbc_tfAnalog.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_tfAnalog.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfAnalog.gridx = 0;
|
||||
gbc_tfAnalog.gridy = 1;
|
||||
add(tfAnalog, gbc_tfAnalog);
|
||||
tfAnalog.setColumns(10);
|
||||
|
||||
lblA = new JLabel("");
|
||||
lblA.setToolTipText("<html>\n<b>Ausgang</b><br/>\n<br/>\nZeigt, ob die Ausgangsschaltung für diesen Kanal aktiv ist.\n</html>");
|
||||
lblA.setIcon(new ImageIcon(ChannelDisplay.class.getResource("/org/hwo/pulscounter/ui/sym_a_passiv.png")));
|
||||
|
@ -134,17 +149,14 @@ public class ChannelDisplay extends JPanel {
|
|||
gbc_lblA.gridy = 1;
|
||||
add(lblA, gbc_lblA);
|
||||
|
||||
tfAnalog = new JTextField();
|
||||
tfAnalog.setToolTipText("<html>\n<b>Analog Messwert</b><br/>\n<br/>\nZeigt die an diesem Kanal gemessene Spannung.\n</html>");
|
||||
tfAnalog.setEditable(false);
|
||||
tfAnalog.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
tfAnalog.setInheritsPopupMenu(true);
|
||||
GridBagConstraints gbc_tfAnalog = new GridBagConstraints();
|
||||
gbc_tfAnalog.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfAnalog.gridx = 3;
|
||||
gbc_tfAnalog.gridy = 1;
|
||||
add(tfAnalog, gbc_tfAnalog);
|
||||
tfAnalog.setColumns(10);
|
||||
lName = new JTextField();
|
||||
lName.setEditable(false);
|
||||
lName.setInheritsPopupMenu(true);
|
||||
GridBagConstraints gbc_lName = new GridBagConstraints();
|
||||
gbc_lName.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lName.gridx = 3;
|
||||
gbc_lName.gridy = 1;
|
||||
add(lName, gbc_lName);
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
@ -181,6 +193,26 @@ public class ChannelDisplay extends JPanel {
|
|||
});
|
||||
|
||||
popupMenu.add(tf);
|
||||
|
||||
popupMenu.addSeparator();
|
||||
|
||||
JLabel l2 = new JLabel("Beschreibung:");
|
||||
popupMenu.add(l2);
|
||||
|
||||
final JTextField tf2 = new JTextField();
|
||||
tf2.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if (!tf2.getText().startsWith("!\"§$%")){
|
||||
setDescriptionText(tf2.getText());
|
||||
};
|
||||
fireChannelDisplayDescriptionSet(tf2.getText());
|
||||
popupMenu.setVisible(false);
|
||||
}
|
||||
});
|
||||
popupMenu.add( tf2 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -206,6 +238,11 @@ public class ChannelDisplay extends JPanel {
|
|||
l.set(this, setValue);
|
||||
}
|
||||
}
|
||||
private void fireChannelDisplayDescriptionSet(String desc){
|
||||
for (ChannelDisplayListener l:channelDisplayListeners){
|
||||
l.setDescriptionText(this, desc);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAnalog(boolean isAnalog) {
|
||||
this.isAnalog = isAnalog;
|
||||
|
@ -256,7 +293,13 @@ public class ChannelDisplay extends JPanel {
|
|||
}
|
||||
public void setCounter(Integer counter) {
|
||||
this.counter = counter;
|
||||
tfCounter.setText(String.format("%d", counter));
|
||||
if (counter != null){
|
||||
tfCounter.setText(String.format("%d", counter));
|
||||
tfCounter.setEnabled(true);
|
||||
} else {
|
||||
tfCounter.setEnabled(false);
|
||||
tfCounter.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public Double getVoltage() {
|
||||
|
@ -264,7 +307,13 @@ public class ChannelDisplay extends JPanel {
|
|||
}
|
||||
public void setVoltage(Double voltage) {
|
||||
this.voltage = voltage;
|
||||
tfAnalog.setText(String.format("%.02f V",voltage));
|
||||
if (voltage != null){
|
||||
tfAnalog.setText(String.format("%.02f V",voltage));
|
||||
tfAnalog.setEnabled(true);
|
||||
} else {
|
||||
tfAnalog.setEnabled(false);
|
||||
tfAnalog.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
public void setChannelName(String channelName) {
|
||||
|
@ -275,4 +324,23 @@ public class ChannelDisplay extends JPanel {
|
|||
return channelName;
|
||||
}
|
||||
|
||||
public void setDescriptionText(String desc){
|
||||
lName.setText(desc);
|
||||
}
|
||||
public String getDescriptionText(){
|
||||
return lName.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled){
|
||||
} else {
|
||||
setVoltage(null);
|
||||
setCounter(null);
|
||||
setOutput(false);
|
||||
setInput(false);
|
||||
setPullup(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,4 +5,6 @@ public interface ChannelDisplayListener {
|
|||
public void reset (ChannelDisplay sender);
|
||||
public void set (ChannelDisplay sender,int setValue);
|
||||
|
||||
public void setDescriptionText(ChannelDisplay sender,String descriptionText);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,302 +0,0 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.pulscounter.PulsCounter;
|
||||
import org.hwo.pulscounter.elements.WorkShift;
|
||||
import org.hwo.pulscounter.elements.WorkShiftRecord;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.swing.JTable;
|
||||
|
||||
import org.hwo.ui.FlexibleJTable;
|
||||
import org.hwo.ui.JComboBoxEx;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
public class CheckWorkshiftRecords extends JFrame {
|
||||
|
||||
private Date selectedDate;
|
||||
private WorkShiftRecord selectedWorkShift;
|
||||
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTextField tfDatum;
|
||||
private JComboBox cbWorkShift;
|
||||
private JTextField tfBegins;
|
||||
private JTextField tfEnds;
|
||||
private FlexibleJTable<WorkShiftRecord.ChannelRecords.ChannelRecord> flexibleJTable;
|
||||
private JComboBoxEx cbChannel;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
CheckWorkshiftRecords frame = new CheckWorkshiftRecords();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public CheckWorkshiftRecords() {
|
||||
setTitle("Schichtdaten prüfen");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 938, 686);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Auswahl", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPane.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JLabel lblDatum = new JLabel("Datum:");
|
||||
GridBagConstraints gbc_lblDatum = new GridBagConstraints();
|
||||
gbc_lblDatum.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblDatum.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblDatum.gridx = 0;
|
||||
gbc_lblDatum.gridy = 0;
|
||||
panel.add(lblDatum, gbc_lblDatum);
|
||||
|
||||
tfDatum = new JTextField();
|
||||
tfDatum.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date d = new Date();
|
||||
d.fromSQLDate(tfDatum.getText());
|
||||
selectDatum(d);
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_tfDatum = new GridBagConstraints();
|
||||
gbc_tfDatum.gridwidth = 2;
|
||||
gbc_tfDatum.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_tfDatum.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfDatum.gridx = 1;
|
||||
gbc_tfDatum.gridy = 0;
|
||||
panel.add(tfDatum, gbc_tfDatum);
|
||||
tfDatum.setColumns(10);
|
||||
|
||||
JButton btnGestern = new JButton("GESTERN");
|
||||
btnGestern.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Date d = new Date();
|
||||
d.addDays(-1);
|
||||
selectDatum(d);
|
||||
}
|
||||
});
|
||||
|
||||
JButton btnHeute = new JButton("HEUTE");
|
||||
btnHeute.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
selectDatum(new Date());
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnHeute = new GridBagConstraints();
|
||||
gbc_btnHeute.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_btnHeute.gridx = 3;
|
||||
gbc_btnHeute.gridy = 0;
|
||||
panel.add(btnHeute, gbc_btnHeute);
|
||||
GridBagConstraints gbc_btnGestern = new GridBagConstraints();
|
||||
gbc_btnGestern.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnGestern.gridx = 4;
|
||||
gbc_btnGestern.gridy = 0;
|
||||
panel.add(btnGestern, gbc_btnGestern);
|
||||
|
||||
JLabel lblSchicht = new JLabel("Schicht:");
|
||||
GridBagConstraints gbc_lblSchicht = new GridBagConstraints();
|
||||
gbc_lblSchicht.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblSchicht.gridx = 0;
|
||||
gbc_lblSchicht.gridy = 1;
|
||||
panel.add(lblSchicht, gbc_lblSchicht);
|
||||
|
||||
cbWorkShift = new JComboBox();
|
||||
cbWorkShift.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
selectionChanged();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_cbWorkShift = new GridBagConstraints();
|
||||
gbc_cbWorkShift.gridwidth = 2;
|
||||
gbc_cbWorkShift.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_cbWorkShift.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbWorkShift.gridx = 1;
|
||||
gbc_cbWorkShift.gridy = 1;
|
||||
panel.add(cbWorkShift, gbc_cbWorkShift);
|
||||
|
||||
JLabel lblSchichtgrenzen = new JLabel("Schichtgrenzen:");
|
||||
GridBagConstraints gbc_lblSchichtgrenzen = new GridBagConstraints();
|
||||
gbc_lblSchichtgrenzen.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblSchichtgrenzen.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblSchichtgrenzen.gridx = 0;
|
||||
gbc_lblSchichtgrenzen.gridy = 2;
|
||||
panel.add(lblSchichtgrenzen, gbc_lblSchichtgrenzen);
|
||||
|
||||
tfBegins = new JTextField();
|
||||
GridBagConstraints gbc_tfBegins = new GridBagConstraints();
|
||||
gbc_tfBegins.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_tfBegins.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfBegins.gridx = 1;
|
||||
gbc_tfBegins.gridy = 2;
|
||||
panel.add(tfBegins, gbc_tfBegins);
|
||||
tfBegins.setColumns(10);
|
||||
|
||||
tfEnds = new JTextField();
|
||||
tfEnds.setColumns(10);
|
||||
GridBagConstraints gbc_tfEnds = new GridBagConstraints();
|
||||
gbc_tfEnds.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_tfEnds.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfEnds.gridx = 2;
|
||||
gbc_tfEnds.gridy = 2;
|
||||
panel.add(tfEnds, gbc_tfEnds);
|
||||
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_2.setBorder(new TitledBorder(null, "Kanal", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel_2 = new GridBagConstraints();
|
||||
gbc_panel_2.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_2.gridx = 0;
|
||||
gbc_panel_2.gridy = 1;
|
||||
contentPane.add(panel_2, gbc_panel_2);
|
||||
GridBagLayout gbl_panel_2 = new GridBagLayout();
|
||||
gbl_panel_2.columnWidths = new int[]{0, 0};
|
||||
gbl_panel_2.rowHeights = new int[]{0, 0};
|
||||
gbl_panel_2.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel_2.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel_2.setLayout(gbl_panel_2);
|
||||
|
||||
cbChannel = new JComboBoxEx();
|
||||
cbChannel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
selectChannel();
|
||||
}
|
||||
}
|
||||
);
|
||||
GridBagConstraints gbc_cbChannel = new GridBagConstraints();
|
||||
gbc_cbChannel.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbChannel.gridx = 0;
|
||||
gbc_cbChannel.gridy = 0;
|
||||
panel_2.add(cbChannel, gbc_cbChannel);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
||||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_1.gridx = 0;
|
||||
gbc_panel_1.gridy = 2;
|
||||
contentPane.add(panel_1, gbc_panel_1);
|
||||
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||||
gbl_panel_1.columnWidths = new int[]{0, 0};
|
||||
gbl_panel_1.rowHeights = new int[]{0, 0};
|
||||
gbl_panel_1.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel_1.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel_1.setLayout(gbl_panel_1);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 0;
|
||||
panel_1.add(scrollPane, gbc_scrollPane);
|
||||
|
||||
flexibleJTable = new FlexibleJTable(WorkShiftRecord.ChannelRecords.ChannelRecord.class);
|
||||
scrollPane.setViewportView(flexibleJTable);
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
void initialize(){
|
||||
for (WorkShift shift: PulsCounter.getInspectorApplication().getWorkShifts()){
|
||||
cbWorkShift.addItem(shift);
|
||||
}
|
||||
|
||||
flexibleJTable.addColumn("timestamp");
|
||||
flexibleJTable.addColumn("value");
|
||||
|
||||
|
||||
|
||||
selectDatum(new Date());
|
||||
}
|
||||
|
||||
void selectDatum(Date date){
|
||||
tfDatum.setText(date.getSQLDate());
|
||||
selectedDate = date;
|
||||
|
||||
selectionChanged();
|
||||
}
|
||||
|
||||
void selectionChanged(){
|
||||
if (cbWorkShift.getSelectedItem()==null)
|
||||
return;
|
||||
if (selectedDate == null)
|
||||
return;
|
||||
|
||||
WorkShift shift = (WorkShift)cbWorkShift.getSelectedItem();
|
||||
|
||||
tfBegins.setText(shift.getShiftBegins(selectedDate).getSQLDateTime());
|
||||
tfEnds.setText(shift.getShiftEnds(selectedDate).getSQLDateTime());
|
||||
|
||||
WorkShiftRecord workShiftRecord = new WorkShiftRecord(shift, selectedDate);
|
||||
|
||||
selectedWorkShift = null;
|
||||
|
||||
flexibleJTable.setRows(new LinkedList<WorkShiftRecord.ChannelRecords.ChannelRecord>());
|
||||
cbChannel.setItems(workShiftRecord.getChannels());
|
||||
|
||||
selectedWorkShift = workShiftRecord;
|
||||
}
|
||||
|
||||
void selectChannel(){
|
||||
if (selectedWorkShift != null){
|
||||
Integer ch = (Integer)cbChannel.getSelectedItem();
|
||||
flexibleJTable.setRows(selectedWorkShift.getChannelRecords(ch).getRecords());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -9,22 +9,28 @@ import javax.swing.border.EmptyBorder;
|
|||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.servicelink.exceptions.*;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
import javax.swing.JTabbedPane;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.Dimension;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JSpinner;
|
||||
|
@ -34,6 +40,7 @@ import javax.swing.JButton;
|
|||
import org.hwo.bitfields.BitField;
|
||||
import org.hwo.bitfields.Field;
|
||||
import org.hwo.bitfields.ui.BitFieldEditor;
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.ui.JTimeSpanEditor;
|
||||
|
@ -42,7 +49,7 @@ import java.awt.event.FocusEvent;
|
|||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
|
||||
public class DeviceConfiguration extends JFrame {
|
||||
public class DeviceConfiguration extends JDialog {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
|
@ -62,15 +69,25 @@ public class DeviceConfiguration extends JFrame {
|
|||
trigger;
|
||||
|
||||
int[] filter,
|
||||
windows;
|
||||
windows,
|
||||
increments;
|
||||
|
||||
private JTable tSettings;
|
||||
|
||||
|
||||
private IDeviceConnector deviceConnector;
|
||||
private JPanel pManagement;
|
||||
private JButton btnSnapshotSpeicherZurcksetzen;
|
||||
private JButton btnSnapshotSpeicherAuf;
|
||||
private JButton btnAlleZhlerLschen;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public DeviceConfiguration() {
|
||||
public DeviceConfiguration(IDeviceConnector deviceConnector) {
|
||||
this.deviceConnector = deviceConnector;
|
||||
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 860, 498);
|
||||
contentPane = new JPanel();
|
||||
|
@ -96,37 +113,24 @@ public class DeviceConfiguration extends JFrame {
|
|||
tabbedPane.addTab("Intervalle", null, panel_2, null);
|
||||
GridBagLayout gbl_panel_2 = new GridBagLayout();
|
||||
gbl_panel_2.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_panel_2.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
|
||||
gbl_panel_2.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_panel_2.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
panel_2.setLayout(gbl_panel_2);
|
||||
|
||||
bfeIntervall = new BitFieldEditor();
|
||||
bfeIntervall.setToolTipText("<html>\n<b>Tagesbasierte Intervalle</b><br/>\n<br/>\nTagesbasierte Intervalle werden immer auf 0:00:00 Uhr des aktuellen Tages bezogen ausgeführt.<br/>\nDies ermöglicht nicht nur eine Regelmäßige Aufzeichnung, sondern erzwingt auch eine Aufzeichnung<br/>\nin einem festgelegten immer gleichen Raster.<br/>\n<br/>\nNicht tageszeitbasierte Intervalle werden mit Bezug auf den 1.1.1970 0:00:00 Uhr ausgeführt.<br/>\nDiese ermöglichen eine stete regelmäßige Aufzeichnung bei der die tageszeit ignoriert wird.\n</html>");
|
||||
bfeIntervall.setToolTipText(Messages.getString("tooltip.tagesbasierte.intervalle")); //"<html>\n<b>Tagesbasierte Intervalle</b><br/>\n<br/>\nTagesbasierte Intervalle werden immer auf 0:00:00 Uhr des aktuellen Tages bezogen ausgeführt.<br/>\nDies ermöglicht nicht nur eine Regelmäßige Aufzeichnung, sondern erzwingt auch eine Aufzeichnung<br/>\nin einem festgelegten immer gleichen Raster.<br/>\n<br/>\nNicht tageszeitbasierte Intervalle werden mit Bezug auf den 1.1.1970 0:00:00 Uhr ausgeführt.<br/>\nDiese ermöglichen eine stete regelmäßige Aufzeichnung bei der die tageszeit ignoriert wird.\n</html>");
|
||||
bfeIntervall.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
int v = bfeIntervall.getIntValue();
|
||||
tseI0.setDaysEnabled(((v & 0x01)==0));
|
||||
tseI1.setDaysEnabled(((v & 0x02)==0));
|
||||
tseI2.setDaysEnabled(((v & 0x04)==0));
|
||||
tseI3.setDaysEnabled(((v & 0x08)==0));
|
||||
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
|
||||
sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (ServiceLinkException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
tseI3.setDaysEnabled(((v & 0x08)==0));
|
||||
}
|
||||
});
|
||||
|
||||
JLabel lblTageszeitabhngigkeit = new JLabel("Tageszeitabhängigkeit:");
|
||||
JLabel lblTageszeitabhngigkeit = new JLabel(Messages.getString("Tageszeitabhängigkeit:"));
|
||||
GridBagConstraints gbc_lblTageszeitabhngigkeit = new GridBagConstraints();
|
||||
gbc_lblTageszeitabhngigkeit.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblTageszeitabhngigkeit.insets = new Insets(0, 0, 5, 5);
|
||||
|
@ -141,8 +145,8 @@ public class DeviceConfiguration extends JFrame {
|
|||
gbc_bfeIntervall.gridy = 0;
|
||||
panel_2.add(bfeIntervall, gbc_bfeIntervall);
|
||||
|
||||
JLabel lblIntervall = new JLabel("Intervall 0:");
|
||||
lblIntervall.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
JLabel lblIntervall = new JLabel(Messages.getString("Intervall 0:"));
|
||||
lblIntervall.setToolTipText(Messages.getString("tooltip.intervall")); // "<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
GridBagConstraints gbc_lblIntervall = new GridBagConstraints();
|
||||
gbc_lblIntervall.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblIntervall.insets = new Insets(0, 0, 5, 5);
|
||||
|
@ -151,23 +155,10 @@ public class DeviceConfiguration extends JFrame {
|
|||
panel_2.add(lblIntervall, gbc_lblIntervall);
|
||||
|
||||
tseI0 = new JTimeSpanEditor();
|
||||
tseI0.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
tseI0.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
tseI0.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
System.err.println("FOCUS LOST 0");
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
|
||||
sl.writeInt(13, 0, 0x1010, (Integer)tseI0.getValue());
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (ServiceLinkException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_tseI0 = new GridBagConstraints();
|
||||
|
@ -177,8 +168,8 @@ public class DeviceConfiguration extends JFrame {
|
|||
gbc_tseI0.gridy = 1;
|
||||
panel_2.add(tseI0, gbc_tseI0);
|
||||
|
||||
JLabel lblIntervall_1 = new JLabel("Intervall 1:");
|
||||
lblIntervall_1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
JLabel lblIntervall_1 = new JLabel(Messages.getString("Intervall 1:"));
|
||||
lblIntervall_1.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
GridBagConstraints gbc_lblIntervall_1 = new GridBagConstraints();
|
||||
gbc_lblIntervall_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblIntervall_1.insets = new Insets(0, 0, 5, 5);
|
||||
|
@ -187,23 +178,10 @@ public class DeviceConfiguration extends JFrame {
|
|||
panel_2.add(lblIntervall_1, gbc_lblIntervall_1);
|
||||
|
||||
tseI1 = new JTimeSpanEditor();
|
||||
tseI1.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
tseI1.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
tseI1.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
|
||||
sl.writeInt(13, 0, 0x1011, (Integer)tseI1.getValue());
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (ServiceLinkException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_tseI1 = new GridBagConstraints();
|
||||
|
@ -213,8 +191,8 @@ public class DeviceConfiguration extends JFrame {
|
|||
gbc_tseI1.gridy = 2;
|
||||
panel_2.add(tseI1, gbc_tseI1);
|
||||
|
||||
JLabel lblIntervall_2 = new JLabel("Intervall 2:");
|
||||
lblIntervall_2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
JLabel lblIntervall_2 = new JLabel(Messages.getString("Intervall 2:"));
|
||||
lblIntervall_2.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
GridBagConstraints gbc_lblIntervall_2 = new GridBagConstraints();
|
||||
gbc_lblIntervall_2.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblIntervall_2.insets = new Insets(0, 0, 5, 5);
|
||||
|
@ -223,22 +201,10 @@ public class DeviceConfiguration extends JFrame {
|
|||
panel_2.add(lblIntervall_2, gbc_lblIntervall_2);
|
||||
|
||||
tseI2 = new JTimeSpanEditor();
|
||||
tseI2.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
tseI2.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
tseI2.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
|
||||
sl.writeInt(13, 0, 0x1012, (Integer)tseI2.getValue());
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (ServiceLinkException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_tseI2 = new GridBagConstraints();
|
||||
|
@ -248,35 +214,24 @@ public class DeviceConfiguration extends JFrame {
|
|||
gbc_tseI2.gridy = 3;
|
||||
panel_2.add(tseI2, gbc_tseI2);
|
||||
|
||||
JLabel lblIntervall_3 = new JLabel("Intervall 3:");
|
||||
lblIntervall_3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
JLabel lblIntervall_3 = new JLabel(Messages.getString("Intervall 3:"));
|
||||
lblIntervall_3.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
GridBagConstraints gbc_lblIntervall_3 = new GridBagConstraints();
|
||||
gbc_lblIntervall_3.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblIntervall_3.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_lblIntervall_3.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblIntervall_3.gridx = 0;
|
||||
gbc_lblIntervall_3.gridy = 4;
|
||||
panel_2.add(lblIntervall_3, gbc_lblIntervall_3);
|
||||
|
||||
tseI3 = new JTimeSpanEditor();
|
||||
tseI3.setToolTipText("<html>\n<b>Intervall</b><br/>\n<br/>\nStellen Sie die gewünschten Intervalllängen ein.<br/>\n<br/>\nEinheiten: <b>Tage, Stunden, Minuten, Sekunden</b>\n</html>");
|
||||
tseI3.setToolTipText(Messages.getString("tooltip.intervall"));
|
||||
tseI3.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
|
||||
sl.writeInt(13, 0, 0x1013, (Integer)tseI3.getValue());
|
||||
|
||||
} catch (ServiceLinkRequestFailedException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (ServiceLinkException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_tseI3 = new GridBagConstraints();
|
||||
gbc_tseI3.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tseI3.anchor = GridBagConstraints.WEST;
|
||||
gbc_tseI3.gridx = 1;
|
||||
gbc_tseI3.gridy = 4;
|
||||
|
@ -304,14 +259,70 @@ public class DeviceConfiguration extends JFrame {
|
|||
tSettings.setCellSelectionEnabled(true);
|
||||
scrollPane.setViewportView(tSettings);
|
||||
|
||||
JButton btnSchliessen = new JButton("abbrechen");
|
||||
pManagement = new JPanel();
|
||||
tabbedPane.addTab("Speicherverwaltung", null, pManagement, null);
|
||||
GridBagLayout gbl_pManagement = new GridBagLayout();
|
||||
gbl_pManagement.columnWidths = new int[] {100};
|
||||
gbl_pManagement.rowHeights = new int[]{25, 0, 0, 0, 0};
|
||||
gbl_pManagement.columnWeights = new double[]{1.0};
|
||||
gbl_pManagement.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
pManagement.setLayout(gbl_pManagement);
|
||||
|
||||
btnAlleZhlerLschen = new JButton(Messages.getString("Alle Zähler zurücksetzen"));
|
||||
btnAlleZhlerLschen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetCounters();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnAlleZhlerLschen_1_1 = new GridBagConstraints();
|
||||
gbc_btnAlleZhlerLschen_1_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_btnAlleZhlerLschen_1_1.gridx = 0;
|
||||
gbc_btnAlleZhlerLschen_1_1.gridy = 0;
|
||||
gbc_btnAlleZhlerLschen_1_1.insets = new Insets(0, 0, 5, 0);
|
||||
pManagement.add(btnAlleZhlerLschen, gbc_btnAlleZhlerLschen_1_1);
|
||||
|
||||
JLabel lblNurNachRcksprache = new JLabel(Messages.getString("Nur nach Rücksprache mit Support:"));
|
||||
GridBagConstraints gbc_lblNurNachRcksprache = new GridBagConstraints();
|
||||
gbc_lblNurNachRcksprache.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblNurNachRcksprache.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_lblNurNachRcksprache.gridx = 0;
|
||||
gbc_lblNurNachRcksprache.gridy = 1;
|
||||
pManagement.add(lblNurNachRcksprache, gbc_lblNurNachRcksprache);
|
||||
|
||||
btnSnapshotSpeicherZurcksetzen = new JButton(Messages.getString("SnapShot Speicher zurücksetzen"));
|
||||
btnSnapshotSpeicherZurcksetzen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetSnapShots();
|
||||
}
|
||||
});
|
||||
|
||||
btnSnapshotSpeicherAuf = new JButton(Messages.getString("SnapShot Speicher auf letzten bekannten SnapShot setzen"));
|
||||
btnSnapshotSpeicherAuf.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
resetSnapShots(true);
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnSnapshotSpeicherAuf_1_1 = new GridBagConstraints();
|
||||
gbc_btnSnapshotSpeicherAuf_1_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_btnSnapshotSpeicherAuf_1_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnSnapshotSpeicherAuf_1_1.gridx = 0;
|
||||
gbc_btnSnapshotSpeicherAuf_1_1.gridy = 2;
|
||||
pManagement.add(btnSnapshotSpeicherAuf, gbc_btnSnapshotSpeicherAuf_1_1);
|
||||
GridBagConstraints gbc_btnSnapshotSpeicherZurcksetzen_1_1 = new GridBagConstraints();
|
||||
gbc_btnSnapshotSpeicherZurcksetzen_1_1.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_btnSnapshotSpeicherZurcksetzen_1_1.gridx = 0;
|
||||
gbc_btnSnapshotSpeicherZurcksetzen_1_1.gridy = 3;
|
||||
pManagement.add(btnSnapshotSpeicherZurcksetzen, gbc_btnSnapshotSpeicherZurcksetzen_1_1);
|
||||
|
||||
|
||||
JButton btnSchliessen = new JButton(Messages.getString("Cancel"));
|
||||
btnSchliessen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
JButton btnOk = new JButton("OK");
|
||||
JButton btnOk = new JButton(Messages.getString("OK"));
|
||||
btnOk.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
writeDevice();
|
||||
|
@ -343,14 +354,16 @@ public class DeviceConfiguration extends JFrame {
|
|||
currentChannel = -1;
|
||||
filter = new int[32];
|
||||
windows = new int[32];
|
||||
increments = new int[32];
|
||||
|
||||
tmSettings = new TableMapper(ChannelConfiguration.class, tSettings);
|
||||
|
||||
BitField bf = new BitField();
|
||||
bf.clear();
|
||||
bf.addField(new Field(bf, 0, 1, "Intervall 0 basiert auf Tageszeit"));
|
||||
bf.addField(new Field(bf, 1, 1, "Intervall 1 basiert auf Tageszeit"));
|
||||
bf.addField(new Field(bf, 2, 1, "Intervall 2 basiert auf Tageszeit"));
|
||||
bf.addField(new Field(bf, 3, 1, "Intervall 3 basiert auf Tageszeit"));
|
||||
bf.addField(new Field(bf, 0, 1, Messages.getString("Intervall 0 basiert auf Tageszeit")));
|
||||
bf.addField(new Field(bf, 1, 1, Messages.getString("Intervall 1 basiert auf Tageszeit")));
|
||||
bf.addField(new Field(bf, 2, 1, Messages.getString("Intervall 2 basiert auf Tageszeit")));
|
||||
bf.addField(new Field(bf, 3, 1, Messages.getString("Intervall 3 basiert auf Tageszeit")));
|
||||
bfeIntervall.setBitField(bf);
|
||||
for (int i=0;i<32;i++){
|
||||
tmSettings.addRow(new ChannelConfiguration(i));
|
||||
|
@ -360,72 +373,72 @@ public class DeviceConfiguration extends JFrame {
|
|||
readDevice();
|
||||
}
|
||||
|
||||
private void resetSnapShots(){
|
||||
resetSnapShots(false);
|
||||
}
|
||||
|
||||
private void resetSnapShots(boolean toLastKnown){
|
||||
if (JOptionPane.showConfirmDialog(null,
|
||||
Messages.getString("<html>Diese Funktion sollte nur auf Aufforderung durch den Support ausgeführt werden.<br/>Soll der Snapshot Index auf dem Gerät wirklich zurückgesetzt werden?</html>"),
|
||||
Messages.getString("Snapshot Index zurücksetzen"),
|
||||
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
|
||||
deviceConnector.reset(toLastKnown ? PulsCounterApplication.getApplication().getDatabase().highestSnapShot(deviceConnector.getDeviceSerial()) : -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetCounters(){
|
||||
|
||||
if (JOptionPane.showConfirmDialog(null,
|
||||
Messages.getString("Wollen Sie wirklich alle Zählerstände auf 0 zurücksetzen?"),
|
||||
Messages.getString("Alle Zählerstände zurücksetzen"),
|
||||
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
|
||||
int[] zero = new int[32];
|
||||
Arrays.fill(zero, 0);
|
||||
deviceConnector.setCounters(zero);
|
||||
}
|
||||
}
|
||||
|
||||
private void readDevice(){
|
||||
Integer v;
|
||||
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
|
||||
outputs = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1008));
|
||||
pullups = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1009));
|
||||
inverts = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100A));
|
||||
trigger = intOr0(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x100B));
|
||||
outputs = intOr0(deviceConnector.getConfigOutputs());
|
||||
pullups = intOr0(deviceConnector.getConfigPullups());
|
||||
inverts = intOr0(deviceConnector.getConfigInverts());
|
||||
trigger = intOr0(deviceConnector.getConfigTriggers());
|
||||
|
||||
bfeIntervall.setIntValue(sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1003));
|
||||
bfeIntervall.setIntValue(deviceConnector.getDailyBaseMask());
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
filter[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1020 + i));
|
||||
windows[i] = intOr0( sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1280 + i));
|
||||
}
|
||||
filter = deviceConnector.getDebounce();
|
||||
windows = deviceConnector.getWindows();
|
||||
increments = deviceConnector.getIncrements();
|
||||
|
||||
|
||||
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1010);
|
||||
if (v!=null){
|
||||
tseI0.setValue(v);
|
||||
}
|
||||
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1011);
|
||||
if (v!=null){
|
||||
tseI1.setValue(v);
|
||||
}
|
||||
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1012);
|
||||
if (v!=null){
|
||||
tseI2.setValue(v);
|
||||
}
|
||||
v = sl.getServiceRegisterCache().getCachedInteger(13, 0, 0x1013);
|
||||
if (v!=null){
|
||||
tseI3.setValue(v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Integer iv0 = deviceConnector.getInterval(0);
|
||||
tseI0.setValue( iv0 == 0 ? null : iv0 );
|
||||
Integer iv1 = deviceConnector.getInterval(0);
|
||||
tseI1.setValue( iv1 == 0 ? null : iv1 );
|
||||
Integer iv2 = deviceConnector.getInterval(0);
|
||||
tseI2.setValue( iv2 == 0 ? null : iv2 );
|
||||
Integer iv3 = deviceConnector.getInterval(0);
|
||||
tseI3.setValue( iv3 == 0 ? null : iv3 );
|
||||
}
|
||||
|
||||
private void writeDevice(){
|
||||
ServiceLink sl = PulsCounter2Application.getApplication().getServiceLink();
|
||||
try {
|
||||
sl.writeInt(13, 0, 0x1008, outputs);
|
||||
sl.writeInt(13, 0, 0x1009, pullups);
|
||||
sl.writeInt(13, 0, 0x100A, inverts);
|
||||
sl.writeInt(13, 0, 0x100B, trigger);
|
||||
|
||||
sl.writeInt(13, 0, 0x1003, bfeIntervall.getIntValue());
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
sl.writeInt(13, 0, 0x1020 + i, filter[i]);
|
||||
sl.writeInt(13, 0, 0x1280 + i, windows[i]);
|
||||
}
|
||||
|
||||
|
||||
sl.writeInt(13, 0, 0x1010, tseI0.getValue());
|
||||
sl.writeInt(13, 0, 0x1011, tseI1.getValue());
|
||||
sl.writeInt(13, 0, 0x1012, tseI2.getValue());
|
||||
sl.writeInt(13, 0, 0x1013, tseI3.getValue());
|
||||
|
||||
/* Konfiguration auf Live-System übertragen */
|
||||
sl.writeInt(13, 0, 0x1001, 1);
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
deviceConnector.setInterval(0, tseI0.getValue(), ((bfeIntervall.getIntValue() & (1<<0)) != 0) ? true : false);
|
||||
deviceConnector.setInterval(1, tseI1.getValue(), ((bfeIntervall.getIntValue() & (1<<1)) != 0) ? true : false);
|
||||
deviceConnector.setInterval(2, tseI2.getValue(), ((bfeIntervall.getIntValue() & (1<<2)) != 0) ? true : false);
|
||||
deviceConnector.setInterval(3, tseI3.getValue(), ((bfeIntervall.getIntValue() & (1<<3)) != 0) ? true : false);
|
||||
|
||||
deviceConnector.setConfigOutputs(outputs);
|
||||
deviceConnector.setConfigPullups(pullups);
|
||||
deviceConnector.setConfigInverts(inverts);
|
||||
deviceConnector.setConfigTriggers(trigger);
|
||||
|
||||
deviceConnector.setDebounce(filter);
|
||||
deviceConnector.setWindows(windows);
|
||||
deviceConnector.setIncrements(increments);
|
||||
|
||||
deviceConnector.syncConfigToLive();
|
||||
}
|
||||
|
||||
class ChannelConfiguration{
|
||||
|
@ -436,7 +449,7 @@ public class DeviceConfiguration extends JFrame {
|
|||
this.channel = channel;
|
||||
}
|
||||
|
||||
@TableColumn(label="Channel",width=80,order=0)
|
||||
@TableColumn(label="Kanal",width=60,order=0,format="%02d")
|
||||
public int getChannel(){
|
||||
return channel;
|
||||
}
|
||||
|
@ -501,6 +514,14 @@ public class DeviceConfiguration extends JFrame {
|
|||
filter[channel] = value;
|
||||
}
|
||||
|
||||
@TableColumn(label="Inkrement",width=80,order=190)
|
||||
public Integer getIncrement(){
|
||||
return increments[channel];
|
||||
}
|
||||
public void setIncrement(Integer increment){
|
||||
increments[channel] = increment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -8,10 +8,14 @@ import javax.swing.JPanel;
|
|||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.datetime.DateTime;
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.hwo.logging.Logging;
|
||||
import org.hwo.logging.LoggingListener;
|
||||
import org.hwo.pulscounter.DeviceTester;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.PulsCounterApplicationListener;
|
||||
import org.hwo.pulscounter.SnapshotManager.Notification;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.pulscounter.device.ServiceLinkDeviceConnector;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.exceptions.*;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JLabel;
|
||||
|
@ -27,7 +31,12 @@ import javax.swing.JButton;
|
|||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
public class DeviceTestFrame extends JFrame implements PulsCounterApplicationListener {
|
||||
import static org.hwo.logging.Logging.*;
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class DeviceTestFrame extends JFrame implements LoggingListener{
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTextField tfCommunication;
|
||||
|
@ -42,11 +51,14 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
private JList lMessages;
|
||||
private DefaultListModel<String> messageListModel;
|
||||
|
||||
private PulsCounterApplication pulsCounterApplication;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public DeviceTestFrame() {
|
||||
public DeviceTestFrame(PulsCounterApplication pulsCounterApplication) {
|
||||
this.pulsCounterApplication = pulsCounterApplication;
|
||||
|
||||
setTitle("Device Test Frame");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 701, 464);
|
||||
|
@ -152,6 +164,18 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
contentPane.add(tfSerial, gbc_tfSerial);
|
||||
tfSerial.setColumns(10);
|
||||
|
||||
JButton btnStart = new JButton("Start");
|
||||
btnStart.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
startTest();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnStart = new GridBagConstraints();
|
||||
gbc_btnStart.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_btnStart.gridx = 0;
|
||||
gbc_btnStart.gridy = 6;
|
||||
contentPane.add(btnStart, gbc_btnStart);
|
||||
|
||||
JButton btnSetDevice = new JButton("Confirm Device");
|
||||
GridBagConstraints gbc_btnSetDevice = new GridBagConstraints();
|
||||
gbc_btnSetDevice.insets = new Insets(0, 0, 5, 0);
|
||||
|
@ -163,7 +187,6 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 7;
|
||||
contentPane.add(scrollPane, gbc_scrollPane);
|
||||
|
@ -174,8 +197,8 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
this.initialize();
|
||||
}
|
||||
|
||||
private PulsCounter2Application application(){
|
||||
return PulsCounter2Application.getApplication();
|
||||
private PulsCounterApplication application(){
|
||||
return this.pulsCounterApplication;
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
|
@ -183,18 +206,17 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
|
||||
messageListModel = new DefaultListModel<String>();
|
||||
lMessages.setModel(messageListModel);
|
||||
|
||||
application().addPulsCounterApplicationListener(this);
|
||||
application().fireConnectionStateChanged(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialPortChanged() {
|
||||
// TODO Auto-generated method stub
|
||||
// Logging.getInstance().addLoggingListener(this);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
ServiceLink getServiceLink(){
|
||||
return ((ServiceLinkDeviceConnector)(application().getInterfaces().get(0))).getServiceLink();
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void connectionStateChanged(Boolean connected) {
|
||||
|
||||
|
@ -207,9 +229,9 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!application().getServiceLink().isOpen()){
|
||||
if (!getServiceLink().isOpen()){
|
||||
try {
|
||||
application().getServiceLink().open();
|
||||
getServiceLink().open();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -218,28 +240,50 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
}, 3000);
|
||||
|
||||
} else {
|
||||
if (this.deviceChecker != null){
|
||||
while (this.deviceChecker.isAlive()){
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.deviceChecker = new DeviceChecker();
|
||||
this.deviceChecker.start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
private void startTest(){
|
||||
/*
|
||||
if (this.deviceChecker != null){
|
||||
while (this.deviceChecker.isAlive()){
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.deviceChecker = new DeviceChecker();
|
||||
this.deviceChecker.start();
|
||||
*/
|
||||
|
||||
DeviceTester dt = new DeviceTester( (application().getInterfaces().get(0)) );
|
||||
dt.start();
|
||||
|
||||
while (dt.isAlive()){
|
||||
try {
|
||||
dt.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void messageArrived(String message) {
|
||||
public void logMessageArrived(String message) {
|
||||
if (EventQueue.isDispatchThread()){
|
||||
int pos = messageListModel.size();
|
||||
String t = String.format("%s: %s",DateTime.NOW().getSQLDateTime(),message);
|
||||
messageListModel.addElement(t);
|
||||
messageListModel.addElement(message);
|
||||
if (messageListModel.getSize() > 32)
|
||||
messageListModel.remove(0);
|
||||
|
||||
lMessages.ensureIndexIsVisible(messageListModel.size()-1);
|
||||
} else {
|
||||
final String msg = message;
|
||||
|
@ -247,7 +291,7 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
messageArrived(msg);
|
||||
logMessageArrived(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -269,6 +313,12 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
getServiceLink().open();
|
||||
} catch (ServiceLinkException e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
checkCommunication();
|
||||
checkEEPROM();
|
||||
checkIO();
|
||||
|
@ -282,8 +332,8 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
|
||||
private void checkCommunication(){
|
||||
if (!this.cancel){
|
||||
Integer version = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x001A);
|
||||
Integer uptime = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0022);
|
||||
Integer version = getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x001A);
|
||||
Integer uptime = getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x0022);
|
||||
|
||||
if ((version != null)&&(uptime != null)){
|
||||
tfCommunication.setText(String.format("OK (V: %d.%d.%d) Up: %d:%d:%d",version >> 16, (version >> 8) & 0xff, version & 0xff, uptime / 3600, (uptime / 60)%60, uptime % 60));
|
||||
|
@ -293,7 +343,7 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
|
||||
private void checkEEPROM(){
|
||||
if (!this.cancel){
|
||||
Integer eesize = application().getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x9000);
|
||||
Integer eesize = getServiceLink().getServiceRegisterCache().getCachedInteger(13, 0, 0x9000);
|
||||
if (eesize != null){
|
||||
tfEEPROM.setText(String.format("EEPROM Size Detected: 0x%08x Bytes (%d kBytes)", eesize, (eesize >> 10)));
|
||||
} else {
|
||||
|
@ -305,50 +355,50 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
private void checkIO(){
|
||||
if (!this.cancel){
|
||||
|
||||
application().message("I/O test begins...");
|
||||
application().message("I/O reset...");
|
||||
log(INFO,"I/O test begins...");
|
||||
log(INFO,"I/O reset...");
|
||||
|
||||
try {
|
||||
application().getServiceLink().writeInt(13, 0, 0x0682, 0);
|
||||
application().getServiceLink().writeInt(13, 0, 0x0683, 0);
|
||||
application().getServiceLink().writeInt(13, 0, 0x0684, 0);
|
||||
application().getServiceLink().writeInt(13, 0, 0x0685, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0682, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0683, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0684, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0685, 0);
|
||||
|
||||
application().message("counter reset.");
|
||||
log(INFO,"counter reset.");
|
||||
for (int i=0;i<32;i++){
|
||||
application().getServiceLink().writeInt(13, 0, 0x0600 + i, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0600 + i, 0);
|
||||
}
|
||||
|
||||
application().message("PullUP-Counter test.");
|
||||
log(INFO,"PullUP-Counter test.");
|
||||
for (int i=0;i<12;i++){
|
||||
Thread.sleep(250);
|
||||
application().getServiceLink().writeInt(13, 0, 0x0683, -1);
|
||||
getServiceLink().writeInt(13, 0, 0x0683, -1);
|
||||
Thread.sleep(250);
|
||||
application().getServiceLink().writeInt(13, 0, 0x0683, 0);
|
||||
getServiceLink().writeInt(13, 0, 0x0683, 0);
|
||||
}
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
Thread.sleep(100);
|
||||
|
||||
Integer c = application().getServiceLink().readInt(13, 0, 0x0600 + i);
|
||||
Integer c = getServiceLink().readInt(13, 0, 0x0600 + i);
|
||||
if ((c != null) && (c.equals(12))){
|
||||
application().message(String.format("OK: Channel %d counted %d events.", i, c));
|
||||
log(INFO,String.format("OK: Channel %d counted %d events.", i, c));
|
||||
} else {
|
||||
application().message(String.format("FAILED: Channel %d counted %d events.", i, c));
|
||||
log(INFO,String.format("FAILED: Channel %d counted %d events.", i, c));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
application().message("I/O test finished!");
|
||||
log(INFO,"I/O test finished!");
|
||||
} catch (IOException | ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
application().message("I/O test FAILED!");
|
||||
log(INFO,"I/O test FAILED!");
|
||||
} catch (InterruptedException iex){
|
||||
iex.printStackTrace();
|
||||
|
||||
application().message("I/O test FAILED!");
|
||||
log(INFO,"I/O test FAILED!");
|
||||
}
|
||||
|
||||
|
||||
|
@ -362,5 +412,6 @@ public class DeviceTestFrame extends JFrame implements PulsCounterApplicationLis
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,14 +9,17 @@ import javax.swing.border.EmptyBorder;
|
|||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.interactiveobjects.ObjectEditorUI;
|
||||
import org.hwo.interactiveobjects.ObjectEditorUIHelper;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.pulscounter.ExportSetting;
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.Insets;
|
||||
|
@ -26,8 +29,10 @@ import java.awt.event.ActionEvent;
|
|||
import javax.swing.JToolBar;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.JSeparator;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
|
||||
public class ExportFilesFrame extends JFrame {
|
||||
public class ExportFilesFrame extends JDialog {
|
||||
|
||||
private JPanel contentPane;
|
||||
private JTable tExportSettings;
|
||||
|
@ -41,12 +46,15 @@ public class ExportFilesFrame extends JFrame {
|
|||
private ExportSetting selectedExportSetting;
|
||||
private JSeparator separator;
|
||||
private JButton btnExec;
|
||||
private JButton btnBatch;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public ExportFilesFrame() {
|
||||
setTitle("Export Einstellungen...");
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
|
||||
setTitle(Messages.getString("Export Einstellungen..."));
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 825, 433);
|
||||
contentPane = new JPanel();
|
||||
|
@ -69,8 +77,8 @@ public class ExportFilesFrame extends JFrame {
|
|||
gbc_toolBar.gridy = 0;
|
||||
contentPane.add(toolBar, gbc_toolBar);
|
||||
|
||||
bAdd = new JButton("+");
|
||||
bAdd.setToolTipText("<html>\n<b>Neue Exportkonfiguration hinzufügen</b><br/>\n</html>");
|
||||
bAdd = new JButton(Messages.getString("Export hinzufügen"));
|
||||
bAdd.setToolTipText(Messages.getString("tooltip.export.add")); //"<html>\n<b>Neue Exportkonfiguration hinzufügen</b><br/>\n</html>");
|
||||
bAdd.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ExportSetting es = new ExportSetting();
|
||||
|
@ -79,8 +87,8 @@ public class ExportFilesFrame extends JFrame {
|
|||
});
|
||||
toolBar.add(bAdd);
|
||||
|
||||
bEdit = new JButton("e");
|
||||
bEdit.setToolTipText("<html>\n<b>Ausgewählte Exportkonfiguration bearbeiten</b>\n</html>");
|
||||
bEdit = new JButton(Messages.getString("Einstellungen"));
|
||||
bEdit.setToolTipText(Messages.getString("tooltip.export.configuration")); // "<html>\n<b>Ausgewählte Exportkonfiguration bearbeiten</b>\n</html>");
|
||||
bEdit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ExportSetting es = (ExportSetting)tmExportSettings.getSelectedRow();
|
||||
|
@ -94,8 +102,8 @@ public class ExportFilesFrame extends JFrame {
|
|||
bEdit.setEnabled(false);
|
||||
toolBar.add(bEdit);
|
||||
|
||||
bRemove = new JButton("-");
|
||||
bRemove.setToolTipText("<html>\n<b>Ausgewählte Exportkonfiguration entfernen</b>\n</html>");
|
||||
bRemove = new JButton(Messages.getString(Messages.getString("Export löschen")));
|
||||
bRemove.setToolTipText(Messages.getString("tooltip.export.remove")); // "<html>\n<b>Ausgewählte Exportkonfiguration entfernen</b>\n</html>");
|
||||
bRemove.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (selectedExportSetting != null){
|
||||
|
@ -110,8 +118,8 @@ public class ExportFilesFrame extends JFrame {
|
|||
separator = new JSeparator();
|
||||
toolBar.add(separator);
|
||||
|
||||
btnExec = new JButton("EXEC");
|
||||
btnExec.setToolTipText("<html>\n<b>Ausgewählte Exportkonfiguration jetzt ausführen</b><br/>\n</html>");
|
||||
btnExec = new JButton(Messages.getString("Export ausführen"));
|
||||
btnExec.setToolTipText(Messages.getString("tooltip.export.run")); //"<html>\n<b>Ausgewählte Exportkonfiguration jetzt ausführen</b><br/>\n</html>");
|
||||
btnExec.setEnabled(false);
|
||||
btnExec.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -120,8 +128,16 @@ public class ExportFilesFrame extends JFrame {
|
|||
});
|
||||
toolBar.add(btnExec);
|
||||
|
||||
btnBatch = new JButton(Messages.getString("Automatiklauf"));
|
||||
btnBatch.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doBatchExport();
|
||||
}
|
||||
});
|
||||
toolBar.add(btnBatch);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setToolTipText("<html>\n<b>Exportkonfigurationen</b><br/>\nZeigt eine Übersicht über die aktuell vorhandenen Exportkonfigurationen\n</html>");
|
||||
scrollPane.setToolTipText(Messages.getString("tooltip.export.list")); // "<html>\n<b>Exportkonfigurationen</b><br/>\nZeigt eine Übersicht über die aktuell vorhandenen Exportkonfigurationen\n</html>");
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridwidth = 3;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
|
@ -141,14 +157,13 @@ public class ExportFilesFrame extends JFrame {
|
|||
setSelectedExportSetting(es);
|
||||
}
|
||||
});
|
||||
tmExportSettings.setRows(PulsCounter2Application.getApplication().getExportSettings());
|
||||
tmExportSettings.setRows(PulsCounterApplication.getApplication().getExportSettings());
|
||||
scrollPane.setViewportView(tExportSettings);
|
||||
|
||||
JButton btnSchliessen = new JButton("schliessen");
|
||||
JButton btnSchliessen = new JButton(Messages.getString("schliessen"));
|
||||
btnSchliessen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
PulsCounter2Application.getApplication().savePrefs();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnSchliessen = new GridBagConstraints();
|
||||
|
@ -177,5 +192,12 @@ public class ExportFilesFrame extends JFrame {
|
|||
((ExportSetting)tmExportSettings.getSelectedRow()).export();
|
||||
}
|
||||
|
||||
public void doBatchExport(){
|
||||
for (ExportSetting es: PulsCounterApplication.getApplication().getExportSettings()){
|
||||
if (es.getAutostart()){
|
||||
es.export();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ public class ExportSettingsEditorDialog extends JDialog implements IObjectEditor
|
|||
}
|
||||
});
|
||||
cbTriggerType.addItem(TriggerType.ALL);
|
||||
cbTriggerType.addItem(TriggerType.Trigger);
|
||||
cbTriggerType.addItem(TriggerType.Intervall);
|
||||
cbTriggerType.addItem(TriggerType.Timer);
|
||||
cbTriggerType.addItem(TriggerType.Manual);
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import org.hwo.datetime.Date;
|
||||
import org.hwo.pulscounter.PulsCounter;
|
||||
import org.hwo.pulscounter.elements.WorkShift;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class InspectionMainFrame extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
InspectionMainFrame frame = new InspectionMainFrame();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public InspectionMainFrame() {
|
||||
setTitle("Inspektor");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 841, 607);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPane.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
JButton btnNewButton = new JButton("Schichtdaten prüfen...");
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
WorkShift[] shifts = PulsCounter.getInspectorApplication().getWorkShifts();
|
||||
Date d = new Date();
|
||||
d.addDays(10);
|
||||
for (int i=0;i<40;i++){
|
||||
|
||||
for (int s = 0;s<shifts.length;s++){
|
||||
System.out.println(shifts[s].getName() + ": " + shifts[s].getShiftBegins(d).getSQLDateTime() + " - " + shifts[s].getShiftEnds(d).getSQLDateTime() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||||
gbc_btnNewButton.gridx = 0;
|
||||
gbc_btnNewButton.gridy = 0;
|
||||
panel.add(btnNewButton, gbc_btnNewButton);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
panel_1.setBorder(new TitledBorder(null, "Einstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
||||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_1.gridx = 0;
|
||||
gbc_panel_1.gridy = 1;
|
||||
contentPane.add(panel_1, gbc_panel_1);
|
||||
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||||
gbl_panel_1.columnWidths = new int[]{0, 0};
|
||||
gbl_panel_1.rowHeights = new int[]{0, 0};
|
||||
gbl_panel_1.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel_1.setLayout(gbl_panel_1);
|
||||
|
||||
JButton btnSchichten = new JButton("Schichten");
|
||||
btnSchichten.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnSchichten = new GridBagConstraints();
|
||||
gbc_btnSchichten.gridx = 0;
|
||||
gbc_btnSchichten.gridy = 0;
|
||||
panel_1.add(btnSchichten, gbc_btnSchichten);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,664 +0,0 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.datetime.JTimeOfDay;
|
||||
import org.hwo.io.SerialPortExeption;
|
||||
import org.hwo.servicelink.ServiceLink;
|
||||
import org.hwo.servicelink.ServiceLinkException;
|
||||
import org.hwo.servicelink.ServiceLinkRequestFailedException;
|
||||
import org.hwo.ui.MousePopupListener;
|
||||
import org.hwo.pulscounter.CounterChannel;
|
||||
import org.hwo.pulscounter.PulsCounter2Application;
|
||||
import org.postgresql.util.UnixCrypt;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream.PutField;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class LiveViewFrame extends JFrame implements AppSettingsListener {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
private Timer liveViewTimer;
|
||||
private ServiceLink serviceLink;
|
||||
|
||||
private JLabel[] inputButtons;
|
||||
private JToggleButton[] pullupButtons;
|
||||
private JToggleButton[] outputButtons;
|
||||
|
||||
private JLabel[] analogLabels;
|
||||
|
||||
private JPanel pDisplay;
|
||||
private JPanel pPullups;
|
||||
private JPanel pAnalog;
|
||||
private JPanel pOutputs;
|
||||
|
||||
private Integer pinputs,
|
||||
inputs,
|
||||
outputs,
|
||||
pullups;
|
||||
private JPanel pDateTime;
|
||||
private JLabel lblUnixZeitstempel;
|
||||
private JTextField tfUnixTime;
|
||||
private JLabel lblAktuellesDatum;
|
||||
private JTextField tfHumanDateTime;
|
||||
private JButton btnSynchronisieren;
|
||||
private JPanel panel;
|
||||
private JScrollPane scrollPane;
|
||||
private JList lMessages;
|
||||
private JPanel panel_1;
|
||||
private JButton btnSnapshot;
|
||||
private JButton btnLeeren;
|
||||
private JButton btnLaufzeitKorrigieren;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public LiveViewFrame() {
|
||||
setTitle("Live Ansicht");
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 1037, 875);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
pDisplay = new JPanel();
|
||||
pDisplay.setBorder(new TitledBorder(null, "Eing\u00E4nge", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_pDisplay = new GridBagConstraints();
|
||||
gbc_pDisplay.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pDisplay.fill = GridBagConstraints.BOTH;
|
||||
gbc_pDisplay.gridx = 0;
|
||||
gbc_pDisplay.gridy = 0;
|
||||
contentPane.add(pDisplay, gbc_pDisplay);
|
||||
GridBagLayout gbl_pDisplay = new GridBagLayout();
|
||||
gbl_pDisplay.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
|
||||
gbl_pDisplay.rowHeights = new int[] {25, 25, 25, 25};
|
||||
gbl_pDisplay.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
|
||||
gbl_pDisplay.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
|
||||
pDisplay.setLayout(gbl_pDisplay);
|
||||
|
||||
pPullups = new JPanel();
|
||||
pPullups.setBorder(new TitledBorder(null, "PullUPs", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_pPullups = new GridBagConstraints();
|
||||
gbc_pPullups.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pPullups.fill = GridBagConstraints.BOTH;
|
||||
gbc_pPullups.gridx = 0;
|
||||
gbc_pPullups.gridy = 1;
|
||||
contentPane.add(pPullups, gbc_pPullups);
|
||||
GridBagLayout gbl_pPullups = new GridBagLayout();
|
||||
gbl_pPullups.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
|
||||
gbl_pPullups.rowHeights = new int[] {25, 25, 25, 25};
|
||||
gbl_pPullups.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
|
||||
gbl_pPullups.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
|
||||
pPullups.setLayout(gbl_pPullups);
|
||||
|
||||
pOutputs = new JPanel();
|
||||
pOutputs.setBorder(new TitledBorder(null, "Ausg\u00E4nge", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_pOutputs = new GridBagConstraints();
|
||||
gbc_pOutputs.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pOutputs.fill = GridBagConstraints.BOTH;
|
||||
gbc_pOutputs.gridx = 0;
|
||||
gbc_pOutputs.gridy = 2;
|
||||
contentPane.add(pOutputs, gbc_pOutputs);
|
||||
GridBagLayout gbl_pOutputs = new GridBagLayout();
|
||||
gbl_pOutputs.columnWidths = new int[] {50, 50, 50, 50, 50, 50, 50, 50};
|
||||
gbl_pOutputs.rowHeights = new int[] {25, 25, 25, 25};
|
||||
gbl_pOutputs.columnWeights = new double[]{1.0, 1.0,1.0, 1.0,1.0, 1.0,1.0, 1.0};
|
||||
gbl_pOutputs.rowWeights = new double[]{1.0, 1.0,1.0, 1.0};
|
||||
pOutputs.setLayout(gbl_pOutputs);
|
||||
|
||||
pAnalog = new JPanel();
|
||||
pAnalog.setBorder(new TitledBorder(null, "Analogkan\u00E4le", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_pAnalog = new GridBagConstraints();
|
||||
gbc_pAnalog.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pAnalog.fill = GridBagConstraints.BOTH;
|
||||
gbc_pAnalog.gridx = 0;
|
||||
gbc_pAnalog.gridy = 3;
|
||||
contentPane.add(pAnalog, gbc_pAnalog);
|
||||
pAnalog.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
|
||||
pDateTime = new JPanel();
|
||||
pDateTime.setBorder(new TitledBorder(null, "Datum und Zeit", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_pDateTime = new GridBagConstraints();
|
||||
gbc_pDateTime.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_pDateTime.fill = GridBagConstraints.BOTH;
|
||||
gbc_pDateTime.gridx = 0;
|
||||
gbc_pDateTime.gridy = 4;
|
||||
contentPane.add(pDateTime, gbc_pDateTime);
|
||||
GridBagLayout gbl_pDateTime = new GridBagLayout();
|
||||
gbl_pDateTime.columnWidths = new int[]{0, 0, 0, 0, 0};
|
||||
gbl_pDateTime.rowHeights = new int[]{0, 0, 0};
|
||||
gbl_pDateTime.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_pDateTime.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||||
pDateTime.setLayout(gbl_pDateTime);
|
||||
|
||||
lblUnixZeitstempel = new JLabel("Unix Zeitstempel:");
|
||||
GridBagConstraints gbc_lblUnixZeitstempel = new GridBagConstraints();
|
||||
gbc_lblUnixZeitstempel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblUnixZeitstempel.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblUnixZeitstempel.gridx = 0;
|
||||
gbc_lblUnixZeitstempel.gridy = 0;
|
||||
pDateTime.add(lblUnixZeitstempel, gbc_lblUnixZeitstempel);
|
||||
|
||||
tfUnixTime = new JTextField();
|
||||
GridBagConstraints gbc_tfUnixTime = new GridBagConstraints();
|
||||
gbc_tfUnixTime.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_tfUnixTime.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfUnixTime.gridx = 1;
|
||||
gbc_tfUnixTime.gridy = 0;
|
||||
pDateTime.add(tfUnixTime, gbc_tfUnixTime);
|
||||
tfUnixTime.setColumns(10);
|
||||
|
||||
lblAktuellesDatum = new JLabel("Aktuelles Datum:");
|
||||
GridBagConstraints gbc_lblAktuellesDatum = new GridBagConstraints();
|
||||
gbc_lblAktuellesDatum.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblAktuellesDatum.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblAktuellesDatum.gridx = 2;
|
||||
gbc_lblAktuellesDatum.gridy = 0;
|
||||
pDateTime.add(lblAktuellesDatum, gbc_lblAktuellesDatum);
|
||||
|
||||
tfHumanDateTime = new JTextField();
|
||||
GridBagConstraints gbc_tfHumanDateTime = new GridBagConstraints();
|
||||
gbc_tfHumanDateTime.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tfHumanDateTime.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfHumanDateTime.gridx = 3;
|
||||
gbc_tfHumanDateTime.gridy = 0;
|
||||
pDateTime.add(tfHumanDateTime, gbc_tfHumanDateTime);
|
||||
tfHumanDateTime.setColumns(10);
|
||||
|
||||
btnSynchronisieren = new JButton("Synchronisieren");
|
||||
btnSynchronisieren.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
syncUnixTime();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnSynchronisieren = new GridBagConstraints();
|
||||
gbc_btnSynchronisieren.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_btnSynchronisieren.gridx = 1;
|
||||
gbc_btnSynchronisieren.gridy = 1;
|
||||
pDateTime.add(btnSynchronisieren, gbc_btnSynchronisieren);
|
||||
|
||||
btnLaufzeitKorrigieren = new JButton("Laufzeit korrigieren");
|
||||
btnLaufzeitKorrigieren.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
quartzCorrect();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnLaufzeitKorrigieren = new GridBagConstraints();
|
||||
gbc_btnLaufzeitKorrigieren.gridx = 3;
|
||||
gbc_btnLaufzeitKorrigieren.gridy = 1;
|
||||
pDateTime.add(btnLaufzeitKorrigieren, gbc_btnLaufzeitKorrigieren);
|
||||
|
||||
panel_1 = new JPanel();
|
||||
panel_1.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), "Kommandos", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
||||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_1.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel_1.gridx = 0;
|
||||
gbc_panel_1.gridy = 5;
|
||||
contentPane.add(panel_1, gbc_panel_1);
|
||||
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||||
gbl_panel_1.columnWidths = new int[]{0, 0};
|
||||
gbl_panel_1.rowHeights = new int[]{0, 0};
|
||||
gbl_panel_1.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel_1.setLayout(gbl_panel_1);
|
||||
|
||||
btnSnapshot = new JButton("SnapShot");
|
||||
btnSnapshot.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
manualSnapshot();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnSnapshot = new GridBagConstraints();
|
||||
gbc_btnSnapshot.gridx = 0;
|
||||
gbc_btnSnapshot.gridy = 0;
|
||||
panel_1.add(btnSnapshot, gbc_btnSnapshot);
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Meldungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 6;
|
||||
contentPane.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{383, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 131, 0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
panel.add(scrollPane, gbc_scrollPane);
|
||||
|
||||
lMessages = new JList();
|
||||
scrollPane.setViewportView(lMessages);
|
||||
|
||||
btnLeeren = new JButton("leeren");
|
||||
btnLeeren.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
((DefaultListModel)lMessages.getModel()).clear();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnLeeren = new GridBagConstraints();
|
||||
gbc_btnLeeren.gridx = 0;
|
||||
gbc_btnLeeren.gridy = 2;
|
||||
panel.add(btnLeeren, gbc_btnLeeren);
|
||||
|
||||
initialize();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
pc2a.removeAppSettingsListener(this);
|
||||
|
||||
liveViewTimer.cancel();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
PulsCounter2Application pc2a = PulsCounter2Application.getApplication();
|
||||
|
||||
lMessages.setModel(new DefaultListModel<String>());
|
||||
|
||||
inputButtons = new JLabel[32];
|
||||
outputButtons = new JToggleButton[32];
|
||||
pullupButtons = new JToggleButton[32];
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
final int n = i;
|
||||
|
||||
inputButtons[i] = new JLabel(String.format("%d", i));
|
||||
inputButtons[i].setOpaque(true);
|
||||
inputButtons[i].setHorizontalAlignment(SwingConstants.CENTER);
|
||||
inputButtons[i].addMouseListener(new MousePopupListener() {
|
||||
|
||||
@Override
|
||||
public void popupTriggered(int x, int y) {
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
JMenuItem mi = new JMenuItem();
|
||||
mi.setText("RESET");
|
||||
mi.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
if (serviceLink != null){
|
||||
try {
|
||||
serviceLink.writeInt(13, 0, 0x0600 + n, 0);
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
popup.add(mi);
|
||||
|
||||
popup.show(inputButtons[n], x, y);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.insets = new Insets(0, 0, 0, 0);
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.gridx = i % 8;
|
||||
gbc.gridy = (i / 8);
|
||||
|
||||
pDisplay.add(inputButtons[i], gbc);
|
||||
|
||||
outputButtons[i] = new JToggleButton(String.format("%d", i));
|
||||
outputButtons[i].addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
setOutput(n, outputButtons[n].isSelected());
|
||||
}
|
||||
});
|
||||
|
||||
pOutputs.add(outputButtons[i], gbc);
|
||||
|
||||
pullupButtons[i] = new JToggleButton(String.format("%d", i));
|
||||
pullupButtons[i].addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
setPullUp(n, pullupButtons[n].isSelected());
|
||||
}
|
||||
});
|
||||
pPullups.add(pullupButtons[i],gbc);
|
||||
}
|
||||
|
||||
analogLabels = new JLabel[8];
|
||||
|
||||
for (int i=0;i<8;i++){
|
||||
analogLabels[i] = new JLabel(String.format("---"));
|
||||
analogLabels[i].setBorder(new TitledBorder(String.format("AN%d",i)));
|
||||
pAnalog.add(analogLabels[i]);
|
||||
}
|
||||
|
||||
|
||||
liveViewTimer = new Timer();
|
||||
liveViewTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateLiveView();
|
||||
}
|
||||
}, 200, 500);
|
||||
|
||||
pc2a.addAppSettingsListener(this);
|
||||
|
||||
serviceLink = pc2a.getServiceLink();
|
||||
|
||||
}
|
||||
|
||||
private synchronized void updateLiveView(){
|
||||
System.err.println("LiveView Update");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
if (serviceLink != null){
|
||||
System.err.println("ServiceLink exists.");
|
||||
try {
|
||||
serviceLink.open();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Integer brkval,heapend;
|
||||
|
||||
brkval = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0020 );
|
||||
if (brkval == null)
|
||||
brkval = 0;
|
||||
|
||||
heapend = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0021 );
|
||||
if (heapend == null)
|
||||
heapend = 0;
|
||||
|
||||
System.err.println(String.format("PC2-BRKVAL: 0x%04x",brkval));
|
||||
System.err.println(String.format("PC2-HEAPEND: 0x%04x",heapend));
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Integer deviceUnixTime = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x001C);
|
||||
if (deviceUnixTime != null){
|
||||
calendar.setTimeInMillis(deviceUnixTime * 1000L);
|
||||
|
||||
tfUnixTime.setText(String.format("%d",deviceUnixTime));
|
||||
tfHumanDateTime.setText(sdf.format(calendar.getTime()));
|
||||
};
|
||||
|
||||
pinputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0680 );
|
||||
inputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0681 );
|
||||
outputs = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0682 );
|
||||
pullups = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0683 );
|
||||
|
||||
Integer[] values = new Integer[32];
|
||||
for (int i=0;i<32;i++){
|
||||
values[i] = serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x0600 + i);
|
||||
};
|
||||
|
||||
|
||||
if (pinputs == null)
|
||||
pinputs = 0;
|
||||
if (inputs == null)
|
||||
inputs = 0;
|
||||
if (outputs == null)
|
||||
outputs = 0;
|
||||
if (pullups == null)
|
||||
pullups = 0;
|
||||
|
||||
System.err.println(String.format("Inputs State (Phys.): 0x%08x",pinputs));
|
||||
System.err.println(String.format("Inputs State: 0x%08x",inputs));
|
||||
System.err.println(String.format("Outputs State: 0x%08x",outputs));
|
||||
System.err.println(String.format("PullUP State: 0x%08x",pullups));
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
if ((inputs & (1<<i))!=0){
|
||||
inputButtons[i].setBackground(Color.GREEN);
|
||||
} else {
|
||||
inputButtons[i].setBackground(Color.WHITE);
|
||||
}
|
||||
|
||||
if (values[i] != null){
|
||||
inputButtons[i].setText(String.format("<html><center>%d<br/>[%d]</center></html>", i, values[i]));
|
||||
} else {
|
||||
inputButtons[i].setText(String.format("<html><center>%d<br/>N.A.</center></html>", i));
|
||||
};
|
||||
|
||||
|
||||
if ((outputs & (1<<i))!=0){
|
||||
outputButtons[i].setBackground(Color.GREEN);
|
||||
outputButtons[i].setSelected(true);
|
||||
} else {
|
||||
outputButtons[i].setBackground(Color.WHITE);
|
||||
outputButtons[i].setSelected(false);
|
||||
}
|
||||
|
||||
if ((pullups & (1<<i))!=0){
|
||||
pullupButtons[i].setBackground(Color.BLUE);
|
||||
pullupButtons[i].setSelected(true);
|
||||
} else {
|
||||
pullupButtons[i].setBackground(Color.WHITE);
|
||||
pullupButtons[i].setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<8;i++){
|
||||
Float analog = serviceLink.getServiceRegisterCache().getCachedFloat(13, 0, 0x8000 + i );
|
||||
if (analog != null){
|
||||
analogLabels[i].setText(String.format("%5.3fV", (analog * 10.0f)));
|
||||
}
|
||||
}
|
||||
|
||||
Integer assert_error,assert_code;
|
||||
|
||||
try
|
||||
{
|
||||
assert_error = -1;
|
||||
for (int i=0;i<8;i++){
|
||||
assert_error = serviceLink.readInt(13, 0, 0x0026);
|
||||
assert_code = serviceLink.readInt(13, 0, 0x0025);
|
||||
|
||||
if (assert_error >= 0)
|
||||
break;
|
||||
|
||||
DefaultListModel<String> lm = (DefaultListModel<String>)lMessages.getModel();
|
||||
lm.addElement(String.format("Assertion: Error: 0x%08x (%d) Position: 0x%04x Mark: %d", assert_error,assert_error, assert_code & 0xffff, (assert_code >> 16) & 0xffff));
|
||||
lMessages.ensureIndexIsVisible(lm.size()-1);
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x0025, -1);
|
||||
};
|
||||
} catch (Exception ex){
|
||||
System.err.println("Exception while checking for assertions...");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
System.err.println(String.format("updateLiveView(): Time needed: %d", (endTime - startTime)));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void ServiceLinkChanged(ServiceLink serviceLink) {
|
||||
this.serviceLink = serviceLink;
|
||||
}
|
||||
|
||||
public synchronized void setOutput(int ch,boolean set){
|
||||
if (this.serviceLink != null){
|
||||
try {
|
||||
if (set){
|
||||
serviceLink.writeInt((byte)13, (byte)0, 0x8100 + ch, 1);
|
||||
} else {
|
||||
serviceLink.writeInt((byte)13, (byte)0, 0x8100 + ch, 0);
|
||||
}
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setPullUp(int ch,boolean set){
|
||||
if (this.serviceLink != null){
|
||||
if (set){
|
||||
pullups |= (1<<ch);
|
||||
} else {
|
||||
pullups &= ~(1<<ch);
|
||||
}
|
||||
|
||||
try {
|
||||
serviceLink.writeInt((byte)13, (byte)0, 0x0683, pullups);
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncUnixTime(){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
if (this.serviceLink != null){
|
||||
try {
|
||||
this.serviceLink.writeInt((byte)13, (byte)0, 0x001C, (int)(calendar.getTimeInMillis() / 1000L));
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void manualSnapshot(){
|
||||
if (this.serviceLink != null){
|
||||
try {
|
||||
Integer emask = this.serviceLink.getServiceRegisterCache().getCachedInteger(13, 0, 0x9001);
|
||||
|
||||
System.err.println(String.format("EMASK: 0x%08x", emask));
|
||||
|
||||
|
||||
this.serviceLink.writeInt((byte)13, (byte)0, 0x1001, 2);
|
||||
} catch (ServiceLinkRequestFailedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ServiceLinkException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void message(String msg){
|
||||
((DefaultListModel<String>)lMessages.getModel()).addElement(msg);
|
||||
}
|
||||
|
||||
private void quartzCorrect(){
|
||||
long lStart,lEnd;
|
||||
long rStart,rEnd;
|
||||
long lDelta,rDelta;
|
||||
long delta;
|
||||
|
||||
if (this.serviceLink != null){
|
||||
try
|
||||
{
|
||||
|
||||
lStart = System.currentTimeMillis();
|
||||
rStart = serviceLink.readInt(13, 0, 0x0027);
|
||||
|
||||
Thread.sleep(30000);
|
||||
|
||||
lEnd = System.currentTimeMillis();
|
||||
rEnd = serviceLink.readInt(13, 0, 0x0027);
|
||||
|
||||
lDelta = (lEnd - lStart)*1000;
|
||||
rDelta = rEnd - rStart;
|
||||
|
||||
delta = lDelta - rDelta;
|
||||
|
||||
message(String.format("Local: %d Remote: %d Delta: %d", lDelta,rDelta,delta));
|
||||
|
||||
delta /= 30;
|
||||
|
||||
message(String.format("Korrektur: %d", delta));
|
||||
|
||||
serviceLink.writeInt(13, 0, 0x1002, (int)delta);
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,38 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Window.Type;
|
||||
import java.awt.Font;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class ShutdownNotification extends JFrame {
|
||||
|
||||
private JPanel contentPane;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public ShutdownNotification() {
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setTitle("Synolo-Log Software wird beendet");
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
setBounds(100, 100, 770, 162);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
setContentPane(contentPane);
|
||||
|
||||
JLabel lblEinenMomentBittedie = new JLabel("<html>Einen Moment bitte.<br/>Die Synolo-Log Software wartet noch auf die Fertigstellung von Hintergrunddiensten...</html>");
|
||||
lblEinenMomentBittedie.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblEinenMomentBittedie.setFont(new Font("DejaVu Sans", Font.BOLD | Font.ITALIC, 14));
|
||||
contentPane.add(lblEinenMomentBittedie, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.SpinnerNumberModel;
|
||||
|
||||
import org.hwo.pulscounter.simplescript.SimpleScriptAddress;
|
||||
import org.hwo.ui.JComboBoxEx;
|
||||
|
||||
public class SimpleScriptAddressEditor extends JPanel {
|
||||
|
||||
AddressRange[] addressRanges = new AddressRange[]{
|
||||
new AddressRange("Zähler", 0, 32),
|
||||
new AddressRange("Analogspannung", 32, 8),
|
||||
new AddressRange("Merker", 40, 24),
|
||||
new AddressRange("PullUp Status", 64, 32),
|
||||
new AddressRange("Ausgang", 96, 32),
|
||||
new AddressRange("Inverter", 128, 32),
|
||||
new AddressRange("Eingang", 160, 32),
|
||||
new AddressRange("Variable", 192, 64)
|
||||
};
|
||||
private JComboBoxEx cbRange;
|
||||
private JSpinner spValue;
|
||||
private SpinnerNumberModel numberModel = new SpinnerNumberModel(0, 0, 0, 1);
|
||||
|
||||
private int
|
||||
address;
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public SimpleScriptAddressEditor() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
cbRange = new JComboBoxEx();
|
||||
GridBagConstraints gbc_cbRange = new GridBagConstraints();
|
||||
gbc_cbRange.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_cbRange.fill = GridBagConstraints.BOTH;
|
||||
gbc_cbRange.gridx = 0;
|
||||
gbc_cbRange.gridy = 0;
|
||||
cbRange.setItems(addressRanges);
|
||||
cbRange.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
syncNumberFormat();
|
||||
}
|
||||
});
|
||||
add(cbRange, gbc_cbRange);
|
||||
|
||||
spValue = new JSpinner();
|
||||
GridBagConstraints gbc_spValue = new GridBagConstraints();
|
||||
gbc_spValue.fill = GridBagConstraints.BOTH;
|
||||
gbc_spValue.gridx = 1;
|
||||
gbc_spValue.gridy = 0;
|
||||
spValue.setModel(numberModel);
|
||||
add(spValue, gbc_spValue);
|
||||
|
||||
cbRange.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
private AddressRange getSelectedRange(){
|
||||
return (AddressRange)cbRange.getSelectedItem();
|
||||
}
|
||||
private int getSelectedDisplayValue(){
|
||||
return (Integer)spValue.getValue();
|
||||
}
|
||||
|
||||
private void syncNumberFormat(){
|
||||
AddressRange range = getSelectedRange();
|
||||
numberModel.setMaximum(range.getSize()-1);
|
||||
|
||||
if (range.getSize() <= getSelectedDisplayValue()){
|
||||
numberModel.setValue(range.getSize()-1);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAddress() {
|
||||
this.address = getSelectedRange().scriptValue(((Integer)numberModel.getValue()).intValue());
|
||||
return address;
|
||||
}
|
||||
public void setAddress(int address) {
|
||||
this.address = address;
|
||||
|
||||
cbRange.setEnabled(true);
|
||||
cbRange.setSelectedItem(findRange(address));
|
||||
syncNumberFormat();
|
||||
|
||||
numberModel.setValue(getSelectedRange().displayValue(address));
|
||||
}
|
||||
|
||||
private AddressRange findRange(int address){
|
||||
for (AddressRange range: addressRanges){
|
||||
if (range.contains(address))
|
||||
return range;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class AddressRange{
|
||||
|
||||
private String name;
|
||||
private int base;
|
||||
private int size;
|
||||
|
||||
public AddressRange(String name,int base,int size){
|
||||
this.name = name;
|
||||
this.size = size;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public int getBase() {
|
||||
return base;
|
||||
}
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean contains(int address){
|
||||
return (base <= address) && (address < (base+size));
|
||||
}
|
||||
|
||||
public int displayValue(int address){
|
||||
return address - base;
|
||||
}
|
||||
public int scriptValue(int displayAddress){
|
||||
return displayAddress + base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,313 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.models.TableMapper.TableColumn;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.models.TableMapper.TableMapperListener;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement;
|
||||
import static org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition.*;
|
||||
import static org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement.*;
|
||||
import org.hwo.ui.JMappedTable;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JTable;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.awt.MenuItem;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JTextArea;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SimpleScriptEditor extends JDialog {
|
||||
|
||||
|
||||
public static boolean show(SimpleScript simpleScript){
|
||||
return show(null,simpleScript);
|
||||
|
||||
}
|
||||
|
||||
public static boolean show(Component parent,SimpleScript simpleScript){
|
||||
SimpleScriptEditor sse = new SimpleScriptEditor();
|
||||
sse.setSimpleScript(simpleScript);
|
||||
if (parent != null){
|
||||
sse.setLocationRelativeTo(parent);
|
||||
}
|
||||
sse.setVisible(true);
|
||||
return sse.isAccepted();
|
||||
}
|
||||
|
||||
|
||||
private SimpleScript simpleScript;
|
||||
private boolean accepted;
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JMappedTable mtScriptElements;
|
||||
private JTextField tfName;
|
||||
private JTextArea taDescription;
|
||||
private JScrollPane spElementTable;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public SimpleScriptEditor() {
|
||||
setTitle(Messages.getString("Skript bearbeiten"));
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 921, 474);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
|
||||
MouseAdapter popupAdapter = new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
checkPopup(e);
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if ((e.getComponent() == spElementTable)){
|
||||
mtScriptElements.clearSelection();
|
||||
}
|
||||
checkPopup(e);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
checkPopup(e);
|
||||
}
|
||||
|
||||
private void checkPopup(MouseEvent e){
|
||||
if (e.isPopupTrigger()){
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
|
||||
JMenuItem miAdd = new JMenuItem(Messages.getString("1x neu"));
|
||||
miAdd.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow();
|
||||
mtScriptElements.getTableMapper().addRow(new SimpleScriptElement(),sse);
|
||||
}
|
||||
});
|
||||
popupMenu.add(miAdd);
|
||||
|
||||
JMenuItem miAdd5 = new JMenuItem(Messages.getString("5x neu"));
|
||||
miAdd5.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow();
|
||||
|
||||
mtScriptElements.getTableMapper().addRows(new SimpleScriptElement[]{
|
||||
new SimpleScriptElement(),
|
||||
new SimpleScriptElement(),
|
||||
new SimpleScriptElement(),
|
||||
new SimpleScriptElement(),
|
||||
new SimpleScriptElement()
|
||||
}, sse);
|
||||
}
|
||||
});
|
||||
popupMenu.add(miAdd5);
|
||||
|
||||
SimpleScriptElement sse = (SimpleScriptElement)mtScriptElements.getTableMapper().getSelectedRow();
|
||||
if (sse != null){
|
||||
JMenuItem miRemove = new JMenuItem(Messages.getString("Entfernen"));
|
||||
miRemove.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SimpleScriptElement[] selected = mtScriptElements.getTableMapper().getSelectedRows(new SimpleScriptElement[0]);
|
||||
for (SimpleScriptElement se: selected){
|
||||
mtScriptElements.getTableMapper().removeRow(se);
|
||||
}
|
||||
}
|
||||
});
|
||||
popupMenu.add(miRemove);
|
||||
}
|
||||
|
||||
popupMenu.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
{
|
||||
JLabel lblBezeichnung = new JLabel(Messages.getString("Bezeichnung:"));
|
||||
GridBagConstraints gbc_lblBezeichnung = new GridBagConstraints();
|
||||
gbc_lblBezeichnung.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblBezeichnung.anchor = GridBagConstraints.NORTH;
|
||||
gbc_lblBezeichnung.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblBezeichnung.gridx = 0;
|
||||
gbc_lblBezeichnung.gridy = 0;
|
||||
contentPanel.add(lblBezeichnung, gbc_lblBezeichnung);
|
||||
}
|
||||
{
|
||||
tfName = new JTextField();
|
||||
GridBagConstraints gbc_tfName = new GridBagConstraints();
|
||||
gbc_tfName.anchor = GridBagConstraints.NORTH;
|
||||
gbc_tfName.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_tfName.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_tfName.gridx = 1;
|
||||
gbc_tfName.gridy = 0;
|
||||
contentPanel.add(tfName, gbc_tfName);
|
||||
tfName.setColumns(10);
|
||||
}
|
||||
{
|
||||
JLabel lblBescrheibung = new JLabel(Messages.getString("Beschreibung:"));
|
||||
GridBagConstraints gbc_lblBescrheibung = new GridBagConstraints();
|
||||
gbc_lblBescrheibung.anchor = GridBagConstraints.NORTH;
|
||||
gbc_lblBescrheibung.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_lblBescrheibung.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblBescrheibung.gridx = 0;
|
||||
gbc_lblBescrheibung.gridy = 1;
|
||||
contentPanel.add(lblBescrheibung, gbc_lblBescrheibung);
|
||||
}
|
||||
{
|
||||
taDescription = new JTextArea();
|
||||
GridBagConstraints gbc_taDescription = new GridBagConstraints();
|
||||
gbc_taDescription.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_taDescription.fill = GridBagConstraints.BOTH;
|
||||
gbc_taDescription.gridx = 1;
|
||||
gbc_taDescription.gridy = 1;
|
||||
contentPanel.add(taDescription, gbc_taDescription);
|
||||
}
|
||||
{
|
||||
spElementTable = new JScrollPane();
|
||||
GridBagConstraints gbc_spElementTable = new GridBagConstraints();
|
||||
gbc_spElementTable.gridwidth = 2;
|
||||
gbc_spElementTable.fill = GridBagConstraints.BOTH;
|
||||
gbc_spElementTable.gridx = 0;
|
||||
gbc_spElementTable.gridy = 2;
|
||||
spElementTable.addMouseListener(popupAdapter);
|
||||
contentPanel.add(spElementTable, gbc_spElementTable);
|
||||
{
|
||||
mtScriptElements = new JMappedTable(SimpleScriptElement.class);
|
||||
mtScriptElements.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
||||
mtScriptElements.setEditorEnabled(true);
|
||||
mtScriptElements.setFillsViewportHeight(true);
|
||||
mtScriptElements.addMouseListener(popupAdapter);
|
||||
spElementTable.setViewportView(mtScriptElements);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton(Messages.getString("OK"));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
accept();
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton(Messages.getString("Cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mtScriptElements.addTableMapperListener(new TableMapperListener() {
|
||||
|
||||
@Override
|
||||
public boolean editorRequest(TableMapper tableMapper, Object row) {
|
||||
SimpleScriptElement e = (SimpleScriptElement)row;
|
||||
if (e != null){
|
||||
if (SimpleScriptElementEditor.show(SimpleScriptEditor.this, e)){
|
||||
mtScriptElements.repaint();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ValueChanged(int row, int column) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void tableRowChanged(TableMapper sender, Object row) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
mtScriptElements.getTableMapper().setEditorEnabled(true);
|
||||
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void accept(){
|
||||
|
||||
simpleScript.setName(tfName.getText());
|
||||
simpleScript.setDescription(taDescription.getText());
|
||||
simpleScript.setSimpleScriptElements(mtScriptElements.getTableMapper().getRows(SimpleScriptElement.class).toArray(new SimpleScriptElement[0]));
|
||||
|
||||
accepted = true;
|
||||
setVisible(false);
|
||||
}
|
||||
private void cancel(){
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public boolean isAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
if (this.simpleScript == null){
|
||||
this.simpleScript = new SimpleScript();
|
||||
}
|
||||
|
||||
tfName.setText(simpleScript.getName());
|
||||
taDescription.setText(simpleScript.getDescription());
|
||||
mtScriptElements.getTableMapper().setRows(new ArrayList<SimpleScriptElement>(simpleScript.getSimpleScriptElements()));
|
||||
mtScriptElements.getTableMapper().setSortingEnabled(false);
|
||||
}
|
||||
|
||||
public SimpleScript getSimpleScript(){
|
||||
return this.simpleScript;
|
||||
}
|
||||
|
||||
public void setSimpleScript(SimpleScript simpleScript){
|
||||
this.simpleScript = simpleScript;
|
||||
initialize();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.ScriptOperation;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement;
|
||||
import org.hwo.ui.JComboBoxEx;
|
||||
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.Font;
|
||||
|
||||
public class SimpleScriptElementEditor extends JDialog {
|
||||
|
||||
|
||||
public static boolean show(Component parent,SimpleScriptElement simpleScriptElement){
|
||||
SimpleScriptElementEditor editor = new SimpleScriptElementEditor();
|
||||
if (parent != null){
|
||||
editor.setLocationRelativeTo(parent);
|
||||
}
|
||||
editor.setSimpleScriptElement(simpleScriptElement);
|
||||
editor.setVisible(true);
|
||||
return editor.isAccepted();
|
||||
}
|
||||
|
||||
private SimpleScriptElement simpleScriptElement;
|
||||
private boolean accepted;
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private SimpleScriptAddressEditor ssaA;
|
||||
private SimpleScriptAddressEditor ssaB;
|
||||
private SimpleScriptAddressEditor ssaZ;
|
||||
private JComboBoxEx cbCondition;
|
||||
private JComboBoxEx cbOperation;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public SimpleScriptElementEditor() {
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setTitle(Messages.getString("Skriptelement bearbeiten"));
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setBounds(100, 100, 519, 350);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Eingangswert A"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
ssaA = new SimpleScriptAddressEditor();
|
||||
GridBagConstraints gbc_ssaA = new GridBagConstraints();
|
||||
gbc_ssaA.fill = GridBagConstraints.BOTH;
|
||||
gbc_ssaA.gridx = 0;
|
||||
gbc_ssaA.gridy = 0;
|
||||
panel.add(ssaA, gbc_ssaA);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Eingangswert B"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 1;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
ssaB = new SimpleScriptAddressEditor();
|
||||
GridBagConstraints gbc_ssaB = new GridBagConstraints();
|
||||
gbc_ssaB.fill = GridBagConstraints.BOTH;
|
||||
gbc_ssaB.gridx = 0;
|
||||
gbc_ssaB.gridy = 0;
|
||||
panel.add(ssaB, gbc_ssaB);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),Messages.getString("Bedingung"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.gridwidth = 2;
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 1;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
cbCondition = new JComboBoxEx();
|
||||
cbCondition.setFont(new Font("Courier", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_cbCondition = new GridBagConstraints();
|
||||
gbc_cbCondition.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbCondition.gridx = 0;
|
||||
gbc_cbCondition.gridy = 0;
|
||||
cbCondition.setItems(SimpleScript.ScriptCondition.values());
|
||||
panel.add(cbCondition, gbc_cbCondition);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),Messages.getString("Operation"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.gridwidth = 2;
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 2;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
cbOperation = new JComboBoxEx();
|
||||
cbOperation.setFont(new Font("Courier", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_cbOperation = new GridBagConstraints();
|
||||
gbc_cbOperation.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_cbOperation.gridx = 0;
|
||||
gbc_cbOperation.gridy = 0;
|
||||
cbOperation.setItems(SimpleScript.ScriptOperation.values());
|
||||
panel.add(cbOperation, gbc_cbOperation);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Ausgangswert Z"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51)));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 3;
|
||||
contentPanel.add(panel, gbc_panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
ssaZ = new SimpleScriptAddressEditor();
|
||||
GridBagConstraints gbc_ssaZ = new GridBagConstraints();
|
||||
gbc_ssaZ.fill = GridBagConstraints.BOTH;
|
||||
gbc_ssaZ.gridx = 0;
|
||||
gbc_ssaZ.gridy = 0;
|
||||
panel.add(ssaZ, gbc_ssaZ);
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton(Messages.getString("OK"));
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
accept();
|
||||
}
|
||||
});
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton(Messages.getString("Cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleScriptElement getSimpleScriptElement() {
|
||||
return simpleScriptElement;
|
||||
}
|
||||
public void setSimpleScriptElement(SimpleScriptElement simpleScriptElement) {
|
||||
this.simpleScriptElement = simpleScriptElement;
|
||||
|
||||
ssaA.setAddress( simpleScriptElement.getA() );
|
||||
ssaB.setAddress( simpleScriptElement.getB() );
|
||||
ssaZ.setAddress( simpleScriptElement.getZ() );
|
||||
cbCondition.setSelectedItem(simpleScriptElement.getScriptCondition());
|
||||
cbOperation.setSelectedItem(simpleScriptElement.getScriptOperation());
|
||||
}
|
||||
|
||||
private void accept(){
|
||||
|
||||
simpleScriptElement.setA(ssaA.getAddress());
|
||||
simpleScriptElement.setB(ssaB.getAddress());
|
||||
simpleScriptElement.setZ(ssaZ.getAddress());
|
||||
simpleScriptElement.setScriptOperation((ScriptOperation)cbOperation.getSelectedItem());
|
||||
simpleScriptElement.setScriptCondition((ScriptCondition)cbCondition.getSelectedItem());
|
||||
|
||||
accepted = true;
|
||||
setVisible(false);
|
||||
}
|
||||
private void cancel(){
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public boolean isAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,286 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import static org.hwo.logging.LogLevel.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.models.TableMapper.TableMapperListener;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.device.IDeviceConnector;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript;
|
||||
import org.hwo.ui.JMappedTable;
|
||||
import org.hwo.ui.JObjectSelector;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.DateFormat;
|
||||
import java.awt.event.ActionEvent;
|
||||
import static org.hwo.logging.Logging.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.Insets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.JButton;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import org.hwo.models.TableMapper.TableMapper;
|
||||
import org.hwo.models.TableMapper.TableMapperListener;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.simplescript.SimpleScript;
|
||||
import org.hwo.ui.JMappedTable;
|
||||
import javax.swing.JScrollPane;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import javax.swing.JTable;
|
||||
|
||||
public class SimpleScriptSetup extends JDialog {
|
||||
|
||||
private JPanel contentPane;
|
||||
private JMappedTable scriptTable;
|
||||
|
||||
private ArrayList<SimpleScript> simpleScripts;
|
||||
private JButton btnEntfernen;
|
||||
private JButton btnBearbeiten;
|
||||
private JButton btnNeu;
|
||||
private JButton btnTransmit;
|
||||
private JButton btnReceive;
|
||||
|
||||
public SimpleScriptSetup() {
|
||||
setTitle(Messages.getString("Formeln"));
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 831, 406);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
|
||||
flowLayout.setAlignment(FlowLayout.LEFT);
|
||||
panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel.gridx = 0;
|
||||
gbc_panel.gridy = 0;
|
||||
contentPane.add(panel, gbc_panel);
|
||||
|
||||
btnNeu = new JButton(Messages.getString("neu..."));
|
||||
btnNeu.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
scriptTable.getTableMapper().addRow(new SimpleScript());
|
||||
}
|
||||
});
|
||||
panel.add(btnNeu);
|
||||
|
||||
btnBearbeiten = new JButton(Messages.getString("bearbeiten..."));
|
||||
btnBearbeiten.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
scriptTable.getTableMapper().openEditor();
|
||||
}
|
||||
});
|
||||
btnBearbeiten.setEnabled(false);
|
||||
panel.add(btnBearbeiten);
|
||||
|
||||
btnEntfernen = new JButton(Messages.getString("entfernen"));
|
||||
btnEntfernen.setEnabled(false);
|
||||
btnEntfernen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SimpleScript sscript = scriptTable.getTableMapper().getSelectedRow(SimpleScript.class);
|
||||
PulsCounterApplication.getApplication().getDatabase().removeSimpleScript( sscript.getId() );
|
||||
scriptTable.getTableMapper().removeRow(sscript);
|
||||
}
|
||||
});
|
||||
panel.add(btnEntfernen);
|
||||
|
||||
btnTransmit = new JButton(Messages.getString("auf Zähler übertragen...."));
|
||||
btnTransmit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
transmit();
|
||||
}
|
||||
});
|
||||
btnTransmit.setEnabled(false);
|
||||
panel.add(btnTransmit);
|
||||
|
||||
btnReceive = new JButton(Messages.getString("von Zähler holen...."));
|
||||
btnReceive.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
receive();
|
||||
}
|
||||
});
|
||||
panel.add(btnReceive);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
contentPane.add(scrollPane, gbc_scrollPane);
|
||||
|
||||
scriptTable = new JMappedTable(SimpleScript.class);
|
||||
scriptTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
||||
scriptTable.setFillsViewportHeight(true);
|
||||
scrollPane.setViewportView(scriptTable);
|
||||
|
||||
JPanel panel_1 = new JPanel();
|
||||
FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
|
||||
flowLayout_1.setAlignment(FlowLayout.RIGHT);
|
||||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
||||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
||||
gbc_panel_1.gridx = 0;
|
||||
gbc_panel_1.gridy = 2;
|
||||
contentPane.add(panel_1, gbc_panel_1);
|
||||
|
||||
JButton btnSchliessen = new JButton(Messages.getString("schliessen"));
|
||||
btnSchliessen.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
panel_1.add(btnSchliessen);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
this.simpleScripts = new ArrayList<>();
|
||||
|
||||
this.simpleScripts.addAll(Arrays.asList(PulsCounterApplication.getApplication().getDatabase().getSimpleScripts()));
|
||||
|
||||
this.scriptTable.getTableMapper().setRows(simpleScripts);
|
||||
this.scriptTable.getTableMapper().setReadOnly(true);
|
||||
this.scriptTable.getTableMapper().setEditorEnabled(true);
|
||||
this.scriptTable.getTableMapper().addListSelectionListener(new ListSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (scriptTable.getTableMapper().getSelectedRow() == null){
|
||||
btnBearbeiten.setEnabled(false);
|
||||
btnEntfernen.setEnabled(false);
|
||||
btnTransmit.setEnabled(false);
|
||||
} else {
|
||||
btnBearbeiten.setEnabled(true);
|
||||
btnEntfernen.setEnabled(true);
|
||||
btnTransmit.setEnabled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.scriptTable.getTableMapper().addTableMapperListener(new TableMapperListener() {
|
||||
|
||||
@Override
|
||||
public boolean editorRequest(TableMapper tableMapper, Object row) {
|
||||
if (row != null){
|
||||
if (SimpleScriptEditor.show(SimpleScriptSetup.this,(SimpleScript)row)){
|
||||
log(INFO,"store SimpleScript");
|
||||
PulsCounterApplication.getApplication().getDatabase().storeSimpleScript((SimpleScript)row);
|
||||
scriptTable.repaint();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ValueChanged(int row, int column) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tableRowChanged(TableMapper sender, Object row) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void transmit(){
|
||||
IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]);
|
||||
IDeviceConnector connector = JObjectSelector.execute(
|
||||
connectors,
|
||||
this,
|
||||
Messages.getString("Schnittstelle wählen..."),
|
||||
Messages.getString("Wählen Sie die Schnittstelle über die das Skript übertragen werden soll.")
|
||||
);
|
||||
|
||||
if (connector != null){
|
||||
log(INFO,"Übertrage Skript an Synololog an Schnittstelle %s", connector);
|
||||
|
||||
connector.setSimpleScript(((SimpleScript)scriptTable.getTableMapper().getSelectedRow()).getSimpleScriptElementsAsInt());
|
||||
|
||||
}
|
||||
}
|
||||
private void receive(){
|
||||
IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]);
|
||||
IDeviceConnector connector = JObjectSelector.execute(
|
||||
connectors,
|
||||
this,
|
||||
Messages.getString("Schnittstelle wählen..."),
|
||||
Messages.getString("Wählen Sie die Schnittstelle über die das Skript empfangen werden soll.")
|
||||
);
|
||||
|
||||
if (connector != null){
|
||||
log(INFO,"Übertrage Skript von Synololog an Schnittstelle %s", connector);
|
||||
|
||||
int[] scriptElements = connector.getSimpleScript();
|
||||
|
||||
if (scriptElements == null){
|
||||
JOptionPane.showMessageDialog(this, Messages.getString("Es konnte kein Skript vom gerät empfangen werden."));
|
||||
} else {
|
||||
SimpleScript simpleScript = new SimpleScript();
|
||||
simpleScript.setSimpleScriptElements(scriptElements);
|
||||
simpleScript.setName(String.format(Messages.getString("Von Gerät %s geholt am %s"), connector.getDeviceSerial(), DateFormat.getDateTimeInstance().format(new Date())));
|
||||
|
||||
scriptTable.getTableMapper().addRow(simpleScript);
|
||||
PulsCounterApplication.getApplication().getDatabase().storeSimpleScript(simpleScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,452 @@
|
|||
package org.hwo.pulscounter.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.Dialog.ModalExclusionType;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JSplitPane;
|
||||
import java.awt.GridBagConstraints;
|
||||
|
||||
import org.hwo.ObjectTable;
|
||||
import org.hwo.i18n.Messages;
|
||||
import org.hwo.pulscounter.PulsCounterApplication;
|
||||
import org.hwo.pulscounter.SnapShot;
|
||||
import org.hwo.ui.JMappedTable;
|
||||
import org.hwo.ui.MousePopupListener;
|
||||
import org.hwo.ui.diagram.AnnotatedPlotProvider;
|
||||
import org.hwo.ui.diagram.LinePlotPainter;
|
||||
import org.hwo.ui.diagram.PlotLabeler;
|
||||
import org.hwo.ui.diagram.SimplePlotProvider;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.lang.management.GarbageCollectorMXBean;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import java.awt.Insets;
|
||||
import java.awt.MenuItem;
|
||||
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.BoxLayout;
|
||||
import org.hwo.ui.JDiagram;
|
||||
import javax.swing.JCheckBox;
|
||||
import java.awt.Dimension;
|
||||
|
||||
public class SnapshotManager extends JDialog {
|
||||
|
||||
public static Color[] plotColors = new Color[32];
|
||||
|
||||
public static void show(Component parent){
|
||||
|
||||
SnapshotManager sm = new SnapshotManager();
|
||||
if (parent != null)
|
||||
{
|
||||
sm.setLocationRelativeTo(parent);
|
||||
}
|
||||
sm.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
private JList lDevices;
|
||||
private JMappedTable mtSnapshots;
|
||||
private JScrollPane scrollPane_1;
|
||||
private JDiagram diaSnapshots;
|
||||
private JCheckBox cbDifferenzen;
|
||||
private JPanel paIndex;
|
||||
|
||||
private JLabel[] graphLabels;
|
||||
private AnnotatedPlotProvider
|
||||
annotatedPlotProvider;
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public SnapshotManager() {
|
||||
setTitle(Messages.getString("Aufgezeichnete Werte verwalten"));
|
||||
setModal(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
|
||||
setBounds(100, 100, 991, 547);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
||||
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
||||
gbl_contentPanel.rowHeights = new int[]{0, 0};
|
||||
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
contentPanel.setLayout(gbl_contentPanel);
|
||||
{
|
||||
JSplitPane splitPane = new JSplitPane();
|
||||
splitPane.setResizeWeight(0.2);
|
||||
GridBagConstraints gbc_splitPane = new GridBagConstraints();
|
||||
gbc_splitPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_splitPane.gridx = 0;
|
||||
gbc_splitPane.gridy = 0;
|
||||
contentPanel.add(splitPane, gbc_splitPane);
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
splitPane.setLeftComponent(panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[]{0, 0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 0;
|
||||
gbc_scrollPane.gridy = 0;
|
||||
panel.add(scrollPane, gbc_scrollPane);
|
||||
{
|
||||
lDevices = new JList();
|
||||
lDevices.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
showSnapshots();
|
||||
}
|
||||
});
|
||||
scrollPane.setViewportView(lDevices);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
splitPane.setRightComponent(panel);
|
||||
GridBagLayout gbl_panel = new GridBagLayout();
|
||||
gbl_panel.columnWidths = new int[]{0, 0};
|
||||
gbl_panel.rowHeights = new int[] {0};
|
||||
gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||||
gbl_panel.rowWeights = new double[]{1.0};
|
||||
panel.setLayout(gbl_panel);
|
||||
{
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
|
||||
gbc_tabbedPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_tabbedPane.gridx = 0;
|
||||
gbc_tabbedPane.gridy = 0;
|
||||
panel.add(tabbedPane, gbc_tabbedPane);
|
||||
{
|
||||
JPanel panel_1 = new JPanel();
|
||||
tabbedPane.addTab("Tabelle", null, panel_1, null);
|
||||
panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
|
||||
{
|
||||
scrollPane_1 = new JScrollPane();
|
||||
panel_1.add(scrollPane_1);
|
||||
scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
|
||||
scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||
{
|
||||
mtSnapshots = new JMappedTable(SnapShot.class);
|
||||
mtSnapshots.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
|
||||
mtSnapshots.setFillsViewportHeight(true);
|
||||
mtSnapshots.setColumnSelectionAllowed(true);
|
||||
scrollPane_1.setViewportView(mtSnapshots);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel panel_1 = new JPanel();
|
||||
tabbedPane.addTab("Diagramm", null, panel_1, null);
|
||||
tabbedPane.setBackgroundAt(1, Color.WHITE);
|
||||
panel_1.setLayout(new BorderLayout(0, 0));
|
||||
{
|
||||
diaSnapshots = new JDiagram();
|
||||
diaSnapshots.setBackground(Color.WHITE);
|
||||
diaSnapshots.setPreferLabelHints(true);
|
||||
diaSnapshots.setDrawVerticalGrid(true);
|
||||
diaSnapshots.setAutoScale(true);
|
||||
panel_1.add(diaSnapshots);
|
||||
}
|
||||
{
|
||||
JPanel panel_2 = new JPanel();
|
||||
panel_1.add(panel_2, BorderLayout.NORTH);
|
||||
GridBagLayout gbl_panel_2 = new GridBagLayout();
|
||||
gbl_panel_2.columnWidths = new int[]{0, 0};
|
||||
gbl_panel_2.rowHeights = new int[]{0, 0};
|
||||
gbl_panel_2.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
gbl_panel_2.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||||
panel_2.setLayout(gbl_panel_2);
|
||||
{
|
||||
cbDifferenzen = new JCheckBox(Messages.getString("Differenzieren"));
|
||||
cbDifferenzen.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int i=0;i<32;i++){
|
||||
annotatedPlotProvider.setPlotDifferentiated(i, cbDifferenzen.isSelected());
|
||||
}
|
||||
diaSnapshots.repaint();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_cbDifferenzen = new GridBagConstraints();
|
||||
gbc_cbDifferenzen.gridx = 0;
|
||||
gbc_cbDifferenzen.gridy = 0;
|
||||
panel_2.add(cbDifferenzen, gbc_cbDifferenzen);
|
||||
}
|
||||
}
|
||||
{
|
||||
paIndex = new JPanel();
|
||||
paIndex.setBackground(Color.WHITE);
|
||||
paIndex.setPreferredSize(new Dimension(80, 10));
|
||||
panel_1.add(paIndex, BorderLayout.EAST);
|
||||
paIndex.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton(Messages.getString("schliessen"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand(Messages.getString("Cancel"));
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initializeDeviceList(){
|
||||
initializeDeviceList(null);
|
||||
}
|
||||
private void initializeDeviceList(Integer preSelected){
|
||||
Integer[] deviceSerials = PulsCounterApplication.getApplication().getDatabase().getKnownDevices();
|
||||
DefaultListModel<Integer> lm = new DefaultListModel<>();
|
||||
|
||||
for (Integer serial: deviceSerials){
|
||||
lm.addElement(serial);
|
||||
}
|
||||
|
||||
lDevices.setModel(lm);
|
||||
lDevices.setSelectedValue(preSelected, true);
|
||||
}
|
||||
|
||||
private void initialize(){
|
||||
graphLabels = new JLabel[32];
|
||||
|
||||
initializeDeviceList();
|
||||
|
||||
mtSnapshots.getTableMapper().setReadOnly(true);
|
||||
mtSnapshots.getTableMapper().addListSelectionListener(new ListSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
updateDiagram();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
final int ii = i;
|
||||
|
||||
JLabel l = new JLabel(String.format("#%02d", i));
|
||||
l.setForeground(plotColors[i]);
|
||||
l.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(java.awt.event.MouseEvent e) {
|
||||
if (l.isEnabled()){
|
||||
l.setEnabled(false);
|
||||
annotatedPlotProvider.setPlotEnabled(ii, false);
|
||||
} else {
|
||||
l.setEnabled(true);
|
||||
annotatedPlotProvider.setPlotEnabled(ii, true);
|
||||
}
|
||||
diaSnapshots.repaint();
|
||||
};
|
||||
});
|
||||
l.addMouseListener(new MousePopupListener() {
|
||||
|
||||
@Override
|
||||
public void popupTriggered(int x, int y) {
|
||||
JPopupMenu popup = new JPopupMenu();
|
||||
|
||||
JMenuItem mi = new JMenuItem(Messages.getString("Nur diesen Graph zeigen"));
|
||||
mi.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int g=0;g<32;g++){
|
||||
graphLabels[g].setEnabled(false);
|
||||
annotatedPlotProvider.setPlotEnabled(g, false);
|
||||
}
|
||||
graphLabels[ii].setEnabled(true);
|
||||
annotatedPlotProvider.setPlotEnabled(ii,true);
|
||||
diaSnapshots.repaint();
|
||||
}
|
||||
});
|
||||
popup.add(mi);
|
||||
|
||||
mi = new JMenuItem(Messages.getString("Alle ausser diesem Graph zeigen"));
|
||||
mi.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int g=0;g<32;g++){
|
||||
graphLabels[g].setEnabled(true);
|
||||
annotatedPlotProvider.setPlotEnabled(g, true);
|
||||
}
|
||||
graphLabels[ii].setEnabled(false);
|
||||
annotatedPlotProvider.setPlotEnabled(ii, false);
|
||||
diaSnapshots.repaint();
|
||||
}
|
||||
});
|
||||
popup.add(mi);
|
||||
|
||||
popup.show(l, x, y);
|
||||
}
|
||||
});
|
||||
|
||||
paIndex.add(l);
|
||||
graphLabels[i] = l;
|
||||
}
|
||||
|
||||
mtSnapshots.addMouseListener(new MousePopupListener() {
|
||||
|
||||
@Override
|
||||
public void popupTriggered(int x, int y) {
|
||||
SnapShot[] selRows = mtSnapshots.getTableMapper().getSelectedRows(new SnapShot[0]);
|
||||
|
||||
if ((selRows != null)&&(selRows.length>0)){
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem mi = new JMenuItem(Messages.getString("Entfernen..."));
|
||||
mi.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
if (JOptionPane.showConfirmDialog(SnapshotManager.this, Messages.getString("Sollen die markierten Snapshots wirklich gelöscht werden?"),Messages.getString("Aufzeichnungen entfernen"),JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
|
||||
for (SnapShot ss: selRows){
|
||||
mtSnapshots.getTableMapper().removeRow(ss);
|
||||
PulsCounterApplication.getApplication().getDatabase().deleteSnapshot(ss);
|
||||
}
|
||||
|
||||
if (mtSnapshots.getTableMapper().getRows().size()==0){
|
||||
initializeDeviceList();
|
||||
}
|
||||
|
||||
mtSnapshots.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
popupMenu.add(mi);
|
||||
|
||||
mi = new JMenuItem(Messages.getString("(Ent-)Parken"));
|
||||
mi.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (SnapShot ss: selRows){
|
||||
mtSnapshots.getTableMapper().removeRow(ss);
|
||||
PulsCounterApplication.getApplication().getDatabase().deleteSnapshot(ss);
|
||||
ss.setDeviceSerial(-ss.getDeviceSerial());
|
||||
PulsCounterApplication.getApplication().getDatabase().storeSnapshots(new SnapShot[]{ss});
|
||||
}
|
||||
initializeDeviceList((Integer)lDevices.getSelectedValue());
|
||||
}
|
||||
});
|
||||
popupMenu.add(mi);
|
||||
|
||||
popupMenu.show(mtSnapshots, x, y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
annotatedPlotProvider = new AnnotatedPlotProvider(SnapShot.class);
|
||||
|
||||
for (int i=0;i<32;i++){
|
||||
annotatedPlotProvider.setColors(i, plotColors[i]);
|
||||
}
|
||||
|
||||
diaSnapshots.setPlotProvider(annotatedPlotProvider);
|
||||
diaSnapshots.setAbszissLabeler(new PlotLabeler() {
|
||||
|
||||
@Override
|
||||
public String getOrdinateLabel(JDiagram diagram, int ordinate, Double value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbzisseLabel(JDiagram diagram, Double pos) {
|
||||
return ((SnapShot)annotatedPlotProvider.getValues().get(pos.intValue())).getTimeStampFormated();
|
||||
}
|
||||
});
|
||||
|
||||
if (lDevices.getModel().getSize()>0)
|
||||
lDevices.setSelectedIndex(0);
|
||||
}
|
||||
|
||||
private void showSnapshots(){
|
||||
|
||||
Integer deviceSerial = (Integer)lDevices.getSelectedValue();
|
||||
if (deviceSerial != null){
|
||||
SnapShot[] snapshots = PulsCounterApplication.getApplication().getDatabase().loadSnapshots(0, deviceSerial);
|
||||
mtSnapshots.getTableMapper().setRows(snapshots);
|
||||
} else {
|
||||
mtSnapshots.getTableMapper().clear();
|
||||
}
|
||||
updateDiagram();
|
||||
}
|
||||
|
||||
private void updateDiagram(){
|
||||
SnapShot[] rows = mtSnapshots.getTableMapper().getSelectedRows(new SnapShot[0]);
|
||||
|
||||
if ((rows == null)||(rows.length==0)){
|
||||
rows = mtSnapshots.getTableMapper().getRows(SnapShot.class).toArray(new SnapShot[0]);
|
||||
}
|
||||
|
||||
annotatedPlotProvider.setValues(rows);
|
||||
diaSnapshots.repaint();
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
plotColors[0] = new Color(255,0,0);
|
||||
plotColors[1] = new Color(0,0,255);
|
||||
plotColors[2] = new Color(0,255,0);
|
||||
plotColors[3] = new Color(255,0,255);
|
||||
plotColors[4] = new Color(0,255,255);
|
||||
plotColors[5] = new Color(255,255,0);
|
||||
plotColors[6] = new Color(192,192,0);
|
||||
plotColors[7] = new Color(0,192,192);
|
||||
|
||||
int a = 2,
|
||||
b = 4;
|
||||
|
||||
for (int i=0;i<3;i++){
|
||||
for (int j=0;j<8;j++){
|
||||
plotColors[8 + (i*8) + j] = new Color(
|
||||
plotColors[j].getRed() * a / b,
|
||||
plotColors[j].getBlue() * a / b,
|
||||
plotColors[j].getGreen() * a / b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<jardesc>
|
||||
<jar path="/Volumes/DATEN/src/java/release/synololog.jar"/>
|
||||
<options buildIfNeeded="true" compress="true" descriptionLocation="/org.hwo.pulscounter/synololog.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
<manifest generateManifest="false" mainClassHandleIdentifier="=org.hwo.pulscounter/src<org.hwo.pulscounter{Application.java[Application" manifestLocation="/org.hwo.pulscounter/Manifest" manifestVersion="1.0" reuseManifest="true" saveManifest="true" usesManifest="true">
|
||||
<sealing sealJar="false">
|
||||
<packagesToSeal/>
|
||||
<packagesToUnSeal/>
|
||||
</sealing>
|
||||
</manifest>
|
||||
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
|
||||
<file path="/org.hwo.pulscounter/missing-translation.txt"/>
|
||||
<file path="/org.hwo.pulscounter/synololog-hsql.properties"/>
|
||||
<file path="/org.hwo.pulscounter/PulsCounterApplication.msg_en.xml"/>
|
||||
<file path="/org.hwo.pulscounter/synololog-hsql.log"/>
|
||||
<file path="/org.hwo.pulscounter/.gitignore"/>
|
||||
<file path="/org.hwo.pulscounter/.project"/>
|
||||
<javaElement handleIdentifier="=org.hwo.servicelink/src"/>
|
||||
<javaElement handleIdentifier="=org.hwo.ui/src"/>
|
||||
<javaElement handleIdentifier="=org.hwo.platform/src"/>
|
||||
<javaElement handleIdentifier="=org.hwo/src"/>
|
||||
<javaElement handleIdentifier="=org.hwo.pulscounter/src"/>
|
||||
<file path="/org.hwo.pulscounter/.classpath"/>
|
||||
<file path="/org.hwo.pulscounter/synololog.cfg"/>
|
||||
<file path="/org.hwo.pulscounter/synololog.log"/>
|
||||
<file path="/org.hwo.pulscounter/PulsCounterApplication.msg.xml"/>
|
||||
<file path="/org.hwo.pulscounter/synololog.log.old"/>
|
||||
<file path="/org.hwo.pulscounter/synololog-hsql.script"/>
|
||||
</selectedElements>
|
||||
</jardesc>
|
Loading…
Reference in New Issue