Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
board.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 The Paparazzi Team
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include "mcu.h"
33 
36 
37 /* Check if the bat_voltage_ardrone2 module is loaded */
38 #include "generated/modules.h"
39 #ifndef BAT_VOLTAGE_ARDRONE2_PERIODIC_FREQ
40 #warning No battery voltage measurement available! Please add <load name="bat_voltage_ardrone2.xml"/> to your modules section in aircraft file.
41 #endif
42 
44  .output_size = {
45  .w = 1280,
46  .h = 720
47  },
48  .sensor_size = {
49  .w = 1280,
50  .h = 720
51  },
52  .crop = {
53  .x = 0,
54  .y = 0,
55  .w = 1280,
56  .h = 720
57  },
58  .dev_name = "/dev/video1",
59  .subdev_name = NULL,
60  .format = V4L2_PIX_FMT_UYVY,
61  .buf_cnt = 10,
62  .filters = 0,
63  .cv_listener=NULL,
64  .fps = 0
65 };
66 
67 
69  .output_size = {
70  .w = 320,
71  .h = 240
72  },
73  .sensor_size = {
74  .w = 320,
75  .h = 240
76  },
77  .crop = {
78  .x = 0,
79  .y = 0,
80  .w = 320,
81  .h = 240
82  },
83  .dev_name = "/dev/video2",
84  .subdev_name = NULL,
85  .format = V4L2_PIX_FMT_UYVY,
86  .buf_cnt = 10,
87  .filters = 0,
88  .cv_listener=NULL,
89  .fps = 0
90 };
91 
92 int KillGracefully(char *process_name);
93 
94 int KillGracefully(char *process_name)
95 {
96  /* "pidof" always in /bin on ARdrone2, no need for "which" */
97  char pidof_commandline[200] = "/bin/pidof -s ";
98  strcat(pidof_commandline, process_name);
99  /* ARDrone2 Busybox a
100  $ cat /proc/sys/kernel/pid_max
101  Gives max 32768, makes sure it never kills existing other process
102  */
103  char pid[7] = "";
104  int ret = 0; /* Return code of kill system call */
105  FILE *fp;
106 
107  while (ret == 0) {
108  fp = popen(pidof_commandline, "r");
109  if (fp != NULL) { /* Could open the pidof with line */
110  if (fgets(pid, sizeof(pid) - 1, fp) != NULL) {
111  printf("Process ID deducted: \"%s\"\n", pid);
112  if (atoi(pid) > 0) { /* To make sure we end 0 > There is a real process id found */
113  char kill_command_and_process[200] = "kill -9 "; /* BTW there is no pkill on this Busybox */
114  strcat(kill_command_and_process, pid);
115  ret = system(kill_command_and_process);
116  /* No need to wait, since if it is not closed the next pidof scan still will still find it and try to kill it */
117  }
118  } else {
119  ret = 256; /* Could not get handle */
120  pclose(fp);
121  }
122  } else {
123  ret = 256; /* fp NULL, so no process, just return */
124  return 0;
125  }
126  } /* end while */
127  return 0;
128 }
129 
130 void board_init(void)
131 {
132  /* Two process to kill, the respawner first to make sure program.elf does not get restarted */
133  int ret = system("killall -15 program.elf.respawner.sh");
134  usleep(50000); /* Give respawner 50ms time to end on a busy system */
135  KillGracefully("program.elf");
136  (void) ret;
137 }
struct img_size_t output_size
Output image size.
Definition: video_device.h:45
Capture images from a V4L2 device (Video for Linux 2)
int KillGracefully(char *process_name)
Definition: board.c:94
void board_init(void)
Optional board init function called at the start of mcu_init().
Definition: board.c:130
Arch independent mcu ( Micro Controller Unit ) utilities.
struct video_config_t bottom_camera
Definition: board.c:68
struct video_config_t front_camera
Definition: board.c:43
uint16_t w
The width.
Definition: image.h:69
V4L2 device settings.
Definition: video_device.h:44