18 void nfadc_dump(
int num_fadc_words,
unsigned char *data);
26 int size =
sizeof(BOOL);
28 &size, TID_BOOL,
TRUE);
33 int num_words = input_size/10;
37 int last_timestamp = -2;
40 int island_timestamp = -1;
41 int last_island_timestamp = 0;
42 for(
int j = 0; j < num_words; j++) {
44 int adc = (input[j*10+0] >> 7) & 0x01;
46 int timestamp = ((input[j*10+0] & 0x7f) << 20) |
47 (input[j*10+1] << 12) |
48 (input[j*10+2] << 4) |
50 if(boardNumber < 128) {
54 if(timestamp != last_timestamp + 1 || adc != last_adc || run_length == 255) {
55 if(island_timestamp != -1) {
62 island_timestamp = timestamp;
67 last_timestamp = timestamp;
72 if(island_timestamp != -1) {
80 for(
int j = 0; j < num_words; j++) {
82 bool overflowB0 = ((input[j*10+3] & 0x08) != 0);
83 bool overflowA0 = ((input[j*10+3] & 0x04) != 0);
84 bool overflowB1 = ((input[j*10+3] & 0x02) != 0);
85 bool overflowA1 = ((input[j*10+3] & 0x01) != 0);
86 sample[3] = (overflowB0 << 12) | (input[j*10+4] << 4) | (input[j*10+5] >> 4);
87 sample[2] = (overflowA0 << 12) | ((input[j*10+5] & 0xf) << 8) | (input[j*10+6]);
88 sample[1] = (overflowB1 << 12) | (input[j*10+7] << 4) | (input[j*10+8] >> 4);
89 sample[0] = (overflowA1 << 12) | ((input[j*10+8] & 0xf) << 8) | (input[j*10+9]);
91 for(
int k = 0; k < 4; k++) {
92 int diff = sample[k] - lastSample;
93 lastSample = sample[k];
96 if(diff <= 7 && diff >= -7) {
108 int nfadc_compress(
unsigned char *input,
int input_size,
unsigned char *output,
int userParam)
113 int *uncompressed_size_p = (
int *) output;
114 *uncompressed_size_p = input_size;
115 output +=
sizeof(int);
119 int compressed_size =
encode_nfadc(input, input_size, &output_buffer, userParam);
120 output += compressed_size;
122 return compressed_size +
sizeof(int);
127 int num_fadc_words = input_size/10;
131 while(j < num_fadc_words) {
137 for(
int k = 0; k < run_length; k++) {
138 int t2 = timestamp + k;
139 if(boardNumber < 128) {
142 output[(j+k)*10+0] = (adc << 7) | ((t2 >> 20) & 0x7f);
143 output[(j+k)*10+1] = (t2 >> 12) & 0xff;
144 output[(j+k)*10+2] = (t2 >> 4) & 0xff;
145 output[(j+k)*10+3] = (t2 & 0xf) << 4;
153 for(
int j = 0; j < num_fadc_words; j++) {
155 for(
int k = 0; k < 4; k++) {
157 if(encodedDiff == 0) {
160 sample[k] = lastSample + encodedDiff - 8;
162 lastSample = sample[k];
165 int overflows = ((sample[0] & 0x1000) ? 0x01 : 0) |
166 ((sample[1] & 0x1000) ? 0x02 : 0) |
167 ((sample[2] & 0x1000) ? 0x04 : 0) |
168 ((sample[3] & 0x1000) ? 0x08 : 0);
169 output[j*10+3] |= overflows;
170 output[j*10+4] = (sample[3] >> 4) & 0xff;
171 output[j*10+5] = ((sample[3] & 0xf) << 4) | ((sample[2] >> 8) & 0xf);
172 output[j*10+6] = (sample[2] & 0xff);
173 output[j*10+7] = (sample[1] >> 4) & 0xff;
174 output[j*10+8] = ((sample[1] & 0xf) << 4) | ((sample[0] >> 8) & 0xf);
175 output[j*10+9] = (sample[0] & 0xff);
181 int nfadc_expand(
unsigned char *input,
int input_size,
unsigned char * output,
int userParam)
188 int *uncompressed_size_p = (
int *) input;
189 int uncompressed_size = *uncompressed_size_p;
190 input +=
sizeof(int);
191 input_size -=
sizeof(int);
196 decode_nfadc(&input_buffer, output, uncompressed_size, userParam);
198 return uncompressed_size;
203 for(
int i = 0;
i < num_fadc_words;
i++) {
205 for(
int j = 0; j < 10; j++) {