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 ) );
#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.
*/
/**
* @brief Function writting message to the game internal log.
*/
-
+/*
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))
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<const scs_telemetry_configuration_t *>(event_info);
}
print_header = true;
+#endif
}
// Handling of individual channels.
}
const scs_telemetry_init_params_v100_t *const version_params = static_cast<const scs_telemetry_init_params_v100_t *>(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;
}
// 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) {
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
// Set the structure with defaults.
- print_header = true;
last_timestamp = static_cast<scs_timestamp_t>(-1);
// Initially the game is paused.
- output_paused = true;
+ telemetry->paused = true;
return SCS_RESULT_ok;
}