Skip to content

Commit

Permalink
[linux] handle SIGINT by hand if needed, useful for debug
Browse files Browse the repository at this point in the history
type Ctrl-C two to stop the program launched from the console on
ardrone2 and bebop

close #1008
  • Loading branch information
gautierhattenberger committed Dec 18, 2014
1 parent 7b83653 commit 7fcb435
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions conf/boards/ardrone2_raw.makefile
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions conf/boards/bebop.makefile
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions sw/airborne/arch/linux/mcu_arch.c
Expand Up @@ -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

0 comments on commit 7fcb435

Please sign in to comment.