85 lines
2.0 KiB
Java
85 lines
2.0 KiB
Java
package org.hwo.pulscounter.ui;
|
|
|
|
import org.hwo.pulscounter.ExportSetting;
|
|
import org.hwo.pulscounter.PulsCounterApplication;
|
|
import org.hwo.pulscounter.PulsCounterApplicationListener;
|
|
import org.hwo.servicelink.ServiceLinkException;
|
|
import static org.hwo.logging.Logging.*;
|
|
import static org.hwo.logging.LogLevel.*;
|
|
|
|
public class BatchRunner implements PulsCounterApplicationListener{
|
|
|
|
private PulsCounterApplication pulsCounterApplication;
|
|
|
|
public BatchRunner(PulsCounterApplication pulsCounterApplication){
|
|
this.pulsCounterApplication = pulsCounterApplication;
|
|
|
|
pulsCounterApplication.addPulsCounterApplicationListener(this);
|
|
|
|
try {
|
|
run();
|
|
} catch (Exception e){
|
|
log(e);
|
|
}
|
|
|
|
pulsCounterApplication.notifyUiIsFinished(true);
|
|
}
|
|
|
|
public void run(){
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
pulsCounterApplication.notifyUiIsFinished(false);
|
|
}
|
|
|
|
@Override
|
|
public void messageArrived(String message) {
|
|
}
|
|
|
|
@Override
|
|
public void interfaceClassesChanged(PulsCounterApplication pulsCounterApplication) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void interfacesChanged(PulsCounterApplication pulsCounterApplication) {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|