-
Notifications
You must be signed in to change notification settings - Fork 1
/
logging.c
60 lines (52 loc) · 1.64 KB
/
logging.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* The flexPTP project, (C) András Wiesner, 2024 */
#include <flexptp/logging.h>
#include <flexptp/ptp_core.h>
#include <flexptp_options.h>
#define S (gPtpCoreState)
// enable/disable general logging
static void ptp_log_def_en(bool en)
{
if (en) { // on turning on
MSG("\n\nT1 [s] | T1 [ns] | T4 [s] | T4 [ns] | Dt [s] | Dt [ns] | Dt [tick] | Addend\n\n");
}
}
// ------------------------
// PTP log pair
typedef struct {
int id; // ID of log type
void (*logEnFn)(bool); // callback function on turning on/off logging
bool *en; // variable storing log state
} PtpLogPair;
static PtpLogPair sLogTable[PTP_LOG_N + 1] = {
{PTP_LOG_DEF, ptp_log_def_en, &(S.logging.def)},
{PTP_LOG_CORR_FIELD, NULL, &(S.logging.corr)},
{PTP_LOG_TIMESTAMPS, NULL, &(S.logging.timestamps)},
{PTP_LOG_INFO, NULL, &(S.logging.info)},
{PTP_LOG_LOCKED_STATE, NULL, &(S.logging.locked)},
{-1, NULL, NULL}
};
void ptp_enable_logging(int logId, bool en)
{
PtpLogPair *pIter = sLogTable;
while (pIter->id != -1) {
if (pIter->id == logId && *(pIter->en) != en) { // if callback is found and changing state indeed
if (pIter->logEnFn != NULL) { // callback function is not necessary
pIter->logEnFn(en);
}
*(pIter->en) = en;
break;
}
pIter++;
}
}
void ptp_disable_all_logging()
{
PtpLogPair *pIter = sLogTable;
while (pIter->logEnFn != NULL) {
if (pIter->logEnFn != NULL) {
pIter->logEnFn(false);
}
*(pIter->en) = false;
pIter++;
}
}