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