Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
intermcu_ap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 The Paparazzi Team
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  */
22 
27 #include "intermcu_ap.h"
28 #include "intermcu_msg.h"
31 #include "mcu_periph/uart.h"
32 
33 #if COMMANDS_NB > 8
34 #error "INTERMCU UART CAN ONLY SEND 8 COMMANDS OR THE UART WILL BE OVERFILLED"
35 #endif
36 
37 // Used for communication
38 static struct link_device *intermcu_device = (&((INTERMCU_LINK).device));
40 
42 static inline void intermcu_parse_msg(struct transport_rx *trans, void (*rc_frame_handler)(void));
43 
44 void intermcu_init(void)
45 {
47 }
48 
50 {
51  /* Check for interMCU loss */
54  } else {
56  }
57 }
58 
59 void intermcu_set_actuators(pprz_t *command_values, uint8_t ap_mode __attribute__((unused)))
60 {
61  pprz_msg_send_IMCU_COMMANDS(&(intermcu_transport.trans_tx), intermcu_device,
62  INTERMCU_AP, 0, COMMANDS_NB, command_values); //TODO: Fix status
63 }
64 
65 static inline void intermcu_parse_msg(struct transport_rx *trans, void (*rc_frame_handler)(void))
66 {
67  /* Parse the Inter MCU message */
68  uint8_t msg_id = trans->payload[1];
69  switch (msg_id) {
70  case DL_IMCU_RADIO_COMMANDS: {
71  uint8_t i;
72  uint8_t size = DL_IMCU_RADIO_COMMANDS_values_length(trans->payload);
73  int16_t *rc_values = DL_IMCU_RADIO_COMMANDS_values(trans->payload);
74  for (i = 0; i < size; i++) {
75  radio_control.values[i] = rc_values[i];
76  }
77 
81  rc_frame_handler();
82  break;
83  }
84 
85  default:
86  break;
87  }
88 
89  // Set to receive another message
90  trans->msg_received = FALSE;
91 }
92 
93 void RadioControlEvent(void (*frame_handler)(void))
94 {
95  /* Parse incoming bytes */
96  if (intermcu_device->char_available(intermcu_device->periph)) {
97  while (intermcu_device->char_available(intermcu_device->periph) && !intermcu_transport.trans_rx.msg_received) {
98  parse_pprz(&intermcu_transport, intermcu_device->get_byte(intermcu_device->periph));
99  }
100 
103  }
104  }
105 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
volatile bool_t msg_received
message received flag
Definition: transport.h:42
#define INTERMCU_LOST_CNT
Definition: intermcu.h:36
void RadioControlEvent(void(*frame_handler)(void))
Definition: intermcu_ap.c:93
static void intermcu_parse_msg(struct transport_rx *trans, void(*rc_frame_handler)(void))
Definition: intermcu_ap.c:65
Generic reception transport header.
Definition: transport.h:39
uint8_t status
Definition: radio_control.h:53
uint8_t payload[TRANSPORT_PAYLOAD_LEN]
payload buffer
Definition: transport.h:40
int16_t pprz_t
Definition: paparazzi.h:6
static void parse_pprz(struct pprz_transport *t, uint8_t c)
void intermcu_periodic(void)
Definition: intermcu_ap.c:49
#define INTERMCU_AP
Definition: intermcu.h:33
enum intermcu_status status
Definition: intermcu.h:44
Building and parsing Paparazzi frames.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
#define FALSE
Definition: std.h:5
void pprz_transport_init(struct pprz_transport *t)
struct transport_tx trans_tx
static struct pprz_transport intermcu_transport
Definition: intermcu_ap.c:39
struct intermcu_t inter_mcu
Definition: intermcu_ap.c:41
signed short int16_t
Definition: types.h:17
struct RadioControl radio_control
Definition: radio_control.c:30
Rotorcraft Inter-MCU on the autopilot.
#define RC_OK
Definition: radio_control.h:48
void intermcu_init(void)
Definition: intermcu_ap.c:44
static struct link_device * intermcu_device
Definition: intermcu_ap.c:38
unsigned char uint8_t
Definition: types.h:14
uint8_t time_since_last_frame
Definition: intermcu.h:45
struct transport_rx trans_rx
uint8_t time_since_last_frame
Definition: radio_control.h:54
void intermcu_set_actuators(pprz_t *command_values, uint8_t ap_mode)
Definition: intermcu_ap.c:59
uint8_t frame_cpt
Definition: radio_control.h:57