Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
downlink.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 Pascal Brisset, Antoine Drouin
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
28
30
31#if (defined DATALINK) || PERIODIC_TELEMETRY
33#endif
34#if defined DATALINK && (DATALINK == PPRZ)
36#endif
37
38#if PERIODIC_TELEMETRY
40#include "mcu_periph/sys_time.h"
41
42static uint32_t last_down_nb_bytes = 0; // previous number of bytes sent
43static uint32_t last_up_nb_msgs = 0; // previous number of received messages
44static uint32_t last_ts = 0; // timestamp in usec when last message was send
45
46static void send_downlink(struct transport_tx *trans, struct link_device *dev)
47{
48 // current timestamp
49 uint32_t now_ts = get_sys_time_msec();
50 // compute downlink byte rate
51 if (now_ts > last_ts) {
52 uint16_t down_rate = (1000 * ((uint32_t)dev->nb_bytes - last_down_nb_bytes)) / (now_ts - last_ts);
53 uint16_t up_rate = (1000 * ((uint32_t)datalink_nb_msgs - last_up_nb_msgs)) / (now_ts - last_ts);
54
55 last_ts = now_ts;
56#if defined DATALINK || defined SITL
57 last_down_nb_bytes = dev->nb_bytes;
59#else
62#endif
63
64 // errors of the uplink parser of this link, known when it is a pprz transport (e.g. the main or an
65 // extra pprz datalink, not the flight recorder): those share their functions and keep the rx and tx
66 // parts in one struct pprz_transport (impl)
67 uint8_t up_err = 0;
68 uint8_t up_ovrn = 0;
69#if defined DATALINK && (DATALINK == PPRZ)
70 if (trans->start_message == pprz_tp.trans_tx.start_message) {
71 struct pprz_transport *tp = (struct pprz_transport *) trans->impl;
72 up_err = tp->trans_rx.error;
73 up_ovrn = tp->trans_rx.ovrn;
74 }
75#endif
76
77 pprz_msg_send_DATALINK_REPORT(trans, dev, AC_ID, &datalink_time, &datalink_nb_msgs, &dev->nb_msgs, &down_rate,
78 &up_rate, &dev->nb_ovrn, &up_err, &up_ovrn);
79 }
80}
81#endif
82
83void downlink_init(void)
84{
85 // Set initial counters
86 (DefaultDevice).device.nb_ovrn = 0;
87 (DefaultDevice).device.nb_bytes = 0;
88 (DefaultDevice).device.nb_msgs = 0;
89
90#if PERIODIC_TELEMETRY
91 register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_DATALINK_REPORT, send_downlink);
92#endif
93}
94
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
static struct uart_periph * dev
struct pprz_transport pprz_tp
PPRZ transport structure.
Definition pprz_dl.c:33
Datalink using PPRZ protocol.
Architecture independent timing functions.
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 short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.