pollOnce gathers all params for a single tick. Returns the CSV row (ISO timestamp, ns timestamp, then each value or "ERR: ") and allErrored=true if every parameter failed.
(sa53 *protocol.Mac, params []string, rl *rawlog.Logger)
| 293 | // (ISO timestamp, ns timestamp, then each value or "ERR:<msg>") and |
| 294 | // allErrored=true if every parameter failed. |
| 295 | func pollOnce(sa53 *protocol.Mac, params []string, rl *rawlog.Logger) (row []string, allErrored bool) { |
| 296 | row = make([]string, 0, len(params)+2) |
| 297 | now := time.Now() |
| 298 | row = append(row, now.UTC().Format(time.RFC3339Nano)) |
| 299 | row = append(row, strconv.FormatInt(now.UnixNano(), 10)) |
| 300 | errCount := 0 |
| 301 | for _, p := range params { |
| 302 | mark(rl, "get "+p) |
| 303 | v, err := sa53.Get(p) |
| 304 | if err != nil { |
| 305 | row = append(row, "ERR:"+err.Error()) |
| 306 | errCount++ |
| 307 | // Drain only when bytes might still be in flight. A clean |
| 308 | // device error ([!N]) means the response is complete. |
| 309 | if !errors.Is(err, protocol.ErrDeviceError) { |
| 310 | sa53.Drain() |
| 311 | } |
| 312 | continue |
| 313 | } |
| 314 | row = append(row, v) |
| 315 | } |
| 316 | return row, errCount == len(params) |
| 317 | } |
| 318 | |
| 319 | // runPollSingleCmd opens the port, sends a single raw command, prints the |
| 320 | // response, and returns. Useful for one-off probes like \{swrev?} for |