Firmware
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 
42 #pragma once
43 
44 #include <uORB/uORB.h>
45 
49 #define MAVLINK_LOG_MAXLEN 50
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 __EXPORT void mavlink_vasprintf(int severity, orb_advert_t *mavlink_log_pub, const char *fmt, ...);
55 #ifdef __cplusplus
56 }
57 #endif
58 
59 #define _MSG_PRIO_DEBUG 7
60 #define _MSG_PRIO_INFO 6
61 #define _MSG_PRIO_NOTICE 5
62 #define _MSG_PRIO_WARNING 4
63 #define _MSG_PRIO_ERROR 3
64 #define _MSG_PRIO_CRITICAL 2
65 #define _MSG_PRIO_ALERT 1
66 #define _MSG_PRIO_EMERGENCY 0
67 
68 /*
69  * The va_args implementation here is not beautiful, but obviously we run into the same issues
70  * the GCC devs saw, and are using their solution:
71  *
72  * http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
73  */
74 
81 #define mavlink_log_info(_pub, _text, ...) mavlink_vasprintf(_MSG_PRIO_INFO, _pub, _text, ##__VA_ARGS__);
82 
89 #define mavlink_log_warning(_pub, _text, ...) \
90  do { \
91  mavlink_vasprintf(_MSG_PRIO_WARNING, _pub, _text, ##__VA_ARGS__); \
92  PX4_WARN(_text, ##__VA_ARGS__); \
93  } while(0);
94 
101 #define mavlink_log_emergency(_pub, _text, ...) \
102  do { \
103  mavlink_vasprintf(_MSG_PRIO_EMERGENCY, _pub, _text, ##__VA_ARGS__); \
104  PX4_ERR(_text, ##__VA_ARGS__); \
105  } while(0);
106 
113 #define mavlink_log_critical(_pub, _text, ...) \
114  do { \
115  mavlink_vasprintf(_MSG_PRIO_CRITICAL, _pub, _text, ##__VA_ARGS__); \
116  PX4_WARN(_text, ##__VA_ARGS__); \
117  } while(0);
118 
125 #define mavlink_and_console_log_info(_pub, _text, ...) \
126  do { \
127  mavlink_log_info(_pub, _text, ##__VA_ARGS__); \
128  PX4_INFO(_text, ##__VA_ARGS__); \
129  } while(0);
130 
132  char text[MAVLINK_LOG_MAXLEN + 1];
133  unsigned char severity;
134 };
135 
137  unsigned int start;
138  unsigned int size;
139  int count;
140  struct mavlink_logmessage *elems;
141 };
142 
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
Definition: I2C.hpp:51
API for the uORB lightweight object broker.