mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 14:03: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:
@@ -150,7 +150,7 @@ ADCSIM::~ADCSIM()
|
||||
int
|
||||
ADCSIM::init()
|
||||
{
|
||||
debug("init done");
|
||||
DEVICE_DEBUG("init done");
|
||||
|
||||
/* create the device node */
|
||||
return VDev::init();
|
||||
|
||||
@@ -250,11 +250,11 @@ int
|
||||
BAROSIM::init()
|
||||
{
|
||||
int ret;
|
||||
debug("BAROSIM::init");
|
||||
DEVICE_DEBUG("BAROSIM::init");
|
||||
|
||||
ret = VDev::init();
|
||||
if (ret != OK) {
|
||||
debug("VDev init failed");
|
||||
DEVICE_DEBUG("VDev init failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ BAROSIM::init()
|
||||
_reports = new ringbuffer::RingBuffer(2, sizeof(baro_report));
|
||||
|
||||
if (_reports == nullptr) {
|
||||
debug("can't get memory for reports");
|
||||
DEVICE_DEBUG("can't get memory for reports");
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
@@ -576,7 +576,7 @@ BAROSIM::cycle()
|
||||
/* measurement phase */
|
||||
ret = measure();
|
||||
if (ret != OK) {
|
||||
//log("measure error %d", ret);
|
||||
//DEVICE_LOG("measure error %d", ret);
|
||||
/* issue a reset command to the sensor */
|
||||
_interface->dev_ioctl(IOCTL_RESET, dummy);
|
||||
/* reset the collection state machine and try again */
|
||||
|
||||
@@ -457,7 +457,7 @@ GYROSIM::init()
|
||||
ret = _gyro->init();
|
||||
/* if probe/setup failed, bail now */
|
||||
if (ret != OK) {
|
||||
debug("gyro init failed");
|
||||
DEVICE_DEBUG("gyro init failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1175,7 +1175,7 @@ GYROSIM_gyro::init()
|
||||
|
||||
/* if probe/setup failed, bail now */
|
||||
if (ret != OK) {
|
||||
debug("gyro init failed");
|
||||
DEVICE_DEBUG("gyro init failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ ToneAlarm::init()
|
||||
if (ret != OK)
|
||||
return ret;
|
||||
|
||||
debug("ready");
|
||||
DEVICE_DEBUG("ready");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ ToneAlarm::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||
{
|
||||
int result = OK;
|
||||
|
||||
debug("ioctl %i %u", cmd, arg);
|
||||
DEVICE_DEBUG("ioctl %i %lu", cmd, arg);
|
||||
|
||||
// irqstate_t flags = irqsave();
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ __EXPORT extern int __px4_log_level_current;
|
||||
* Additional behavior can be added using "{\" for __px4__log_startline and
|
||||
* "}" for __px4__log_endline and any other required setup or teardown steps
|
||||
****************************************************************************/
|
||||
#define __px4__log_startcond(cond) if (cond) printf(
|
||||
#define __px4__log_startline(level) if (level <= __px4_log_level_current) printf(
|
||||
|
||||
#define __px4__log_timestamp_fmt "%-10" PRIu64 " "
|
||||
@@ -112,6 +113,22 @@ __EXPORT extern int __px4_log_level_current;
|
||||
****************************************************************************/
|
||||
#define __px4_log_omit(level, FMT, ...) do_nothing(level, ##__VA_ARGS__)
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log_named_cond:
|
||||
* Convert a message in the form:
|
||||
* PX4_LOG_COND(__dbg_enabled, "val is %d", val);
|
||||
* to
|
||||
* printf("%-5s val is %d\n", "LOG", val);
|
||||
* if the first arg/condition is true.
|
||||
****************************************************************************/
|
||||
#define __px4_log_named_cond(name, cond, FMT, ...) \
|
||||
__px4__log_startcond(cond)\
|
||||
"%s " \
|
||||
FMT\
|
||||
__px4__log_end_fmt \
|
||||
,name, ##__VA_ARGS__\
|
||||
__px4__log_endline
|
||||
|
||||
/****************************************************************************
|
||||
* __px4_log:
|
||||
* Convert a message in the form:
|
||||
@@ -305,5 +322,7 @@ __EXPORT extern int __px4_log_level_current;
|
||||
#define PX4_DEBUG(FMT, ...) __px4_log_omit(_PX4_LOG_LEVEL_DEBUG, FMT, ##__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
#define PX4_LOG_NAMED(name, FMT, ...) __px4_log_named_cond(name, true, FMT, ##__VA_ARGS__)
|
||||
#define PX4_LOG_NAMED_COND(name, cond, FMT, ...) __px4_log_named_cond(name, cond, FMT, ##__VA_ARGS__)
|
||||
__END_DECLS
|
||||
#endif
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#include <queue.h>
|
||||
#include <px4_platform_types.h>
|
||||
|
||||
#ifdef __PX4_QURT
|
||||
#include <dspal_types.h>
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define HPWORK 0
|
||||
|
||||
Reference in New Issue
Block a user