6
6
#include " custom_types.h"
7
7
#include " helper_functions.h"
8
8
9
- SCSAPI_VOID handle_frame_start (const scs_event_t UNUSED (event), const void* const event_info, const scs_context_t context) {
9
+ SCSAPI_VOID handle_frame_start (const scs_event_t UNUSED (event), const void* const UNUSED( event_info) , const scs_context_t context) {
10
10
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
11
11
12
12
std::stringstream state;
@@ -41,7 +41,7 @@ SCSAPI_VOID handle_pause_start(const scs_event_t event, const void* const UNUSED
41
41
SCSAPI_VOID handle_position (const scs_string_t name, const scs_u32_t index, const scs_value_t * const value, const scs_context_t context) {
42
42
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
43
43
44
- if (! value) {
44
+ if (value == NULL ) {
45
45
telemetry->position .avalible = false ;
46
46
return ;
47
47
}
@@ -53,23 +53,26 @@ SCSAPI_VOID handle_position(const scs_string_t name, const scs_u32_t index, cons
53
53
point2d p{ (double )telemetry->position .x , (double )telemetry->position .z };
54
54
point2d closest_city = telemetry->cities ->nearest (p);
55
55
56
- telemetry->position .closestCity = closest_city.name ;
57
- telemetry->position .country = closest_city.country ;
56
+ telemetry->position .closestCity = static_cast <std::string>( closest_city.name ) ;
57
+ telemetry->position .country = static_cast <std::string>( closest_city.country ) ;
58
58
}
59
59
60
60
SCSAPI_VOID handle_speed (const scs_string_t name, const scs_u32_t index, const scs_value_t * const value, const scs_context_t context) {
61
+ if (value == NULL ) return ;
61
62
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
62
63
63
64
telemetry->speed = value->value_float .value ;
64
65
}
65
66
66
67
SCSAPI_VOID handle_distance (const scs_string_t name, const scs_u32_t index, const scs_value_t * const value, const scs_context_t context) {
68
+ if (value == NULL ) return ;
67
69
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
68
70
69
71
telemetry->distance = value->value_float .value ;
70
72
}
71
73
72
74
SCSAPI_VOID handle_trailer_connect (const scs_string_t name, const scs_u32_t index, const scs_value_t * const value, const scs_context_t context) {
75
+ if (value == NULL ) return ;
73
76
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
74
77
75
78
if (value) {
@@ -82,19 +85,17 @@ SCSAPI_VOID handle_trailer_connect(const scs_string_t name, const scs_u32_t inde
82
85
83
86
SCSAPI_VOID handle_configuration (const scs_event_t event, const void * const event_info, const scs_context_t context)
84
87
{
88
+ if (event_info == NULL ) return ;
85
89
telemetry_state* const telemetry = static_cast <telemetry_state*>(context);
86
90
const struct scs_telemetry_configuration_t * const info = static_cast <const scs_telemetry_configuration_t *>(event_info);
87
91
88
92
std::string id = info->id ;
89
93
90
94
if (id.compare (SCS_TELEMETRY_CONFIG_job) == 0 ) {
91
- for (size_t i = 0 ; i < sizeof (info->attributes ) / sizeof (scs_named_value_t ); i++)
92
- {
93
- const scs_named_value_t * current = &info->attributes [i];
95
+ for (const scs_named_value_t * current = info->attributes ; current->name ; ++current) {
94
96
const std::string name = current->name ;
95
-
96
97
if (name.compare (SCS_TELEMETRY_CONFIG_ATTRIBUTE_cargo) == 0 ) {
97
- telemetry->cargo .name = current->value .value_string .value ;
98
+ telemetry->cargo .name = static_cast <std::string>( current->value .value_string .value ) ;
98
99
}
99
100
else if (name.compare (SCS_TELEMETRY_CONFIG_ATTRIBUTE_cargo_mass) == 0 ) {
100
101
telemetry->cargo .weight = current->value .value_float .value ;
@@ -105,16 +106,13 @@ SCSAPI_VOID handle_configuration(const scs_event_t event, const void* const even
105
106
}
106
107
}
107
108
else if (id.compare (SCS_TELEMETRY_CONFIG_truck) == 0 ) {
108
- for (size_t i = 0 ; i < sizeof (info->attributes ) / sizeof (scs_named_value_t ); i++)
109
- {
110
- const scs_named_value_t * current = &info->attributes [i];
109
+ for (const scs_named_value_t * current = info->attributes ; current->name ; ++current) {
111
110
const std::string name = current->name ;
112
-
113
111
if (name.compare (SCS_TELEMETRY_CONFIG_ATTRIBUTE_brand) == 0 ) {
114
- telemetry->truck .brand = current->value .value_string .value ;
112
+ telemetry->truck .brand = static_cast <std::string>( current->value .value_string .value ) ;
115
113
}
116
114
else if (name.compare (SCS_TELEMETRY_CONFIG_ATTRIBUTE_name) == 0 ) {
117
- telemetry->truck .name = current->value .value_string .value ;
115
+ telemetry->truck .name = static_cast <std::string>( current->value .value_string .value ) ;
118
116
}
119
117
}
120
118
}
0 commit comments