[linux] handle SIGINT by hand if needed, useful for debug

type Ctrl-C two to stop the program launched from the console on
ardrone2 and bebop

close #1008
This commit is contained in:
Gautier Hattenberger
2014-12-18 10:55:10 +01:00
parent 7b83653df1
commit 7fcb4357a4
3 changed files with 48 additions and 0 deletions
+3
View File
@@ -43,6 +43,9 @@ $(TARGET).CFLAGS += -DUART1_DEV=\"/dev/ttyUSB0\"
# for distinction between RAW and SDK version
$(TARGET).CFLAGS +=-DARDRONE2_RAW
# handle linux signals by hand
$(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL
# -----------------------------------------------------------------------
# default LED configuration
+3
View File
@@ -29,6 +29,9 @@ GPS_PORT ?= UART1
GPS_BAUD ?= B230400
$(TARGET).CFLAGS += -DUART1_DEV=\"/dev/ttyPA1\"
# handle linux signals by hand
$(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL
# -----------------------------------------------------------------------
# default LED configuration
+42
View File
@@ -29,4 +29,46 @@
#include "mcu_arch.h"
#if USE_LINUX_SIGNAL
/**
* Handle linux signals by hand if the program is not launch
* by a shell already doing it
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
/**
* catch SIGINT signal two times to stop the main program
*/
static void sig_handler(int signo)
{
static int nb_signal = 0;
if (signo == SIGINT) {
printf("Received SIGINT\n");
if (nb_signal == 0) {
printf("Press Ctrl-C again to stop the program\n");
nb_signal++;
} else {
printf("Leaving now\n");
exit(0);
}
}
}
void mcu_arch_init(void)
{
if (signal(SIGINT, sig_handler) == SIG_ERR) {
printf("Can't catch SIGINT\n");
}
}
#else
void mcu_arch_init(void) { }
#endif