From 2a9da2b573637a9dc948969e4b4b05894129e744 Mon Sep 17 00:00:00 2001 From: Gavin Ying Date: Mon, 9 Nov 2026 18:28:43 +0800 Subject: [PATCH] feat: read example models from Open Modbus Catalog (SIM-01) Pin the ADAM-5017UH model, vectors and scenario at catalog commit f4e1f9c instead of modbus-models. Use the frozen ADAM-6024 regression fixture as the second example device and ship it in the image. Check the catalog vectors against the independent known values in the interop acceptance, and point the docs at the open catalog. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/acceptance.yaml | 6 +++--- CONTRIBUTING.md | 13 ++++++------ Dockerfile | 1 + README.md | 17 ++++++++-------- contrib/README.md | 7 ++----- docs/preview-notes.md | 3 ++- examples/deployment.yaml | 8 ++++---- examples/model-source.yaml | 19 +++++------------- tests/fixtures/io-module/README.md | 4 ++-- tests/test_catalog_platform.py | 2 +- tools/catalog-interop.py | 32 +++++++++++++++--------------- 11 files changed, 51 insertions(+), 61 deletions(-) diff --git a/.github/workflows/acceptance.yaml b/.github/workflows/acceptance.yaml index 9d40aa9..a1b1fd7 100644 --- a/.github/workflows/acceptance.yaml +++ b/.github/workflows/acceptance.yaml @@ -67,13 +67,13 @@ jobs: cp examples/model-source.yaml "$RUNNER_TEMP/catalog-acceptance/examples/" cd "$RUNNER_TEMP/catalog-acceptance" "$RUNNER_TEMP/modsim/bin/python" tools/fetch-models.py --output "$RUNNER_TEMP/catalog-acceptance/inputs" - "$RUNNER_TEMP/modsim/bin/python" tools/catalog-interop.py --scenario "$RUNNER_TEMP/catalog-acceptance/inputs/advantech/adam-5017uh/simulation/interop-inputs.sim.json" --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$GITHUB_WORKSPACE/.interop/modpoll/tools/wot-interop/read-write.cjs" --output "$RUNNER_TEMP/catalog-interop.json" - - name: Verify released runtime for product evidence + "$RUNNER_TEMP/modsim/bin/python" tools/catalog-interop.py --vectors "$RUNNER_TEMP/catalog-acceptance/inputs/devices/advantech/adam-5017uh/models/adam-5017uh.vectors.json" --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$GITHUB_WORKSPACE/.interop/modpoll/tools/wot-interop/read-write.cjs" --output "$RUNNER_TEMP/catalog-interop.json" + - name: Verify the released runtime against the catalog model run: | uv venv "$RUNNER_TEMP/released-modsim" uv pip install --python "$RUNNER_TEMP/released-modsim/bin/python" 'modsim==2.0.0a2' cd "$RUNNER_TEMP/catalog-acceptance" - "$RUNNER_TEMP/released-modsim/bin/python" tools/catalog-interop.py --scenario "$RUNNER_TEMP/catalog-acceptance/inputs/advantech/adam-5017uh/simulation/interop-inputs.sim.json" --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$GITHUB_WORKSPACE/.interop/modpoll/tools/wot-interop/read-write.cjs" --output "$RUNNER_TEMP/catalog-interop-released.json" + "$RUNNER_TEMP/released-modsim/bin/python" tools/catalog-interop.py --vectors "$RUNNER_TEMP/catalog-acceptance/inputs/devices/advantech/adam-5017uh/models/adam-5017uh.vectors.json" --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$GITHUB_WORKSPACE/.interop/modpoll/tools/wot-interop/read-write.cjs" --output "$RUNNER_TEMP/catalog-interop-released.json" - uses: actions/upload-artifact@v4 with: name: catalog-interop diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea7a738..de39ea8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,16 +11,15 @@ uv run python tools/generate-td.py --check uv run --group docs mkdocs build -s ``` -Device TMs, metadata, sources, evidence and product-specific scenarios belong in -[modbus-models](https://github.com/top-maker/modbus-models), targeting its `main` -through a PR and required catalog CI. Do not add editable device copies here. -A new model submission needs an executable TM and source/permission/known limits; -maintainers can help complete metadata. Photos and hardware evidence are optional. +Device TMs, metadata, sources and product-specific scenarios belong in +[Open Modbus Catalog](https://github.com/top-maker/open-modbus-catalog), targeting +its `main` through a PR and required catalog CI. Do not add editable device copies +here. A new model submission needs an executable TM and source/permission/known +limits; maintainers can help complete metadata. Never include private endpoints, credentials or customer data in public inputs. The model-source lock and downloader are consumers of immutable public data. -For a data update, resolve the release tag to its full SHA, review every file and -hash, update examples/model-source.yaml through a PR, run the downloader, then +For a data update, pin the full catalog commit, review every file and hash, update examples/model-source.yaml through a PR, run the downloader, then run affected simulator/client tests. The tests/fixtures tree is a frozen runtime regression fixture, not a contribution catalog. Generated TD fixtures are regenerated by tools/generate-td.py, never hand edited. diff --git a/Dockerfile b/Dockerfile index a1da322..faeb19e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,7 @@ RUN uv sync --locked --no-dev --no-install-project # Copy Python app to the Docker image COPY modsim /app/modsim/ COPY examples /app/examples +COPY tests/fixtures/io-module /app/tests/fixtures/io-module COPY examples/deployment.yaml /app/deployment.yaml COPY tools/fetch-models.py /app/tools/fetch-models.py RUN .venv/bin/python tools/fetch-models.py diff --git a/README.md b/README.md index 0cc6b27..822e69a 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,9 @@ uv run modsim ps The commands use `examples/deployment.yaml` by default. The example starts two virtual ADAM devices: Unit 1 exposes ADAM-5017UH raw inputs; Unit 2 exposes ADAM-6024 raw I/O with synthetic AO→AI and DO→DI loopback. These are simulation -values, not verified physical measurements. Models, scenarios and source -information are in [modbus-models](https://github.com/top-maker/modbus-models). +values, not verified physical measurements. The ADAM-5017UH model and scenario +come from [Open Modbus Catalog](https://github.com/top-maker/open-modbus-catalog); +the ADAM-6024 model is a frozen regression fixture in `tests/fixtures/io-module/`. The deployment binds to all interfaces by default; set `server.bind` to `127.0.0.1` in `examples/deployment.yaml` to restrict a direct local run. @@ -174,9 +175,9 @@ For a single device without a managed deployment: ```bash uv run python tools/fetch-models.py -uv run modsim --config examples/models/advantech/adam-5017uh/adam-5017uh.tm.json \ +uv run modsim --config examples/models/devices/advantech/adam-5017uh/models/adam-5017uh.tm.json \ --unit-id 1 --port 5020 \ - --scenario examples/models/advantech/adam-5017uh/simulation/adam-5017uh.sim.json + --scenario examples/models/devices/advantech/adam-5017uh/simulation/adam-5017uh.sim.json ``` The single-device model runtime currently supports TCP. The unconfigured demo @@ -195,10 +196,10 @@ source change. ## Pinned public model inputs -Device data and optional scenarios are maintained only in -[modbus-models](https://github.com/top-maker/modbus-models). -`examples/model-source.yaml` pins data release `modbus-models-v2` to its full -commit and individual SHA-256 hashes. Prepare examples with +Device data and optional scenarios are maintained in +[Open Modbus Catalog](https://github.com/top-maker/open-modbus-catalog). +`examples/model-source.yaml` pins a full catalog commit and individual SHA-256 +hashes. Prepare examples with `uv run python tools/fetch-models.py`; this downloads verified local inputs to ignored `examples/models/`, never executes downloaded Python, and does not copy an interpreter. Re-run after updating the lock through a reviewed PR. diff --git a/contrib/README.md b/contrib/README.md index 19b212e..a328dc9 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -1,11 +1,8 @@ # Device data moved -The active model contribution source is -[modbus-models](https://github.com/top-maker/modbus-models). +Device models are maintained in +[Open Modbus Catalog](https://github.com/top-maker/open-modbus-catalog). Use its contribution guide and target main. This directory no longer accepts model edits. Historical commits and published releases are unchanged. -The initial curated data release contains two ADAM models; other former catalog -entries remain historical, pending source/redistribution review. See the -[fixed migration inventory](https://github.com/top-maker/modbus-models/blob/2493526acc6645393b3ebb3f32279167a88d6f41/schemas/migration.yaml). Prepare current examples using tools/fetch-models.py and examples/model-source.yaml. diff --git a/docs/preview-notes.md b/docs/preview-notes.md index aaaef8f..8659838 100644 --- a/docs/preview-notes.md +++ b/docs/preview-notes.md @@ -10,7 +10,8 @@ selected read spans. #### Modsim 2.0.0a2 This candidate uses published modpoll-wot 0.2.0a2 and immutable modbus-models-v1 -inputs. Device mappings and contribution workflows now live in modbus-models; +inputs. Device mappings and contribution workflows moved to a data repository, +now [Open Modbus Catalog](https://github.com/top-maker/open-modbus-catalog); examples pin a full data commit and individual content hashes. Vendor originals are not copied. The tool and data releases remain independent. diff --git a/examples/deployment.yaml b/examples/deployment.yaml index b1f3a3b..0a04672 100644 --- a/examples/deployment.yaml +++ b/examples/deployment.yaml @@ -5,16 +5,16 @@ server: port: 5020 devices: - id: adam-5017uh - model: examples/models/advantech/adam-5017uh/adam-5017uh.tm.json + model: examples/models/devices/advantech/adam-5017uh/models/adam-5017uh.tm.json parameters: THING_ID: urn:modsim:device:advantech:adam-5017uh UNIT_ID: 1 HOST: 127.0.0.1 - scenario: examples/models/advantech/adam-5017uh/simulation/adam-5017uh.sim.json + scenario: examples/models/devices/advantech/adam-5017uh/simulation/adam-5017uh.sim.json - id: adam-6024 - model: examples/models/advantech/adam-6024/adam-6024.tm.json + model: tests/fixtures/io-module/adam-6024.tm.json parameters: THING_ID: urn:modsim:device:advantech:adam-6024 UNIT_ID: 2 HOST: 127.0.0.1 - scenario: examples/models/advantech/adam-6024/simulation/adam-6024.sim.json + scenario: tests/fixtures/io-module/simulation/adam-6024.sim.json diff --git a/examples/model-source.yaml b/examples/model-source.yaml index 6ee3ec7..802ff67 100644 --- a/examples/model-source.yaml +++ b/examples/model-source.yaml @@ -1,15 +1,6 @@ -repository: top-maker/modbus-models -release: modbus-models-v2 -revision: db8cf19a2b58bcfc3b45319caa2d386d5ab5cacd -profile: '0.2' -interpreter: 0.2.0a2 +repository: top-maker/open-modbus-catalog +revision: f4e1f9cdb39d886e11e1f9aa5345828128b3aaca files: - advantech/adam-5017uh/adam-5017uh.tm.json: 9e1d6e38dbb4e2db2f30f8dfd3d9df90a349b2e9aeb60a168ae4d60ee709ead7 - advantech/adam-5017uh/simulation/adam-5017uh-behavior.py: b1ec8ff3d0fe6e32127f587d5049523584adef479509f90c004c010f3ceeb789 - advantech/adam-5017uh/simulation/adam-5017uh-scripted-analog-input.sim.json: efbd727d253febdb8e816e70a07e2314f2110f47e705eca8e942e0948c80417e - advantech/adam-5017uh/simulation/adam-5017uh.sim.json: 246e0eaf9234aaec6c85c63497a27bbd89c132e436345636c9cdba8969fd3c9f - advantech/adam-6024/adam-6024.tm.json: 4c2aee3334faf6622f4ee34a23108fa0ec100a6b3110a78200eee79da8935596 - advantech/adam-6024/simulation/adam-6024.sim.json: 2beb25195324919b10710d24dbdad93d9e3d4a37e857824faedf9246296c1cc0 - advantech/adam-5017uh/simulation/interop-inputs.sim.json: dd10b90523317122ea8b70cf21b7417bd60b688ea5b12e36fb798d9e2a6d5a58 - advantech/adam-5017uh/evidence/l2-check.yaml: a5f83e77acb60bf2cd5359523ad3fe76b0fae4adb90703b8f09a9dddad9a883b - schemas/evidence-schema.yaml: ecfbecbd89ab599f842357994239c67097e92983e0ffacfef2fa3615b27c5837 + devices/advantech/adam-5017uh/models/adam-5017uh.tm.json: 9e1d6e38dbb4e2db2f30f8dfd3d9df90a349b2e9aeb60a168ae4d60ee709ead7 + devices/advantech/adam-5017uh/models/adam-5017uh.vectors.json: a76f365ae333b78e8113227940e15cc52e527962d676d62754d6211b184e22eb + devices/advantech/adam-5017uh/simulation/adam-5017uh.sim.json: 246e0eaf9234aaec6c85c63497a27bbd89c132e436345636c9cdba8969fd3c9f diff --git a/tests/fixtures/io-module/README.md b/tests/fixtures/io-module/README.md index 807d953..7a39778 100644 --- a/tests/fixtures/io-module/README.md +++ b/tests/fixtures/io-module/README.md @@ -2,5 +2,5 @@ Frozen MIT model/scenario/TD used only for protocol and codec regression. Not a device contribution or independently maintained product mapping. -The canonical product lives in top-maker/modbus-models; generated TDs are checked -by tools/generate-td.py. Do not use this fixture as a model contribution target. +It also serves as the ADAM-6024 device in examples/deployment.yaml. Generated +TDs are checked by tools/generate-td.py. Do not use this fixture as a model contribution target. diff --git a/tests/test_catalog_platform.py b/tests/test_catalog_platform.py index 0681249..f90fad4 100644 --- a/tests/test_catalog_platform.py +++ b/tests/test_catalog_platform.py @@ -22,7 +22,7 @@ def test_remote_model_single_device_read_and_stop(tmp_path): lock = yaml.safe_load( (Path(__file__).resolve().parents[1] / "examples/model-source.yaml").read_text() ) - url = f"https://raw.githubusercontent.com/{lock['repository']}/{lock['revision']}/advantech/adam-5017uh/adam-5017uh.tm.json" + url = f"https://raw.githubusercontent.com/{lock['repository']}/{lock['revision']}/devices/advantech/adam-5017uh/models/adam-5017uh.tm.json" scenario = tmp_path / "initial.sim.json" values = [0x1234, 0x8001, 0xABCD, 0, 65535, 42, 0x0102, 0xFE01] scenario.write_text( diff --git a/tools/catalog-interop.py b/tools/catalog-interop.py index ff4f3a2..4f2474b 100644 --- a/tools/catalog-interop.py +++ b/tools/catalog-interop.py @@ -20,7 +20,7 @@ import yaml ROOT = Path(__file__).resolve().parents[1] -MODEL = "advantech/adam-5017uh/adam-5017uh.tm.json" +MODEL = "devices/advantech/adam-5017uh/models/adam-5017uh.tm.json" VALUES = [0x1234, 0x8001, 0xABCD, 0, 65535, 42, 0x0102, 0xFE01] EXPECTED = {f"AI{i}_RAW": value for i, value in enumerate(VALUES)} @@ -76,17 +76,17 @@ def run(args): port = reserve.getsockname()[1] with TemporaryDirectory(prefix="modsim-catalog-interop-") as temporary: work = Path(temporary) - if args.scenario: - scenario = args.scenario.resolve() - if json.loads(scenario.read_bytes()) != { - "version": "1", - "initial": EXPECTED, - }: - raise ValueError("Scenario differs from independent expected vector") - else: - scenario = work / "initial.sim.json" - scenario.write_text(json.dumps({"version": "1", "initial": EXPECTED})) - scenario_digest = hashlib.sha256(scenario.read_bytes()).hexdigest() + if args.vectors and json.loads(args.vectors.read_bytes()) != EXPECTED: + raise ValueError( + "Catalog vectors differ from the independent expected vector" + ) + scenario = work / "initial.sim.json" + scenario.write_text(json.dumps({"version": "1", "initial": EXPECTED})) + vectors_digest = ( + hashlib.sha256(args.vectors.read_bytes()).hexdigest() + if args.vectors + else None + ) env = dict(os.environ) env.pop("PYTHONPATH", None) with (work / "simulator.log").open("w+") as log: @@ -206,7 +206,7 @@ def run(args): report = { "executed-at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"), "data-revision": revision, - "scenario-sha256": scenario_digest, + "vectors-sha256": vectors_digest, "td-sha256": td_digest, "td-endpoint": { "host": "127.0.0.1", @@ -241,7 +241,7 @@ def run(args): args.output.parent.mkdir(parents=True, exist_ok=True) args.output.write_text(json.dumps(report, indent=2) + "\n") print( - "Catalog L2 subset passed: raw wire, published modpoll, node-wot, wrong-byte-order rejection, shutdown" + "Catalog interoperability passed: raw wire, published modpoll, node-wot, wrong-byte-order rejection, shutdown" ) @@ -251,9 +251,9 @@ def run(args): "--lock", type=Path, default=ROOT / "examples/model-source.yaml" ) parser.add_argument( - "--scenario", + "--vectors", type=Path, - help="Fixed local input with the independent known vector", + help="Catalog vectors file that must equal the independent known vector", ) parser.add_argument("--modpoll-python", type=Path, required=True) parser.add_argument("--node-reader", type=Path, required=True)