Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Philippe Gaussier
Drone FlyMonitor2
Commits
980ef957
Commit
980ef957
authored
Sep 15, 2021
by
Léo Coquet
Browse files
Added signal detection
parent
68004f5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Com_server/test/TestDroneRemoteControl.cpp
View file @
980ef957
...
...
@@ -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
=
""
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment