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 11:c49cf952d67d, committed 2018-03-24
- Comitter:
- Lorenzo Maiorfi
- Date:
- Sat Mar 24 19:50:19 2018 +0100
- Parent:
- 10:926dbab7a7bc
- Child:
- 12:8dc9761210c1
- Commit message:
- Fixed NonCopyable<T> issue for Timers
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiLogger/DigiLogger.cpp Sat Mar 24 19:50:19 2018 +0100
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#include "DigiLogger.h"
+
+#include <stdarg.h>
+
+using namespace DigiLog;
+
+LogLevel DigiLogger::_log_level;
+
+DigiLogger* DigiLogger::current_logger;
+
+/* Base Class constructor */
+DigiLogger::DigiLogger()
+{
+ _log_level = LogLevelNone;
+
+ current_logger = NULL;
+}
+
+/* Class destructor */
+DigiLogger::~DigiLogger()
+{
+ current_logger = NULL;
+}
+
+void DigiLogger::set_level(LogLevel log_level)
+{
+ _log_level = log_level;
+}
+
+LogLevel DigiLogger::get_level()
+{
+ return _log_level;
+}
+
+void DigiLogger::log_format(LogLevel log_level, const char *format, ...)
+{
+ static char buffer[DEBUG_BUFFER_LEN];
+ va_list argp;
+
+ if (current_logger == NULL) {
+ return;
+ }
+
+ if (_log_level < log_level) {
+ return;
+ }
+
+ va_start(argp, format);
+ vsnprintf(buffer, DEBUG_BUFFER_LEN, format, argp);
+ va_end(argp);
+
+ current_logger->log_buffer(buffer);
+}
+
+void DigiLogger::log_buffer(char const * const buffer)
+{
+ (void)(buffer);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiLogger/DigiLogger.h Sat Mar 24 19:50:19 2018 +0100
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#if !defined(__DIGI_LOGGER_H_)
+#define __DIGI_LOGGER_H_
+
+#include <cstdlib>
+#include <stdio.h>
+
+/**
+ * @defgroup LogLevel
+ * @{
+ */
+/**
+ * Library Logging level.
+ */
+enum LogLevel {
+ LogLevelNone, /** Level None */
+ LogLevelError, /** Level Error */
+ LogLevelWarning, /** Level Warning */
+ LogLevelInfo, /** Level Info */
+ LogLevelDebug, /** Level Debug */
+ LogLevelFrameData, /** Level Frame Data */
+ LogLevelAll /** Level All */
+};
+/**
+ * @}
+ */
+
+#define DEBUG_BUFFER_LEN 200
+
+namespace DigiLog {
+
+class DigiLogger
+{
+ protected:
+
+ /** module log level */
+ static LogLevel _log_level;
+
+ static DigiLogger* current_logger;
+
+ /* Not implemented for base class */
+ virtual void log_buffer(char const * const buffer);
+
+ public:
+
+ /** Class constructor */
+ DigiLogger();
+
+ /** Class destructor */
+ virtual ~DigiLogger();
+
+ /** set_level - set logging level.
+ *
+ * @param log_level desired overall logging level
+ */
+ static void set_level(LogLevel log_level);
+
+ /** get_level - get logging level.
+ *
+ * @returns current overall logging level
+ */
+ static LogLevel get_level();
+
+ /** log_format - logs a printf-like message.
+ *
+ * @param log_level logging level
+ * @param format ... printf-like message
+ */
+ static void log_format(LogLevel log_level, const char *format, ...);
+
+};
+
+} /* namespace DigiLog */
+
+#endif /* defined(__DIGI_LOGGER_H_) */
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiLogger/DigiLoggerMbedSerial.cpp Sat Mar 24 19:50:19 2018 +0100
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#include "DigiLoggerMbedSerial.h"
+
+using namespace DigiLog;
+
+Serial *DigiLoggerMbedSerial::_log_serial;
+
+/* Class constructor when using a serial port as logging channel */
+DigiLoggerMbedSerial::DigiLoggerMbedSerial(Serial * log_serial, LogLevel log_level)
+{
+ _log_serial = log_serial;
+
+ _log_level = log_level;
+
+ DigiLogger::current_logger = this;
+}
+
+/* Class destructor */
+DigiLoggerMbedSerial::~DigiLoggerMbedSerial()
+{
+ _log_serial = NULL;
+ DigiLogger::current_logger = NULL;
+}
+
+void DigiLoggerMbedSerial::log_buffer(char const * const buffer)
+{
+ if (_log_serial == NULL) {
+ return;
+ }
+
+ _log_serial->printf("%s", buffer);
+ fflush(*_log_serial);
+}
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DigiLogger/DigiLoggerMbedSerial.h Sat Mar 24 19:50:19 2018 +0100
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#if !defined(__DIGI_LOGGER_MBED_SERIAL_H_)
+#define __DIGI_LOGGER_MBED_SERIAL_H_
+
+#include "mbed.h"
+#include "DigiLogger.h"
+
+namespace DigiLog {
+
+class DigiLoggerMbedSerial : public DigiLogger
+{
+ protected:
+
+ /** serial port for debugging */
+ static Serial *_log_serial;
+
+ /** log_buffer - logs a buffer through the configured serial port.
+ *
+ * @param buffer ... buffer to log
+ */
+ virtual void log_buffer(char const * const buffer);
+
+ public:
+
+ /** Class constructor */
+ DigiLoggerMbedSerial(Serial * log_serial, LogLevel log_level = LogLevelInfo);
+
+ /** Class destructor */
+ virtual ~DigiLoggerMbedSerial();
+};
+
+} /* namespace DigiLog */
+
+#endif /* defined(__DIGI_LOGGER_MBED_SERIAL_H_) */
+
+
+
--- a/XBee/RadioConfig.cpp Sat Mar 24 18:15:23 2018 +0000
+++ b/XBee/RadioConfig.cpp Sat Mar 24 19:50:19 2018 +0100
@@ -209,9 +209,9 @@
}
_timeout_ms = nd_timeout;
- Timer nd_timer = Timer();
+ Timer* pnd_timer = new Timer();
- nd_timer.start();
+ pnd_timer->start();
AtCmdFrame atnd_frame = AtCmdFrame("ND", (const uint8_t *)node_id, strlen(node_id));
const uint8_t frame_id = atnd_frame.get_frame_id();
@@ -225,6 +225,7 @@
if (resp_frame == NULL) {
digi_log(LogLevelWarning, "_get_remote_node_by_id: timeout when waiting for ATND response");
+ delete pnd_timer;
return;
}
@@ -232,6 +233,7 @@
/* In 802.15.4 this might be the OK or Timeout message with no information */
digi_log(LogLevelInfo, "_get_remote_node_by_id: node not found\r\n", __FUNCTION__, node_id);
_framebuf_syncr.free_frame(resp_frame);
+ delete pnd_timer;
return;
}
@@ -239,6 +241,7 @@
if (resp != AtCmdFrame::AtCmdRespOk) {
digi_log(LogLevelWarning, "_get_remote_node_by_id: send_at_cmd bad response: 0x%x\r\n", resp);
_framebuf_syncr.free_frame(resp_frame);
+ delete pnd_timer;
return;
}
@@ -247,11 +250,12 @@
_framebuf_syncr.free_frame(resp_frame);
if (wait_for_complete_timeout) {
- while (nd_timer.read_ms() < nd_timeout) {
+ while (pnd_timer->read_ms() < nd_timeout) {
wait_ms(10);
}
}
+ delete pnd_timer;
return;
}
--- a/XBee/XBee.cpp Sat Mar 24 18:15:23 2018 +0000
+++ b/XBee/XBee.cpp Sat Mar 24 19:50:19 2018 +0100
@@ -223,17 +223,20 @@
RadioStatus XBee::wait_for_module_to_reset(volatile uint16_t *rst_cnt_p, uint16_t init_rst_cnt)
{
- Timer timer = Timer();
- timer.start();
+ Timer* ptimer = new Timer();
+ ptimer->start();
- while (*rst_cnt_p == init_rst_cnt && timer.read_ms() < RESET_TIMEOUT_MS) {
+ while (*rst_cnt_p == init_rst_cnt && ptimer->read_ms() < RESET_TIMEOUT_MS) {
wait_ms(100);
}
if (*rst_cnt_p == init_rst_cnt) {
digi_log(LogLevelWarning, "Reset Timeout\r\n");
+ delete ptimer;
return Failure;
}
+
+ delete ptimer;
return Success;
}
@@ -496,10 +499,10 @@
ApiFrame * XBee::get_this_api_frame(uint8_t id, ApiFrame::ApiFrameType type,
ApiFrame::ApiFrameType type2)
{
- Timer timer = Timer();
- timer.start();
+ Timer* ptimer = new Timer();
+ ptimer->start();
- while (timer.read_ms() < _timeout_ms) {
+ while (ptimer->read_ms() < _timeout_ms) {
ApiFrame * frame = _framebuf_syncr.get_next_complete_frame();
if (frame == NULL) {
wait_ms(10);
@@ -520,11 +523,15 @@
}
/* frame found */
+ delete ptimer;
+
return frame;
}
digi_log(LogLevelWarning, "Frame type: %02x, id: %02x, timeout\r\n", (uint8_t)type, id);
+ delete ptimer;
+
return NULL;
}
