updates to Daq

New DLL, and some LED control, but hasn't fixed stalling problem.
This commit is contained in:
Douglas Gillespie 2024-07-22 09:29:38 +01:00
parent 910950878d
commit 3da8401756
3 changed files with 78 additions and 16 deletions

Binary file not shown.

View File

@ -19,6 +19,9 @@ public class SmruDaqJNI {
static public final int SMRU_VAL_SLAVE_MASTERED = 3; static public final int SMRU_VAL_SLAVE_MASTERED = 3;
static public final int SMRU_RET_OK = 0; static public final int SMRU_RET_OK = 0;
static public final int GREEN_LED = 1;
static public final int RED_LED = 0;
/** /**
* Have rebuilt SAIL Daq interface in 2022, but in principle this was * Have rebuilt SAIL Daq interface in 2022, but in principle this was
@ -29,11 +32,6 @@ public class SmruDaqJNI {
private static final String SILIB = "SailDaqJNI"; private static final String SILIB = "SailDaqJNI";
// private static final String SILIB = "SailDaqV7"; // private static final String SILIB = "SailDaqV7";
/**
* this is the verbose level for the C code part.
*/
private static final int verboseLevel = 0;
private static final String DEVNAME = "/dev/cypress_smru0"; private static final String DEVNAME = "/dev/cypress_smru0";
private static final int MINJNIVERSION = 5; private static final int MINJNIVERSION = 5;
@ -265,7 +263,7 @@ public class SmruDaqJNI {
this.smruDaqSystem = smruDaqSystem; this.smruDaqSystem = smruDaqSystem;
loadLibrary(); loadLibrary();
if (haveLibrary()) { if (haveLibrary()) {
setVerbose(verboseLevel); setVerbose(SmruDaqSystem.VERBOSELEVEL);
/** /**
* List the devices, but don't do any resetting and * List the devices, but don't do any resetting and
@ -492,7 +490,7 @@ public class SmruDaqJNI {
public int toggleLED(int board, int led) { public int toggleLED(int board, int led) {
board = boardOrder[board]; board = boardOrder[board];
int state = getLED(board, led); int state = getLED(board, led);
System.out.println("state="+state); // System.out.println("LED state="+state);
if (state == 0) { if (state == 0) {
state = 1; state = 1;
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -13,6 +14,7 @@ import soundPlayback.PlaybackControl;
import soundPlayback.PlaybackSystem; import soundPlayback.PlaybackSystem;
import Acquisition.AcquisitionControl; import Acquisition.AcquisitionControl;
import Acquisition.AcquisitionDialog; import Acquisition.AcquisitionDialog;
import Acquisition.AcquisitionProcess;
import Acquisition.DaqSystem; import Acquisition.DaqSystem;
import Acquisition.AudioDataQueue; import Acquisition.AudioDataQueue;
import PamController.PamControlledUnitSettings; import PamController.PamControlledUnitSettings;
@ -49,7 +51,8 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
public static final String oldCardName = "SMRU Ltd DAQ Card"; public static final String oldCardName = "SMRU Ltd DAQ Card";
private static final int VERBOSELEVEL = 0; public static final int VERBOSELEVEL = 0;
/** /**
* @param daqControl * @param daqControl
@ -61,6 +64,11 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
smruDaqJNI = new SmruDaqJNI(this); smruDaqJNI = new SmruDaqJNI(this);
nDaqCards = smruDaqJNI.getnDevices(); nDaqCards = smruDaqJNI.getnDevices();
for (int i = 0; i < nDaqCards; i++) {
for (int l = 0; l < 2; l++) {
smruDaqJNI.setLED(i, l, 0);
}
}
smruDaqDialogPanel = new SmruDaqDialogPanel(this); smruDaqDialogPanel = new SmruDaqDialogPanel(this);
PamSettingManager.getInstance().registerSettings(this); PamSettingManager.getInstance().registerSettings(this);
@ -275,6 +283,8 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
boolean prepareDaqCard(int iBoard, boolean fullReset) { boolean prepareDaqCard(int iBoard, boolean fullReset) {
// devices are left closed, so will need to reopen them. // devices are left closed, so will need to reopen them.
// of course, there is a vile lookup table, so... // of course, there is a vile lookup table, so...
smruDaqJNI.setLED(iBoard, SmruDaqJNI.GREEN_LED, 0);
smruDaqJNI.setLED(iBoard, SmruDaqJNI.RED_LED, 0);
int hardId = smruDaqJNI.getBoardOrder(iBoard); int hardId = smruDaqJNI.getBoardOrder(iBoard);
int prepOk = smruDaqJNI.prepareDevice(hardId, fullReset); int prepOk = smruDaqJNI.prepareDevice(hardId, fullReset);
terminalPrint("Opened daq card returned " + prepOk, 1); terminalPrint("Opened daq card returned " + prepOk, 1);
@ -313,6 +323,7 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
if (ans) { if (ans) {
Thread t = new Thread(new DaqThread()); Thread t = new Thread(new DaqThread());
t.setPriority(Thread.MAX_PRIORITY);
t.start(); t.start();
keepRunning = true; keepRunning = true;
daqThreadRunning = true; daqThreadRunning = true;
@ -371,18 +382,43 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
boolean first = true; boolean first = true;
boolean needRestart = false; boolean needRestart = false;
int iChan; int iChan;
// some flags on checks of incoming data rate
// long recentSamples = 0;
// long recentCheckTime = System.currentTimeMillis();
int loopCount = 0;
for (int iBoard = 0; iBoard < nDaqCards; iBoard++) {
smruDaqJNI.setLED(iBoard, SmruDaqJNI.GREEN_LED, 1);
smruDaqJNI.setLED(iBoard, SmruDaqJNI.RED_LED, 0);
}
while (keepRunning) { while (keepRunning) {
iChan = 0; iChan = 0;
dataMillis = daqControl.getAcquisitionProcess().absSamplesToMilliseconds(totalSamples); dataMillis = daqControl.getAcquisitionProcess().absSamplesToMilliseconds(totalSamples);
if (isStalled()) {
needRestart = true;
for (int iBoard = 0; iBoard < nDaqCards; iBoard++) {
smruDaqJNI.setLED(iBoard, SmruDaqJNI.GREEN_LED, 0);
smruDaqJNI.setLED(iBoard, SmruDaqJNI.RED_LED, 1);
}
// don't set this false or the shutdown doesn't work properly.
// keepRunning = false;
break;
}
loopCount++;
for (int iBoard = 0; iBoard < nDaqCards && keepRunning; iBoard++) { for (int iBoard = 0; iBoard < nDaqCards && keepRunning; iBoard++) {
if ((loopCount % 10000) == 0) {
// toggleLED(iBoard, 0);
smruDaqJNI.setLED(iBoard, SmruDaqJNI.GREEN_LED, 1);
}
for (int i = 0; i < boardChannels[iBoard] && keepRunning; i++) { for (int i = 0; i < boardChannels[iBoard] && keepRunning; i++) {
newData = smruDaqJNI.readSamples(iBoard, i, wantedSamples); newData = smruDaqJNI.readSamples(iBoard, i, wantedSamples);
if (newData == null) { if (newData == null) {
smruDaqJNI.setLED(iBoard, SmruDaqJNI.RED_LED, 1);
System.out.println(String.format("Null data read from smruDaqJNI.readSamples board %d, chan %d, samples %d", System.out.println(String.format("Null data read from smruDaqJNI.readSamples board %d, chan %d, samples %d",
iBoard, i, wantedSamples)); iBoard, i, wantedSamples));
// System.out.println("Issue restart ..."); // System.out.println("Issue restart ...");
needRestart = true; needRestart = true;
keepRunning = false; // keepRunning = false;
break; break;
} }
readSamples = newData.length; readSamples = newData.length;
@ -409,19 +445,47 @@ public class SmruDaqSystem extends DaqSystem implements PamSettings {
if (++dcOffsetCalls == 100) { if (++dcOffsetCalls == 100) {
dcOffsetScale = 100.; // after a bit, increase the time constant. dcOffsetScale = 100.; // after a bit, increase the time constant.
} }
totalSamples += readSamples; totalSamples += readSamples;
} };
daqThreadRunning = false; daqThreadRunning = false;
if (needRestart) {
PamController pamController = PamController.getInstance(); for (int iBoard = 0; iBoard < nDaqCards; iBoard++) {
pamController.pamStop(); smruDaqJNI.setLED(iBoard, SmruDaqJNI.GREEN_LED, 0);
PamDialog.showWarning(daqControl.getGuiFrame(), daqControl.getUnitName(), "Problem with one or more SAIL DAQ Cards.\n"
+ "Restart PAMGuard, check connections and try again." );
// pamController.startLater();
} }
if (needRestart) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
PamController pamController = PamController.getInstance();
pamController.pamStop();
System.out.println("Problem with one or more SAIL DAQ Cards. "
+ "Restart PAMGuard, check connections and try again." );
// PamDialog.showWarning(daqControl.getGuiFrame(), daqControl.getUnitName(), "Problem with one or more SAIL DAQ Cards.\n"
// + "Restart PAMGuard, check connections and try again." );
pamController.startLater();
}
});
}
}
// private long lastFakeStall = 0;
private boolean isStalled() {
// if (lastFakeStall == 0) {
// lastFakeStall = System.currentTimeMillis();
// }
// long now = System.currentTimeMillis();
// if (now-lastFakeStall > 10000) {
// System.out.println("Random pretend stalled");
// lastFakeStall = 0;
// return true;
// }
return daqControl.getAcquisitionProcess().isStalled();
} }
public static short getSample(byte[] buffer, int position) { public static short getSample(byte[] buffer, int position) {