From: Urban Wallasch Date: Wed, 31 Jul 2019 12:17:23 +0000 (+0200) Subject: * Added more truck and job configuration data to telemetry. X-Git-Tag: v0.1.0~49 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=4be5aedbd5a9524095afad2784cbd2c9558e0af2;p=ets2_tele.git * Added more truck and job configuration data to telemetry. --- diff --git a/dash.html b/dash.html index 3d3d0d1..3cdfc95 100644 --- a/dash.html +++ b/dash.html @@ -120,6 +120,18 @@ x-bar { + + + + + + + + + +
Vehicle -
Trailers -
Cargo -
Mass -
From -
To -
Reward -
+
+ Paused @@ -148,6 +160,14 @@ var nav_slimit = document.getElementById("nav_slimit"); var next_rest = document.getElementById("next_rest"); var job_ttd = document.getElementById("job_ttd"); // +var vehicle = document.getElementById("vehicle"); +var trailer = document.getElementById("trailer"); +var cargo = document.getElementById("cargo"); +var cargomass = document.getElementById("cargomass"); +var source = document.getElementById("source"); +var destination = document.getElementById("destination"); +var reward = document.getElementById("reward"); +// var errbar = document.getElementById("errbar"); var pausebar = document.getElementById("pausebar"); @@ -292,6 +312,17 @@ function update_cb() { : '[external]' : '[none]' + //// "job" box + + // make and model of truck and number of trailers + vehicle.innerHTML = tele.truck_brand + ' ' + tele.truck_name; + trailer.innerHTML = tele.trailer_cnt; + cargo.innerHTML = tele.job_isvalid ? tele.job_cargo : '-'; + cargomass.innerHTML = tele.job_isvalid ? (tele.job_cargo_mass / 1000).toFixed(0) + 't' : '-'; + source.innerHTML = tele.job_isvalid ? tele.job_source_city : '-'; + destination.innerHTML = tele.job_isvalid ? tele.job_destination_city : '-'; + reward.innerHTML = tele.job_isvalid ? tele.job_income + '.-' : '-'; + //// pause and error bar status: pausebar.style.display = tele.paused ? "block" : "none"; diff --git a/telehttpd.c b/telehttpd.c index c465c14..076b818 100644 --- a/telehttpd.c +++ b/telehttpd.c @@ -79,7 +79,7 @@ static void write_telejson( int fd ) { write(fd, buf, sprintf( buf, " \"rpm\": %f,\n", telemetry->rpm ) ); write(fd, buf, sprintf( buf, " \"gear\": %d,\n", telemetry->gear ) ); write(fd, buf, sprintf( buf, " \"gear_disp\": %d,\n", telemetry->gear_disp ) ); - write(fd, buf, sprintf( buf, " \"gear_fwdcnt\": %u,\n", telemetry->gear_fwdcnt ) ); + write(fd, buf, sprintf( buf, " \"gear_fwdcnt\": %u,\n", telemetry->truck_fwd_gear_cnt ) ); write(fd, buf, sprintf( buf, " \"clutch_eff\": %f,\n", telemetry->clutch_eff ) ); write(fd, buf, sprintf( buf, " \"shifter\": %d,\n", telemetry->shifter ) ); @@ -94,8 +94,18 @@ 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, " \"truck_brand\": \"%s\",\n", telemetry->truck_brand ) ); + write(fd, buf, sprintf( buf, " \"truck_name\": \"%s\",\n", telemetry->truck_name ) ); + + write(fd, buf, sprintf( buf, " \"trailer_cnt\": %u,\n", telemetry->trailer_cnt ) ); + write(fd, buf, sprintf( buf, " \"job_isvalid\": %d,\n", (int)telemetry->job_isvalid ) ); write(fd, buf, sprintf( buf, " \"job_deltime\": %u,\n", telemetry->job_deltime ) ); + write(fd, buf, sprintf( buf, " \"job_income\": %"PRIu64",\n", telemetry->job_income ) ); + write(fd, buf, sprintf( buf, " \"job_cargo_mass\": %f,\n", telemetry->job_cargo_mass ) ); + write(fd, buf, sprintf( buf, " \"job_cargo\": \"%s\",\n", telemetry->job_cargo ) ); + write(fd, buf, sprintf( buf, " \"job_source_city\": \"%s\",\n", telemetry->job_source_city ) ); + write(fd, buf, sprintf( buf, " \"job_destination_city\": \"%s\",\n", telemetry->job_destination_city ) ); // add more here diff --git a/telelogger.c b/telelogger.c index 1647742..5d29228 100644 --- a/telelogger.c +++ b/telelogger.c @@ -59,7 +59,7 @@ static int log_console(void) { printf( "rpm: %.0f /min\n", telemetry->rpm ); printf( "gear: %d\n", telemetry->gear ); printf( "gear d: %d\n", telemetry->gear_disp ); - printf( "gear fwd cnt: %u\n", telemetry->gear_fwdcnt ); + printf( "fwd gear cnt: %u\n", telemetry->truck_fwd_gear_cnt ); printf( "clutch eff: %.1f\n", telemetry->clutch_eff ); printf( "shifter: %s\n", telemetry->shifter ? "manual" : "automatic" ); @@ -74,8 +74,19 @@ static int log_console(void) { 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", - telemetry->job_isvalid ? m2hm( telemetry->job_deltime - telemetry->game_time ) : "--:--" ); + printf( "truck brand: %s\n", telemetry->truck_brand ); + printf( "truck model: %s\n", telemetry->truck_name ); + + printf( "trailer count: %u\n", telemetry->trailer_cnt ); + + if ( telemetry->job_isvalid ) { + printf( "job delivery time: %s\n", m2hm( telemetry->job_deltime - telemetry->game_time ) ); + printf( "job income: %"PRIu64"\n", telemetry->job_income / 10 ); + printf( "job cargo mass: %.1f t\n", telemetry->job_cargo_mass / 1000 ); + printf( "job cargo: %s\n", telemetry->job_cargo ); + printf( "job source city: %s\n", telemetry->job_source_city ); + printf( "job destination city: %s\n", telemetry->job_destination_city ); + } puts(""); diff --git a/telemetry.h b/telemetry.h index f885996..19286f5 100644 --- a/telemetry.h +++ b/telemetry.h @@ -6,6 +6,8 @@ #define TELE_SHM_KEY 0xecc11 +#define TELE_STRLEN 30 + struct telemetry_state_t { char game_id[10]; unsigned game_major_ver; @@ -34,7 +36,6 @@ struct telemetry_state_t { float rpm; // engine rpm int gear; // engine gear int gear_disp; // displayed gear - unsigned gear_fwdcnt; // gearbox number of forward gears float clutch_eff; // effective clutch int shifter; // 0 = automatic, 1 = manual @@ -49,8 +50,19 @@ struct telemetry_state_t { float nav_slimit; // navigation speed limit in m/s int next_rest; // time to next rest stop in minutes + char truck_brand[TELE_STRLEN]; // truck brand name + char truck_name[TELE_STRLEN]; // truck model name + unsigned truck_fwd_gear_cnt; // truck number of forward gears + bool job_isvalid; // job info is current, i.e. job is in progress unsigned job_deltime; // job deadline in minutes (see game_time) + uint64_t job_income; // job reward without penalties in in-game currency + float job_cargo_mass; // cargo mass in kg + char job_cargo[TELE_STRLEN]; // job cargo name + char job_source_city[TELE_STRLEN]; // job source city name + char job_destination_city[TELE_STRLEN]; // job destination city name + + unsigned trailer_cnt; // number of active trailers }; #endif /* TELEMETRY_H_ */ diff --git a/teleshmem.cpp b/teleshmem.cpp index 6109f21..dab22ee 100644 --- a/teleshmem.cpp +++ b/teleshmem.cpp @@ -274,14 +274,50 @@ SCSAPI_VOID telemetry_gameplay(const scs_event_t event, const void *const event_ } } + +#define TELEMETRY_CONFIG_trailerX "trailer." + SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const event_info, const scs_context_t UNUSED(context)) { const struct scs_telemetry_configuration_t *const info = static_cast(event_info); if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_truck ) ) { + /* + * @li brand_id + * @li brand + * @li id + * @li name + * @li fuel_capacity + * @li fuel_warning_factor + * @li adblue_capacity + * @li ablue_warning_factor + * @li air_pressure_warning + * @li air_pressure_emergency + * @li oil_pressure_warning + * @li water_temperature_warning + * @li battery_voltage_warning + * @li rpm_limit + * @li foward_gear_count + * @li reverse_gear_count + * @li retarder_step_count + * @li cabin_position + * @li head_position + * @li hook_position + * @li license_plate + * @li license_plate_country + * @li license_plate_country_id + * @li wheel_count + * @li wheel positions for wheel_count wheels + */ for (const scs_named_value_t *current = info->attributes; current->name; ++current) { - if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_forward_gear_count ) ) { - telemetry->gear_fwdcnt = current->value.value_u32.value; + if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_brand ) ) { + snprintf( telemetry->truck_brand, sizeof telemetry->truck_brand, "%s", current->value.value_string.value ); + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_name ) ) { + snprintf( telemetry->truck_name, sizeof telemetry->truck_name, "%s", current->value.value_string.value ); + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_forward_gear_count ) ) { + telemetry->truck_fwd_gear_cnt = current->value.value_u32.value; } } } @@ -298,11 +334,57 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e } } else if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_job ) ) { + /* + * @li cargo_id + * @li cargo + * @li cargo_mass + * @li destination_city_id + * @li destination_city + * @li source_city_id + * @li source_city + * @li destination_company_id (only available for non special transport jobs) + * @li destination_company (only available for non special transport jobs) + * @li source_company_id (only available for non special transport jobs) + * @li source_company (only available for non special transport jobs) + * @li income - represents expected income for the job without any penalties + * @li delivery_time + * @li is_cargo_loaded + * @li job_market + * @li special_job + */ for (const scs_named_value_t *current = info->attributes; current->name; ++current) { if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_delivery_time ) ) { telemetry->job_deltime = current->value.value_u32.value; telemetry->job_isvalid = true; } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_income ) ) { + telemetry->job_income = current->value.value_u64.value; + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_cargo_mass ) ) { + telemetry->job_cargo_mass = current->value.value_float.value; + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_cargo ) ) { + snprintf( telemetry->job_cargo, sizeof telemetry->job_cargo, "%s", current->value.value_string.value ); + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_source_city ) ) { + snprintf( telemetry->job_source_city, sizeof telemetry->job_source_city, "%s", current->value.value_string.value ); + } + else if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_destination_city ) ) { + snprintf( telemetry->job_destination_city, sizeof telemetry->job_destination_city, "%s", current->value.value_string.value ); + } + } + } + else if ( 0 == strcmp( info->id, SCS_TELEMETRY_CONFIG_trailer ) ) + { // (Ab)use the compatibility single trailer configuration to reset the trailer counter. + telemetry->trailer_cnt = 0; + } + else if ( 0 == strncmp( info->id, TELEMETRY_CONFIG_trailerX, strlen(TELEMETRY_CONFIG_trailerX) ) ) { + // sample the last valid trailer's index plus one + for (const scs_named_value_t *current = info->attributes; current->name; ++current) { + if ( 0 == strcmp( current->name, SCS_TELEMETRY_CONFIG_ATTRIBUTE_id ) ) { + telemetry->trailer_cnt = strtoul(info->id + strlen(TELEMETRY_CONFIG_trailerX), NULL, 0) + 1; + break; + } } }