From: Urban Wallasch Date: Tue, 23 Jul 2019 12:24:18 +0000 (+0200) Subject: * Added game id, version info and paused state to telemetry. X-Git-Tag: v0.1.0~79 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=54770744a3f1e11a802908462992fb8d2a49e5ff;p=ets2_tele.git * Added game id, version info and paused state to telemetry. * Removed some cruft from telemetry.cpp. --- diff --git a/telehttpd.c b/telehttpd.c index 1363d40..e6ffe45 100644 --- a/telehttpd.c +++ b/telehttpd.c @@ -55,6 +55,13 @@ enum respond_code { static void write_telejson( int fd ) { char buf[512]; write(fd, buf, sprintf( buf, "{\n" ) ); + + write(fd, buf, sprintf( buf, " \"game_id\": \"%s\",\n", telemetry->game_id ) ); + write(fd, buf, sprintf( buf, " \"game_major_ver\": %u,\n", telemetry->game_major_ver ) ); + write(fd, buf, sprintf( buf, " \"game_minor_ver\": %u,\n", telemetry->game_minor_ver ) ); + write(fd, buf, sprintf( buf, " \"game_ver_warn\": %d,\n", (int)telemetry->game_ver_warn ) ); + + write(fd, buf, sprintf( buf, " \"paused\": %d,\n", (int)telemetry->paused ) ); write(fd, buf, sprintf( buf, " \"timestamp\": %"PRIu64",\n", telemetry->timestamp ) ); write(fd, buf, sprintf( buf, " \"x\": %f,\n", telemetry->x ) ); write(fd, buf, sprintf( buf, " \"y\": %f,\n", telemetry->y ) ); diff --git a/telelogger.c b/telelogger.c index 406f72c..105c3ef 100644 --- a/telelogger.c +++ b/telelogger.c @@ -16,7 +16,14 @@ static const char *s2hms( int s ) { static int log_console(void) { uint64_t last_timestamp = telemetry->timestamp; + + printf( "game id: %s version %u.%u (%s)\n" , telemetry->game_id, + telemetry->game_major_ver, telemetry->game_minor_ver, + telemetry->game_ver_warn ? "OK" : "WARNING!" ); + while ( 1 ) { + printf("paused: %s\n", telemetry->paused ? "yes" : "no" ); + printf("timestamp: %"PRIu64"\n", telemetry->timestamp); // uint64_t raw_rendering_timestamp; // uint64_t raw_simulation_timestamp; @@ -51,7 +58,7 @@ static int log_console(void) { puts(""); sleep( 1 ); - while ( last_timestamp == telemetry->timestamp ) + while ( telemetry->paused || last_timestamp == telemetry->timestamp ) sleep( 1 ); last_timestamp = telemetry->timestamp; } diff --git a/telemetry.cpp b/telemetry.cpp index 650f6c5..bb8cbed 100644 --- a/telemetry.cpp +++ b/telemetry.cpp @@ -35,17 +35,6 @@ #define UNUSED(x) -/** - * @brief Tracking of paused state of the game. - */ -bool output_paused = true; - -/** - * @brief Should we print the data header next time - * we are printing the data? - */ -bool print_header = true; - /** * @brief Last timestamp we received. */ @@ -87,7 +76,7 @@ static void release_shm(void) /** * @brief Function writting message to the game internal log. */ - +/* static void log_print(const char *const text, ...) { } @@ -95,7 +84,7 @@ static void log_print(const char *const text, ...) static void log_line(const char *const text, ...) { } - +*/ // Handling of individual events. SCSAPI_VOID telemetry_frame_start(const scs_event_t UNUSED(event), const void *const event_info, const scs_context_t UNUSED(context)) @@ -133,49 +122,16 @@ SCSAPI_VOID telemetry_frame_start(const scs_event_t UNUSED(event), const void *c SCSAPI_VOID telemetry_frame_end(const scs_event_t UNUSED(event), const void *const UNUSED(event_info), const scs_context_t UNUSED(context)) { - if (output_paused) { - return; - } - - // The header. - - if (print_header) { - print_header = false; - log_line("timestamp[us];raw rendering timestamp[us];raw simulation timestamp[us];raw paused simulation timestamp[us];heading[deg];pitch[deg];roll[deg];speed[km/s];cc[km/s]rpm;gear"); - } - - // The data line. - - log_print("%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64 ";%" SCS_PF_U64, telemetry->timestamp, telemetry->raw_rendering_timestamp, telemetry->raw_simulation_timestamp, telemetry->raw_paused_simulation_timestamp); - if (telemetry->placement_available) { - log_print(";%f;%f;%f", telemetry->heading, telemetry->pitch, telemetry->roll); - } - else { - log_print(";---;---;---"); - } - log_line( - ";%3.2f;%3.2f;%f;%d", - telemetry->speed * 3.6, - telemetry->cctrl * 3.6, - telemetry->rpm, - telemetry->gear - ); } SCSAPI_VOID telemetry_pause(const scs_event_t event, const void *const UNUSED(event_info), const scs_context_t UNUSED(context)) { - output_paused = (event == SCS_TELEMETRY_EVENT_paused); - if (output_paused) { - log_line("Telemetry paused"); - } - else { - log_line("Telemetry unpaused"); - } - print_header = true; + telemetry->paused = (event == SCS_TELEMETRY_EVENT_paused); } SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const event_info, const scs_context_t UNUSED(context)) { +#if 0 // Here we just print the configuration info. const struct scs_telemetry_configuration_t *const info = static_cast(event_info); @@ -279,6 +235,7 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e } print_header = true; +#endif } // Handling of individual channels. @@ -352,7 +309,7 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in } const scs_telemetry_init_params_v100_t *const version_params = static_cast(params); - if (! init_shm()) { + if ( !init_shm() ) { version_params->common.log(SCS_LOG_TYPE_error, "Unable to initialize shared memory"); return SCS_RESULT_generic_error; } @@ -360,24 +317,27 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in // Check application version. Note that this example uses fairly basic channels which are likely to be supported // by any future SCS trucking game however more advanced application might want to at least warn the user if there // is game or version they do not support. - - log_line("Game '%s' %u.%u", version_params->common.game_id, SCS_GET_MAJOR_VERSION(version_params->common.game_version), SCS_GET_MINOR_VERSION(version_params->common.game_version)); + snprintf( telemetry->game_id, sizeof telemetry->game_id, "%s", version_params->common.game_id ); + telemetry->game_major_ver = SCS_GET_MAJOR_VERSION(version_params->common.game_version); + telemetry->game_minor_ver = SCS_GET_MINOR_VERSION(version_params->common.game_version); if (strcmp(version_params->common.game_id, SCS_GAME_ID_EUT2) == 0) { - // Bellow the minimum version there might be some missing features (only minor change) or + // Below the minimum version there might be some missing features (only minor change) or // incompatible values (major change). const scs_u32_t MINIMAL_VERSION = SCS_TELEMETRY_EUT2_GAME_VERSION_1_00; if (version_params->common.game_version < MINIMAL_VERSION) { - log_line("WARNING: Too old version of the game, some features might behave incorrectly"); + //log_line("WARNING: Too old version of the game, some features might behave incorrectly"); + telemetry->game_ver_warn = true; } // Future versions are fine as long the major version is not changed. const scs_u32_t IMPLEMENTED_VERSION = SCS_TELEMETRY_EUT2_GAME_VERSION_CURRENT; if (SCS_GET_MAJOR_VERSION(version_params->common.game_version) > SCS_GET_MAJOR_VERSION(IMPLEMENTED_VERSION)) { - log_line("WARNING: Too new major version of the game, some features might behave incorrectly"); + //log_line("WARNING: Too new major version of the game, some features might behave incorrectly"); + telemetry->game_ver_warn = true; } } else if (strcmp(version_params->common.game_id, SCS_GAME_ID_ATS) == 0) { @@ -387,18 +347,21 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in const scs_u32_t MINIMAL_VERSION = SCS_TELEMETRY_ATS_GAME_VERSION_1_00; if (version_params->common.game_version < MINIMAL_VERSION) { - log_line("WARNING: Too old version of the game, some features might behave incorrectly"); + //log_line("WARNING: Too old version of the game, some features might behave incorrectly"); + telemetry->game_ver_warn = true; } // Future versions are fine as long the major version is not changed. const scs_u32_t IMPLEMENTED_VERSION = SCS_TELEMETRY_ATS_GAME_VERSION_CURRENT; if (SCS_GET_MAJOR_VERSION(version_params->common.game_version) > SCS_GET_MAJOR_VERSION(IMPLEMENTED_VERSION)) { - log_line("WARNING: Too new major version of the game, some features might behave incorrectly"); + //log_line("WARNING: Too new major version of the game, some features might behave incorrectly"); + telemetry->game_ver_warn = true; } } else { - log_line("WARNING: Unsupported game, some features or values might behave incorrectly"); + //log_line("WARNING: Unsupported game, some features or values might behave incorrectly"); + telemetry->game_ver_warn = true; } // Register for events. Note that failure to register those basic events @@ -450,12 +413,11 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in // Set the structure with defaults. - print_header = true; last_timestamp = static_cast(-1); // Initially the game is paused. - output_paused = true; + telemetry->paused = true; return SCS_RESULT_ok; } diff --git a/telemetry.h b/telemetry.h index ea65e70..7048c47 100644 --- a/telemetry.h +++ b/telemetry.h @@ -4,6 +4,12 @@ #define SHM_KEY 0xecc11 struct telemetry_state_t { + char game_id[10]; + unsigned game_major_ver; + unsigned game_minor_ver; + bool game_ver_warn; + bool paused; + uint64_t timestamp; uint64_t raw_rendering_timestamp; uint64_t raw_simulation_timestamp;