mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-24 13:55:51 +08:00
[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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user