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.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Kirk Scheper <kirkscheper@gmail.com>
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 
28 #define DATALINK_C
29 #define MODULES_DATALINK_C
30 
31 #include "datalink.h"
33 
34 #include "generated/modules.h"
35 #include "generated/settings.h"
36 
37 #include "pprzlink/messages.h"
38 
39 #if defined RADIO_CONTROL && defined RADIO_CONTROL_TYPE_DATALINK
41 #endif
42 
43 #if USE_GPS
44 #include "subsystems/gps.h"
45 #endif
46 
47 #ifdef RADIO_CONTROL_DATALINK_LED
48 #include "led.h"
49 #endif
50 
51 #if USE_NPS
52 bool datalink_enabled = true;
53 #endif
54 
55 void dl_parse_msg(void)
56 {
57  uint8_t sender_id = SenderIdOfPprzMsg(dl_buffer);
58  uint8_t msg_id = IdOfPprzMsg(dl_buffer);
59 
60  /* parse telemetry messages coming from other AC */
61  if (sender_id != 0) {
62  switch (msg_id) {
63  default: {
64  break;
65  }
66  }
67  } else {
68  /* parse telemetry messages coming from ground station */
69  switch (msg_id) {
70  case DL_PING: {
71  DOWNLINK_SEND_PONG(DefaultChannel, DefaultDevice);
72  }
73  break;
74 
75  case DL_SETTING : {
76  if (DL_SETTING_ac_id(dl_buffer) != AC_ID) { break; }
77  uint8_t i = DL_SETTING_index(dl_buffer);
78  float var = DL_SETTING_value(dl_buffer);
79  DlSetting(i, var);
80  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &var);
81  }
82  break;
83 
84  case DL_GET_SETTING : {
85  if (DL_GET_SETTING_ac_id(dl_buffer) != AC_ID) { break; }
86  uint8_t i = DL_GET_SETTING_index(dl_buffer);
87  float val = settings_get_value(i);
88  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &val);
89  }
90  break;
91 
92 #ifdef RADIO_CONTROL_TYPE_DATALINK
93  case DL_RC_3CH :
94 #ifdef RADIO_CONTROL_DATALINK_LED
95  LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
96 #endif
98  DL_RC_3CH_throttle_mode(dl_buffer),
99  DL_RC_3CH_roll(dl_buffer),
100  DL_RC_3CH_pitch(dl_buffer));
101  break;
102  case DL_RC_4CH :
103  if (DL_RC_4CH_ac_id(dl_buffer) == AC_ID) {
104 #ifdef RADIO_CONTROL_DATALINK_LED
105  LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
106 #endif
107  parse_rc_4ch_datalink(DL_RC_4CH_mode(dl_buffer),
108  DL_RC_4CH_throttle(dl_buffer),
109  DL_RC_4CH_roll(dl_buffer),
110  DL_RC_4CH_pitch(dl_buffer),
111  DL_RC_4CH_yaw(dl_buffer));
112  }
113  break;
114 #endif // RADIO_CONTROL_TYPE_DATALINK
115 
116 #if USE_GPS
117  case DL_GPS_INJECT : {
118  // Check if the GPS is for this AC
119  if (DL_GPS_INJECT_ac_id(dl_buffer) != AC_ID) { break; }
120 
121  // GPS parse data
123  DL_GPS_INJECT_packet_id(dl_buffer),
124  DL_GPS_INJECT_data_length(dl_buffer),
125  DL_GPS_INJECT_data(dl_buffer)
126  );
127  }
128  break;
129 #endif // USE_GPS
130 
131  default:
132  break;
133  }
134  }
135  /* Parse firmware specific datalink */
137 
138  /* Parse modules datalink */
139  modules_parse_datalink(msg_id);
140 }
141 
142 /* default empty WEAK implementation for firmwares without an extra firmware_parse_msg */
143 WEAK void firmware_parse_msg(void)
144 {
145 }
Device independent GPS code (interface)
uint16_t val[TCOUPLE_NB]
#define LED_TOGGLE(i)
Definition: led_hw.h:51
unsigned char uint8_t
Definition: types.h:14
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
arch independent LED (Light Emitting Diodes) API
void gps_inject_data(uint8_t packet_id, uint8_t length, uint8_t *data)
Override the default GPS packet injector to inject the data trough UART.
Definition: gps_piksi.c:408