[modules] RSSI info storage

Stores info received from RSSI message from other aircrafts for communication protocols that support it.

picked out of #1630
This commit is contained in:
kirkscheper
2016-04-26 11:47:13 +02:00
committed by Felix Ruess
parent 84fd6f0bb6
commit cc1d9dd010
4 changed files with 160 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="rssi" dir="multi">
<doc>
<description>
RSSI info from other aircrafts.
Stores info received from RSSI message from other aircrafts for communication protocols that support it.
</description>
</doc>
<header>
<file name="rssi.h"/>
</header>
<init fun="rssi_init()"/>
<datalink message="RSSI" fun="parse_rssi_dl()"/>
<makefile>
<file name="rssi.c"/>
</makefile>
</module>
+93
View File
@@ -0,0 +1,93 @@
/*
* Copyright (C) Kirk Scheper
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/multi/rssi.c"
* @author Kirk Scheper
* stores received rssi values for communication protocols that support it
*/
#include "modules/multi/rssi.h"
#include "subsystems/datalink/datalink.h"
#include "pprzlink/messages.h"
#include "subsystems/abi.h" // rssi messages subscription
#include "generated/airframe.h" // AC_ID
#ifndef NB_ACS_ID
#define NB_ACS_ID 256
#endif
#ifndef NB_ACS
#define NB_ACS 24
#endif
uint8_t rssi_acs_idx;
struct rssi_info_ rssi_acs[NB_ACS];
uint8_t rssi_acs_id[NB_ACS_ID];
abi_event ev;
static void rssi_cb(uint8_t sender_id __attribute__((unused)), uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
{
set_rssi(_ac_id, _tx_strength, _rssi);
}
void rssi_init()
{
memset(rssi_acs_id, 0, NB_ACS_ID);
rssi_acs_id[0] = 0; // ground station
rssi_acs_id[AC_ID] = 1;
rssi_acs[rssi_acs_id[AC_ID]].ac_id = AC_ID;
rssi_acs_idx = 2;
/* register for rssi messages */
AbiBindMsgRSSI(ABI_BROADCAST, &ev, rssi_cb);
}
void parse_rssi_dl(void)
{
uint8_t sender_id = SenderIdOfPprzMsg(dl_buffer);
uint8_t msg_id = IdOfPprzMsg(dl_buffer);
if (sender_id > 0 && msg_id == DL_RSSI) {
set_rssi(sender_id,
DL_RSSI_tx_power(dl_buffer),
DL_RSSI_rssi(dl_buffer));
}
}
void set_rssi(uint8_t _ac_id, int8_t _tx_strength, int8_t _rssi)
{
if (rssi_acs_idx < NB_ACS) {
if (_ac_id > 0 && rssi_acs_id[_ac_id] == 0) {
rssi_acs_id[_ac_id] = rssi_acs_idx++;
rssi_acs[rssi_acs_id[_ac_id]].ac_id = _ac_id;
}
rssi_acs[rssi_acs_id[_ac_id]].rssi = _rssi;
rssi_acs[rssi_acs_id[_ac_id]].tx_strength = _tx_strength;
}
}
struct rssi_info_ get_rssi(uint8_t _ac_id)
{
return rssi_acs[rssi_acs_id[_ac_id]];
}
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright (C) Kirk Scheper
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/multi/rssi.h"
* @author Kirk Scheper
* stores received rssi values for communication protocols that support it
*/
#ifndef RSSI_H
#define RSSI_H
#include <inttypes.h>
struct rssi_info_ {
uint8_t ac_id;
int8_t rssi;
int8_t tx_strength;
};
extern uint8_t rssi_acs_idx;
extern uint8_t rssi_acs_id[];
extern struct rssi_info_ rssi_acs[];
extern void rssi_init(void);
extern void set_rssi(uint8_t _ac_id, int8_t _rssi, int8_t _tx_strength);
extern struct rssi_info_ get_rssi(uint8_t _ac_id);
extern void parse_rssi_dl(void);
#endif