| 1 |
pamelats |
1.1 |
#include "Digitizer.h" |
| 2 |
|
|
|
| 3 |
|
|
|
| 4 |
|
|
void Digitizer::DigitizePSCU(UInt_t length, UChar_t type, UShort_t *pPSCU) { |
| 5 |
|
|
// |
| 6 |
|
|
UChar_t buff[16]; |
| 7 |
|
|
// |
| 8 |
|
|
// CPU signature |
| 9 |
|
|
// |
| 10 |
|
|
buff[0] = 0xFA; |
| 11 |
|
|
buff[1] = 0xFE; |
| 12 |
|
|
buff[2] = 0xDE; |
| 13 |
|
|
// |
| 14 |
|
|
// packet type (twice) |
| 15 |
|
|
// |
| 16 |
|
|
buff[3] = type; |
| 17 |
|
|
buff[4] = type; |
| 18 |
|
|
// |
| 19 |
|
|
// counter |
| 20 |
|
|
// |
| 21 |
|
|
fCounter++; |
| 22 |
|
|
while ( fCounter > 16777215 ){ |
| 23 |
|
|
fCounter -= 16777215; |
| 24 |
|
|
}; |
| 25 |
|
|
// |
| 26 |
|
|
buff[5] = (UChar_t)(fCounter >> 16); |
| 27 |
|
|
buff[6] = (UChar_t)(fCounter >> 8); |
| 28 |
|
|
buff[7] = (UChar_t)fCounter; |
| 29 |
|
|
// |
| 30 |
|
|
// on board time |
| 31 |
|
|
// |
| 32 |
|
|
ULong64_t obt = fOBT + 30LL; |
| 33 |
|
|
// |
| 34 |
|
|
while ( obt > 4294967295LL ){ |
| 35 |
|
|
obt -= 4294967295LL; |
| 36 |
|
|
}; |
| 37 |
|
|
fOBT = (UInt_t)obt; |
| 38 |
|
|
// |
| 39 |
|
|
buff[8] = (UChar_t)(fOBT >> 24); |
| 40 |
|
|
buff[9] = (UChar_t)(fOBT >> 16); |
| 41 |
|
|
buff[10] = (UChar_t)(fOBT >> 8); |
| 42 |
|
|
buff[11] = (UChar_t)fOBT; |
| 43 |
|
|
// |
| 44 |
|
|
// Packet length |
| 45 |
|
|
// |
| 46 |
|
|
fLen = length; |
| 47 |
|
|
// |
| 48 |
|
|
buff[12] = (UChar_t)(fLen >> 16); |
| 49 |
|
|
buff[13] = (UChar_t)(fLen >> 8); |
| 50 |
|
|
buff[14] = (UChar_t)fLen; |
| 51 |
|
|
// |
| 52 |
|
|
// CPU header CRC |
| 53 |
|
|
// |
| 54 |
|
|
buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15); |
| 55 |
|
|
// |
| 56 |
|
|
//memcpy(fDataPSCU,buff,16*sizeof(UChar_t)); |
| 57 |
|
|
memcpy(pPSCU,buff,16*sizeof(UChar_t)); |
| 58 |
|
|
// |
| 59 |
|
|
}; |
| 60 |
|
|
void Digitizer::AddPadding(){ |
| 61 |
|
|
// |
| 62 |
|
|
Float_t pd0 = (fLen+16)/64.; |
| 63 |
|
|
Float_t pd1 = pd0 - (Float_t)int(pd0); |
| 64 |
|
|
Float_t padfrac = 64. - pd1 * 64.; |
| 65 |
|
|
// |
| 66 |
|
|
UInt_t padbytes = (UInt_t)padfrac; |
| 67 |
|
|
if ( padbytes > 0 && padbytes < 64 ){ |
| 68 |
|
|
// |
| 69 |
|
|
// here the padding length |
| 70 |
|
|
// |
| 71 |
|
|
fPadding = padbytes+64; |
| 72 |
|
|
// |
| 73 |
|
|
// random padding bytes |
| 74 |
|
|
// |
| 75 |
|
|
for (Int_t ur=0; ur<32; ur++){ |
| 76 |
|
|
fDataPadding[ur] = (UShort_t)rand(); |
| 77 |
|
|
}; |
| 78 |
|
|
}; |
| 79 |
|
|
}; |