Paparazzi UAS  v5.18.0_stable
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 
31 #include "generated/periodic_telemetry.h"
32 
33 /* Implement global structures from generated header.
34  * Can register up to #TELEMETRY_NB_CBS callbacks per periodic message.
35  */
36 struct telemetry_cb_slots telemetry_cbs[TELEMETRY_PPRZ_NB_MSG] = TELEMETRY_PPRZ_CBS;
37 struct periodic_telemetry pprz_telemetry = { TELEMETRY_PPRZ_NB_MSG, telemetry_cbs };
38 
39 
47 {
48  uint8_t i, j;
49  // return if NULL is passed as periodic_telemetry
50  if (_pt == NULL) { return -1; }
51  // check if message with id _msgn has a periodic entery in telemetry file
52  for (i = 0; i < _pt->nb; i++) {
53  if (_pt->cbs[i].id == _id) {
54  // msg found, register another callback if not all TELEMETRY_NB_CBS slots taken
55  for (j = 0; j < TELEMETRY_NB_CBS; j++) {
56  if (_pt->cbs[i].slots[j] == NULL) {
57  _pt->cbs[i].slots[j] = _cb;
58  return j;
59  }
60  }
61  // message matched but no more empty slots available
62  return -1;
63  }
64  }
65  // message is not in telemetry file
66  return -1;
67 }
68 
69 #if USE_PERIODIC_TELEMETRY_REPORT
70 
72 
79 {
80  uint8_t process = _process;
81  uint8_t mode = _mode;
82  uint8_t id = _id;
83  DOWNLINK_SEND_PERIODIC_TELEMETRY_ERR(DefaultChannel, DefaultDevice, &process, &mode, &id);
84 }
85 
86 #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:78
telemetry_cb
void(* telemetry_cb)(struct transport_tx *trans, struct link_device *dev)
Telemetry callback definition.
Definition: telemetry_common.h:44
telemetry_cbs
struct telemetry_cb_slots telemetry_cbs[TELEMETRY_PPRZ_NB_MSG]
Definition: telemetry.c:36
periodic_telemetry::cbs
struct telemetry_cb_slots * cbs
array of callbacks defined through TELEMETRY_MSG
Definition: telemetry_common.h:64
telemetry_common.h
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
uint8_t
unsigned char uint8_t
Definition: types.h:14
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:46
periodic_telemetry::nb
uint8_t nb
number of messages
Definition: telemetry_common.h:63
int8_t
signed char int8_t
Definition: types.h:15
pprz_telemetry
struct periodic_telemetry pprz_telemetry
Global telemetry structure.
Definition: telemetry.c:37
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