From fe8ece0a42937d2b04cd3d05f51c4f7c4e4747cb Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sat, 27 Jul 2019 21:35:22 +0200 Subject: [PATCH] * Added game_time to telemetry. * Added delivery_time to telemetry and display. * Reworked display formatting, CSS and JavaScript. --- dash.html | 127 +++++++++++++++++++++++++++++--------------------- telehttpd.c | 4 ++ telelogger.c | 2 + telemetry.h | 4 ++ teleshmem.cpp | 30 +++++++++--- 5 files changed, 107 insertions(+), 60 deletions(-) diff --git a/dash.html b/dash.html index 354d022..0af7d3b 100644 --- a/dash.html +++ b/dash.html @@ -12,40 +12,48 @@ html, body { background-color: black; color: white; } - -x-content { +x-page { display: block; width: 100%; } x-boxleft, x-boxright { display: block; - padding: 0.2em; - margin: 0.1em; border: none; } x-boxleft { float:left; } x-boxright { float:right; } .clear { clear:both; } - .cont { + min-width:15em; + padding: 0.2em; border: solid 2px grey; - min-width:13em; - /* - width:15em; +} +.bar { min-width:15em; - height:22em; - min-height:22em; - */ +} + +table, caption, tbody, tfoot, thead, tr, th, td { + width: auto; + height: auto; + margin: 0; + padding: 0; + border: 0; + border-collapse: collapse; + outline: 0; + vertical-align: baseline; + background: transparent; } .aright { text-align: right; } .aleft { text-align: left; } +.acenter { text-align: center; } .ajust { text-align: justify; } .big { font-size: 8em; } .medium { font-size: 4em; } -.small { font-size: 2em; } +.small { font-size: 2.5em; } +.smaller { font-size: 1.8em; } .tiny { font-size: 1.2em; } .warn1 { color:#fd0; } @@ -53,11 +61,10 @@ x-boxright { float:right; } .setval { color:#0af; } .hilite { background-color: #ff0; } - x-bar { - display: none; + display: block; clear: both; - width: 90%; + width: 100%; padding: 0.2em; margin: 0.1em; border: none; @@ -79,37 +86,45 @@ x-bar { - -- km/h - - - - --- - - - - km/h - x  - 0 rpm - - km + + + + + + + +
-- km/h
+ + --- +   - km/h
x0 rpm
- - l - - km - - l/100km + + + + + +
Fuel- l
Range- km
Average- l/100km
Mileage-km
- - km - - eta - - ttr + + + + + +
Distance- km
ETA-
Next rest-
Deadline-
-Paused - + + Paused + +
- + diff --git a/telehttpd.c b/telehttpd.c index b8229d0..69f9454 100644 --- a/telehttpd.c +++ b/telehttpd.c @@ -65,6 +65,8 @@ static void write_telejson( int fd ) { 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, " \"game_time\": %u,\n", telemetry->game_time ) ); + write(fd, buf, sprintf( buf, " \"x\": %f,\n", telemetry->x ) ); write(fd, buf, sprintf( buf, " \"y\": %f,\n", telemetry->y ) ); write(fd, buf, sprintf( buf, " \"z\": %f,\n", telemetry->z ) ); @@ -91,6 +93,8 @@ static void write_telejson( int fd ) { write(fd, buf, sprintf( buf, " \"nav_slimit\": %f,\n", telemetry->nav_slimit ) ); write(fd, buf, sprintf( buf, " \"next_rest\": %d,\n", telemetry->next_rest ) ); + write(fd, buf, sprintf( buf, " \"job_deltime\": %u,\n", telemetry->job_deltime ) ); + // add more here write(fd, buf, sprintf( buf, " \"dummy\": 0\n" ) ); diff --git a/telelogger.c b/telelogger.c index a4c744f..b744572 100644 --- a/telelogger.c +++ b/telelogger.c @@ -41,6 +41,7 @@ static int log_console(void) { // uint64_t raw_rendering_timestamp; // uint64_t raw_simulation_timestamp; // uint64_t raw_paused_simulation_timestamp; + printf( "game_time: %u\n", telemetry->game_time ); if ( telemetry->placement_available ) { printf( "position: %.3f, %.3f, %.3f\n", @@ -71,6 +72,7 @@ static int log_console(void) { printf( "nav eta: %s\n", s2hms( telemetry->nav_eta ) ); printf( "nav limit: %.1f km/h\n", telemetry->nav_slimit * 3.6 ); printf( "next rest: %s\n", m2hm( telemetry->next_rest ) ); + printf( "time till delivery: %s\n", m2hm( telemetry->job_deltime - telemetry->game_time ) ); puts(""); diff --git a/telemetry.h b/telemetry.h index b1dba1d..ea6a12a 100644 --- a/telemetry.h +++ b/telemetry.h @@ -15,6 +15,8 @@ struct telemetry_state_t { uint64_t raw_simulation_timestamp; uint64_t raw_paused_simulation_timestamp; + unsigned game_time; // minutes since beginning of first in-game day + // truck placement and orientation bool placement_available; double x; @@ -42,6 +44,8 @@ struct telemetry_state_t { float nav_eta; // navigation time in s float nav_slimit; // navigation speed limit in m/s int next_rest; // time to next rest stop in minutes + + unsigned job_deltime; // job deadline in minutes (see game_time) }; #endif /* TELEMETRY_H_ */ diff --git a/teleshmem.cpp b/teleshmem.cpp index a0b19d2..df1c0ff 100644 --- a/teleshmem.cpp +++ b/teleshmem.cpp @@ -165,16 +165,19 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e for (const scs_named_value_t *current = info->attributes; current->name; ++current) { - // SCS_TELEMETRY_CONFIG_ATTRIBUTE_shifter_type - // SCS_SHIFTER_TYPE_arcade - // SCS_SHIFTER_TYPE_automatic - // SCS_SHIFTER_TYPE_manual - // SCS_SHIFTER_TYPE_hshifter - if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_shifter_type ) ) + if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_shifter_type ) ) { + // SCS_SHIFTER_TYPE_arcade + // SCS_SHIFTER_TYPE_automatic + // SCS_SHIFTER_TYPE_manual + // SCS_SHIFTER_TYPE_hshifter telemetry->shifter = !strcmp( current->value.value_string.value, SCS_SHIFTER_TYPE_manual ) || !strcmp( current->value.value_string.value, SCS_SHIFTER_TYPE_hshifter ); + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_delivery_time ) ) { + telemetry->job_deltime = current->value.value_u32.value; + } - + // log configuration log_print(" %s", current->name); if (current->index != SCS_U32_NIL) { log_print("[%u]", static_cast(current->index)); @@ -330,6 +333,17 @@ SCSAPI_VOID telemetry_store_s32(const scs_string_t name, const scs_u32_t index, *static_cast(context) = value->value_s32.value; } +SCSAPI_VOID telemetry_store_u32(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) +{ + // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration + // so this callback is only called when a valid value is available. + + assert(value); + assert(value->type == SCS_VALUE_TYPE_u32); + assert(context); + *static_cast(context) = value->value_u32.value; +} + SCSAPI_VOID telemetry_store_bool(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) { // The SCS_TELEMETRY_CHANNEL_FLAG_no_value flag was not provided during registration @@ -442,6 +456,8 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in // (SCS_RESULT_unsupported_type). For purpose of this example we ignore the failues // so the unsupported channels will remain at theirs default value. + version_params->register_for_channel(SCS_TELEMETRY_CHANNEL_game_time, SCS_U32_NIL, SCS_VALUE_TYPE_u32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_u32, &telemetry->game_time); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_world_placement, SCS_U32_NIL, SCS_VALUE_TYPE_dplacement, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_dplacement, telemetry); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_speed, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->speed); -- 2.30.2