Skip to content

Commit e34031c

Browse files
committed
Moved serial number from board details to board list
1 parent 92367f3 commit e34031c

File tree

5 files changed

+71
-69
lines changed

5 files changed

+71
-69
lines changed

Diff for: cli/board/list.go

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func watchList(cmd *cobra.Command, inst *rpc.Instance) {
109109
Protocol: event.Port.Protocol,
110110
ProtocolLabel: event.Port.ProtocolLabel,
111111
Boards: event.Port.Boards,
112+
SerialNumber: event.Port.SerialNumber,
112113
Error: event.Error,
113114
})
114115
}
@@ -181,6 +182,7 @@ type watchEvent struct {
181182
Protocol string `json:"protocol,omitempty"`
182183
ProtocolLabel string `json:"protocol_label,omitempty"`
183184
Boards []*rpc.BoardListItem `json:"boards,omitempty"`
185+
SerialNumber string `json:"serial_number,omitempty"`
184186
Error string `json:"error,omitempty"`
185187
}
186188

Diff for: commands/board/details.go

-20
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,5 @@ func Details(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsRe
146146
})
147147
}
148148

149-
// Get connected boards
150-
ports, err := commands.ListBoards(pm)
151-
if err != nil {
152-
return nil, err
153-
}
154-
for _, port := range ports {
155-
// Skip the port if serial number is not found
156-
if !port.Prefs.ContainsKey("serialNumber") {
157-
continue
158-
}
159-
160-
// Search for a board with the same FQBN set in request
161-
for _, board := range pm.IdentifyBoard(port.IdentificationPrefs) {
162-
if board.FQBN() == req.Fqbn {
163-
details.SerialNumber = port.Prefs.Get("serialNumber")
164-
break
165-
}
166-
}
167-
}
168-
169149
return details, nil
170150
}

Diff for: commands/board/list.go

+7
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func List(instanceID int32) (r []*rpc.DetectedPort, e error) {
185185
Protocol: port.Protocol,
186186
ProtocolLabel: port.ProtocolLabel,
187187
Boards: boards,
188+
SerialNumber: port.Prefs.Get("serialNumber"),
188189
}
189190
retVal = append(retVal, p)
190191
}
@@ -222,13 +223,19 @@ func Watch(instanceID int32, interrupt <-chan bool) (<-chan *rpc.BoardListWatchR
222223
}
223224
}
224225

226+
serialNumber := ""
227+
if props := event.Port.Properties; props != nil {
228+
serialNumber = props.Get("serialNumber")
229+
}
230+
225231
outChan <- &rpc.BoardListWatchResp{
226232
EventType: event.Type,
227233
Port: &rpc.DetectedPort{
228234
Address: event.Port.Address,
229235
Protocol: event.Port.Protocol,
230236
ProtocolLabel: event.Port.ProtocolLabel,
231237
Boards: boards,
238+
SerialNumber: serialNumber,
232239
},
233240
Error: boardsError,
234241
}

Diff for: rpc/commands/board.pb.go

+60-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: rpc/commands/board.proto

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ message DetectedPort {
194194
string protocol_label = 3;
195195
// The boards attached to the port.
196196
repeated BoardListItem boards = 4;
197+
// Serial number of connected board
198+
string serial_number = 5;
197199
}
198200

199201
message BoardListAllReq {

0 commit comments

Comments
 (0)