Paparazzi UAS  v5.18.0_stable
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 {
118  // Call common DC init
119  dc_init();
121  for (int t = 0; t < THUMB_COUNT; t++) {
122  for (int i = 0; i < THUMB_MSG_SIZE; i++) {
123  thumbs[t][i] = 0;
124  }
125  }
126 #if PERIODIC_TELEMETRY
128 #endif
129 
130 #ifdef SITL
131  serial_init("/dev/ttyUSB0");
132 #endif
133 }
134 
136 {
137  // Common DC Periodic task
138  dc_periodic();
139 }
140 
141 
142 /* Command The Camera */
144 {
145  switch (cmd) {
146  case DC_SHOOT:
147  // Send Photo Position To Camera
148  dc_shot_msg.data.nr = dc_photo_nr + 1;
158 
160  for (int i = 0; i < (MORA_SHOOT_MSG_SIZE); i++) {
162  }
163  MoraTrailer();
165  break;
166  case DC_TALLER:
167  break;
168  case DC_WIDER:
169  break;
170  case DC_ON:
171  break;
172  case DC_OFF:
173  break;
174  default:
175  break;
176  }
177 
178  // call command send_command function
180 }
CameraLinkChAvailable
#define CameraLinkChAvailable()
Definition: uart_cam_ctrl.c:51
Int32Eulers::theta
int32_t theta
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:148
dc_send_command_common
void dc_send_command_common(uint8_t cmd)
Command sending function.
Definition: dc.c:189
LlaCoor_i::lon
int32_t lon
in degrees*1e7
Definition: pprz_geodetic_int.h:61
MORA_SHOOT
#define MORA_SHOOT
Definition: protocol.h:47
digital_cam_uart_thumbnails
int digital_cam_uart_thumbnails
Definition: uart_cam_ctrl.c:58
LlaCoor_i::alt
int32_t alt
in millimeters above WGS84 reference ellipsoid
Definition: pprz_geodetic_int.h:62
dc_photo_nr
uint16_t dc_photo_nr
export the number of the last photo
Definition: dc.c:93
mora_status_union::bin
uint8_t bin[MORA_STATUS_MSG_SIZE]
Definition: protocol.h:91
MoraHeader
#define MoraHeader(msg_id, payload_len)
Definition: protocol.h:109
thumbs
static uint8_t thumbs[THUMB_COUNT][THUMB_MSG_SIZE]
Definition: uart_cam_ctrl.c:61
thumb_pointer
static uint8_t thumb_pointer
Definition: uart_cam_ctrl.c:62
dc_send_command
void dc_send_command(uint8_t cmd)
Send Command To Camera.
Definition: uart_cam_ctrl.c:143
stateGetPositionLla_i
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
Definition: state.h:683
protocol.h
MORA_PAYLOAD
#define MORA_PAYLOAD
Definition: protocol.h:74
mora_transport::msg_id
uint8_t msg_id
Definition: protocol.h:134
MORA_STATUS
#define MORA_STATUS
Definition: protocol.h:80
DC_OFF
@ DC_OFF
Definition: dc.h:116
mora_status_union::mora_status_struct::shots
uint16_t shots
Definition: protocol.h:88
stateGetHorizontalSpeedDir_i
static int32_t stateGetHorizontalSpeedDir_i(void)
Get dir of horizontal ground speed (int).
Definition: state.h:899
MORA_STATUS_MSG_SIZE
#define MORA_STATUS_MSG_SIZE
Definition: protocol.h:81
dc.h
mora_status_msg
union mora_status_union mora_status_msg
Definition: uart_cam_ctrl.c:55
MORA_PAYLOAD_MSG_SIZE
#define MORA_PAYLOAD_MSG_SIZE
Definition: protocol.h:75
mora_status_union
Definition: protocol.h:84
LlaCoor_i::lat
int32_t lat
in degrees*1e7
Definition: pprz_geodetic_int.h:60
telemetry.h
MORA_BUFFER_EMPTY
#define MORA_BUFFER_EMPTY
Definition: protocol.h:70
Int32Eulers::psi
int32_t psi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:149
Int32Eulers::phi
int32_t phi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:147
mora_transport::payload
uint8_t payload[256]
Definition: protocol.h:132
MORA_SHOOT_MSG_SIZE
#define MORA_SHOOT_MSG_SIZE
Definition: protocol.h:48
serial_init
int serial_init(char *port_name)
Definition: serial.c:28
MoraTrailer
#define MoraTrailer()
Definition: protocol.h:117
DC_WIDER
@ DC_WIDER
Definition: dc.h:102
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
mora_protocol
struct mora_transport mora_protocol
Definition: protocol.c:18
uint8_t
unsigned char uint8_t
Definition: types.h:14
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
DC_TALLER
@ DC_TALLER
Definition: dc.h:103
dc_send_shot_position
void dc_send_shot_position(void)
Send Down the coordinates of where the photo was taken.
Definition: dc.c:104
THUMB_MSG_SIZE
#define THUMB_MSG_SIZE
Definition: uart_cam_ctrl.c:59
MoraPutUint8
#define MoraPutUint8(_byte)
Definition: protocol.h:103
dc_shot_union::data
struct dc_shot_union::@288 data
parse_mora
void parse_mora(struct mora_transport *t, uint8_t c)
Definition: protocol.c:20
mora_transport::msg_received
bool msg_received
Definition: protocol.h:135
serial.h
digital_cam_uart_event
void digital_cam_uart_event(void)
Definition: uart_cam_ctrl.c:65
THUMB_COUNT
#define THUMB_COUNT
Definition: uart_cam_ctrl.c:60
DC_SHOOT
@ DC_SHOOT
Definition: dc.h:100
dc_shot_msg
union dc_shot_union dc_shot_msg
Definition: uart_cam_ctrl.c:54
uart_cam_ctrl.h
Digital Camera Control Over UART with download of thumbnails over the PAYLOAD message.
CameraLinkGetch
#define CameraLinkGetch()
Definition: uart_cam_ctrl.c:52
DC_ON
@ DC_ON
Definition: dc.h:115
digital_cam_uart_periodic
void digital_cam_uart_periodic(void)
Definition: uart_cam_ctrl.c:135
digital_cam_uart_status
int digital_cam_uart_status
Definition: uart_cam_ctrl.c:56
stateGetHorizontalSpeedNorm_i
static uint32_t stateGetHorizontalSpeedNorm_i(void)
Get norm of horizontal ground speed (int).
Definition: state.h:890
POS_BFP_OF_REAL
#define POS_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:216
send_thumbnails
static void send_thumbnails(struct transport_tx *trans, struct link_device *dev)
Definition: uart_cam_ctrl.c:91
stateGetNedToBodyEulers_i
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
State::alt_agl_f
float alt_agl_f
Altitude above ground level.
Definition: state.h:198
dc_shot_union::bin
uint8_t bin[MORA_SHOOT_MSG_SIZE]
Definition: protocol.h:66
state.h
digital_cam_uart_init
void digital_cam_uart_init(void)
Definition: uart_cam_ctrl.c:116
dc_init
void dc_init(void)
initialize settings
Definition: dc.c:156
dc_shot_union
Definition: protocol.h:53
mora_status_union::data
struct mora_status_union::mora_status_struct data
state
struct State state
Definition: state.c:36
dc_periodic
void dc_periodic(void)
periodic function
Definition: dc.c:273
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66