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;
|
using namespace std;
|
||||||
|
|
||||||
#define DEFAULT_PACKET_SIZE 1286
|
#define DEFAULT_PACKET_SIZE 1286
|
||||||
|
#define DEFAULT_PACKETS_PER_FRAME 2
|
||||||
#define DEFAULT_PORTNO 1952
|
#define DEFAULT_PORTNO 1952
|
||||||
#define DEFAULT_BACKLOG 5
|
#define DEFAULT_BACKLOG 5
|
||||||
#define DEFAULT_UDP_PORTNO 50001
|
#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),
|
// 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);
|
// 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),
|
//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: */
|
/* // 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:
|
case UDP:
|
||||||
if (socketDescriptor<0) return -1;
|
if (socketDescriptor<0) return -1;
|
||||||
// while(length>0){
|
// while(length>0){
|
||||||
for(int i=0;i<2;i++){
|
for(int i=0;i<packets_per_frame;i++){
|
||||||
nsending=packet_size;
|
nsending=packet_size;
|
||||||
//nsending = (length>packet_size) ? packet_size:length;
|
//nsending = (length>packet_size) ? packet_size:length;
|
||||||
nsent = recvfrom(socketDescriptor,(char*)buf+total_sent,nsending, 0, (struct sockaddr *) &clientAddress, &clientAddress_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 nsending;
|
||||||
int nsent;
|
int nsent;
|
||||||
int total_sent;
|
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_MAC "00:aa:bb:cc:dd:ee"
|
||||||
#define DEFAULT_DET_IP "129.129.202.46"
|
#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
|
\file sls_detector_defs.h
|
||||||
This file contains all the basic definitions common to the slsDetector class
|
This file contains all the basic definitions common to the slsDetector class
|
||||||
@ -518,10 +521,10 @@ enum angleConversionParameter {
|
|||||||
|
|
||||||
|
|
||||||
/** Error flags */
|
/** Error flags */
|
||||||
#define NUM_ERROR_FLAGS=32
|
#define NUM_ERROR_FLAGS 32
|
||||||
#define CANNOT_CONNECT_TO_DETECTOR 0x80000000
|
#define CANNOT_CONNECT_TO_DETECTOR 0x80000000
|
||||||
#define CANNOT_CONNECT_TO_RECEIVER 0x40000000
|
#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 {
|
//typedef struct {
|
||||||
|
@ -244,26 +244,26 @@ int cleanFifo(){
|
|||||||
printf("\nCleaning FIFO\n");
|
printf("\nCleaning FIFO\n");
|
||||||
addr=ADC_SYNC_REG;
|
addr=ADC_SYNC_REG;
|
||||||
|
|
||||||
//88322114
|
//88332214
|
||||||
if (ROI_flag==0) {
|
if (ROI_flag==0) {
|
||||||
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY;
|
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY;
|
||||||
bus_w(addr,val);
|
bus_w(addr,val);
|
||||||
//88022114
|
//88032214
|
||||||
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY;
|
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY;
|
||||||
bus_w(addr,val);
|
bus_w(addr,val);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//1b322114
|
//1b332214
|
||||||
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI;
|
val=ADCSYNC_VAL | ADCSYNC_CLEAN_FIFO_BITS | TOKEN_RESTART_DELAY_ROI;
|
||||||
bus_w(addr,val);
|
bus_w(addr,val);
|
||||||
//1b022114
|
//1b032214
|
||||||
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY_ROI;
|
val=ADCSYNC_VAL | TOKEN_RESTART_DELAY_ROI;
|
||||||
|
bus_w(addr,val);
|
||||||
|
|
||||||
}
|
}
|
||||||
reg=bus_r(addr);
|
reg=bus_r(addr);
|
||||||
//#ifdef DDEBUG
|
//#ifdef DDEBUG
|
||||||
printf("\n***ADC SYNC reg:%x****\n",reg);
|
printf("ADC SYNC reg 0x19:%x\n",reg);
|
||||||
//#endif
|
//#endif
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -290,11 +290,9 @@ int setDAQRegister(int adcval)
|
|||||||
reg=bus_r(addr);
|
reg=bus_r(addr);
|
||||||
bus_w(addr,val);
|
bus_w(addr,val);
|
||||||
reg=bus_r(addr);
|
reg=bus_r(addr);
|
||||||
#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
printf("DAQ reg:%x\n",reg);
|
printf("DAQ reg 0x15:%x\n",reg);
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
cleanFifo();
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -1182,11 +1180,11 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
|||||||
//update adc configured
|
//update adc configured
|
||||||
adcConfigured = adc;
|
adcConfigured = adc;
|
||||||
|
|
||||||
printf("configuring with adc:%d\n",adc);
|
|
||||||
//setting adc mask
|
//setting adc mask
|
||||||
int reg;
|
int reg;
|
||||||
int udpPacketSize=0x050E;
|
int udpPacketSize=0x050E;
|
||||||
int ipPacketSize=0x0522;
|
int ipPacketSize=0x0522;
|
||||||
|
|
||||||
switch(adc){
|
switch(adc){
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
@ -1196,6 +1194,7 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
|||||||
ROI_flag=1;
|
ROI_flag=1;
|
||||||
//setting daqregister
|
//setting daqregister
|
||||||
setDAQRegister(adc);
|
setDAQRegister(adc);
|
||||||
|
cleanFifo();
|
||||||
reg = (NCHAN*2)<<CHANNEL_OFFSET;
|
reg = (NCHAN*2)<<CHANNEL_OFFSET;
|
||||||
reg&=CHANNEL_MASK;
|
reg&=CHANNEL_MASK;
|
||||||
int mask =1<<adc;
|
int mask =1<<adc;
|
||||||
@ -1206,10 +1205,12 @@ int configureMAC(int ipad,long long int macad,long long int detectormacad, int d
|
|||||||
break;
|
break;
|
||||||
//for all adcs
|
//for all adcs
|
||||||
default:
|
default:
|
||||||
|
adc=-1;
|
||||||
adcConfigured=-1;
|
adcConfigured=-1;
|
||||||
ROI_flag=0;
|
ROI_flag=0;
|
||||||
//setting daqregister
|
//setting daqregister
|
||||||
setDAQRegister(adc);
|
setDAQRegister(adc);
|
||||||
|
cleanFifo();
|
||||||
reg = (NCHAN*NCHIP)<<CHANNEL_OFFSET;
|
reg = (NCHAN*NCHIP)<<CHANNEL_OFFSET;
|
||||||
reg&=CHANNEL_MASK;
|
reg&=CHANNEL_MASK;
|
||||||
reg|=ACTIVE_ADC_MASK;
|
reg|=ACTIVE_ADC_MASK;
|
||||||
@ -1440,10 +1441,11 @@ u_int32_t runState(void) {
|
|||||||
// State Machine
|
// State Machine
|
||||||
|
|
||||||
int startStateMachine(){
|
int startStateMachine(){
|
||||||
cleanFifo();
|
|
||||||
//#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
printf("Starting State Machine\n");
|
printf("*******Starting State Machine***************\n");
|
||||||
//#endif
|
//#endif
|
||||||
|
cleanFifo();
|
||||||
// fifoReset(); printf("Starting State Machine\n");
|
// fifoReset(); printf("Starting State Machine\n");
|
||||||
now_ptr=(char*)ram_values;
|
now_ptr=(char*)ram_values;
|
||||||
#ifdef SHAREDMEMORY
|
#ifdef SHAREDMEMORY
|
||||||
|
@ -78,6 +78,7 @@ int init_detector( int b) {
|
|||||||
|
|
||||||
prepareADC();
|
prepareADC();
|
||||||
setDAQRegister(-1);
|
setDAQRegister(-1);
|
||||||
|
cleanFifo();
|
||||||
setSettings(GET_SETTINGS,-1);
|
setSettings(GET_SETTINGS,-1);
|
||||||
//Initialization
|
//Initialization
|
||||||
setFrames(1);
|
setFrames(1);
|
||||||
@ -2604,7 +2605,8 @@ int configure_mac(int file_des) {
|
|||||||
if (ret==OK){
|
if (ret==OK){
|
||||||
if(runBusy()){
|
if(runBusy()){
|
||||||
ret=stopStateMachine();
|
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)
|
if(ret==OK)
|
||||||
@ -2614,6 +2616,8 @@ int configure_mac(int file_des) {
|
|||||||
#endif
|
#endif
|
||||||
if (ret==FAIL)
|
if (ret==FAIL)
|
||||||
printf("configuring MAC of mod %d failed\n", imod);
|
printf("configuring MAC of mod %d failed\n", imod);
|
||||||
|
else
|
||||||
|
printf("Configuremac successful of mod %d and adc %d\n",imod,retval);
|
||||||
|
|
||||||
if (differentClients)
|
if (differentClients)
|
||||||
ret=FORCE_UPDATE;
|
ret=FORCE_UPDATE;
|
||||||
|
@ -691,7 +691,7 @@ int slsDetector::initializeDetectorSize(detectorType type) {
|
|||||||
fileIndex=parentDet->fileIndex;
|
fileIndex=parentDet->fileIndex;
|
||||||
framesPerFile=parentDet->framesPerFile;
|
framesPerFile=parentDet->framesPerFile;
|
||||||
if(thisDetector->myDetectorType==GOTTHARD)
|
if(thisDetector->myDetectorType==GOTTHARD)
|
||||||
setFramesPerFile(20000);
|
setFramesPerFile(MAX_FRAMES_PER_FILE);
|
||||||
|
|
||||||
thisReceiver = new receiverInterface(dataSocket);
|
thisReceiver = new receiverInterface(dataSocket);
|
||||||
|
|
||||||
@ -4548,6 +4548,9 @@ char* slsDetector::setDetectorIP(string detectorIP){
|
|||||||
|
|
||||||
char* slsDetector::setReceiver(string receiverIP){
|
char* slsDetector::setReceiver(string receiverIP){
|
||||||
|
|
||||||
|
if(getRunStatus()==RUNNING)
|
||||||
|
stopAcquisition();
|
||||||
|
|
||||||
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
|
strcpy(thisDetector->receiver_hostname,receiverIP.c_str());
|
||||||
|
|
||||||
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
if(setReceiverOnline(ONLINE_FLAG)==ONLINE_FLAG){
|
||||||
@ -4655,8 +4658,8 @@ int slsDetector::setUDPConnection(){
|
|||||||
if(ret==FORCE_UPDATE)
|
if(ret==FORCE_UPDATE)
|
||||||
updateReceiver();
|
updateReceiver();
|
||||||
|
|
||||||
//configure detector with udp details
|
//configure detector with udp details, -100 is so it doesnt overwrite the previous value
|
||||||
if(configureMAC()==FAIL){
|
if(configureMAC(-1)==FAIL){
|
||||||
setReceiverOnline(OFFLINE_FLAG);
|
setReceiverOnline(OFFLINE_FLAG);
|
||||||
std::cout << "could not configure mac" << endl;
|
std::cout << "could not configure mac" << endl;
|
||||||
}
|
}
|
||||||
@ -4671,124 +4674,155 @@ int slsDetector::setUDPConnection(){
|
|||||||
|
|
||||||
|
|
||||||
int slsDetector::configureMAC(int adc){
|
int slsDetector::configureMAC(int adc){
|
||||||
int i;
|
int i;
|
||||||
int ret=FAIL;
|
int ret=FAIL;
|
||||||
int fnum=F_CONFIGURE_MAC;
|
int fnum=F_CONFIGURE_MAC;
|
||||||
char mess[100];
|
char mess[100];
|
||||||
char arg[5][50];
|
char arg[5][50];
|
||||||
char cword[50]="", *pcword;
|
char cword[50]="", *pcword;
|
||||||
string sword;
|
string sword;
|
||||||
|
int shortframe=1;
|
||||||
|
int retval=-100;
|
||||||
|
|
||||||
//if udpip wasnt initialized in config file
|
if(((adc>=-1)&&(adc<=4))||(adc==-100));
|
||||||
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
|
else{
|
||||||
//hostname is an ip address
|
std::cout << "configure mac failed.\nConfigure [adc]; adc should be -1, 0, 1, 2, 3 or 4" << endl;
|
||||||
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
|
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
||||||
strcpy(thisDetector->receiverUDPIP,thisDetector->receiver_hostname);
|
return FAIL;
|
||||||
//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));
|
|
||||||
}
|
}
|
||||||
controlSocket->Disconnect();
|
|
||||||
if (ret==FORCE_UPDATE)
|
|
||||||
updateDetector();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret==FAIL) {
|
//if udpip wasnt initialized in config file
|
||||||
std::cout<< "Configuring MAC failed " << std::endl;
|
if(!(strcmp(thisDetector->receiverUDPIP,"none"))){
|
||||||
setErrorMask((getErrorMask())|(COULD_NOT_CONFIGURE_MAC));
|
//hostname is an ip address
|
||||||
}
|
if(strchr(thisDetector->receiver_hostname,'.')!=NULL)
|
||||||
return ret;
|
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
|
//receiver
|
||||||
else{
|
else{
|
||||||
|
while(1){
|
||||||
|
if (checkJoinThread()) break;
|
||||||
|
usleep(200000);
|
||||||
|
}
|
||||||
|
/*
|
||||||
pthread_mutex_lock(&mg);
|
pthread_mutex_lock(&mg);
|
||||||
int prevCaught=getReceiverCurrentFrameIndex();
|
int prevCaught=getReceiverCurrentFrameIndex();
|
||||||
pthread_mutex_unlock(&mg);
|
pthread_mutex_unlock(&mg);
|
||||||
@ -441,7 +446,7 @@ void* postProcessing::processData(int delflag) {
|
|||||||
cout<<"****Detector returned mismatched indeices***"<<endl;
|
cout<<"****Detector returned mismatched indeices***"<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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);
|
printf("ERROR reading from socket %d, %d %d\n", n, fnum, file_des);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
else
|
else
|
||||||
printf("size of data received %d\n",n);
|
printf("size of data received %d\n",n);
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#ifdef VERBOSE
|
//#ifdef VERBOSE
|
||||||
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
|
printf( "calling function fnum = %d %x\n",fnum,flist[fnum]);
|
||||||
#endif
|
//#endif
|
||||||
if (fnum<0 || fnum>255)
|
if (fnum<0 || fnum>255)
|
||||||
fnum=255;
|
fnum=255;
|
||||||
retval=(*flist[fnum])(file_des);
|
retval=(*flist[fnum])(file_des);
|
||||||
|
@ -5,13 +5,19 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define GOODBYE -200
|
#define GOODBYE -200
|
||||||
#define BUFFER_SIZE 1286*2
|
|
||||||
#define SHORT_BUFFER_SIZE 518
|
#define BUFFER_SIZE 1286*2
|
||||||
#define DATABYTES 2560
|
#define DATA_BYTES 2560
|
||||||
#define FIFO_SIZE 25000
|
#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
|
//#define THIS_SOFTWARE_VERSION 0x20120919
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,6 +26,7 @@ FILE* slsReceiverFunctionList::sfilefd(NULL);
|
|||||||
int slsReceiverFunctionList::listening_thread_running(0);
|
int slsReceiverFunctionList::listening_thread_running(0);
|
||||||
|
|
||||||
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
||||||
|
maxFramesPerFile(MAX_FRAMES),
|
||||||
enableFileWrite(1),
|
enableFileWrite(1),
|
||||||
shortFileName(shortfname),
|
shortFileName(shortfname),
|
||||||
shortFileNameIndex(0),
|
shortFileNameIndex(0),
|
||||||
@ -43,7 +44,10 @@ slsReceiverFunctionList::slsReceiverFunctionList(bool shortfname):
|
|||||||
latestData(NULL),
|
latestData(NULL),
|
||||||
udpSocket(NULL),
|
udpSocket(NULL),
|
||||||
server_port(DEFAULT_UDP_PORTNO),
|
server_port(DEFAULT_UDP_PORTNO),
|
||||||
fifo(NULL)
|
fifo(NULL),
|
||||||
|
shortFrame(0),
|
||||||
|
bufferSize(BUFFER_SIZE),
|
||||||
|
packetsPerFrame(2)
|
||||||
{
|
{
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
strcpy(actualfilename,"");
|
strcpy(actualfilename,"");
|
||||||
@ -73,7 +77,7 @@ int slsReceiverFunctionList::getFrameIndex(){
|
|||||||
if(startFrameIndex==-1)
|
if(startFrameIndex==-1)
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
else
|
else
|
||||||
frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/2;
|
frameIndex=((int)(*((int*)latestData)) - startFrameIndex)/packetsPerFrame;
|
||||||
return frameIndex;
|
return frameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +87,7 @@ int slsReceiverFunctionList::getAcquisitionIndex(){
|
|||||||
if(startAcquisitionIndex==-1)
|
if(startAcquisitionIndex==-1)
|
||||||
acquisitionIndex=0;
|
acquisitionIndex=0;
|
||||||
else
|
else
|
||||||
acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/2;
|
acquisitionIndex=((int)(*((int*)latestData)) - startAcquisitionIndex)/packetsPerFrame;
|
||||||
return acquisitionIndex;
|
return acquisitionIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +108,10 @@ char* slsReceiverFunctionList::setFilePath(char c[]){
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
if(stat(c,&st) == 0)
|
if(stat(c,&st) == 0)
|
||||||
strcpy(filePath,c);
|
strcpy(filePath,c);
|
||||||
|
else{
|
||||||
|
strcpy(filePath,"");
|
||||||
|
cout<<"FilePath does not exist:"<<filePath<<endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getFilePath();
|
return getFilePath();
|
||||||
}
|
}
|
||||||
@ -131,6 +139,8 @@ int slsReceiverFunctionList::startReceiver(){
|
|||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cout << "Starting Receiver" << endl;
|
cout << "Starting Receiver" << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if(!listening_thread_running){
|
if(!listening_thread_running){
|
||||||
cout << "Starting new acquisition threadddd ...." << endl;
|
cout << "Starting new acquisition threadddd ...." << endl;
|
||||||
@ -232,21 +242,29 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
// very end of the program.
|
// very end of the program.
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!strlen(eth)){
|
if(!strlen(eth)){
|
||||||
cout<<"warning:eth is empty.listening to all"<<endl;
|
cout<<"warning:eth is empty.listening to all"<<endl;
|
||||||
udpSocket = new genericSocket(server_port,genericSocket::UDP);
|
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame);
|
||||||
}else
|
}else{
|
||||||
udpSocket = new genericSocket(server_port,genericSocket::UDP,eth);
|
cout<<"eth:"<<eth<<endl;
|
||||||
|
udpSocket = new genericSocket(server_port,genericSocket::UDP,bufferSize/packetsPerFrame,packetsPerFrame,eth);
|
||||||
|
}
|
||||||
|
|
||||||
if (udpSocket->getErrorStatus()){
|
if (udpSocket->getErrorStatus()){
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Could not create UDP socket "<< server_port << std::endl;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (listening_thread_running) {
|
while (listening_thread_running) {
|
||||||
status = RUNNING;
|
status = RUNNING;
|
||||||
|
|
||||||
buffer = new char[BUFFER_SIZE];
|
buffer = new char[bufferSize];
|
||||||
//receiver 2 half frames
|
//receiver 2 half frames
|
||||||
rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer));
|
rc = udpSocket->ReceiveDataOnly(buffer,sizeof(buffer));
|
||||||
if( rc < 0)
|
if( rc < 0)
|
||||||
@ -254,7 +272,7 @@ int slsReceiverFunctionList::startListening(){
|
|||||||
|
|
||||||
//start for each scan
|
//start for each scan
|
||||||
if(startFrameIndex==-1){
|
if(startFrameIndex==-1){
|
||||||
startFrameIndex=(int)(*((int*)buffer))-2;
|
startFrameIndex=(int)(*((int*)buffer))-packetsPerFrame;
|
||||||
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
//cout<<"startFrameIndex:"<<startFrameIndex<<endl;
|
||||||
prevframenum=startFrameIndex;
|
prevframenum=startFrameIndex;
|
||||||
}
|
}
|
||||||
@ -325,7 +343,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
framesCaught=0;
|
framesCaught=0;
|
||||||
frameIndex=0;
|
frameIndex=0;
|
||||||
|
|
||||||
latestData = new char[BUFFER_SIZE];
|
latestData = new char[bufferSize];
|
||||||
if(sfilefd) sfilefd=0;
|
if(sfilefd) sfilefd=0;
|
||||||
|
|
||||||
strcpy(savefilename,"");
|
strcpy(savefilename,"");
|
||||||
@ -351,8 +369,8 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
|
|
||||||
while(listening_thread_running){
|
while(listening_thread_running){
|
||||||
|
|
||||||
//when it reaches MAX_FRAMES_PER_FILE,start writing new file
|
//when it reaches maxFramesPerFile,start writing new file
|
||||||
if (framesInFile == MAX_FRAMES_PER_FILE) {
|
if (framesInFile == maxFramesPerFile) {
|
||||||
|
|
||||||
if(enableFileWrite){
|
if(enableFileWrite){
|
||||||
fclose(sfilefd);
|
fclose(sfilefd);
|
||||||
@ -369,7 +387,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
currframenum=(int)(*((int*)latestData));
|
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"
|
"framenum " << currframenum << "\t\t"
|
||||||
"p " << prevframenum << endl;
|
"p " << prevframenum << endl;
|
||||||
|
|
||||||
@ -385,7 +403,7 @@ int slsReceiverFunctionList::startWriting(){
|
|||||||
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
|
//cout<<"write buffer:"<<dataWriteFrame<<endl<<endl;
|
||||||
framesCaught++;
|
framesCaught++;
|
||||||
totalFramesCaught++;
|
totalFramesCaught++;
|
||||||
memcpy(latestData,dataWriteFrame->buffer,BUFFER_SIZE);
|
memcpy(latestData,dataWriteFrame->buffer,bufferSize);
|
||||||
//cout<<"list write \t index:"<<(int)(*(int*)latestData)<<endl;
|
//cout<<"list write \t index:"<<(int)(*(int*)latestData)<<endl;
|
||||||
if(enableFileWrite)
|
if(enableFileWrite)
|
||||||
fwrite(dataWriteFrame->buffer, 1, dataWriteFrame->rc, sfilefd);
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -170,11 +170,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
char* readFrame(char* c);
|
char* readFrame(char* c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set short frame
|
||||||
|
* @param i if shortframe i=1
|
||||||
|
*/
|
||||||
|
int setShortFrame(int i);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static const int MAX_FRAMES_PER_FILE = 20000;
|
/** max frames per file **/
|
||||||
|
int maxFramesPerFile;
|
||||||
|
|
||||||
/** File write enable */
|
/** File write enable */
|
||||||
int enableFileWrite;
|
int enableFileWrite;
|
||||||
@ -260,6 +267,15 @@ private:
|
|||||||
/** circular fifo to read and write data*/
|
/** circular fifo to read and write data*/
|
||||||
CircularFifo<dataStruct,FIFO_SIZE>* fifo;
|
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:
|
public:
|
||||||
/** File Descriptor */
|
/** File Descriptor */
|
||||||
static FILE *sfilefd;
|
static FILE *sfilefd;
|
||||||
|
@ -22,7 +22,8 @@ int slsReceiverFuncs::socketDescriptor(-1);
|
|||||||
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname):
|
slsReceiverFuncs::slsReceiverFuncs(MySocketTCP *&mySocket,string const fname,int &success, bool shortfname):
|
||||||
socket(mySocket),
|
socket(mySocket),
|
||||||
ret(OK),
|
ret(OK),
|
||||||
lockStatus(0){
|
lockStatus(0),
|
||||||
|
shortFrame(0){
|
||||||
|
|
||||||
int port_no = DEFAULT_PORTNO+2;
|
int port_no = DEFAULT_PORTNO+2;
|
||||||
ifstream infile;
|
ifstream infile;
|
||||||
@ -128,6 +129,7 @@ int slsReceiverFuncs::function_table(){
|
|||||||
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
|
flist[F_READ_FRAME] = &slsReceiverFuncs::read_frame;
|
||||||
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
|
flist[F_ENABLE_FILE_WRITE] = &slsReceiverFuncs::enable_file_write;
|
||||||
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
|
flist[F_GET_ID] = &slsReceiverFuncs::get_version;
|
||||||
|
flist[F_CONFIGURE_MAC] = &slsReceiverFuncs::set_short_frame;
|
||||||
|
|
||||||
//General Functions
|
//General Functions
|
||||||
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
flist[F_LOCK_SERVER] = &slsReceiverFuncs::lock_receiver;
|
||||||
@ -475,7 +477,7 @@ int slsReceiverFuncs::start_receiver(){
|
|||||||
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
sprintf(mess,"Receiver locked by %s\n", socket->lastClientIP);
|
||||||
ret=FAIL;
|
ret=FAIL;
|
||||||
}
|
}
|
||||||
else if(!strlen(slsReceiverList->setFilePath(""))){
|
else if(!strlen(slsReceiverList->getFilePath())){
|
||||||
strcpy(mess,"receiver not set up. set receiver ip again.\n");
|
strcpy(mess,"receiver not set up. set receiver ip again.\n");
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
}
|
}
|
||||||
@ -649,11 +651,22 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
char fName[MAX_STR_LENGTH];
|
char fName[MAX_STR_LENGTH];
|
||||||
int arg = -1;
|
int arg = -1;
|
||||||
|
|
||||||
int nel = BUFFER_SIZE/(sizeof(int));
|
int bufferSize = BUFFER_SIZE;
|
||||||
int onebuffersize = BUFFER_SIZE/2;
|
int databytes = DATA_BYTES;
|
||||||
int onedatasize = DATABYTES/2;
|
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* origVal = new int[nel];
|
||||||
int* retval = new int[nel];
|
int* retval = new int[nel];
|
||||||
|
|
||||||
@ -676,7 +689,7 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
ret=OK;
|
ret=OK;
|
||||||
break;
|
break;
|
||||||
}else
|
}else
|
||||||
usleep(1000000);
|
usleep(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -687,7 +700,7 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
raw=slsReceiverList->readFrame(fName);
|
raw=slsReceiverList->readFrame(fName);
|
||||||
index=(int)(*(int*)raw);
|
index=(int)(*(int*)raw);
|
||||||
index2= (int)(*((int*)((char*)(raw+onebuffersize))));
|
index2= (int)(*((int*)((char*)(raw+onebuffersize))));
|
||||||
memcpy(origVal,raw,BUFFER_SIZE);
|
memcpy(origVal,raw,bufferSize);
|
||||||
raw=NULL;
|
raw=NULL;
|
||||||
//cout<<"funcs\tindex:"<<index<<"\tindex2:"<<index2<<endl;
|
//cout<<"funcs\tindex:"<<index<<"\tindex2:"<<index2<<endl;
|
||||||
|
|
||||||
@ -748,7 +761,7 @@ int slsReceiverFuncs::read_frame(){
|
|||||||
else{
|
else{
|
||||||
socket->SendDataOnly(fName,MAX_STR_LENGTH);
|
socket->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||||
socket->SendDataOnly(&arg,sizeof(arg));
|
socket->SendDataOnly(&arg,sizeof(arg));
|
||||||
socket->SendDataOnly(retval,DATABYTES);
|
socket->SendDataOnly(retval,DATA_BYTES);
|
||||||
}
|
}
|
||||||
//return ok/fail
|
//return ok/fail
|
||||||
return ret;
|
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 */
|
/** Get Version */
|
||||||
int get_version();
|
int get_version();
|
||||||
|
|
||||||
|
/** set short frame */
|
||||||
|
int set_short_frame();
|
||||||
|
|
||||||
//General Functions
|
//General Functions
|
||||||
/** Locks Receiver */
|
/** Locks Receiver */
|
||||||
int lock_receiver();
|
int lock_receiver();
|
||||||
@ -130,6 +133,9 @@ private:
|
|||||||
/** Lock Status if server locked to a client */
|
/** Lock Status if server locked to a client */
|
||||||
int lockStatus;
|
int lockStatus;
|
||||||
|
|
||||||
|
/** Short frame */
|
||||||
|
int shortFrame;
|
||||||
|
|
||||||
static int file_des;
|
static int file_des;
|
||||||
static int socketDescriptor;
|
static int socketDescriptor;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user