#include #include struct APP_SETTINGS settings; void Settings_InitDefaultValues() { // #define LOG_EMERG 0 /* system is unusable */ // #define LOG_ALERT 1 /* action must be taken immediately */ // #define LOG_CRIT 2 /* critical conditions */ // #define LOG_ERR 3 /* error conditions */ // #define LOG_WARNING 4 /* warning conditions */ // #define LOG_NOTICE 5 /* normal but significant condition */ // #define LOG_INFO 6 /* informational */ // #define LOG_DEBUG 7 /* debug-level messages */ settings.iDebugLevel = LOG_INFO; settings.iCanSimu = 0; settings.iMotorCount = 1; settings.iMotorPwrMinRaw = 38; settings.iMotorPwrMaxRaw = 250; settings.iMotorPwrStepCount = 7; // Get path of the executable itself ssize_t length = readlink("/proc/self/exe", settings.sExePath, sizeof(settings.sExePath) - 1); if (length >= 0) { settings.sExePath[length] = '\0'; mylog(LOG_INFO, "SETTINGS: Executable path: %s", settings.sExePath); } else { settings.sExePath[0] = '\0'; mylog(LOG_ERR, "SETTINGS: Executable path not found!"); } } void Settings_ReadConfFile() { const char *filename = "/etc/CanRtDriver.conf"; FILE *file = fopen(filename, "r"); if (file == NULL) { mylog(LOG_ERR, "Failed to open settings file %s", filename); return; } char line[MAX_LINE_LENGTH]; while (fgets(line, sizeof(line), file)) { // 1. Ignore comments and empty lines if (line[0] == '#' || line[0] == '\n' || line[0] == '\r') { continue; } // 2. Remove CRLF at end of line line[strcspn(line, "\r\n")] = 0; // 3. Split line to key and value char *key = strtok(line, "="); char *value = strtok(NULL, "="); if ((key != NULL) && (value != NULL)) { mylog(LOG_DEBUG, "SETTINGS: Found key: '%s' | value: '%s'\n", key, value); // // Beispiel: Wert verarbeiten // if (strcmp(key, "port") == 0) // { // int port = atoi(value); // printf(" [System] Port auf %d gesetzt.\n", port); // } } } fclose(file); }