mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-24 23:30:03 +02:00
the gotthard receiver works for short frames, gui commented out for now
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@444 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
parent
7d96d8b3af
commit
22bd638f64
@ -72,6 +72,7 @@ class sockaddr_in;
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_PACKET_SIZE 1286
|
||||
#define DEFAULT_PACKETS_PER_FRAME 2
|
||||
#define DEFAULT_PORTNO 1952
|
||||
#define DEFAULT_BACKLOG 5
|
||||
#define DEFAULT_UDP_PORTNO 50001
|
||||
@ -89,9 +90,9 @@ enum communicationProtocol{
|
||||
};
|
||||
|
||||
|
||||
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p) :
|
||||
genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME) :
|
||||
// portno(port_number),
|
||||
protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFAULT_PACKET_SIZE)// sender (client): where to? ip
|
||||
protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(ps),packets_per_frame(t)// sender (client): where to? ip
|
||||
{
|
||||
|
||||
// strcpy(hostname,host_ip_or_name);
|
||||
@ -138,9 +139,9 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA
|
||||
|
||||
*/
|
||||
|
||||
genericSocket(unsigned short int const port_number, communicationProtocol p, const char *eth=NULL):
|
||||
genericSocket(unsigned short int const port_number, communicationProtocol p, int ps = DEFAULT_PACKET_SIZE, int t = DEFAULT_PACKETS_PER_FRAME, const char *eth=NULL):
|
||||
//portno(port_number),
|
||||
protocol(p), is_a_server(1),socketDescriptor(-1), file_des(-1), packet_size(DEFAULT_PACKET_SIZE){
|
||||
protocol(p), is_a_server(1),socketDescriptor(-1), file_des(-1), packet_size(ps), packets_per_frame(t){
|
||||
|
||||
/* // you can specify an IP address: */
|
||||
/* */
|
||||
@ -521,7 +522,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA
|
||||
case UDP:
|
||||
if (socketDescriptor<0) return -1;
|
||||
// while(length>0){
|
||||
for(int i=0;i<2;i++){
|
||||
for(int i=0;i<packets_per_frame;i++){
|
||||
nsending=packet_size;
|
||||
//nsending = (length>packet_size) ? packet_size:length;
|
||||
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_length);
|
||||
@ -625,6 +626,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA
|
||||
int nsending;
|
||||
int nsent;
|
||||
int total_sent;
|
||||
int packets_per_frame;
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,9 @@ typedef float dacs_t;
|
||||
#define DEFAULT_DET_MAC "00:aa:bb:cc:dd:ee"
|
||||
#define DEFAULT_DET_IP "129.129.202.46"
|
||||
|
||||
#define MAX_FRAMES_PER_FILE 20000
|
||||
#define SHORT_MAX_FRAMES_PER_FILE 100000
|
||||
|
||||
/**
|
||||
\file sls_detector_defs.h
|
||||
This file contains all the basic definitions common to the slsDetector class
|
||||
@ -518,10 +521,10 @@ enum angleConversionParameter {
|
||||
|
||||
|
||||
/** Error flags */
|
||||
#define NUM_ERROR_FLAGS=32
|
||||
#define NUM_ERROR_FLAGS 32
|
||||
#define CANNOT_CONNECT_TO_DETECTOR 0x80000000
|
||||
#define CANNOT_CONNECT_TO_RECEIVER 0x40000000
|
||||
#define COULD_NOT_CONFIGURE_MAC 0x00008000 //cant seem to get this error
|
||||
#define COULD_NOT_CONFIGURE_MAC 0x00008000
|
||||
|
||||
|
||||
//typedef struct {
|
||||
|
@ -244,26 +244,26 @@ int cleanFifo(){
|
||||
printf("\nCleaning FIFO\n");
|
||||
addr=ADC_SYNC_REG;
|
||||
|
||||
//88322114
|
||||
//88332214
|
||||
if (ROI_flag==0) {
|
||||
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY;
|
||||
bus_w(addr,val);
|
||||
//88022114
|
||||
//88032214
|
||||
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY;
|
||||
bus_w(addr,val);
|
||||
}
|
||||
else {
|
||||
//1b322114
|
||||
//1b332214
|
||||
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI;
|
||||
bus_w(addr,val);
|
||||
//1b022114
|
||||
//1b032214
|
||||
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY_ROI;
|
||||
|
||||
bus_w(addr,val);
|
||||
|
||||
}
|
||||
reg=bus_r(addr);
|
||||
//#ifdef DDEBUG
|
||||
printf("\n***ADC SYNC reg:%x****\n",reg);
|
||||
printf("ADC SYNC reg 0x19:%x\n",reg);
|
||||
//#endif
|
||||
return OK;
|
||||
}
|
||||
@ -290,11 +290,9 @@ int setDAQRegister(int adcval)
|
||||
reg=bus_r(addr);
|
||||
bus_w(addr,val);
|
||||
reg=bus_r(addr);
|
||||
#ifdef VERBOSE
|
||||
printf("DAQ reg:%x\n",reg);
|
||||
#endif
|
||||
|
||||
cleanFifo();
|
||||
//#ifdef VERBOSE
|
||||
printf("DAQ reg 0x15:%x\n",reg);
|
||||
//#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -1182,11 +1180,11 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
||||
//update adc configured
|
||||
adcConfigured = adc;
|
||||
|
||||
printf("configuring with adc:%d\n",adc);
|
||||
//setting adc mask
|
||||
int reg;
|
||||
int udpPacketSize=0x050E;
|
||||
int ipPacketSize=0x0522;
|
||||
|
||||
switch(adc){
|
||||
case 0:
|
||||
case 1:
|
||||
@ -1196,6 +1194,7 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
||||
ROI_flag=1;
|
||||
//setting daqregister
|
||||
setDAQRegister(adc);
|
||||
cleanFifo();
|
||||
reg = (NCHAN*2)<<CHANNEL_OFFSET;
|
||||
reg&=CHANNEL_MASK;
|
||||
int mask =1<<adc;
|
||||
@ -1206,10 +1205,12 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
||||
break;
|
||||
//for all adcs
|
||||
default:
|
||||
adc=-1;
|
||||
adcConfigured=-1;
|
||||
ROI_flag=0;
|
||||
//setting daqregister
|
||||
setDAQRegister(adc);
|
||||
cleanFifo();
|
||||
reg = (NCHAN*NCHIP)<<CHANNEL_OFFSET;
|
||||
reg&=CHANNEL_MASK;
|
||||
reg|=ACTIVE_ADC_MASK;
|
||||
@ -1440,10 +1441,11 @@ u_int32_t runState(void) {
|
||||
// State Machine
|
||||
|
||||
int startStateMachine(){
|
||||
cleanFifo();
|
||||
|
||||
//#ifdef VERBOSE
|
||||
printf("Starting State Machine\n");
|
||||
printf("*******Starting State Machine***************\n");
|
||||
//#endif
|
||||
cleanFifo();
|
||||
// fifoReset(); printf("Starting State Machine\n");
|
||||
now_ptr=(char*)ram_values;
|
||||
#ifdef SHAREDMEMORY
|
||||
|
@ -78,6 +78,7 @@ int init_detector( int b) {
|
||||
|
||||
prepareADC();
|
||||
setDAQRegister(-1);
|
||||
cleanFifo();
|
||||
setSettings(GET_SETTINGS,-1);
|
||||
//Initialization
|
||||
setFrames(1);
|
||||
@ -2604,7 +2605,8 @@ int configure_mac(int file_des) {
|
||||
if (ret==OK){
|
||||
if(runBusy()){
|
||||
ret=stopStateMachine();
|
||||
strcpy(mess,"could not stop detector acquisition to configure mac");
|
||||
if(ret==FAIL)
|
||||
strcpy(mess,"could not stop detector acquisition to configure mac");
|
||||
}
|
||||
|
||||
if(ret==OK)
|
||||
@ -2614,6 +2616,8 @@ int configure_mac(int file_des) {
|
||||
#endif
|
||||
if (ret==FAIL)
|
||||
printf("configuring MAC of mod %d failed\n", imod);
|
||||
else
|
||||
printf("Configuremac successful of mod %d and adc %d\n",imod,retval);
|
||||
|
||||
if (differentClients)
|
||||
ret=FORCE_UPDATE;
|
||||
|
@ -691,7 +691,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
||||
fileIndex=parentDet->fileIndex;
|
||||
framesPerFile=parentDet->framesPerFile;
|
||||
if(thisDetector->myDetectorType==GOTTHARD)
|
||||
setFramesPerFile(20000);
|
||||
setFramesPerFile(MAX_FRAMES_PER_FILE);
|
||||
|
||||
thisReceiver = new receiverInterface(dataSocket);
|
||||
|
||||
@ -4548,6 +4548,9 @@ char* slsDetector::setDetectorIP(string detectorIP){
|
||||
|
||||
char* slsDetector::setReceiver(string receiverIP){
|
||||
|
||||
if(getRunStatus()==RUNNING)
|
||||
stopAcquisition();
|
||||
|
||||
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
|
||||
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
@ -4655,8 +4658,8 @@ int slsDetector::setUDPConnection(){
|
||||
if(ret==FORCE_UPDATE)
|
||||
updateReceiver();
|
||||
|
||||
//configure detector with udp details
|
||||
if(configureMAC()==FAIL){
|
||||
//configure detector with udp details, -100 is so it doesnt overwrite the previous value
|
||||
if(configureMAC(-1)==FAIL){
|
||||
setReceiverOnline(OFFLINE_FLAG);
|
||||
std::cout << "could not configure mac" << endl;
|
||||
}
|
||||
@ -4671,124 +4674,155 @@ int slsDetector::setUDPConnection(){
|
||||
|
||||
|
||||
int slsDetector::configureMAC(int adc){
|
||||
int i;
|
||||
int ret=FAIL;
|
||||
int fnum=F_CONFIGURE_MAC;
|
||||
char mess[100];
|
||||
char arg[5][50];
|
||||
char cword[50]="", *pcword;
|
||||
string sword;
|
||||
int i;
|
||||
int ret=FAIL;
|
||||
int fnum=F_CONFIGURE_MAC;
|
||||
char mess[100];
|
||||
char arg[5][50];
|
||||
char cword[50]="", *pcword;
|
||||
string sword;
|
||||
int shortframe=1;
|
||||
int retval=-100;
|
||||
|
||||
//if udpip wasnt initialized in config file
|
||||
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
|
||||
//hostname is an ip address
|
||||
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
|
||||
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
|
||||
//if hostname not ip, convert it to ip
|
||||
else{
|
||||
struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
|
||||
if (he != NULL)
|
||||
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
|
||||
else{
|
||||
std::cout << "no rx_udpip given and invalid receiver hostname" << endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
strcpy(arg[0],thisDetector->receiverUDPIP);
|
||||
strcpy(arg[1],thisDetector->receiverUDPMAC);
|
||||
sprintf(arg[2],"%x",thisDetector->receiverUDPPort);
|
||||
strcpy(arg[3],thisDetector->detectorMAC);
|
||||
strcpy(arg[4],thisDetector->detectorIP);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Configuring MAC with adc:"<< adc << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
for(i=0;i<2;i++){
|
||||
if(!strcmp(arg[i],"none")){
|
||||
std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "IP/MAC Addresses valid "<< std::endl;
|
||||
#endif
|
||||
|
||||
//converting IPaddress to hex.
|
||||
pcword = strtok (arg[0],".");
|
||||
while (pcword != NULL) {
|
||||
sprintf(arg[0],"%02x",atoi(pcword));
|
||||
strcat(cword,arg[0]);
|
||||
pcword = strtok (NULL, ".");
|
||||
}
|
||||
strcpy(arg[0],cword);
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting MACaddress to hex.
|
||||
sword.assign(arg[1]);
|
||||
strcpy(arg[1],"");
|
||||
stringstream sstr(sword);
|
||||
while(getline(sstr,sword,':'))
|
||||
strcat(arg[1],sword.c_str());
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl;
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver udp port:"<<arg[2]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting server MACaddress to hex.
|
||||
sword.assign(arg[3]);
|
||||
strcpy(arg[3],"");
|
||||
stringstream ssstr(sword);
|
||||
while(getline(ssstr,sword,':'))
|
||||
strcat(arg[3],sword.c_str());
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting IPaddress to hex.
|
||||
strcpy(cword,"");
|
||||
pcword = strtok (arg[4],".");
|
||||
while (pcword != NULL) {
|
||||
sprintf(arg[4],"%02x",atoi(pcword));
|
||||
strcat(cword,arg[4]);
|
||||
pcword = strtok (NULL, ".");
|
||||
}
|
||||
strcpy(arg[4],cword);
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
|
||||
#endif
|
||||
|
||||
//send to server
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
if (controlSocket->Connect()>=0) {
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(arg,sizeof(arg));
|
||||
controlSocket->SendDataOnly(&adc,sizeof(adc));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL){
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
if(((adc>=-1)&&(adc<=4))||(adc==-100));
|
||||
else{
|
||||
std::cout << "configure mac failed.\nConfigure [adc]; adc should be -1, 0, 1, 2, 3 or 4" << endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
return FAIL;
|
||||
}
|
||||
controlSocket->Disconnect();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret==FAIL) {
|
||||
std::cout<< "Configuring MAC failed " << std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
}
|
||||
return ret;
|
||||
//if udpip wasnt initialized in config file
|
||||
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
|
||||
//hostname is an ip address
|
||||
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
|
||||
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
|
||||
//if hostname not ip, convert it to ip
|
||||
else{
|
||||
struct hostent *he = gethostbyname(thisDetector->receiver_hostname);
|
||||
if (he != NULL)
|
||||
strcpy(thisDetector->receiverUDPIP,inet_ntoa(*(struct in_addr*)he->h_addr));
|
||||
else{
|
||||
std::cout << "configure mac failed. no rx_udpip given and invalid receiver hostname" << endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
strcpy(arg[0],thisDetector->receiverUDPIP);
|
||||
strcpy(arg[1],thisDetector->receiverUDPMAC);
|
||||
sprintf(arg[2],"%x",thisDetector->receiverUDPPort);
|
||||
strcpy(arg[3],thisDetector->detectorMAC);
|
||||
strcpy(arg[4],thisDetector->detectorIP);
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Configuring MAC with adc:"<< adc << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
for(i=0;i<2;i++){
|
||||
if(!strcmp(arg[i],"none")){
|
||||
std::cout<< "Configure MAC Error. IP/MAC Addresses not set"<< std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "IP/MAC Addresses valid "<< std::endl;
|
||||
#endif
|
||||
|
||||
//converting IPaddress to hex.
|
||||
pcword = strtok (arg[0],".");
|
||||
while (pcword != NULL) {
|
||||
sprintf(arg[0],"%02x",atoi(pcword));
|
||||
strcat(cword,arg[0]);
|
||||
pcword = strtok (NULL, ".");
|
||||
}
|
||||
strcpy(arg[0],cword);
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver udp ip:"<<arg[0]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting MACaddress to hex.
|
||||
sword.assign(arg[1]);
|
||||
strcpy(arg[1],"");
|
||||
stringstream sstr(sword);
|
||||
while(getline(sstr,sword,':'))
|
||||
strcat(arg[1],sword.c_str());
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver mac:"<<arg[1]<<"."<<std::endl;
|
||||
#endif
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"receiver udp port:"<<arg[2]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting server MACaddress to hex.
|
||||
sword.assign(arg[3]);
|
||||
strcpy(arg[3],"");
|
||||
stringstream ssstr(sword);
|
||||
while(getline(ssstr,sword,':'))
|
||||
strcat(arg[3],sword.c_str());
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"detecotor mac:"<<arg[3]<<"."<<std::endl;
|
||||
#endif
|
||||
//converting IPaddress to hex.
|
||||
strcpy(cword,"");
|
||||
pcword = strtok (arg[4],".");
|
||||
while (pcword != NULL) {
|
||||
sprintf(arg[4],"%02x",atoi(pcword));
|
||||
strcat(cword,arg[4]);
|
||||
pcword = strtok (NULL, ".");
|
||||
}
|
||||
strcpy(arg[4],cword);
|
||||
#ifdef VERBOSE
|
||||
std::cout<<"detector ip:"<<arg[4]<<"."<<std::endl;
|
||||
#endif
|
||||
|
||||
//send to server
|
||||
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||
if (controlSocket) {
|
||||
if (controlSocket->Connect()>=0) {
|
||||
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
controlSocket->SendDataOnly(arg,sizeof(arg));
|
||||
controlSocket->SendDataOnly(&adc,sizeof(adc));
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret==FAIL){
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
}
|
||||
else
|
||||
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||
controlSocket->Disconnect();
|
||||
if (ret==FORCE_UPDATE)
|
||||
updateDetector();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret==FAIL) {
|
||||
ret=FAIL;
|
||||
std::cout<< "Configuring MAC failed " << std::endl;
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
}
|
||||
else{
|
||||
//set frames per file
|
||||
if(retval==-1)
|
||||
setFramesPerFile(MAX_FRAMES_PER_FILE);
|
||||
else
|
||||
setFramesPerFile(SHORT_MAX_FRAMES_PER_FILE);
|
||||
//connect to receiver
|
||||
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
|
||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||
if(retval==-1) shortframe=0;
|
||||
#ifdef VERBOSE
|
||||
std::cout << "Sending shortframe to receiver " << shortframe << std::endl;
|
||||
#endif
|
||||
ret=thisReceiver->sendInt(fnum,retval,shortframe);
|
||||
if(ret==FAIL)
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -393,6 +393,11 @@ void* postProcessing::processData(int delflag) {
|
||||
}
|
||||
//receiver
|
||||
else{
|
||||
while(1){
|
||||
if (checkJoinThread()) break;
|
||||
usleep(200000);
|
||||
}
|
||||
/*
|
||||
pthread_mutex_lock(&mg);
|
||||
int prevCaught=getReceiverCurrentFrameIndex();
|
||||
pthread_mutex_unlock(&mg);
|
||||
@ -441,7 +446,7 @@ void* postProcessing::processData(int delflag) {
|
||||
cout<<"****Detector returned mismatched indeices***"<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -93,14 +93,14 @@ int decode_function(int file_des) {
|
||||
printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des);
|
||||
return FAIL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
else
|
||||
printf("size of data received %d\n",n);
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
#ifdef VERBOSE
|
||||
//#ifdef VERBOSE
|
||||
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
|
||||
#endif
|
||||
//#endif
|
||||
if (fnum<0 || fnum>255)
|
||||
fnum=255;
|
||||
retval=(*flist[fnum])(file_des);
|
||||
|
@ -5,13 +5,19 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define GOODBYE -200
|
||||
#define BUFFER_SIZE 1286*2
|
||||
#define SHORT_BUFFER_SIZE 518
|
||||
#define DATABYTES 2560
|
||||
#define FIFO_SIZE 25000
|
||||
#define GOODBYE -200
|
||||
|
||||
#define BUFFER_SIZE 1286*2
|
||||
#define DATA_BYTES 2560
|
||||
#define MAX_FRAMES 20000
|
||||
#define PACKETS_PER_FRAME 2
|
||||
|
||||
#define SHORT_BUFFER_SIZE 518
|
||||
#define SHORT_MAX_FRAMES 100000
|
||||
#define SHORT_PACKETS_PER_FRAME 1
|
||||
|
||||
|
||||
#define FIFO_SIZE 25000
|
||||
|
||||
//#define THIS_SOFTWARE_VERSION 0x20120919
|
||||
#endif
|
||||
|
@ -26,6 +26,7 @@ FILE* slsReceiverFunctionList::sfilefd(NULL);
|
||||
int slsReceiverFunctionList::listening_thread_running(0);
|
||||
|
||||
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
maxFramesPerFile(MAX_FRAMES),
|
||||
enableFileWrite(1),
|
||||
shortFileName(shortfname),
|
||||
shortFileNameIndex(0),
|
||||
@ -43,7 +44,10 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||
latestData(NULL),
|
||||
udpSocket(NULL),
|
||||
server_port(DEFAULT_UDP_PORTNO),
|
||||
fifo(NULL)
|
||||
fifo(NULL),
|
||||
shortFrame(0),
|
||||
bufferSize(BUFFER_SIZE),
|
||||
packetsPerFrame(2)
|
||||
{
|
||||
strcpy(savefilename,"");
|
||||
strcpy(actualfilename,"");
|
||||
@ -73,7 +77,7 @@ int slsReceiverFunctionList::getFrameIndex(){
|
||||
if(startFrameIndex==-1)
|
||||
frameIndex=0;
|
||||
else
|
||||
frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/2;
|
||||
frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/packetsPerFrame;
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
@ -83,7 +87,7 @@ int slsReceiverFunctionList::getAcquisitionIndex(){
|
||||
if(startAcquisitionIndex==-1)
|
||||
acquisitionIndex=0;
|
||||
else
|
||||
acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/2;
|
||||
acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/packetsPerFrame;
|
||||
return acquisitionIndex;
|
||||
}
|
||||
|
||||
@ -104,6 +108,10 @@ char* slsReceiverFunctionList::setFilePath(char c[]){
|
||||
struct stat st;
|
||||
if(stat(c,&st) == 0)
|
||||
strcpy(filePath,c);
|
||||
else{
|
||||
strcpy(filePath,"");
|
||||
cout<<"FilePath does not exist:"<<filePath<<endl;
|
||||
}
|
||||
}
|
||||
return getFilePath();
|
||||
}
|
||||
@ -131,6 +139,8 @@ int slsReceiverFunctionList::startReceiver(){
|
||||
#ifdef VERBOSE
|
||||
cout << "Starting Receiver" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
int err = 0;
|
||||
if(!listening_thread_running){
|
||||
cout << "Starting new acquisition threadddd ...." << endl;
|
||||
@ -232,21 +242,29 @@ int slsReceiverFunctionList::startListening(){
|
||||
// very end of the program.
|
||||
do {
|
||||
|
||||
|
||||
|
||||
if(!strlen(eth)){
|
||||
cout<<"warning:eth is empty.listening to all"<<endl;
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP);
|
||||
}else
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,eth);
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame);
|
||||
}else{
|
||||
cout<<"eth:"<<eth<<endl;
|
||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame,eth);
|
||||
}
|
||||
|
||||
if (udpSocket->getErrorStatus()){
|
||||
#ifdef VERBOSE
|
||||
std::cout<< "Could not create UDP socket "<< server_port << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while (listening_thread_running) {
|
||||
status = RUNNING;
|
||||
|
||||
buffer = new char[BUFFER_SIZE];
|
||||
buffer = new char[bufferSize];
|
||||
//receiver 2 half frames
|
||||
rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer));
|
||||
if( rc < 0)
|
||||
@ -254,7 +272,7 @@ int slsReceiverFunctionList::startListening(){
|
||||
|
||||
//start for each scan
|
||||
if(startFrameIndex==-1){
|
||||
startFrameIndex=(int)(*((int*)buffer))-2;
|
||||
startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame;
|
||||
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
||||
prevframenum=startFrameIndex;
|
||||
}
|
||||
@ -325,7 +343,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
framesCaught=0;
|
||||
frameIndex=0;
|
||||
|
||||
latestData = new char[BUFFER_SIZE];
|
||||
latestData = new char[bufferSize];
|
||||
if(sfilefd) sfilefd=0;
|
||||
|
||||
strcpy(savefilename,"");
|
||||
@ -351,8 +369,8 @@ int slsReceiverFunctionList::startWriting(){
|
||||
|
||||
while(listening_thread_running){
|
||||
|
||||
//when it reaches MAX_FRAMES_PER_FILE,start writing new file
|
||||
if (framesInFile == MAX_FRAMES_PER_FILE) {
|
||||
//when it reaches maxFramesPerFile,start writing new file
|
||||
if (framesInFile == maxFramesPerFile) {
|
||||
|
||||
if(enableFileWrite){
|
||||
fclose(sfilefd);
|
||||
@ -369,7 +387,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
}
|
||||
|
||||
currframenum=(int)(*((int*)latestData));
|
||||
cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(2*framesInFile))/(double)(2*framesInFile))*100.000 << "%\t\t"
|
||||
cout << "packet loss " << fixed << setprecision(4) << ((currframenum-prevframenum-(packetsPerFrame*framesInFile))/(double)(packetsPerFrame*framesInFile))*100.000 << "%\t\t"
|
||||
"framenum " << currframenum << "\t\t"
|
||||
"p " << prevframenum << endl;
|
||||
|
||||
@ -385,7 +403,7 @@ int slsReceiverFunctionList::startWriting(){
|
||||
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
|
||||
framesCaught++;
|
||||
totalFramesCaught++;
|
||||
memcpy(latestData,dataWriteFrame->buffer,BUFFER_SIZE);
|
||||
memcpy(latestData,dataWriteFrame->buffer,bufferSize);
|
||||
//cout<<"list write \t index:"<<(int)(*(int*)latestData)<<endl;
|
||||
if(enableFileWrite)
|
||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
||||
@ -423,5 +441,23 @@ char* slsReceiverFunctionList::readFrame(char* c){
|
||||
}
|
||||
|
||||
|
||||
int slsReceiverFunctionList::setShortFrame(int i){
|
||||
shortFrame=i;
|
||||
|
||||
if(shortFrame){
|
||||
bufferSize = SHORT_BUFFER_SIZE;
|
||||
maxFramesPerFile = SHORT_MAX_FRAMES;
|
||||
packetsPerFrame = 1;
|
||||
|
||||
}else{
|
||||
bufferSize = BUFFER_SIZE;
|
||||
maxFramesPerFile = MAX_FRAMES;
|
||||
packetsPerFrame = 2;
|
||||
}
|
||||
|
||||
return shortFrame;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -170,11 +170,18 @@ public:
|
||||
*/
|
||||
char* readFrame(char* c);
|
||||
|
||||
/**
|
||||
* Set short frame
|
||||
* @param i if shortframe i=1
|
||||
*/
|
||||
int setShortFrame(int i);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static const int MAX_FRAMES_PER_FILE = 20000;
|
||||
/** max frames per file **/
|
||||
int maxFramesPerFile;
|
||||
|
||||
/** File write enable */
|
||||
int enableFileWrite;
|
||||
@ -260,6 +267,15 @@ private:
|
||||
/** circular fifo to read and write data*/
|
||||
CircularFifo<dataStruct,FIFO_SIZE>* fifo;
|
||||
|
||||
/** short frames */
|
||||
int shortFrame;
|
||||
|
||||
/** buffer size can be 1286*2 or 518 */
|
||||
int bufferSize;
|
||||
|
||||
/** number of packets per frame*/
|
||||
int packetsPerFrame;
|
||||
|
||||
public:
|
||||
/** File Descriptor */
|
||||
static FILE *sfilefd;
|
||||
|
@ -22,7 +22,8 @@ int slsReceiverFuncs::socketDescriptor(-1);
|
||||
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname):
|
||||
socket(mySocket),
|
||||
ret(OK),
|
||||
lockStatus(0){
|
||||
lockStatus(0),
|
||||
shortFrame(0){
|
||||
|
||||
int port_no = DEFAULT_PORTNO+2;
|
||||
ifstream infile;
|
||||
@ -128,6 +129,7 @@ int slsReceiverFuncs::function_table(){
|
||||
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
|
||||
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
|
||||
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
|
||||
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
|
||||
|
||||
//General Functions
|
||||
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
||||
@ -475,7 +477,7 @@ int slsReceiverFuncs::start_receiver(){
|
||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(!strlen(slsReceiverList->setFilePath(""))){
|
||||
else if(!strlen(slsReceiverList->getFilePath())){
|
||||
strcpy(mess,"receiver not set up. set receiver ip again.\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
@ -649,11 +651,22 @@ int slsReceiverFuncs::read_frame(){
|
||||
char fName[MAX_STR_LENGTH];
|
||||
int arg = -1;
|
||||
|
||||
int nel = BUFFER_SIZE/(sizeof(int));
|
||||
int onebuffersize = BUFFER_SIZE/2;
|
||||
int onedatasize = DATABYTES/2;
|
||||
int bufferSize = BUFFER_SIZE;
|
||||
int databytes = DATA_BYTES;
|
||||
int packetsPerFrame = PACKETS_PER_FRAME;
|
||||
|
||||
char* raw = new char[BUFFER_SIZE];
|
||||
if(shortFrame){
|
||||
bufferSize = SHORT_BUFFER_SIZE;
|
||||
databytes = SHORT_BUFFER_SIZE;
|
||||
packetsPerFrame = SHORT_PACKETS_PER_FRAME;
|
||||
}
|
||||
|
||||
int nel = bufferSize/(sizeof(int));
|
||||
int onebuffersize = bufferSize/packetsPerFrame;
|
||||
int onedatasize = databytes/packetsPerFrame;
|
||||
|
||||
|
||||
char* raw = new char[bufferSize];
|
||||
int* origVal = new int[nel];
|
||||
int* retval = new int[nel];
|
||||
|
||||
@ -676,7 +689,7 @@ int slsReceiverFuncs::read_frame(){
|
||||
ret=OK;
|
||||
break;
|
||||
}else
|
||||
usleep(1000000);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
|
||||
@ -687,7 +700,7 @@ int slsReceiverFuncs::read_frame(){
|
||||
raw=slsReceiverList->readFrame(fName);
|
||||
index=(int)(*(int*)raw);
|
||||
index2= (int)(*((int*)((char*)(raw+onebuffersize))));
|
||||
memcpy(origVal,raw,BUFFER_SIZE);
|
||||
memcpy(origVal,raw,bufferSize);
|
||||
raw=NULL;
|
||||
//cout<<"funcs\tindex:"<<index<<"\tindex2:"<<index2<<endl;
|
||||
|
||||
@ -748,7 +761,7 @@ int slsReceiverFuncs::read_frame(){
|
||||
else{
|
||||
socket->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
socket->SendDataOnly(&arg,sizeof(arg));
|
||||
socket->SendDataOnly(retval,DATABYTES);
|
||||
socket->SendDataOnly(retval,DATA_BYTES);
|
||||
}
|
||||
//return ok/fail
|
||||
return ret;
|
||||
@ -836,6 +849,55 @@ int slsReceiverFuncs::get_version(){
|
||||
|
||||
|
||||
|
||||
int slsReceiverFuncs::set_short_frame() {
|
||||
ret=OK;
|
||||
int index=0;
|
||||
int retval=-100;
|
||||
strcpy(mess,"Could not set/reset short frame for receiver\n");
|
||||
|
||||
|
||||
// receive arguments
|
||||
if(socket->ReceiveDataOnly(&index,sizeof(index)) < 0 ){
|
||||
strcpy(mess,"Error reading from socket\n");
|
||||
ret = FAIL;
|
||||
}
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_FUNCTION_LIST
|
||||
if (ret==OK) {
|
||||
if (lockStatus==1 && socket->differentClients==1){//necessary???
|
||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||
ret=FAIL;
|
||||
}
|
||||
else if(slsReceiverList->getStatus()==RUNNING){
|
||||
strcpy(mess,"Cannot set short frame while status is running\n");
|
||||
ret=FAIL;
|
||||
}
|
||||
else{
|
||||
retval=slsReceiverList->setShortFrame(index);
|
||||
shortFrame = retval;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(ret==OK && socket->differentClients){
|
||||
cout << "Force update" << endl;
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
socket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL)
|
||||
socket->SendDataOnly(mess,sizeof(mess));
|
||||
socket->SendDataOnly(&retval,sizeof(retval));
|
||||
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -83,6 +83,9 @@ public:
|
||||
/** Get Version */
|
||||
int get_version();
|
||||
|
||||
/** set short frame */
|
||||
int set_short_frame();
|
||||
|
||||
//General Functions
|
||||
/** Locks Receiver */
|
||||
int lock_receiver();
|
||||
@ -130,6 +133,9 @@ private:
|
||||
/** Lock Status if server locked to a client */
|
||||
int lockStatus;
|
||||
|
||||
/** Short frame */
|
||||
int shortFrame;
|
||||
|
||||
static int file_des;
|
||||
static int socketDescriptor;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user