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
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 }
int32_t psi
in rad with INT32_ANGLE_FRAC
static int32_t stateGetHorizontalSpeedDir_i(void)
Get dir of horizontal ground speed (int).
Definition: state.h:899
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.
Periodic telemetry system header (includes downlink utility and generated code).
int32_t theta
in rad with INT32_ANGLE_FRAC
#define POS_BFP_OF_REAL(_af)
static uint8_t thumb_pointer
Definition: uart_cam_ctrl.c:62
struct mora_transport mora_protocol
Definition: protocol.c:18
#define MORA_PAYLOAD
Definition: protocol.h:74
|STX|length|...
#define MoraPutUint8(_byte)
Definition: protocol.h:103
uint16_t dc_photo_nr
export the number of the last photo
Definition: dc.c:93
void dc_send_command(uint8_t cmd)
Send Command To Camera.
#define CameraLinkChAvailable()
Definition: uart_cam_ctrl.c:51
uint8_t msg_id
Definition: protocol.h:134
#define THUMB_COUNT
Definition: uart_cam_ctrl.c:60
int32_t alt
in millimeters above WGS84 reference ellipsoid
void dc_init(void)
initialize settings
Definition: dc.c:156
#define THUMB_MSG_SIZE
Definition: uart_cam_ctrl.c:59
Definition: dc.h:100
Definition: dc.h:103
uint8_t payload[256]
Definition: protocol.h:132
Standard Digital Camera Control Interface.
uint8_t bin[MORA_SHOOT_MSG_SIZE]
Definition: protocol.h:66
int digital_cam_uart_thumbnails
Definition: uart_cam_ctrl.c:58
void dc_send_command_common(uint8_t cmd)
Command sending function.
Definition: dc.c:189
static uint8_t thumbs[THUMB_COUNT][THUMB_MSG_SIZE]
Definition: uart_cam_ctrl.c:61
uint8_t bin[MORA_STATUS_MSG_SIZE]
Definition: protocol.h:91
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
int32_t lon
in degrees*1e7
static uint32_t stateGetHorizontalSpeedNorm_i(void)
Get norm of horizontal ground speed (int).
Definition: state.h:890
#define MORA_STATUS
Definition: protocol.h:80
struct dc_shot_union::@278 data
Definition: dc.h:102
Definition: dc.h:116
#define MORA_STATUS_MSG_SIZE
Definition: protocol.h:81
float alt_agl_f
Altitude above ground level.
Definition: state.h:198
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
void digital_cam_uart_event(void)
Definition: uart_cam_ctrl.c:65
bool msg_received
Definition: protocol.h:135
#define MORA_SHOOT_MSG_SIZE
Definition: protocol.h:48
int serial_init(char *port_name)
Definition: serial.c:28
int32_t phi
in rad with INT32_ANGLE_FRAC
unsigned char uint8_t
Definition: types.h:14
#define MoraTrailer()
Definition: protocol.h:117
API to get/set the generic vehicle states.
void dc_periodic(void)
periodic function
Definition: dc.c:273
void digital_cam_uart_periodic(void)
union dc_shot_union dc_shot_msg
Definition: uart_cam_ctrl.c:54
#define MORA_PAYLOAD_MSG_SIZE
Definition: protocol.h:75
int digital_cam_uart_status
Definition: uart_cam_ctrl.c:56
#define MORA_SHOOT
Definition: protocol.h:47
void digital_cam_uart_init(void)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
Definition: dc.h:115
int32_t lat
in degrees*1e7
#define MoraHeader(msg_id, payload_len)
Definition: protocol.h:109
struct mora_status_union::mora_status_struct data
#define CameraLinkGetch()
Definition: uart_cam_ctrl.c:52
void parse_mora(struct mora_transport *t, uint8_t c)
Definition: protocol.c:20
static void send_thumbnails(struct transport_tx *trans, struct link_device *dev)
Definition: uart_cam_ctrl.c:91
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
Definition: state.h:683
struct State state
Definition: state.c:36
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
void dc_send_shot_position(void)
Send Down the coordinates of where the photo was taken.
Definition: dc.c:104
#define MORA_BUFFER_EMPTY
Definition: protocol.h:70