Commit 980ef957 authored by Léo Coquet's avatar Léo Coquet
Browse files

Added signal detection

parent 68004f5c
......@@ -267,7 +267,36 @@ drone1.command_setMode(DRONE_OFF);
// drone1.get()->write_message(message);
// }
/**
* @fn void signalHandler(int number)
* @brief Handles received signals. Triggered when a signal is received.
*
* @param number The signal code.
**/
void signalHandler(int number)
{
switch(number)
{
case SIGINT :
printf("SIGINT caught\n"); //CTRL+C
//TODO handle SIGINT reception situation
break;
case SIGTERM :
printf("SIGTERM caught\n"); //kill (term command)
//TODO handle SIGTERM reception situation
break;
case SIGFPE :
printf("SIGFPE caught\n"); //Floating-Point arithmetic Exception
//TODO handle SIGFPE reception situation
exit(0); //to prevent infinite loop
break;
default :
printf("Signal number : %d caught\n", number);
}
}
/**
* Only the main exe of the programm
......@@ -278,8 +307,18 @@ int main(int argc, char *argv[])
// General var
// bool flag_run = true; //Flag use for the main loop of the system
struct sigaction action;
if(argc>1) {strcpy(device_path ,argv[1]); printf("port = %s \n",device_path);}
//signal handler initialisation
sigfillset(&action.sa_mask);
action.sa_handler = signalHandler;
action.sa_flags = 0;
//Make the list of all SIG to catch (will not be caught if not listed here, the list is not definitive and all are not necessarily usefull)
if(sigaction(SIGINT, &action, NULL) != 0) printf("SIGINT couldn't be attached\n"); //ctrl+C
if(sigaction(SIGTERM, &action, NULL) != 0) printf("SIGTERM couldn't be attached\n"); //kill [PID]
if(sigaction(SIGFPE, &action, NULL) != 0) printf("SIGFPE couldn't be attached\n"); //integer divided by 0
drone1.open(device_path, device_baudrate);
string buffer1="";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment