Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
telemetry_intermcu_fbw.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freek van Tienen <freek.v.tienen@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  */
22 
27 #include "telemetry_intermcu.h"
28 #include "subsystems/intermcu.h"
29 #include "pprzlink/pprz_transport.h"
30 #include "pprzlink/intermcu_msg.h"
33 
34 #define MSG_SIZE 256
35 
36 extern fbw_mode_enum fbw_mode;
37 
38 /* Structure for handling telemetry over InterMCU */
39 struct telemetry_intermcu_t {
40  struct link_device *dev;
41  struct pprz_transport trans;
42 
44  bool msg_received;
45 };
46 
47 /* Telemetry InterMCU throughput */
49 
50 /* Statically defined functions */
51 static void telemetry_intermcu_repack(struct transport_tx *trans, struct link_device *dev, uint8_t ac_id, uint8_t *msg, uint8_t size);
52 
53 /* InterMCU initialization */
55 {
56  // Initialize transport structure
57  pprz_transport_init(&telemetry_intermcu.trans);
58 
59  // Set the link device
60  telemetry_intermcu.dev = &(TELEMETRY_INTERMCU_DEV.device);
61 }
62 
63 /* InterMCU periodic handling of telemetry */
65 {
66 
67 }
68 
69 /* InterMCU event handling of telemetry */
71 {
72  pprz_check_and_parse(&(TELEMETRY_INTERMCU_DEV).device, &telemetry_intermcu.trans, telemetry_intermcu.rx_buffer, &telemetry_intermcu.msg_received);
74  /* Switch on MSG ID */
75  switch(pprzlink_get_msg_id(telemetry_intermcu.rx_buffer)) {
76  case DL_EMERGENCY_CMD:
77  if(DL_EMERGENCY_CMD_ac_id(telemetry_intermcu.rx_buffer) == AC_ID
78  && DL_EMERGENCY_CMD_cmd(telemetry_intermcu.rx_buffer) == 0) {
80  }
81  break;
82 
83  default:
84  break;
85  }
86 
87  /* Forward to AP */
88  pprz_msg_send_IMCU_DATALINK(&(intermcu.transport.trans_tx), intermcu.device,
90 
92  }
93 }
94 
96 {
98 }
99 
100 static void telemetry_intermcu_repack(struct transport_tx *trans, struct link_device *dev, uint8_t ac_id,uint8_t *msg, uint8_t size)
101 {
102 #if PPRZLINK_DEFAULT_VER == 2
103  struct pprzlink_msg pmsg;
104  pmsg.trans = trans;
105  pmsg.dev = dev;
106  pmsg.sender_id = ac_id;
107  pmsg.receiver_id = 0;
108  pmsg.component_id = 0;
109 
110  trans->count_bytes(&pmsg, size);
111  trans->start_message(&pmsg, _FD, size);
112  trans->put_bytes(&pmsg, _FD, DL_TYPE_UINT8, DL_FORMAT_ARRAY, (void *) msg, size);
113  trans->end_message(&pmsg, _FD);
114 #else
115  trans->count_bytes(trans->impl, dev, trans->size_of(trans->impl, size));
116  trans->start_message(trans->impl, dev, 0, size);
117  trans->put_bytes(trans->impl, dev, 0, DL_TYPE_UINT8, DL_FORMAT_ARRAY, (void *) msg, size);
118  trans->end_message(trans->impl, dev, 0);
119 #endif
120 }
uint8_t ac_id
Definition: sim_ap.c:48
void telemetry_intermcu_event(void)
struct link_device dev
Device structure for communication.
static void telemetry_intermcu_repack(struct transport_tx *trans, struct link_device *dev, uint8_t ac_id, uint8_t *msg, uint8_t size)
bool msg_received
Whenever a datalink message is received.
struct short_transport trans
Transport without any extra encoding.
struct link_device * device
Device used for communication.
Definition: intermcu.h:71
Periodic telemetry system header (includes downlink utility and generated code).
#define MSG_SIZE
struct intermcu_t intermcu
Definition: intermcu_ap.c:41
Telemetry through InterMCU.
struct link_device * dev
Device structure for communication.
static struct telemetry_intermcu_t telemetry_intermcu
fbw_mode_enum fbw_mode
Fly by wire modes.
Definition: main_fbw.c:63
uint8_t rx_buffer[MSG_SIZE]
Received bytes from datalink.
fbw_mode_enum
Definition: main_fbw.h:64
void telemetry_intermcu_init(void)
Rotorcraft Inter-MCU interface.
void telemetry_intermcu_on_msg(uint8_t *msg, uint8_t size)
struct pprz_transport transport
Transport over communication line (PPRZ)
Definition: intermcu.h:72
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
Fly By Wire:
unsigned char uint8_t
Definition: types.h:14
#define INTERMCU_FBW
Definition: intermcu.h:35
void telemetry_intermcu_periodic(void)
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)