Settings-Datei fortgesetzt
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <main.h>
|
||||
#include <settings/settings.h>
|
||||
|
||||
|
||||
struct APP_SETTINGS settings;
|
||||
|
||||
void Settings_InitDefaultValues()
|
||||
@@ -15,9 +16,67 @@ void Settings_InitDefaultValues()
|
||||
// #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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user