Skip to content

Commit 5732909

Browse files
authored
Merge branch 'master' into discoveries_fix
2 parents 5abbe84 + 396718f commit 5732909

File tree

23 files changed

+10864
-10455
lines changed

23 files changed

+10864
-10455
lines changed

Diff for: arduino/discovery/discovery.go

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type Port struct {
9191
AddressLabel string `json:"label"`
9292
Protocol string `json:"protocol"`
9393
ProtocolLabel string `json:"protocolLabel"`
94+
HardwareID string `json:"hardwareId,omitempty"`
9495
Properties *properties.Map `json:"properties"`
9596
}
9697

@@ -107,6 +108,7 @@ func (p *Port) ToRPC() *rpc.Port {
107108
Label: p.AddressLabel,
108109
Protocol: p.Protocol,
109110
ProtocolLabel: p.ProtocolLabel,
111+
HardwareId: p.HardwareID,
110112
Properties: props.AsMap(),
111113
}
112114
}

Diff for: commands/sketch/new.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ func validateSketchName(name string) error {
7575
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name cannot be empty"))}
7676
}
7777
if len(name) > sketchNameMaxLength {
78-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%d characters). Maximum allowed length is %d",
78+
return &arduino.CantCreateSketchError{Cause: errors.New(tr("sketch name too long (%[1]d characters). Maximum allowed length is %[2]d",
7979
len(name),
8080
sketchNameMaxLength))}
8181
}
8282
if !sketchNameValidationRegex.MatchString(name) {
83-
return &arduino.CantCreateSketchError{Cause: errors.New(tr("invalid sketch name \"%s\". Required pattern %s",
84-
name,
85-
sketchNameValidationRegex.String()))}
83+
return &arduino.CantCreateSketchError{Cause: errors.New(tr(`invalid sketch name "%[1]s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
84+
name))}
8685
}
8786
return nil
8887
}

Diff for: commands/sketch/new_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sketch
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67

78
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -11,7 +12,6 @@ import (
1112
func Test_SketchNameWrongPattern(t *testing.T) {
1213
invalidNames := []string{
1314
"&",
14-
"",
1515
".hello",
1616
"_hello",
1717
"-hello",
@@ -24,11 +24,9 @@ func Test_SketchNameWrongPattern(t *testing.T) {
2424
SketchName: name,
2525
SketchDir: t.TempDir(),
2626
})
27-
require.NotNil(t, err)
2827

29-
require.Error(t, err, `Can't create sketch: invalid sketch name "%s". Required pattern %s`,
30-
name,
31-
sketchNameValidationRegex)
28+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: invalid sketch name "%s": the first character must be alphanumeric, the following ones can also contain "_", "-", and ".".`,
29+
name))
3230
}
3331
}
3432

@@ -38,9 +36,8 @@ func Test_SketchNameEmpty(t *testing.T) {
3836
SketchName: emptyName,
3937
SketchDir: t.TempDir(),
4038
})
41-
require.NotNil(t, err)
4239

43-
require.Error(t, err, `Can't create sketch: sketch name cannot be empty`)
40+
require.EqualError(t, err, `Can't create sketch: sketch name cannot be empty`)
4441
}
4542

4643
func Test_SketchNameTooLong(t *testing.T) {
@@ -52,11 +49,10 @@ func Test_SketchNameTooLong(t *testing.T) {
5249
SketchName: string(tooLongName),
5350
SketchDir: t.TempDir(),
5451
})
55-
require.NotNil(t, err)
5652

57-
require.Error(t, err, `Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
53+
require.EqualError(t, err, fmt.Sprintf(`Can't create sketch: sketch name too long (%d characters). Maximum allowed length is %d`,
5854
len(tooLongName),
59-
sketchNameMaxLength)
55+
sketchNameMaxLength))
6056
}
6157

6258
func Test_SketchNameOk(t *testing.T) {

Diff for: docs/pluggable-discovery-specification.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ call. The format of the response is the following:
127127
"label": <-- HOW THE PORT IS DISPLAYED ON THE GUI
128128
"protocol": <-- THE PROTOCOL USED BY THE BOARD
129129
"protocolLabel": <-- HOW THE PROTOCOL IS DISPLAYED ON THE GUI
130+
"hardwareId": <-- A STRING THAT UNIQUELY IDENTIFIES A BOARD INSTANCE
130131
"properties": {
131132
<-- A LIST OF PROPERTIES OF THE PORT
132133
}
@@ -147,7 +148,15 @@ Each port has:
147148
`SSH on 192.168.10.100`)
148149
- `protocol` is the protocol identifier (such as `serial` or `dfu` or `ssh`)
149150
- `protocolLabel` is the `protocol` in human readable form (for example `Serial port` or `DFU USB` or `Network (ssh)`)
150-
- `properties` is a list of key/value pairs that represent information relative to the specific port
151+
- `hardwareId` (optional) a string that uniquely identifies a specific board instance (even among other boards of the
152+
same model). Different ports with the same `hardwareId` must belong to the same board instance. The identifier should
153+
be sufficiently long to uniquely identify the board instance and reduce the probability of collisions. Good examples
154+
of `hardwareId` values are: Ethernet MAC Address, USB Serial Number, CPU-ID number, etc.
155+
156+
This value **should not** be used to identify the board **model** (see the
157+
[board identification](#board-identification) section for more information about identification of the board model).
158+
159+
- `properties` is a list of key/value pairs that represent information relative to the specific port.
151160

152161
To make the above more clear let's show an example output from the `serial-discovery` builtin in the Arduino CLI:
153162

@@ -160,6 +169,7 @@ To make the above more clear let's show an example output from the `serial-disco
160169
"label": "ttyACM0",
161170
"protocol": "serial",
162171
"protocolLabel": "Serial Port (USB)",
172+
"hardwareId": "EBEABFD6514D32364E202020FF10181E",
163173
"properties": {
164174
"pid": "0x804e",
165175
"vid": "0x2341",
@@ -175,6 +185,9 @@ In this case the serial port metadata comes from a USB serial converter. Inside
175185
properties of the port, and some of them may be useful for product identification (in this case only USB VID/PID is
176186
useful to identify the board model).
177187

188+
The `hardwareId` field is populated with the USB `serialNumber` since this value is useful to identify the board
189+
instance.
190+
178191
The `LIST` command performs a one-shot polling of the ports. The discovery should answer as soon as reasonably possible,
179192
without any additional delay.
180193

@@ -231,6 +244,7 @@ The `add` event looks like the following:
231244
"port": {
232245
"address": "/dev/ttyACM0",
233246
"label": "ttyACM0",
247+
"hardwareId": "EBEABFD6514D32364E202020FF10181E",
234248
"properties": {
235249
"pid": "0x804e",
236250
"vid": "0x2341",

0 commit comments

Comments
 (0)