Erste Vorbereitungen für Settings-Datei

This commit is contained in:
Bernhard Schräer
2026-01-20 07:33:02 +01:00
parent f91aee06c7
commit b5f7b5a45d
7 changed files with 87 additions and 32 deletions

41
main.c
View File

@@ -3,6 +3,7 @@
#include <mqtt/mqtt_client.h>
#include <can/can_client.h>
#include <io/io.h>
#include <settings/settings.h>
// Period info of the realtime task
struct period_info pinfo;
@@ -16,27 +17,30 @@ int iLogToConsole = 1;
/// @param
void mylog(int prio, const char *format, ...)
{
va_list args;
if (prio >= settings.iDebugLevel)
{
va_list args;
// 1. Initialisiere die Argumentenliste mit dem letzten festen Parameter
va_start(args, format);
// 1. Initialize the argument list with the last fixed argument
va_start(args, format);
// 2. Übergabe an vsyslog (statt syslog)
// vsyslog nimmt eine va_list entgegen
vsyslog(prio, format, args);
// 2. Transfer to vsyslog (instead of syslog)
// vsyslog accepts a va_list
vsyslog(prio, format, args);
// 3. Optional: Zusätzlich auf die Konsole ausgeben
// Wir müssen die Liste neu initialisieren, da va_list "verbraucht" wird
if (iLogToConsole)
{
va_end(args);
va_start(args, format);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
}
// 3. Optional: Output additionally to the console
// We have to reinitialize the list because va_list is "consumed."
if (iLogToConsole)
{
va_end(args);
va_start(args, format);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
}
// 4. Aufräumen
va_end(args);
// 4. Cleanup
va_end(args);
}
}
@@ -209,6 +213,9 @@ int main(int argc, char* argv[])
pthread_t thread;
int ret;
// First we have to get the default values of our settings
Settings_InitDefaultValues();
openlog("CanRtDriver", LOG_PID | LOG_CONS, LOG_DAEMON);
mylog(LOG_INFO, "Service started. PID: %d", getpid());