Aktionen
  Logging » Historie » Revision 3
      « Zurück |
    Revision 3/6
      (diff)
      | Weiter »
    
    Maximilian Seesslen, 21.12.2022 13:56 
    
    
Logging¶
There is no clean logging concept at the moment.
- Work within ISRs.
 - Only short messages, e.g. 20 chars.
 - Heart-beat LED might be involved
 - CAN might be involved to transmit diagnose
 - Debug can be disabled even for Debug-builds; BIWAK_LOG_DEBUG has to be defined to show bDebug
 
Heartbeat-Class¶
An LED can indicate problems.
- good (double)
 - crytical error (fast blink)
 - fatal error (slow blink)
 - temporary error/ trouble (fast blink - off 1Hz) (goes away)
 
Usecases¶
- invalid eeprom causes "critical"-state
 - Not being able to sen CAN messages causes "trouble"
 - fatal: the application can not run for some reason but the led should work; e.g. a reception buffer is full
 - exception: Don't even try to run any more. e.g. memory error.
 
Examples¶
add_definitions( BIWAK_LOG_HEARTBEAT )
add_definitions( BIWAK_LOG_CAN )
add_definitions( BIWAK_LOG_DEBUG )
#define bDebug(a,...) debug(a, __VA_ARGS__)
#include <biwak/log.hpp>
main()
{
   bDebug();      // Just print some text
   bCritical();
   bTrouble();    // 
   bFatal();
   bException("Static text");
}
static struct {
    char buf[20];
    bool used;
}buffers[2]={0};
void bWarning(const char *text, ...)
{
    va_list list;
    va_start(list, text);
    int bufid;
    for(bufid=0; bufid < ARRAY_ELEMENTS(buffers); bufid++)
    {
        if(!buffers[bufid].used)
        {
            break;
        }
    }
    if(bufid >= ARRAY_ELEMENTS(buffers))
    {
        bException("Out of log buffers!");
    }
    buffers[bufid].used=true;
    vsnprintf(buffers[bufid].buf, 20, text, list);
    puts(buffers[bufid].buf);
    printf("Bufid: %d; elements: %d\n", bufid, ARRAY_ELEMENTS(buffers));
};
Von Maximilian Seesslen vor fast 3 Jahren aktualisiert · 3 Revisionen