Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
intermcu_ap.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
3 * Copyright (C) 2022 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 */
22
26
27#define PERIODIC_C_INTERMCU
28
30#include "pprzlink/intermcu_msg.h"
32#include "generated/modules.h"
33#include "autopilot.h"
34#if TELEMETRY_INTERMCU
36#endif
37#include "generated/periodic_telemetry.h"
38
39#if COMMANDS_NB > 8
40#warning "INTERMCU UART CAN ONLY SEND 8 COMMANDS OR THE UART MIGHT BE OVERFILLED"
41#endif
42
43
44/* Main InterMCU defines */
46 .device = (&((INTERMCU_LINK).device)),
47 .enabled = true,
48 .msg_available = false,
49};
50
51uint8_t imcu_msg_buf[128] __attribute__((aligned));
52
54
55
56#if PERIODIC_TELEMETRY
58
59/* Send FBW status */
60static void send_status(struct transport_tx *trans, struct link_device *dev)
61{
62 pprz_msg_send_FBW_STATUS(trans, dev, AC_ID,
63 &fbw_status.rc_status, &fbw_status.frame_rate, &fbw_status.mode,
64 &electrical.vsupply, &electrical.current);
65}
66#endif
67
68/* InterMCU initialization */
69void intermcu_init(void)
70{
71 pprz_transport_init(&intermcu.transport);
72
73#if PERIODIC_TELEMETRY
75#endif
76}
77
78/* Check for InterMCU loss */
80{
81 /* Check for interMCU loss */
82 if (intermcu.time_since_last_frame >= INTERMCU_LOST_CNT) {
83 intermcu.status = INTERMCU_LOST;
84 } else {
85 intermcu.time_since_last_frame++;
86 }
87
88#ifdef TELEMETRY_PROCESS_InterMCU
89 // send periodic InterMCU if defined in telemetry file
90 periodic_telemetry_send_InterMCU(DefaultPeriodic, &intermcu.transport.trans_tx, intermcu.device);
91#endif
92}
93
94/* Check new characters */
96{
97 /* Parse incoming bytes */
98 if (intermcu.enabled) {
99 pprz_check_and_parse(intermcu.device, &intermcu.transport, imcu_msg_buf, &intermcu.msg_available);
100 if (intermcu.msg_available) {
101 uint8_t class_id = pprzlink_get_msg_class_id(imcu_msg_buf);
102 // reset intermcu timer, don't touch msg_available flag
103 intermcu.time_since_last_frame = 0;
104
105 if (class_id == DL_intermcu_CLASS_ID) {
106 // parse intermcu messages and call callbacks
107 dl_parse_msg(intermcu.device, &intermcu.transport.trans_tx, imcu_msg_buf);
108 } else {
109 // reset datalink_time if message is not intermcu class
110 datalink_time = 0;
112#if TELEMETRY_INTERMCU
113 // forward all other messages if needed
114 intermcu_dl_on_msg(imcu_msg_buf, intermcu.transport.trans_rx.payload_len);
115#endif
116 }
117 intermcu.msg_available = false;
118 }
119 }
120}
121
122/* Enable or disable the communication of the InterMCU */
123void intermcu_set_enabled(bool value)
124{
125 intermcu.enabled = value;
126}
127
128/* Send the commands to the FBW */
129void intermcu_send_commands(pprz_t *command_values, uint8_t ap_mode __attribute__((unused)))
130{
131 if (!intermcu.enabled) {
132 return;
133 }
134
135 // Set the autopilot motors on status
138 }
139
140 // Send the message and reset cmd_status
141 pprz_msg_send_IMCU_COMMANDS(&(intermcu.transport.trans_tx), intermcu.device,
142 AC_ID, &intermcu.cmd_status, COMMANDS_NB, command_values); //TODO: Append more status
143 intermcu.cmd_status = 0;
144}
145
146/* Send the spektrum Bind message */
148{
149 if (intermcu.enabled) {
150 pprz_msg_send_IMCU_SPEKTRUM_SOFT_BIND(&(intermcu.transport.trans_tx), intermcu.device, AC_ID);
151 }
152}
153
155{
156 fbw_status.rc_status = DL_IMCU_FBW_STATUS_rc_status(buf);
157 fbw_status.frame_rate = DL_IMCU_FBW_STATUS_frame_rate(buf);
158 fbw_status.mode = DL_IMCU_FBW_STATUS_mode(buf);
159 electrical.vsupply = DL_IMCU_FBW_STATUS_vsupply(buf);
160 electrical.current = DL_IMCU_FBW_STATUS_current(buf);
161}
162
bool autopilot_get_motors_on(void)
get motors status
Definition autopilot.c:303
Core autopilot interface common to all firmwares.
static struct uart_periph * dev
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
#define INTERMCU_SET_CMD_STATUS(_bit)
Definition intermcu.h:55
#define INTERMCU_LOST_CNT
Definition intermcu.h:35
@ INTERMCU_LOST
No interMCU communication anymore.
Definition intermcu.h:43
bool enabled
If the InterMCU communication is enabled.
Definition intermcu.h:65
@ INTERMCU_CMD_MOTORS_ON
The status of intermcu_ap_motors_on.
Definition intermcu.h:48
struct intermcu_t intermcu
Definition intermcu_ap.c:45
bool msg_available
If we have an InterMCU message.
Definition intermcu.h:66
void intermcu_event(void)
Definition intermcu_ap.c:95
void intermcu_periodic(void)
Definition intermcu_ap.c:79
static void send_status(struct transport_tx *trans, struct link_device *dev)
Definition intermcu_ap.c:60
void intermcu_send_spektrum_bind(void)
send binding signal for spektrum receiver
void intermcu_set_enabled(bool value)
enable/disable intermcu link
void intermcu_parse_IMCU_FBW_STATUS(uint8_t *buf)
Datalink event functions.
uint8_t imcu_msg_buf[128]
The InterMCU message buffer.
Definition intermcu_ap.c:51
void intermcu_send_commands(pprz_t *command_values, uint8_t ap_mode)
send command vector over intermcu link instead of actuators
static struct fbw_status_t fbw_status
Definition intermcu_ap.c:53
void intermcu_init(void)
Definition intermcu_ap.c:69
Inter-MCU on the AP side.
void intermcu_dl_on_msg(uint8_t *msg, uint8_t size)
function to forward telemetry from AP to the ground
Definition intermcu_dl.c:79
datalink forwarder for InterMCU
int16_t pprz_t
Definition paparazzi.h:6
static void send_status(struct transport_tx *trans, struct link_device *dev)
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.