Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
datalink.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Pascal Brisset, Antoine Drouin
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
27 #ifndef DATALINK_H
28 #define DATALINK_H
29 
30 #ifdef DATALINK_C
31 #define EXTERN
32 #else
33 #define EXTERN extern
34 #endif
35 
36 #include "std.h"
37 #include "pprzlink/dl_protocol.h"
38 
39 /* Message id helpers */
40 #define SenderIdOfPprzMsg(x) (x[0])
41 #define IdOfPprzMsg(x) (x[1])
42 
44 #define PPRZ 1
45 #define XBEE 2
46 #define SUPERBITRF 3
47 #define W5100 4
48 #define BLUEGIGA 5
49 
52 
55 
58 
59 #define MSG_SIZE 128
60 EXTERN uint8_t dl_buffer[MSG_SIZE] __attribute__((aligned));
61 
63 EXTERN void dl_parse_msg(void);
64 
66 EXTERN void firmware_parse_msg(void);
67 
68 #if USE_NPS
69 EXTERN bool datalink_enabled;
70 #endif
71 
73 #define DatalinkFillDlBuffer(_buf, _len) { \
74  uint8_t _i = 0; \
75  for (_i = 0; _i < _len; _i++) { \
76  dl_buffer[_i] = _buf[_i]; \
77  } \
78  dl_msg_available = true; \
79 }
80 
82 static inline void DlCheckAndParse(void)
83 {
84  // make it possible to disable datalink in NPS sim
85 #if USE_NPS
86  if (!datalink_enabled) {
87  return;
88  }
89 #endif
90 
91  if (dl_msg_available) {
92  datalink_time = 0;
94  dl_parse_msg();
95  dl_msg_available = false;
96  }
97 }
98 
99 #if defined DATALINK && DATALINK == PPRZ
100 
101 #define DatalinkEvent() { \
102  pprz_check_and_parse(&(PPRZ_UART).device, &pprz_tp, dl_buffer, &dl_msg_available); \
103  DlCheckAndParse(); \
104  }
105 
106 #elif defined DATALINK && DATALINK == XBEE
107 
108 #define DatalinkEvent() { \
109  xbee_check_and_parse(&(XBEE_UART).device, &xbee_tp, dl_buffer, &dl_msg_available); \
110  DlCheckAndParse(); \
111  }
112 
113 #elif defined DATALINK && DATALINK == W5100
114 
115 #define DatalinkEvent() { \
116  W5100CheckAndParse(W5100, pprz_tp); \
117  DlCheckAndParse(); \
118  }
119 
120 #elif defined DATALINK && DATALINK == SUPERBITRF
121 
122 #define DatalinkEvent() { \
123  SuperbitRFCheckAndParse(); \
124  DlCheckAndParse(); \
125  }
126 
127 #elif defined DATALINK && DATALINK == BLUEGIGA
128 
129 #define DatalinkEvent() { \
130  pprz_check_and_parse(&(DOWNLINK_DEVICE).device, &pprz_tp, dl_buffer, &dl_msg_available); \
131  DlCheckAndParse(); \
132  }
133 
134 #else
135 
136 // Unknown DATALINK
137 #define DatalinkEvent() {}
138 
139 #endif /* DATALINK == */
140 
141 #endif /* DATALINK_H */
unsigned short uint16_t
Definition: types.h:16
unsigned char uint8_t
Definition: types.h:14