org.hwo.pulscounter/src/org/hwo/pulscounter/ui/BatchRunner.java

85 lines
2.0 KiB
Java
Raw Normal View History

2016-09-06 16:49:11 +02:00
package org.hwo.pulscounter.ui;
import org.hwo.pulscounter.ExportSetting;
2016-09-08 18:47:31 +02:00
import org.hwo.pulscounter.PulsCounterApplication;
2016-09-06 16:49:11 +02:00
import org.hwo.pulscounter.PulsCounterApplicationListener;
2017-03-10 15:11:01 +01:00
import org.hwo.servicelink.exceptions.*;
2016-10-26 19:21:57 +02:00
import static org.hwo.logging.Logging.*;
import static org.hwo.logging.LogLevel.*;
2016-09-06 16:49:11 +02:00
public class BatchRunner implements PulsCounterApplicationListener{
2016-09-08 18:47:31 +02:00
private PulsCounterApplication pulsCounterApplication;
2016-09-06 16:49:11 +02:00
2016-09-08 18:47:31 +02:00
public BatchRunner(PulsCounterApplication pulsCounterApplication){
this.pulsCounterApplication = pulsCounterApplication;
pulsCounterApplication.addPulsCounterApplicationListener(this);
2016-10-26 19:21:57 +02:00
try {
run();
} catch (Exception e){
log(e);
}
2016-09-06 16:49:11 +02:00
2016-10-26 19:21:57 +02:00
pulsCounterApplication.notifyUiIsFinished(true);
2016-09-06 16:49:11 +02:00
}
public void run(){
2016-10-26 19:21:57 +02:00
2016-11-21 16:08:15 +01:00
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();
for (ExportSetting es: PulsCounterApplication.getApplication().getExportSettings()){
if (es.getAutostart()){
es.export();
}
2016-09-06 16:49:11 +02:00
}
2016-11-21 16:08:15 +01:00
2016-09-06 16:49:11 +02:00
}
2016-10-26 19:21:57 +02:00
2016-09-08 18:47:31 +02:00
pulsCounterApplication.notifyUiIsFinished(false);
2016-09-06 16:49:11 +02:00
}
@Override
public void messageArrived(String message) {
}
2016-09-08 18:47:31 +02:00
@Override
public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
}
@Override
public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
}
2016-09-06 16:49:11 +02:00
}