@@ -24,9 +24,10 @@ import (
24
24
25
25
// Board represents a board loaded from an installed platform
26
26
type Board struct {
27
- BoardID string
28
- Properties * properties.Map `json:"-"`
29
- PlatformRelease * PlatformRelease `json:"-"`
27
+ BoardID string
28
+ Properties * properties.Map `json:"-"`
29
+ PlatformRelease * PlatformRelease `json:"-"`
30
+ identificationProperties []* properties.Map
30
31
}
31
32
32
33
// HasUsbID returns true if the board match the usb vid and pid parameters
@@ -140,22 +141,18 @@ func (b *Board) GeneratePropertiesForConfiguration(config string) (*properties.M
140
141
return b .GetBuildProperties (fqbn .Configs )
141
142
}
142
143
143
- // IsBoardMatchingIDProperties returns true if the board match the given
144
- // identification properties
145
- func ( b * Board ) IsBoardMatchingIDProperties ( query * properties. Map ) bool {
146
- portIDPropsSet := b . Properties . SubTree ( "upload_port" )
147
- if portIDPropsSet . Size () == 0 {
148
- return false
144
+ // GetIdentificationProperties calculate and returns a list of properties sets
145
+ // containing the properties required to identify the board. The returned sets
146
+ // must not be changed by the caller.
147
+ func ( b * Board ) GetIdentificationProperties () [] * properties. Map {
148
+ if b . identificationProperties != nil {
149
+ return b . identificationProperties
149
150
}
151
+ b .identificationProperties = []* properties.Map {}
150
152
151
- // check checks if the given set of properties p match the "query"
152
- check := func (p * properties.Map ) bool {
153
- for k , v := range p .AsMap () {
154
- if ! strings .EqualFold (query .Get (k ), v ) {
155
- return false
156
- }
157
- }
158
- return true
153
+ portIDPropsSet := b .Properties .SubTree ("upload_port" )
154
+ if portIDPropsSet .Size () == 0 {
155
+ return b .identificationProperties
159
156
}
160
157
161
158
// First check the identification properties with sub index "upload_port.N.xxx"
@@ -166,9 +163,7 @@ func (b *Board) IsBoardMatchingIDProperties(query *properties.Map) bool {
166
163
idx ++
167
164
if idProps .Size () > 0 {
168
165
haveIndexedProperties = true
169
- if check (idProps ) {
170
- return true
171
- }
166
+ b .identificationProperties = append (b .identificationProperties , idProps )
172
167
} else if idx > 1 {
173
168
// Always check sub-id 0 and 1 (https://github.com/arduino/arduino-cli/issues/456)
174
169
break
@@ -177,8 +172,30 @@ func (b *Board) IsBoardMatchingIDProperties(query *properties.Map) bool {
177
172
178
173
// if there are no subindexed then check the whole "upload_port.xxx"
179
174
if ! haveIndexedProperties {
180
- return check ( portIDPropsSet )
175
+ b . identificationProperties = append ( b . identificationProperties , portIDPropsSet )
181
176
}
182
177
178
+ return b .identificationProperties
179
+ }
180
+
181
+ // IsBoardMatchingIDProperties returns true if the board match the given
182
+ // identification properties
183
+ func (b * Board ) IsBoardMatchingIDProperties (query * properties.Map ) bool {
184
+ // check checks if the given set of properties p match the "query"
185
+ check := func (p * properties.Map ) bool {
186
+ for k , v := range p .AsMap () {
187
+ if ! strings .EqualFold (query .Get (k ), v ) {
188
+ return false
189
+ }
190
+ }
191
+ return true
192
+ }
193
+
194
+ // First check the identification properties with sub index "upload_port.N.xxx"
195
+ for _ , idProps := range b .GetIdentificationProperties () {
196
+ if check (idProps ) {
197
+ return true
198
+ }
199
+ }
183
200
return false
184
201
}
0 commit comments