Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
actuators_t4_uart.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 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, see
18 * <http://www.gnu.org/licenses/>.
19 */
27#include "pprzlink/pprz_transport.h"
28#include "mcu_periph/uart.h"
29#include "mcu_periph/sys_time.h"
30#include <time.h>
31#include <sys/time.h>
32#include "modules/core/abi.h"
34
35/* Variables for outbound packet */
40
41/* Variables for outbound packet */
44
50
52
53
54#if PERIODIC_TELEMETRY
55
57
58static void actuators_t4_downlink(struct transport_tx *trans, struct link_device *dev) {
63
68
73
78
79 // Not used, and if so maybe to uint16_t in Kelvin not Celcius
80 //int16_t esc_1_temperature_telemetry = actuators_t4_in.esc_1_temperature;
81 //int16_t esc_2_temperature_telemetry = actuators_t4_in.esc_2_temperature;
82 //int16_t esc_3_temperature_telemetry = actuators_t4_in.esc_3_temperature;
83 //int16_t esc_4_temperature_telemetry = actuators_t4_in.esc_4_temperature;
84
97
109
112
127}
128
129 static void actuators_t4_uplink(struct transport_tx *trans, struct link_device *dev) {
130
137
150
153
161
162 }
163
164#endif // PERIODIC_TELEMETRY
165
167
168 /* Copying the struct to be transmitted and the extra data in a local variable: */
171
172 /* Increase the counter to track the sending messages: */
176 if(actuators_t4_out_msg_id == 255){
178 }
179
180 /* Send the message over UART to the T4 Actuators Board: */
182 //Calculating the checksum
184 for(uint16_t i = 0; i < sizeof(struct ActuatorsT4Out) - 1; i++){
186 }
188
189#ifdef ACTUATORS_T4_SIM
190 /* don't send the data if it is SIM */
191 //TODO: why not, could be useful for HITL
192#else
193 /* Do send the bytes */
195 for(uint8_t i = 0; i < sizeof(struct ActuatorsT4Out) ; i++){
197 }
198#endif
199}
200
214
215/* Send the received message over ABI so then another module can use this actuator state info in e.g. control modules */
217{
218 memcpy(&actuators_t4_in, &actuators_t4_msg_buf_in[1], sizeof(struct ActuatorsT4In)); //Starting from 1 to avoid reading the starting byte
219 /* Assign the rolling message: */
221 /* Send msg through ABI: */
223}
224
225/* Event checking if serial packet are available on the bus */
227{
228 if(fabs(get_sys_time_float() - actuators_t4_last_ts) > 5){ //Reset received packets to zero every 5 second to update the statistics
231 }
232#ifdef ACTUATORS_T4_SIM //TODO: use the SIM, NPS and HITL flags ,but if HIL is used it should be able to send the data to the T4 board
233 /* Don't do anything if it is SIM */
234#else
241 }
242 if (actuators_t4_buf_in_cnt > sizeof(struct ActuatorsT4In) ) {
245 for(uint16_t i = 1; i < sizeof(struct ActuatorsT4In) ; i++){
247 }
251 }
252 else {
254 }
255 }
256 }
257#endif
259}
260
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:59
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
uint32_t actuators_t4_received_packets
void actuators_t4_uart_event()
static uint8_t actuators_t4_msg_buf_in[sizeof(struct ActuatorsT4In) *2]
The message buffer for the device chosen to be 2* message_size total.
uint8_t actuators_t4_out_msg_id
float actuators_t4_last_ts
float actuators_t4_extra_data_in[255]
float actuators_t4_extra_data_out[255]
static abi_event ACTUATORS_T4_OUT
struct ActuatorsT4In actuators_t4_in
struct ActuatorsT4Out actuators_t4_out
void actuators_t4_uart_parse_msg_in(void)
static void actuators_t4_uplink(struct transport_tx *trans, struct link_device *dev)
uint32_t actuators_t4_missed_packets_in
uint16_t actuators_t4_buf_in_cnt
void actuators_t4_uart_init()
static void actuators_t4_downlink(struct transport_tx *trans, struct link_device *dev)
static void data_actuators_t4_out(uint8_t sender_id, struct ActuatorsT4Out *actuators_t4_out_ptr, float *actuators_t4_extra_data_out_ptr)
uint16_t actuators_t4_message_frequency_in
Uses a T4 Actuators Board as fly by wire system. This Board can control serial bus servos,...
#define START_BYTE_ACTUATORS_T4
uint16_t bitmask_servo_health
void uart_put_byte(struct uart_periph *periph, long fd, uint8_t data)
Definition uart_arch.c:306
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
Definition uart_arch.c:357
uint8_t uart_getch(struct uart_periph *p)
Definition uart_arch.c:348
uint16_t foo
Definition main_demo5.c:58
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:138
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
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.