Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
copilot_common.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 2017 Michal Podhradsky <http://github.com/podhrmic>
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 */
43
46
50
54
58
60void copilot_init(void)
61{
62 send_cam_snapshot = false;
63 send_cam_payload = false;
64 send_copilot_status = false;
65
66 memset(&cam_payload, 0, sizeof(cam_payload));
67 memset(&cam_snapshot, 0, sizeof(cam_snapshot));
68 memset(&copilot_status, 0, sizeof(copilot_status));
69
73}
74
77{
80 // send down to GCS
81 DOWNLINK_SEND_CAMERA_SNAPSHOT(DefaultChannel, DefaultDevice,
82 &cam_snapshot.cam_id, &cam_snapshot.cam_state,
83 &cam_snapshot.snapshot_num, &cam_snapshot.snapshot_valid,
84 &cam_snapshot.lens_temp, &cam_snapshot.array_temp);
85
86 send_cam_snapshot = false;
87 }
89
91 if (send_cam_payload) {
92 // NOTE: to send the message over the EXTRA_DL port
93 // use "DOWNLINK_SEND_CAMERA_PAYLOAD(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,"
94
95 // send down to GCS
96 DOWNLINK_SEND_CAMERA_PAYLOAD(DefaultChannel, DefaultDevice,
97 &cam_payload.timestamp, &cam_payload.used_mem, &cam_payload.used_disk,
98 &cam_payload.door_status, &cam_payload.error_code);
99
100 send_cam_payload = false;
101 }
103
105 // send down to GCS
107 DOWNLINK_SEND_COPILOT_STATUS(DefaultChannel, DefaultDevice,
108 &copilot_status.timestamp, &copilot_status.used_mem,
109 &copilot_status.used_disk, &copilot_status.status,
110 &copilot_status.error_code);
111
112 send_copilot_status = false;
113 }
115
116}
117
128{
130
131 // copy CAMERA_SNAPSHOT message and mark it to be sent
132 cam_snapshot.cam_id = DL_CAMERA_SNAPSHOT_DL_camera_id(buf);
133 cam_snapshot.cam_state = DL_CAMERA_SNAPSHOT_DL_camera_state(buf);
134 cam_snapshot.snapshot_num = DL_CAMERA_SNAPSHOT_DL_snapshot_image_number(buf);
135 cam_snapshot.snapshot_valid = DL_CAMERA_SNAPSHOT_DL_snapshot_valid(buf);
136 cam_snapshot.lens_temp = DL_CAMERA_SNAPSHOT_DL_lens_temp(buf);
137 cam_snapshot.array_temp = DL_CAMERA_SNAPSHOT_DL_array_temp(buf);
138
139 send_cam_snapshot = true;
140
142}
143
148{
150
151 cam_payload.timestamp = DL_CAMERA_PAYLOAD_DL_timestamp(buf);
152 cam_payload.used_mem = DL_CAMERA_PAYLOAD_DL_used_memory(buf);
153 cam_payload.used_disk = DL_CAMERA_PAYLOAD_DL_used_disk(buf);
154 cam_payload.door_status = DL_CAMERA_PAYLOAD_DL_door_status(buf);
155 cam_payload.error_code = DL_CAMERA_PAYLOAD_DL_error_code(buf);
156
157 send_cam_payload = true;
158
160}
161
166{
168
169 copilot_status.timestamp = DL_COPILOT_STATUS_DL_timestamp(buf);
170 copilot_status.used_mem = DL_COPILOT_STATUS_DL_used_memory(buf);
171 copilot_status.used_disk = DL_COPILOT_STATUS_DL_used_disk(buf);
172 copilot_status.status = DL_COPILOT_STATUS_DL_status(buf);
173 copilot_status.error_code = DL_COPILOT_STATUS_DL_error_code(buf);
174
175 send_copilot_status = true;
176
178}
179
184void copilot_parse_payload_command_dl(uint8_t *buf __attribute__((unused)))
185{
186#if FORWARD_PAYLOAD
187MESSAGE("Forwarding PAYLOAD_COMMAND messages.")
188 // Check if message was for us
189 if (DL_PAYLOAD_COMMAND_ac_id(buf) == AC_ID) {
190 uint8_t len = DL_PAYLOAD_COMMAND_command_length(buf);
191
192 if (buf == extra_dl_get_buffer()) {
193 // Message came from extra_dl, forward to GCS via telemetry
194 DOWNLINK_SEND_PAYLOAD(DefaultChannel, DefaultDevice,
195 len, DL_PAYLOAD_COMMAND_command(buf));
196 }
197
198 if (buf == datalink_get_buffer()) {
199 // Message came from GCS/Telemetry, forward to extra_dl
200 DOWNLINK_SEND_PAYLOAD(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,
201 len, DL_PAYLOAD_COMMAND_command(buf));
202 }
203 }
204#endif /* FORWARD_PAYLOAD */
205}
int pprz_mtx_unlock(pprz_mutex_t *mtx)
int pprz_mtx_init(pprz_mutex_t *mtx)
int pprz_mtx_lock(pprz_mutex_t *mtx)
Mission Computer module, interfacing the mission computer (also known as Copilot),...
pprz_mutex_t copilot_cam_snapshot_mtx
pprz_mutex_t copilot_status_mtx
bool send_cam_payload
pprz_mutex_t copilot_cam_payload_mtx
bool send_cam_snapshot
bool send_copilot_status
struct CameraPayload cam_payload
void copilot_init(void)
Init function.
struct CopilotStatus copilot_status
void copilot_parse_cam_snapshot_dl(uint8_t *buf)
copy CAMERA_SNAPSHOT message and mark it to be sent
void copilot_parse_cam_payload_dl(uint8_t *buf)
copy CAMERA_PAYLOAD message and mark it to be sent
void copilot_parse_payload_command_dl(uint8_t *buf)
Pass through PAYLOAD_COMMAND message and send it as PAYLOAD msg over telemetry.
struct CameraSnapshot cam_snapshot
void copilot_parse_copilot_status_dl(uint8_t *buf)
copy COPILOT_STATUS message and mark it to be sent
void copilot_periodic(void)
Periodic function.
struct pprz_transport extra_pprz_tp
uint8_t * extra_dl_get_buffer(void)
Periodic telemetry system header (includes downlink utility and generated code).
struct pprzMutex pprz_mutex_t
Definition threads.h:21
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.