FDA-108
This commit is contained in:
2014-01-22 11:00:29 +01:00
parent e915cbc783
commit 55689fd464
3 changed files with 120 additions and 71 deletions
+5 -1
View File
@@ -31,4 +31,8 @@ This will take the default connections settings:
# Development
A standalone jar can be build via `mvn clean compile assembly:single`.
To upload the latest version to the artifact repository use ` mvn clean compile deploy`.
To upload the latest version to the artifact repository use ` mvn clean compile deploy`.
# Notes
Trigger port is `Trigger In 1`. For testing apply a 1kHz signal. Max frequency before loosing data is arround 2kHz.
@@ -21,11 +21,14 @@ package ch.psi.fda.fdaq;
import java.io.File;
import java.util.concurrent.Executors;
import sun.misc.Signal;
import sun.misc.SignalHandler;
import ch.psi.fda.serializer.SerializerTXT;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
@SuppressWarnings("restriction")
public class FdaqMain {
public static void main(String[] args) {
@@ -51,13 +54,35 @@ public class FdaqMain {
EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
FdaqService fdaq = new FdaqService(bus);
final FdaqService fdaq = new FdaqService(bus);
if(acquire){
Signal.handle(new Signal("INT"), new SignalHandler() {
int count = 0;
public void handle(Signal sig) {
if(count < 1){
fdaq.stop();
count++;
return;
}
System.exit(0);
}
});
SerializerTXT serializer = new SerializerTXT(file);
serializer.setShowDimensionHeader(false);
bus.register(serializer);
// This stop ensures that the data server is in a good shape (i.e. gets restarted)
// We need to wait a certain amount of time to have the server restarted.
fdaq.stop();
try {
Thread.sleep(1000); // TODO check whether this sleep is really necessary
} catch (InterruptedException e) {
e.printStackTrace();
}
fdaq.acquire();
}
else{
@@ -51,7 +51,7 @@ public class FdaqService {
private String hostname = "mchip015.psi.ch";
private int port = 2233;
private int killPort = 2234;
private int numberOfElements = Integer.MAX_VALUE/2;
private int numberOfElements = Integer.MAX_VALUE;
public FdaqService(EventBus bus){
this.bus = bus;
@@ -78,78 +78,97 @@ public class FdaqService {
DataOutputStream out = null;
DataInputStream in = null;
try {
stopAcquisition = false;
echoSocket = new Socket(hostname, port);
out = new DataOutputStream(echoSocket.getOutputStream());
in = new DataInputStream(echoSocket.getInputStream());
// struct fdaqbloc_in {int fnum;int nsample;};
ByteBuffer bytebuffer = ByteBuffer.allocate(2 * 4); // 2 times
// Integers
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
bytebuffer.putInt(26);
bytebuffer.putInt(numberOfElements);
out.write(bytebuffer.array());
out.flush();
final List<Metadata> metadata = new ArrayList<>();
metadata.add(new Metadata("counter"));
metadata.add(new Metadata("ain1"));
metadata.add(new Metadata("ain2"));
metadata.add(new Metadata("ain3"));
metadata.add(new Metadata("ain4"));
metadata.add(new Metadata("enc1"));
for (int t = 0; t < numberOfElements; t++) {
// struct fdaqbloc_out {int trigindex;int adc1reg;int
// adc2reg;int encoder;};
ByteBuffer buffer = ByteBuffer.allocate(4 * 4); // 4 times
// Integers
buffer.order(ByteOrder.LITTLE_ENDIAN);
int r = in.read(buffer.array());
if (r == -1) {
break;
}
int a = buffer.getInt();
int b = buffer.getInt();
int b1 = b & 0xffff;
int b2 = (b >> 16) & 0xffff;
int c = buffer.getInt();
int c1 = c & 0xffff;
int c2 = (c >> 16) & 0xffff;
int d = buffer.getInt();
DataMessage message = new DataMessage(metadata);
message.getData().add(a);
message.getData().add(b1);
message.getData().add(b2);
message.getData().add(c1);
message.getData().add(c2);
message.getData().add(d);
bus.post(message);
}
} catch (IOException e) {
// Ignore potential exceptions if stop was triggered before all messages were retrieved
if (!stopAcquisition) {
throw new RuntimeException(e);
}
} finally {
bus.post(new EndOfStreamMessage());
while(running){
try {
out.close();
in.close();
echoSocket.close();
stopAcquisition = false;
echoSocket = new Socket(hostname, port);
out = new DataOutputStream(echoSocket.getOutputStream());
in = new DataInputStream(echoSocket.getInputStream());
// st ruct fdaqbloc_in {int fnum;int nsample;};
ByteBuffer bytebuffer = ByteBuffer.allocate(2 * 4); // 2 times
// Integers
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
bytebuffer.putInt(26);
// bytebuffer.putInt(numberOfElements);
bytebuffer.putInt(16000);
out.write(bytebuffer.array());
out.flush();
final List<Metadata> metadata = new ArrayList<>();
metadata.add(new Metadata("counter"));
metadata.add(new Metadata("ain1"));
metadata.add(new Metadata("ain2"));
metadata.add(new Metadata("ain3"));
metadata.add(new Metadata("ain4"));
metadata.add(new Metadata("enc1"));
int index=0;
for (int t = 0; t < numberOfElements; t++) {
// struct fdaqbloc_out {int trigindex;int adc1reg;int
// adc2reg;int encoder;};
ByteBuffer buffer = ByteBuffer.allocate(4 * 4); // 4 times
// Integers
buffer.order(ByteOrder.LITTLE_ENDIAN);
int r = in.read(buffer.array());
if (r == -1) {
logger.info("End of Stream");
break;
}
int a = buffer.getInt();
int b = buffer.getInt();
int b1 = b & 0xffff;
int b2 = (b >> 16) & 0xffff;
int c = buffer.getInt();
int c1 = c & 0xffff;
int c2 = (c >> 16) & 0xffff;
int d = buffer.getInt();
DataMessage message = new DataMessage(metadata);
message.getData().add(a);
message.getData().add(b1);
message.getData().add(b2);
message.getData().add(c1);
message.getData().add(c2);
message.getData().add(d);
bus.post(message);
if(t==0){
logger.info("index: "+a);
}
index=a;
}
logger.info("Done ..."+index);
} catch (IOException e) {
// Ignore because not relevant at this stage
// Ignore potential exceptions if stop was triggered before all messages were retrieved
if (!stopAcquisition) {
throw new RuntimeException(e);
}
} finally {
// bus.post(new EndOfStreamMessage());
try {
out.close();
in.close();
echoSocket.close();
} catch (IOException e) {
// Ignore because not relevant at this stage
}
running = false;
}
running = false;
}
bus.post(new EndOfStreamMessage());
}
/**
@@ -157,6 +176,7 @@ public class FdaqService {
*/
public void stop() {
try {
running=false;
stopAcquisition = true;
Socket echoSocket = new Socket(hostname, killPort);
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());