Initial commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
*
|
||||
* 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.fdaq;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Simple socket client to connect to the fdaq black box.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class SocketClient {
|
||||
|
||||
/**
|
||||
* Requires connection to:
|
||||
* ssh -L9999:mchip015:2233 x10da-gw
|
||||
*
|
||||
* @param args
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
|
||||
// Socket echoSocket = new Socket("localhost", 9999);
|
||||
Socket echoSocket = new Socket("mchip015", 2233);
|
||||
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
|
||||
DataInputStream in = new DataInputStream(echoSocket.getInputStream());
|
||||
|
||||
int nMessages = 100;
|
||||
|
||||
// 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(nMessages);
|
||||
out.write(bytebuffer.array());
|
||||
out.flush();
|
||||
|
||||
|
||||
|
||||
for (int t=0;t<nMessages;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();
|
||||
|
||||
System.out.println(a+ " " +b1+ " " +b2+ " " + c1+ " " +c2+ " " +d );
|
||||
}
|
||||
|
||||
out.close();
|
||||
in.close();
|
||||
echoSocket.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user