Skip to content

Add gRPC interface for board list watcher #1048

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

Merged
merged 1 commit into from
Nov 11, 2020

Conversation

silvanocerza
Copy link
Contributor

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce?

Add a gRPC interface for the board list watch command.

  • What is the current behavior?

gRPC consumers must poll the daemon to know which boards are connected or disconnected.

  • What is the new behavior?

gRPC consumers now receive an event whenever a board is connected or disconnected.

  • Does this PR introduce a breaking change?

No.

  • Other information:

None.


See how to contribute

@silvanocerza silvanocerza force-pushed the scerza/grpc-board-list-watcher branch from 0204a43 to ae0df34 Compare November 5, 2020 10:10
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

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

I made a few proposals. No hurry with the change, I continue with the integration based on what we have now as it also works.


message BoardListWatchResp {
// Event type as received from the serial discovery tool
string event_type = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe an enum could help instead of the current "add" and "remove" strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, didn't think about it.

// Information about the port
DetectedPort port = 2;
// Eventual errors when detecting connected boards
string error = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not a proto expert and I hope @cmaglie can help, but I would have expected to have something like:

message BoardListWatchResp {
  oneof content {
    DetectedChange change = 1;
    string error = 2;
  }
}

message DetectedChange {
  enum ChangeType { ADDED = 0; REMOVED = 0; }
  ChangeType type = 1;
  DetectedPort port = 2;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither am I and that's why didn't about this approach, I like it though.

Copy link
Member

Choose a reason for hiding this comment

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

I'm positive to move the pair (ChangeType, DetectedPort) into their own separate message.
I would change the naming, since we are now talking about Ports IMHO it should be:

message BoardListWatchResp {
  oneof content {
    DetectedPortEvent event = 1;
    string error = 2;
  }
}

message DetectedPortEvent {
  enum Event { ADDED = 0; REMOVED = 0; }
  Event action = 1;
  DetectedPort port = 2;
}

(and at this point also we should probably go all-in and call it Port instead of DetectedPort, this is something that we must face once Pluggable Discovery is merged...)

I'm not sure about the oneof, there are other places where it may be useful to make the API more explicit, anyway when I tried it, IIRC, the generated API turned out to be very messy especially in languages without sum types like go, java, c++ where accessors (boilerplate) methods are added to handle it correctly. Let's evaluate if the pro (a cleaner proto API) is more valuable than the cons (a bigger "cognitive" load in the implementation).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your recommendations, @cmaglie. As I said, I am fine with this API now. It's your call whether you want to make the changes now or later.

@kittaakos
Copy link
Contributor

I have a couple of questions regarding the behavior;

  1. When I attach a board, I receive a response with event-type add. This response has the port (with address and protocol) and an array of boards (can be empty, for sure) but it is usually one. However, when I attach my Portenta board, I see one port with three boards. What does it mean domain-wise?
{
  "type": "add",
  "address": "/dev/cu.usbmodem14101",
  "protocol": "serial",
  "protocol_label": "Serial Port (USB)",
  "boards": [
    {
      "name": "Arduino Portenta H7 (M7 core)",
      "FQBN": "arduino-beta-development:mbed:envie_m7"
    },
    {
      "name": "Arduino Portenta H7 (ThreadDebug)",
      "FQBN": "arduino-beta-development:mbed:envie_m7_thread_debug"
    },
    {
      "name": "Arduino Portenta H7 (M7 core)",
      "FQBN": "arduino-beta:mbed:envie_m7"
    }
  ]
}
  1. When I detach a board, I receive a response with even_type remove and it has only the address of the port.
{
  "type": "remove",
  "address": "/dev/cu.usbmodem14101"
}

Does it mean that consumers of the gRPC API should move away from a board-driven approach, and track ports instead? In other words, from now on boards are always kind of an additional "meta" information of the detected port, and the ports are the first-class citizens of the CLI.

Thank you!

@silvanocerza
Copy link
Contributor Author

You see 3 boards because by searching in the locally installed platforms we find mutiple matches for the VID/PID combination probably.

If it's better for you I could change the message sent so that the list of possible connected boards to that port is included, I'd have to keep track of them in the CLI though.

@silvanocerza silvanocerza merged commit 27381c5 into master Nov 11, 2020
@silvanocerza silvanocerza deleted the scerza/grpc-board-list-watcher branch November 11, 2020 16:26
@silvanocerza
Copy link
Contributor Author

Suggested changes to the gRPC interface will be made in a future PR, this is good enough for now.

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