Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redefine Simulator::handle_message() prototype and create Simulator::set_publish() method. #11564

Merged
merged 3 commits into from
Mar 5, 2019

Conversation

mcsauder
Copy link
Contributor

@mcsauder mcsauder commented Feb 28, 2019

Describe problem solved by the proposed pull request
This PR redefines the Simulator::handle_message() prototype to match MavlinkReceiver::handle_message() and creates the Simulator::set_publish() method and associated _publish member variable to preserve functionality.

The work in this PR creates the path for additional refactoring of the Simulator::handle_message() started in #11499.

Please let me know if you have any questions about this PR. Thanks!

-Mark

@bkueng

@mcsauder mcsauder changed the title Redfine MavlinkReceiver::handle_message() prototype and create Simulator::set_publish() method. Redefine MavlinkReceiver::handle_message() prototype and create Simulator::set_publish() method. Feb 28, 2019
@mcsauder mcsauder changed the title Redefine MavlinkReceiver::handle_message() prototype and create Simulator::set_publish() method. Redefine Simulator::handle_message() prototype and create Simulator::set_publish() method. Feb 28, 2019
@mcsauder mcsauder force-pushed the simulator_mavlink_handle_methods branch from 7d355b4 to 8391f77 Compare February 28, 2019 20:57
@@ -838,14 +837,17 @@ void Simulator::poll_for_MAVLink_messages(bool publish)
for (int i = 0; i < len; ++i) {
if (mavlink_parse_char(MAVLINK_COMM_1, serial_buf[i], &msg, &serial_status)) {
// have a message, handle it
handle_message(&msg, true);
set_publish(true);
handle_message(&msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do it like this:

						bool prev_publish = _publish;
						_publish = true;
						handle_message(&msg);
						_publish = prev_publish;

Otherwise you're affecting and overriding the state for the next loop iteration.

Copy link
Contributor Author

@mcsauder mcsauder Mar 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bkueng ,
Changes requested are pushed up!

Otherwise you're affecting and overriding the state for the next loop iteration.

You are correct, that was intentional. The current logic in master cannot allow a persistent publish == true state to exist outside of one loop. The set_publish(false) call added at the end of the loop was a guard against that new possibility. With the latest commit that guard has been removed.

Let me know if you spot anything else I can address. Thanks for your feedback!

@mcsauder mcsauder force-pushed the simulator_mavlink_handle_methods branch 4 times, most recently from a584ed9 to ff82a7f Compare March 3, 2019 05:38
mcsauder added 2 commits March 3, 2019 22:16
… variable to allow redefinition of the Simulator::handle_message() prototype to match MavlinkReceiver::handle_message().
…)set each loop in simulator_mapvlink.cpp and provide a default argument to set_publish() in simulator.h.
@mcsauder mcsauder force-pushed the simulator_mavlink_handle_methods branch from ff82a7f to 79cab05 Compare March 4, 2019 05:16
void request_hil_state_quaternion();
void send();
void send_controls();
void send_heartbeat();
void send_mavlink_message(const mavlink_message_t &aMsg);
void set_publish(const bool publish = false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default is confusing to me: if I were to see a simulator->set_publish(), I would not expect it to disable publication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I can set it to default true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go?

Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go?

Yes

@bkueng bkueng merged commit a97151f into PX4:master Mar 5, 2019
@mcsauder
Copy link
Contributor Author

mcsauder commented Mar 5, 2019

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants