mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 19:42:08 +02:00
Fix bugs in printf logging code & add version to log
- Fix printf end of line detection - Fix overwriting of timestamp in printf path - Add version + build date/time to log
This commit is contained in:
parent
cc4229f774
commit
0512d02101
2 changed files with 7 additions and 6 deletions
|
@ -85,14 +85,13 @@ size_t Logging::write(const uint8_t* buffer, size_t size) {
|
||||||
|
|
||||||
void Logging::printf(const char* fmt, ...) {
|
void Logging::printf(const char* fmt, ...) {
|
||||||
#ifdef DEBUG_LOG
|
#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) {
|
if (previous_message_was_newline) {
|
||||||
add_timestamp(MAX_LINE_LENGTH_PRINTF);
|
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];
|
static char buffer[MAX_LINE_LENGTH_PRINTF];
|
||||||
char* message_buffer;
|
char* message_buffer;
|
||||||
#ifdef DEBUG_VIA_WEB
|
#ifdef DEBUG_VIA_WEB
|
||||||
|
@ -132,6 +131,6 @@ void Logging::printf(const char* fmt, ...) {
|
||||||
}
|
}
|
||||||
#endif // DEBUG_VIA_WEB
|
#endif // DEBUG_VIA_WEB
|
||||||
|
|
||||||
previous_message_was_newline = buffer[size - 1] == '\n';
|
previous_message_was_newline = message_buffer[size - 1] == '\n';
|
||||||
#endif // DEBUG_LOG
|
#endif // DEBUG_LOG
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
|
extern const char* version_number; // The current software version, shown on webserver
|
||||||
|
|
||||||
class Logging : public Print {
|
class Logging : public Print {
|
||||||
void add_timestamp(size_t size);
|
void add_timestamp(size_t size);
|
||||||
|
|
||||||
|
@ -11,7 +13,7 @@ class Logging : public Print {
|
||||||
virtual size_t write(const uint8_t* buffer, size_t size);
|
virtual size_t write(const uint8_t* buffer, size_t size);
|
||||||
virtual size_t write(uint8_t) { return 0; }
|
virtual size_t write(uint8_t) { return 0; }
|
||||||
void printf(const char* fmt, ...);
|
void printf(const char* fmt, ...);
|
||||||
Logging() {}
|
Logging() {printf("Battery emulator %s build "__DATE__ " " __TIME__ "\n", version_number);}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Logging logging;
|
extern Logging logging;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue