Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "subsystems/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 
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 
65 void parse_rssi_dl(void)
66 {
67  uint8_t sender_id = SenderIdOfPprzMsg(dl_buffer);
68  uint8_t msg_id = IdOfPprzMsg(dl_buffer);
69 
70  if (sender_id > 0 && msg_id == DL_RSSI) {
71  set_rssi(sender_id,
72  DL_RSSI_tx_power(dl_buffer),
73  DL_RSSI_rssi(dl_buffer));
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 }
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
Main include for ABI (AirBorneInterface).
void parse_rssi_dl(void)
Definition: rssi.c:65
#define NB_ACS_ID
Definition: rssi.c:35
uint8_t rssi_acs_idx
Definition: rssi.c:41
#define NB_ACS
Definition: rssi.c:38
uint8_t rssi_acs_id[NB_ACS_ID]
Definition: rssi.c:43
int8_t rssi
Definition: rssi.h:33
unsigned char uint8_t
Definition: types.h:14
struct rssi_info_ get_rssi(uint8_t _ac_id)
Definition: rssi.c:90
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:64
uint8_t ac_id
Definition: rssi.h:32
#define ABI_BROADCAST
Broadcast address.
Definition: abi_common.h:56
static void rssi_cb(uint8_t sender_id, uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
Definition: rssi.c:47
signed char int8_t
Definition: types.h:15
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
struct rssi_info_ rssi_acs[NB_ACS]
Definition: rssi.c:42
int8_t tx_strength
Definition: rssi.h:34
abi_event ev
Definition: rssi.c:45