* Small improvements in telemetry .cpp.
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" ) );
}
#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 ) {
// 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 );
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 )
static int shmid = -1;
-bool init_shm(void)
+static bool init_shm(void)
{
if ( 0 < shmid )
return true;
return true;
}
-void release_shm(void)
+static void release_shm(void)
{
if ( 0 < shmid) {
shmdt(telemetry);
* @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, ...)
{
}
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<telemetry_state_t *>(context);
*static_cast<int *>(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<bool *>(context) = value->value_bool.value;
+}
+
/**
* @brief Telemetry API initialization function.
*
const scs_telemetry_init_params_v100_t *const version_params = static_cast<const scs_telemetry_init_params_v100_t *>(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;
}
// 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.
uint64_t raw_simulation_timestamp;
uint64_t raw_paused_simulation_timestamp;
+ // truck placement and orientation
bool placement_available;
double x;
double y;
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_ */