From 85e4e9d1172c43bd52bc11e3d20325c91642bf66 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sun, 21 Jul 2019 19:26:42 +0200 Subject: [PATCH] * Moved telemetry_state_t declaration and SHM_KEY to new file telemetry.h. --- shmget.c | 25 ++----------------------- telemetry.cpp | 24 +++--------------------- telemetry.h | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 44 deletions(-) create mode 100644 telemetry.h diff --git a/shmget.c b/shmget.c index 690e869..2a29955 100644 --- a/shmget.c +++ b/shmget.c @@ -16,30 +16,9 @@ #include "fserv.h" #include "net.h" #include "log.h" +#include "telemetry.h" - -#define SHM_KEY 0xecc11 - -typedef uint64_t scs_timestamp_t; - -struct telemetry_state_t -{ - scs_timestamp_t timestamp; - scs_timestamp_t raw_rendering_timestamp; - scs_timestamp_t raw_simulation_timestamp; - scs_timestamp_t raw_paused_simulation_timestamp; - - bool orientation_available; - float heading; - float pitch; - float roll; - - float speed; - float rpm; - int gear; - float cc; //cruise_control - float fc_avg; //fuel consumption average -} *telemetry; +struct telemetry_state_t *telemetry; static volatile int force_quit; diff --git a/telemetry.cpp b/telemetry.cpp index cbc1f51..39db1be 100644 --- a/telemetry.cpp +++ b/telemetry.cpp @@ -54,40 +54,22 @@ scs_timestamp_t last_timestamp = static_cast(-1); /** * @brief Combined telemetry data. */ -struct telemetry_state_t -{ - scs_timestamp_t timestamp; - scs_timestamp_t raw_rendering_timestamp; - scs_timestamp_t raw_simulation_timestamp; - scs_timestamp_t raw_paused_simulation_timestamp; - - bool orientation_available; - float heading; - float pitch; - float roll; - - float speed; - float rpm; - int gear; - float cc; //cruise_control - float fc_avg; //fuel consumption average -} *telemetry; +#include "telemetry.h" +struct telemetry_state_t *telemetry; /** * @brief Function writting message to the game internal log. */ static int shmid = -1; -#define KEY 0xecc11 -// Management of the log file. bool init_log(void) { if (shmid > 0) { return true; } - shmid = shmget (KEY, sizeof (struct telemetry_state_t), IPC_CREAT | IPC_EXCL | 0600); + shmid = shmget (SHM_KEY, sizeof (struct telemetry_state_t), IPC_CREAT | IPC_EXCL | 0600); telemetry = static_cast(shmat (shmid, NULL, 0)); return true; } diff --git a/telemetry.h b/telemetry.h new file mode 100644 index 0000000..b9e5f70 --- /dev/null +++ b/telemetry.h @@ -0,0 +1,24 @@ +#ifndef TELEMETRY_H_ +#define TELEMETRY_H_ + +#define SHM_KEY 0xecc11 + +struct telemetry_state_t { + uint64_t timestamp; + uint64_t raw_rendering_timestamp; + uint64_t raw_simulation_timestamp; + uint64_t raw_paused_simulation_timestamp; + + bool orientation_available; + float heading; + float pitch; + float roll; + + float speed; + float rpm; + int gear; + float cc; // cruise_control + float fc_avg; // fuel consumption average +}; + +#endif /* TELEMETRY_H_ */ -- 2.30.2