AlcapDAQ  1
diag.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdarg.h>
3 
4 #include "midas.h"
5 
6 #include "odb_wrapper.h"
7 #include "crate.h"
8 #include "diag.h"
9 
12 
13 time_t last_message_time = 0;
15 
16 /* ******************************************************************* */
17 /*
18  * diag_print_setup
19  *
20  * Reads threshold for diagnostic printout from ODB.
21  */
23 {
24  // Read the diagnostic print thresholds from the ODB
26  odb_get_int("/Equipment/Crate %d/Settings/Diagnostic Print Level", crate_number);
28  odb_get_int("/Equipment/Crate %d/Settings/Operator Message Level", crate_number);
29 }
30 
31 /* ******************************************************************* */
32 /*
33  *
34  */
35 void diag_print_impl(int level, char *format, va_list argp)
36 {
37  // Format the message.
38  char buffer[4096];
39  vsnprintf(buffer, sizeof(buffer), format, argp);
40 
41  // Print on standard output
42  // if (level <= diag_print_threshold) {
43  printf("%s", buffer);
44  fflush(stdout);
45  // }
46 
47  // Send to cm_msg
48  if(level <= diag_cm_msg_threshold) {
49 
50  // Be careful to avoid sending too many messages...let's limit ourselves
51  // to 10 per second.
52 
53  time_t now = time(NULL);
54  if(last_message_time == now) {
56  if(num_messages_this_second < 1) {
57  cm_msg(MINFO, frontend_name, buffer);
58  }
59  } else {
61  }
62 
63  last_message_time = now;
64  }
65 }