Skip to content

gRPC interface to monitors #286

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 9 commits into from
Jul 29, 2019
Merged

gRPC interface to monitors #286

merged 9 commits into from
Jul 29, 2019

Conversation

masci
Copy link
Contributor

@masci masci commented Jul 17, 2019

What

This PR adds a bidirectional stream implementing a serial monitor through gRPC

How

The concept of Monitor is introduced in the arduino package. A Monitor is an interface capable of reading a writing to a certain "target":

type Monitor interface {
	Close() error
	Read(bytes []byte) (int, error)
	Write(bytes []byte) (int, error)
}

A Monitor is used by a new gRPC service, different from the one exposing the cli commands, to let users pass a stream object that can be used to read/write from/to the monitor at the same time (bidirectional stream):

service Monitor {
  rpc StreamingOpen(stream StreamingOpenReq)
      returns (stream StreamingOpenResp) {}
}

In order to initialize a Monitor target (think about opening a serial port, or connecting to a socket) the first message of the stream must contain a special message containing the type of the target (for now only SERIAL), a string containing the target name, and a special field called additionalConfig that implements a JSON-like generic object, to be used to pass configuration options that are peculiar for specific targets:

message MonitorConfig {
  enum TargetType { SERIAL = 0; }

  string target = 1;
  TargetType type = 2;
  google.protobuf.Struct additionalConfig = 3;
}

Subsequent message will just contain data in the form of an array of bytes. Messages sent back from the Monitor will be similar, just containing data:

message StreamingOpenResp {
    bytes data = 1;
} 

Serial monitor

This PR also includes a concrete implementation of the Monitor interface, specific to talk with a serial port:

// SerialMonitor is a monitor for serial ports
type SerialMonitor struct {
	port serial.Port
}

Upon receiving the first message, a serial port will be opened according to the configuration parameters, and 2 goroutines will be started to interact with the gRPC stream and the serial port respectively. The serial port will be gracefully closed in case the stream is closed from the client side.

Example

To test a server started out of this branch you can use a sketch and client programs from https://gist.github.com/masci/804ba2679c8598630ca05919713ab106

TODO

  • Add tests where possible
  • Double check for race conditions

@masci masci force-pushed the massi/rpc-monitor branch from 46c5267 to e312a15 Compare July 17, 2019 14:43
@masci
Copy link
Contributor Author

masci commented Jul 17, 2019

Tests are failing because of a missing dep on the Docker image we use in the CI, fixing in a separate PR.

Copy link
Contributor

@rsora rsora left a comment

Choose a reason for hiding this comment

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

Super clean implementation, I like it a lot.
Tested successfully with the provided gist.

@masci masci force-pushed the massi/rpc-monitor branch from 6d7e0cc to f43897f Compare July 25, 2019 09:09
@rsora rsora self-requested a review July 26, 2019 15:38
Copy link
Contributor

@rsora rsora left a comment

Choose a reason for hiding this comment

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

Serial monitor test checked: LGTM

@masci masci merged commit a6fdfea into master Jul 29, 2019
@masci masci deleted the massi/rpc-monitor branch July 29, 2019 10:35
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