Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
uart_cam_ctrl.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) OpenUAS
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 
28 #include "uart_cam_ctrl.h"
29 #include "generated/airframe.h"
30 
31 // Include Standard Camera Control Interface
32 #include "modules/digital_cam/dc.h"
33 
34 // Telemetry
36 
37 #include BOARD_CONFIG
38 
39 // Communication
41 
42 #ifdef SITL
44 #endif
45 
46 #include "state.h"
47 
48 
49 #define CameraLinkDev (&((CAMERA_LINK).device))
50 #define CameraLinkTransmit(c) CameraLinkDev->put_byte(CameraLinkDev->periph, 0, c)
51 #define CameraLinkChAvailable() CameraLinkDev->char_available(CameraLinkDev->periph)
52 #define CameraLinkGetch() CameraLinkDev->get_byte(CameraLinkDev->periph)
53 
57 
59 #define THUMB_MSG_SIZE MORA_PAYLOAD_MSG_SIZE
60 #define THUMB_COUNT 10
63 
64 
66 {
67  while (CameraLinkChAvailable()) {
70  switch (mora_protocol.msg_id) {
71  case MORA_STATUS:
72  for (int i = 0; i < MORA_STATUS_MSG_SIZE; i++) {
74  }
76  break;
77  case MORA_PAYLOAD:
78  for (int i = 0; i < MORA_PAYLOAD_MSG_SIZE; i++) {
80  }
81  break;
82  default:
83  break;
84  }
86  }
87  }
88 }
89 
90 #if PERIODIC_TELEMETRY
91 static void send_thumbnails(struct transport_tx *trans, struct link_device *dev)
92 {
93  static int cnt = 0;
95  if (digital_cam_uart_thumbnails == 1) {
96  cnt++;
97  if (cnt > 1) {
98  cnt = 0;
99  return;
100  }
101  }
102  pprz_msg_send_PAYLOAD(trans, dev, AC_ID, THUMB_MSG_SIZE, thumbs[thumb_pointer]);
103 
104  // Update the write/read pointer: if we receive a new thumb part, that will be sent, otherwise the oldest infor is repeated
105  thumb_pointer++;
106  if (thumb_pointer >= THUMB_COUNT) {
107  thumb_pointer = 0;
108  }
109 
111  MoraTrailer();
112  }
113 }
114 #endif
115 
117 {
119  for (int t = 0; t < THUMB_COUNT; t++) {
120  for (int i = 0; i < THUMB_MSG_SIZE; i++) {
121  thumbs[t][i] = 0;
122  }
123  }
124 #if PERIODIC_TELEMETRY
126 #endif
127 
128 #ifdef SITL
129  serial_init("/dev/ttyUSB0");
130 #endif
131 }
132 
134 {
135  // Common DC Periodic task
136  dc_periodic();
137 }
138 
139 
140 /* Command The Camera */
142 {
143  switch (cmd) {
144  case DC_SHOOT:
145  // Send Photo Position To Camera
146  dc_shot_msg.data.nr = dc_photo_nr + 1;
156 
158  for (int i = 0; i < (MORA_SHOOT_MSG_SIZE); i++) {
160  }
161  MoraTrailer();
163  break;
164  case DC_TALLER:
165  break;
166  case DC_WIDER:
167  break;
168  case DC_ON:
169  break;
170  case DC_OFF:
171  break;
172  default:
173  break;
174  }
175 
176  // call command send_command function
178 }
void dc_periodic(void)
periodic function
Definition: dc.c:279
void dc_send_command_common(uint8_t cmd)
Command sending function.
Definition: dc.c:192
uint16_t dc_photo_nr
export the number of the last photo
Definition: dc.c:95
void dc_send_shot_position(void)
Send Down the coordinates of where the photo was taken.
Definition: dc.c:106
Standard Digital Camera Control Interface.
@ DC_OFF
Definition: dc.h:118
@ DC_WIDER
Definition: dc.h:104
@ DC_SHOOT
Definition: dc.h:102
@ DC_TALLER
Definition: dc.h:105
@ DC_ON
Definition: dc.h:117
|STX|length|...
#define MORA_PAYLOAD_MSG_SIZE
Definition: protocol.h:75
#define MORA_STATUS
Definition: protocol.h:80
#define MORA_STATUS_MSG_SIZE
Definition: protocol.h:81
#define MoraTrailer()
Definition: protocol.h:117
#define MoraHeader(msg_id, payload_len)
Definition: protocol.h:109
#define MoraPutUint8(_byte)
Definition: protocol.h:103
struct dc_shot_union::@293 data
uint8_t payload[256]
Definition: protocol.h:132
#define MORA_BUFFER_EMPTY
Definition: protocol.h:70
#define MORA_SHOOT_MSG_SIZE
Definition: protocol.h:48
uint8_t msg_id
Definition: protocol.h:134
uint8_t bin[MORA_SHOOT_MSG_SIZE]
Definition: protocol.h:66
bool msg_received
Definition: protocol.h:135
struct mora_status_union::mora_status_struct data
#define MORA_PAYLOAD
Definition: protocol.h:74
#define MORA_SHOOT
Definition: protocol.h:47
uint8_t bin[MORA_STATUS_MSG_SIZE]
Definition: protocol.h:91
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define POS_BFP_OF_REAL(_af)
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t lon
in degrees*1e7
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1288
struct State state
Definition: state.c:36
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
Definition: state.h:812
float alt_agl_f
Altitude above ground level.
Definition: state.h:226
static int32_t stateGetHorizontalSpeedDir_i(void)
Get dir of horizontal ground speed (int).
Definition: state.h:1040
static uint32_t stateGetHorizontalSpeedNorm_i(void)
Get norm of horizontal ground speed (int).
Definition: state.h:1031
void parse_mora(struct mora_transport *t, uint8_t c)
Definition: protocol.c:20
struct mora_transport mora_protocol
Definition: protocol.c:18
int serial_init(char *port_name)
Definition: serial.c:28
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
static uint8_t thumbs[THUMB_COUNT][THUMB_MSG_SIZE]
Definition: uart_cam_ctrl.c:61
static void send_thumbnails(struct transport_tx *trans, struct link_device *dev)
Definition: uart_cam_ctrl.c:91
#define THUMB_MSG_SIZE
Definition: uart_cam_ctrl.c:59
void digital_cam_uart_event(void)
Definition: uart_cam_ctrl.c:65
int digital_cam_uart_thumbnails
Definition: uart_cam_ctrl.c:58
void dc_send_command(uint8_t cmd)
Send Command To Camera.
int digital_cam_uart_status
Definition: uart_cam_ctrl.c:56
void digital_cam_uart_init(void)
#define CameraLinkChAvailable()
Definition: uart_cam_ctrl.c:51
void digital_cam_uart_periodic(void)
static uint8_t thumb_pointer
Definition: uart_cam_ctrl.c:62
union dc_shot_union dc_shot_msg
Definition: uart_cam_ctrl.c:54
#define CameraLinkGetch()
Definition: uart_cam_ctrl.c:52
#define THUMB_COUNT
Definition: uart_cam_ctrl.c:60
union mora_status_union mora_status_msg
Definition: uart_cam_ctrl.c:55
Digital Camera Control Over UART with download of thumbnails over the PAYLOAD message.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98