From 695581b66d98bfb63dc372dc5714696ca5797348 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Sun, 15 Sep 2024 12:24:23 -0400 Subject: [PATCH] Fix issue with test not having a car set --- src/monocoque/gameloop/gameloop.c | 1 + src/monocoque/helper/confighelper.c | 16 ++++++++++++++++ src/monocoque/helper/confighelper.h | 1 + src/monocoque/monocoque.c | 3 ++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/monocoque/gameloop/gameloop.c b/src/monocoque/gameloop/gameloop.c index 660af81..e640f06 100644 --- a/src/monocoque/gameloop/gameloop.c +++ b/src/monocoque/gameloop/gameloop.c @@ -561,6 +561,7 @@ int tester(SimDevice* devices, int numdevices) tcsetattr(0, TCSANOW, &newsettings); fprintf(stdout, "\n"); + simdata->car = "MONOCOQUETESTCAR"; simdata->gear = MONOCOQUE_GEAR_NEUTRAL; simdata->velocity = 16; simdata->rpms = 100; diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index 4aa315c..b3fef37 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -176,6 +176,22 @@ int strtodev(const char* device_type, const char* device_subtype, DeviceSettings return MONOCOQUE_ERROR_NONE; } +int getNumberOfConfigs(const char* config_file_str) +{ + config_t cfg; + config_init(&cfg); + if (!config_read_file(&cfg, config_file_str)) + { + fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); + return -1; + } + config_setting_t* config = NULL; + config_setting_t* config_widgets = NULL; + config = config_lookup(&cfg, "configs"); + int configs = config_setting_length(config); + + return configs; +} int getconfigtouse(const char* config_file_str, char* car, int sim) { config_t cfg; diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index 7d554ff..6ec6a8e 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -199,4 +199,5 @@ int configcheck(const char* config_file_str, int confignum, int* devices); int uiloadconfig(const char* config_file_str, int confignum, int configureddevices, MonocoqueSettings* ms, DeviceSettings* ds); +int getNumberOfConfigs(const char* config_file_str); #endif diff --git a/src/monocoque/monocoque.c b/src/monocoque/monocoque.c index 450af23..d36f202 100644 --- a/src/monocoque/monocoque.c +++ b/src/monocoque/monocoque.c @@ -249,7 +249,8 @@ int main(int argc, char** argv) ms->useconfig = 0; - int confignum = getconfigtouse(ms->config_str, "default", 0); + int configs = getNumberOfConfigs(ms->config_str); + int confignum = getconfigtouse(ms->config_str, "default", configs-1); int configureddevices; configcheck(ms->config_str, confignum, &configureddevices);