Skip to content

Commit

Permalink
Merge pull request #742 from dalathegreat/enhancement/logging
Browse files Browse the repository at this point in the history
Fix bugs in printf logging code & add version to log
  • Loading branch information
dalathegreat authored Jan 5, 2025
2 parents 1e93ad8 + 54d96a6 commit 6944561
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ Logging logging;
void setup() {
init_serial();

// We print this after setting up serial, such that is also printed to serial with DEBUG_VIA_USB set.
logging.printf("Battery emulator %s build " __DATE__ " " __TIME__ "\n", version_number);

init_stored_settings();

#ifdef WIFI
Expand Down
9 changes: 4 additions & 5 deletions Software/src/devboard/utils/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,13 @@ size_t Logging::write(const uint8_t* buffer, size_t size) {

void Logging::printf(const char* fmt, ...) {
#ifdef DEBUG_LOG
char* message_string = datalayer.system.info.logged_can_messages;
int offset = datalayer.system.info.logged_can_messages_offset; // Keeps track of the current position in the buffer
size_t message_string_size = sizeof(datalayer.system.info.logged_can_messages);

if (previous_message_was_newline) {
add_timestamp(MAX_LINE_LENGTH_PRINTF);
}

char* message_string = datalayer.system.info.logged_can_messages;
size_t message_string_size = sizeof(datalayer.system.info.logged_can_messages);
int offset = datalayer.system.info.logged_can_messages_offset; // Keeps track of the current position in the buffer
static char buffer[MAX_LINE_LENGTH_PRINTF];
char* message_buffer;
#ifdef DEBUG_VIA_WEB
Expand Down Expand Up @@ -132,6 +131,6 @@ void Logging::printf(const char* fmt, ...) {
}
#endif // DEBUG_VIA_WEB

previous_message_was_newline = buffer[size - 1] == '\n';
previous_message_was_newline = message_buffer[size - 1] == '\n';
#endif // DEBUG_LOG
}

0 comments on commit 6944561

Please sign in to comment.