Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
temp_temod.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Martin Mueller
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 
30 #include "mcu_periph/i2c.h"
31 #include "led.h"
32 #include "mcu_periph/uart.h"
33 #include "pprzlink/messages.h"
35 
36 // sd-log
37 #if TEMP_TEMOD_SDLOG
39 #include "subsystems/gps.h"
40 bool log_temod_started;
41 #endif
42 
45 
46 
47 #ifndef TEMOD_I2C_DEV
48 #define TEMOD_I2C_DEV i2c0
49 #endif
50 
51 #ifndef TEMOD_TYPE
52 #define TEMOD_TYPE TEMOD_I2C_R1
53 #endif
54 
55 #define TEMOD_SLAVE_ADDR 0xF0
56 
57 void temod_init(void)
58 {
60 
61 #if TEMP_TEMOD_SDLOG
62  log_temod_started = false;
63 #endif
64 }
65 
66 void temod_periodic(void)
67 {
68  if (tmd_trans.status == I2CTransDone) {
70  }
71 
72 }
73 
74 void temod_event(void)
75 {
76 
78 
79  // if MSB is 1, sensor reports an error, skip value
80  if (bit_is_set(tmd_trans.buf[0], 7)) {
82  return;
83  }
84 
85  uint16_t tmd_temperature;
86 
87  /* read two byte temperature */
88  tmd_temperature = tmd_trans.buf[0] << 8;
89  tmd_temperature |= tmd_trans.buf[1];
90 
91  ftmd_temperature = (tmd_temperature / TEMOD_TYPE) - 32.;
92 
93  DOWNLINK_SEND_TMP_STATUS(DefaultChannel, DefaultDevice, &tmd_temperature, &ftmd_temperature);
95 
96 
97 #if TEMP_TEMOD_SDLOG
98  if (pprzLogFile != -1) {
99  if (!log_temod_started) {
100  sdLogWriteLog(pprzLogFile, "TEMOD: Temp(degC) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gspeed(cm/s) course(1e7deg) climb(cm/s)\n");
101  log_temod_started = true;
102  }
103  else {
104  sdLogWriteLog(pprzLogFile, "temod: %9.4f %d %d %d %d %d %d %d %d %d\n",
106  gps.fix, gps.tow, gps.week,
109  }
110  }
111 #endif
112 
113  }
114  else if (tmd_trans.status == I2CTransFailed) {
116  }
117 }
118 
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
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
void temod_periodic(void)
Definition: temp_temod.c:66
uint16_t week
GPS week.
Definition: gps.h:108
#define TEMOD_SLAVE_ADDR
Definition: temp_temod.c:55
int32_t z
Down.
#define TEMOD_I2C_DEV
Definition: temp_temod.c:48
void temod_init(void)
Definition: temp_temod.c:57
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
transaction set to done by user level
Definition: i2c.h:59
uint32_t tow
GPS time of week in ms.
Definition: gps.h:109
Device independent GPS code (interface)
int32_t lon
in degrees*1e7
FileDes pprzLogFile
Definition: sdlog_chibios.c:86
transaction failed
Definition: i2c.h:58
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
float ftmd_temperature
Definition: temp_temod.c:43
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:99
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:334
arch independent LED (Light Emitting Diodes) API
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:97
struct i2c_transaction tmd_trans
Definition: temp_temod.c:44
#define TEMOD_TYPE
Definition: temp_temod.c:52
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:92
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:107
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:96
void temod_event(void)
Definition: temp_temod.c:74
struct GpsState gps
global GPS state
Definition: gps.c:69
Architecture independent I2C (Inter-Integrated Circuit Bus) API.