MCPcopy Create free account
hub / github.com/facebook/time / runPollSingleCmd

Function runPollSingleCmd

sa53/cmd/poll.go:323–378  ·  view source on GitHub ↗

runPollSingleCmd opens the port, sends a single raw command, prints the response, and returns. Useful for one-off probes like \{swrev?} for firmware version. If rawPath is non-empty, raw TX/RX bytes are tee'd to that file just like the polling path.

(device, raw, rawPath string)

Source from the content-addressed store, hash-verified

321// firmware version. If rawPath is non-empty, raw TX/RX bytes are tee'd to
322// that file just like the polling path.
323func runPollSingleCmd(device, raw, rawPath string) error {
324 ok, err := detectSA5xCard()
325 if err != nil {
326 return err
327 }
328 if !ok {
329 return nil
330 }
331 if err := preflight.Default.Preflight(device); err != nil {
332 return err
333 }
334 sa53, err := protocol.Init(device)
335 if err != nil {
336 return err
337 }
338 defer sa53.Close()
339
340 var rl *rawlog.Logger
341 if rawPath != "" {
342 f, err := os.Create(rawPath)
343 if err != nil {
344 return fmt.Errorf("create raw log %s: %w", rawPath, err)
345 }
346 defer func() {
347 if err := f.Close(); err != nil {
348 log.Errorf("close raw log %s: %v", rawPath, err)
349 }
350 }()
351 rl = rawlog.NewLogger(f)
352 defer rl.Close()
353 sa53.WrapPort(func(p protocol.SerialReadWriter) protocol.SerialReadWriter {
354 return rawlog.NewLoggingPort(p, rl)
355 })
356 }
357
358 if err := sa53.SetReadTimeout(pollReadTimeout); err != nil {
359 return fmt.Errorf("set read timeout: %w", err)
360 }
361 mark(rl, "cmd "+raw)
362 resp, err := sa53.Cmd(raw)
363 if err != nil {
364 return err
365 }
366 val, perr := protocol.ParseValue(resp)
367 if perr == nil {
368 fmt.Println(val)
369 return nil
370 }
371 if errors.Is(perr, protocol.ErrDeviceError) {
372 log.Fatalf("device returned error: %v", perr)
373 }
374 // Non-device parse failure: surface the raw response so the operator
375 // can decode it themselves.
376 fmt.Println(resp)
377 return nil
378}

Callers 1

poll.goFile · 0.85

Calls 12

CloseMethod · 0.95
InitFunction · 0.92
NewLoggerFunction · 0.92
NewLoggingPortFunction · 0.92
ParseValueFunction · 0.92
detectSA5xCardFunction · 0.85
markFunction · 0.85
PreflightMethod · 0.80
WrapPortMethod · 0.80
CmdMethod · 0.80
CloseMethod · 0.65
SetReadTimeoutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…