Skip to content

Commit 9d079c1

Browse files
authored
Merge pull request #6 from arduino/protocol_v1
Implement Pluggable Discovery protocol v1
2 parents d21bd88 + 497dea0 commit 9d079c1

File tree

6 files changed

+226
-111
lines changed

6 files changed

+226
-111
lines changed

README.md

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,35 @@ Install a recent go enviroment (>=13.0) and run `go build`. The executable `seri
88

99
## Usage
1010

11-
After startup, the tool waits for commands. The available commands are: `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`.
11+
After startup, the tool waits for commands. The available commands are: `HELLO`, `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`.
12+
13+
#### HELLO command
14+
15+
The `HELLO` command is used to establish the pluggable discovery protocol between client and discovery.
16+
The format of the command is:
17+
18+
`HELLO <PROTOCOL_VERSION> "<USER_AGENT>"`
19+
20+
for example:
21+
22+
`HELLO 1 "Arduino IDE"`
23+
24+
or:
25+
26+
`HELLO 1 "arduino-cli"`
27+
28+
in this case the protocol version requested by the client is `1` (at the moment of writing there were no other revisions of the protocol).
29+
The response to the command is:
30+
31+
```json
32+
{
33+
"eventType": "hello",
34+
"protocolVersion": 1,
35+
"message": "OK"
36+
}
37+
```
38+
39+
`protocolVersion` is the protocol version that the discovery is going to use in the remainder of the communication.
1240

1341
#### START command
1442

@@ -56,14 +84,10 @@ The `LIST` command returns a list of the currently available serial ports. The f
5684
{
5785
"address": "/dev/ttyACM0",
5886
"label": "/dev/ttyACM0",
59-
"prefs": {
60-
"productId": "0x804e",
61-
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
62-
"vendorId": "0x2341"
63-
},
64-
"identificationPrefs": {
87+
"properties": {
6588
"pid": "0x804e",
66-
"vid": "0x2341"
89+
"vid": "0x2341",
90+
"serialNumber": "EBEABFD6514D32364E202020FF10181E"
6791
},
6892
"protocol": "serial",
6993
"protocolLabel": "Serial Port (USB)"
@@ -72,13 +96,23 @@ The `LIST` command returns a list of the currently available serial ports. The f
7296
}
7397
```
7498

75-
The `ports` field contains a list of the available serial ports. If the serial port comes from an USB serial converter the USB VID/PID and USB SERIAL NUMBER properties are also reported inside `prefs`. Inside the `identificationPrefs` instead we have only the properties useful for product identification (in this case USB VID/PID only that may be useful to identify the board)
99+
The `ports` field contains a list of the available serial ports. If the serial port comes from an USB serial converter the USB VID/PID and USB SERIAL NUMBER properties are also reported inside `properties`.
76100

77101
The list command is a one-shot command, if you need continuos monitoring of ports you should use `START_SYNC` command.
78102

79103
#### START_SYNC command
80104

81105
The `START_SYNC` command puts the tool in "events" mode: the discovery will send `add` and `remove` events each time a new port is detected or removed respectively.
106+
The immediate response to the command is:
107+
108+
```json
109+
{
110+
"eventType": "start_sync",
111+
"message": "OK"
112+
}
113+
```
114+
115+
after that the discovery enters in "events" mode.
82116

83117
The `add` events looks like the following:
84118

@@ -88,14 +122,10 @@ The `add` events looks like the following:
88122
"port": {
89123
"address": "/dev/ttyACM0",
90124
"label": "/dev/ttyACM0",
91-
"prefs": {
92-
"productId": "0x804e",
93-
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
94-
"vendorId": "0x2341"
95-
},
96-
"identificationPrefs": {
125+
"properties": {
97126
"pid": "0x804e",
98-
"vid": "0x2341"
127+
"vid": "0x2341",
128+
"serialNumber": "EBEABFD6514D32364E202020FF10181E"
99129
},
100130
"protocol": "serial",
101131
"protocolLabel": "Serial Port (USB)"
@@ -111,65 +141,80 @@ The `remove` event looks like this:
111141
{
112142
"eventType": "remove",
113143
"port": {
114-
"address": "/dev/ttyACM0"
144+
"address": "/dev/ttyACM0",
145+
"protocol": "serial"
115146
}
116147
}
117148
```
118149

119-
in this case only the `address` field is reported.
150+
in this case only the `address` and `protocol` fields are reported.
120151

121152
### Example of usage
122153

123154
A possible transcript of the discovery usage:
124155

125156
```
126-
$ ./serial-discovery
157+
$ ./serial-discovery
127158
START
128159
{
129160
"eventType": "start",
130161
"message": "OK"
131162
}
163+
LIST
164+
{
165+
"eventType": "list",
166+
"ports": [
167+
{
168+
"address": "/dev/ttyACM0",
169+
"label": "/dev/ttyACM0",
170+
"protocol": "serial",
171+
"protocolLabel": "Serial Port (USB)",
172+
"properties": {
173+
"pid": "0x004e",
174+
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
175+
"vid": "0x2341"
176+
}
177+
}
178+
]
179+
}
132180
START_SYNC
133181
{
182+
"eventType": "start_sync",
183+
"message": "OK"
184+
}
185+
{ <--- this event has been immediately sent
134186
"eventType": "add",
135187
"port": {
136188
"address": "/dev/ttyACM0",
137189
"label": "/dev/ttyACM0",
138-
"prefs": {
139-
"productId": "0x804e",
190+
"protocol": "serial",
191+
"protocolLabel": "Serial Port (USB)",
192+
"properties": {
193+
"pid": "0x004e",
140194
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
141-
"vendorId": "0x2341"
142-
},
143-
"identificationPrefs": {
144-
"pid": "0x804e",
145195
"vid": "0x2341"
146-
},
147-
"protocol": "serial",
148-
"protocolLabel": "Serial Port (USB)"
196+
}
149197
}
150198
}
151199
{ <--- the board has been disconnected here
152200
"eventType": "remove",
153201
"port": {
154-
"address": "/dev/ttyACM0"
202+
"address": "/dev/ttyACM0",
203+
"protocol": "serial"
155204
}
156205
}
157206
{ <--- the board has been connected again
158207
"eventType": "add",
159208
"port": {
160209
"address": "/dev/ttyACM0",
161210
"label": "/dev/ttyACM0",
162-
"prefs": {
163-
"productId": "0x804e",
211+
"protocol": "serial",
212+
"protocolLabel": "Serial Port (USB)",
213+
"properties": {
214+
"pid": "0x004e",
164215
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
165-
"vendorId": "0x2341"
166-
},
167-
"identificationPrefs": {
168-
"pid": "0x804e",
169216
"vid": "0x2341"
170-
},
171-
"protocol": "serial",
172-
"protocolLabel": "Serial Port (USB)"
217+
}
173218
}
174219
}
175220
QUIT
@@ -196,5 +241,4 @@ The software is released under the GNU General Public License, which covers the
196241
of the serial-discovery code. The terms of this license can be found at:
197242
https://www.gnu.org/licenses/gpl-3.0.en.html
198243

199-
See [LICENSE.txt](<https://github.com/arduino/serial-discovery/blob/master/LICENSE.txt>) for details.
200-
244+
See [LICENSE.txt](https://github.com/arduino/serial-discovery/blob/master/LICENSE.txt) for details.

0 commit comments

Comments
 (0)