From: Urban Wallasch Date: Tue, 23 Jul 2019 11:49:16 +0000 (+0200) Subject: * Added several parameters to telemetry. X-Git-Tag: v0.1.0~80 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=911113c32de480b2655ff5d4345143f70e879b25;p=ets2_tele.git * Added several parameters to telemetry. * Small improvements in telemetry .cpp. --- diff --git a/telehttpd.c b/telehttpd.c index 73b3f89..1363d40 100644 --- a/telehttpd.c +++ b/telehttpd.c @@ -62,12 +62,25 @@ static void write_telejson( int fd ) { write(fd, buf, sprintf( buf, " \"heading\": %f,\n", telemetry->heading ) ); write(fd, buf, sprintf( buf, " \"pitch\": %f,\n", telemetry->pitch ) ); write(fd, buf, sprintf( buf, " \"roll\": %f,\n", telemetry->roll ) ); + write(fd, buf, sprintf( buf, " \"speed\": %f,\n", telemetry->speed ) ); + write(fd, buf, sprintf( buf, " \"cctrl\": %f,\n", telemetry->cctrl ) ); 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, " \"cctrl\": %f,\n", telemetry->cctrl ) ); - write(fd, buf, sprintf( buf, " \"fc_avg\": %f,\n", telemetry->fc_avg ) ); + write(fd, buf, sprintf( buf, " \"gear disp\": %d,\n", telemetry->gear_disp ) ); + + write(fd, buf, sprintf( buf, " \"fuel\": %f,\n", telemetry->fuel ) ); + write(fd, buf, sprintf( buf, " \"fuel_warn\": %d,\n", (int)telemetry->fuel_warn ) ); + write(fd, buf, sprintf( buf, " \"fuel_avg\": %f,\n", telemetry->fuel_avg ) ); + write(fd, buf, sprintf( buf, " \"fuel_range\": %f,\n", telemetry->fuel_range ) ); + + write(fd, buf, sprintf( buf, " \"odometer\": %f,\n", telemetry->odometer ) ); + write(fd, buf, sprintf( buf, " \"nav dist\": %f,\n", telemetry->nav_dist ) ); + write(fd, buf, sprintf( buf, " \"nav eta\": %f,\n", telemetry->nav_eta ) ); + write(fd, buf, sprintf( buf, " \"nav limit\": %f,\n", telemetry->nav_slimit ) ); + // add more here + write(fd, buf, sprintf( buf, " \"dummy\": 0\n" ) ); write(fd, buf, sprintf( buf, "}\n" ) ); } diff --git a/telelogger.c b/telelogger.c index 9e856ff..406f72c 100644 --- a/telelogger.c +++ b/telelogger.c @@ -8,6 +8,12 @@ #include "shmget.h" +static const char *s2hms( int s ) { + static char buf[50]; + sprintf( buf, "%02d:%02d:%02d", s / 3600, s % 3600 / 60, s % 60 ); + return buf; +} + static int log_console(void) { uint64_t last_timestamp = telemetry->timestamp; while ( 1 ) { @@ -15,6 +21,7 @@ static int log_console(void) { // uint64_t raw_rendering_timestamp; // uint64_t raw_simulation_timestamp; // uint64_t raw_paused_simulation_timestamp; + if ( telemetry->placement_available ) { printf( "position: %.3f, %.3f, %.3f\n", telemetry->x, telemetry->y, telemetry->z ); @@ -25,11 +32,23 @@ static int log_console(void) { printf( "position: n.a.\n" ); printf( "orientation: n.a.\n" ); } - printf( "speed: %.1fkm/h (%.1fm/s)\n", telemetry->speed * 3.6, telemetry->speed ); - printf( "cctrl: %.1fkm/h (%.1fm/s)\n", telemetry->cctrl * 3.6, telemetry->cctrl ); - printf( "rpm: %.0f\n", telemetry->rpm ); + + printf( "speed: %.1f km/h (%.1f m/s)\n", telemetry->speed * 3.6, telemetry->speed ); + printf( "cctrl: %.1f km/h (%.1f m/s)\n", telemetry->cctrl * 3.6, telemetry->cctrl ); + printf( "rpm: %.0f /min\n", telemetry->rpm ); printf( "gear: %d\n", telemetry->gear ); - printf( "fc_avg: %.1f\n", telemetry->fc_avg ); + printf( "gear d: %d\n", telemetry->gear_disp ); + + printf( "fuel: %.1f l\n", telemetry->fuel ); + printf( "fuel warn: %s\n", telemetry->fuel_warn ? "yes" : "no" ); + printf( "fuel average: %.1f l/100km\n", telemetry->fuel_avg * 100 ); + printf( "fuel range: %.1f km\n", telemetry->fuel_range ); + + printf( "odometer: %.1f km\n", telemetry->odometer ); + printf( "nav dist: %.1f km\n", telemetry->nav_dist / 1000 ); + printf( "nav eta: %s\n", s2hms( telemetry->nav_eta ) ); + printf( "nav limit: %.1f km/h\n", telemetry->nav_slimit * 3.6 ); + puts(""); sleep( 1 ); while ( last_timestamp == telemetry->timestamp ) diff --git a/telemetry.cpp b/telemetry.cpp index b24de20..650f6c5 100644 --- a/telemetry.cpp +++ b/telemetry.cpp @@ -60,7 +60,7 @@ struct telemetry_state_t *telemetry; static int shmid = -1; -bool init_shm(void) +static bool init_shm(void) { if ( 0 < shmid ) return true; @@ -75,7 +75,7 @@ bool init_shm(void) return true; } -void release_shm(void) +static void release_shm(void) { if ( 0 < shmid) { shmdt(telemetry); @@ -88,11 +88,11 @@ void release_shm(void) * @brief Function writting message to the game internal log. */ -void log_print(const char *const text, ...) +static void log_print(const char *const text, ...) { } -void log_line(const char *const text, ...) +static void log_line(const char *const text, ...) { } @@ -285,6 +285,8 @@ SCSAPI_VOID telemetry_configuration(const scs_event_t event, const void *const e SCSAPI_VOID telemetry_store_dplacement(const scs_string_t name, const scs_u32_t index, const scs_value_t *const value, const scs_context_t context) { + assert(value); + assert(value->type == SCS_VALUE_TYPE_dplacement); assert(context); telemetry_state_t *const tele = static_cast(context); @@ -325,6 +327,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_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 + // so this callback is only called when a valid value is available. + + assert(value); + assert(value->type == SCS_VALUE_TYPE_bool); + assert(context); + *static_cast(context) = value->value_bool.value; +} + /** * @brief Telemetry API initialization function. * @@ -340,7 +353,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()) { - version_params->common.log(SCS_LOG_TYPE_error, "Unable to initialize the log file"); + version_params->common.log(SCS_LOG_TYPE_error, "Unable to initialize shared memory"); return SCS_RESULT_generic_error; } @@ -418,11 +431,22 @@ SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_in // so the unsupported channels will remain at theirs default value. 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); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_cruise_control, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->cctrl); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_rpm, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->rpm); version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_gear, SCS_U32_NIL, SCS_VALUE_TYPE_s32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_s32, &telemetry->gear); - version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_cruise_control, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->cctrl); - version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel_average_consumption, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->fc_avg); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_displayed_gear, SCS_U32_NIL, SCS_VALUE_TYPE_s32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_s32, &telemetry->gear_disp); + + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->fuel); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel_warning, SCS_U32_NIL, SCS_VALUE_TYPE_bool, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_bool, &telemetry->fuel_warn); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel_average_consumption, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->fuel_avg); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel_range, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->fuel_range); + + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_odometer, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->odometer); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_navigation_distance, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->nav_dist); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_navigation_time, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->nav_eta); + version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_navigation_speed_limit, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->nav_slimit); // Set the structure with defaults. diff --git a/telemetry.h b/telemetry.h index 4495922..ea65e70 100644 --- a/telemetry.h +++ b/telemetry.h @@ -9,6 +9,7 @@ struct telemetry_state_t { uint64_t raw_simulation_timestamp; uint64_t raw_paused_simulation_timestamp; + // truck placement and orientation bool placement_available; double x; double y; @@ -17,11 +18,21 @@ struct telemetry_state_t { double pitch; double roll; - float speed; - float rpm; - int gear; - float cctrl; // cruise_control - float fc_avg; // fuel consumption average + float speed; // truck speed in m/s + float cctrl; // cruise_control in m/s + float rpm; // engine rpm + int gear; // engine gear + int gear_disp; // displayed gear + + float fuel; // fuel amount in l + bool fuel_warn; // fuel low warning + float fuel_avg; // fuel consumption average in l/km + float fuel_range; // estimated range in km + + float odometer; // odometer reading + float nav_dist; // navigation distance in m + float nav_eta; // navigation time in s + float nav_slimit; // navigation speed limit in m/s }; #endif /* TELEMETRY_H_ */