From c9bd6f4981398858c870fdd7ec1c3c76dd0eda28 Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Fri, 20 Nov 2026 15:18:29 -0600 Subject: [PATCH] la pins: read a long listing in pages (from/next, la_pins_paged) On firmware with la_pins_paged (features rev 12) a reply that cannot carry every pin says next; the CLI asks again with from (and the same la) and joins the pins, levels and pull_dirs from the last reply. Capped at 16 replies; stops when next does not move forward. Older firmware keeps the two-half fallback, now on BP0054 (cloud) as well as BP0053. Feature table synced to revision 12. Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +- cmd/benchpod-cli/busmaster.go | 76 +++++++++++++++++- cmd/benchpod-cli/lapins_subset_test.go | 105 ++++++++++++++++++++++++- internal/features/features.json | 37 ++++++--- 4 files changed, 200 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ab68a38..ce29241 100644 --- a/README.md +++ b/README.md @@ -1606,8 +1606,9 @@ under a push-pull output (it only costs current), or a pin driven high or pulled while the pod's target power is off (that powers an unpowered DUT through its pins; ignore it when the DUT has its own supply). Directions and warnings need gateware v55 or later; older pods show every pin as `unknown`. A list too large for one cloud reply -(a long sensor instance name on every pin) is read in two parts by itself (firmware after -3.10.12; older firmware answers "reply too large" then). +(a long sensor instance name on every pin) is read in parts by itself: in pages on firmware +after 4.0.0 (`la_pins_paged`), else in two halves (firmware after 3.10.12; older firmware +answers "reply too large" then). | Flag | Default | Purpose | |----------|---------|----------------------------------| diff --git a/cmd/benchpod-cli/busmaster.go b/cmd/benchpod-cli/busmaster.go index 15d6f3d..631a858 100644 --- a/cmd/benchpod-cli/busmaster.go +++ b/cmd/benchpod-cli/busmaster.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/embeddedci-com/benchpod-cli/internal/features" "github.com/embeddedci-com/benchpod-cli/internal/tcpclient" "github.com/spf13/cobra" ) @@ -567,15 +568,24 @@ type laPinsCommander interface { Command(ctx context.Context, req map[string]any) (json.RawMessage, error) } +// laPinsMaxPages caps the la_pins paging loop (a full listing takes at most 14 replies). +const laPinsMaxPages = 16 + // laPinsFetch reads la_pins: every pin (pins nil) or only those pins (the pod sends only the pins -// asked for). A full listing the pod answers with BP0053 (reply_too_large: a long sensor instance -// name on every pin) is read in two parts, LA1-7 and LA8-14, and joined. +// asked for). On firmware with la_pins_paged (features rev 12) a reply that cannot carry every pin +// says "next": the rest is asked for with "from" (and the same "la") and the pins are joined, +// levels and pull_dirs from the last reply. Older firmware answers a full listing too large for one +// reply (a long sensor instance name on every pin) with BP0053 (BP0054 over the cloud); that one is +// read in two parts, LA1-7 and LA8-14, and joined. func laPinsFetch(ctx context.Context, c laPinsCommander, pins []int) (json.RawMessage, error) { + if laPinsPaged(ctx, c) { + return laPinsFetchPaged(ctx, c, pins) + } if pins != nil { return c.Command(ctx, map[string]any{"cmd": "la_pins", "la": pins}) } raw, err := c.Command(ctx, map[string]any{"cmd": "la_pins"}) - if err == nil || !tcpclient.HasCode(err, "BP0053") { + if err == nil || !(tcpclient.HasCode(err, "BP0053") || tcpclient.HasCode(err, "BP0054")) { return raw, err } var parts [2]map[string]any @@ -594,6 +604,64 @@ func laPinsFetch(ctx context.Context, c laPinsCommander, pins []int) (json.RawMe return json.Marshal(parts[0]) } +// laPinsPaged reports whether the pod's features list la_pins_paged (a status it cannot read +// counts as no). +func laPinsPaged(ctx context.Context, c laPinsCommander) bool { + st, err := c.Command(ctx, features.StatusRequest()) + if err != nil { + return false + } + ok, err := features.Has(st, "la_pins_paged") + return err == nil && ok +} + +// laPinsFetchPaged follows "next" with "from" until a reply has none (at most laPinsMaxPages +// replies; it stops when next does not move forward). +func laPinsFetchPaged(ctx context.Context, c laPinsCommander, pins []int) (json.RawMessage, error) { + req := map[string]any{"cmd": "la_pins"} + if pins != nil { + req["la"] = pins + } + var all []any + var last map[string]any + from := 1 + for page := 0; page < laPinsMaxPages; page++ { + raw, err := c.Command(ctx, req) + if err != nil { + return nil, err + } + last = nil + if err := json.Unmarshal(raw, &last); err != nil { + return nil, fmt.Errorf("unexpected reply %s", strings.TrimSpace(string(raw))) + } + p, _ := last["pins"].([]any) + all = append(all, p...) + next, ok := last["next"].(float64) + if !ok { + break + } + if int(next) <= from || next > 14 { + fmt.Fprintf(os.Stderr, "warning: la_pins: next %v does not follow from %d; the list stops there\n", next, from) + break + } + if page == laPinsMaxPages-1 { + fmt.Fprintf(os.Stderr, "warning: la_pins: still not done after %d replies; the list stops there\n", laPinsMaxPages) + break + } + from = int(next) + req = map[string]any{"cmd": "la_pins", "from": from} + if pins != nil { + req["la"] = pins + } + } + delete(last, "next") + if all == nil { + all = []any{} + } + last["pins"] = all + return json.Marshal(last) +} + func newLAPinsCmd(g *globalFlags) *cobra.Command { var asJSON bool cmd := &cobra.Command{ @@ -601,7 +669,7 @@ func newLAPinsCmd(g *globalFlags) *cobra.Command { Short: "List every LA pin: function, GPIO state, live level, pull-up, direction and warnings", Long: "List every LA pin, or only PINS (a pin, a list or a range: 9, 9,10, 9-12, la9, or a\n" + "name from the pod's wiring profile). A list too large for one cloud reply is read\n" + - "in two parts by itself.", + "in parts by itself.", Example: " benchpod la pins\n benchpod la pins 1-4\n benchpod la pins uart_rx --json", Args: cobra.MaximumNArgs(1), RunE: func(_ *cobra.Command, args []string) error { diff --git a/cmd/benchpod-cli/lapins_subset_test.go b/cmd/benchpod-cli/lapins_subset_test.go index 919d6b4..343f71b 100644 --- a/cmd/benchpod-cli/lapins_subset_test.go +++ b/cmd/benchpod-cli/lapins_subset_test.go @@ -10,23 +10,43 @@ import ( ) // fakeLAPins answers la_pins like the firmware: "la" selects pins when subset is true (firmware -// after 3.10.12), the full listing fails with "reply too large" when tooLarge is true. +// after 3.10.12), the full listing fails with "reply too large" when tooLarge is true. With page +// > 0 (firmware with la_pins_paged, features rev 12) a reply carries at most page pins and says +// "next"; "from" continues there. badNext makes next point back at LA1. type fakeLAPins struct { subset, tooLarge bool + tooLargeCode string + page int + badNext bool sent []map[string]any } func (f *fakeLAPins) Command(_ context.Context, req map[string]any) (json.RawMessage, error) { + if req["cmd"] == "status" { + rev := 11 + if f.page > 0 { + rev = 12 + } + return json.Marshal(map[string]any{"version": "4.0.1", "features_rev": rev, "gateware": 60}) + } f.sent = append(f.sent, req) want, has := req["la"].([]int) if !f.subset { has = false } if !has && f.tooLarge { - return nil, tcpclient.RefusalError("", "BP0053", nil) + code := f.tooLargeCode + if code == "" { + code = "BP0053" + } + return nil, tcpclient.RefusalError("", code, nil) + } + from := 1 + if v, ok := req["from"].(int); ok && f.page > 0 { + from = v } var pins []map[string]any - for la := 1; la <= 14; la++ { + for la := from; la <= 14; la++ { ok := !has for _, w := range want { ok = ok || w == la @@ -35,7 +55,16 @@ func (f *fakeLAPins) Command(_ context.Context, req map[string]any) (json.RawMes pins = append(pins, map[string]any{"la": la, "function": "none"}) } } - return json.Marshal(map[string]any{"pins": pins, "pull_dirs": []string{"up", "down"}, "levels": nil}) + rep := map[string]any{"pull_dirs": []string{"up", "down"}, "levels": len(f.sent)} + if f.page > 0 && len(pins) > f.page { + rep["next"] = pins[f.page]["la"] + if f.badNext { + rep["next"] = 1 + } + pins = pins[:f.page] + } + rep["pins"] = pins + return json.Marshal(rep) } func pinNumbers(t *testing.T, raw json.RawMessage) []int { @@ -81,3 +110,71 @@ func TestLAPinsTooLargeReadsInTwoParts(t *testing.T) { t.Fatalf("requests %v", f.sent) } } + +// Over the cloud the refusal is BP0054: the same two halves. +func TestLAPinsTooLargeOverCloudReadsInTwoParts(t *testing.T) { + f := &fakeLAPins{subset: true, tooLarge: true, tooLargeCode: "BP0054"} + raw, err := laPinsFetch(context.Background(), f, nil) + if err != nil { + t.Fatal(err) + } + if got := pinNumbers(t, raw); len(got) != 14 || len(f.sent) != 3 { + t.Fatalf("pins %v, requests %v", got, f.sent) + } +} + +// Firmware with la_pins_paged: follow next with from, join the pins, levels from the last reply. +func TestLAPinsPaged(t *testing.T) { + f := &fakeLAPins{subset: true, page: 5} + raw, err := laPinsFetch(context.Background(), f, nil) + if err != nil { + t.Fatal(err) + } + want := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14} + if got := pinNumbers(t, raw); !reflect.DeepEqual(got, want) { + t.Fatalf("pins %v", got) + } + wantSent := []map[string]any{{"cmd": "la_pins"}, {"cmd": "la_pins", "from": 6}, {"cmd": "la_pins", "from": 11}} + if !reflect.DeepEqual(f.sent, wantSent) { + t.Fatalf("requests %v", f.sent) + } + var rep map[string]any + _ = json.Unmarshal(raw, &rep) + if _, has := rep["next"]; has || rep["levels"] != float64(3) { + t.Fatalf("joined reply %v", rep) + } +} + +// A subset pages with the same la. +func TestLAPinsPagedSubset(t *testing.T) { + f := &fakeLAPins{subset: true, page: 2} + raw, err := laPinsFetch(context.Background(), f, []int{2, 4, 6, 8, 10}) + if err != nil { + t.Fatal(err) + } + if got := pinNumbers(t, raw); !reflect.DeepEqual(got, []int{2, 4, 6, 8, 10}) { + t.Fatalf("pins %v", got) + } + la := []int{2, 4, 6, 8, 10} + wantSent := []map[string]any{{"cmd": "la_pins", "la": la}, {"cmd": "la_pins", "la": la, "from": 6}, + {"cmd": "la_pins", "la": la, "from": 10}} + if !reflect.DeepEqual(f.sent, wantSent) { + t.Fatalf("requests %v", f.sent) + } +} + +// A listing that fits is one request, and a next that does not move forward stops the loop. +func TestLAPinsPagedStops(t *testing.T) { + f := &fakeLAPins{subset: true, page: 14} + if _, err := laPinsFetch(context.Background(), f, nil); err != nil || len(f.sent) != 1 { + t.Fatalf("err %v, requests %v", err, f.sent) + } + f = &fakeLAPins{subset: true, page: 5, badNext: true} + raw, err := laPinsFetch(context.Background(), f, nil) + if err != nil { + t.Fatal(err) + } + if got := pinNumbers(t, raw); !reflect.DeepEqual(got, []int{1, 2, 3, 4, 5}) || len(f.sent) != 1 { + t.Fatalf("pins %v, requests %v", got, f.sent) + } +} diff --git a/internal/features/features.json b/internal/features/features.json index 1b5ea18..1515380 100644 --- a/internal/features/features.json +++ b/internal/features/features.json @@ -1,10 +1,10 @@ { "_generated": "GENERATED by tools/gen_features.py from features/features.toml. DO NOT EDIT: edit the table.", "schema": 1, - "revision": 11, + "revision": 12, "api": 2, "min_client_api": 2, - "table_sha256": "ea8870a74cd198ed990eeec337ab4792870bb26185f2c5449c7a23bd8dc94b05", + "table_sha256": "875940ed02d7f8b7a9058803971565fc38e7f095d1795a80ee83627c563736dd", "floor": "3.9.2", "docs_base": "https://github.com/embeddedci-com/benchpod-firmware/blob/main/docs/", "facts": { @@ -134,6 +134,11 @@ "firmware": "3.10.13", "gateware": 59, "date": "2026-11-19" + }, + { + "firmware": "4.0.0", + "gateware": 59, + "date": "2026-11-20" } ], "features": { @@ -701,69 +706,75 @@ }, "client_api": { "rev": 8, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#client-compatibility" }, "lan_tls_default": { "rev": 9, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#lan_tls--the-lan-api-over-tls" }, "sig_always_required": { "rev": 9, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#sig_policy--which-firmware-and-blob-updates-the-pod-accepts" }, "generate_volts_only": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "analog", "docs": "API.md#generate--dac-waveform-output" }, "json_names_4": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#commands" }, "can_start_stop": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#can_start--bring-can-up" }, "la_step_pull_split": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#la_pull--la-pin-pull-resistors" }, "json_booleans_4": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#target_power--enabledisable-a-target-power-efuse" }, "console_recovery_json": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "usb-serial-interface.md#removed-in-firmware-400" }, "usb_host": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#usb_host--usb-host-mode" }, "dac_pinout_guard": { "rev": 11, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#dac-pinout-on-the-flat-cable" + }, + "la_pins_paged": { + "rev": 12, + "firmware": "next", + "board": "any", + "docs": "API.md#la_pins--report-every-la-pin" } } }