Skip to content

Commit

Permalink
rtps: Exit when receive shutdown command
Browse files Browse the repository at this point in the history
As uORB shutdown command is low prio, if rtps keeps running, it risks
not ever allowing shutdown command to run - for instance, if it keeps
receiving messages.

This was the reason why it was necessary a flush and sleep right after
RTPS shutdown command was sent by Tools/px_uploader. With rtps side
fixed, no need for this hack anymore.
  • Loading branch information
edersondisouza committed May 10, 2017
1 parent 3fd8e50 commit 046b0c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Tools/px_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,9 @@ def send_reboot(self):
print("If the board does not respond, unplug and re-plug the USB connector.", file=sys.stderr)

try:
# try MAVLINK command first
# try RTPS and MAVLINK command first
self.port.flush()
self.__send(uploader.RTPS_REBOOT0)
self.port.flush()
time.sleep(0.5)
self.__send(uploader.MAVLINK_REBOOT_ID1)
self.__send(uploader.MAVLINK_REBOOT_ID0)
# then try reboot via NSH
Expand Down
10 changes: 8 additions & 2 deletions src/examples/rtps/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void handle_vehicle_command(struct reader_data *reader_data, char *buffer);
extern "C" __EXPORT int rtps_main(int argc, char *argv[]);

static int _started = 0;
static bool _should_exit_task = false;

struct reader_data {
UART_node &uart_node;
Expand All @@ -41,6 +42,11 @@ void handle_vehicle_command(struct reader_data *reader_data, char *buffer)
struct vehicle_command_s vehicle_command_data;

deserialize_vehicle_command(&vehicle_command_data, buffer);

if (vehicle_command_data.command == vehicle_command_s::VEHICLE_CMD_PREFLIGHT_REBOOT_SHUTDOWN) {
_should_exit_task = true;
}

orb_publish(ORB_ID(vehicle_command), reader_data->vehicle_command_pub, &vehicle_command_data);
}

Expand All @@ -55,7 +61,7 @@ void *uart_reader_thread(void *data)
uint8_t len;

char topic_ID = 255;
while (true) {
while (!_should_exit_task) {
if (poll(&fds[0], 1, 1000) > 0) {
uint8_t seq;
if ((len = reader_data->uart_node.readFromUART(&topic_ID, &seq, buffer)) != 0) {
Expand Down Expand Up @@ -157,7 +163,7 @@ int _rtps_main(int argc, char *argv[])

/* Sender loop */
_started++;
for (;;)
while (!_should_exit_task)
{
bool updated;

Expand Down

0 comments on commit 046b0c9

Please sign in to comment.