PX4 Firmware
PX4 Autopilot Software http://px4.io
mavlink_log.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2016 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file mavlink_log.h
36  * MAVLink text logging.
37  *
38  * @author Lorenz Meier <lorenz@px4.io>
39  * @author Julian Oes <julian@oes.ch>
40  */
41 
42 #pragma once
43 
44 #include <px4_log.h>
45 #include <uORB/uORB.h>
46 
47 /**
48  * The maximum string length supported.
49  */
50 #define MAVLINK_LOG_MAXLEN 50
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 __EXPORT void mavlink_vasprintf(int severity, orb_advert_t *mavlink_log_pub, const char *fmt, ...);
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #define _MSG_PRIO_DEBUG 7
61 #define _MSG_PRIO_INFO 6
62 #define _MSG_PRIO_NOTICE 5
63 #define _MSG_PRIO_WARNING 4
64 #define _MSG_PRIO_ERROR 3
65 #define _MSG_PRIO_CRITICAL 2
66 #define _MSG_PRIO_ALERT 1
67 #define _MSG_PRIO_EMERGENCY 0
68 
69 /*
70  * The va_args implementation here is not beautiful, but obviously we run into the same issues
71  * the GCC devs saw, and are using their solution:
72  *
73  * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
74  */
75 
76 /**
77  * Send a mavlink info message (not printed to console).
78  *
79  * @param _pub Pointer to the uORB advert;
80  * @param _text The text to log;
81  */
82 #define mavlink_log_info(_pub, _text, ...) mavlink_vasprintf(_MSG_PRIO_INFO, _pub, _text, ##__VA_ARGS__);
83 
84 /**
85  * Send a mavlink warning message and print to console.
86  *
87  * @param _pub Pointer to the uORB advert;
88  * @param _text The text to log;
89  */
90 #define mavlink_log_warning(_pub, _text, ...) \
91  do { \
92  mavlink_vasprintf(_MSG_PRIO_WARNING, _pub, _text, ##__VA_ARGS__); \
93  PX4_WARN(_text, ##__VA_ARGS__); \
94  } while(0);
95 
96 /**
97  * Send a mavlink emergency message and print to console.
98  *
99  * @param _pub Pointer to the uORB advert;
100  * @param _text The text to log;
101  */
102 #define mavlink_log_emergency(_pub, _text, ...) \
103  do { \
104  mavlink_vasprintf(_MSG_PRIO_EMERGENCY, _pub, _text, ##__VA_ARGS__); \
105  PX4_ERR(_text, ##__VA_ARGS__); \
106  } while(0);
107 
108 /**
109  * Send a mavlink critical message and print to console.
110  *
111  * @param _pub Pointer to the uORB advert;
112  * @param _text The text to log;
113  */
114 #define mavlink_log_critical(_pub, _text, ...) \
115  do { \
116  mavlink_vasprintf(_MSG_PRIO_CRITICAL, _pub, _text, ##__VA_ARGS__); \
117  PX4_WARN(_text, ##__VA_ARGS__); \
118  } while(0);
119 
120 /**
121  * Send a mavlink emergency message and print to console.
122  *
123  * @param _pub Pointer to the uORB advert;
124  * @param _text The text to log;
125  */
126 #define mavlink_and_console_log_info(_pub, _text, ...) \
127  do { \
128  mavlink_log_info(_pub, _text, ##__VA_ARGS__); \
129  PX4_INFO(_text, ##__VA_ARGS__); \
130  } while(0);
131 
134  unsigned char severity;
135 };
136 
138  unsigned int start;
139  unsigned int size;
140  int count;
142 };
143 
static orb_advert_t * mavlink_log_pub
API for the uORB lightweight object broker.
Definition: I2C.hpp:51
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134