Fix OBD2 debug logging format handling
All checks were successful
CI-Build/Kettenoeler/pipeline/head This commit looks good

This commit is contained in:
2025-12-08 17:49:28 +01:00
parent 2a1caf6d23
commit fed62fa26b

View File

@@ -3,7 +3,7 @@
#include "dtc.h"
#include "debugger.h"
#include "globals.h"
#include <stdarg.h>
#include <stdio.h>
// Trace-Sink aus webui.cpp (o.ä.)
extern void TRACE_OnObdFrame(uint32_t id, bool rx, const uint8_t *d, uint8_t dlc, const char *note);
@@ -72,8 +72,6 @@ static uint32_t s_lastRespTime = 0;
static uint32_t s_lastIntegrateMs = 0;
static uint32_t s_lastSpeedMMps = 0;
static uint32_t s_lastDbgMs = 0;
// =======================
// Hilfsfunktionen
// =======================
@@ -87,22 +85,6 @@ static inline uint32_t kmh_to_mmps(uint16_t kmh)
return (uint32_t)kmh * 1000000UL / 3600UL;
}
static inline void maybeDebug(uint32_t now, const char *fmt, ...)
{
#if 1
if (now - s_lastDbgMs < OBD2_DEBUG_INTERVAL_MS)
return;
s_lastDbgMs = now;
va_list ap;
va_start(ap, fmt);
Debug_pushMessage(fmt, ap); // nimmt va_list
va_end(ap);
#else
(void)now;
(void)fmt;
#endif
}
// =======================
// Öffentliche API
// =======================
@@ -155,7 +137,6 @@ bool Init_CAN_OBD2()
s_lastRespTime = 0;
s_lastIntegrateMs = now;
s_lastSpeedMMps = 0;
s_lastDbgMs = 0;
Debug_pushMessage("CAN(OBD2): Filters set (7E8..7EF), NORMAL mode\n");
return true;
@@ -198,7 +179,12 @@ uint32_t Process_CAN_OBD2_Speed()
{
// Senden fehlgeschlagen -> harter Timeout-DTC
MaintainDTC(DTC_OBD2_CAN_TIMEOUT, true);
maybeDebug(now, "OBD2-CAN send failed (%u)\n", st);
static uint8_t dbgSendFail = 0;
if (++dbgSendFail >= 10)
{
dbgSendFail = 0;
Debug_pushMessage("OBD2-CAN send failed (%u)\n", st);
}
}
}
}
@@ -253,8 +239,13 @@ uint32_t Process_CAN_OBD2_Speed()
snprintf(note, sizeof(note), "speed=%ukmh", (unsigned)speedKmh);
TRACE_OnObdFrame(rxId, /*rx=*/true, rx, len, note);
maybeDebug(now, "OBD2 speed: %u km/h (%lu mm/s)\n",
(unsigned)speedKmh, (unsigned long)s_lastSpeedMMps);
static uint8_t dbgSpeed = 0;
if (++dbgSpeed >= 10)
{
dbgSpeed = 0;
Debug_pushMessage("OBD2 speed: %u km/h (%lu mm/s)\n",
(unsigned)speedKmh, (unsigned long)s_lastSpeedMMps);
}
break; // eine valide Antwort pro Zyklus reicht
}
else