Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ed35d4c922 |
@@ -33,7 +33,7 @@ ch.psi.fda.fdaq.port=1234
|
||||
ch.psi.fda.fdaq.killPort=4321
|
||||
```
|
||||
|
||||
Use `-Dch.psi.fda.fdaq.config.file=<file>` to use this property file as base configuration.
|
||||
Use `-Dch.psi.fda.fdaq.config=<file>` to use this property file as base configuration.
|
||||
|
||||
|
||||
|
||||
|
||||
+4
-16
@@ -3,25 +3,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.fda.fdaq</artifactId>
|
||||
<version>2.3.4</version>
|
||||
<version>1.0.9</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.fda.core</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>jcae</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -60,12 +48,12 @@
|
||||
<snapshotRepository>
|
||||
<id>i.snapshots</id>
|
||||
<name>Artifactory Snapshots</name>
|
||||
<url>http://yoke.psi.ch:8081/artifactory/libs-snapshots-local</url>
|
||||
<url>http://yoke/artifactory/libs-snapshots-local</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>i.releases</id>
|
||||
<name>Atrifactory Releases</name>
|
||||
<url>http://yoke.psi.ch:8081/artifactory/libs-releases-local</url>
|
||||
<url>http://yoke/artifactory/libs-releases-local</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
@@ -18,10 +18,8 @@
|
||||
*/
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -37,6 +35,10 @@ import ch.psi.fda.messages.DataMessage;
|
||||
import ch.psi.fda.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.messages.Metadata;
|
||||
|
||||
/**
|
||||
* Fdaq service
|
||||
*
|
||||
*/
|
||||
public class Fdaq {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Fdaq.class.getName());
|
||||
@@ -47,7 +49,7 @@ public class Fdaq {
|
||||
private final EventBus bus;
|
||||
|
||||
private FdaqConfiguration configuration;
|
||||
private final int numberOfElements = Integer.MAX_VALUE/2;
|
||||
private final int numberOfElements = Integer.MAX_VALUE/2;
|
||||
|
||||
public Fdaq(EventBus bus, FdaqConfiguration configuration){
|
||||
this.bus = bus;
|
||||
@@ -63,14 +65,6 @@ public class Fdaq {
|
||||
public void acquire() {
|
||||
running = true; // potential threading problem
|
||||
|
||||
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"));
|
||||
|
||||
Socket echoSocket = null;
|
||||
DataOutputStream out = null;
|
||||
DataInputStream in = null;
|
||||
@@ -84,7 +78,7 @@ public class Fdaq {
|
||||
stopAcquisition = false;
|
||||
echoSocket = new Socket(configuration.getHostname(), configuration.getPort());
|
||||
out = new DataOutputStream(echoSocket.getOutputStream());
|
||||
in = new DataInputStream(new BufferedInputStream(echoSocket.getInputStream()));
|
||||
in = new DataInputStream(echoSocket.getInputStream());
|
||||
|
||||
ByteBuffer bytebuffer = ByteBuffer.allocate(3 * 4); // 3 times Integer
|
||||
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
@@ -103,12 +97,11 @@ public class Fdaq {
|
||||
out.flush();
|
||||
|
||||
for (int t = 0; t < numberOfElements; t++) {
|
||||
byte[] cbuffer = new byte[4*4]; // 4 times Integers a 4 bytes
|
||||
|
||||
try{
|
||||
in.readFully(cbuffer);
|
||||
}
|
||||
catch(EOFException e){
|
||||
// struct fdaqbloc_out {int trigindex;int adc1reg;int
|
||||
// adc2reg;int encoder;};
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4 * 4); // 4 times Integers
|
||||
int r = in.read(buffer.array());
|
||||
if (r == -1) {
|
||||
logger.info("End of Stream");
|
||||
break;
|
||||
}
|
||||
@@ -119,30 +112,8 @@ public class Fdaq {
|
||||
// This is independent of the frequency
|
||||
continue;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(cbuffer);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
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);
|
||||
bus.post(buffer);
|
||||
}
|
||||
|
||||
logger.info("Done ...");
|
||||
|
||||
} catch (IOException e) {
|
||||
// Ignore potential exceptions if stop was triggered before all messages were retrieved
|
||||
if (!stopAcquisition) {
|
||||
@@ -150,21 +121,17 @@ public class Fdaq {
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (out!=null)
|
||||
out.close();
|
||||
if (in!=null)
|
||||
in.close();
|
||||
if (echoSocket!=null)
|
||||
echoSocket.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore because not relevant at this stage
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bus.post(new EndOfStreamMessage());
|
||||
// bus.post(new EndOfStreamMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2014 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.fda.messages.DataMessage;
|
||||
import ch.psi.fda.messages.Metadata;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
/**
|
||||
* Does the bit shuffle required for fdaq.
|
||||
*/
|
||||
public class FdaqBitShuffle {
|
||||
|
||||
private final EventBus bus;
|
||||
private final List<Metadata> metadata;
|
||||
|
||||
public FdaqBitShuffle(EventBus bus){
|
||||
this.bus = bus;
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void shuffle(ByteBuffer buffer){
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -22,28 +22,12 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class FdaqConfiguration {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FdaqConfiguration.class.getName());
|
||||
private final static String FDAQ_CONFIG = "ch.psi.fda.fdaq.config.file";
|
||||
|
||||
private String hostname = "mchip015.psi.ch";
|
||||
private int port = 2233;
|
||||
private int killPort = 2234;
|
||||
|
||||
public FdaqConfiguration(){
|
||||
String config = System.getProperty(FDAQ_CONFIG);
|
||||
|
||||
if(config != null){
|
||||
loadFile(new File(config));
|
||||
}
|
||||
else{
|
||||
logger.warning("No configuration file specified via -D"+FDAQ_CONFIG+"=... - using defaults");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadFile(File file) {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2014 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import ch.psi.fda.EContainer;
|
||||
import ch.psi.fda.fdaq.FdaqConfiguration;
|
||||
import ch.psi.fda.serializer.SerializerTXT;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
public class FdaqEContainer implements EContainer {
|
||||
|
||||
private Fdaq fdaq;
|
||||
private EventBus bus;
|
||||
|
||||
private FdaqEDescriptor edescriptor;
|
||||
|
||||
@Inject
|
||||
public FdaqEContainer(FdaqEDescriptor edescriptor, EventBus ebus){
|
||||
this.bus = ebus;
|
||||
this.edescriptor = edescriptor;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
if(fdaq!=null && fdaq.isRunning()){
|
||||
throw new IllegalStateException("FDAQ is already running");
|
||||
}
|
||||
|
||||
fdaq = new Fdaq(bus, new FdaqConfiguration());
|
||||
|
||||
File file = new File(edescriptor.getFileName());
|
||||
file.getParentFile().mkdirs(); // Create data base directory
|
||||
|
||||
SerializerTXT serializer = new SerializerTXT(file);
|
||||
serializer.setShowDimensionHeader(false);
|
||||
bus.register(serializer);
|
||||
|
||||
fdaq.acquire();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort() {
|
||||
fdaq.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return fdaq.isRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import ch.psi.fda.EContainer;
|
||||
import ch.psi.fda.EContainerFactory;
|
||||
import ch.psi.fda.edescriptor.EDescriptor;
|
||||
|
||||
public class FdaqEContainerFactory implements EContainerFactory {
|
||||
|
||||
@Override
|
||||
public boolean supportsEDescriptor(EDescriptor descriptor) {
|
||||
return descriptor instanceof FdaqEDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EContainer getEContainer(EDescriptor descriptor, EventBus bus) {
|
||||
return new FdaqEContainer((FdaqEDescriptor) descriptor, bus);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import ch.psi.fda.edescriptor.EDescriptor;
|
||||
|
||||
@XmlRootElement(name="fdaq")
|
||||
public class FdaqEDescriptor implements EDescriptor {
|
||||
|
||||
private String fileName;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import ch.psi.fda.DescriptorProvider;
|
||||
import ch.psi.fda.edescriptor.EDescriptor;
|
||||
import ch.psi.fda.vdescriptor.VDescriptor;
|
||||
|
||||
public class FdaqEDescriptorProvider implements DescriptorProvider {
|
||||
|
||||
private EDescriptor edescriptor;
|
||||
|
||||
@Override
|
||||
public void load(File... files) {
|
||||
try {
|
||||
JAXBContext context = JAXBContext.newInstance(FdaqEDescriptor.class);
|
||||
Unmarshaller u = context.createUnmarshaller();
|
||||
edescriptor = (EDescriptor) u.unmarshal(files[0]);
|
||||
} catch (JAXBException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDescriptor getEDescriptor() {
|
||||
return edescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VDescriptor getVDescriptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getEDescriptorClass() {
|
||||
return FdaqEDescriptor.class;
|
||||
}
|
||||
|
||||
}
|
||||
+17
-5
@@ -16,15 +16,14 @@
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.fda.fdaq.ui;
|
||||
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.fdaq.Fdaq;
|
||||
import ch.psi.fda.fdaq.FdaqConfiguration;
|
||||
import ch.psi.fda.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.serializer.SerializerTXT;
|
||||
|
||||
import com.google.common.eventbus.AsyncEventBus;
|
||||
@@ -33,6 +32,8 @@ import com.google.common.eventbus.EventBus;
|
||||
@SuppressWarnings("restriction")
|
||||
public class FdaqMain {
|
||||
|
||||
public final static String FDAQ_CONFIG = "ch.psi.fda.fdaq.config";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if(args.length != 1){
|
||||
@@ -48,15 +49,26 @@ public class FdaqMain {
|
||||
}
|
||||
|
||||
FdaqConfiguration configuration = new FdaqConfiguration();
|
||||
String config = System.getProperty(FDAQ_CONFIG);
|
||||
|
||||
EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
|
||||
final Fdaq fdaq = new Fdaq(bus, configuration);
|
||||
if(config != null){
|
||||
configuration.loadFile(new File(config));
|
||||
}
|
||||
|
||||
|
||||
EventBus busA = new AsyncEventBus(Executors.newSingleThreadExecutor());
|
||||
final EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
|
||||
|
||||
final Fdaq fdaq = new Fdaq(busA, configuration);
|
||||
final FdaqBitShuffle bshuffle= new FdaqBitShuffle(bus);
|
||||
busA.register(bshuffle);
|
||||
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
int count = 0;
|
||||
public void handle(Signal sig) {
|
||||
if(count < 1){
|
||||
fdaq.stop();
|
||||
bus.post(new EndOfStreamMessage());
|
||||
count++;
|
||||
return;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
ch.psi.fda.fdaq.FdaqEDescriptorProvider
|
||||
@@ -1 +0,0 @@
|
||||
ch.psi.fda.fdaq.FdaqEContainerFactory
|
||||
@@ -1,154 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.fda.fdaq;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Simple socket server emulating the fdaq black box.
|
||||
*/
|
||||
public class FdaqServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(FdaqServer.class.getName());
|
||||
|
||||
private volatile boolean stop = false;
|
||||
|
||||
public void startKillSocket(int port) {
|
||||
try {
|
||||
ServerSocket serverSocket = new ServerSocket(port);
|
||||
try{
|
||||
while(true){
|
||||
Socket socket = serverSocket.accept();
|
||||
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
||||
DataInputStream in = new DataInputStream(socket.getInputStream());
|
||||
|
||||
byte[] requestBuffer = new byte[1 * 4]; // 2 times integers
|
||||
ByteBuffer bytebuffer = ByteBuffer.wrap(requestBuffer);
|
||||
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
in.read(requestBuffer);
|
||||
|
||||
bytebuffer.getInt();
|
||||
|
||||
logger.info("Terminate sender");
|
||||
stop=true;
|
||||
|
||||
out.close();
|
||||
in.close();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
finally{
|
||||
serverSocket.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void startSenderSocket(int port) {
|
||||
stop = false;
|
||||
try {
|
||||
ServerSocket serverSocket = new ServerSocket(port);
|
||||
try{
|
||||
while(true){
|
||||
Socket socket = serverSocket.accept();
|
||||
stop = false;
|
||||
|
||||
logger.info("Start sending ...");
|
||||
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
||||
DataInputStream in = new DataInputStream(socket.getInputStream());
|
||||
|
||||
byte[] requestBuffer = new byte[2 * 4]; // 2 times integers
|
||||
ByteBuffer bytebuffer = ByteBuffer.wrap(requestBuffer);
|
||||
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
in.read(requestBuffer);
|
||||
|
||||
bytebuffer.getInt(); // This will always be 26
|
||||
int nMessages = bytebuffer.getInt(); // Contains number of images to
|
||||
// receive
|
||||
|
||||
// System.out.println("Messages to send: "+nMessages);
|
||||
|
||||
for (int t = 0; t < nMessages; t++) {
|
||||
|
||||
if(stop){ // Terminate loop if kill socket got a request
|
||||
break;
|
||||
}
|
||||
// System.out.println(t+" "+0+" "+0+" "+ (-t));
|
||||
|
||||
byte[] dataBuffer = new byte[4 * 4]; // 4 times Integers
|
||||
ByteBuffer buffer = ByteBuffer.wrap(dataBuffer); // 4 times
|
||||
// Integers
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
buffer.putInt(t);
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(-t);
|
||||
|
||||
out.write(dataBuffer);
|
||||
out.flush();
|
||||
|
||||
if(t>1028){ // The first 1028 images are skipped anyways
|
||||
Thread.sleep(10);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
finally{
|
||||
serverSocket.close();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
|
||||
final FdaqConfiguration configuration = new FdaqConfiguration();
|
||||
final FdaqServer server = new FdaqServer();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
server.startSenderSocket(configuration.getPort());
|
||||
}
|
||||
}).start();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
server.startKillSocket(configuration.getKillPort());
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Simple socket client to connect to the fdaq black box.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class SocketClient {
|
||||
|
||||
@@ -41,13 +43,11 @@ public class SocketClient {
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
|
||||
// Socket echoSocket = new Socket("localhost", 9999);
|
||||
// Socket echoSocket = new Socket("mchip015", 2233);
|
||||
Socket echoSocket = new Socket("localhost", 2233);
|
||||
Socket echoSocket = new Socket("mchip015", 2233);
|
||||
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
|
||||
DataInputStream in = new DataInputStream(echoSocket.getInputStream());
|
||||
|
||||
// int nMessages = 100;
|
||||
int nMessages = Integer.MAX_VALUE;
|
||||
int nMessages = 100;
|
||||
|
||||
// struct fdaqbloc_in {int fnum;int nsample;};
|
||||
ByteBuffer bytebuffer = ByteBuffer.allocate(2*4); // 2 times Integers
|
||||
@@ -77,7 +77,7 @@ public class SocketClient {
|
||||
int c2 = (c>>16)&0xffff;
|
||||
int d = buffer.getInt();
|
||||
|
||||
System.out.println( a+ " " +b1+ " " +b2+ " " + c1+ " " +c2+ " " +d );
|
||||
System.out.println(a+ " " +b1+ " " +b2+ " " + c1+ " " +c2+ " " +d );
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Simple socket client to connect to the fdaq black box.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class SocketClientStop {
|
||||
|
||||
@@ -39,8 +41,7 @@ public class SocketClientStop {
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
|
||||
// Socket echoSocket = new Socket("localhost", 9998);
|
||||
Socket echoSocket = new Socket("localhost", 2234);
|
||||
Socket echoSocket = new Socket("localhost", 9998);
|
||||
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
|
||||
|
||||
ByteBuffer bytebuffer = ByteBuffer.allocate(1*4); // 2 times Integers
|
||||
|
||||
Reference in New Issue
Block a user