mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 00:50:35 +08:00
POSIX: Improved logging
The warnx and warn calls map to PX4_WARN. Calls to errx or err genrtate a compile error. The px4_log.h file implements a new log format: For DEBUG and INFO: <level> <msg> For ERROR and WARN: <level> <msg> (file filepath line linenum) The verbosity can be changed by setting the macro to use either linux_log or linux_log_verbose in px4_log.h Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -81,7 +81,7 @@ int Simulator::start(int argc, char *argv[])
|
||||
int ret = 0;
|
||||
_instance = new Simulator();
|
||||
if (_instance) {
|
||||
PX4_INFO("Simulator started\n");
|
||||
PX4_INFO("Simulator started");
|
||||
drv_led_start();
|
||||
if (argv[2][1] == 's') {
|
||||
#ifndef __PX4_QURT
|
||||
@@ -92,7 +92,7 @@ int Simulator::start(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
else {
|
||||
PX4_WARN("Simulator creation failed\n");
|
||||
PX4_WARN("Simulator creation failed");
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
@@ -150,7 +150,7 @@ void Simulator::publishSensorsCombined() {
|
||||
gyro.timestamp = time_last;
|
||||
mag.timestamp = time_last;
|
||||
// publish the sensor values
|
||||
//printf("Publishing SensorsCombined\n");
|
||||
//PX4_DEBUG("Publishing SensorsCombined\n");
|
||||
orb_publish(ORB_ID(sensor_combined), _sensor_combined_pub, &sensors);
|
||||
orb_publish(ORB_ID(sensor_baro), _baro_pub, &baro);
|
||||
orb_publish(ORB_ID(sensor_accel), _accel_pub, &baro);
|
||||
@@ -225,14 +225,14 @@ bool static _led_state[2] = { false , false };
|
||||
|
||||
__EXPORT void led_init()
|
||||
{
|
||||
PX4_DBG("LED_INIT\n");
|
||||
PX4_DEBUG("LED_INIT");
|
||||
}
|
||||
|
||||
__EXPORT void led_on(int led)
|
||||
{
|
||||
if (led == 1 || led == 0)
|
||||
{
|
||||
PX4_DBG("LED%d_ON", led);
|
||||
PX4_DEBUG("LED%d_ON", led);
|
||||
_led_state[led] = true;
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ __EXPORT void led_off(int led)
|
||||
{
|
||||
if (led == 1 || led == 0)
|
||||
{
|
||||
PX4_DBG("LED%d_OFF", led);
|
||||
PX4_DEBUG("LED%d_OFF", led);
|
||||
_led_state[led] = false;
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ __EXPORT void led_toggle(int led)
|
||||
if (led == 1 || led == 0)
|
||||
{
|
||||
_led_state[led] = !_led_state[led];
|
||||
PX4_DBG("LED%d_TOGGLE: %s\n", led, _led_state[led] ? "ON" : "OFF");
|
||||
PX4_DEBUG("LED%d_TOGGLE: %s", led, _led_state[led] ? "ON" : "OFF");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ void Simulator::updateSamples()
|
||||
int serial_fd = open(PIXHAWK_DEVICE, O_RDWR);
|
||||
|
||||
if (serial_fd < 0) {
|
||||
PX4_WARN("failed to open %s\n", PIXHAWK_DEVICE);
|
||||
PX4_WARN("failed to open %s", PIXHAWK_DEVICE);
|
||||
}
|
||||
|
||||
// tell the device to stream some messages
|
||||
@@ -343,7 +343,7 @@ void Simulator::updateSamples()
|
||||
int w = ::write(serial_fd, command, sizeof(command));
|
||||
|
||||
if (w <= 0) {
|
||||
PX4_WARN("failed to send streaming command to %s\n", PIXHAWK_DEVICE);
|
||||
PX4_WARN("failed to send streaming command to %s", PIXHAWK_DEVICE);
|
||||
}
|
||||
|
||||
char serial_buf[1024];
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
#ifndef _SYSTEMLIB_ERR_H
|
||||
#define _SYSTEMLIB_ERR_H
|
||||
|
||||
#include <px4_log.h>
|
||||
#include <stdarg.h>
|
||||
#include "visibility.h"
|
||||
|
||||
@@ -72,6 +73,14 @@ __BEGIN_DECLS
|
||||
|
||||
__EXPORT const char *getprogname(void);
|
||||
|
||||
#ifdef __PX4_POSIX
|
||||
|
||||
#define err(...) ERROR
|
||||
#define errx(...) ERROR
|
||||
#define warn(...) PX4_WARN(__VA_ARGS__)
|
||||
#define warnx(...) PX4_WARN(__VA_ARGS__)
|
||||
|
||||
#else
|
||||
__EXPORT void err(int eval, const char *fmt, ...) __attribute__((noreturn, format(printf, 2, 3)));
|
||||
__EXPORT void verr(int eval, const char *fmt, va_list) __attribute__((noreturn, format(printf, 2, 0)));
|
||||
__EXPORT void errc(int eval, int code, const char *fmt, ...) __attribute__((noreturn, format(printf, 3, 4)));
|
||||
@@ -84,6 +93,7 @@ __EXPORT void warnc(int code, const char *fmt, ...) __attribute__((format(print
|
||||
__EXPORT void vwarnc(int code, const char *fmt, va_list) __attribute__((format(printf, 2, 0)));
|
||||
__EXPORT void warnx(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
__EXPORT void vwarnx(const char *fmt, va_list) __attribute__((format(printf, 1, 0)));
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
# System utility library
|
||||
#
|
||||
|
||||
SRCS = err.c \
|
||||
SRCS = \
|
||||
perf_counter.c \
|
||||
param/param.c \
|
||||
conversions.c \
|
||||
@@ -55,7 +55,8 @@ SRCS = err.c \
|
||||
circuit_breaker_params.c
|
||||
|
||||
ifeq ($(PX4_TARGET_OS),nuttx)
|
||||
SRCS += up_cxxinitialize.c
|
||||
SRCS += err.c \
|
||||
up_cxxinitialize.c
|
||||
endif
|
||||
|
||||
ifneq ($(PX4_TARGET_OS),qurt)
|
||||
|
||||
Reference in New Issue
Block a user