AlcapDAQ  1
Functions
Functions.c File Reference
#include "keyb.h"
#include "Functions.h"
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <ctype.h>
#include <sys/time.h>

Go to the source code of this file.

Functions

long get_time ()
 Get time in milliseconds. More...
 
int DataConsistencyCheck (uint32_t *buff32, int NumWords)
 Do some data consistency check. More...
 
int SaveHistogram (char *basename, int b, int ch, uint32_t *EHisto)
 
int SaveWaveform (int b, int ch, int trace, int size, int16_t *WaveData)
 
int SaveDigitalProbe (int b, int ch, int trace, int size, uint8_t *WaveData)
 Save Digital Waveforms to output file. More...
 
void PrintInterface ()
 Print the interface to screen. More...
 

Function Documentation

int DataConsistencyCheck ( uint32_t *  buff32,
int  NumWords 
)

Do some data consistency check.

Returns
0=success; -1=error

Definition at line 64 of file Functions.c.

References i, and printf().

65 {
66  int i, zcnt=0, pnt=0;
67  uint32_t EventSize;
68 
69  if (NumWords == 0)
70  return 0;
71 
72  // Check for events integrity
73  do {
74  EventSize = buff32[pnt] & 0x0FFFFFFF;
75  pnt += EventSize; // Jump to next event
76  } while (pnt<NumWords);
77  if (pnt != NumWords) {
78  printf("Data Error: Event truncation\n");
79  return -1;
80  }
81 
82  // Check for burst of zeroes (more than 2 consecutive zeroes)
83  for(i=0; i<NumWords; i++) {
84  if (buff32[i] == 0) zcnt++;
85  else zcnt=0;
86  if (zcnt > 2) {
87  printf("Data Error: Burst of zeroes\n");
88  return -1;
89  }
90  }
91  return 0;
92 }
long get_time ( )

Get time in milliseconds.

Returns
time in msec
Note
TERMS OF USE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. The user relies on the software, documentation and results solely at his own risk.
Returns
time in msec

Definition at line 43 of file Functions.c.

Referenced by A3818UpgradeFromFile(), A3818UpgradeFromMem(), and main().

44 {
45  long time_ms;
46 #ifdef WIN32
47  struct _timeb timebuffer;
48  _ftime( &timebuffer );
49  time_ms = (long)timebuffer.time * 1000 + (long)timebuffer.millitm;
50 #else
51  struct timeval t1;
52  struct timezone tz;
53  gettimeofday(&t1, &tz);
54  time_ms = (t1.tv_sec) * 1000 + t1.tv_usec / 1000;
55 #endif
56  return time_ms;
57 }
void PrintInterface ( )

Print the interface to screen.

Returns
none /* ------------------------------------------------------------------------------------------------------—

Definition at line 177 of file Functions.c.

References printf().

Referenced by main().

177  {
178  printf("\ns ) Start acquisition\n");
179  printf("S ) Stop acquisition\n");
180  printf("r ) Restart acquisition\n");
181  printf("q ) Quit\n");
182  printf("t ) Send a software trigger\n");
183  printf("h ) Save Histograms to file\n");
184  printf("w ) Save waveforms to file\n\n\n");
185 }
int SaveDigitalProbe ( int  b,
int  ch,
int  trace,
int  size,
uint8_t *  WaveData 
)

Save Digital Waveforms to output file.

Returns
0=success; -1=error

Definition at line 153 of file Functions.c.

References i, size, and sprintf().

Referenced by main().

154 {
155  /*
156  This function saves the digital waveform in a textfile as a sequence of number representing the wave height
157  */
158  FILE *fh;
159  int i;
160  char filename[20];
161 
162  sprintf(filename, "DWaveform_%d_%d_%d.txt", b, ch, trace);
163  fh = fopen(filename, "w");
164  if (fh == NULL)
165  return -1;
166  for(i=0; i<size; i++)
167  fprintf(fh, "%d\n", WaveData[i]); //&((1<<MAXNBITS)-1)
168  fclose(fh);
169  return 0;
170 }
int SaveHistogram ( char *  basename,
int  b,
int  ch,
uint32_t *  EHisto 
)

Definition at line 101 of file Functions.c.

References i, printf(), and sprintf().

Referenced by main().

102 {
103  /*
104  This function saves the first 10000 bin of each EHisto[ch] array in separate text files
105  each array value is a number representing the histogram height in the corresponding bin
106  NB: each EHisto[ch] must be a pointer already initialized with at least 10000 values
107  */
108  FILE *fh;
109  int i;
110  char filename[20];
111  sprintf(filename, "%s_%d_%d.txt", basename, b, ch);
112  fh = fopen(filename, "w");
113  if (fh == NULL)
114  return -1;
115  for(i=0; i<(1<<12); i++) {
116  fprintf(fh, "%d\n", EHisto[i]);
117  }
118  fclose(fh);
119  printf("Histograms saved to '%s_<board>_<channel>.txt'\n", basename);
120 
121  return 0;
122 }
int SaveWaveform ( int  b,
int  ch,
int  trace,
int  size,
int16_t *  WaveData 
)

Definition at line 129 of file Functions.c.

References i, size, and sprintf().

Referenced by main().

130 {
131  /*
132  This function saves the waveform in a textfile as a sequence of number representing the wave height
133  */
134  FILE *fh;
135  int i;
136  char filename[20];
137 
138  sprintf(filename, "Waveform_%d_%d_%d.txt", b, ch, trace);
139  fh = fopen(filename, "w");
140  if (fh == NULL)
141  return -1;
142  for(i=0; i<size; i++)
143  fprintf(fh, "%d\n", WaveData[i]); //&((1<<MAXNBITS)-1)
144  fclose(fh);
145  return 0;
146 }