diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-05-22 12:16:41 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-05-22 12:16:41 +0200 |
commit | 03eac33a3df0d8e49941e5ab1095816a547c7f0f (patch) | |
tree | 1cf334f12e0340f6b01999bda98f12d572548725 /src/include | |
parent | b7d430e3c06c10411419bfc8bfb30574f7a9cb56 (diff) | |
parent | 2c94b72f10079cac62783a6073509badb1c013c6 (diff) | |
download | px4-firmware-03eac33a3df0d8e49941e5ab1095816a547c7f0f.tar.gz px4-firmware-03eac33a3df0d8e49941e5ab1095816a547c7f0f.tar.bz2 px4-firmware-03eac33a3df0d8e49941e5ab1095816a547c7f0f.zip |
Merge branch 'master' of github.com:cvg/Firmware_Private into fmuv2_bringup
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/mavlink/mavlink_log.h | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/include/mavlink/mavlink_log.h b/src/include/mavlink/mavlink_log.h index 233a76cb3..a28ff3a68 100644 --- a/src/include/mavlink/mavlink_log.h +++ b/src/include/mavlink/mavlink_log.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (C) 2012 PX4 Development Team. All rights reserved. + * Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved. * Author: Lorenz Meier <lm@inf.ethz.ch> * * Redistribution and use in source and binary forms, with or without @@ -47,27 +47,42 @@ */ #include <sys/ioctl.h> -/* +/** * The mavlink log device node; must be opened before messages * can be logged. */ #define MAVLINK_LOG_DEVICE "/dev/mavlink" +/** + * The maximum string length supported. + */ +#define MAVLINK_LOG_MAXLEN 50 #define MAVLINK_IOC_SEND_TEXT_INFO _IOC(0x1100, 1) #define MAVLINK_IOC_SEND_TEXT_CRITICAL _IOC(0x1100, 2) #define MAVLINK_IOC_SEND_TEXT_EMERGENCY _IOC(0x1100, 3) +#ifdef __cplusplus +extern "C" { +#endif +__EXPORT void mavlink_vasprintf(int _fd, int severity, const char *fmt, ...); +#ifdef __cplusplus +} +#endif + +/* + * The va_args implementation here is not beautiful, but obviously we run into the same issues + * the GCC devs saw, and are using their solution: + * + * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html + */ + /** * Send a mavlink emergency message. * * @param _fd A file descriptor returned from open(MAVLINK_LOG_DEVICE, 0); * @param _text The text to log; */ -#ifdef __cplusplus -#define mavlink_log_emergency(_fd, _text) ::ioctl(_fd, MAVLINK_IOC_SEND_TEXT_EMERGENCY, (unsigned long)_text); -#else -#define mavlink_log_emergency(_fd, _text) ioctl(_fd, MAVLINK_IOC_SEND_TEXT_EMERGENCY, (unsigned long)_text); -#endif +#define mavlink_log_emergency(_fd, _text, ...) mavlink_vasprintf(_fd, MAVLINK_IOC_SEND_TEXT_EMERGENCY, _text, ##__VA_ARGS__); /** * Send a mavlink critical message. @@ -75,11 +90,7 @@ * @param _fd A file descriptor returned from open(MAVLINK_LOG_DEVICE, 0); * @param _text The text to log; */ -#ifdef __cplusplus -#define mavlink_log_critical(_fd, _text) ::ioctl(_fd, MAVLINK_IOC_SEND_TEXT_CRITICAL, (unsigned long)_text); -#else -#define mavlink_log_critical(_fd, _text) ioctl(_fd, MAVLINK_IOC_SEND_TEXT_CRITICAL, (unsigned long)_text); -#endif +#define mavlink_log_critical(_fd, _text, ...) mavlink_vasprintf(_fd, MAVLINK_IOC_SEND_TEXT_CRITICAL, _text, ##__VA_ARGS__); /** * Send a mavlink info message. @@ -87,14 +98,10 @@ * @param _fd A file descriptor returned from open(MAVLINK_LOG_DEVICE, 0); * @param _text The text to log; */ -#ifdef __cplusplus -#define mavlink_log_info(_fd, _text) ::ioctl(_fd, MAVLINK_IOC_SEND_TEXT_INFO, (unsigned long)_text); -#else -#define mavlink_log_info(_fd, _text) ioctl(_fd, MAVLINK_IOC_SEND_TEXT_INFO, (unsigned long)_text); -#endif +#define mavlink_log_info(_fd, _text, ...) mavlink_vasprintf(_fd, MAVLINK_IOC_SEND_TEXT_INFO, _text, ##__VA_ARGS__); struct mavlink_logmessage { - char text[51]; + char text[MAVLINK_LOG_MAXLEN + 1]; unsigned char severity; }; @@ -116,5 +123,7 @@ void mavlink_logbuffer_write(struct mavlink_logbuffer *lb, const struct mavlink_ int mavlink_logbuffer_read(struct mavlink_logbuffer *lb, struct mavlink_logmessage *elem); +void mavlink_logbuffer_vasprintf(struct mavlink_logbuffer *lb, int severity, const char *fmt, ...); + #endif |