Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
telemetry.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Gautier Hattenberger
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 
32 #include "generated/periodic_telemetry.h"
33 #if FIXEDWING_FIRMWARE || ROTORCRAFT_FIRMWARE || ROVER_FIRMWARE
34 #include "autopilot.h"
35 #endif
36 
37 
38 /* Implement global structures from generated header.
39  * Can register up to #TELEMETRY_NB_CBS callbacks per periodic message.
40  */
41 struct telemetry_cb_slots telemetry_cbs[TELEMETRY_PPRZ_NB_MSG] = TELEMETRY_PPRZ_CBS;
42 struct periodic_telemetry pprz_telemetry = { TELEMETRY_PPRZ_NB_MSG, telemetry_cbs };
43 
44 
52 {
53  uint8_t i, j;
54  // return if NULL is passed as periodic_telemetry
55  if (_pt == NULL) { return -1; }
56  // check if message with id _msgn has a periodic entery in telemetry file
57  for (i = 0; i < _pt->nb; i++) {
58  if (_pt->cbs[i].id == _id) {
59  // msg found, register another callback if not all TELEMETRY_NB_CBS slots taken
60  for (j = 0; j < TELEMETRY_NB_CBS; j++) {
61  if (_pt->cbs[i].slots[j] == NULL) {
62  _pt->cbs[i].slots[j] = _cb;
63  return j;
64  }
65  }
66  // message matched but no more empty slots available
67  return -1;
68  }
69  }
70  // message is not in telemetry file
71  return -1;
72 }
73 
78 {
79 #if FIXEDWING_FIRMWARE || ROTORCRAFT_FIRMWARE || ROVER_FIRMWARE
80  static uint8_t boot = true;
81 
82  /* initialisation phase during boot */
83  if (boot) {
84 #if DOWNLINK && !(defined INTERMCU_FBW)
86 #endif
87  boot = false;
88  }
89  /* then report periodicly */
90  else {
91 #if FIXEDWING_FIRMWARE
92 #if AP
93  periodic_telemetry_send_Ap(DefaultPeriodic, &(DefaultChannel).trans_tx, &(DefaultDevice).device);
94 #endif // AP
95 #if FBW || !TELEMETRY_INTERMCU // FIXME for now send both AP and FBW process if needed
96  periodic_telemetry_send_Fbw(DefaultPeriodic, &(DefaultChannel).trans_tx, &(DefaultDevice).device);
97 #endif //FBW
98 #else // ROTORCRAFT && ROVER
99  periodic_telemetry_send_Main(DefaultPeriodic, &(DefaultChannel).trans_tx, &(DefaultDevice).device);
100 #endif
101  }
102 #endif
103 }
104 
105 
106 #if USE_PERIODIC_TELEMETRY_REPORT
107 
109 
116 {
117  uint8_t process = _process;
118  uint8_t mode = _mode;
119  uint8_t id = _id;
120  DOWNLINK_SEND_PERIODIC_TELEMETRY_ERR(DefaultChannel, DefaultDevice, &process, &mode, &id);
121 }
122 
123 #endif
periodic_telemetry_err_report
void periodic_telemetry_err_report(uint8_t _process, uint8_t _mode, uint8_t _id)
Send an error report when trying to send message that as not been register.
Definition: telemetry.c:115
telemetry_cb
void(* telemetry_cb)(struct transport_tx *trans, struct link_device *dev)
Telemetry callback definition.
Definition: telemetry_common.h:44
int8_t
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
telemetry_cbs
struct telemetry_cb_slots telemetry_cbs[TELEMETRY_PPRZ_NB_MSG]
Definition: telemetry.c:41
periodic_telemetry::cbs
struct telemetry_cb_slots * cbs
array of callbacks defined through TELEMETRY_MSG
Definition: telemetry_common.h:64
telemetry_common.h
telemetry.h
autopilot_send_version
void autopilot_send_version(void)
send autopilot version
Definition: autopilot.c:316
telemetry_cb_slots::id
uint8_t id
id of telemetry message
Definition: telemetry_common.h:54
TELEMETRY_NB_CBS
#define TELEMETRY_NB_CBS
number of callbacks that can be registered per msg
Definition: telemetry_common.h:51
periodic_telemetry
Periodic telemetry structure.
Definition: telemetry_common.h:62
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
periodic_telemetry::nb
uint8_t nb
number of messages
Definition: telemetry_common.h:63
autopilot.h
pprz_telemetry
struct periodic_telemetry pprz_telemetry
Global telemetry structure.
Definition: telemetry.c:42
telemetry_cb_slots::slots
telemetry_cb slots[TELEMETRY_NB_CBS]
Definition: telemetry_common.h:55
mode
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
telemetry_cb_slots
Definition: telemetry_common.h:53
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
telemetry_reporting_task
void telemetry_reporting_task(void)
Peridioc task Send a series of initialisation messages followed by a stream of periodic ones.
Definition: telemetry.c:77