Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
30 
31 #if PERIODIC_TELEMETRY
34 #include "mcu_periph/sys_time.h"
35 
36 static uint32_t last_down_nb_bytes = 0; // previous number of bytes sent
37 static uint32_t last_up_nb_msgs = 0; // previous number of received messages
38 static uint32_t last_ts = 0; // timestamp in usec when last message was send
39 
40 static void send_downlink(struct transport_tx *trans, struct link_device *dev)
41 {
42  // current timestamp
43  uint32_t now_ts = get_sys_time_msec();
44  // compute downlink byte rate
45  if (now_ts > last_ts) {
46  uint16_t down_rate = (1000 * ((uint32_t)dev->nb_bytes - last_down_nb_bytes)) / (now_ts - last_ts);
47  uint16_t up_rate = (1000 * ((uint32_t)datalink_nb_msgs - last_up_nb_msgs)) / (now_ts - last_ts);
48 
49  last_ts = now_ts;
50 #if defined DATALINK || defined SITL
51  last_down_nb_bytes = dev->nb_bytes;
52  last_up_nb_msgs = datalink_nb_msgs;
53 #else
54  last_down_nb_bytes = 0;
55  last_up_nb_msgs = 0;
56 #endif
57 
58  pprz_msg_send_DATALINK_REPORT(trans, dev, AC_ID, &datalink_time, &datalink_nb_msgs, &dev->nb_msgs, &down_rate,
59  &up_rate, &dev->nb_ovrn);
60  }
61 }
62 #endif
63 
64 void downlink_init(void)
65 {
66  // Set initial counters
68  (DefaultDevice).device.nb_bytes = 0;
70 
71 #if defined DATALINK
72 
73  datalink_nb_msgs = 0;
74 
75 #if DATALINK == PPRZ || DATALINK == SUPERBITRF || DATALINK == W5100 || DATALINK == BLUEGIGA
77 #endif
78 #if DATALINK == XBEE
79  xbee_init();
80 #endif
81 #if DATALINK == W5100
82  w5100_init();
83 #endif
84 #if DATALINK == BLUEGIGA
86 #endif
87 
88 #endif
89 
90 #if USE_PPRZLOG
92 #endif
93 
94 #if SITL && !USE_NPS
96 #endif
97 
98 #if PERIODIC_TELEMETRY
99  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_DATALINK_REPORT, send_downlink);
100 #endif
101 }
102 
static uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
Definition: sys_time_arch.h:49
unsigned short uint16_t
Definition: types.h:16
struct link_device device
Generic device interface.
Definition: bluegiga.h:61
Generic transmission transport header.
Definition: transport.h:89
Periodic telemetry system header (includes downlink utility and generated code).
void w5100_init(void)
Definition: w5100.c:183
struct bluegiga_periph bluegiga_p
Definition: bluegiga.c:50
void ivy_transport_init(void)
void bluegiga_init(struct bluegiga_periph *p)
Definition: bluegiga.c:126
uint16_t datalink_nb_msgs
Definition: sim_ap.c:44
void pprz_transport_init(struct pprz_transport *t)
Architecture independent timing functions.
void pprzlog_transport_init(void)
unsigned long uint32_t
Definition: types.h:18
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
uint16_t datalink_time
Definition: sim_ap.c:43
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
struct pprz_transport pprz_tp
void xbee_init(void)
Initialisation in API mode and setting of the local address FIXME: busy wait.
Definition: xbee.c:165
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46