Paparazzi UAS v7.0_unstable
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 "modules/gps/gps.h"
33#include "generated/airframe.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
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 uint8_t vsupply = Min(electrical.vsupply * 10.f, 255); // deciVolt
83 uint8_t charge = Min(electrical.vsupply * 10.f, 255); // deciAh
84 com_trans.buf[17] = vsupply;
85 com_trans.buf[18] = charge;
91}
92
94{
95 // Handle I2C event
98 }
99}
100
101void start_com(void)
102{
103 active_com = true;
105}
106
113
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:222
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
Core autopilot interface common to all firmwares.
uint16_t flight_time
flight time in seconds
Definition autopilot.h:65
uint16_t charge[CHARGE_NB]
Definition charge_sens.c:43
Hardware independent code for commands handling.
uint8_t get_nav_block()
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float vsupply
supply voltage in V
Definition electrical.h:45
#define Min(x, y)
Definition esc_dshot.c:109
#define GENERIC_COM_I2C_DEV
Definition generic_com.c:41
#define FillBufWith16bit(_buf, _index, _value)
Definition generic_com.c:65
void generic_com_init(void)
Definition generic_com.c:52
#define FillBufWith32bit(_buf, _index, _value)
Definition generic_com.c:58
void start_com(void)
void generic_com_periodic(void)
Definition generic_com.c:70
void generic_com_event(void)
Definition generic_com.c:93
struct i2c_transaction com_trans
Definition generic_com.c:48
#define GENERIC_COM_SLAVE_ADDR
Definition generic_com.c:45
bool active_com
Definition generic_com.c:50
#define NB_DATA
Definition generic_com.c:38
void stop_com(void)
struct GpsState gps
global GPS state
Definition gps.c:74
Device independent GPS code (interface)
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition gps.h:92
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition gps.h:99
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition gps.h:97
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:122
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:202
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:57
@ I2CTransFailed
transaction failed
Definition i2c.h:58
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:59
I2C transaction structure.
Definition i2c.h:93
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t lon
in degrees*1e7
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition state.h:1590
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
API to get/set the generic vehicle states.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.