Skip to content

Commit

Permalink
move shared definitions to defs.h
Browse files Browse the repository at this point in the history
  • Loading branch information
jthistle committed Mar 20, 2021
1 parent baee534 commit 78c1bbc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions linux/plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ SDK_INCLUDES=\

all: ets2-telemetry-lin.so read_util

ets2-telemetry-lin.so: plugin.cpp $(SDK_HEADERS)
ets2-telemetry-lin.so: plugin.cpp $(SDK_HEADERS) defs.h
g++ -O2 -o $@ -fPIC -Wall --shared -Wl,-soname,$@ $(SDK_INCLUDES) plugin.cpp -lrt

read_util: read_util.cpp $(SDK_HEADERS)
read_util: read_util.cpp $(SDK_HEADERS) defs.h
g++ -O2 -o $@ -Wall $(SDK_INCLUDES) read_util.cpp -lrt

.PHONY: clean
Expand Down
20 changes: 20 additions & 0 deletions linux/plugins/defs.h
Original file line number Diff line number Diff line change
@@ -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__ */
18 changes: 3 additions & 15 deletions linux/plugins/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
#include <unistd.h>
#include <fcntl.h>

// 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)

Expand All @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 3 additions & 9 deletions linux/plugins/read_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <unistd.h>
#include <fcntl.h>

#include "defs.h"

// SDK

#include "scssdk_telemetry.h"
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 78c1bbc

Please sign in to comment.