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
generic_com.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Gautier Hattenberger
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 /* Generic module to send data to a gsm/satcom module controlled by arduino over i2c */
24 
25 #include "std.h"
26 
28 #include "mcu_periph/i2c.h"
29 
30 #include "estimator.h"
31 #include "subsystems/gps.h"
32 #include "subsystems/electrical.h"
33 #include "generated/airframe.h"
34 #include "inter_mcu.h"
37 
38 #define NB_DATA 24
39 
40 #ifndef GENERIC_COM_I2C_DEV
41 #define GENERIC_COM_I2C_DEV i2c0
42 #endif
43 
44 #ifndef GENERIC_COM_SLAVE_ADDR
45 #define GENERIC_COM_SLAVE_ADDR 0x26
46 #endif
47 
49 
50 bool_t active_com;
51 
52 void generic_com_init( void ) {
53  active_com = FALSE;
55 }
56 
57 #define FillBufWith32bit(_buf, _index, _value) { \
58  _buf[_index] = (uint8_t) (_value); \
59  _buf[_index+1] = (uint8_t) ((_value) >> 8); \
60  _buf[_index+2] = (uint8_t) ((_value) >> 16); \
61  _buf[_index+3] = (uint8_t) ((_value) >> 24); \
62 }
63 
64 #define FillBufWith16bit(_buf, _index, _value) { \
65  _buf[_index] = (uint8_t) (_value); \
66  _buf[_index+1] = (uint8_t) ((_value) >> 8); \
67 }
68 
69 void generic_com_periodic( void ) {
70 
71  if (com_trans.status != I2CTransDone) { return; }
72 
76  FillBufWith16bit(com_trans.buf, 9, (int16_t)(gps.lla_pos.alt/1000)); // altitude (meters)
77  FillBufWith16bit(com_trans.buf, 11, gps.gspeed); // ground speed (cm/s)
78  FillBufWith16bit(com_trans.buf, 13, (int16_t)(gps.course/1e4)); // course (1e3rad)
79  FillBufWith16bit(com_trans.buf, 15, (uint16_t)(estimator_airspeed*100)); // TAS (cm/s)
80  com_trans.buf[17] = electrical.vsupply; // decivolts
81  com_trans.buf[18] = (uint8_t)(energy/100); // deciAh
82  com_trans.buf[19] = (uint8_t)(ap_state->commands[COMMAND_THROTTLE]*100/MAX_PPRZ);
83  com_trans.buf[20] = pprz_mode;
84  com_trans.buf[21] = nav_block;
87 
88 }
89 
90 void generic_com_event( void ) {
91  // Handle I2C event
94  }
95 }
96 
97 void start_com( void ) {
98  active_com = TRUE;
100 }
101 
102 void stop_com( void ) {
103  active_com = FALSE;
104  com_trans.buf[0] = active_com;
106 }
107 
unsigned short uint16_t
Definition: types.h:16
struct LlaCoor_i lla_pos
position in LLA (lat,lon: rad*1e7; alt: mm over ellipsoid)
Definition: gps.h:64
int32_t lat
in radians*1e7
int32_t course
GPS heading in rad*1e7 (CW/north)
Definition: gps.h:71
uint16_t estimator_flight_time
flight time in seconds.
Definition: estimator.c:59
uint8_t pprz_mode
Definition: main_ap.c:111
#define I2CTransmit(_p, _t, _s_addr, _len)
Definition: i2c.h:148
#define FillBufWith16bit(_buf, _index, _value)
Definition: generic_com.c:64
uint8_t nav_block
void start_com(void)
Definition: generic_com.c:97
void generic_com_periodic(void)
Definition: generic_com.c:69
#define FALSE
Definition: imu_chimu.h:141
struct ap_state * ap_state
Definition: inter_mcu.c:35
int16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:69
uint8_t vsupply
Definition: electrical.h:8
Device independent GPS code (interface)
float estimator_airspeed
m/s
Definition: estimator.c:69
signed short int16_t
Definition: types.h:17
int32_t alt
in millimeters above WGS84 reference ellipsoid
#define GENERIC_COM_SLAVE_ADDR
Definition: generic_com.c:45
void stop_com(void)
Definition: generic_com.c:102
bool_t active_com
Definition: generic_com.c:50
enum I2CTransactionStatus status
Definition: i2c.h:47
struct i2c_transaction com_trans
Definition: generic_com.c:48
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
unsigned char uint8_t
Definition: types.h:14
int32_t lon
in radians*1e7
float energy
Fuel consumption (mAh) TODO: move to electrical subsystem.
Definition: main_ap.c:138
#define NB_DATA
Definition: generic_com.c:38
State estimation, fusioning sensors.
struct Electrical electrical
Definition: electrical.c:16
#define MAX_PPRZ
Definition: paparazzi.h:8
void generic_com_event(void)
Definition: generic_com.c:90
void generic_com_init(void)
Definition: generic_com.c:52
#define FillBufWith32bit(_buf, _index, _value)
Definition: generic_com.c:57
struct GpsState gps
global GPS state
Definition: gps.c:31
#define GENERIC_COM_I2C_DEV
Definition: generic_com.c:41