@@ -97,6 +97,10 @@ public PreferencesMap getPrefs() {
9797 return prefs ;
9898 }
9999
100+ public PreferencesMap getIdentificationPrefs () {
101+ return identificationPrefs ;
102+ }
103+
100104 public void setLabel (String label ) {
101105 this .label = label ;
102106 }
@@ -126,7 +130,7 @@ public TargetBoard searchMatchingBoard() {
126130 for (TargetPackage targetPackage : BaseNoGui .packages .values ()) {
127131 for (TargetPlatform targetPlatform : targetPackage .getPlatforms ().values ()) {
128132 for (TargetBoard board : targetPlatform .getBoards ().values ()) {
129- if (matchesIdentificationPrefs (board )) {
133+ if (matchesBoard (board )) {
130134 setBoardName (board .getName ());
131135 return board ;
132136 }
@@ -135,21 +139,44 @@ public TargetBoard searchMatchingBoard() {
135139 }
136140 return null ;
137141 }
138- // Check whether a board matches all identificationPrefs fields
139- private boolean matchesIdentificationPrefs (TargetBoard board ) {
140- for (String key : identificationPrefs .keySet ()) {
141- if (!matchesIdentificationPref (board , key )) return false ;
142- }
143- return true ;
144- }
145- // Check whether a board matches a single identificationPrefs field
146- private boolean matchesIdentificationPref (TargetBoard board , String key ) {
147- String value = identificationPrefs .get (key );
148- if (value == null ) return false ;
149- for (String property : board .getPreferences ().subTree (key ).values ()) {
150- if (property .equalsIgnoreCase (value )) return true ;
142+
143+ public boolean matchesBoard (TargetBoard board ) {
144+ PreferencesMap identificationProps = getIdentificationPrefs ();
145+ PreferencesMap boardProps = board .getPreferences ();
146+
147+ // Identification properties are defined in boards.txt with a ".N" suffix
148+ // for example:
149+ //
150+ // uno.name=Arduino/Genuino Uno
151+ // uno.vid.0=0x2341
152+ // uno.pid.0=0x0043
153+ // uno.vid.1=0x2341
154+ // uno.pid.1=0x0001
155+ // uno.vid.2=0x2A03
156+ // uno.pid.2=0x0043
157+ // uno.vid.3=0x2341
158+ // uno.pid.3=0x0243
159+ //
160+ // so we must search starting from suffix ".0" and increasing until we
161+ // found a match or the board has no more identification properties defined
162+
163+ for (int suffix = 0 ;; suffix ++) {
164+ boolean found = true ;
165+ for (String prop : identificationProps .keySet ()) {
166+ String value = identificationProps .get (prop );
167+ prop += "." + suffix ;
168+ if (!boardProps .containsKey (prop )) {
169+ return false ;
170+ }
171+ if (!value .equalsIgnoreCase (boardProps .get (prop ))) {
172+ found = false ;
173+ break ;
174+ }
175+ }
176+ if (found ) {
177+ return true ;
178+ }
151179 }
152- return false ;
153180 }
154181
155182}
0 commit comments