Projekt

Allgemein

Profil

Logging » Historie » Version 4

Maximilian Seesslen, 21.12.2022 14:07

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