diff --git a/conf/modules/rssi.xml b/conf/modules/rssi.xml new file mode 100644 index 0000000000..b6f4476684 --- /dev/null +++ b/conf/modules/rssi.xml @@ -0,0 +1,19 @@ + + + + + + RSSI info from other aircrafts. + Stores info received from RSSI message from other aircrafts for communication protocols that support it. + + +
+ +
+ + + + + +
+ diff --git a/sw/airborne/modules/multi/rssi.c b/sw/airborne/modules/multi/rssi.c new file mode 100644 index 0000000000..a4a05b8833 --- /dev/null +++ b/sw/airborne/modules/multi/rssi.c @@ -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 + * . + */ +/** + * @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]]; +} diff --git a/sw/airborne/modules/multi/rssi.h b/sw/airborne/modules/multi/rssi.h new file mode 100644 index 0000000000..62e0f0125f --- /dev/null +++ b/sw/airborne/modules/multi/rssi.h @@ -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 + * . + */ +/** + * @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 + +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 diff --git a/sw/ext/pprzlink b/sw/ext/pprzlink index ce7f042185..ab69fa785b 160000 --- a/sw/ext/pprzlink +++ b/sw/ext/pprzlink @@ -1 +1 @@ -Subproject commit ce7f04218522ebc239df27c13b710783c92cd88a +Subproject commit ab69fa785b6145037c949873d92a9aed65160949