mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 16:48:01 +02:00
somewhere in between.. next step include generalData pointer in listerner and dataprocessor calss in constructor and a setter
This commit is contained in:
@ -32,9 +32,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface*
|
||||
receiverBase(rbase),
|
||||
ret(OK),
|
||||
lockStatus(0),
|
||||
shortFrame(-1),
|
||||
packetsPerFrame(GOTTHARD_PACKETS_PER_FRAME),
|
||||
dynamicrange(16),
|
||||
killTCPServerThread(0),
|
||||
tenGigaEnable(0),
|
||||
portNumber(DEFAULT_PORTNO+2),
|
||||
@ -195,7 +192,7 @@ void slsReceiverTCPIPInterface::startTCPServer(){
|
||||
receiverBase->shutDownUDPSockets();
|
||||
|
||||
cout << "Closing Files... " << endl;
|
||||
receiverBase->closeFile();
|
||||
receiverBase->closeFiles();
|
||||
}
|
||||
|
||||
mySock->exitServer();
|
||||
@ -334,7 +331,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){
|
||||
|
||||
|
||||
void slsReceiverTCPIPInterface::closeFile(int p){
|
||||
receiverBase->closeFile();
|
||||
receiverBase->closeFiles();
|
||||
}
|
||||
|
||||
|
||||
@ -1098,11 +1095,6 @@ int slsReceiverTCPIPInterface::set_short_frame() {
|
||||
else{
|
||||
receiverBase->setShortFrameEnable(index);
|
||||
retval = receiverBase->getShortFrameEnable();
|
||||
shortFrame = retval;
|
||||
if(shortFrame==-1)
|
||||
packetsPerFrame=GOTTHARD_PACKETS_PER_FRAME;
|
||||
else
|
||||
packetsPerFrame=GOTTHARD_SHORT_PACKETS_PER_FRAME;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1144,940 +1136,39 @@ int slsReceiverTCPIPInterface::read_frame(){
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::moench_read_frame(){
|
||||
ret=OK;
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int acquisitionIndex = -1;
|
||||
int frameIndex= -1;
|
||||
int i;
|
||||
int slsReceiverTCPIPInterface::moench_read_frame(){ return FAIL;}
|
||||
|
||||
|
||||
int bufferSize = MOENCH_BUFFER_SIZE;
|
||||
int rnel = bufferSize/(sizeof(int));
|
||||
int* retval = new int[rnel];
|
||||
int* origVal = new int[rnel];
|
||||
//all initialized to 0
|
||||
for(i=0;i<rnel;i++) retval[i]=0;
|
||||
for(i=0;i<rnel;i++) origVal[i]=0;
|
||||
|
||||
char* raw;
|
||||
|
||||
int64_t startAcquisitionIndex=0;
|
||||
int64_t startFrameIndex=0;
|
||||
uint32_t index = -1,bindex = 0, offset=0;
|
||||
int slsReceiverTCPIPInterface::gotthard_read_frame(){ return FAIL;}
|
||||
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
/**send garbage with -1 index to try again*/
|
||||
else if(!receiverBase->getFramesCaught()){
|
||||
startAcquisitionIndex = -1;
|
||||
cout<<"haven't caught any frame yet"<<endl;
|
||||
}
|
||||
|
||||
else{
|
||||
ret = OK;
|
||||
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
|
||||
|
||||
/**send garbage with -1 index to try again*/
|
||||
if (raw == NULL){
|
||||
startAcquisitionIndex = -1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"data not ready for gui yet"<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
else{
|
||||
bindex = ((uint32_t)(*((uint32_t*)raw)));
|
||||
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
//************** packet number order**********************
|
||||
index = ((bindex & (MOENCH_FRAME_INDEX_MASK)) >> MOENCH_FRAME_INDEX_OFFSET);
|
||||
int slsReceiverTCPIPInterface::propix_read_frame(){ return FAIL;}
|
||||
|
||||
uint32_t numPackets = MOENCH_PACKETS_PER_FRAME; //40
|
||||
uint32_t onePacketSize = MOENCH_DATA_BYTES / MOENCH_PACKETS_PER_FRAME; //1280*40 / 40 = 1280
|
||||
uint32_t packetDatabytes_row = onePacketSize * (MOENCH_BYTES_IN_ONE_ROW / MOENCH_BYTES_PER_ADC); //1280 * 4 = 5120
|
||||
uint32_t partsPerFrame = onePacketSize / MOENCH_BYTES_PER_ADC; // 1280 / 80 = 16
|
||||
uint32_t packetOffset = 0;
|
||||
int packetIndex,x,y;
|
||||
int iPacket = 0;
|
||||
offset = 4;
|
||||
|
||||
|
||||
while (iPacket < (int)numPackets){
|
||||
#ifdef VERYVERBOSE
|
||||
printf("iPacket:%d\n",iPacket);cout << endl;
|
||||
#endif
|
||||
//if missing packets, dont send to gui
|
||||
bindex = (*((uint32_t*)(((char*)origVal)+packetOffset)));
|
||||
if (bindex == 0xFFFFFFFF){
|
||||
cout << "Missing Packet,Not sending to gui" << endl;
|
||||
index = startAcquisitionIndex - 1;
|
||||
break;//use continue and change index above if you want to display missing packets with 0 value anyway in gui
|
||||
}
|
||||
|
||||
packetIndex = bindex & MOENCH_PACKET_INDEX_MASK;
|
||||
//cout<<"packetIndex:"<<packetIndex<<endl;
|
||||
//the first packet is placed in the end
|
||||
packetIndex--;
|
||||
if(packetIndex ==-1)
|
||||
packetIndex = 39;
|
||||
//cout<<"packetIndexM:"<<packetIndex<<endl;
|
||||
//check validity
|
||||
if ((packetIndex >= 40) && (packetIndex < 0))
|
||||
cout << "cannot decode packet index:" << packetIndex << endl;
|
||||
else{
|
||||
|
||||
x = packetIndex / 10;
|
||||
y = packetIndex % 10;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"x:"<<x<<" y:"<<y<<endl;
|
||||
#endif
|
||||
//copy 16 times 80 bytes
|
||||
for (i = 0; i < (int)partsPerFrame; i++) {
|
||||
memcpy((((char*)retval) +
|
||||
y * packetDatabytes_row +
|
||||
i * MOENCH_BYTES_IN_ONE_ROW +
|
||||
x * MOENCH_BYTES_PER_ADC),
|
||||
|
||||
(((char*) origVal) +
|
||||
iPacket * offset +
|
||||
iPacket * onePacketSize +
|
||||
i * MOENCH_BYTES_PER_ADC + 4) ,
|
||||
MOENCH_BYTES_PER_ADC);
|
||||
}
|
||||
}
|
||||
|
||||
//increment
|
||||
offset=6;
|
||||
iPacket++;
|
||||
packetOffset = packetOffset + offset + onePacketSize;
|
||||
|
||||
//check if same frame number
|
||||
}
|
||||
|
||||
acquisitionIndex = index-startAcquisitionIndex;
|
||||
if(acquisitionIndex == -1)
|
||||
startFrameIndex = -1;
|
||||
else
|
||||
frameIndex = index-startFrameIndex;
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex calculated is:" << frameIndex << endl;
|
||||
cout << "index:" << index << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
int slsReceiverTCPIPInterface::eiger_read_frame(){ return FAIL;}
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "fName:" << fName << endl;
|
||||
cout << "acquisitionIndex:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex:" << frameIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
else{
|
||||
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
mySock->SendDataOnly(retval,MOENCH_DATA_BYTES);
|
||||
}
|
||||
//return ok/fail
|
||||
|
||||
|
||||
delete [] retval;
|
||||
delete [] origVal;
|
||||
delete [] raw;
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::gotthard_read_frame(){
|
||||
ret=OK;
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int acquisitionIndex = -1;
|
||||
int frameIndex= -1;
|
||||
int i;
|
||||
|
||||
|
||||
//retval is a full frame
|
||||
int bufferSize = GOTTHARD_BUFFER_SIZE;
|
||||
int rnel = bufferSize/(sizeof(int));
|
||||
int* retval = new int[rnel];
|
||||
int* origVal = new int[rnel];
|
||||
//all initialized to 0
|
||||
for(i=0;i<rnel;i++) retval[i]=0;
|
||||
for(i=0;i<rnel;i++) origVal[i]=0;
|
||||
|
||||
//only for full frames
|
||||
int onebuffersize = GOTTHARD_BUFFER_SIZE/GOTTHARD_PACKETS_PER_FRAME;
|
||||
int onedatasize = GOTTHARD_DATA_BYTES/GOTTHARD_PACKETS_PER_FRAME;
|
||||
|
||||
|
||||
//depending on shortframe or not
|
||||
if(shortFrame!=-1)
|
||||
bufferSize=GOTTHARD_SHORT_BUFFER_SIZE;
|
||||
char* raw;
|
||||
|
||||
|
||||
uint32_t index=-1,index2=0;
|
||||
uint32_t pindex=0,pindex2=0;
|
||||
uint32_t bindex=0,bindex2=0;
|
||||
int64_t startAcquisitionIndex=0;
|
||||
int64_t startFrameIndex=0;
|
||||
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
/**send garbage with -1 index to try again*/
|
||||
else if(!receiverBase->getFramesCaught()){
|
||||
startAcquisitionIndex=-1;
|
||||
cout<<"haven't caught any frame yet"<<endl;
|
||||
}else{
|
||||
ret = OK;
|
||||
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
|
||||
|
||||
/**send garbage with -1 index to try again*/
|
||||
if (raw == NULL){
|
||||
startAcquisitionIndex = -1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"data not ready for gui yet"<<endl;
|
||||
#endif
|
||||
}else{
|
||||
if(shortFrame!=-1){
|
||||
bindex = (uint32_t)(*((uint32_t*)raw));
|
||||
pindex = (bindex & GOTTHARD_SHORT_PACKET_INDEX_MASK);
|
||||
index = ((bindex & GOTTHARD_SHORT_FRAME_INDEX_MASK) >> GOTTHARD_SHORT_FRAME_INDEX_OFFSET);
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "index:" << hex << index << endl;
|
||||
#endif
|
||||
}else{
|
||||
bindex = ((uint32_t)(*((uint32_t*)raw)))+1;
|
||||
pindex = (bindex & GOTTHARD_PACKET_INDEX_MASK);
|
||||
index = ((bindex & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
|
||||
bindex2 = ((uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize)))))+1;
|
||||
pindex2 =(bindex2 & GOTTHARD_PACKET_INDEX_MASK);
|
||||
index2 =((bindex2 & GOTTHARD_FRAME_INDEX_MASK) >> GOTTHARD_FRAME_INDEX_OFFSET);
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "index1:" << hex << index << endl;
|
||||
cout << "index2:" << hex << index << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
|
||||
//1 adc
|
||||
if(shortFrame!=-1){
|
||||
if(bindex != 0xFFFFFFFF)
|
||||
memcpy((((char*)retval)+(GOTTHARD_SHORT_DATABYTES*shortFrame)),((char*) origVal)+4, GOTTHARD_SHORT_DATABYTES);
|
||||
else{
|
||||
index = startAcquisitionIndex - 1;
|
||||
cout << "Missing Packet,Not sending to gui" << endl;
|
||||
}
|
||||
}
|
||||
//all adc
|
||||
else{
|
||||
/*//ignore if half frame is missing
|
||||
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/
|
||||
|
||||
//should be same frame
|
||||
if (index == index2){
|
||||
//ideal situation (should be odd, even(index+1))
|
||||
if(!pindex){
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
}
|
||||
//swap to even,odd
|
||||
else{
|
||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
index=index2;
|
||||
}
|
||||
}else
|
||||
cout << "different frames caught. frame1:"<< hex << index << ":"<<pindex<<" frame2:" << hex << index2 << ":"<<pindex2<<endl;
|
||||
/*}
|
||||
else{
|
||||
index = startIndex - 1;
|
||||
cout << "Missing Packet,Not sending to gui" << endl;
|
||||
}*/
|
||||
}
|
||||
|
||||
acquisitionIndex = index-startAcquisitionIndex;
|
||||
if(acquisitionIndex == -1)
|
||||
startFrameIndex = -1;
|
||||
else
|
||||
frameIndex = index-startFrameIndex;
|
||||
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex calculated is:" << frameIndex << endl;
|
||||
cout << "index:" << index << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
if(frameIndex!=-1){
|
||||
cout << "fName:" << fName << endl;
|
||||
cout << "acquisitionIndex:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex:" << frameIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
else{
|
||||
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
mySock->SendDataOnly(retval,GOTTHARD_DATA_BYTES);
|
||||
}
|
||||
|
||||
delete [] retval;
|
||||
delete [] origVal;
|
||||
delete [] raw;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::propix_read_frame(){
|
||||
ret=OK;
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int acquisitionIndex = -1;
|
||||
int frameIndex= -1;
|
||||
int i;
|
||||
|
||||
|
||||
//retval is a full frame
|
||||
int bufferSize = PROPIX_BUFFER_SIZE;
|
||||
int onebuffersize = bufferSize/PROPIX_PACKETS_PER_FRAME;
|
||||
int onedatasize = PROPIX_DATA_BYTES;
|
||||
|
||||
char* raw;
|
||||
int rnel = bufferSize/(sizeof(int));
|
||||
int* retval = new int[rnel];
|
||||
int* origVal = new int[rnel];
|
||||
//all initialized to 0
|
||||
for(i=0;i<rnel;i++) retval[i]=0;
|
||||
for(i=0;i<rnel;i++) origVal[i]=0;
|
||||
|
||||
|
||||
uint32_t index=-1,index2=0;
|
||||
uint32_t pindex=0,pindex2=0;
|
||||
uint32_t bindex=0,bindex2=0;
|
||||
int64_t startAcquisitionIndex=0;
|
||||
int64_t startFrameIndex=0;
|
||||
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
/**send garbage with -1 index to try again*/
|
||||
else if(!receiverBase->getFramesCaught()){
|
||||
startAcquisitionIndex=-1;
|
||||
cout<<"haven't caught any frame yet"<<endl;
|
||||
}else{
|
||||
ret = OK;
|
||||
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
|
||||
|
||||
/**send garbage with -1 index to try again*/
|
||||
if (raw == NULL){
|
||||
startAcquisitionIndex = -1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"data not ready for gui yet"<<endl;
|
||||
#endif
|
||||
}else{
|
||||
bindex = ((uint32_t)(*((uint32_t*)raw)))+1;
|
||||
pindex = (bindex & PROPIX_PACKET_INDEX_MASK);
|
||||
index = ((bindex & PROPIX_FRAME_INDEX_MASK) >> PROPIX_FRAME_INDEX_OFFSET);
|
||||
bindex2 = ((uint32_t)(*((uint32_t*)((char*)(raw+onebuffersize)))))+1;
|
||||
pindex2 =(bindex2 & PROPIX_PACKET_INDEX_MASK);
|
||||
index2 =((bindex2 & PROPIX_FRAME_INDEX_MASK) >> PROPIX_FRAME_INDEX_OFFSET);
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "index1:" << hex << index << endl;
|
||||
cout << "index2:" << hex << index << endl;
|
||||
#endif
|
||||
|
||||
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,bufferSize);
|
||||
raw=NULL;
|
||||
|
||||
/*//ignore if half frame is missing
|
||||
if ((bindex != 0xFFFFFFFF) && (bindex2 != 0xFFFFFFFF)){*/
|
||||
|
||||
//should be same frame
|
||||
if (index == index2){
|
||||
//ideal situation (should be odd, even(index+1))
|
||||
if(!pindex){
|
||||
memcpy(retval,((char*) origVal)+4, onedatasize);
|
||||
memcpy((((char*)retval)+onedatasize), ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
}
|
||||
//swap to even,odd
|
||||
else{
|
||||
memcpy((((char*)retval)+onedatasize),((char*) origVal)+4, onedatasize);
|
||||
memcpy(retval, ((char*) origVal)+10+onedatasize, onedatasize);
|
||||
index=index2;
|
||||
}
|
||||
}else
|
||||
cout << "different frames caught. frame1:"<< hex << index << ":"<<pindex<<" frame2:" << hex << index2 << ":"<<pindex2<<endl;
|
||||
/*}
|
||||
else{
|
||||
index = startIndex - 1;
|
||||
cout << "Missing Packet,Not sending to gui" << endl;
|
||||
}*/
|
||||
|
||||
|
||||
acquisitionIndex = index-startAcquisitionIndex;
|
||||
if(acquisitionIndex == -1)
|
||||
startFrameIndex = -1;
|
||||
else
|
||||
frameIndex = index-startFrameIndex;
|
||||
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex calculated is:" << frameIndex << endl;
|
||||
cout << "index:" << index << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
if(frameIndex!=-1){
|
||||
cout << "fName:" << fName << endl;
|
||||
cout << "acquisitionIndex:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex:" << frameIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
else{
|
||||
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
mySock->SendDataOnly(retval,PROPIX_DATA_BYTES);
|
||||
}
|
||||
|
||||
delete [] retval;
|
||||
delete [] origVal;
|
||||
delete [] raw;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::eiger_read_frame(){
|
||||
ret=OK;
|
||||
/*
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int acquisitionIndex = -1;
|
||||
int frameIndex= -1;
|
||||
int index=0;
|
||||
int subframenumber=-1;
|
||||
|
||||
int frameSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
|
||||
int dataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
|
||||
int oneDataSize = EIGER_ONE_GIGA_ONE_DATA_SIZE;
|
||||
int onePacketSize = EIGER_ONE_GIGA_ONE_PACKET_SIZE;
|
||||
if(tenGigaEnable){
|
||||
frameSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
|
||||
dataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE * packetsPerFrame * EIGER_MAX_PORTS;
|
||||
oneDataSize = EIGER_TEN_GIGA_ONE_DATA_SIZE;
|
||||
onePacketSize = EIGER_TEN_GIGA_ONE_PACKET_SIZE;
|
||||
}
|
||||
char* raw;
|
||||
char* origVal = new char[frameSize]();
|
||||
char* retval = new char[dataSize]();
|
||||
memset(origVal,0xFF,frameSize);
|
||||
memset(retval,0xFF,dataSize);
|
||||
|
||||
int64_t startAcquisitionIndex=0;
|
||||
int64_t startFrameIndex=0;
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
//send garbage with -1 index to try again
|
||||
else if(!receiverBase->getFramesCaught()){
|
||||
startAcquisitionIndex=-1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"haven't caught any frame yet"<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// acq started
|
||||
else{
|
||||
ret = OK;
|
||||
int fnum[EIGER_MAX_PORTS];
|
||||
for(int i=0;i<EIGER_MAX_PORTS;i++)
|
||||
fnum[i] = -1;
|
||||
//read a frame
|
||||
for(int i=0;i<EIGER_MAX_PORTS;i++){
|
||||
receiverBase->readFrame(i,fName,&raw,startAcquisitionIndex,startFrameIndex);
|
||||
//send garbage with -1 index to try again
|
||||
if (raw == NULL){
|
||||
startAcquisitionIndex = -1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"data not ready for gui yet for "<< i << endl;
|
||||
#endif
|
||||
raw=NULL;
|
||||
break;
|
||||
}
|
||||
else{
|
||||
eiger_packet_footer_t* wbuf_footer;
|
||||
wbuf_footer = (eiger_packet_footer_t*)(raw + HEADER_SIZE_NUM_TOT_PACKETS + oneDataSize + sizeof(eiger_packet_header_t));
|
||||
index =(uint32_t)(*( (uint64_t*) wbuf_footer));
|
||||
index += (startFrameIndex-1);
|
||||
fnum[i] = index;
|
||||
if(dynamicrange == 32){
|
||||
eiger_packet_header_t* wbuf_header;
|
||||
wbuf_header = (eiger_packet_header_t*) (raw + HEADER_SIZE_NUM_TOT_PACKETS);
|
||||
subframenumber = *( (uint32_t*) wbuf_header->subFrameNumber);
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "index:" << dec << index << endl;
|
||||
cout << "subframenumber:" << dec << subframenumber << endl;
|
||||
#endif
|
||||
int numpackets = (uint32_t)(*( (uint32_t*) raw));
|
||||
memcpy(((char*)origVal)+(i*onePacketSize*packetsPerFrame),raw + HEADER_SIZE_NUM_TOT_PACKETS,numpackets*onePacketSize);
|
||||
raw=NULL;
|
||||
}
|
||||
}
|
||||
//proper frame
|
||||
if(startAcquisitionIndex != -1){
|
||||
//cout<<"**** got proper frame ******"<<endl;
|
||||
|
||||
//let them continue
|
||||
//for(int i=0;i<EIGER_MAX_PORTS;++i)
|
||||
//receiverBase->resetGuiPointer(i);
|
||||
|
||||
if(fnum[0]!=fnum[1])
|
||||
cprintf(BG_RED,"Fnums differ %d and %d\n",fnum[0],fnum[1]);
|
||||
|
||||
int c1=8;//first port
|
||||
int c2=(frameSize/2) + 8; //second port
|
||||
int retindex=0;
|
||||
int irow,ibytesperpacket;
|
||||
int linesperpacket = (16*1/dynamicrange);// 16:1 line, 8:2 lines, 4:4 lines, 32: 0.5
|
||||
int numbytesperlineperport=(EIGER_PIXELS_IN_ONE_ROW/EIGER_MAX_PORTS)*dynamicrange/8;//16:1024,8:512,4:256,32:2048
|
||||
int datapacketlength = EIGER_ONE_GIGA_ONE_DATA_SIZE;
|
||||
int total_num_bytes = EIGER_ONE_GIGA_ONE_PACKET_SIZE *(EIGER_ONE_GIGA_CONSTANT *dynamicrange)*2;
|
||||
|
||||
if(tenGigaEnable){
|
||||
linesperpacket = (16*4/dynamicrange);// 16:4 line, 8:8 lines, 4:16 lines, 32: 2
|
||||
datapacketlength = EIGER_TEN_GIGA_ONE_DATA_SIZE;
|
||||
total_num_bytes = EIGER_TEN_GIGA_ONE_PACKET_SIZE*(EIGER_TEN_GIGA_CONSTANT*dynamicrange)*2;
|
||||
}
|
||||
//if 1GbE, one line is split into two packets for 32 bit mode, so its special
|
||||
else if(dynamicrange == 32){
|
||||
numbytesperlineperport = 1024;
|
||||
linesperpacket = 1; //we repeat this twice anyway for 32 bit
|
||||
}
|
||||
|
||||
if(!bottom){
|
||||
|
||||
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
|
||||
ibytesperpacket=0;
|
||||
while(ibytesperpacket<datapacketlength){
|
||||
//first port
|
||||
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c1 += numbytesperlineperport;
|
||||
if(dynamicrange == 32 && !tenGigaEnable){
|
||||
c1 += 16;
|
||||
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c1 += numbytesperlineperport;
|
||||
c1 += 16;
|
||||
}
|
||||
//second port
|
||||
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c2 += numbytesperlineperport;
|
||||
if(dynamicrange == 32 && !tenGigaEnable){
|
||||
c2 += 16;
|
||||
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c2 += numbytesperlineperport;
|
||||
c2 += 16;
|
||||
}
|
||||
ibytesperpacket += numbytesperlineperport;
|
||||
}
|
||||
if(dynamicrange != 32 || tenGigaEnable) {
|
||||
c1 += 16;
|
||||
c2 += 16;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//bottom half module
|
||||
|
||||
else{
|
||||
c1 = (frameSize/2) - numbytesperlineperport - 8 ;
|
||||
c2 = total_num_bytes - numbytesperlineperport - 8;
|
||||
|
||||
for(irow=0;irow<EIGER_PIXELS_IN_ONE_COL/linesperpacket;++irow){
|
||||
ibytesperpacket=0;
|
||||
while(ibytesperpacket<datapacketlength){
|
||||
if(dynamicrange == 32 && !tenGigaEnable){
|
||||
//first port first chip
|
||||
c1 -= (numbytesperlineperport + 16);
|
||||
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
//first port second chip
|
||||
c1 += (numbytesperlineperport+16);
|
||||
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c1 -= (numbytesperlineperport*2+32);//1024*2+16*2
|
||||
//second port first chip
|
||||
c2 -= (numbytesperlineperport + 16);
|
||||
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
//second port second chip
|
||||
c2 += (numbytesperlineperport + 16);
|
||||
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c2 -= (numbytesperlineperport*2+32);
|
||||
}else{
|
||||
//first port
|
||||
memcpy(retval+retindex ,origVal+c1 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c1 -= numbytesperlineperport;
|
||||
//second port
|
||||
memcpy(retval+retindex ,origVal+c2 ,numbytesperlineperport);
|
||||
retindex += numbytesperlineperport;
|
||||
c2 -= numbytesperlineperport;
|
||||
}
|
||||
ibytesperpacket += numbytesperlineperport;
|
||||
}
|
||||
if(dynamicrange != 32 || tenGigaEnable) {
|
||||
c1 -= 16;
|
||||
c2 -= 16;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
acquisitionIndex = index-startAcquisitionIndex;
|
||||
if(acquisitionIndex == -1)
|
||||
startFrameIndex = -1;
|
||||
else
|
||||
frameIndex = index-startFrameIndex;
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex calculated is:" << frameIndex << endl;
|
||||
cout << "index:" << index << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
cout << "subframenumber:" << subframenumber << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
if(frameIndex!=-1){
|
||||
cout << "fName:" << fName << endl;
|
||||
cout << "acquisitionIndex:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex:" << frameIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
cout << "subframenumber:" << subframenumber << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
else{
|
||||
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
mySock->SendDataOnly(&subframenumber,sizeof(subframenumber));
|
||||
mySock->SendDataOnly(retval,dataSize);
|
||||
}
|
||||
|
||||
delete [] retval;
|
||||
delete [] origVal;
|
||||
delete [] raw;
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int slsReceiverTCPIPInterface::jungfrau_read_frame(){
|
||||
ret=OK;
|
||||
|
||||
char fName[MAX_STR_LENGTH]="";
|
||||
int acquisitionIndex = -1;
|
||||
int frameIndex= -1;
|
||||
int64_t currentIndex=0;
|
||||
int64_t startAcquisitionIndex=0;
|
||||
int64_t startFrameIndex=0;
|
||||
strcpy(mess,"Could not read frame\n");
|
||||
|
||||
|
||||
int frameSize = JFRAU_ONE_PACKET_SIZE * packetsPerFrame;
|
||||
int dataSize = JFRAU_ONE_DATA_SIZE * packetsPerFrame;
|
||||
int oneDataSize = JFRAU_ONE_DATA_SIZE;
|
||||
|
||||
char* raw;
|
||||
char* origVal = new char[frameSize]();
|
||||
char* retval = new char[dataSize]();
|
||||
char* blackpacket = new char[oneDataSize]();
|
||||
|
||||
for(int i=0;i<oneDataSize;i++)
|
||||
blackpacket[i]='0';
|
||||
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
#ifdef SLS_RECEIVER_UDP_FUNCTIONS
|
||||
|
||||
if (receiverBase == NULL){
|
||||
strcpy(mess,SET_RECEIVER_ERR_MESSAGE);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
||||
//send garbage with -1 currentIndex to try again
|
||||
else if(!receiverBase->getFramesCaught()){
|
||||
startAcquisitionIndex=-1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"haven't caught any frame yet"<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// acq started
|
||||
else{
|
||||
ret = OK;
|
||||
//read a frame
|
||||
receiverBase->readFrame(0,fName,&raw,startAcquisitionIndex,startFrameIndex);
|
||||
//send garbage with -1 index to try again
|
||||
if (raw == NULL){
|
||||
startAcquisitionIndex = -1;
|
||||
#ifdef VERYVERBOSE
|
||||
cout<<"data not ready for gui yet"<<endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
//proper frame
|
||||
else{
|
||||
//cout<<"**** got proper frame ******"<<endl;
|
||||
memcpy(origVal,raw + HEADER_SIZE_NUM_TOT_PACKETS,frameSize);
|
||||
raw=NULL;
|
||||
|
||||
//fixed frame number
|
||||
jfrau_packet_header_t* header = (jfrau_packet_header_t*) origVal;
|
||||
currentIndex = (*( (uint32_t*) header->frameNumber))&0xffffff;
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "currentIndex:" << dec << currentIndex << endl;
|
||||
#endif
|
||||
|
||||
int64_t currentPacket = packetsPerFrame-1;
|
||||
int offsetsrc = 0;
|
||||
int offsetdest = 0;
|
||||
int64_t ifnum=-1;
|
||||
int64_t ipnum=-1;
|
||||
|
||||
while(currentPacket >= 0){
|
||||
header = (jfrau_packet_header_t*) (origVal + offsetsrc);
|
||||
ifnum = (*( (uint32_t*) header->frameNumber))&0xffffff;
|
||||
ipnum = (*( (uint8_t*) header->packetNumber));
|
||||
if(ifnum != currentIndex) {
|
||||
cout << "current packet " << currentPacket << " Wrong Frame number " << ifnum << ", copying blank packet" << endl;
|
||||
memcpy(retval+offsetdest,blackpacket,oneDataSize);
|
||||
offsetdest += oneDataSize;
|
||||
//no need to increase offsetsrc as all packets will be wrong
|
||||
currentPacket--;
|
||||
continue;
|
||||
}
|
||||
if(ipnum!= currentPacket){
|
||||
cout << "current packet " << currentPacket << " Wrong packet number " << ipnum << ", copying blank packet" << endl;
|
||||
memcpy(retval+offsetdest,blackpacket,oneDataSize);
|
||||
offsetdest += oneDataSize;
|
||||
//no need to increase offsetsrc until we get the right packet
|
||||
currentPacket--;
|
||||
continue;
|
||||
}
|
||||
offsetsrc+=JFRAU_HEADER_LENGTH;
|
||||
memcpy(retval+offsetdest,origVal+offsetsrc,oneDataSize);
|
||||
offsetdest += oneDataSize;
|
||||
offsetsrc += oneDataSize;
|
||||
currentPacket--;
|
||||
}
|
||||
|
||||
|
||||
acquisitionIndex = (int)(currentIndex-startAcquisitionIndex);
|
||||
if(acquisitionIndex == -1)
|
||||
startFrameIndex = -1;
|
||||
else
|
||||
frameIndex = (int)(currentIndex-startFrameIndex);
|
||||
#ifdef VERY_VERY_DEBUG
|
||||
cout << "acquisitionIndex calculated is:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex calculated is:" << frameIndex << endl;
|
||||
cout << "currentIndex:" << currentIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
if(frameIndex!=-1){
|
||||
cout << "fName:" << fName << endl;
|
||||
cout << "acquisitionIndex:" << acquisitionIndex << endl;
|
||||
cout << "frameIndex:" << frameIndex << endl;
|
||||
cout << "startAcquisitionIndex:" << startAcquisitionIndex << endl;
|
||||
cout << "startFrameIndex:" << startFrameIndex << endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
if(ret==OK && mySock->differentClients){
|
||||
FILE_LOG(logDEBUG) << "Force update";
|
||||
ret=FORCE_UPDATE;
|
||||
}
|
||||
|
||||
// send answer
|
||||
mySock->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret==FAIL){
|
||||
cprintf(RED,"%s\n",mess);
|
||||
mySock->SendDataOnly(mess,sizeof(mess));
|
||||
}
|
||||
else{
|
||||
mySock->SendDataOnly(fName,MAX_STR_LENGTH);
|
||||
mySock->SendDataOnly(&acquisitionIndex,sizeof(acquisitionIndex));
|
||||
mySock->SendDataOnly(&frameIndex,sizeof(frameIndex));
|
||||
mySock->SendDataOnly(retval,dataSize);
|
||||
}
|
||||
|
||||
delete [] retval;
|
||||
delete [] origVal;
|
||||
delete [] raw;
|
||||
|
||||
return ret;
|
||||
}
|
||||
int slsReceiverTCPIPInterface::jungfrau_read_frame(){ return FAIL;}
|
||||
|
||||
|
||||
|
||||
@ -2703,16 +1794,6 @@ int slsReceiverTCPIPInterface::set_dynamic_range() {
|
||||
retval = receiverBase->getDynamicRange();
|
||||
if(dr > 0 && retval != dr)
|
||||
ret = FAIL;
|
||||
else{
|
||||
dynamicrange = retval;
|
||||
if(myDetectorType == EIGER){
|
||||
if(!tenGigaEnable)
|
||||
packetsPerFrame = EIGER_ONE_GIGA_CONSTANT * dynamicrange;
|
||||
else
|
||||
packetsPerFrame = EIGER_TEN_GIGA_CONSTANT * dynamicrange;
|
||||
}else if (myDetectorType == JUNGFRAU)
|
||||
packetsPerFrame = JFRAU_PACKETS_PER_FRAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user