Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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  */
46 
50 
54 
55 PPRZ_MUTEX(copilot_cam_snapshot_mtx);
56 PPRZ_MUTEX(copilot_cam_payload_mtx);
57 PPRZ_MUTEX(copilot_status_mtx);
58 
60 void 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 
70  PPRZ_MUTEX_INIT(copilot_cam_snapshot_mtx);
71  PPRZ_MUTEX_INIT(copilot_cam_payload_mtx);
72  PPRZ_MUTEX_INIT(copilot_status_mtx);
73 }
74 
76 void copilot_periodic(void)
77 {
78  PPRZ_MUTEX_LOCK(copilot_cam_snapshot_mtx);
80  {
81  // send down to GCS
82  DOWNLINK_SEND_CAMERA_SNAPSHOT(DefaultChannel, DefaultDevice,
89 
90  send_cam_snapshot = false;
91  }
92  PPRZ_MUTEX_UNLOCK(copilot_cam_snapshot_mtx);
93 
94 
95  PPRZ_MUTEX_LOCK(copilot_cam_payload_mtx);
96  if (send_cam_payload)
97  {
98  // NOTE: to send the message over the EXTRA_DL port
99  // use "DOWNLINK_SEND_CAMERA_PAYLOAD(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,"
100 
101  // send down to GCS
102  DOWNLINK_SEND_CAMERA_PAYLOAD(DefaultChannel, DefaultDevice,
108 
109  send_cam_payload = false;
110  }
111  PPRZ_MUTEX_UNLOCK(copilot_cam_payload_mtx);
112 
113  PPRZ_MUTEX_LOCK(copilot_status_mtx);
114  // send down to GCS
116  {
117  DOWNLINK_SEND_COPILOT_STATUS(DefaultChannel, DefaultDevice,
123 
124  send_copilot_status = false;
125  }
126  PPRZ_MUTEX_UNLOCK(copilot_status_mtx);
127 
128 }
129 
140 {
141  PPRZ_MUTEX_LOCK(copilot_cam_snapshot_mtx);
142 
143  // copy CAMERA_SNAPSHOT message and mark it to be sent
144  cam_snapshot.cam_id = DL_CAMERA_SNAPSHOT_DL_camera_id(buf);
145  cam_snapshot.cam_state = DL_CAMERA_SNAPSHOT_DL_camera_state(buf);
146  cam_snapshot.snapshot_num = DL_CAMERA_SNAPSHOT_DL_snapshot_image_number(buf);
147  cam_snapshot.snapshot_valid = DL_CAMERA_SNAPSHOT_DL_snapshot_valid(buf);
148  cam_snapshot.lens_temp = DL_CAMERA_SNAPSHOT_DL_lens_temp(buf);
149  cam_snapshot.array_temp = DL_CAMERA_SNAPSHOT_DL_array_temp(buf);
150 
151  send_cam_snapshot = true;
152 
153  PPRZ_MUTEX_UNLOCK(copilot_cam_snapshot_mtx);
154 }
155 
160 {
161  PPRZ_MUTEX_LOCK(copilot_cam_payload_mtx);
162 
163  cam_payload.timestamp = DL_CAMERA_PAYLOAD_DL_timestamp(buf);
164  cam_payload.used_mem = DL_CAMERA_PAYLOAD_DL_used_memory(buf);
165  cam_payload.used_disk = DL_CAMERA_PAYLOAD_DL_used_disk(buf);
166  cam_payload.door_status = DL_CAMERA_PAYLOAD_DL_door_status(buf);
167  cam_payload.error_code = DL_CAMERA_PAYLOAD_DL_error_code(buf);
168 
169  send_cam_payload = true;
170 
171  PPRZ_MUTEX_UNLOCK(copilot_cam_payload_mtx);
172 }
173 
178 {
179  PPRZ_MUTEX_LOCK(copilot_status_mtx);
180 
181  copilot_status.timestamp = DL_COPILOT_STATUS_DL_timestamp(buf);
182  copilot_status.used_mem = DL_COPILOT_STATUS_DL_used_memory(buf);
183  copilot_status.used_disk = DL_COPILOT_STATUS_DL_used_disk(buf);
184  copilot_status.status = DL_COPILOT_STATUS_DL_status(buf);
185  copilot_status.error_code = DL_COPILOT_STATUS_DL_error_code(buf);
186 
187  send_copilot_status = true;
188 
189  PPRZ_MUTEX_UNLOCK(copilot_status_mtx);
190 }
uint8_t used_disk
Definition: copilot.h:75
uint8_t used_mem
Definition: copilot.h:74
Periodic telemetry system header (includes downlink utility and generated code).
struct CameraSnapshot cam_snapshot
uint8_t snapshot_valid
Definition: copilot.h:67
float timestamp
Definition: copilot.h:56
float timestamp
Definition: copilot.h:73
#define PPRZ_MUTEX_LOCK(_mtx)
Definition: pprz_mutex.h:46
bool send_cam_snapshot
void copilot_periodic(void)
Periodic function.
uint8_t cam_state
Definition: copilot.h:65
PPRZ_MUTEX(copilot_cam_snapshot_mtx)
uint8_t error_code
Definition: copilot.h:60
bool send_copilot_status
void copilot_parse_cam_payload_dl(uint8_t *buf)
copy CAMERA_PAYLOAD message and mark it to be sent
void copilot_parse_copilot_status_dl(uint8_t *buf)
copy COPILOT_STATUS message and mark it to be sent
#define PPRZ_MUTEX_INIT(_mtx)
Definition: pprz_mutex.h:45
uint8_t used_mem
Definition: copilot.h:57
bool send_cam_payload
uint16_t cam_id
Definition: copilot.h:64
uint8_t status
Definition: copilot.h:76
void copilot_parse_cam_snapshot_dl(uint8_t *buf)
copy CAMERA_SNAPSHOT message and mark it to be sent
unsigned char uint8_t
Definition: types.h:14
Mission Computer module, interfacing the mission computer (also known as Copilot), based losely on ISaAC: The Intelligent Safety and Airworthiness Co-Pilot module Based on paper "A Payload Verification and Management Framework for Small UAV-based Personal Remote Sensing Systems" by Cal Coopmans and Chris Coffin.
struct CameraPayload cam_payload
float array_temp
Definition: copilot.h:69
void copilot_init(void)
Init function.
uint16_t snapshot_num
Definition: copilot.h:66
float lens_temp
Definition: copilot.h:68
uint8_t error_code
Definition: copilot.h:77
uint8_t used_disk
Definition: copilot.h:58
#define PPRZ_MUTEX_UNLOCK(_mtx)
Definition: pprz_mutex.h:47
uint8_t door_status
Definition: copilot.h:59
struct CopilotStatus copilot_status