Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xtend_rssi.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2011 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
33 #include "mcu_periph/pwm_input.h"
34 #include "mcu_periph/sys_time.h"
35 
36 #ifndef DOWNLINK_DEVICE
37 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
38 #endif
39 
40 #include "mcu_periph/uart.h"
41 #include "messages.h"
43 
44 //from Digi XTend manual
45 #define XTEND_RSSI_PWM_PERIOD_USEC 8320 //rssi pwm period () in sys tics
46 
47 #define XTEND_RSSI_PWM_ARRAY_INDEX (XTEND_RSSI_PWM_INPUT_CHANNEL - 1)
48 
49 void xtend_rssi_periodic( void ) {
50 
51 /* get the last duty if valid then reset valid flag (this says if we got another pulse since the last one)
52  calculate the % and dB from the duty using datasheet specs
53  send the %, dB, datalink time
54 */
55 
57  uint8_t duty_percent = 0;
58  uint8_t rssi_dB_fade_margin = 0; //shows dB fade margin above rated minimum sensitivity
59 
61  {
62  duty_percent = (duty_tics * 100) / CPU_TICKS_OF_USEC(XTEND_RSSI_PWM_PERIOD_USEC);
63  rssi_dB_fade_margin = (2 * duty_percent + 10) / 3; //not sure if this is right, datasheet isn't very informative
65  }
66  DOWNLINK_SEND_XTEND_RSSI(DefaultChannel, DefaultDevice,
68  &rssi_dB_fade_margin,
69  &duty_percent );
70 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
volatile uint32_t pwm_input_duty_tics[PWM_INPUT_NB]
Definition: pwm_input.c:31
arch independent PWM input capture API
volatile uint8_t pwm_input_duty_valid[PWM_INPUT_NB]
Definition: pwm_input.c:32
#define FALSE
Definition: imu_chimu.h:141
void xtend_rssi_periodic(void)
Definition: xtend_rssi.c:49
#define XTEND_RSSI_PWM_ARRAY_INDEX
Definition: xtend_rssi.c:47
#define XTEND_RSSI_PWM_PERIOD_USEC
Definition: xtend_rssi.c:45
Architecture independent timing functions.
This measures the rssi pwm signal from a Digi XTend radio modem and sends a message with the info...
#define CPU_TICKS_OF_USEC(us)
Definition: sys_time.h:102
unsigned long uint32_t
Definition: types.h:18
uint16_t datalink_time
Definition: sim_ap.c:46
unsigned char uint8_t
Definition: types.h:14