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_fbw.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_fbw.h"
28 #include "intermcu_msg.h"
30 #include "mcu_periph/uart.h"
32 
33 #if RADIO_CONTROL_NB_CHANNEL > 8
34 #undef RADIO_CONTROL_NB_CHANNEL
35 #define RADIO_CONTROL_NB_CHANNEL 8
36 #warning "INTERMCU UART WILL ONLY SEND 8 RADIO CHANNELS"
37 #endif
38 
39 // Used for communication
40 static struct link_device *intermcu_device = (&((INTERMCU_LINK).device));
42 
45 static inline void intermcu_parse_msg(struct transport_rx *trans, void (*commands_frame_handler)(void));
46 
47 void intermcu_init(void)
48 {
50 }
51 
53 {
54  /* Check for interMCU loss */
57  } else {
59  }
60 }
61 
63 {
64  pprz_msg_send_IMCU_RADIO_COMMANDS(&(intermcu_transport.trans_tx), intermcu_device,
66 }
67 
69 {
70  // Send Status
71  (void)mode;
72  //FIXME
73 }
74 
75 static inline void intermcu_parse_msg(struct transport_rx *trans, void (*commands_frame_handler)(void))
76 {
77  /* Parse the Inter MCU message */
78  uint8_t msg_id = trans->payload[1];
79  switch (msg_id) {
80  case DL_IMCU_COMMANDS: {
81  uint8_t i;
82  uint8_t size = DL_IMCU_COMMANDS_values_length(trans->payload);
83  int16_t *new_commands = DL_IMCU_COMMANDS_values(trans->payload);
84  for (i = 0; i < size; i++) {
85  intermcu_commands[i] = new_commands[i];
86  }
87 
90  commands_frame_handler();
91  break;
92  }
93 
94  default:
95  break;
96  }
97 
98  // Set to receive another message
99  trans->msg_received = FALSE;
100 }
101 
102 void InterMcuEvent(void (*frame_handler)(void))
103 {
104  /* Parse incoming bytes */
105  if (intermcu_device->char_available(intermcu_device->periph)) {
106  while (intermcu_device->char_available(intermcu_device->periph) && !intermcu_transport.trans_rx.msg_received) {
107  parse_pprz(&intermcu_transport, intermcu_device->get_byte(intermcu_device->periph));
108  }
109 
112  }
113  }
114 }
static struct link_device * intermcu_device
Definition: intermcu_fbw.c:40
void intermcu_send_status(uint8_t mode)
Definition: intermcu_fbw.c:68
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 InterMcuEvent(void(*frame_handler)(void))
Definition: intermcu_fbw.c:102
Generic reception transport header.
Definition: transport.h:39
pprz_t intermcu_commands[COMMANDS_NB]
Definition: intermcu_fbw.c:44
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)
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
Rotorcraft Inter-MCU on FlyByWire.
void pprz_transport_init(struct pprz_transport *t)
struct transport_tx trans_tx
struct intermcu_t inter_mcu
Definition: intermcu_fbw.c:43
signed short int16_t
Definition: types.h:17
struct RadioControl radio_control
Definition: radio_control.c:30
static struct pprz_transport intermcu_transport
Definition: intermcu_fbw.c:41
void intermcu_on_rc_frame(void)
Definition: intermcu_fbw.c:62
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:34
static void intermcu_parse_msg(struct transport_rx *trans, void(*commands_frame_handler)(void))
Definition: intermcu_fbw.c:75
unsigned char uint8_t
Definition: types.h:14
void intermcu_init(void)
Definition: intermcu_fbw.c:47
uint8_t time_since_last_frame
Definition: intermcu.h:45
struct transport_rx trans_rx
#define INTERMCU_FBW
Definition: intermcu.h:34
void intermcu_periodic(void)
Definition: intermcu_fbw.c:52