Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 "state.h"
31 #include "subsystems/gps.h"
32 #include "subsystems/electrical.h"
33 #include "generated/airframe.h"
34 #include "inter_mcu.h"
35 #include "autopilot.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 
51 
52 void generic_com_init(void)
53 {
54  active_com = false;
56 }
57 
58 #define FillBufWith32bit(_buf, _index, _value) { \
59  _buf[_index] = (uint8_t) (_value); \
60  _buf[_index+1] = (uint8_t) ((_value) >> 8); \
61  _buf[_index+2] = (uint8_t) ((_value) >> 16); \
62  _buf[_index+3] = (uint8_t) ((_value) >> 24); \
63  }
64 
65 #define FillBufWith16bit(_buf, _index, _value) { \
66  _buf[_index] = (uint8_t) (_value); \
67  _buf[_index+1] = (uint8_t) ((_value) >> 8); \
68  }
69 
71 {
72 
73  if (com_trans.status != I2CTransDone) { return; }
74 
78  FillBufWith16bit(com_trans.buf, 9, (int16_t)(gps.lla_pos.alt / 1000)); // altitude (meters)
79  FillBufWith16bit(com_trans.buf, 11, gps.gspeed); // ground speed (cm/s)
80  FillBufWith16bit(com_trans.buf, 13, (int16_t)(gps.course / 1e4)); // course (1e3rad)
81  FillBufWith16bit(com_trans.buf, 15, (uint16_t)(stateGetAirspeed_f() * 100)); // TAS (cm/s)
82  com_trans.buf[17] = electrical.vsupply; // decivolts
83  com_trans.buf[18] = (uint8_t)(energy / 100); // deciAh
84  com_trans.buf[19] = (uint8_t)(imcu_get_command(COMMAND_THROTTLE) * 100 / MAX_PPRZ);
86  com_trans.buf[21] = nav_block;
89 
90 }
91 
93 {
94  // Handle I2C event
97  }
98 }
99 
100 void start_com(void)
101 {
102  active_com = true;
104 }
105 
106 void stop_com(void)
107 {
108  active_com = false;
109  com_trans.buf[0] = active_com;
111 }
112 
unsigned short uint16_t
Definition: types.h:16
Communication between fbw and ap processes.
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
transaction successfully finished by I2C driver
Definition: i2c.h:57
#define FillBufWith16bit(_buf, _index, _value)
Definition: generic_com.c:65
uint16_t flight_time
flight time in seconds
Definition: autopilot.h:61
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
uint8_t nav_block
void start_com(void)
Definition: generic_com.c:100
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
void generic_com_periodic(void)
Definition: generic_com.c:70
int32_t alt
in millimeters above WGS84 reference ellipsoid
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw FIXME use electrical module ...
transaction set to done by user level
Definition: i2c.h:59
Interface for electrical status: supply voltage, current, battery status, etc.
Device independent GPS code (interface)
signed short int16_t
Definition: types.h:17
int32_t lon
in degrees*1e7
#define GENERIC_COM_SLAVE_ADDR
Definition: generic_com.c:45
transaction failed
Definition: i2c.h:58
void stop_com(void)
Definition: generic_com.c:106
struct i2c_transaction com_trans
Definition: generic_com.c:48
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:260
Core autopilot interface common to all firmwares.
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:93
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
bool active_com
Definition: generic_com.c:50
#define NB_DATA
Definition: generic_com.c:38
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:91
struct Electrical electrical
Definition: electrical.c:65
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:86
#define MAX_PPRZ
Definition: paparazzi.h:8
void generic_com_event(void)
Definition: generic_com.c:92
void generic_com_init(void)
Definition: generic_com.c:52
int32_t lat
in degrees*1e7
#define FillBufWith32bit(_buf, _index, _value)
Definition: generic_com.c:58
struct GpsState gps
global GPS state
Definition: gps.c:75
#define GENERIC_COM_I2C_DEV
Definition: generic_com.c:41
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:183
Architecture independent I2C (Inter-Integrated Circuit Bus) API.