Skip to content

Commit ab6bafe

Browse files
authored
fix defs logs (#39)
* fix(defs.h): replace deprecated ESP-IDF log config option * fix: include "defs.h" in client.cpp, message_builders.cpp, and peer.cpp * fix(log): remove commented code for clarity in log function * fix(tb_utils): replace printf with LOG_ERROR for better logging consistency
1 parent 52dcbfd commit ab6bafe

5 files changed

Lines changed: 15 additions & 13 deletions

File tree

include/defs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#ifdef ESP_PLATFORM
44

5+
#ifndef LOG_LOCAL_LEVEL
6+
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
7+
#endif
58
#include "esp_log.h"
69
static const char *const TAG = "tesla_ble";
7-
#define CONFIG_LOG_DEFAULT_LEVEL_DEBUG
810
#define LOG(...) ESP_LOGI(TAG, __VA_ARGS__)
911
#define LOG_INFO(...) ESP_LOGI(TAG, __VA_ARGS__)
1012
#define LOG_DEBUG(...) ESP_LOGD(TAG, __VA_ARGS__)
@@ -32,8 +34,7 @@ void log(const char *type, const char *color, const char *s, Args... args)
3234
{
3335
printf("%s%s - ", color, type);
3436
if constexpr (sizeof...(args) > 0) {
35-
// printf(": ");
36-
printf(s, args...); // Only use format specifiers for additional arguments
37+
printf(s, args...);
3738
} else {
3839
printf("%s", s);
3940
}

src/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <ctime>
1212
#include <iomanip>
1313
#include <sstream>
14+
#include "defs.h"
1415

1516
#include <pb_decode.h>
1617
#include <pb_encode.h>

src/message_builders.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "message_builders.h"
22
#include "tb_utils.h"
3+
#include "defs.h"
34
#include "car_server.pb.h"
45
#include "universal_message.pb.h"
56

src/peer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <chrono>
88
#include <pb.h>
99
#include <inttypes.h>
10+
#include "defs.h"
1011
#include <mbedtls/ctr_drbg.h>
1112
#include <mbedtls/ecdh.h>
1213
#include <mbedtls/entropy.h>

src/tb_utils.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <pb.h>
77
#include <sstream>
88

9+
#include "defs.h"
910
#include "errors.h"
1011

1112
namespace TeslaBLE
@@ -19,36 +20,33 @@ namespace TeslaBLE
1920
// Validate input parameters
2021
if (!output_buffer || !output_length || !fields || !src_struct)
2122
{
22-
printf("[E][pb_encode] Invalid parameters: output_buffer=%p, output_length=%p, fields=%p, src_struct=%p\n",
23-
output_buffer, output_length, fields, src_struct);
23+
LOG_ERROR("pb_encode: Invalid parameters (buffer=%p, length=%p, fields=%p, struct=%p)",
24+
output_buffer, output_length, fields, src_struct);
2425
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
2526
}
2627

2728
pb_ostream_t unsigned_message_size_stream = {nullptr, 0, 0, 0, nullptr};
2829
bool status_encode_length = pb_encode(&unsigned_message_size_stream, fields, src_struct);
2930
if (!status_encode_length)
3031
{
31-
printf("[E][pb_encode] Failed to get encoded message size (err: %s)\n",
32-
PB_GET_ERROR(&unsigned_message_size_stream));
32+
LOG_ERROR("pb_encode: Failed to get encoded message size (err: %s)",
33+
PB_GET_ERROR(&unsigned_message_size_stream));
3334
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
3435
}
35-
// printf("Bytes written: %zu\n", unsigned_message_size_stream.bytes_written);
3636
if (unsigned_message_size_stream.bytes_written == 0)
3737
{
38-
printf("[E][pb_encode] No bytes written\n");
38+
LOG_ERROR("pb_encode: No bytes written");
3939
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
4040
}
4141
*output_length = unsigned_message_size_stream.bytes_written;
42-
// printf("Message size: %hhu\n", *output_length);
4342

4443
// now encode proper
45-
// printf("Encoding message\n");
4644
pb_ostream_t unsigned_message_stream = pb_ostream_from_buffer(output_buffer, *output_length);
4745
bool status_encode_bytes = pb_encode(&unsigned_message_stream, fields, src_struct);
4846
if (!status_encode_bytes)
4947
{
50-
printf("[E][pb_encode] Failed to encode message (err: %s)\n",
51-
PB_GET_ERROR(&unsigned_message_stream));
48+
LOG_ERROR("pb_encode: Failed to encode message (err: %s)",
49+
PB_GET_ERROR(&unsigned_message_stream));
5250
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
5351
}
5452
return TeslaBLE_Status_E_OK;

0 commit comments

Comments
 (0)