mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 12:07:44 +01:00
cleaning the project
This commit is contained in:
79
slsReceiverSoftware/include/MySocketTCP.h
Normal file
79
slsReceiverSoftware/include/MySocketTCP.h
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
#ifndef MY_SOCKET_TCP_H
|
||||
#define MY_SOCKET_TCP_H
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @libdoc The MySocketTCP class provides a simple interface for creating and sending/receiving data over a TCP socket.
|
||||
*
|
||||
* @short This class provides a simple interface for creating and sending/receiving data over a TCP socket.
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//version 1.0, base development, Ian 19/01/09
|
||||
|
||||
/* Modified by anna on 19.01.2009 */
|
||||
/*
|
||||
canceled SetupParameters() and varaibles intialized in the constructors' headers;
|
||||
defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file)
|
||||
|
||||
added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file)
|
||||
|
||||
defined private variables char hostname[1000] and int portno to store connection informations;
|
||||
|
||||
defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations
|
||||
|
||||
added public function int getErrorStatus() returning 1 if socketDescriptor<0
|
||||
|
||||
remove exits in the constructors and replace them with socketDescriptor=-1
|
||||
|
||||
replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings)
|
||||
|
||||
added a function which really does not close the socket between send/receive (senddataonly, receivedataonly)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* Modified by Anna on 31.10.2012
|
||||
|
||||
developed and
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "genericSocket.h"
|
||||
#define TCP_PACKET_SIZE 4096
|
||||
|
||||
class MySocketTCP: public genericSocket {
|
||||
|
||||
public:
|
||||
MySocketTCP(const char* const host_ip_or_name, unsigned short int const port_number): genericSocket(host_ip_or_name, port_number,TCP), last_keep_connection_open_action_was_a_send(0){setPacketSize(TCP_PACKET_SIZE);}; // sender (client): where to? ip
|
||||
MySocketTCP(unsigned short int const port_number):genericSocket(port_number,TCP), last_keep_connection_open_action_was_a_send(0) {setPacketSize(TCP_PACKET_SIZE);}; // receiver (server) local no need for ip
|
||||
|
||||
|
||||
//The following two functions will connectioned->send/receive->disconnect
|
||||
int SendData(void* buf,int length);//length in characters
|
||||
int ReceiveData(void* buf,int length);
|
||||
|
||||
|
||||
//The following two functions stay connected, blocking other connections, and must be manually disconnected,
|
||||
// when the last call is a SendData() or ReceiveData() the disconnection will be done automatically
|
||||
//These function will also automatically disconnect->reconnect if
|
||||
// two reads (or two writes) are called in a row to preserve the data send/receive structure
|
||||
int SendDataAndKeepConnection(void* buf,int length);
|
||||
int ReceiveDataAndKeepConnection(void* buf,int length);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
bool last_keep_connection_open_action_was_a_send;
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
155
slsReceiverSoftware/include/circularFifo.h
Normal file
155
slsReceiverSoftware/include/circularFifo.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/* CircularFifo.h
|
||||
* Not any company's property but Public-Domain
|
||||
* Do with source-code as you will. No requirement to keep this
|
||||
* header if need to use it/change it/ or do whatever with it
|
||||
*
|
||||
* Note that there is No guarantee that this code will work
|
||||
* and I take no responsibility for this code and any problems you
|
||||
* might get if using it. The code is highly platform dependent!
|
||||
*
|
||||
* Code & platform dependent issues with it was originally
|
||||
* published at http://www.kjellkod.cc/threadsafecircularqueue
|
||||
* 2009-11-02
|
||||
* @author Kjell Hedstr<74>m, hedstrom@kjellkod.cc */
|
||||
|
||||
#ifndef CIRCULARFIFO_H_
|
||||
#define CIRCULARFIFO_H_
|
||||
|
||||
//#include "sls_receiver_defs.h"
|
||||
#include <semaphore.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
|
||||
|
||||
/** Circular Fifo (a.k.a. Circular Buffer)
|
||||
* Thread safe for one reader, and one writer */
|
||||
template<typename Element>
|
||||
class CircularFifo {
|
||||
public:
|
||||
|
||||
CircularFifo(unsigned int Size) : tail(0), head(0){
|
||||
Capacity = Size + 1;
|
||||
array.resize(Capacity);
|
||||
sem_init(&free_mutex,0,0);
|
||||
}
|
||||
virtual ~CircularFifo() {
|
||||
sem_destroy(&free_mutex);
|
||||
}
|
||||
|
||||
bool push(Element*& item_);
|
||||
bool pop(Element*& item_);
|
||||
|
||||
bool isEmpty() const;
|
||||
bool isFull() const;
|
||||
|
||||
int getSemValue();
|
||||
|
||||
private:
|
||||
volatile unsigned int tail; // input index
|
||||
vector <Element*> array;
|
||||
volatile unsigned int head; // output index
|
||||
unsigned int Capacity;
|
||||
sem_t free_mutex;
|
||||
|
||||
unsigned int increment(unsigned int idx_) const;
|
||||
};
|
||||
|
||||
template<typename Element>
|
||||
int CircularFifo<Element>::getSemValue()
|
||||
{
|
||||
int value;
|
||||
sem_getvalue(&free_mutex, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/** Producer only: Adds item to the circular queue.
|
||||
* If queue is full at 'push' operation no update/overwrite
|
||||
* will happen, it is up to the caller to handle this case
|
||||
*
|
||||
* \param item_ copy by reference the input item
|
||||
* \return whether operation was successful or not */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::push(Element*& item_)
|
||||
{
|
||||
|
||||
int nextTail = increment(tail);
|
||||
if(nextTail != head)
|
||||
{
|
||||
array[tail] = item_;
|
||||
tail = nextTail;
|
||||
sem_post(&free_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// queue was full
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Consumer only: Removes and returns item from the queue
|
||||
* If queue is empty at 'pop' operation no retrieve will happen
|
||||
* It is up to the caller to handle this case
|
||||
*
|
||||
* \param item_ return by reference the wanted item
|
||||
* \return whether operation was successful or not */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::pop(Element*& item_)
|
||||
{
|
||||
// if(head == tail)
|
||||
// return false; // empty queue
|
||||
sem_wait(&free_mutex);
|
||||
|
||||
item_ = array[head];
|
||||
head = increment(head);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Useful for testinng and Consumer check of status
|
||||
* Remember that the 'empty' status can change quickly
|
||||
* as the Procuder adds more items.
|
||||
*
|
||||
* \return true if circular buffer is empty */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::isEmpty() const
|
||||
{
|
||||
return (head == tail);
|
||||
}
|
||||
|
||||
/** Useful for testing and Producer check of status
|
||||
* Remember that the 'full' status can change quickly
|
||||
* as the Consumer catches up.
|
||||
*
|
||||
* \return true if circular buffer is full. */
|
||||
template<typename Element>
|
||||
bool CircularFifo<Element>::isFull() const
|
||||
{
|
||||
int tailCheck = (tail+1) % Capacity;
|
||||
return (tailCheck == head);
|
||||
}
|
||||
|
||||
/** Increment helper function for index of the circular queue
|
||||
* index is inremented or wrapped
|
||||
*
|
||||
* \param idx_ the index to the incremented/wrapped
|
||||
* \return new value for the index */
|
||||
template<typename Element>
|
||||
unsigned int CircularFifo<Element>::increment(unsigned int idx_) const
|
||||
{
|
||||
// increment or wrap
|
||||
// =================
|
||||
// index++;
|
||||
// if(index == array.lenght) -> index = 0;
|
||||
//
|
||||
//or as written below:
|
||||
// index = (index+1) % array.length
|
||||
idx_ = (idx_+1) % Capacity;
|
||||
return idx_;
|
||||
}
|
||||
|
||||
#endif /* CIRCULARFIFO_H_ */
|
||||
678
slsReceiverSoftware/include/genericSocket.h
Normal file
678
slsReceiverSoftware/include/genericSocket.h
Normal file
@@ -0,0 +1,678 @@
|
||||
|
||||
#ifndef GENERIC_SOCKET_H
|
||||
#define GENERIC_SOCKET_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @libdoc genericSocket provides some functions to open/close sockets both TCP and UDP
|
||||
*
|
||||
* @short some functions to open/close sockets both TCP and UDP
|
||||
* @author Anna Bergamaschi
|
||||
* @version 0.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//version 1.0, base development, Ian 19/01/09
|
||||
|
||||
/* Modified by anna on 19.01.2009 */
|
||||
/*
|
||||
canceled SetupParameters() and varaibles intialized in the constructors' headers;
|
||||
defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file)
|
||||
|
||||
added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file)
|
||||
|
||||
defined private variables char hostname[1000] and int portno to store connection informations;
|
||||
|
||||
defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations
|
||||
|
||||
added public function int getErrorStatus() returning 1 if socketDescriptor<0
|
||||
|
||||
remove exits in the constructors and replace them with socketDescriptor=-1
|
||||
|
||||
replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings)
|
||||
|
||||
added a function which really does not close the socket between send/receive (senddataonly, receivedataonly)
|
||||
*/
|
||||
|
||||
#ifdef __CINT__
|
||||
//class sockaddr_in;
|
||||
class socklen_t;
|
||||
class uint32_t;
|
||||
class uint32_t_ss;
|
||||
// CINT view of types:
|
||||
class sockaddr_in;
|
||||
// {
|
||||
// unsigned short int sa_family;
|
||||
// unsigned char sa_data[14];
|
||||
// };
|
||||
#else
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_PACKET_SIZE 1286
|
||||
#define SOCKET_BUFFER_SIZE (100*1024*1024) //100MB
|
||||
#define DEFAULT_PORTNO 1952
|
||||
#define DEFAULT_BACKLOG 5
|
||||
#define DEFAULT_UDP_PORTNO 50001
|
||||
#define DEFAULT_GUI_PORTNO 65000
|
||||
|
||||
class genericSocket{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
Communication protocol
|
||||
*/
|
||||
enum communicationProtocol{
|
||||
TCP, /**< TCP/IP */
|
||||
UDP /**< UDP */
|
||||
};
|
||||
|
||||
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE) :
|
||||
// portno(port_number),
|
||||
protocol(p),
|
||||
is_a_server(0),
|
||||
socketDescriptor(-1),
|
||||
file_des(-1),
|
||||
packet_size(ps),
|
||||
nsending(0),
|
||||
nsent(0),
|
||||
total_sent(0)// sender (client): where to? ip
|
||||
{
|
||||
|
||||
// strcpy(hostname,host_ip_or_name);
|
||||
struct hostent *hostInfo = gethostbyname(host_ip_or_name);
|
||||
if (hostInfo == NULL){
|
||||
cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n";
|
||||
} else {
|
||||
// Set some fields in the serverAddress structure.
|
||||
serverAddress.sin_family = hostInfo->h_addrtype;
|
||||
memcpy((char *) &serverAddress.sin_addr.s_addr,
|
||||
hostInfo->h_addr_list[0], hostInfo->h_length);
|
||||
serverAddress.sin_port = htons(port_number);
|
||||
socketDescriptor=0; //You can use send and recv, //would it work?????
|
||||
}
|
||||
clientAddress_length=sizeof(clientAddress);
|
||||
}
|
||||
|
||||
|
||||
int getProtocol(communicationProtocol p) {
|
||||
switch (p) {
|
||||
case TCP:
|
||||
return SOCK_STREAM;
|
||||
break;
|
||||
case UDP:
|
||||
return SOCK_DGRAM;
|
||||
|
||||
default:
|
||||
cerr << "unknow protocol " << p << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int getProtocol() {return getProtocol(protocol);};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The constructor for a server
|
||||
@short the contructor for a server
|
||||
\param port_number port number to listen to
|
||||
\param p TCP or UDP
|
||||
\param eth interface name or IP address to listen to (if NULL, listen to all interfaces)
|
||||
|
||||
*/
|
||||
|
||||
genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, const char *eth=NULL):
|
||||
//portno(port_number),
|
||||
protocol(p),
|
||||
is_a_server(1),
|
||||
socketDescriptor(-1),
|
||||
file_des(-1),
|
||||
packet_size(ps),
|
||||
nsending(0),
|
||||
nsent(0),
|
||||
total_sent(0)
|
||||
{
|
||||
|
||||
/* // you can specify an IP address: */
|
||||
/* */
|
||||
|
||||
/* // or you can let it automatically select one: */
|
||||
/* myaddr.sin_addr.s_addr = INADDR_ANY; */
|
||||
|
||||
if(serverAddress.sin_port == htons(port_number)){
|
||||
socketDescriptor = -10;
|
||||
return;
|
||||
}
|
||||
|
||||
char ip[20];
|
||||
|
||||
strcpy(ip,"0.0.0.0");
|
||||
clientAddress_length=sizeof(clientAddress);
|
||||
if (eth) {
|
||||
strcpy(ip,nameToIp(string(eth)).c_str());
|
||||
if (string(ip)==string("0.0.0.0"))
|
||||
strcpy(ip,eth);
|
||||
}
|
||||
|
||||
// strcpy(hostname,"localhost"); //needed?!?!?!?
|
||||
|
||||
|
||||
socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp
|
||||
|
||||
if (socketDescriptor < 0) {
|
||||
cerr << "Can not create socket "<<endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Set some fields in the serverAddress structure.
|
||||
serverAddress.sin_family = AF_INET;
|
||||
serverAddress.sin_port = htons(port_number);
|
||||
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
|
||||
if (string(ip)!=string("0.0.0.0")) {
|
||||
if (inet_pton(AF_INET, ip, &(serverAddress.sin_addr)))
|
||||
;
|
||||
else
|
||||
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
}
|
||||
|
||||
|
||||
// reuse port
|
||||
int val=1;
|
||||
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(int)) == -1) {
|
||||
cerr << "setsockopt" << endl;
|
||||
socketDescriptor=-1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//increase buffer size if its udp
|
||||
val = SOCKET_BUFFER_SIZE;
|
||||
if((p == UDP) && (setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVBUF, &val, sizeof(int)) == -1))
|
||||
{
|
||||
cerr << "WARNING:Could not set socket receive buffer size" << endl;
|
||||
//socketDescriptor=-1;
|
||||
//return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||
cerr << "Can not bind socket "<< endl;
|
||||
socketDescriptor=-1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (getProtocol()==SOCK_STREAM)
|
||||
listen(socketDescriptor, DEFAULT_BACKLOG);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The destructor: disconnects and close the socket
|
||||
@short the destructor
|
||||
|
||||
*/
|
||||
~genericSocket(){ \
|
||||
Disconnect();
|
||||
if (socketDescriptor >= 0){ \
|
||||
close(socketDescriptor); \
|
||||
} \
|
||||
file_des=-1; \
|
||||
serverAddress.sin_port=-1; \
|
||||
};
|
||||
|
||||
|
||||
/* /\** @short if client returns hostname for connection */
|
||||
/* \param name string to write the hostname to */
|
||||
/* \returns 0 if client, 1 if server (in this case ignore name return value) */
|
||||
|
||||
/* *\/ */
|
||||
/* int getHostname(char *name){ */
|
||||
/* if (is_a_server==0) { */
|
||||
/* strcpy(name,getHostname().c_str()); */
|
||||
/* } */
|
||||
/* return is_a_server; */
|
||||
/* }; */
|
||||
/* /\** @short if client returns hostname for connection */
|
||||
/* \returns hostname */
|
||||
|
||||
/* *\/ */
|
||||
/* string getHostname(){return string(hostname);}; */
|
||||
|
||||
/* /\** @short returns port number for connection */
|
||||
/* \returns port number */
|
||||
/* *\/ */
|
||||
/* int getPortNumber(){return portno;}; */
|
||||
|
||||
/** @short returns communication protocol
|
||||
\returns TCP or UDP
|
||||
*/
|
||||
int getCommunicationProtocol(){return protocol;};
|
||||
|
||||
|
||||
/** @short returns error status
|
||||
\returns 1 if error
|
||||
*/
|
||||
int getErrorStatus(){if (socketDescriptor==-10) return -10; else if (socketDescriptor<0) return 1; else return 0;};
|
||||
|
||||
|
||||
/** @short etablishes connection; disconnect should always follow
|
||||
\returns 1 if error
|
||||
*/
|
||||
int Connect(){//cout<<"connect"<<endl;
|
||||
|
||||
if(file_des>0) return file_des;
|
||||
if (protocol==UDP) return -1;
|
||||
|
||||
if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection
|
||||
if (socketDescriptor>0) {
|
||||
if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) {
|
||||
cerr << "Error: with server accept, connection refused"<<endl;
|
||||
switch(errno) {
|
||||
case EWOULDBLOCK:
|
||||
printf("ewouldblock eagain\n");
|
||||
break;
|
||||
case EBADF:
|
||||
printf("ebadf\n");
|
||||
break;
|
||||
case ECONNABORTED:
|
||||
printf("econnaborted\n");
|
||||
break;
|
||||
case EFAULT:
|
||||
printf("efault\n");
|
||||
break;
|
||||
case EINTR:
|
||||
printf("eintr\n");
|
||||
break;
|
||||
case EINVAL:
|
||||
printf("einval\n");
|
||||
break;
|
||||
case EMFILE:
|
||||
printf("emfile\n");
|
||||
break;
|
||||
case ENFILE:
|
||||
printf("enfile\n");
|
||||
break;
|
||||
case ENOTSOCK:
|
||||
printf("enotsock\n");
|
||||
break;
|
||||
case EOPNOTSUPP:
|
||||
printf("eOPNOTSUPP\n");
|
||||
break;
|
||||
case ENOBUFS:
|
||||
printf("ENOBUFS\n");
|
||||
break;
|
||||
case ENOMEM:
|
||||
printf("ENOMEM\n");
|
||||
break;
|
||||
case ENOSR:
|
||||
printf("ENOSR\n");
|
||||
break;
|
||||
case EPROTO:
|
||||
printf("EPROTO\n");
|
||||
break;
|
||||
default:
|
||||
printf("unknown error\n");
|
||||
}
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
else{
|
||||
inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN);
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "client connected "<< file_des << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
// file_des = socketDescriptor;
|
||||
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "fd " << file_des << endl;
|
||||
#endif
|
||||
} else {
|
||||
if (socketDescriptor<=0)
|
||||
socketDescriptor = socket(AF_INET, getProtocol(),0);
|
||||
// SetTimeOut(10);
|
||||
if (socketDescriptor < 0){
|
||||
cerr << "Can not create socket "<<endl;
|
||||
file_des = socketDescriptor;
|
||||
} else {
|
||||
|
||||
if(connect(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
|
||||
cerr << "Can not connect to socket "<<endl;
|
||||
file_des = -1;
|
||||
} else{
|
||||
file_des = socketDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return file_des;
|
||||
}
|
||||
|
||||
uint16_t getPortNumber(){
|
||||
return ntohs(serverAddress.sin_port);
|
||||
}
|
||||
|
||||
int getFileDes(){return file_des;};
|
||||
|
||||
int getsocketDescriptor(){return socketDescriptor;};
|
||||
|
||||
/** @short free connection */
|
||||
void Disconnect(){
|
||||
if (protocol==UDP){
|
||||
close(socketDescriptor);
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
else{
|
||||
if(file_des>=0){ //then was open
|
||||
if(is_a_server){
|
||||
close(file_des);
|
||||
}
|
||||
else {
|
||||
close(socketDescriptor);
|
||||
socketDescriptor=-1;
|
||||
}
|
||||
file_des=-1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ShutDownSocket(){
|
||||
while(!shutdown(socketDescriptor, SHUT_RDWR));
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Set the socket timeout ts is in seconds */
|
||||
int SetTimeOut(int ts){
|
||||
|
||||
|
||||
if (ts<=0)
|
||||
return -1;
|
||||
|
||||
//cout << "socketdescriptor "<< socketDescriptor << endl;
|
||||
struct timeval tout;
|
||||
tout.tv_sec = 0;
|
||||
tout.tv_usec = 0;
|
||||
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(struct timeval)) <0)
|
||||
{
|
||||
cerr << "Error in setsockopt SO_RCVTIMEO "<< 0 << endl;
|
||||
}
|
||||
tout.tv_sec = ts;
|
||||
tout.tv_usec = 0;
|
||||
if(::setsockopt(socketDescriptor, SOL_SOCKET, SO_SNDTIMEO, &tout, sizeof(struct timeval)) < 0)
|
||||
{
|
||||
cerr << "Error in setsockopt SO_SNDTIMEO " << ts << endl;
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
int setPacketSize(int i=-1) { if (i>=0) packet_size=i; return packet_size;};
|
||||
|
||||
|
||||
|
||||
static string ipToName(string ip) {
|
||||
struct ifaddrs *addrs, *iap;
|
||||
struct sockaddr_in *sa;
|
||||
char buf[32];
|
||||
|
||||
strcpy(buf,"none");
|
||||
|
||||
getifaddrs(&addrs);
|
||||
for (iap = addrs; iap != NULL; iap = iap->ifa_next) {
|
||||
if (iap->ifa_addr && (iap->ifa_flags & IFF_UP) && iap->ifa_addr->sa_family == AF_INET) {
|
||||
sa = (struct sockaddr_in *)(iap->ifa_addr);
|
||||
inet_ntop(iap->ifa_addr->sa_family, (void *)&(sa->sin_addr), buf, sizeof(buf));
|
||||
if (ip==string(buf)) {
|
||||
//printf("%s\n", iap->ifa_name);
|
||||
strcpy(buf,iap->ifa_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
freeifaddrs(addrs);
|
||||
return string(buf);
|
||||
};
|
||||
|
||||
static string nameToMac(string inf) {
|
||||
struct ifreq ifr;
|
||||
int sock, j, k;
|
||||
char mac[32];
|
||||
|
||||
sock=getSock(inf,&ifr);
|
||||
|
||||
if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
|
||||
perror("ioctl(SIOCGIFHWADDR) ");
|
||||
return string("00:00:00:00:00:00");
|
||||
}
|
||||
for (j=0, k=0; j<6; j++) {
|
||||
k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
|
||||
(int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
|
||||
}
|
||||
mac[sizeof(mac)-1]='\0';
|
||||
|
||||
return string(mac);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
static string nameToIp(string inf){
|
||||
struct ifreq ifr;
|
||||
int sock;
|
||||
char *p, addr[32];
|
||||
|
||||
sock=getSock(inf,&ifr);
|
||||
|
||||
if (-1==ioctl(sock, SIOCGIFADDR, &ifr)) {
|
||||
perror("ioctl(SIOCGIFADDR) ");
|
||||
return string("0.0.0.0");
|
||||
}
|
||||
p=inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr);
|
||||
strncpy(addr,p,sizeof(addr)-1);
|
||||
addr[sizeof(addr)-1]='\0';
|
||||
|
||||
return string(addr);
|
||||
|
||||
};
|
||||
|
||||
static int getSock(string inf, struct ifreq *ifr) {
|
||||
|
||||
int sock;
|
||||
sock=socket(PF_INET, SOCK_STREAM, 0);
|
||||
if (-1==sock) {
|
||||
perror("socket() ");
|
||||
return 1;
|
||||
}
|
||||
strncpy(ifr->ifr_name,inf.c_str(),sizeof(ifr->ifr_name)-1);
|
||||
ifr->ifr_name[sizeof(ifr->ifr_name)-1]='\0';
|
||||
|
||||
return sock;
|
||||
|
||||
};
|
||||
|
||||
|
||||
int ReceiveDataOnly(void* buf,int length=0){
|
||||
|
||||
|
||||
if (buf==NULL) return -1;
|
||||
|
||||
|
||||
total_sent=0;
|
||||
|
||||
switch(protocol) {
|
||||
case TCP:
|
||||
if (file_des<0) return -1;
|
||||
while(length>0){
|
||||
nsending = (length>packet_size) ? packet_size:length;
|
||||
nsent = read(file_des,(char*)buf+total_sent,nsending);
|
||||
if(!nsent) break;
|
||||
length-=nsent;
|
||||
total_sent+=nsent;
|
||||
}
|
||||
break;
|
||||
case UDP:
|
||||
if (socketDescriptor<0) return -1;
|
||||
//if length given, listens to length, else listens for packetsize till length is reached
|
||||
if(length){
|
||||
while(length>0){
|
||||
nsending = (length>packet_size) ? packet_size:length;
|
||||
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
|
||||
if(!nsent) break;
|
||||
length-=nsent;
|
||||
total_sent+=nsent;
|
||||
}
|
||||
}
|
||||
//listens to only 1 packet
|
||||
else{
|
||||
//normal
|
||||
nsending=packet_size;
|
||||
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
|
||||
total_sent+=nsent;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "sent "<< total_sent << " Bytes" << endl;
|
||||
#endif
|
||||
if (total_sent>0)
|
||||
strcpy(thisClientIP,dummyClientIP);
|
||||
|
||||
if (strcmp(lastClientIP,thisClientIP))
|
||||
differentClients=1;
|
||||
else
|
||||
differentClients=0;
|
||||
|
||||
return total_sent;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SendDataOnly(void *buf, int length) {
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "want to send "<< length << " Bytes" << endl;
|
||||
#endif
|
||||
if (buf==NULL) return -1;
|
||||
|
||||
total_sent=0;
|
||||
|
||||
|
||||
switch(protocol) {
|
||||
case TCP:
|
||||
if (file_des<0) return -1;
|
||||
while(length>0){
|
||||
nsending = (length>packet_size) ? packet_size:length;
|
||||
nsent = write(file_des,(char*)buf+total_sent,nsending);
|
||||
if(!nsent) break;
|
||||
length-=nsent;
|
||||
total_sent+=nsent;
|
||||
}
|
||||
break;
|
||||
case UDP:
|
||||
if (socketDescriptor<0) return -1;
|
||||
while(length>0){
|
||||
nsending = (length>packet_size) ? packet_size:length;
|
||||
nsent = sendto(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, clientAddress_length);
|
||||
if(!nsent) break;
|
||||
length-=nsent;
|
||||
total_sent+=nsent;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
#ifdef VERY_VERBOSE
|
||||
cout << "sent "<< total_sent << " Bytes" << endl;
|
||||
#endif
|
||||
return total_sent;
|
||||
|
||||
|
||||
}
|
||||
|
||||
char lastClientIP[INET_ADDRSTRLEN];
|
||||
char thisClientIP[INET_ADDRSTRLEN];
|
||||
int differentClients;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
communicationProtocol protocol;
|
||||
|
||||
|
||||
|
||||
int is_a_server;
|
||||
|
||||
|
||||
int socketDescriptor;
|
||||
int file_des;
|
||||
|
||||
int packet_size;
|
||||
|
||||
struct sockaddr_in clientAddress, serverAddress;
|
||||
socklen_t clientAddress_length;
|
||||
|
||||
|
||||
char dummyClientIP[INET_ADDRSTRLEN];
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int nsending;
|
||||
int nsent;
|
||||
int total_sent;
|
||||
|
||||
|
||||
|
||||
// pthread_mutex_t mp;
|
||||
};
|
||||
#endif
|
||||
11
slsReceiverSoftware/include/gitInfoReceiver.h
Normal file
11
slsReceiverSoftware/include/gitInfoReceiver.h
Normal file
@@ -0,0 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL "git@gitorious.psi.ch:sls_det_software/sls_receiver_software.git"
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID "1c259aeba8b068b9f6e550d63a9a3a14bd7d3ab7"
|
||||
//#define SVNREV 0x6
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH "Maliakal_Dhanya"
|
||||
#define SVNREV 0x6
|
||||
#define SVNDATE 0x20140603
|
||||
//
|
||||
11
slsReceiverSoftware/include/gitInfoReceiverTmp.h
Normal file
11
slsReceiverSoftware/include/gitInfoReceiverTmp.h
Normal file
@@ -0,0 +1,11 @@
|
||||
//#define SVNPATH ""
|
||||
#define SVNURL ""
|
||||
//#define SVNREPPATH ""
|
||||
#define SVNREPUUID ""
|
||||
//#define SVNREV ""
|
||||
//#define SVNKIND ""
|
||||
//#define SVNSCHED ""
|
||||
#define SVNAUTH ""
|
||||
#define SVNREV ""
|
||||
#define SVNDATE ""
|
||||
//
|
||||
181
slsReceiverSoftware/include/logger.h
Normal file
181
slsReceiverSoftware/include/logger.h
Normal file
@@ -0,0 +1,181 @@
|
||||
//#ifndef __LOG_H__
|
||||
//#define __LOG_H__
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
inline std::string NowTime();
|
||||
|
||||
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
|
||||
|
||||
template <typename T> class Log{
|
||||
public:
|
||||
Log();
|
||||
virtual ~Log();
|
||||
std::ostringstream& Get(TLogLevel level = logINFO);
|
||||
static TLogLevel& ReportingLevel();
|
||||
static std::string ToString(TLogLevel level);
|
||||
static TLogLevel FromString(const std::string& level);
|
||||
protected:
|
||||
std::ostringstream os;
|
||||
private:
|
||||
Log(const Log&);
|
||||
Log& operator =(const Log&);
|
||||
};
|
||||
|
||||
|
||||
class Output2FILE {
|
||||
public:
|
||||
static FILE*& Stream();
|
||||
static void Output(const std::string& msg);
|
||||
};
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
# elif defined (USING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllimport)
|
||||
# else
|
||||
# define FILELOG_DECLSPEC
|
||||
# endif // BUILDING_DBSIMPLE_DLL
|
||||
#else
|
||||
# define FILELOG_DECLSPEC
|
||||
#endif // _WIN32
|
||||
|
||||
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
|
||||
//typedef Log<Output2FILE> FILELog;
|
||||
|
||||
#ifndef FILELOG_MAX_LEVEL
|
||||
#define FILELOG_MAX_LEVEL logDEBUG4
|
||||
#endif
|
||||
|
||||
#define FILE_LOG(level) \
|
||||
if (level > FILELOG_MAX_LEVEL) ; \
|
||||
else if (level > FILELog::ReportingLevel() || !Output2FILE::Stream()) ; \
|
||||
else FILELog().Get(level)
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
inline std::string NowTime()
|
||||
|
||||
{
|
||||
const int MAX_LEN = 200;
|
||||
char buffer[MAX_LEN];
|
||||
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
|
||||
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
|
||||
return "Error in NowTime()";
|
||||
|
||||
char result[100] = {0};
|
||||
static DWORD first = GetTickCount();
|
||||
sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
inline std::string NowTime()
|
||||
{
|
||||
char buffer[11];
|
||||
time_t t;
|
||||
time(&t);
|
||||
tm r = {0};
|
||||
strftime(buffer, sizeof(buffer), "%X", localtime_r(&t, &r));
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
char result[100] = {0};
|
||||
sprintf(result, "%s.%03ld", buffer, (long)tv.tv_usec / 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif //WIN32
|
||||
|
||||
|
||||
template <typename T> Log<T>::Log(){}
|
||||
|
||||
template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
{
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level) << ": ";
|
||||
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename T> Log<T>::~Log()
|
||||
{
|
||||
os << std::endl;
|
||||
T::Output(os.str());
|
||||
}
|
||||
|
||||
template <typename T> TLogLevel& Log<T>::ReportingLevel()
|
||||
{
|
||||
static TLogLevel reportingLevel = logDEBUG4;
|
||||
return reportingLevel;
|
||||
}
|
||||
|
||||
template <typename T> std::string Log<T>::ToString(TLogLevel level)
|
||||
{
|
||||
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"};
|
||||
return buffer[level];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
TLogLevel Log<T>::FromString(const std::string& level)
|
||||
{
|
||||
if (level == "DEBUG4")
|
||||
return logDEBUG4;
|
||||
if (level == "DEBUG3")
|
||||
return logDEBUG3;
|
||||
if (level == "DEBUG2")
|
||||
return logDEBUG2;
|
||||
if (level == "DEBUG1")
|
||||
return logDEBUG1;
|
||||
if (level == "DEBUG")
|
||||
return logDEBUG;
|
||||
if (level == "INFO")
|
||||
return logINFO;
|
||||
if (level == "WARNING")
|
||||
return logWARNING;
|
||||
if (level == "ERROR")
|
||||
return logERROR;
|
||||
Log<T>().Get(logWARNING) << "Unknown logging level '" << level << "'. Using INFO level as default.";
|
||||
return logINFO;
|
||||
}
|
||||
|
||||
|
||||
inline FILE*& Output2FILE::Stream()
|
||||
{
|
||||
static FILE* pStream = stderr;
|
||||
return pStream;
|
||||
}
|
||||
|
||||
inline void Output2FILE::Output(const std::string& msg)
|
||||
{
|
||||
FILE* pStream = Stream();
|
||||
if (!pStream)
|
||||
return;
|
||||
fprintf(pStream, "%s", msg.c_str());
|
||||
fflush(pStream);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
# elif defined (USING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllimport)
|
||||
# else
|
||||
# define FILELOG_DECLSPEC
|
||||
# endif // BUILDING_DBSIMPLE_DLL
|
||||
#else
|
||||
# define FILELOG_DECLSPEC
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
//#endif //__LOG_H__
|
||||
97
slsReceiverSoftware/include/receiver_defs.h
Executable file
97
slsReceiverSoftware/include/receiver_defs.h
Executable file
@@ -0,0 +1,97 @@
|
||||
#ifndef RECEIVER_DEFS_H
|
||||
#define RECEIVER_DEFS_H
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define GOODBYE -200
|
||||
|
||||
#define DO_NOTHING 0
|
||||
#define CREATE_FILES 1
|
||||
#define DO_EVERYTHING 2
|
||||
|
||||
#define BUF_SIZE (16*1024*1024) //16mb
|
||||
#define SAMPLE_TIME_IN_NS 100000000//100ms
|
||||
#define MAX_JOBS_PER_THREAD 1000
|
||||
#define HEADER_SIZE_NUM_TOT_PACKETS 2
|
||||
#define HEADER_SIZE_NUM_FRAMES 2
|
||||
#define HEADER_SIZE_NUM_PACKETS 1
|
||||
|
||||
|
||||
//all max frames defined in sls_receiver_defs.h. 20000 gotthard, 100000 for short gotthard, 1000 for moench, eiger 20000
|
||||
|
||||
|
||||
|
||||
#define GOTTHARD_FIFO_SIZE 25000 //cannot be less than max jobs per thread = 1000
|
||||
/*#define GOTTHARD_ALIGNED_FRAME_SIZE 4096*/
|
||||
#define GOTTHARD_PACKETS_PER_FRAME 2
|
||||
#define GOTTHARD_ONE_PACKET_SIZE 1286
|
||||
#define GOTTHARD_BUFFER_SIZE (GOTTHARD_ONE_PACKET_SIZE*GOTTHARD_PACKETS_PER_FRAME) //1286*2
|
||||
#define GOTTHARD_DATA_BYTES (1280*GOTTHARD_PACKETS_PER_FRAME) //1280*2
|
||||
|
||||
#define GOTTHARD_FRAME_INDEX_MASK 0xFFFFFFFE
|
||||
#define GOTTHARD_FRAME_INDEX_OFFSET 1
|
||||
#define GOTTHARD_PACKET_INDEX_MASK 0x1
|
||||
|
||||
#define GOTTHARD_PIXELS_IN_ROW 1280
|
||||
#define GOTTHARD_PIXELS_IN_COL 1
|
||||
|
||||
|
||||
#define GOTTHARD_SHORT_PACKETS_PER_FRAME 1
|
||||
#define GOTTHARD_SHORT_ONE_PACKET_SIZE 518
|
||||
#define GOTTHARD_SHORT_BUFFER_SIZE 518
|
||||
#define GOTTHARD_SHORT_DATABYTES 512
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_MASK 0xFFFFFFFF
|
||||
#define GOTTHARD_SHORT_FRAME_INDEX_OFFSET 0
|
||||
#define GOTTHARD_SHORT_PACKET_INDEX_MASK 0
|
||||
#define GOTTHARD_SHORT_PIXELS_IN_ROW 256
|
||||
#define GOTTHARD_SHORT_PIXELS_IN_COL 1
|
||||
|
||||
|
||||
|
||||
|
||||
#define MOENCH_FIFO_SIZE 2500 //cannot be less than max jobs per thread = 1000
|
||||
/*#define MOENCH_ALIGNED_FRAME_SIZE 65536*/
|
||||
#define MOENCH_PACKETS_PER_FRAME 40
|
||||
#define MOENCH_ONE_PACKET_SIZE 1286
|
||||
#define MOENCH_BUFFER_SIZE (MOENCH_ONE_PACKET_SIZE*MOENCH_PACKETS_PER_FRAME) //1286*40
|
||||
#define MOENCH_DATA_BYTES (1280*MOENCH_PACKETS_PER_FRAME) //1280*40
|
||||
|
||||
#define MOENCH_FRAME_INDEX_MASK 0xFFFFFF00
|
||||
#define MOENCH_FRAME_INDEX_OFFSET 8
|
||||
#define MOENCH_PACKET_INDEX_MASK 0xFF
|
||||
|
||||
#define MOENCH_BYTES_PER_ADC (40*2)
|
||||
#define MOENCH_PIXELS_IN_ONE_ROW 160
|
||||
#define MOENCH_BYTES_IN_ONE_ROW (MOENCH_PIXELS_IN_ONE_ROW*2)
|
||||
|
||||
|
||||
|
||||
|
||||
#define EIGER_MAX_PORTS 2
|
||||
#define EIGER_HEADER_LENGTH 48
|
||||
|
||||
#define EIGER_FIFO_SIZE 250 //cannot be less than max jobs per thread = 1000
|
||||
/*#define EIGER_ALIGNED_FRAME_SIZE 65536*/
|
||||
#define EIGER_ONE_GIGA_CONSTANT 16
|
||||
#define EIGER_TEN_GIGA_CONSTANT 4
|
||||
//#define EIGER_PACKETS_PER_FRAME_COSTANT (16*EIGER_MAX_PORTS)//*bit mode 4*16=64, 8*16=128, 16*16=256, 32*16=512
|
||||
#define EIGER_ONE_GIGA_ONE_PACKET_SIZE 1040
|
||||
#define EIGER_ONE_GIGA_ONE_DATA_SIZE 1024
|
||||
#define EIGER_TEN_GIGA_ONE_PACKET_SIZE 4112
|
||||
#define EIGER_TEN_GIGA_ONE_DATA_SIZE 4096
|
||||
//#define EIGER_BUFFER_SIZE_CONSTANT (EIGER_ONE_PACKET_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT)//1040*16*2//*bit mode
|
||||
//#define EIGER_DATA_BYTES_CONSTANT (EIGER_ONE_DATA_SIZE*EIGER_PACKETS_PER_FRAME_COSTANT) //1024*16*2//*bit mode
|
||||
|
||||
#define EIGER_FRAME_INDEX_MASK 0xFFFF
|
||||
#define EIGER_FRAME_INDEX_OFFSET 0
|
||||
#define EIGER_PACKET_INDEX_MASK 0x0
|
||||
|
||||
#define EIGER_IMAGE_HEADER_SIZE 48
|
||||
|
||||
#define EIGER_PIXELS_IN_ONE_ROW (256*4)
|
||||
#define EIGER_PIXELS_IN_ONE_COL (256)
|
||||
|
||||
|
||||
#endif
|
||||
119
slsReceiverSoftware/include/sls_receiver_defs.h
Executable file
119
slsReceiverSoftware/include/sls_receiver_defs.h
Executable file
@@ -0,0 +1,119 @@
|
||||
#ifndef SLS_RECEIVER_DEFS_H
|
||||
#define SLS_RECEIVER_DEFS_H
|
||||
|
||||
|
||||
#ifdef __CINT__
|
||||
#define MYROOT
|
||||
#define __cplusplus
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
/** default maximum string length */
|
||||
#define MAX_STR_LENGTH 1000
|
||||
#define MAX_FRAMES_PER_FILE 20000
|
||||
#define SHORT_MAX_FRAMES_PER_FILE 100000
|
||||
#define MOENCH_MAX_FRAMES_PER_FILE 1000
|
||||
#define EIGER_MAX_FRAMES_PER_FILE 20000
|
||||
|
||||
|
||||
/**
|
||||
\file sls_receiver_defs.h
|
||||
This file contains all the basic definitions common to the slsReceiver class
|
||||
and to the server programs running on the receiver
|
||||
* @author Anna Bergamaschi
|
||||
* @version 0.1alpha (any string)
|
||||
* @see slsDetector
|
||||
$Revision: 809 $
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/** @short class containing all the constants and enum definitions */
|
||||
class slsReceiverDefs {
|
||||
public:
|
||||
|
||||
slsReceiverDefs(){};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Type of the detector
|
||||
*/
|
||||
enum detectorType {
|
||||
GET_DETECTOR_TYPE=-1, /**< the detector will return its type */
|
||||
GENERIC, /**< generic sls detector */
|
||||
MYTHEN, /**< mythen */
|
||||
PILATUS, /**< pilatus */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
PICASSO, /**< picasso */
|
||||
AGIPD, /**< agipd */
|
||||
MOENCH /**< moench */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
return values
|
||||
*/
|
||||
enum {
|
||||
OK, /**< function succeeded */
|
||||
FAIL, /**< function failed */
|
||||
FINISHED, /**< acquisition finished */
|
||||
FORCE_UPDATE
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
indexes for the acquisition timers
|
||||
*/
|
||||
enum timerIndex {
|
||||
FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
|
||||
ACQUISITION_TIME, /**< exposure time */
|
||||
FRAME_PERIOD, /**< period between exposures */
|
||||
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
|
||||
GATES_NUMBER, /**< number of gates per frame (in gated mode) */
|
||||
PROBES_NUMBER, /**< number of probe types in pump-probe mode */
|
||||
CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
|
||||
ACTUAL_TIME, /**< Actual time of the detector's internal timer */
|
||||
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
|
||||
|
||||
PROGRESS, /**< fraction of measurement elapsed - only get! */
|
||||
MEASUREMENTS_NUMBER
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
staus mask
|
||||
*/
|
||||
enum runStatus {
|
||||
IDLE, /**< detector ready to start acquisition - no data in memory */
|
||||
ERROR, /**< error i.e. normally fifo full */
|
||||
WAITING, /**< waiting for trigger or gate signal */
|
||||
RUN_FINISHED, /**< acquisition not running but data in memory */
|
||||
TRANSMITTING, /**< acquisition running and data in memory */
|
||||
RUNNING /**< acquisition running, no data in memory */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT
|
||||
#include "sls_receiver_funcs.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
;
|
||||
57
slsReceiverSoftware/include/sls_receiver_funcs.h
Normal file
57
slsReceiverSoftware/include/sls_receiver_funcs.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
@internal
|
||||
function indexes to call on the server
|
||||
All set functions with argument -1 work as get, when possible
|
||||
*/
|
||||
#ifndef SLS_RECEIVER_FUNCS_H
|
||||
#define SLS_RECEIVER_FUNCS_H
|
||||
|
||||
enum {
|
||||
//General functions
|
||||
F_EXEC_RECEIVER_COMMAND=0, /**< command is executed */
|
||||
F_EXIT_RECEIVER, /**< turn off receiver server */
|
||||
F_LOCK_RECEIVER, /**< Locks/Unlocks server communication to the given client */
|
||||
F_GET_LAST_RECEIVER_CLIENT_IP, /**< returns the IP of the client last connected to the receiver */
|
||||
F_SET_RECEIVER_PORT, /**< Changes communication port of the receiver */
|
||||
F_UPDATE_RECEIVER_CLIENT, /**< Returns all the important parameters to update the shared memory of the client */
|
||||
|
||||
// Identification
|
||||
F_GET_RECEIVER_ID, /**< get receiver id of version */
|
||||
F_GET_RECEIVER_TYPE, /**< return receiver type */
|
||||
F_SEND_RECEIVER_DETHOSTNAME, /**< set detector hostname to receiver */
|
||||
|
||||
//network functions
|
||||
F_RECEIVER_SHORT_FRAME, /**< Sets receiver to receive short frames */
|
||||
F_SETUP_RECEIVER_UDP, /**< sets the receiver udp connection and returns receiver mac address */
|
||||
|
||||
//Acquisition setup functions
|
||||
F_SET_RECEIVER_TIMER, /**< set/get timer value */
|
||||
F_SET_RECEIVER_DYNAMIC_RANGE, /**< set/get detector dynamic range */
|
||||
F_READ_RECEIVER_FREQUENCY, /**< sets the frequency of receiver sending frames to gui */
|
||||
|
||||
// Acquisition functions
|
||||
F_GET_RECEIVER_STATUS, /**< gets the status of receiver listening mode */
|
||||
F_START_RECEIVER, /**< starts the receiver listening mode */
|
||||
F_STOP_RECEIVER, /**< stops the receiver listening mode */
|
||||
F_START_RECEIVER_READOUT, /**< acquisition has stopped. start remaining readout in receiver */
|
||||
F_READ_RECEIVER_FRAME, /**< read one frame to gui*/
|
||||
|
||||
//file functions
|
||||
F_SET_RECEIVER_FILE_PATH, /**< sets receiver file directory */
|
||||
F_SET_RECEIVER_FILE_NAME, /**< sets receiver file name */
|
||||
F_SET_RECEIVER_FILE_INDEX, /**< sets receiver file index */
|
||||
F_SET_RECEIVER_FRAME_INDEX, /**< sets the receiver frame index */
|
||||
F_GET_RECEIVER_FRAME_INDEX, /**< gets the receiver frame index */
|
||||
F_GET_RECEIVER_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */
|
||||
F_RESET_RECEIVER_FRAMES_CAUGHT, /**< resets the frames caught by receiver */
|
||||
F_ENABLE_RECEIVER_FILE_WRITE, /**< sets the receiver file write */
|
||||
F_ENABLE_RECEIVER_COMPRESSION, /**< enable compression in receiver */
|
||||
F_ENABLE_RECEIVER_OVERWRITE, /**< set overwrite flag in receiver */
|
||||
|
||||
F_ENABLE_RECEIVER_TEN_GIGA /**< enable 10Gbe in receiver */
|
||||
|
||||
/* Always append functions hereafter!!! */
|
||||
};
|
||||
|
||||
#endif
|
||||
/** @endinternal */
|
||||
13
slsReceiverSoftware/include/utilities.h
Normal file
13
slsReceiverSoftware/include/utilities.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
#include "sls_receiver_defs.h"
|
||||
|
||||
/* uncomment next line to enable debug output */
|
||||
//#define EIGER_DEBUG
|
||||
|
||||
|
||||
int read_config_file(string fname, int *tcpip_port_no);
|
||||
|
||||
Reference in New Issue
Block a user