mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 10:33:33 +08:00
Refactored debug() and log() in CDev
These functions used vprintf which is not available on all platforms. They also do not enable line and file debug output. Changed to macros that preserve the output format. Uses new macro that can be used to implement per object, runtime selectable logging Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -51,6 +51,9 @@
|
||||
#include <stdint.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#define DEVICE_LOG(FMT, ...) PX4_LOG_NAMED(_name, FMT, ##__VA_ARGS__)
|
||||
#define DEVICE_DEBUG(FMT, ...) PX4_LOG_NAMED_COND(_name, _debug_enabled, FMT, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Namespace encapsulating all device framework classes, functions and data.
|
||||
*/
|
||||
@@ -176,7 +179,7 @@ protected:
|
||||
* Note that we must loop as the wait may be interrupted by a signal.
|
||||
*/
|
||||
void lock() {
|
||||
debug("lock");
|
||||
DEVICE_DEBUG("lock");
|
||||
do {} while (sem_wait(&_lock) != 0);
|
||||
}
|
||||
|
||||
@@ -184,26 +187,10 @@ protected:
|
||||
* Release the driver lock.
|
||||
*/
|
||||
void unlock() {
|
||||
debug("unlock");
|
||||
DEVICE_DEBUG("unlock");
|
||||
sem_post(&_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message.
|
||||
*
|
||||
* The message is prefixed with the driver name, and followed
|
||||
* by a newline.
|
||||
*/
|
||||
void log(const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* Print a debug message.
|
||||
*
|
||||
* The message is prefixed with the driver name, and followed
|
||||
* by a newline.
|
||||
*/
|
||||
void debug(const char *fmt, ...);
|
||||
|
||||
private:
|
||||
sem_t _lock;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user