Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 }
intermcu.h
Rotorcraft Inter-MCU interface.
telemetry_intermcu_init
void telemetry_intermcu_init(void)
Definition: telemetry_intermcu_fbw.c:54
FBW_MODE_FAILSAFE
@ FBW_MODE_FAILSAFE
Definition: main_fbw.h:64
telemetry_intermcu_event
void telemetry_intermcu_event(void)
Definition: telemetry_intermcu_fbw.c:70
telemetry_intermcu.h
Telemetry through InterMCU.
intermcu_t::device
struct link_device * device
Device used for communication.
Definition: intermcu.h:71
telemetry_intermcu_t::dev
struct link_device dev
Device structure for communication.
Definition: telemetry_intermcu_ap.h:40
telemetry_intermcu_t::dev
struct link_device * dev
Device structure for communication.
Definition: telemetry_intermcu_fbw.c:40
INTERMCU_FBW
#define INTERMCU_FBW
Definition: intermcu.h:35
fbw_mode
fbw_mode_enum fbw_mode
Fly by wire modes.
Definition: main_fbw.c:63
telemetry_intermcu_repack
static void telemetry_intermcu_repack(struct transport_tx *trans, struct link_device *dev, uint8_t ac_id, uint8_t *msg, uint8_t size)
Definition: telemetry_intermcu_fbw.c:100
main_fbw.h
msg
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
Definition: high_speed_logger_direct_memory.c:134
telemetry.h
intermcu
struct intermcu_t intermcu
Definition: intermcu_ap.c:41
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
uint8_t
unsigned char uint8_t
Definition: types.h:14
telemetry_intermcu_t
Definition: telemetry_intermcu_ap.h:39
telemetry_intermcu_t::trans
struct short_transport trans
Transport without any extra encoding.
Definition: telemetry_intermcu_ap.h:41
intermcu_t::transport
struct pprz_transport transport
Transport over communication line (PPRZ)
Definition: intermcu.h:72
MSG_SIZE
#define MSG_SIZE
Definition: telemetry_intermcu_fbw.c:34
ac_id
uint8_t ac_id
Definition: sim_ap.c:48
telemetry_intermcu_on_msg
void telemetry_intermcu_on_msg(uint8_t *msg, uint8_t size)
Definition: telemetry_intermcu_fbw.c:95
telemetry_intermcu_t::rx_buffer
uint8_t rx_buffer[MSG_SIZE]
Received bytes from datalink.
Definition: telemetry_intermcu_fbw.c:43
telemetry_intermcu_t::msg_received
bool msg_received
Whenever a datalink message is received.
Definition: telemetry_intermcu_fbw.c:44
telemetry_intermcu
static struct telemetry_intermcu_t telemetry_intermcu
Definition: telemetry_intermcu_fbw.c:48
fbw_mode_enum
fbw_mode_enum
Definition: main_fbw.h:64
telemetry_intermcu_periodic
void telemetry_intermcu_periodic(void)
Definition: telemetry_intermcu_fbw.c:64