From 76939ce77f847cacd72475d4f9d57b29fb63aaa9 Mon Sep 17 00:00:00 2001 From: James Thistlewood Date: Sat, 20 Mar 2021 20:53:56 +0000 Subject: [PATCH] move shared definitions to defs.h --- linux/plugins/defs.h | 20 ++++++++++++++++++++ linux/plugins/plugin.cpp | 18 +++--------------- linux/plugins/read_util.cpp | 12 +++--------- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 linux/plugins/defs.h diff --git a/linux/plugins/defs.h b/linux/plugins/defs.h new file mode 100644 index 000000000..7fe0ecd41 --- /dev/null +++ b/linux/plugins/defs.h @@ -0,0 +1,20 @@ +#ifndef __DEFS__ +#define __DEFS__ + +// SDK +#include "scssdk_telemetry.h" +#include "eurotrucks2/scssdk_eut2.h" +#include "eurotrucks2/scssdk_telemetry_eut2.h" +#include "amtrucks/scssdk_ats.h" +#include "amtrucks/scssdk_telemetry_ats.h" + +const char shm_name[] = "/ets2radiolinux"; +const int NUM_PAGES = 1; + +typedef struct telemetry_state_t +{ + scs_value_dplacement_t world_position; + scs_value_bool_t electricity; +} telemetry_state_t; + +#endif /* __DEFS__ */ diff --git a/linux/plugins/plugin.cpp b/linux/plugins/plugin.cpp index 69a303853..dc1b2fb25 100644 --- a/linux/plugins/plugin.cpp +++ b/linux/plugins/plugin.cpp @@ -11,13 +11,7 @@ #include #include -// SDK - -#include "scssdk_telemetry.h" -#include "eurotrucks2/scssdk_eut2.h" -#include "eurotrucks2/scssdk_telemetry_eut2.h" -#include "amtrucks/scssdk_ats.h" -#include "amtrucks/scssdk_telemetry_ats.h" +#include "defs.h" #define UNUSED(x) @@ -29,11 +23,7 @@ bool output_paused = true; /** * @brief Useful telemetry data. */ -struct telemetry_state_t -{ - scs_value_dplacement_t world_position; - scs_value_bool_t electricity; -} telemetry; +telemetry_state_t telemetry; /** * @brief Time since last mmap @@ -48,8 +38,6 @@ static scs_timestamp_t update_interval = 5e5; // every 0.5s void* mapped_region = NULL; size_t MAP_SIZE = -1; -static char shm_name[] = "/ets2radiolinux"; - /** * @brief Function writing message to the game internal log. */ @@ -231,7 +219,7 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in memset(&telemetry, 0, sizeof(telemetry)); // We only need one page of memory - MAP_SIZE = getpagesize(); + MAP_SIZE = getpagesize() * NUM_PAGES; // Open shared memory int handle = shm_open(shm_name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); diff --git a/linux/plugins/read_util.cpp b/linux/plugins/read_util.cpp index 110047656..d9f4135b1 100644 --- a/linux/plugins/read_util.cpp +++ b/linux/plugins/read_util.cpp @@ -9,6 +9,8 @@ #include #include +#include "defs.h" + // SDK #include "scssdk_telemetry.h" @@ -17,14 +19,6 @@ #include "amtrucks/scssdk_ats.h" #include "amtrucks/scssdk_telemetry_ats.h" -static char shm_name[] = "/ets2radiolinux"; - -typedef struct telemetry_state_t -{ - scs_value_dplacement_t world_position; - scs_value_bool_t electricity; -} telemetry_state_t; - void print_info(telemetry_state_t info) { scs_value_dvector_t pos = info.world_position.position; int elec = info.electricity.value > 0 ? 1 : 0; @@ -34,7 +28,7 @@ void print_info(telemetry_state_t info) { int main() { // We only need one page of memory - size_t MAP_SIZE = getpagesize(); + size_t MAP_SIZE = getpagesize() * NUM_PAGES; // Open shared memory int handle = shm_open(shm_name, O_RDONLY, S_IRUSR);