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:
l_maliakal_d
2013-01-30 16:41:36 +00:00
parent 7d96d8b3af
commit 22bd638f64
12 changed files with 349 additions and 173 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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;