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

Serial connection support for Windows #375

Merged
merged 9 commits into from
May 2, 2018
Merged

Serial connection support for Windows #375

merged 9 commits into from
May 2, 2018

Conversation

julianoes
Copy link
Collaborator

@julianoes julianoes commented Apr 29, 2018

This adds support for serial connections on Windows.

Todos:

  • make it work on Windows.
  • remove comments that this is not supported.
  • fix add_any_connection to work on Windows.

This is mainly used to parse the URI inputs such as:
- serial:///dev/ttyS0
- serial://COM3
- udp://0.0.0.0:14540
This should not change the DroneCore interface, however it makes it
possible use UDP connections on other local interfaces than 0.0.0.0.

Also, this gets rid of the default for serial connections because these
tend to be different on every system.
@julianoes julianoes changed the title [WIP] Serial connection support for Windows Serial connection support for Windows Apr 30, 2018
core/dronecore.h Outdated
ConnectionResult add_any_connection(const std::string &connection_url);

/**
* @brief Adds a UDP connection to the specified port number on 0.0.0.0 on any local interface.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does "any local interface" mean any network? (ie I am wondering what this means as opposed to if you did not have this text)

Copy link
Collaborator

Choose a reason for hiding this comment

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

"0.0.0.0" does means "listen on any interface". So "on any local interface" here does not add information, but explicits what "0.0.0.0" means.

Here it is from Wikipedia:

In the context of servers, 0.0.0.0 can mean "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses.

core/dronecore.h Outdated
*
* @param local_port_number The local UDP port to listen to (defaults to 14540, the same as mavros).
* To accept only connections local connections of the machine, use 127.0.0.1, for any
Copy link
Collaborator

Choose a reason for hiding this comment

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

"127.0.0.1, for any" - make that comma into a full stop and split into 2 sentences.

core/dronecore.h Outdated
* incoming connections, use 0.0.0.0.
*
* @param local_bind_ip The local UDP ip to listen to.
* @param local_port The local UDP port to listen to (defaults to 14540, the same as mavros).
Copy link
Collaborator

Choose a reason for hiding this comment

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

mavros is the package name, MAVROS is the product name. I would say this is an instance of MAVROS.

@@ -50,6 +43,18 @@ class NullStream

namespace dronecore {

enum class Color {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is all much nicer :-)

Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

LGTM. I don't really understand the new #if defined(WINDOWS) part in core/serial_connection.cpp, but anyway I don't really understand how it works for the other platforms, so I cannot really comment on that part :-).

core/dronecore.h Outdated
ConnectionResult add_any_connection(const std::string &connection_url);

/**
* @brief Adds a UDP connection to the specified port number on 0.0.0.0 on any local interface.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"0.0.0.0" does means "listen on any interface". So "on any local interface" here does not add information, but explicits what "0.0.0.0" means.

Here it is from Wikipedia:

In the context of servers, 0.0.0.0 can mean "all IPv4 addresses on the local machine". If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses.

@julianoes
Copy link
Collaborator Author

Thanks @hamishwillee, I went through your comments and tried to fix them.

@julianoes julianoes merged commit 3459479 into develop May 2, 2018
@julianoes julianoes deleted the windows-serial branch May 2, 2018 18:54
* - Default Bind host IP is localhost(127.0.0.1)
*
* @warning Serial connections are not supported on Windows (they are supported on Linux and macOS).
* Default URL : udp://0.0.0.0:14540.
Copy link
Collaborator

@hamishwillee hamishwillee May 2, 2018

Choose a reason for hiding this comment

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

@julianoes The new interface must take a connection_url string so presumably this is no longer a default value!

Why have we chosen to not have a default anymore? Even if we choose not to have a default in the interface, why not default in the examples - passed through as argument?

If this stays the same, in addition to this update, we will need to change the usage instructions in the examples that use this method (since they also refer to default).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, the host is not a must, see:

- TCP - tcp://[Remote_host][:Remote_port]
- Serial - serial://[Dev_Node][:Baudrate]
- Serial - serial://Dev_Node[:Baudrate]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, still confused. The prototype is this:

 ConnectionResult add_any_connection(const std::string &connection_url);

There is no default value specified there for connection_url (e.g. it isn't like:)

 ConnectionResult add_any_connection(const std::string &connection_url=SOME_DEFAULT);

so AFAIK in C++ to call this method you must specify a value for the URL right?. So how can there be a default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, you're right. There is no default. You need to specify it, and that shouild usually be done using a command line argument I suggest.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@julianoes Before I do that, this is now inconsistent - the other methods (e.g. for adding UDP) do have defaults. Can you either add the default back OR remote all the other defaults?

@@ -23,11 +23,10 @@ class System;
class DroneCore
{
public:
static constexpr auto DEFAULT_UDP_CONNECTION_URL = "udp://:14540";
static constexpr auto DEFAULT_UDP_BIND_IP = "0.0.0.0";
Copy link
Collaborator

Choose a reason for hiding this comment

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

@julianoes These should have doc strings (ideally)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, I'll add it next time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cheers. I mean "all of them should"

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.

3 participants