Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
rssi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Kirk Scheper
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  */
26 #include "modules/multi/rssi.h"
27 
29 #include "pprzlink/messages.h"
30 
31 #include "modules/core/abi.h" // rssi messages subscription
32 #include "generated/airframe.h" // AC_ID
33 
34 #ifndef NB_ACS_ID
35 #define NB_ACS_ID 256
36 #endif
37 #ifndef NB_ACS
38 #define NB_ACS 24
39 #endif
40 
42 struct rssi_info_ rssi_acs[NB_ACS];
44 
46 
47 static void rssi_cb(uint8_t sender_id __attribute__((unused)), uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
48 {
49  set_rssi(_ac_id, _tx_strength, _rssi);
50 }
51 
52 void rssi_init()
53 {
54  memset(rssi_acs_id, 0, NB_ACS_ID);
55 
56  rssi_acs_id[0] = 0; // ground station
57  rssi_acs_id[AC_ID] = 1;
58  rssi_acs[rssi_acs_id[AC_ID]].ac_id = AC_ID;
59  rssi_acs_idx = 2;
60 
61  /* register for rssi messages */
62  AbiBindMsgRSSI(ABI_BROADCAST, &ev, rssi_cb);
63 }
64 
66 {
67  uint8_t sender_id = SenderIdOfPprzMsg(buf);
68  uint8_t msg_id = IdOfPprzMsg(buf);
69 
70  if (sender_id > 0 && msg_id == DL_RSSI) {
71  set_rssi(sender_id,
72  DL_RSSI_tx_power(buf),
73  DL_RSSI_rssi(buf));
74  }
75 }
76 
77 void set_rssi(uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
78 {
79  if (rssi_acs_idx < NB_ACS) {
80  if (_ac_id > 0 && rssi_acs_id[_ac_id] == 0) {
81  rssi_acs_id[_ac_id] = rssi_acs_idx++;
82  rssi_acs[rssi_acs_id[_ac_id]].ac_id = _ac_id;
83  }
84 
85  rssi_acs[rssi_acs_id[_ac_id]].rssi = _rssi;
86  rssi_acs[rssi_acs_id[_ac_id]].tx_strength = _tx_strength;
87  }
88 }
89 
90 struct rssi_info_ get_rssi(uint8_t _ac_id)
91 {
92  return rssi_acs[rssi_acs_id[_ac_id]];
93 }
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Definition: abi_common.h:58
Event structure to store callbacks in a linked list.
Definition: abi_common.h:67
abi_event ev
Definition: rssi.c:45
static void rssi_cb(uint8_t sender_id, uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
Definition: rssi.c:47
struct rssi_info_ get_rssi(uint8_t _ac_id)
Definition: rssi.c:90
void set_rssi(uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
Definition: rssi.c:77
void rssi_init()
Definition: rssi.c:52
uint8_t rssi_acs_id[NB_ACS_ID]
Definition: rssi.c:43
uint8_t rssi_acs_idx
Definition: rssi.c:41
struct rssi_info_ rssi_acs[NB_ACS]
Definition: rssi.c:42
void parse_rssi_dl(uint8_t *buf)
Definition: rssi.c:65
#define NB_ACS_ID
Definition: rssi.c:35
#define NB_ACS
Definition: rssi.c:38
int8_t rssi
Definition: rssi.h:33
uint8_t ac_id
Definition: rssi.h:32
int8_t tx_strength
Definition: rssi.h:34
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103