11#include < client.h>
22#include < cstdio>
3- #include < cstring>
43#include < cinttypes>
54#include < pb_decode.h>
65#include < pb_encode.h>
76#include < signatures.pb.h>
8- #include < string.h >
7+ #include < cstring >
98#include < universal_message.pb.h>
109#include < vcsec.pb.h>
1110#include < sstream>
1211#include < iomanip>
1312
1413#include " defs.h"
1514#include " errors.h"
16- #include " tb_utils.h"
17- #include " log.cpp"
15+ #include " log.h"
1816
1917// mock data from PROTOCOL.md examples
20- static const char * MOCK_VIN = " 5YJ30123456789ABC" ;
18+ static constexpr char MOCK_VIN[] = " 5YJ30123456789ABC" ;
2119static const unsigned char MOCK_PRIVATE_KEY[227 ] =
2220 " -----BEGIN EC PRIVATE "
2321 " KEY-----\n MHcCAQEEILRjIS9VEyG+0K71a2T/"
@@ -40,16 +38,16 @@ int main() {
4038 * this loads an existing private key and generates the public key
4139 */
4240 LOG_INFO (" Loading private key" );
43- TeslaBLE::TeslaBLEStatus status = client.load_private_key (MOCK_PRIVATE_KEY, sizeof MOCK_PRIVATE_KEY);
44- // int status = client.createPrivateKey ();
45- if (status != TeslaBLE::TeslaBLEStatus::OK ) {
41+ int status = client.load_private_key (MOCK_PRIVATE_KEY, sizeof MOCK_PRIVATE_KEY);
42+ // int status = client.create_private_key ();
43+ if (status != 0 ) {
4644 LOG_ERROR (" Failed create private key" );
4745 }
4846
4947 unsigned char private_key_buffer[sizeof MOCK_PRIVATE_KEY + 1 ];
5048 size_t private_key_length;
5149 status = client.get_private_key (private_key_buffer, sizeof (private_key_buffer), &private_key_length);
52- if (status != TeslaBLE::TeslaBLEStatus::OK ) {
50+ if (status != 0 ) {
5351 LOG_ERROR (" Failed to get private key" );
5452 }
5553 LOG_DEBUG (" Private key length: %d" , private_key_length);
@@ -60,13 +58,13 @@ int main() {
6058 // support for wake command added to CHARGING_MANAGER_ROLE in 2024.20.x (not sure?)
6159 // https://github.com/teslamotors/vehicle-command/issues/232#issuecomment-2181503570
6260 LOG_INFO (" Building whitelist message for CHARGING MANAGER" );
63- TeslaBLE::TeslaBLEStatus return_code =
61+ int return_code =
6462 client.build_white_list_message (Keys_Role_ROLE_CHARGING_MANAGER, VCSEC_KeyFormFactor_KEY_FORM_FACTOR_CLOUD_KEY,
6563 whitelist_message_buffer, &whitelist_message_length);
6664
67- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
68- LOG_ERROR ( " Failed to build whitelist message: %s " ,
69- TeslaBLE::teslable_status_to_string (static_cast <TeslaBLE::TeslaBLEStatus>(return_code) ));
65+ if (return_code != 0 ) {
66+ auto status = static_cast <TeslaBLE::TeslaBLE_Status_E>(return_code);
67+ LOG_ERROR ( " Failed to build whitelist message: %s " , TeslaBLE::teslable_status_to_string (status ));
7068 return -1 ;
7169 }
7270 LOG_DEBUG (" Whitelist message length: %d" , whitelist_message_length);
@@ -91,26 +89,26 @@ int main() {
9189 UniversalMessage_RoutableMessage received_message_vcsec = UniversalMessage_RoutableMessage_init_default;
9290 return_code =
9391 client.parse_universal_message (received_bytes_vcsec, sizeof (received_bytes_vcsec), &received_message_vcsec);
94- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
95- LOG_ERROR ( " Failed to parse received message VSSE: %s " ,
96- TeslaBLE::teslable_status_to_string (static_cast <TeslaBLE::TeslaBLEStatus>(return_code) ));
92+ if (return_code != 0 ) {
93+ auto status = static_cast <TeslaBLE::TeslaBLE_Status_E>(return_code);
94+ LOG_ERROR ( " Failed to parse received message VSSE: %s " , TeslaBLE::teslable_status_to_string (status ));
9795 return -1 ;
9896 }
9997 log_routable_message (&received_message_vcsec);
10098
10199 Signatures_SessionInfo session_info_vcsec = Signatures_SessionInfo_init_default;
102100 return_code = client.parse_payload_session_info (&received_message_vcsec.payload .session_info , &session_info_vcsec);
103- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
101+ if (return_code != 0 ) {
104102 LOG_ERROR (" Failed to parse session info VSSEC" );
105103 return -1 ;
106104 }
107105 log_session_info (&session_info_vcsec);
108106
109107 UniversalMessage_Domain domain = UniversalMessage_Domain_DOMAIN_VEHICLE_SECURITY;
110- auto session = client.get_peer (domain);
108+ auto * session = client.get_peer (domain);
111109
112110 return_code = session->update_session (&session_info_vcsec);
113- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
111+ if (return_code != 0 ) {
114112 LOG_ERROR (" Failed to update session VSSEC" );
115113 return -1 ;
116114 }
@@ -134,7 +132,7 @@ int main() {
134132 size_t action_message_buffer_length = 0 ;
135133 return_code = client.build_vcsec_action_message (VCSEC_RKEAction_E_RKE_ACTION_WAKE_VEHICLE, action_message_buffer,
136134 &action_message_buffer_length);
137- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
135+ if (return_code != 0 ) {
138136 LOG_ERROR (" Failed to build action message " );
139137 return -1 ;
140138 }
@@ -148,7 +146,7 @@ int main() {
148146 return_code =
149147 client.build_vcsec_information_request_message (VCSEC_InformationRequestType_INFORMATION_REQUEST_TYPE_GET_STATUS,
150148 info_request_status_buffer, &info_request_status_length);
151- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
149+ if (return_code != 0 ) {
152150 LOG_ERROR (" Failed to build action message " );
153151 return -1 ;
154152 }
@@ -175,7 +173,7 @@ int main() {
175173 UniversalMessage_RoutableMessage received_message = UniversalMessage_RoutableMessage_init_default;
176174 return_code = client.parse_universal_message (received_bytes_infotainment, sizeof (received_bytes_infotainment),
177175 &received_message);
178- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
176+ if (return_code != 0 ) {
179177 LOG_ERROR (" Failed to parse received message INFOTAINMENT" );
180178 return -1 ;
181179 }
@@ -184,15 +182,15 @@ int main() {
184182 LOG_INFO (" Parsing session info INFOTAINMENT" );
185183 Signatures_SessionInfo session_info = Signatures_SessionInfo_init_default;
186184 return_code = client.parse_payload_session_info (&received_message.payload .session_info , &session_info);
187- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
188- printf (" Failed to parse session info INFOTAINMENT" );
185+ if (return_code != 0 ) {
186+ LOG_ERROR (" Failed to parse session info INFOTAINMENT" );
189187 return -1 ;
190188 }
191189 log_session_info (&session_info);
192190
193191 session = client.get_peer (UniversalMessage_Domain_DOMAIN_INFOTAINMENT);
194192 return_code = session->update_session (&session_info);
195- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
193+ if (return_code != 0 ) {
196194 LOG_ERROR (" Failed to update session INFOTAINMENT" );
197195 return -1 ;
198196 }
@@ -223,7 +221,7 @@ int main() {
223221 return_code = client.build_car_server_vehicle_action_message (
224222 charging_amps_message_buffer, &charging_amps_message_length, CarServer_VehicleAction_setChargingAmpsAction_tag,
225223 &charging_amps_action);
226- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
224+ if (return_code != 0 ) {
227225 LOG_ERROR (" Failed to build charging amps message" );
228226 return -1 ;
229227 }
@@ -239,7 +237,7 @@ int main() {
239237 return_code = client.build_car_server_vehicle_action_message (
240238 charging_limit_message_buffer, &charging_limit_message_length, CarServer_VehicleAction_chargingSetLimitAction_tag,
241239 &charging_limit_action);
242- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
240+ if (return_code != 0 ) {
243241 LOG_ERROR (" Failed to build charging limit message" );
244242 return -1 ;
245243 }
@@ -255,7 +253,7 @@ int main() {
255253 hvac_action.manual_override = false ;
256254 return_code = client.build_car_server_vehicle_action_message (
257255 hvac_on_message_buffer, &hvac_on_message_length, CarServer_VehicleAction_hvacAutoAction_tag, &hvac_action);
258- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
256+ if (return_code != 0 ) {
259257 LOG_ERROR (" Failed to build HVAC message" );
260258 return -1 ;
261259 }
@@ -267,8 +265,8 @@ int main() {
267265 size_t get_data_message_length;
268266 return_code = client.build_car_server_get_vehicle_data_message (get_data_message_buffer, &get_data_message_length,
269267 CarServer_GetVehicleData_getChargeState_tag);
270- if (return_code != TeslaBLE::TeslaBLEStatus::OK ) {
271- LOG_ERROR (" Failed to buildCarServerGetVehicleDataMessage " );
268+ if (return_code != 0 ) {
269+ LOG_ERROR (" Failed to build_car_server_get_vehicle_data_message " );
272270 return -1 ;
273271 }
274272 LOG_DEBUG (" HVAC length: %d" , get_data_message_length);
0 commit comments