Digi XBeeLib fixed for NonCopyable issue
Dependents: XBeeZB_Receive_Data
Fork of XBeeLib by
This lib fixes NonCopyable<T> issues of Digi XBeeLib. Also, lib has been reworked in order to make it RTOS-aware, overcoming several others issues due to stdio Mutex operations.
Revision 12:8dc9761210c1, committed 2018-03-25
- Comitter:
- Lorenzo Maiorfi
- Date:
- Sun Mar 25 16:54:52 2018 +0200
- Parent:
- 11:c49cf952d67d
- Child:
- 13:09e0b4f5a9e1
- Commit message:
- Fixed thread-affinity. Please use ENABLE_THREAD_SAFE_LOGGING #define in config.h to enable RTOS support.
Changed in this revision
| Utils/Debug.h | Show annotated file Show diff for this revision Revisions of this file |
| XBee/XBee.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Utils/Debug.h Sat Mar 24 19:50:19 2018 +0100
+++ b/Utils/Debug.h Sun Mar 25 16:54:52 2018 +0200
@@ -15,11 +15,30 @@
#include "config.h"
+
+#if defined(ENABLE_THREAD_SAFE_LOGGING)
+
+#include "mbed.h"
+
+extern EventQueue s_logging_event_queue;
+
+#endif
+
+
#if defined(ENABLE_LOGGING)
#include "DigiLogger.h"
+#if !(defined(ENABLE_THREAD_SAFE_LOGGING))
+
#define digi_log(...) DigiLog::DigiLogger::log_format(__VA_ARGS__);
+
+#else
+
+#define digi_log(...) s_logging_event_queue.call(&DigiLog::DigiLogger::log_format, __VA_ARGS__);
+
+#endif
+
#else
#define digi_log(...) do {} while(0)
#endif
@@ -27,11 +46,24 @@
#if defined(ENABLE_ASSERTIONS)
#include "mbed.h"
#if !(defined assert)
-#define assert(expr) if (!(expr)) { \
- digi_log(LogLevelNone, "Assertion failed: %s, file %s, line %d\n", \
+
+#if !(defined(ENABLE_THREAD_SAFE_LOGGING))
+
+ #define assert(expr) if (!(expr)) { \
+ DigiLog::DigiLogger::log_format(LogLevelNone, "Assertion failed: %s, file %s, line %d\n", \
#expr, __FILE__, __LINE__); \
mbed_die(); \
}
+
+#else
+
+ #define assert(expr) if (!(expr)) { \
+ s_logging_event_queue.call(&DigiLog::DigiLogger::log_format, LogLevelNone, "Assertion failed: %s, file %s, line %d\n", #expr, __FILE__, __LINE__ ); \
+ mbed_die(); \
+ }
+
+#endif
+
#endif
#else
#define assert(expr)
--- a/XBee/XBee.cpp Sat Mar 24 19:50:19 2018 +0100
+++ b/XBee/XBee.cpp Sun Mar 25 16:54:52 2018 +0200
@@ -13,6 +13,13 @@
#include "XBeeLib.h"
#include "FrameHandlers/FH_ModemStatus.h"
+#if defined(ENABLE_THREAD_SAFE_LOGGING)
+
+Thread s_thread_for_logging_event_queue;
+EventQueue s_logging_event_queue;
+
+#endif
+
/* States for the state machine that processes incoming data on the serial port */
#define WAITING_FOR_START_FRAME (0)
#define WAITING_FOR_LENGTH_MSB (1)
@@ -190,6 +197,12 @@
_modem_status_handler->process_frame_data(&frame);
}
+#if defined(ENABLE_THREAD_SAFE_LOGGING)
+
+ s_thread_for_logging_event_queue.start(callback(&s_logging_event_queue, &EventQueue::dispatch_forever));
+
+#endif
+
return Success;
}
