@@ -83,16 +83,37 @@ func FromFQBN(ctx context.Context, fqbn string) ([]Board, error) {
8383 switch port .GetPort ().GetProtocol () {
8484 case SerialProtocol :
8585 serial := strings .ToLower (port .GetPort ().GetHardwareId ()) // in windows this is uppercase.
86+
87+ // TODO: we should store the board custom name in the product id so we can get it from the discovery service.
88+ var customName string
89+ if conn , err := adb .FromSerial (serial , "" ); err == nil {
90+ if name , err := GetCustomName (ctx , conn ); err == nil {
91+ customName = name
92+ }
93+ }
94+
8695 boards = append (boards , Board {
87- Protocol : SerialProtocol ,
88- Serial : serial ,
89- BoardName : boardName ,
96+ Protocol : SerialProtocol ,
97+ Serial : serial ,
98+ BoardName : boardName ,
99+ CustomName : customName ,
90100 })
91101 case NetworkProtocol :
102+ var customName string
103+ if name , ok := port .GetPort ().GetProperties ()["hostname" ]; ok {
104+ // take the part before the first dot as custom name
105+ idx := strings .Index (name , "." )
106+ if idx == - 1 {
107+ idx = len (name )
108+ }
109+ customName = name [:idx ]
110+ }
111+
92112 boards = append (boards , Board {
93- Protocol : NetworkProtocol ,
94- Address : port .GetPort ().GetAddress (),
95- BoardName : boardName ,
113+ Protocol : NetworkProtocol ,
114+ Address : port .GetPort ().GetAddress (),
115+ BoardName : boardName ,
116+ CustomName : customName ,
96117 })
97118 default :
98119 slog .Warn ("unknown protocol" , "protocol" , port .GetPort ().GetProtocol ())
@@ -108,22 +129,6 @@ func FromFQBN(ctx context.Context, fqbn string) ([]Board, error) {
108129 }
109130 })
110131
111- // Get board names
112- for i := range boards {
113- switch boards [i ].Protocol {
114- case SerialProtocol :
115- // TODO: we should store the board custom name in the product id so we can get it from the discovery service.
116- var name string
117- if conn , err := adb .FromSerial (boards [i ].Serial , "" ); err == nil {
118- if name , err = GetCustomName (ctx , conn ); err == nil {
119- boards [i ].CustomName = name
120- }
121- }
122- case NetworkProtocol :
123- // TODO: get from mDNS
124- }
125- }
126-
127132 return boards , nil
128133 }
129134
0 commit comments