AlcapDAQ
1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
crate3
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
10
int
diag_print_threshold
= -1;
11
int
diag_cm_msg_threshold
= -1;
12
13
time_t
last_message_time
= 0;
14
int
num_messages_this_second
= 0;
15
16
/* ******************************************************************* */
17
/*
18
* diag_print_setup
19
*
20
* Reads threshold for diagnostic printout from ODB.
21
*/
22
void
diag_print_setup
()
23
{
24
// Read the diagnostic print thresholds from the ODB
25
diag_print_threshold
=
26
odb_get_int
(
"/Equipment/Crate %d/Settings/Diagnostic Print Level"
,
crate_number
);
27
diag_cm_msg_threshold
=
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) {
55
num_messages_this_second
++;
56
if
(
num_messages_this_second
< 1) {
57
cm_msg(MINFO,
frontend_name
, buffer);
58
}
59
}
else
{
60
num_messages_this_second
= 0;
61
}
62
63
last_message_time
= now;
64
}
65
}
Generated by
1.8.4