Exemplo n.º 1
0
int sendRawWaveformPackets(int bufSize) 
{
    static int errorCounter=0;
    int retVal;
    if(bufSize!=sizeof(AnitaEventBody_t)) {
	if(errorCounter<100) {
	  syslog(LOG_ERR,"Buffer size %d, expected %u -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
	  fprintf(stderr,"Buffer size %d, expected %u -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
	    errorCounter++;
	}
	return -1;
    }
    AnitaEventBody_t *bdPtr = (AnitaEventBody_t*) theBuffer;
    int chan;
    RawWaveformPacket_t *wvPtr;
    for(chan=0;chan<NUM_DIGITZED_CHANNELS;chan++) {
	wvPtr=(RawWaveformPacket_t*) chanBuffer;
	wvPtr->eventNumber=bdPtr->eventNumber;
	memcpy(&(wvPtr->waveform),&(bdPtr->channel[chan]),sizeof(SurfChannelFull_t));
	wvPtr->gHdr.packetNumber=getOpenportNumber();
	fillGenericHeader(wvPtr,PACKET_WV,sizeof(RawWaveformPacket_t));
	retVal = openportWrite(chanBuffer,sizeof(RawWaveformPacket_t),0);
	eventDataSent+=sizeof(RawWaveformPacket_t);
	if(retVal<0) {
	    //Problem sending data
	    if(errorCounter<100) {
		syslog(LOG_ERR,"Problem sending event %u over OPENPORT high rate\n",bdPtr->eventNumber);
		errorCounter++;
	    }
	    fprintf(stderr,"Problem sending event %u over OPENPORT high rate \n",bdPtr->eventNumber);
	}
    }
    return retVal;
}
Exemplo n.º 2
0
int sendRawSurfPackets(int bufSize) 
{
    static int errorCounter=0;
    int retVal;
    if(bufSize!=sizeof(AnitaEventBody_t)) {
	if(errorCounter<100) {
	    syslog(LOG_ERR,"Buffer size %d, expected %u -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
	    fprintf(stderr,"Buffer size %d, expected %u -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
	    errorCounter++;
	}
	return -1;
    }
    AnitaEventBody_t *bdPtr = (AnitaEventBody_t*) theBuffer;
    int surf;
    RawSurfPacket_t *surfPtr;
    for(surf=0;surf<ACTIVE_SURFS;surf++) {
	surfPtr=(RawSurfPacket_t*) chanBuffer;
	surfPtr->eventNumber=bdPtr->eventNumber;	
	memcpy(&(surfPtr->waveform[0]),&(bdPtr->channel[CHANNELS_PER_SURF*surf]),sizeof(SurfChannelFull_t)*CHANNELS_PER_SURF);

	surfPtr->gHdr.packetNumber=getOpenportNumber();
	fillGenericHeader(surfPtr,PACKET_SURF,sizeof(RawSurfPacket_t));
	retVal = openportWrite(chanBuffer,sizeof(RawSurfPacket_t),0);
	eventDataSent+=sizeof(RawSurfPacket_t);
	if(retVal<0) {
	    //Problem sending data
	    if(errorCounter<100) {
		syslog(LOG_ERR,"Problem sending event %u over Openport\n",bdPtr->eventNumber);
		errorCounter++;
	    }
	    fprintf(stderr,"Problem sending event %u over Openport\n",bdPtr->eventNumber);
	}
    }
    return retVal;
}
Exemplo n.º 3
0
int sendPedSubbedSurfPackets(int bufSize) 
{
  if(bufSize!=sizeof(PedSubbedEventBody_t)) {
    syslog(LOG_ERR,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t));
    fprintf(stderr,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t));
    return -1;
  }
  PedSubbedEventBody_t *bdPtr = (PedSubbedEventBody_t*) eventBuffer;
  int surf;
  PedSubbedSurfPacket_t *surfPtr;
  int numBytes=sizeof(PedSubbedSurfPacket_t);
  for(surf=0;surf<ACTIVE_SURFS;surf++) {
    if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) {
      doWrite();
    }
    surfPtr=(PedSubbedSurfPacket_t*) &losBuffer[numBytesInBuffer];
    surfPtr->eventNumber=bdPtr->eventNumber;	
    surfPtr->whichPeds=bdPtr->whichPeds;	
    memcpy(&(surfPtr->waveform[0]),&(bdPtr->channel[CHANNELS_PER_SURF*surf]),sizeof(SurfChannelPedSubbed_t)*CHANNELS_PER_SURF);
    surfPtr->gHdr.packetNumber=getLosNumber();
    fillGenericHeader(surfPtr,PACKET_PEDSUB_SURF,sizeof(PedSubbedSurfPacket_t));
    numBytesInBuffer+=sizeof(PedSubbedSurfPacket_t);
  }
  return 0;
}
Exemplo n.º 4
0
int sendPedSubbedWaveformPackets(int bufSize) 
{
  if(bufSize!=sizeof(PedSubbedEventBody_t)) {
    syslog(LOG_ERR,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t));
    fprintf(stderr,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(PedSubbedEventBody_t));
  }
  PedSubbedEventBody_t *bdPtr = (PedSubbedEventBody_t*) eventBuffer;
  int chan;
  PedSubbedWaveformPacket_t *wvPtr;
  int numBytes=sizeof(PedSubbedWaveformPacket_t);
  for(chan=0;chan<NUM_DIGITZED_CHANNELS;chan++) {
    if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) {
      doWrite();
    }
    wvPtr=(PedSubbedWaveformPacket_t*) &losBuffer[numBytesInBuffer];
    wvPtr->eventNumber=bdPtr->eventNumber;
    wvPtr->whichPeds=bdPtr->whichPeds;
    memcpy(&(wvPtr->waveform),&(bdPtr->channel[chan]),sizeof(SurfChannelPedSubbed_t));
    wvPtr->gHdr.packetNumber=getLosNumber();
    fillGenericHeader(wvPtr,PACKET_PEDSUB_WV,sizeof(PedSubbedWaveformPacket_t));
    //	printf("%#x %d\n",wvPtr->gHdr.code,wvPtr->gHdr.numBytes);
    numBytesInBuffer+=sizeof(PedSubbedWaveformPacket_t);
  }
  return 0;
}
Exemplo n.º 5
0
int sendEncodedPedSubbedWavePackets(int bufSize) 
{
    static int errorCounter=0;
    EncodedPedSubbedChannelPacketHeader_t *waveHdPtr;    
    EncodedPedSubbedSurfPacketHeader_t *surfHdPtr;  
    EncodedSurfChannelHeader_t *chanHdPtr;
    EncodedSurfChannelHeader_t *chanHdPtr2;
    int numBytes,count=0,surf=0,retVal,chan,count2=0;
    int chanNumBytes=0;
    // Remember what the file contains is actually 10 EncodedPedSubbedSurfPacketHeader_t's
//    count=0;
    count=sizeof(EncodedEventWrapper_t);
    for(surf=0;surf<ACTIVE_SURFS;surf++) {
	surfHdPtr = (EncodedPedSubbedSurfPacketHeader_t*) &theBuffer[count];
//	surfHdPtr->gHdr.packetNumber=getOpenportNumber();
	numBytes = surfHdPtr->gHdr.numBytes;
	count2=count+sizeof(EncodedPedSubbedSurfPacketHeader_t);
	if(numBytes) {	    
	    for(chan=0;chan<CHANNELS_PER_SURF;chan++) {
		chanNumBytes=0;
		chanHdPtr = (EncodedSurfChannelHeader_t*) &theBuffer[count2];
		waveHdPtr= (EncodedPedSubbedChannelPacketHeader_t*) &chanBuffer[0];
		waveHdPtr->gHdr.packetNumber=getOpenportNumber();
		waveHdPtr->eventNumber=surfHdPtr->eventNumber;
		waveHdPtr->whichPeds=surfHdPtr->whichPeds;
		chanNumBytes=sizeof(EncodedPedSubbedChannelPacketHeader_t);
		chanHdPtr2 = (EncodedSurfChannelHeader_t*) &chanBuffer[chanNumBytes];
		(*chanHdPtr2)=(*chanHdPtr);
		count2+=sizeof(EncodedSurfChannelHeader_t);
		chanNumBytes+=sizeof(EncodedSurfChannelHeader_t);
		memcpy(&chanBuffer[chanNumBytes],&theBuffer[count2],chanHdPtr->numBytes);
		chanNumBytes+=chanHdPtr->numBytes;
		fillGenericHeader(waveHdPtr,PACKET_ENC_WV_PEDSUB,chanNumBytes);
		retVal = openportWrite(chanBuffer,chanNumBytes,0);
		eventDataSent+=chanNumBytes;
		if(retVal<0) {
		    //Problem sending data
		    if(errorCounter<100) {
			syslog(LOG_ERR,"Problem sending event %u over OPENPORT high rate \n",surfHdPtr->eventNumber);
			errorCounter++;
		    }
		    fprintf(stderr,"Problem sending event %u over OPENPORT high rate \n",surfHdPtr->eventNumber);
		}
	    }		
	    count+=numBytes;

	}
	else break;
	if(count>bufSize) return -1;
    }
    return 0;
}
Exemplo n.º 6
0
void sendWakeUpBuffer() 
{
  GenericHeader_t *gHdr = (GenericHeader_t*) &losBuffer[0];
  int count;
  for(count=sizeof(GenericHeader_t);count<WAKEUP_LOS_BUFFER_SIZE;count++) {
    losBuffer[count]=0xfe;
  }
  fillGenericHeader(gHdr,PACKET_WAKEUP_LOS,WAKEUP_LOS_BUFFER_SIZE);
  gHdr->packetNumber=getLosNumber();
  numBytesInBuffer=WAKEUP_LOS_BUFFER_SIZE;
  doWrite();
    
}
Exemplo n.º 7
0
int sendEncodedPedSubbedWavePackets(int bufSize)
{
  EncodedPedSubbedChannelPacketHeader_t *waveHdPtr;
  EncodedPedSubbedSurfPacketHeader_t *surfHdPtr;
  int numBytes,count=0,surf=0,chan,count2;;
  EncodedSurfChannelHeader_t *chanHdPtr;
  EncodedSurfChannelHeader_t *chanHdPtr2;

  count+=sizeof(EncodedEventWrapper_t);

  // Remember what the file contains is actually 9 EncodedPedSubbedSurfPacketHeader_t's
  for(surf=0;surf<ACTIVE_SURFS;surf++) {
    surfHdPtr = (EncodedPedSubbedSurfPacketHeader_t*) &eventBuffer[count];
    //	printf("surfHdPtr.eventNumber %u, numBytes %d (%d)\n",surfHdPtr->eventNumber,numBytes,numBytesInBuffer);
    count2=count+sizeof(EncodedPedSubbedSurfPacketHeader_t);
    for(chan=0;chan<CHANNELS_PER_SURF;chan++) {
      chanHdPtr = (EncodedSurfChannelHeader_t*)&eventBuffer[count2];
		    
      //	    printf("surf %d, chan %d, encType %d, numBytes %d\n",
      //		   surf,chan,chanHdPtr->encType,chanHdPtr->numBytes);
      numBytes=chanHdPtr->numBytes;
      //	    printf("%d %d %d\n",numBytesInBuffer,LOS_MAX_BYTES,numBytes);
      if((numBytesInBuffer+numBytes+sizeof(EncodedPedSubbedSurfPacketHeader_t)+sizeof(EncodedSurfChannelHeader_t))>LOS_MAX_BYTES) {
	doWrite();
      }
      //	    if((LOS_MAX_BYTES-numBytesInBuffer)<(numBytes+sizeof(EncodedSurfChannelHeader_t))) {		
      //		doWrite();
      //	    }
      waveHdPtr=(EncodedPedSubbedChannelPacketHeader_t*)&losBuffer[numBytesInBuffer];
      waveHdPtr->gHdr.packetNumber=getLosNumber();
      waveHdPtr->eventNumber=surfHdPtr->eventNumber;
      waveHdPtr->whichPeds=surfHdPtr->whichPeds;
      numBytesInBuffer+=sizeof(EncodedPedSubbedChannelPacketHeader_t);
      chanHdPtr2= (EncodedSurfChannelHeader_t*)&losBuffer[numBytesInBuffer];
      (*chanHdPtr2)=(*chanHdPtr);
      numBytesInBuffer+=sizeof(EncodedSurfChannelHeader_t);
      count2+=sizeof(EncodedSurfChannelHeader_t);
      memcpy(&losBuffer[numBytesInBuffer],&eventBuffer[count2],numBytes);
      fillGenericHeader(waveHdPtr,PACKET_ENC_WV_PEDSUB,sizeof(EncodedPedSubbedChannelPacketHeader_t)+sizeof(EncodedSurfChannelHeader_t)+numBytes);
      count2+=chanHdPtr->numBytes;
      numBytesInBuffer+=numBytes;
    }
    if(surfHdPtr->gHdr.numBytes>0) {
      count+=surfHdPtr->gHdr.numBytes;
    }
    else break;
    if(count>bufSize) return -1;
  }
  return 0;
}
Exemplo n.º 8
0
int writeFileAndLink(GpuPhiSectorPowerSpectrumStruct_t* payloadPowSpec, int phi) {
    char theFilename[FILENAME_MAX];
    int retVal=0;
    
    fillGenericHeader(payloadPowSpec,PACKET_GPU_AVE_POW_SPEC,sizeof(GpuPhiSectorPowerSpectrumStruct_t));
    
    sprintf(theFilename,"%s/gpuPowSpec_%u_phi%d.dat",
	    GPU_TELEM_DIR,payloadPowSpec->unixTimeFirstEvent,phi);
    retVal=writeStruct(payloadPowSpec,theFilename,sizeof(GpuPhiSectorPowerSpectrumStruct_t));
    retVal=makeLink(theFilename,GPU_TELEM_LINK_DIR);

    retVal=cleverHkWrite((unsigned char*)payloadPowSpec,sizeof(GpuPhiSectorPowerSpectrumStruct_t),
			 payloadPowSpec->unixTimeFirstEvent,&gpuWriter);
    printf("cleverHkWrite for fileName %s returned %d\n", theFilename, retVal);

    if(retVal<0) {
	//Had an error
    }
    
    return retVal;
}
Exemplo n.º 9
0
int sendRawWaveformPackets(int bufSize) 
{
  if(bufSize!=sizeof(AnitaEventBody_t)) {
    syslog(LOG_ERR,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
    fprintf(stderr,"Buffer size %d, expected %d -- Bailing\n",bufSize,(unsigned int)sizeof(AnitaEventBody_t));
    return -1;
  }
  AnitaEventBody_t *bdPtr = (AnitaEventBody_t*) eventBuffer;
  int chan;
  RawWaveformPacket_t *wvPtr;
  int numBytes=sizeof(RawWaveformPacket_t);
  for(chan=0;chan<NUM_DIGITZED_CHANNELS;chan++) {
    if((LOS_MAX_BYTES-numBytesInBuffer)<numBytes) {
      doWrite();
    }
    wvPtr=(RawWaveformPacket_t*) &losBuffer[numBytesInBuffer];
    wvPtr->eventNumber=bdPtr->eventNumber;
    memcpy(&(wvPtr->waveform),&(bdPtr->channel[chan]),sizeof(SurfChannelFull_t));
    wvPtr->gHdr.packetNumber=getLosNumber();
    fillGenericHeader(wvPtr,PACKET_WV,sizeof(RawWaveformPacket_t));
    numBytesInBuffer+=sizeof(RawWaveformPacket_t);
  }
  return 0;
}
Exemplo n.º 10
0
int outputData(AnalogueCode_t code) 
{
    int retVal;
    char theFilename[FILENAME_MAX];
    char fullFilename[FILENAME_MAX];
    SSHkDataStruct_t theHkData;
    AnitaHkWriterStruct_t *wrPtr;

    static int telemCount=0;


    struct timeval timeStruct;
    gettimeofday(&timeStruct,NULL);
	    
    theHkData.unixTime=timeStruct.tv_sec;;
    theHkData.unixTimeUs=timeStruct.tv_usec;;
    switch(code) {
	case (IP320_RAW):
	    sprintf(theFilename,"sshk_%d_%d.raw.dat",theHkData.unixTime,
		theHkData.unixTimeUs);
	    theHkData.ip320=rawDataStruct;
	    wrPtr=&hkRawWriter;
	    break;
	case(IP320_CAL):
	    sprintf(theFilename,"sshk_%d_%d.cal.dat",theHkData.unixTime,
		    theHkData.unixTimeUs);
	    theHkData.ip320=calDataStruct;
	    wrPtr=&hkCalWriter;
	    break;
	case(IP320_AVZ):
	    sprintf(theFilename,"sshk_%d_%d.avz.dat",theHkData.unixTime,
		    theHkData.unixTimeUs);
	    theHkData.ip320=autoZeroStruct;
//	    printf("First two %d %d\n",theHkData.ip320.board[0].data[0]&0xfff,
//		   theHkData.ip320.board[0].data[0]&0xfff);
	    wrPtr=&hkCalWriter;
	    break;
	default:
	    syslog(LOG_WARNING,"Unknown HK data code: %d",code);
	    if(printToScreen) 
		fprintf(stderr,"Unknown HK data code: %d\n",code);
	    return -1;
    }
	    


    fillGenericHeader(&theHkData,PACKET_HKD_SS,sizeof(SSHkDataStruct_t));

    if(code==IP320_RAW) {
      int chan=0;
      printf("Raw data: ");
      for(chan=0;chan<40;chan++) {
	printf("%d ",rawDataStruct.board.data[chan]);
      }
      printf("\n");
    }


    telemCount++;
    if(telemCount>=telemEvery) {    
	//Write file and make link for SIPd
      if(printToScreen) printf("%s\n",theFilename);
	sprintf(fullFilename,"%s/%s",HK_TELEM_DIR,theFilename);
	retVal=writeStruct(&theHkData,fullFilename,sizeof(SSHkDataStruct_t));     
	retVal+=makeLink(fullFilename,HK_TELEM_LINK_DIR);      
	
	telemCount=0;
    }
    
    //Write file to main disk
    retVal=cleverHkWrite((unsigned char*)&theHkData,sizeof(SSHkDataStruct_t),
			 theHkData.unixTime,wrPtr);
    if(retVal<0) {
	//Had an error
	//Do something
    }	    
    

    return retVal;
}
Exemplo n.º 11
0
void sendEvent(PlaybackRequest_t *pReq)
{
    int retVal=0;
    AnitaEventHeader_t theHead;
    PedSubbedEventBody_t psBody;
    char indexName[FILENAME_MAX];
    char eventFileName[FILENAME_MAX];
    char headerFileName[FILENAME_MAX];
    int dirNum=(EVENTS_PER_FILE*EVENT_FILES_PER_DIR)*(pReq->eventNumber/(EVENTS_PER_FILE*EVENT_FILES_PER_DIR));
    int subDirNum=(EVENTS_PER_FILE*EVENT_FILES_PER_DIR*EVENT_FILES_PER_DIR)*(pReq->eventNumber/(EVENTS_PER_FILE*EVENT_FILES_PER_DIR*EVENT_FILES_PER_DIR));
    int fileNum=(EVENTS_PER_FILE)*(pReq->eventNumber/EVENTS_PER_FILE);

    sprintf(indexName,"/mnt/data/anita/index/ev%d/ev%d/index_%d.dat.gz",subDirNum,dirNum,fileNum);
    
//    syslog(LOG_INFO,"Trying to send event %u, with priority %d\n",
//	   pReq->eventNumber,pReq->pri);
    fprintf(stderr,"Trying to send event %u, with priority %d\n",
	   pReq->eventNumber,pReq->pri);
    
    int numSeek=pReq->eventNumber-fileNum;
    numSeek--;
    gzFile indFile=gzopen(indexName,"rb");
    if(!indFile) {
	fprintf(stderr,"Couldn't open: %s\n",indexName);
	syslog(LOG_ERR,"Couldn't open: %s\n",indexName);
	return;
    }
    
/*     if(numSeek) { */
/* 	gzseek(indFile,numSeek*sizeof(IndexEntry_t),SEEK_SET); */
/*     } */


    IndexEntry_t indEntry;
    int count=0;
    do {
	int test=gzread(indFile,&indEntry,sizeof(IndexEntry_t));
	if(test<0) {
	    fprintf(stderr,"Couldn't read from: %s\n",indexName);
	    syslog(LOG_ERR,"Couldn't read from: %s\n",indexName);
	    
	    gzclose(indFile);
	    return;
	}
//	printf("count %d, index %u\n",count,indEntry.eventNumber);
	count++;
    } while (indEntry.eventNumber!=pReq->eventNumber);
    gzclose(indFile);
//    printf("index: %u -- %#x\n",indEntry.eventNumber,indEntry.eventDiskBitMask);

    //Now have index
    //Here we're going to have to add something that checks if the file we want is on one of the already mounted disks. If it is we'll go ahead and read it from there, if not we'll have to mount the disk specified by usedisk on /mnt/playback and read the file from there
    int diskInd=0;
    int gotDisk=-1;

    for(diskInd=0;diskInd<DISK_TYPES;diskInd++) {
      if(indEntry.eventDiskBitMask & diskBitMasks[diskInd]) {
	//So the event was allegedly written to this disk type
	if(diskInd==0) {
	  gotDisk=0;
	}
	else if(diskInd==1) {
	  gotDisk=1;
	}
	else if(diskInd==2) {
	  if(strncmp(usbName,indEntry.usbLabel,12)==0) {
	    gotDisk=2;
	    break;
	  }
	}
	else if(diskInd==3) {
	  gotDisk=3;
	  break;
	}
      }      
    }

    if(gotDisk==-1) {
      //The file isn't on one of the mounted disks will try and mount
      //a disk on /mnt/playback
      if(useDisk==2)  {
	retVal=cleverMountPlaybackDisk(indEntry.usbLabel);
	if(retVal!=0) {
	  syslog(LOG_ERR,"Error calling cleverMountPlaybackDisk %d\n",retVal);
	}
      	gotDisk=4;
      }
    }


    if(gotDisk>=0 && gotDisk<=4) {
	//Read it from puck
	sprintf(headerFileName,"%s/run%u/event/ev%d/ev%d/hd_%d.dat.gz",
		diskNames[gotDisk],indEntry.runNumber,subDirNum,dirNum,fileNum);
	gzFile headFile = gzopen(headerFileName,"rb");
	if(!headFile) {
	    fprintf(stderr,"Couldn't open: %s\n",headerFileName);	    
	    return;
	}
	int retVal;

	
	if(numSeek) {
	    gzseek(headFile,numSeek*sizeof(AnitaEventHeader_t),SEEK_SET);
	}

	int test=0;
	do {
	    retVal=gzread(headFile,&theHead,sizeof(AnitaEventHeader_t));
	    printf("try %d, head %u\n",test,theHead.eventNumber);
	    test++;
	}
	while(retVal>0 && theHead.eventNumber!=pReq->eventNumber);
	gzclose(headFile);
	if(retVal<0) {
	    fprintf(stderr,"Couldn't find header %u\n",pReq->eventNumber);	    
	    return;
	}

	sprintf(eventFileName,"%s/run%u/event/ev%d/ev%d/psev_%d.dat.gz",
		diskNames[gotDisk],indEntry.runNumber,subDirNum,dirNum,fileNum);
	gzFile eventFile = gzopen(eventFileName,"rb");
	if(!eventFile) {
	    fprintf(stderr,"Couldn't open: %s\n",eventFileName);	    
	    return;
	}
//	int numSeek=pReq->eventNumber-fileNum;
//	numSeek--;
	if(numSeek) {
	    gzseek(eventFile,numSeek*sizeof(PedSubbedEventBody_t),SEEK_SET);
	}
	do {
	    retVal=gzread(eventFile,&psBody,sizeof(PedSubbedEventBody_t));
	}
	while(retVal>0 && psBody.eventNumber!=pReq->eventNumber);	
	gzclose(eventFile);
	if(retVal<0) {
	    fprintf(stderr,"Couldn't find event %u\n",pReq->eventNumber);	    
	    return;
	}
    }

    theHead.priority=((pReq->pri&0xf) | (theHead.priority&0xf0));
    fillGenericHeader(&theHead,PACKET_HD,sizeof(AnitaEventHeader_t));
    printf("head: %u, event: %u\n",theHead.eventNumber,psBody.eventNumber);
//    int samp=0;
//    for(samp=0;samp<260;samp++) {
//	printf("%d --%d\n",samp,psBody.channel[0].data[samp]);
//    }
    //In theory should have header and event now
    encodeAndWriteEvent(&theHead,&psBody, pReq->pri);

}