diff --git a/conf/airframes/ENAC/quadrotor/ard2_base_digit.xml b/conf/airframes/ENAC/quadrotor/ard2_base_digit.xml
index e948a401df..8ab5c8f96c 100644
--- a/conf/airframes/ENAC/quadrotor/ard2_base_digit.xml
+++ b/conf/airframes/ENAC/quadrotor/ard2_base_digit.xml
@@ -36,7 +36,9 @@
-
+
+
+
diff --git a/conf/modules/image_nc_send.xml b/conf/modules/image_nc_send.xml
deleted file mode 100644
index 9f031137a0..0000000000
--- a/conf/modules/image_nc_send.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
-
- Download Images from ARDone 2 with netcat
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/conf/modules/video_rtp_stream.xml b/conf/modules/video_rtp_stream.xml
index 989a33ca2f..cc82f6f202 100644
--- a/conf/modules/video_rtp_stream.xml
+++ b/conf/modules/video_rtp_stream.xml
@@ -49,16 +49,19 @@
VIEWVIDEO_BROADCAST ?= $(MODEM_BROADCAST)
VIEWVIDEO_DEV_LOWER = $(shell echo $(VIEWVIDEO_DEV) | tr A-Z a-z)
- STREAM_CFLAGS = -DUSE_$(VIEWVIDEO_DEV) -DVIEWVIDEO_DEV=$(VIEWVIDEO_DEV_LOWER) -DVIEWVIDEO_PORT_OUT=$(VIEWVIDEO_PORT_OUT)
- STREAM_CFLAGS += -D$(VIEWVIDEO_DEV)_PORT_OUT=$(VIEWVIDEO_PORT_OUT) -D$(VIEWVIDEO_DEV)_PORT_IN=$(VIEWVIDEO_PORT_IN)
- STREAM_CFLAGS += -D$(VIEWVIDEO_DEV)_BROADCAST=$(VIEWVIDEO_BROADCAST) -D$(VIEWVIDEO_DEV)_HOST=\"$(VIEWVIDEO_HOST)\"
- ap.CFLAGS += $(STREAM_CFLAGS)
+ VIEWVID_G_CFLAGS = -DVIEWVIDEO_HOST=\"$(VIEWVIDEO_HOST)\" -DVIEWVIDEO_PORT_OUT=$(VIEWVIDEO_PORT_OUT)
+ VIEWVID_CFLAGS = -DUSE_$(VIEWVIDEO_DEV) -DVIEWVIDEO_DEV=$(VIEWVIDEO_DEV_LOWER)
+ VIEWVID_CFLAGS += -D$(VIEWVIDEO_DEV)_PORT_OUT=$(VIEWVIDEO_PORT_OUT) -D$(VIEWVIDEO_DEV)_PORT_IN=$(VIEWVIDEO_PORT_IN)
+ VIEWVID_CFLAGS += -D$(VIEWVIDEO_DEV)_BROADCAST=$(VIEWVIDEO_BROADCAST) -D$(VIEWVIDEO_DEV)_HOST=\"$(VIEWVIDEO_HOST)\"
+ ifeq ($(VIEWVIDEO_USE_NC),)
+ ap.CFLAGS += $(VIEWVID_G_CFLAGS) $(VIEWVID_CFLAGS)
+ else
+ ap.CFLAGS += $(VIEWVID_G_CFLAGS) -DVIEWVIDEO_USE_NC
+ endif
-
-
diff --git a/sw/airborne/modules/computer_vision/image_nc_send.c b/sw/airborne/modules/computer_vision/image_nc_send.c
deleted file mode 100644
index 3c90244778..0000000000
--- a/sw/airborne/modules/computer_vision/image_nc_send.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (C) 2014 Gautier Hattenberger
- *
- * This file is part of Paparazzi.
- *
- * Paparazzi is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * Paparazzi is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with paparazzi; see the file COPYING. If not, see
- * .
- *
- */
-
-/**
- * @file modules/computer_vision/image_nc_send.c
- *
- * Capture an image on an ARDrone2 and send it to the ground with netcat (nc)
- */
-
-// Own header
-#include "modules/computer_vision/image_nc_send.h"
-
-#include
-#include
-#include
-#include
-#include
-
-// Video
-#include "modules/computer_vision/lib/v4l/v4l2.h"
-#include "modules/computer_vision/cv/resize.h"
-#include "modules/computer_vision/cv/encoding/jpeg.h"
-
-// Threaded computer vision
-#include
-
-// Default netcat server IP (destination)
-#ifndef IMAGE_SERVER_IP
-#define IMAGE_SERVER_IP "192.168.1.2"
-#endif
-
-// Default netcat port
-#ifndef IMAGE_SERVER_PORT
-#define IMAGE_SERVER_PORT 4900
-#endif
-
-// Default downsize factor
-#ifndef IMAGE_DOWNSIZE_FACTOR
-#define IMAGE_DOWNSIZE_FACTOR 1
-#endif
-
-// JPEG compression quality factor from 0 to 99 (99=high)
-#ifndef IMAGE_QUALITY_FACTOR
-#define IMAGE_QUALITY_FACTOR 99
-#endif
-
-// Frame Per Second
-#ifndef IMAGE_FPS
-#define IMAGE_FPS (1./6.)
-#endif
-
-// Save images by default
-#ifndef IMAGE_SAVE
-#define IMAGE_SAVE 1
-#endif
-
-void image_nc_send_run(void) {}
-
-
-/////////////////////////////////////////////////////////////////////////
-// COMPUTER VISION THREAD
-
-pthread_t computervision_thread;
-volatile uint8_t computervision_thread_status = 0;
-volatile uint8_t computer_vision_thread_command = 0;
-void *computervision_thread_main(void *data);
-void *computervision_thread_main(void *data)
-{
- // Create a V4L2 device
-#if USE_BOTTOM_CAMERA
- struct v4l2_device *dev = v4l2_init("/dev/video2", 320, 240, 10);
-#else
- struct v4l2_device *dev = v4l2_init("/dev/video1", 1280, 720, 4);
-#endif
- if (dev == NULL) {
- printf("Error initialising video\n");
- return 0;
- }
-
-
- // Start the streaming on the V4L2 device
- if(!v4l2_start_capture(dev)) {
- printf("Could not start capture\n");
- return 0;
- }
-
-
- // Frame Resizing
- uint8_t quality_factor = IMAGE_QUALITY_FACTOR;
- uint8_t dri_jpeg_header = 1;
-
- struct img_struct small;
- small.w = dev->w / IMAGE_DOWNSIZE_FACTOR;
- small.h = dev->h / IMAGE_DOWNSIZE_FACTOR;
- small.buf = (uint8_t *)malloc(small.w * small.h * 2);
-
- // Commpressed image buffer
- uint8_t *jpegbuf = (uint8_t *)malloc(dev->h * dev->w * 2);
-
- // file index (search from 0)
- int file_index = 0;
-
- int microsleep = (int)(1000000. / IMAGE_FPS);
-
- while (computer_vision_thread_command > 0) {
- usleep(microsleep);
- // Wait for a new frame
- struct v4l2_img_buf *img = v4l2_image_get(dev);
- struct img_struct input;
- input.buf = img->buf;
- input.w = dev->w;
- input.h = dev->h;
-
- // Resize
- resize_uyuv(&input, &small, IMAGE_DOWNSIZE_FACTOR);
-
- // Free the image
- v4l2_image_free(dev, img);
-
- // JPEG encode the image:
- uint32_t image_format = FOUR_TWO_TWO; // format (in jpeg.h)
- uint8_t *end = encode_image(small.buf, jpegbuf, quality_factor, image_format, small.w, small.h, dri_jpeg_header);
- uint32_t size = end - (jpegbuf);
-
-#if IMAGE_SAVE
- FILE *save;
- char save_name[128];
- if (system("mkdir -p /data/video/images") == 0) {
- // search available index (max is 99)
- for (; file_index < 99; file_index++) {
- printf("search %d\n", file_index);
- sprintf(save_name, "/data/video/images/img_%02d.jpg", file_index);
- // test if file exists or not
- if (access(save_name, F_OK) == -1) {
- printf("access\n");
- save = fopen(save_name, "w");
- if (save != NULL) {
- fwrite(jpegbuf, sizeof(uint8_t), size, save);
- fclose(save);
- } else {
- printf("Error when opening file %s\n", save_name);
- }
- // leave for loop
- break;
- } else {printf("file exists\n");}
- }
- }
-#endif
-
- // Fork process
- int status;
- pid_t pid = fork();
-
- if (pid == 0) {
- // Open process to send using netcat in child process
- char nc_cmd[64];
- sprintf(nc_cmd, "nc %s %d", IMAGE_SERVER_IP, IMAGE_SERVER_PORT);
- FILE *netcat;
- netcat = popen(nc_cmd, "w");
- if (netcat != NULL) {
- fwrite(jpegbuf, sizeof(uint8_t), size, netcat);
- if (pclose(netcat) == 0) {
- printf("Sending image succesfully\n");
- }
- } else {
- printf("Fail sending image\n");
- }
- exit(0);
- } else if (pid < 0) {
- printf("Fork failed\n");
- } else {
- // Parent is waiting for child to terminate
- wait(&status);
- }
-
- }
- printf("Thread Closed\n");
- v4l2_close(dev);
- computervision_thread_status = -100;
- return 0;
-}
-
-void image_nc_send_start(void)
-{
- computer_vision_thread_command = 1;
- int rc = pthread_create(&computervision_thread, NULL, computervision_thread_main, NULL);
- if (rc) {
- printf("ctl_Init: Return code from pthread_create(mot_thread) is %d\n", rc);
- }
-}
-
-void image_nc_send_stop(void)
-{
- computer_vision_thread_command = 0;
-}
-
diff --git a/sw/airborne/modules/computer_vision/image_nc_send.h b/sw/airborne/modules/computer_vision/image_nc_send.h
deleted file mode 100644
index c7bab94da6..0000000000
--- a/sw/airborne/modules/computer_vision/image_nc_send.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2014 Gautier Hattenberger
- *
- * This file is part of Paparazzi.
- *
- * Paparazzi is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * Paparazzi is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with paparazzi; see the file COPYING. If not, see
- * .
- *
- */
-
-/**
- * @file modules/computer_vision/image_nc_send.h
- *
- * Capture an image on an ARDrone2 and send it to the ground with netcat (nc)
- */
-
-#ifndef IMAGE_NC_SEND_H
-#define IMAGE_NC_SEND_H
-
-// Module functions
-extern void image_nc_send_run(void);
-extern void image_nc_send_start(void);
-extern void image_nc_send_stop(void);
-
-#endif /* IMAGE_NC_SEND_H */
-
diff --git a/sw/airborne/modules/computer_vision/image_nc_send_nps.c b/sw/airborne/modules/computer_vision/image_nc_send_nps.c
deleted file mode 100644
index f2ca1ff16b..0000000000
--- a/sw/airborne/modules/computer_vision/image_nc_send_nps.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2014 Gautier Hattenberger
- *
- * This file is part of Paparazzi.
- *
- * Paparazzi is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * Paparazzi is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Paparazzi; see the file COPYING. If not, write to
- * the Free Software Foundation, 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-
-// Own header
-#include "image_capture.h"
-
-void image_capture_run(void) {}
-
-void image_capture_start(void) {}
-
-void image_capture_stop(void) {}
-
diff --git a/sw/airborne/modules/computer_vision/viewvideo.c b/sw/airborne/modules/computer_vision/viewvideo.c
index 8c662217a2..d802f53032 100644
--- a/sw/airborne/modules/computer_vision/viewvideo.c
+++ b/sw/airborne/modules/computer_vision/viewvideo.c
@@ -93,8 +93,16 @@ PRINT_CONFIG_VAR(VIEWVIDEO_FPS);
#endif
PRINT_CONFIG_VAR(VIEWVIDEO_SHOT_PATH);
-/* These are defined with configure */
+// Check if we are using netcat instead of RTP/UDP
+#ifdef VIEWVIDEO_NC_IP
+PRINT_CONFIG_MSG("[viewvideo] Using netcat.");
+#else
+PRINT_CONFIG_MSG("[viewvideo] Using RTP/UDP stream.");
PRINT_CONFIG_VAR(VIEWVIDEO_DEV);
+#endif
+
+/* These are defined with configure */
+PRINT_CONFIG_VAR(VIEWVIDEO_HOST);
PRINT_CONFIG_VAR(VIEWVIDEO_PORT_OUT);
// Main thread
@@ -202,6 +210,20 @@ static void *viewvideo_thread(void *data __attribute__((unused)))
uint8_t *end = jpeg_encode_image(small.buf, jpegbuf, VIEWVIDEO_QUALITY_FACTOR, FOUR_TWO_TWO, small.w, small.h, FALSE);
uint32_t size = end - (jpegbuf);
+#ifdef VIEWVIDEO_USE_NC
+ // Open process to send using netcat
+ char nc_cmd[64];
+ sprintf(nc_cmd, "nc %s %d", VIEWVIDEO_HOST, VIEWVIDEO_PORT_OUT);
+ FILE *netcat = popen(nc_cmd, "w");
+ if (netcat != NULL) {
+ fwrite(jpegbuf, sizeof(uint8_t), size, netcat);
+ if (pclose(netcat) != 0) {
+ printf("[viewvideo] Sending image trough netcat failed.\n");
+ }
+ } else {
+ printf("[viewvideo] Failed to open netcat process.\n");
+ }
+#else
// Send image with RTP
rtp_frame_send(
&VIEWVIDEO_DEV, // UDP device
@@ -220,6 +242,7 @@ static void *viewvideo_thread(void *data __attribute__((unused)))
// the timestamp is always "late" so the frame is displayed immediately).
// Here, we set the time increment to the lowest possible value
// (1 = 1/90000 s) which is probably stupid but is actually working.
+#endif
// Free the image
v4l2_image_free(viewvideo.dev, img);