Projekt

Allgemein

Profil

Logging » Historie » Version 5

Maximilian Seesslen, 21.12.2022 14:39

1 1 Maximilian Seesslen
h1. Logging
2
3 2 Maximilian Seesslen
There is no clean logging concept at the moment.
4 1 Maximilian Seesslen
5 5 Maximilian Seesslen
* Low footprint
6 4 Maximilian Seesslen
* Work within ISRs. The output is delayed. The order is preserved.
7 2 Maximilian Seesslen
* Only short messages, e.g. 20 chars. 
8
* Heart-beat LED might be involved
9
* CAN might be involved to transmit diagnose
10
* Debug can be disabled even for Debug-builds; BIWAK_LOG_DEBUG has to be defined to show bDebug
11
12
h2. Heartbeat-Class
13
14
An LED can indicate problems.
15
16 4 Maximilian Seesslen
* good (double heartbeat)
17
* critical error/ exception (fast blink)
18 1 Maximilian Seesslen
* fatal error (slow blink)
19
* temporary error/ trouble (fast blink - off 1Hz) (goes away)
20
21 2 Maximilian Seesslen
h2. Usecases
22 1 Maximilian Seesslen
23
* invalid eeprom causes "critical"-state
24
* Not being able to sen CAN messages causes "trouble"
25
* fatal: the application can not run for some reason but the led should work; e.g. a reception buffer is full
26
* exception: Don't even try to run any more. e.g. memory error.
27 4 Maximilian Seesslen
28
h2. Notes
29
30
There is already a doublebuffer-class for CAN.
31 1 Maximilian Seesslen
32 2 Maximilian Seesslen
h2. Examples
33
34
<pre><code class="cpp">
35
add_definitions( BIWAK_LOG_HEARTBEAT )
36
add_definitions( BIWAK_LOG_CAN )
37
add_definitions( BIWAK_LOG_DEBUG )
38
39
#define bDebug(a,...) debug(a, __VA_ARGS__)
40
</code></pre>
41
42
<pre><code class="cpp">
43
#include <biwak/log.hpp>
44
45
main()
46
{
47
   bDebug();      // Just print some text
48
   bCritical();
49
   bTrouble();    // 
50
   bFatal();
51
   bException("Static text");
52
}
53
</code></pre>
54 3 Maximilian Seesslen
55
<pre><code class="cpp">
56
static struct {
57
    char buf[20];
58
    bool used;
59
}buffers[2]={0};
60
61
void bWarning(const char *text, ...)
62
{
63
    va_list list;
64
    va_start(list, text);
65
    int bufid;
66
    for(bufid=0; bufid < ARRAY_ELEMENTS(buffers); bufid++)
67
    {
68
        if(!buffers[bufid].used)
69
        {
70
            break;
71
        }
72
    }
73
    if(bufid >= ARRAY_ELEMENTS(buffers))
74
    {
75
        bException("Out of log buffers!");
76
    }
77
    buffers[bufid].used=true;
78
    vsnprintf(buffers[bufid].buf, 20, text, list);
79
    puts(buffers[bufid].buf);
80
    printf("Bufid: %d; elements: %d\n", bufid, ARRAY_ELEMENTS(buffers));
81
};
82
</code></pre>