Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ A missing privilege exits with code 9 and the error code `permission_denied` ([d
| `gsdml schema versions` | the GSDML schema versions go-profinet has (1.0 to 2.46) |
| `gsdml schema validate FILE [--version V]` | validation against the schema of the file's version (or `V`) only: structure, simple types and facets, identity constraints, each issue with its line (exit code 7 when it is not valid) |
| `gsdml schema dump FILE [--version V] [--no-validate]` | the typed model of the file as JSON, with the schema's names and JSON numbers and booleans for numeric and boolean types |
| `gsdml modules FILE`, `gsdml submodules FILE` | the module and submodule types, with IO lengths, records and (`submodules`) the API of a submodule of an API other than 0 |
| `gsdml modules FILE`, `gsdml submodules FILE` | the module and submodule types, with IO lengths, records and (`submodules`) the API of a submodule of an API other than 0; `modules` also lists, with why, the modules left out of the catalog because they need a configurable submodule |
| `gsdml plan FILE [--dap ID] [--plug SLOT=IDENT]... [--slot N]... [--param-value SLOT:SUBSLOT:INDEX:FIELD=VALUE]... [--param-defaults]` | the parameter records an AR with the same flags writes before PrmEnd, in write order (with the API of a submodule of an API other than 0), built from the file's fields with go-profinet's `PlanParameters`, with the issues of the records and their severity (with `--format table` on stderr); sends nothing (exit code 7 when go-profinet refuses the plan for errors of the records). An AR's `--param` records are not part of the plan |
| `gsdml generate --model MODEL.json [--output-file FILE\|DIR] [--pnio-version V] [--device-access=false]` | the GSDML file of a go-profinet device model (`--output-file`/`-O`: a file, or a directory for the conventional name; `--pnio-version`: declared PNIO_Version, default V2.35; `--device-access`: declare DeviceAccessSupported, default true) |
| `connect` | establish an AR as IO-Controller and run it: states and alarms are streamed, then a summary; `--slot N` expects only some modules (shared device: another controller owns the rest), `--peer-check PORT=STATION/PORT` has the device watch a port's neighbor, `--mrp-role client\|manager\|off` gives a multiport device its MRP role, `--reparam SLOT:SUBSLOT:INDEX:HEX` re-parameterizes the running AR (PrmBegin … PrmEnd) |
Expand Down
45 changes: 45 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,51 @@ ending with a `---` line and no `---` line inside a section

---

## v0.21.0

**Date:** 2026-11-24
**Previous release:** v0.20.1

## Summary

Built on go-profinet v0.23.0, whose `gsdml.ToModel` refuses a device
access point that needs configurable submodules (`UseableSubmodules`),
which it does not convert, and leaves a catalog module that needs one out
of the catalog. `gsdml modules` lists those modules with why, and `--plug`
of one says why it cannot be plugged instead of reporting an unknown
ident.

## Changes

### Changed

- **go-profinet v0.23.0** (from v0.22.0). `--gsdml` and the `gsdml`
commands that build a model (`modules`, `submodules`, `plan`, `connect`
and the other AR commands) fail with `unsupported_gsdml` (exit 3) for a
device access point whose own submodules or plugged modules include a
configurable submodule with `FixedInSubslots` or `UsedInSubslots`. Such
a file was accepted before and gave a model without those submodules.
`gsdml inspect` reports the error per DAP.
- **`--plug SLOT=IDENT`** (`connect`, the AR commands, `gsdml plan`): a
module of the file that the catalog leaves out fails with
`unsupported_gsdml` (exit 3), naming the module and go-profinet's
reason, with or without `--plug-any-slot`. An ident the file does not
have is still `invalid_input` (exit 3).

### Added

- **`gsdml modules`**: `omitted_modules` in JSON (`id`, `ident_number`,
`reason`), the modules after the usable ones in text, and rows with
`omitted` in the table.

### Breaking

A GSDML file profinetctl took before can now exit 3 with
`unsupported_gsdml` (go-profinet's RELEASE.md, v0.23.0, gives the counts
on its local corpus). Configurable submodules cannot be selected yet.

---

## v0.20.1

**Date:** unreleased
Expand Down
54 changes: 51 additions & 3 deletions cmd/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ func (o *arOptions) parse() (*parsedAR, error) {
if doc != nil && !o.plugAnySlot {
rules = slotRulesOf(doc, o.dap)
}
if err := plug(m, o.plugs, rules); err != nil {
var omitted []omittedModule
if len(o.plugs) > 0 {
omitted = omittedModules(doc, o.dap)
}
if err := plug(m, o.plugs, rules, omitted); err != nil {
return nil, err
}
if m, err = withSlots(m, o.slots); err != nil {
Expand Down Expand Up @@ -390,9 +394,48 @@ func clipList(s string) string {
return s[:64] + "..."
}

// omittedModule is a module gsdml.ToModel leaves out of a device access
// point's catalog (gsdml.ModuleReport.Omitted): it needs a configurable
// submodule, which go-profinet does not convert.
type omittedModule struct {
ID string
IdentNumber uint32
Err error
}

// omittedModules returns the modules ToModel leaves out of the catalog of
// the device access point dap (the first for ""), once per ident number,
// in file order; none for no document.
func omittedModules(doc *gsdml.Document, dap string) []omittedModule {
if doc == nil {
return nil
}
reps, err := gsdml.AnalyzeModels(doc)
if err != nil {
return nil
}
var out []omittedModule
seen := map[uint32]bool{}
for _, r := range reps {
if dap != "" && r.DAP != dap {
continue
}
for _, mr := range r.Modules {
if mr.Omitted && !seen[mr.ModuleIdent] {
seen[mr.ModuleIdent] = true
out = append(out, omittedModule{ID: mr.Target, IdentNumber: mr.ModuleIdent, Err: mr.ModuleErr})
}
}
break
}
return out
}

// plug plugs modules of the catalog into slots, in the slots rules allow
// them in; nil rules allow every slot.
func plug(m *model.Device, plugs []string, rules *slotRules) error {
// them in; nil rules allow every slot. omitted are the modules of the
// GSDML file the catalog leaves out (omittedModules): plugging one fails
// with why.
func plug(m *model.Device, plugs []string, rules *slotRules, omitted []omittedModule) error {
for _, pl := range plugs {
slotS, identS, ok := strings.Cut(pl, "=")
slot, err := parseUint16(slotS)
Expand All @@ -412,6 +455,11 @@ func plug(m *model.Device, plugs []string, rules *slotRules) error {
}
}
if mod == nil {
for _, om := range omitted {
if om.IdentNumber == uint32(ident) {
return errs.InvalidInput(errs.CodeUnsupportedGSDML, fmt.Sprintf("--plug %q: module %s (0x%08X) is not in the catalog: %v", pl, om.ID, ident, om.Err), om.Err)
}
}
return errs.InvalidInput(errs.CodeInvalidInput, fmt.Sprintf("--plug %q: no module type with ident number 0x%08X (profinetctl gsdml modules lists them)", pl, ident), nil)
}
if err := rules.check(pl, slot, uint32(ident)); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/ar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ func TestConnectErrors(t *testing.T) {
func TestPlug(t *testing.T) {
t.Parallel()
m := testModel()
if err := plug(m, []string{"4=0x40", "1=0x40"}, nil); err != nil {
if err := plug(m, []string{"4=0x40", "1=0x40"}, nil, nil); err != nil {
t.Fatal(err)
}
if len(m.Slots) != 4 || m.Slots[0].Module.IdentNumber != 0x40 || m.Slots[3].Number != 4 {
t.Fatalf("slots %+v", m.Slots)
}
if err := plug(m, []string{"0=0x40"}, nil); err == nil {
if err := plug(m, []string{"0=0x40"}, nil, nil); err == nil {
t.Fatal("slot 0 plugged")
}
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestPlugSlotRules(t *testing.T) {
t.Fatalf("clip %q", got)
}
m := testModel()
if err := plug(m, []string{"3=0x40"}, &slotRules{dap: "D", physical: "0..3", allowed: map[uint32][]string{0x40: {"1"}}}); err == nil {
if err := plug(m, []string{"3=0x40"}, &slotRules{dap: "D", physical: "0..3", allowed: map[uint32][]string{0x40: {"1"}}}, nil); err == nil {
t.Fatal("plugged where it is not allowed")
}
}
Expand Down
25 changes: 24 additions & 1 deletion cmd/gsdml.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,17 @@ type moduleView struct {
type modulesResult struct {
DAP string `json:"dap"`
Modules []moduleView `json:"modules"`
// Omitted are the modules the file lets the DAP use that are not in
// the model's catalog, with why: they need a configurable submodule,
// which go-profinet does not convert (--plug refuses them).
Omitted []omittedModuleView `json:"omitted_modules,omitempty"`
}

// omittedModuleView is a module the catalog leaves out.
type omittedModuleView struct {
ID string `json:"id"`
IdentNumber uint32 `json:"ident_number"`
Reason string `json:"reason"`
}

func (r modulesResult) MarshalTextOutput() (string, error) {
Expand All @@ -310,6 +321,12 @@ func (r modulesResult) MarshalTextOutput() (string, error) {
fmt.Fprintf(&b, "0x%08X %-32s slots %-8s %d submodule(s), %d in / %d out octets\n", m.IdentNumber, m.Name, slots, m.Submodules, m.InputLen, m.OutputLen)
}
fmt.Fprintf(&b, "%d module(s) usable with DAP %s\n", len(r.Modules), r.DAP)
if len(r.Omitted) > 0 {
fmt.Fprintf(&b, "%d module(s) of the file not in the catalog (cannot be plugged):\n", len(r.Omitted))
for _, o := range r.Omitted {
fmt.Fprintf(&b, "0x%08X %s: %s\n", o.IdentNumber, o.ID, o.Reason)
}
}
return b.String(), nil
}

Expand All @@ -326,6 +343,9 @@ func (r modulesResult) TableRows() [][]string {
}
rows = append(rows, []string{fmt.Sprintf("0x%08X", m.IdentNumber), m.Name, slots, fmt.Sprint(m.Submodules), fmt.Sprint(m.InputLen), fmt.Sprint(m.OutputLen)})
}
for _, o := range r.Omitted {
rows = append(rows, []string{fmt.Sprintf("0x%08X", o.IdentNumber), o.ID, "omitted", "-", "-", "-"})
}
return rows
}

Expand Down Expand Up @@ -485,14 +505,17 @@ profinetctl, and this is not PI's GSDML checker.`,
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
return a.result(c, func(ctx context.Context) (any, error) {
m, err := loadModel(args[0], dap, "")
m, doc, err := loadModelDoc(args[0], dap, "")
if err != nil {
return nil, err
}
if err := interrupted(ctx); err != nil {
return nil, err
}
r := modulesResult{DAP: orDash(dap), Modules: []moduleView{}}
for _, om := range omittedModules(doc, dap) {
r.Omitted = append(r.Omitted, omittedModuleView{ID: om.ID, IdentNumber: om.IdentNumber, Reason: om.Err.Error()})
}
for _, mt := range m.ModuleTypes() {
v := moduleView{Name: mt.Name, IdentNumber: mt.IdentNumber, Submodules: len(mt.Submodules), Info: mt.Info}
for _, s := range mt.Submodules {
Expand Down
101 changes: 101 additions & 0 deletions cmd/omitted_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: MIT

package cmd

import (
"strings"
"testing"

"github.com/otfabric/go-profinet/gsdml"
)

// omittedGSDMLFile writes the test model's GSDML file with a configurable
// submodule (UseableSubmodules, UsedInSubslots) on the catalog module
// 0x40, which no slot plugs: gsdml.ToModel leaves it out of the catalog.
func omittedGSDMLFile(t *testing.T) string {
t.Helper()
doc, err := gsdml.FromModel(testModel(), gsdml.GenerateOptions{SupervisorAR: true})
if err != nil {
t.Fatal(err)
}
found := false
for _, mi := range doc.ProfileBody.ApplicationProcess.ModuleList.ModuleItems {
if v, err := gsdml.ParseUint32(mi.ModuleIdentNumber); err == nil && v == 0x40 {
mi.UseableSubmodules = &gsdml.UseableSubmodules{SubmoduleItemRefs: []*gsdml.SubmoduleItemRef{
{SubmoduleItemTarget: "SM_CHANNEL", AllowedInSubslots: "2..3", UsedInSubslots: "2"}}}
found = true
}
}
if !found {
t.Fatal("no module 0x40 in the generated file")
}
b, err := gsdml.Marshal(doc)
if err != nil {
t.Fatal(err)
}
return writeFile(t, "omitted.xml", b)
}

// A module the catalog leaves out: gsdml modules lists it apart with why,
// and --plug of it fails with that reason (unsupported_gsdml), in connect
// and plan, with and without --plug-any-slot.
func TestOmittedModule(t *testing.T) {
t.Parallel()
n := newTestNet(t)
n.device("dev-a", "192.168.0.10")
gf := omittedGSDMLFile(t)
var mods modulesResult
n.json(&mods, "gsdml", "modules", gf)
if len(mods.Modules) != 3 || len(mods.Omitted) != 1 || mods.Omitted[0].IdentNumber != 0x40 || mods.Omitted[0].ID == "" ||
!strings.Contains(mods.Omitted[0].Reason, "configurable submodule SM_CHANNEL") {
t.Fatalf("modules %+v", mods)
}
for _, m := range mods.Modules {
if m.IdentNumber == 0x40 {
t.Fatalf("0x40 among the usable modules: %+v", mods)
}
}
if out := n.ok("gsdml", "modules", gf); !strings.Contains(out, "3 module(s) usable") || !strings.Contains(out, "1 module(s) of the file not in the catalog (cannot be plugged):") ||
!strings.Contains(out, "0x00000040 "+mods.Omitted[0].ID+": ") {
t.Fatalf("text:\n%s", out)
}
if out := n.ok("gsdml", "modules", gf, "-o", "table"); !strings.Contains(out, "omitted") {
t.Fatalf("table:\n%s", out)
}
// The file without it lists none.
var plain modulesResult
n.json(&plain, "gsdml", "modules", gsdmlFile(t))
if len(plain.Omitted) != 0 {
t.Fatalf("plain %+v", plain)
}
base := []string{"-i", "pn0", "connect", "-s", "dev-a", "--gsdml", gf, "--duration", "100ms"}
for _, extra := range [][]string{nil, {"--plug-any-slot"}} {
msg := n.fails(3, "unsupported_gsdml", append(append(append([]string{}, base...), "--plug", "3=0x40"), extra...)...)
if !strings.Contains(msg, `--plug "3=0x40": module `+mods.Omitted[0].ID+` (0x00000040) is not in the catalog`) || !strings.Contains(msg, "configurable submodule SM_CHANNEL") {
t.Fatalf("connect %v: %s", extra, msg)
}
}
if msg := n.fails(3, "unsupported_gsdml", "gsdml", "plan", gf, "--plug", "3=0x40"); !strings.Contains(msg, "is not in the catalog") {
t.Fatalf("plan: %s", msg)
}
// An ident the file does not have stays unknown.
if msg := n.fails(3, "invalid_input", append(append([]string{}, base...), "--plug", "3=0x99")...); !strings.Contains(msg, "no module type with ident number 0x00000099") {
t.Fatalf("unknown: %s", msg)
}
}

// omittedModules picks the named device access point, and none without a
// document or for one that does not parse into reports.
func TestOmittedModulesOf(t *testing.T) {
t.Parallel()
if omittedModules(nil, "") != nil || omittedModules(&gsdml.Document{}, "") != nil {
t.Fatal("no document")
}
doc, err := gsdml.FromModel(testModel(), gsdml.GenerateOptions{})
if err != nil {
t.Fatal(err)
}
if got := omittedModules(doc, "no such DAP"); got != nil {
t.Fatalf("%+v", got)
}
}
6 changes: 5 additions & 1 deletion cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ after the planned ones, as given.`,
if err != nil {
return nil, err
}
if err := plug(m, plugs, slotRulesOf(doc, dap)); err != nil {
var omitted []omittedModule
if len(plugs) > 0 {
omitted = omittedModules(doc, dap)
}
if err := plug(m, plugs, slotRulesOf(doc, dap), omitted); err != nil {
return nil, err
}
if m, err = withSlots(m, slots); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/exitcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
| `kind` | `code` values |
|--------|---------------|
| `usage` | `invalid_input`, `invalid_flag_combination`, `confirmation_required` |
| `invalid_input` | `invalid_input`, `invalid_format`, `invalid_flag_combination`, `invalid_gsdml`, `unsupported_gsdml` (a document type declaration with an internal subset, a file naming no schema version go-profinet has, for `gsdml schema validate` and `gsdml schema dump` without `--version`, a float value JSON cannot represent (INF, -INF or NaN) for `gsdml schema dump`, a Ref DefaultValue of a DataType whose encoding go-profinet does not know: the file may be valid), `invalid_model`, `input_file_open_failed`, `output_file_create_failed`, `interface_open_failed` (no such interface) |
| `invalid_input` | `invalid_input`, `invalid_format`, `invalid_flag_combination`, `invalid_gsdml`, `unsupported_gsdml` (a document type declaration with an internal subset, a file naming no schema version go-profinet has, for `gsdml schema validate` and `gsdml schema dump` without `--version`, a float value JSON cannot represent (INF, -INF or NaN) for `gsdml schema dump`, a Ref DefaultValue of a DataType whose encoding go-profinet does not know, a device access point or plugged module that needs a configurable submodule (`UseableSubmodules` with `FixedInSubslots` or `UsedInSubslots`), a `--plug` of a module the catalog leaves out for one: the file may be valid), `invalid_model`, `input_file_open_failed`, `output_file_create_failed`, `interface_open_failed` (no such interface) |
| `transport` | `interface_open_failed`, `socket_failed` |
| `timeout` | `request_timeout`, `connect_failed` |
| `refused` | `pnio_error` (the message names the status: ErrorCode, ErrorDecode, ErrorCode1, ErrorCode2), `dcp_block_error`, `connect_failed`, `duplicate_station_name`, `invalid_input` (no IP address) |
Expand Down
2 changes: 1 addition & 1 deletion docs/json-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ These conventions are a **stable contract** for scripting. Field names are snake
| `gsdml schema dump` | `{"file", "schema_version", "validated", "document"}`; `document` is the root element `ISO15745Profile` with the elements and attributes the file has, under the schema's names (absent optional ones are left out), in the schema's order; numeric and boolean types are JSON numbers and booleans, `xsd:integer` and `xsd:decimal` strings; `validated` is false with `--no-validate` |
| `disconnect` | `{"station", "ar_uuid"}` |
| `gsdml plan` | `{"file", "dap", "planned", "writes": [{"api", "slot", "subslot", "index", "name", "module_ident_number", "submodule_ident_number", "transfer_sequence", "values", "length", "data"}], "errors", "warnings", "unvalidated", "issues": [{"path", "line", "message", "severity", "rule"}]}`; `writes` in the order an AR writes them, `api` the API of the write's submodule in the plugged configuration, `data` the record in hex, `values` the number of fields `--param-value` set in it (0: defaults only), `transfer_sequence` 0 when the file gives none; `planned` is false when go-profinet refused the plan for the errors in `issues` (`writes` is then empty, exit code 7); `severity` is `"error"`, `"warning"` or `"unvalidated"` |
| `gsdml modules`, `gsdml submodules` | `{"dap", "modules": [...]}`, `{"dap", "submodules": [...]}`; a submodule has `module`, `module_ident_number`, `name`, `ident_number`, `api`, `subslot`, `input_length`, `output_length`, `records` |
| `gsdml modules`, `gsdml submodules` | `{"dap", "modules": [...], "omitted_modules": [...]}`, `{"dap", "submodules": [...]}`; an omitted module (one the file lets the DAP use that needs a configurable submodule, so not in the catalog and refused by `--plug`) has `id`, `ident_number`, `reason`, and the key is absent when there is none; a submodule has `module`, `module_ident_number`, `name`, `ident_number`, `api`, `subslot`, `input_length`, `output_length`, `records` |
| `ar` | `{"station", "mac", "ip", "ar": {"ar_uuid", "session_key", "ar_type", "rt_class", "advanced", "device_address", "local_alarm_ref", "remote_alarm_ref", "input": iocr, "output": iocr}, "module_diff", "differences"}`; an iocr has `frame_id`, `data_length`, `send_clock_factor`, `reduction_ratio`, `watchdog_factor`, `data_hold_factor`, `cycle_ms` |
| `iocr` | `{"ar_uuid", "entries": [{"iocr", "frame_id", "kind": "data" \| "iocs", "slot", "subslot", "offset", "length"}]}` |
| `io status` | `{"station", "state", "inputs": [{"slot", "subslot", "data", "iops"}], "outputs": [{"slot", "subslot", "iocs"}]}`; a status is `"good"`, `"bad (0x..)"` or `"-"` (not received yet) |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/otfabric/profinetctl
go 1.26

require (
github.com/otfabric/go-profinet v0.22.0
github.com/otfabric/go-profinet v0.23.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
)
Expand Down
Loading
Loading