-
Notifications
You must be signed in to change notification settings - Fork 45
EE UART logging #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
EE UART logging #171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,12 @@ | |
| #include "file/file_utils.hpp" | ||
| #include "info/info.hpp" | ||
|
|
||
| #ifdef EESIO_UART_USE_SIOCOOKIE | ||
| #include <SIOCookie.h> | ||
| #else | ||
| #include <sio.h> | ||
| #endif | ||
|
|
||
| #define TYRA_LOG(...) TyraDebug::writeLines("LOG: ", ##__VA_ARGS__, "\n") | ||
| #define TYRA_WARN(...) TyraDebug::writeLines("==WARN: ", ##__VA_ARGS__, "\n") | ||
| #define TYRA_ERROR(...) TyraDebug::writeLines("====ERR: ", ##__VA_ARGS__, "\n") | ||
|
|
@@ -48,8 +54,11 @@ class TyraDebug { | |
| using expander = int[]; | ||
| (void)expander{0, (void(ss << std::forward<Args>(args)), 0)...}; | ||
|
|
||
| if (Tyra::Info::writeLogsToFile) { | ||
| if (Tyra::Info::loggingMode == LOGGING_FILE) { | ||
| writeInLogFile(&ss); | ||
| } else if (Tyra::Info::loggingMode == LOGGING_EESIO) { | ||
| initializeEESIO(); | ||
| sio_putsn(ss.str().c_str()); | ||
| } else { | ||
| printf("%s", ss.str().c_str()); | ||
| } | ||
|
|
@@ -63,7 +72,7 @@ class TyraDebug { | |
| ss1 << "| Assertion failed!\n"; | ||
| ss1 << "|\n"; | ||
|
|
||
| if (Tyra::Info::writeLogsToFile) { | ||
| if (Tyra::Info::loggingMode == LOGGING_FILE) { | ||
| writeInLogFile(&ss1); | ||
| } else { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
| printf("%s", ss1.str().c_str()); | ||
|
|
@@ -76,8 +85,11 @@ class TyraDebug { | |
| ss2 << "| File : " << file << ":" << line << "\n"; | ||
| ss2 << "====================================\n\n"; | ||
|
|
||
| if (Tyra::Info::writeLogsToFile) { | ||
| if (Tyra::Info::loggingMode == LOGGING_FILE) { | ||
| writeInLogFile(&ss2); | ||
| } else if (Tyra::Info::loggingMode == LOGGING_EESIO) { | ||
| initializeEESIO(); | ||
| sio_putsn(ss2.str().c_str()); | ||
| } else { | ||
| printf("%s", ss2.str().c_str()); | ||
| } | ||
|
|
@@ -93,6 +105,7 @@ class TyraDebug { | |
|
|
||
| private: | ||
| static void writeInLogFile(std::stringstream* ss); | ||
| static void initializeEESIO(); | ||
|
|
||
| template <typename Arg, typename... Args> | ||
| static void writeAssertLines(Arg&& arg, Args&&... args) { | ||
|
|
@@ -103,8 +116,11 @@ class TyraDebug { | |
| (void)expander{ | ||
| 0, (void(ss << "| " << std::forward<Args>(args) << "\n"), 0)...}; | ||
|
|
||
| if (Tyra::Info::writeLogsToFile) { | ||
| if (Tyra::Info::loggingMode == LOGGING_FILE) { | ||
| writeInLogFile(&ss); | ||
| } else if (Tyra::Info::loggingMode == LOGGING_EESIO) { | ||
| initializeEESIO(); | ||
| sio_putsn(ss.str().c_str()); | ||
| } else { | ||
| printf("%s", ss.str().c_str()); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,10 @@ | |
| #include "time/timer.hpp" | ||
| #include "./version.hpp" | ||
|
|
||
| #define LOGGING_STDOUT (0) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please replace this C-Style code to C++ enums (like here).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe. If we explicitly say this is for EE. Rn I don't have my PC at hand. Will fix later |
||
| #define LOGGING_FILE (1) | ||
| #define LOGGING_EESIO (3) | ||
|
|
||
| namespace Tyra { | ||
|
|
||
| class Info { | ||
|
|
@@ -24,7 +28,7 @@ class Info { | |
|
|
||
| Version version; | ||
|
|
||
| static bool writeLogsToFile; | ||
| static int loggingMode; | ||
|
|
||
| /** Called by engine */ | ||
| void update(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
|
|
||
| #include "debug/debug.hpp" | ||
|
|
||
| bool EESIO_Initialized = false; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about making this variable as |
||
| void TyraDebug::writeInLogFile(std::stringstream* ss) { | ||
| std::ofstream logFile; | ||
| logFile.open(Tyra::FileUtils::fromCwd("log.txt"), | ||
|
|
@@ -18,3 +19,16 @@ void TyraDebug::writeInLogFile(std::stringstream* ss) { | |
| logFile.flush(); | ||
| // logFile.close(); | ||
| } | ||
|
|
||
| void TyraDebug::initializeEESIO() { | ||
| if (EESIO_Initialized) | ||
| return; | ||
| #ifndef EESIO_UART_USE_SIOCOOKIE | ||
| sio_init(38400, 0, 0, 0, 0); | ||
| sio_putsn("TYRA: EE_SIO Enabled\n"); | ||
| #else | ||
| ee_sio_start(38400, 0, 0, 0, 0, 1); // alternative wrapper. initializes UART, but also re-routes STDOUT and STDERR FILE* streams to EE_SIO | ||
| printf("TYRA: EE_SIO Enabled & STDOUT/STDERR hooked\n") | ||
|
Comment on lines
+26
to
+31
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain this a bit more?
BTW I see that you have |
||
| #endif | ||
| EESIO_Initialized = true; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to fix this duplicate