Batch Processing (#102)

* Update FileListWorker.java

* Support batch processing

Multicast controller and a couple of additional commands to work with
the batch processing plugin.

* Database float unpack

Better unpacking checks of floats coming back from the database
This commit is contained in:
Douglas Gillespie 2023-04-07 18:25:27 +01:00 committed by GitHub
parent 42d560f91b
commit 7ae7739b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 193 additions and 38 deletions

View File

@ -873,4 +873,19 @@ public class AcquisitionControl extends RawInputControlledUnit implements PamSet
return getDaqProcess().setAnalysisStartTime(startTime); return getDaqProcess().setAnalysisStartTime(startTime);
} }
/**
* Very specific command handler for batch status which will only work
* with the folderinputSystem.
* @return
*/
public String getBatchStatus() {
DaqSystem runningSystem = getAcquisitionProcess().getRunningSystem();
if (runningSystem instanceof FolderInputSystem) {
return ((FolderInputSystem) runningSystem).getBatchStatus();
}
else {
return null;
}
}
} }

View File

@ -893,5 +893,19 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings, D
return false; return false;
} }
/**
* Get a status update for batch processing.
*/
public String getBatchStatus() {
int nFiles = 0;
if (allFiles != null) {
nFiles = allFiles.size();
}
int generalStatus = PamController.getInstance().getPamStatus();
File currFile = getCurrentFile();
String bs = String.format("%d,%d,%d,%s", nFiles,currentFile,generalStatus,currFile);
return bs;
}
} }

View File

@ -55,7 +55,7 @@ import generalDatabase.DBControlUnit;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.stage.Stage; import javafx.stage.Stage;
import Array.ArrayManager; import Array.ArrayManager;
import PamController.command.MultiportController; import PamController.command.MulticastController;
import PamController.command.NetworkController; import PamController.command.NetworkController;
import PamController.command.TerminalController; import PamController.command.TerminalController;
import PamController.command.WatchdogComms; import PamController.command.WatchdogComms;
@ -258,8 +258,8 @@ public class PamController implements PamControllerInterface, PamSettings {
if (pamBuoyGlobals.getNetworkControlPort() != null) { if (pamBuoyGlobals.getNetworkControlPort() != null) {
networkController = new NetworkController(this); networkController = new NetworkController(this);
} }
if (pamBuoyGlobals.getMultiportAddress() != null) { if (pamBuoyGlobals.getMulticastAddress() != null) {
new MultiportController(this); new MulticastController(this);
} }
guiFrameManager = PamGUIManager.createGUI(this, object); guiFrameManager = PamGUIManager.createGUI(this, object);

View File

@ -0,0 +1,64 @@
package PamController.command;
import networkTransfer.send.NetworkSender;
import pamguard.GlobalArguments;
public class BatchCommand extends ExtCommand {
public static final String commandId = "batchcommand";
private CommandManager commandManager;
public BatchCommand(CommandManager commandManager) {
super(commandId, true);
this.commandManager = commandManager;
}
@Override
public String execute(String command) {
/**
* this should have to identifiers. If they match the identifiers of
* this pamguard instance, then the command part is passed back to the manager
* otherwise it is ignored.
*/
if (command == null) {
return null;
}
String[] bits = command.split(" ");
if (bits.length < 4) {
return null;
}
int id1 = 0;
int id2 = 0;
int expId1 = 0, expId2 = 0;
try {
id1 = Integer.valueOf(bits[1]);
id2 = Integer.valueOf(bits[2]);
}
catch (NumberFormatException e) {
System.out.println("Invalid BatchCommand: " + command);
return null;
}
String nid1 = GlobalArguments.getParam(NetworkSender.ID1);
String nid2 = GlobalArguments.getParam(NetworkSender.ID2);
if (bits[1].trim().equals(nid1) == false) {
return null;
}
// now trim the string to the end of the third comma and send on the rest
int comPos = -1;
for (int i = 0; i < 3; i++) {
comPos = command.indexOf(" ", comPos+1);
if (comPos < 0) {
return null;
}
}
String trueCommand = command.substring(comPos);
trueCommand = trueCommand.trim();
// System.out.printf(">>>>>>>>>>>>>>>>>>> Batchcommand execute \"%s\" in command manager %s\n", trueCommand, commandManager.getClass().getName());
if (commandManager.interpretCommand(trueCommand)) {
// return commandManager.get
}
return null;
}
}

View File

@ -0,0 +1,31 @@
package PamController.command;
import Acquisition.AcquisitionControl;
import PamController.PamController;
import pamViewFX.PamControlledGUIFX;
/**
* Command to get PAMGuard to send back the batch processing status.
*
* @author dg50
*
*/
public class BatchStatusCommand extends ExtCommand {
public static final String commandId = "batchstatus";
public BatchStatusCommand() {
super(commandId, true);
// TODO Auto-generated constructor stub
}
@Override
public String execute(String command) {
AcquisitionControl daqControl = (AcquisitionControl) PamController.getInstance().findControlledUnit(AcquisitionControl.class, null);
if (daqControl == null) {
return null;
}
return daqControl.getBatchStatus();
}
}

View File

@ -40,6 +40,8 @@ public abstract class CommandManager extends PamControlledUnit {
commandsList.add(new HelpCommand(this)); commandsList.add(new HelpCommand(this));
commandsList.add(new GetXMLSettings()); commandsList.add(new GetXMLSettings());
commandsList.add(new SetXMLSettings()); commandsList.add(new SetXMLSettings());
commandsList.add(new BatchStatusCommand());
commandsList.add(new BatchCommand(this));
} }
@ -81,16 +83,16 @@ public abstract class CommandManager extends PamControlledUnit {
} }
ExtCommand extCommand = findCommand(command); ExtCommand extCommand = findCommand(command);
if (extCommand == null) { if (extCommand == null) {
sendData("Cmd \"" + commandString + "\" Not Recognised."); sendData(extCommand, "Cmd \"" + commandString + "\" Not Recognised.");
return false; return false;
} }
if (extCommand.canExecute() == false) { if (extCommand.canExecute() == false) {
sendData("Cmd \"" + command + "\" Cannot Execute."); sendData(extCommand, "Cmd \"" + command + "\" Cannot Execute.");
// sendData(" Cmd return string = " + extCommand.getReturnString()); // sendData(" Cmd return string = " + extCommand.getReturnString());
return false; return false;
} }
String output = extCommand.executeCommand(commandString); String output = extCommand.executeCommand(commandString);
sendData(output); sendData(extCommand,output);
return true; return true;
@ -154,9 +156,10 @@ public abstract class CommandManager extends PamControlledUnit {
/** /**
* Reply to data called from InterpredData * Reply to data called from InterpredData
* @param extCommand
* @param dataString * @param dataString
* @return true if replay successful * @return true if replay successful
*/ */
abstract public boolean sendData(String dataString); abstract public boolean sendData(ExtCommand extCommand, String dataString);
} }

View File

@ -10,8 +10,10 @@ import PamController.PamSettingManager;
*/ */
public class ExitCommand extends ExtCommand { public class ExitCommand extends ExtCommand {
public static final String commandId = "Exit";
public ExitCommand() { public ExitCommand() {
super("Exit", false); super(commandId, false);
} }
@Override @Override

View File

@ -25,7 +25,7 @@ public class HelpCommand extends ExtCommand {
out += "\n"; out += "\n";
} }
} }
commandManager.sendData(out); commandManager.sendData(this, out);
return getName(); return getName();
} }

View File

@ -12,12 +12,14 @@ import java.nio.charset.StandardCharsets;
import PamController.PamController; import PamController.PamController;
import PamController.pamBuoyGlobals; import PamController.pamBuoyGlobals;
import networkTransfer.send.NetworkSender;
import pamguard.GlobalArguments;
public class MultiportController extends CommandManager { public class MulticastController extends CommandManager {
//The multicast addresses are in the range 224.0.0.0 through 239.255.255.255 //The multicast addresses are in the range 224.0.0.0 through 239.255.255.255
private static String unitName = "Multiport Controller"; private static String unitName = "Multicast Controller";
private PamController pamController; private PamController pamController;
private String mAddress; private String mAddress;
private int mPort; private int mPort;
@ -29,11 +31,11 @@ public class MultiportController extends CommandManager {
private byte[] byteBuffer = new byte[MAX_COMMAND_LENGTH]; private byte[] byteBuffer = new byte[MAX_COMMAND_LENGTH];
private DatagramPacket lastDatagram; private DatagramPacket lastDatagram;
public MultiportController(PamController pamController) { public MulticastController(PamController pamController) {
super(pamController, unitName); super(pamController, unitName);
this.pamController = pamController; this.pamController = pamController;
this.mAddress = pamBuoyGlobals.getMultiportAddress(); this.mAddress = pamBuoyGlobals.getMulticastAddress();
this.mPort = pamBuoyGlobals.getMuliportPort(); this.mPort = pamBuoyGlobals.getMulticastPort();
Thread t = new Thread(new ListenerThread()); Thread t = new Thread(new ListenerThread());
t.start(); t.start();
@ -83,17 +85,35 @@ public class MultiportController extends CommandManager {
private void processDatagram(DatagramPacket datagram) { private void processDatagram(DatagramPacket datagram) {
lastDatagram = datagram; lastDatagram = datagram;
String str = new String(datagram.getData(), 0, datagram.getLength()); String str = new String(datagram.getData(), 0, datagram.getLength());
// str = str.substring(0, datagram.getLength()); str = str.substring(0, datagram.getLength());
System.out.println("Datagram received \"" + str + "\""); // System.out.println("Datagram received \"" + str + "\"");
interpretCommand(str); interpretCommand(str);
} }
@Override @Override
public boolean sendData(String dataString) { public boolean sendData(ExtCommand extCommand, String dataString) {
if (dataString == null || dataString.length() == 0) {
return false;
}
DatagramPacket senderInfo = lastDatagram; DatagramPacket senderInfo = lastDatagram;
System.out.printf("Send back data \"%s\" to %s port %d\n", dataString, senderInfo.getAddress(), senderInfo.getPort()); String commandName;
if (extCommand == null) {
commandName = "Unknown";
}
else {
commandName = extCommand.getName();
}
// System.out.printf("Send back data \"%s\" to %s port %d\n", dataString, senderInfo.getAddress(), senderInfo.getPort());
/*
* for multicast, we need to send a slightly different string back which has the station id as part of
* the returned string. These will be 0 if they weren't passed in at the command line.
*/
String id1 = GlobalArguments.getParam(NetworkSender.ID1);
String id2 = GlobalArguments.getParam(NetworkSender.ID2);
String bigString = String.format("%s,%s,%s,%s", commandName, id1, id2, dataString);
// dataString += "\n"; // dataString += "\n";
DatagramPacket packet = new DatagramPacket(dataString.getBytes(), dataString.length()); DatagramPacket packet = new DatagramPacket(bigString.getBytes(), bigString.length());
packet.setAddress(senderInfo.getAddress()); packet.setAddress(senderInfo.getAddress());
packet.setPort(senderInfo.getPort()); packet.setPort(senderInfo.getPort());
try { try {

View File

@ -124,16 +124,14 @@ public class NetworkController extends CommandManager {
} }
} }
@Override
public boolean sendData(String dataString) { public boolean sendData(ExtCommand extCommand, String dataString) {
DatagramPacket packet = new DatagramPacket(dataString.getBytes(), dataString.length()); DatagramPacket packet = new DatagramPacket(dataString.getBytes(), dataString.length());
packet.setAddress(udpPacket.getAddress()); packet.setAddress(udpPacket.getAddress());
packet.setPort(udpPacket.getPort()); packet.setPort(udpPacket.getPort());
try { try {
receiveSocket.send(packet); receiveSocket.send(packet);
// receiveSocket.
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }

View File

@ -17,7 +17,7 @@ public class TerminalController extends CommandManager {
} }
@Override @Override
public boolean sendData(String dataString) { public boolean sendData(ExtCommand extcommand, String dataString) {
System.out.println(dataString); System.out.println(dataString);
return true; return true;
} }

View File

@ -16,7 +16,7 @@ public enum ReprocessStoreChoice {
public String toString() { public String toString() {
switch (this) { switch (this) {
case STARTNORMAL: case STARTNORMAL:
return "Start normally. No risk of overwriting"; return "Start normally. Note risk of overwriting!";
case CONTINUECURRENTFILE: case CONTINUECURRENTFILE:
return "Continue from start of last input file processed"; return "Continue from start of last input file processed";
case CONTINUENEXTFILE: case CONTINUENEXTFILE:

View File

@ -14,9 +14,9 @@ public class pamBuoyGlobals {
// public static Integer useGstreamer = 0; // public static Integer useGstreamer = 0;
// public static boolean useNetworkCont = false; // public static boolean useNetworkCont = false;
private static Integer networkControlPort = null; private static Integer networkControlPort = null;
private static String multiportAddress; private static String multicastAddress;
// private static boolean useDSP = false; // private static boolean useDSP = false;
private static int muliportPort; private static int mulicastPort;
/** /**
* @return the networkControlPort * @return the networkControlPort
@ -33,28 +33,28 @@ private static int muliportPort;
} }
/** /**
* Set parameters for mulitport configutation. * Set parameters for mulitport configuration.
* @param mAddr * @param mAddr
* @param mPort * @param mPort
*/ */
public static void setMultiportConfig(String mAddr, int mPort) { public static void setMultiportConfig(String mAddr, int mPort) {
multiportAddress = mAddr; multicastAddress = mAddr;
muliportPort = mPort; mulicastPort = mPort;
} }
/** /**
* @return the multiportAddress * @return the multiportAddress
*/ */
public static String getMultiportAddress() { public static String getMulticastAddress() {
return multiportAddress; return multicastAddress;
} }
/** /**
* @return the muliportPort * @return the muliportPort
*/ */
public static int getMuliportPort() { public static int getMulticastPort() {
return muliportPort; return mulicastPort;
} }

View File

@ -488,6 +488,15 @@ public class PamTableItem implements Cloneable {
if (value == null) { if (value == null) {
return Float.NaN; return Float.NaN;
} }
if (value instanceof String) {
try {
double val = Double.valueOf((String) value);
return (float) val;
}
catch (NumberFormatException ex) {
return Float.NaN;
}
}
if (value.getClass() == Double.class) { if (value.getClass() == Double.class) {
double dVal = (Double) value; double dVal = (Double) value;
return (float) dVal; return (float) dVal;

View File

@ -222,8 +222,7 @@ public class Pamguard {
PamGUIManager.setType(PamGUIManager.NOGUI); PamGUIManager.setType(PamGUIManager.NOGUI);
System.out.println("no gui operation."); System.out.println("no gui operation.");
} }
/////////////// else if (anArg.equalsIgnoreCase("-psf") || anArg.equalsIgnoreCase("-psfx")) {
else if (anArg.equalsIgnoreCase("-psf")) {
String autoPsf = args[iArg++]; String autoPsf = args[iArg++];
PamSettingManager.remote_psf = autoPsf; PamSettingManager.remote_psf = autoPsf;
System.out.println("Running using settings from " + autoPsf); System.out.println("Running using settings from " + autoPsf);
@ -234,12 +233,12 @@ public class Pamguard {
pamBuoyGlobals.setNetworkControlPort(Integer.parseInt(port)); pamBuoyGlobals.setNetworkControlPort(Integer.parseInt(port));
System.out.println("Setting UDP control port " + port); System.out.println("Setting UDP control port " + port);
} }
else if (anArg.equalsIgnoreCase("-mport")) { else if (anArg.equalsIgnoreCase("-multicast") || anArg.equalsIgnoreCase("-mport")) {
// multicast control (for multiple PAMGuards) // multicast control (for multiple PAMGuards)
String mAddr = args[iArg++]; String mAddr = args[iArg++];
int mPort = Integer.parseInt(args[iArg++]); int mPort = Integer.parseInt(args[iArg++]);
pamBuoyGlobals.setMultiportConfig(mAddr, mPort); pamBuoyGlobals.setMultiportConfig(mAddr, mPort);
System.out.printf("Setting multiport control addr %s port %d\n", mAddr, mPort); System.out.printf("Setting multicast control addr %s port %d\n", mAddr, mPort);
} }
else if (anArg.equalsIgnoreCase("-nolog")) { else if (anArg.equalsIgnoreCase("-nolog")) {
System.out.println("Disabling log file from command line switch..."); System.out.println("Disabling log file from command line switch...");