Logging » Historie » Version 3
  Maximilian Seesslen, 21.12.2022 13:56 
  
| 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 | 2 | Maximilian Seesslen | * Work within ISRs.  | 
| 6 | * 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 | 1 | Maximilian Seesslen | * good (double)  | 
| 16 | * crytical error (fast blink)  | 
||
| 17 | * 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 | |||
| 27 | 2 | Maximilian Seesslen | h2. Examples  | 
| 28 | |||
| 29 | <pre><code class="cpp">  | 
||
| 30 | add_definitions( BIWAK_LOG_HEARTBEAT )  | 
||
| 31 | add_definitions( BIWAK_LOG_CAN )  | 
||
| 32 | add_definitions( BIWAK_LOG_DEBUG )  | 
||
| 33 | |||
| 34 | #define bDebug(a,...) debug(a, __VA_ARGS__)  | 
||
| 35 | </code></pre>  | 
||
| 36 | |||
| 37 | <pre><code class="cpp">  | 
||
| 38 | #include <biwak/log.hpp>  | 
||
| 39 | |||
| 40 | main()  | 
||
| 41 | { | 
||
| 42 | bDebug(); // Just print some text  | 
||
| 43 | bCritical();  | 
||
| 44 | bTrouble(); //  | 
||
| 45 | bFatal();  | 
||
| 46 |    bException("Static text"); | 
||
| 47 | }  | 
||
| 48 | </code></pre>  | 
||
| 49 | 3 | Maximilian Seesslen | |
| 50 | <pre><code class="cpp">  | 
||
| 51 | static struct { | 
||
| 52 | char buf[20];  | 
||
| 53 | bool used;  | 
||
| 54 | }buffers[2]={0}; | 
||
| 55 | |||
| 56 | void bWarning(const char *text, ...)  | 
||
| 57 | { | 
||
| 58 | va_list list;  | 
||
| 59 | va_start(list, text);  | 
||
| 60 | int bufid;  | 
||
| 61 | for(bufid=0; bufid < ARRAY_ELEMENTS(buffers); bufid++)  | 
||
| 62 |     { | 
||
| 63 | if(!buffers[bufid].used)  | 
||
| 64 |         { | 
||
| 65 | break;  | 
||
| 66 | }  | 
||
| 67 | }  | 
||
| 68 | if(bufid >= ARRAY_ELEMENTS(buffers))  | 
||
| 69 |     { | 
||
| 70 |         bException("Out of log buffers!"); | 
||
| 71 | }  | 
||
| 72 | buffers[bufid].used=true;  | 
||
| 73 | vsnprintf(buffers[bufid].buf, 20, text, list);  | 
||
| 74 | puts(buffers[bufid].buf);  | 
||
| 75 |     printf("Bufid: %d; elements: %d\n", bufid, ARRAY_ELEMENTS(buffers)); | 
||
| 76 | };  | 
||
| 77 | </code></pre>  |