--- rawreader/src/RunHeaderReader.cpp 2006/12/10 13:05:58 1.2 +++ rawreader/src/RunHeaderReader.cpp 2007/01/28 10:55:49 1.3 @@ -1,115 +1,122 @@ -//mikhailov : -//reading and updating of time sync information +//mikhailov : +//reading and updating of time sync information -#include "descript.h" -#include "CRC.h" -//int RTtoMT,RT,Timesync,OBTtimesync; // Resurs time to moscow, Resurs time, ... - -extern int print_flag; -extern long int Timesync; -extern long int OBTtimesync; -void RunHeaderReader(char *packet) - { - -//char *packet=new char[Nmax]; - //unsigned int type=0; /*PAMELA packet type*/ -// unsigned int error=0;/*PAMELA packet error flag*/ - //int Length=0; /*Length of filename*/ -// long int counter[26];/*Counter for PAMELA packets in each dat file*/ -// unsigned long int adr1=0;/*First byte of PAMELA packet in _cln2.pam*/ - //unsigned long int adr2=0;/*Last byte of PAMELA packet in _cln2.pam*/ - long int time=0; /*PAMELA packet time*/ -// long int first[26]; /*First byte for PAMELA packets of given type*/ -// long int last[26]; /*Last byte for PAMELA packets of given type*/ - long int temp=0; - //int type; -// int packet_type; - char *subData; -// char eventCRC[2]; - int j; - FILE *ftime_sync; - unsigned short calCRC; //calculated CRC of the data - unsigned short readCRC; //CRC read from the end of the subpacket - long int dataLength; - long int length; - long int RM_ACQ_SETTING_MODE,OBT_TIME_SYNC, - LAST_TYME_SYNC_INFO, - FAVOURITE_WORKING_SCHEDULE, - EFFECTIVE_WORKING_SCHEDULE, - PRH_VAR_TRIGGER_MODE_A, - PRH_VAR_TRIGGER_MODE_B, - RM_ACQ_AFTER_CALIB ; - time=(long int)(unsigned char)(packet[11])+ - 256*(long int)(unsigned char)(packet[10])+ - 256*256*(long int)(unsigned char)(packet[9])+ - 256*256*256*(long int)(unsigned char)(packet[8]); - - temp=(long int)(unsigned char)(packet[7])+ - 256*(long int)(unsigned char)(packet[6])+ - 256*256*(long int)(unsigned char)(packet[5]); - if ((fmod((float)(temp),(float)(10000.))==0.)&&(print_flag>0)) cout<<"sorting "<read(subData, sizeof(unsigned char)*dataLength); */ - - calCRC = CM_Compute_CRC16(0, (unsigned char*)subData, dataLength); - if (print_flag>0) printf("crc %x %x\n",calCRC,readCRC); - //took the final CRC to compare it with the previous calculated CRC of the data - -// for(j=0;j0)) {cout<0) cout<0)cout<<"length="<read(subData, sizeof(subData)); + + for (j=0;j0) printf("crc Cal Read %x %x %x\n",calCRC,readCRC,(((UINT16)subData[length-1])&0x00FF)); -// mikhailov 06.12.2004 - ftime_sync=fopen("timesync.dat","a+"); - Timesync=LAST_TYME_SYNC_INFO; - OBTtimesync=OBT_TIME_SYNC; -extern long int RTtoMT; -extern long int RT; - fprintf(ftime_sync,"%u %u %u %u\n",RTtoMT,RT,OBTtimesync,Timesync); - // read for initial information for time synchronization - if (print_flag>0) - {cout<0) printf("crc %x %x\n",calCRC,readCRC); + //took the final CRC to compare it with the previous calculated CRC of the data -} + +// cout<0) cout<0){ for (k=0;k<8;k++) cout<<(UINT32)packet[k+5+16]<<"\n";}; +k=16; + OBT_TIME_SYNC = (((UINT32)packet[5+k]<<24)&0xFF000000) + (((UINT32)packet[6+k]<<16)&0x00FF0000) + (((UINT32)packet[7+k]<<8)&0x0000FF00) + (((UINT32)packet[8+k])&0x000000FF); + LAST_TYME_SYNC_INFO = (((UINT32)packet[9+k]<<24)&0xFF000000) + (((UINT32)packet[10+k]<<16)&0x00FF0000) + (((UINT32)packet[11+k]<<8)&0x0000FF00) + (((UINT32)packet[12+k])&0x000000FF); +// FAVOURITE_WORKING_SCHEDULE = (BYTE)packet[25]; +// EFFECTIVE_WORKING_SCHEDULE = (BYTE)packet[26]; +// PRH_VAR_TRIGGER_MODE_A = (((UINT32)packet[27]<<24)&0xFF000000) + (((UINT32)packet[28]<<16)&0x00FF0000) + (((UINT32)packet[29]<<8)&0x0000FF00) + (((UINT32)packet[30])&0x000000FF); +// PRH_VAR_TRIGGER_MODE_B = (((UINT32)packet[31]<<24)&0xFF000000) + (((UINT32)packet[32]<<16)&0x00FF0000) + (((UINT32)packet[33]<<8)&0x0000FF00) + (((UINT32)packet[34])&0x000000FF); +// RM_ACQ_AFTER_CALIB = (BYTE)packet[35]; +// if (print_flag>0) cout<OBT_TIME_SYNC = (((UINT32)subData[5]<<24)&0xFF000000) + (((UINT32)subData[6]<<16)&0x00FF0000) + (((UINT32)subData[7]<<8)&0x0000FF00) + (((UINT32)subData[8])&0x000000FF); +// RunHeader->LAST_TIME_SYNC_INFO = (((UINT32)subData[9]<<24)&0xFF000000) + (((UINT32)subData[10]<<16)&0x00FF0000) + (((UINT32)subData[11]<<8)&0x0000FF00) + (((UINT32)subData[12])&0x000000FF); + +// mikhailov 06.12.2004 + if ((ftime_sync=fopen(timesync,"a+"))==NULL) + { + printf("Can not open timesync.dat file. \n"); + exit(1); + } + Timesync=LAST_TYME_SYNC_INFO; + OBTtimesync=OBT_TIME_SYNC; +extern long int RTtoMT; +extern long int RT; + fprintf(ftime_sync,"%u %u %u %u\n",RTtoMT,RT,OBTtimesync,Timesync); + // read for initial information for time synchronization + if (print_flag>0) + {cout<