Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#ifdef ESP_PLATFORM

#ifndef LOG_LOCAL_LEVEL
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif
#include "esp_log.h"
static const char *const TAG = "tesla_ble";
#define CONFIG_LOG_DEFAULT_LEVEL_DEBUG
#define LOG(...) ESP_LOGI(TAG, __VA_ARGS__)
#define LOG_INFO(...) ESP_LOGI(TAG, __VA_ARGS__)
#define LOG_DEBUG(...) ESP_LOGD(TAG, __VA_ARGS__)
Expand Down Expand Up @@ -32,8 +34,7 @@ void log(const char *type, const char *color, const char *s, Args... args)
{
printf("%s%s - ", color, type);
if constexpr (sizeof...(args) > 0) {
// printf(": ");
printf(s, args...); // Only use format specifiers for additional arguments
printf(s, args...);
} else {
printf("%s", s);
}
Expand Down
1 change: 1 addition & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ctime>
#include <iomanip>
#include <sstream>
#include "defs.h"

#include <pb_decode.h>
#include <pb_encode.h>
Expand Down
1 change: 1 addition & 0 deletions src/message_builders.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "message_builders.h"
#include "tb_utils.h"
#include "defs.h"
#include "car_server.pb.h"
#include "universal_message.pb.h"

Expand Down
1 change: 1 addition & 0 deletions src/peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <chrono>
#include <pb.h>
#include <inttypes.h>
#include "defs.h"
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/ecdh.h>
#include <mbedtls/entropy.h>
Expand Down
18 changes: 8 additions & 10 deletions src/tb_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <pb.h>
#include <sstream>

#include "defs.h"
#include "errors.h"

namespace TeslaBLE
Expand All @@ -19,36 +20,33 @@ namespace TeslaBLE
// Validate input parameters
if (!output_buffer || !output_length || !fields || !src_struct)
{
printf("[E][pb_encode] Invalid parameters: output_buffer=%p, output_length=%p, fields=%p, src_struct=%p\n",
output_buffer, output_length, fields, src_struct);
LOG_ERROR("pb_encode: Invalid parameters (buffer=%p, length=%p, fields=%p, struct=%p)",
output_buffer, output_length, fields, src_struct);
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
}

pb_ostream_t unsigned_message_size_stream = {nullptr, 0, 0, 0, nullptr};
bool status_encode_length = pb_encode(&unsigned_message_size_stream, fields, src_struct);
if (!status_encode_length)
{
printf("[E][pb_encode] Failed to get encoded message size (err: %s)\n",
PB_GET_ERROR(&unsigned_message_size_stream));
LOG_ERROR("pb_encode: Failed to get encoded message size (err: %s)",
PB_GET_ERROR(&unsigned_message_size_stream));
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
}
// printf("Bytes written: %zu\n", unsigned_message_size_stream.bytes_written);
if (unsigned_message_size_stream.bytes_written == 0)
{
printf("[E][pb_encode] No bytes written\n");
LOG_ERROR("pb_encode: No bytes written");
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
}
*output_length = unsigned_message_size_stream.bytes_written;
// printf("Message size: %hhu\n", *output_length);

// now encode proper
// printf("Encoding message\n");
pb_ostream_t unsigned_message_stream = pb_ostream_from_buffer(output_buffer, *output_length);
bool status_encode_bytes = pb_encode(&unsigned_message_stream, fields, src_struct);
if (!status_encode_bytes)
{
printf("[E][pb_encode] Failed to encode message (err: %s)\n",
PB_GET_ERROR(&unsigned_message_stream));
LOG_ERROR("pb_encode: Failed to encode message (err: %s)",
PB_GET_ERROR(&unsigned_message_stream));
return TeslaBLE_Status_E_ERROR_PB_ENCODING;
}
return TeslaBLE_Status_E_OK;
Expand Down