Skip to content

Commit a31ff4c

Browse files
committed
added readme to dummy-discovery
1 parent 21f28b6 commit a31ff4c

File tree

1 file changed

+265
-0
lines changed

1 file changed

+265
-0
lines changed

dummy-discovery/README.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
# Arduino pluggable discovery reference implementation
2+
3+
The `dummy-discovery` tool is a command line program that interacts via stdio. It accepts commands as plain ASCII strings terminated with LF `\n` and sends response as JSON.
4+
The "communication ports" returned by the tool are fake, this discovery is intenteded only for educational and testing purposes.
5+
6+
## How to build
7+
8+
Install a recent go enviroment and run `go build`. The executable `dummy-discovery` will be produced in your working directory.
9+
10+
## Usage
11+
12+
After startup, the tool waits for commands. The available commands are: `HELLO`, `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`.
13+
14+
#### HELLO command
15+
16+
The `HELLO` command is used to establish the pluggable discovery protocol between client and discovery.
17+
The format of the command is:
18+
19+
`HELLO <PROTOCOL_VERSION> "<USER_AGENT>"`
20+
21+
for example:
22+
23+
`HELLO 1 "Arduino IDE"`
24+
25+
or:
26+
27+
`HELLO 1 "arduino-cli"`
28+
29+
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).
30+
The response to the command is:
31+
32+
```json
33+
{
34+
"eventType": "hello",
35+
"protocolVersion": 1,
36+
"message": "OK"
37+
}
38+
```
39+
40+
`protocolVersion` is the protocol version that the discovery is going to use in the remainder of the communication.
41+
42+
#### START command
43+
44+
The `START` starts the internal subroutines of the discovery that looks for ports. This command must be called before `LIST` or `START_SYNC`. The response to the start command is:
45+
46+
```json
47+
{
48+
"eventType": "start",
49+
"message": "OK"
50+
}
51+
```
52+
53+
#### STOP command
54+
55+
The `STOP` command stops the discovery internal subroutines and free some resources. This command should be called if the client wants to pause the discovery for a while. The response to the stop command is:
56+
57+
```json
58+
{
59+
"eventType": "stop",
60+
"message": "OK"
61+
}
62+
```
63+
64+
#### QUIT command
65+
66+
The `QUIT` command terminates the discovery. The response to quit is:
67+
68+
```json
69+
{
70+
"eventType": "quit",
71+
"message": "OK"
72+
}
73+
```
74+
75+
after this output the tool quits.
76+
77+
#### LIST command
78+
79+
The `LIST` command returns a list of the currently available serial ports. The format of the response is the following:
80+
81+
```json
82+
{
83+
"eventType": "list",
84+
"ports": [
85+
{
86+
"address": "1",
87+
"label": "Dummy upload port",
88+
"protocol": "dummy",
89+
"protocolLabel": "Dummy protocol",
90+
"properties": {
91+
"mac": "73622384782",
92+
"pid": "0x0041",
93+
"vid": "0x2341"
94+
}
95+
}
96+
]
97+
}
98+
```
99+
100+
#### START_SYNC command
101+
102+
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.
103+
The immediate response to the command is:
104+
105+
```json
106+
{
107+
"eventType": "start_sync",
108+
"message": "OK"
109+
}
110+
```
111+
112+
after that the discovery enters in "events" mode.
113+
114+
The `add` events looks like the following:
115+
116+
```json
117+
118+
"eventType": "add",
119+
"port": {
120+
"address": "4",
121+
"label": "Dummy upload port",
122+
"protocol": "dummy",
123+
"protocolLabel": "Dummy protocol",
124+
"properties": {
125+
"mac": "294489539128",
126+
"pid": "0x0041",
127+
"vid": "0x2341"
128+
}
129+
}
130+
}
131+
```
132+
133+
it basically gather the same information as the `list` event but for a single port. After calling `START_SYNC` a bunch of `add` events may be generated in sequence to report all the ports available at the moment of the start.
134+
135+
The `remove` event looks like this:
136+
137+
```json
138+
{
139+
"eventType": "remove",
140+
"port": {
141+
"address": "4",
142+
"protocol": "dummy"
143+
}
144+
}
145+
```
146+
147+
in this case only the `address` and `protocol` fields are reported.
148+
149+
### Example of usage
150+
151+
A possible transcript of the discovery usage:
152+
153+
```
154+
HELLO 1 "arduino-cli"
155+
{
156+
"eventType": "hello",
157+
"message": "OK",
158+
"protocolVersion": 1
159+
}
160+
START
161+
{
162+
"eventType": "start",
163+
"message": "OK"
164+
}
165+
LIST
166+
{
167+
"eventType": "list",
168+
"ports": [
169+
{
170+
"address": "1",
171+
"label": "Dummy upload port",
172+
"protocol": "dummy",
173+
"protocolLabel": "Dummy protocol",
174+
"properties": {
175+
"mac": "73622384782",
176+
"pid": "0x0041",
177+
"vid": "0x2341"
178+
}
179+
}
180+
]
181+
}
182+
STOP
183+
{
184+
"eventType": "stop",
185+
"message": "OK"
186+
}
187+
START_SYNC
188+
{
189+
"eventType": "start_sync",
190+
"message": "OK"
191+
}
192+
{
193+
"eventType": "add",
194+
"port": {
195+
"address": "2",
196+
"label": "Dummy upload port",
197+
"protocol": "dummy",
198+
"protocolLabel": "Dummy protocol",
199+
"properties": {
200+
"mac": "147244769564",
201+
"pid": "0x0041",
202+
"vid": "0x2341"
203+
}
204+
}
205+
}
206+
{
207+
"eventType": "add",
208+
"port": {
209+
"address": "3",
210+
"label": "Dummy upload port",
211+
"protocol": "dummy",
212+
"protocolLabel": "Dummy protocol",
213+
"properties": {
214+
"mac": "220867154346",
215+
"pid": "0x0041",
216+
"vid": "0x2341"
217+
}
218+
}
219+
}
220+
{
221+
"eventType": "add",
222+
"port": {
223+
"address": "4",
224+
"label": "Dummy upload port",
225+
"protocol": "dummy",
226+
"protocolLabel": "Dummy protocol",
227+
"properties": {
228+
"mac": "294489539128",
229+
"pid": "0x0041",
230+
"vid": "0x2341"
231+
}
232+
}
233+
}
234+
{
235+
"eventType": "remove",
236+
"port": {
237+
"address": "4",
238+
"protocol": "dummy"
239+
}
240+
}
241+
QUIT
242+
{
243+
"eventType": "quit",
244+
"message": "OK"
245+
}
246+
$
247+
```
248+
249+
## Security
250+
251+
If you think you found a vulnerability or other security-related bug in this project, please read our
252+
[security policy](https://github.com/arduino/serial-discovery/security/policy) and report the bug to our Security Team 🛡️
253+
Thank you!
254+
255+
e-mail contact: security@arduino.cc
256+
257+
## License
258+
259+
Copyright (c) 2021 ARDUINO SA (www.arduino.cc)
260+
261+
The software is released under the GNU General Public License, which covers the main body
262+
of the serial-discovery code. The terms of this license can be found at:
263+
https://www.gnu.org/licenses/gpl-3.0.en.html
264+
265+
See [LICENSE.txt](https://github.com/arduino/serial-discovery/blob/master/LICENSE.txt) for details.

0 commit comments

Comments
 (0)