Skip to content
This repository was archived by the owner on Nov 15, 2026. It is now read-only.
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
9 changes: 1 addition & 8 deletions .github/workflows/acceptance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,9 @@ 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 --vectors "$RUNNER_TEMP/catalog-acceptance/inputs/products/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 --vectors "$RUNNER_TEMP/catalog-acceptance/inputs/products/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"
"$RUNNER_TEMP/modsim/bin/python" tools/catalog-interop.py --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"
- uses: actions/upload-artifact@v4
with:
name: catalog-interop
path: |
${{ runner.temp }}/catalog-interop.json
${{ runner.temp }}/catalog-interop-released.json
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ jobs:
- name: Test with tox
run: uv run --locked --no-sync tox -e ${{ matrix.tox-env }}

snapshot-replay:
name: modpoll snapshot replay
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4

- name: Set up uv and Python
uses: ./.github/actions/setup-uv

- name: Install an independent released modpoll
run: |
uv venv "$RUNNER_TEMP/modpoll"
uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" 'modpoll==2.0.0a5'

- name: Export with modpoll and replay with modsim
env:
MODSIM_TEST_MODPOLL_PYTHON: ${{ runner.temp }}/modpoll/bin/python
run: uv run --locked pytest tests/test_snapshot_replay.py -v

docs:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to modsim

Simulator code, runtime and scenario language changes target the affected tool
Simulator code, runtime and simulation data changes target the affected tool
line (`v2` for model-driven development). Run relevant checks from the root:

```sh
Expand All @@ -11,7 +11,7 @@ uv run python tools/generate-td.py --check
uv run --group docs mkdocs build -s
```

Device TMs, metadata, sources and product-specific scenarios belong in
Device TMs, metadata, sources and product-specific simulation data 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
Expand Down
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
modsim is a standalone Modbus simulator for device integration and testing.
The v2 development source reads WoT Thing Models (TM), instantiates device
descriptions (TD), and runs independent simulated devices on one Modbus TCP
listener. Models, scenarios, the simulator and the client remain separate.
listener. Models, simulation data, the simulator and the client remain separate.

This README describes the **v2 development branch**. The published `2.0.0a1`
preview predates the managed deployment commands shown below; do not assume an
Expand Down Expand Up @@ -35,7 +35,7 @@ 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. The ADAM-5017UH model and scenario
values, not verified physical measurements. The ADAM-5017UH model and simulation data
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/`.

Expand Down Expand Up @@ -84,7 +84,7 @@ container unless stopped. Each restart resets simulation state. TDs advertise
`127.0.0.1` by default; configure the advertised host and port mapping when
clients connect from another machine.

The deployment and model/scenario files are mounted from the repository.
The deployment, model and simulation data files are mounted from the repository.
`docker compose up -d` starts the configured deployment; do not run `modsim up`
again just to start it. After editing the mounted deployment file, apply the
updated configuration to the running simulator with:
Expand Down Expand Up @@ -162,22 +162,33 @@ Stop modpoll with Ctrl+C, stop the broker if used (`docker stop
modpoll-demo-mqtt`), then stop modsim with `uv run modsim down` or stop the
Compose deployment with `docker compose down`.

## Models and scenarios
## Models and simulation data

A deployment has a stable ID per device, a TM path, instance parameters and an
optional scenario. TD IDs and Modbus Unit IDs must be unique. Scenarios define
initial values, seeded generators and bindings; local Python behavior requires
`--allow-scripts`. They do not duplicate the Thing Model's point mappings. See
A deployment has a stable ID per device, a TM path, instance parameters and
optional simulation data. TD IDs and Modbus Unit IDs must be unique.
[Simulation data](https://github.com/top-maker/modpoll-wot/blob/main/profile.md#simulation-data)
gives static initial values, seeded generators and bindings, and carries no
code; a local Python behavior is a separate `script` that requires
`--allow-scripts`. Neither duplicates the Thing Model's point mappings. See
[model configuration](docs/site/model-validation.md) for the supported profile,
codecs, constraints and behavior hooks.

For a single device without a managed deployment:

```bash
uv run python tools/fetch-models.py
uv run modsim --config examples/models/products/advantech/adam-5017uh/models/adam-5017uh.tm.json \
uv run modsim --config examples/models/products/advantech/adam-5017uh/model.tm.json \
--unit-id 1 --port 5020 \
--scenario examples/models/products/advantech/adam-5017uh/simulation/adam-5017uh.sim.json
--data examples/models/products/advantech/adam-5017uh/model.sim.json
```

A modpoll `--export` snapshot is simulation data too, so a device read once can
be replayed locally. Snapshots hold readings of a real device; keep them on
your computer:

```bash
modpoll --config device.tm.json --tcp 192.168.1.10 --once --export snapshot.json
uv run modsim --config device.tm.json --port 5020 --data snapshot.json
```

Without `--port`, modsim listens on 502, the standard Modbus TCP port, so
Expand All @@ -203,17 +214,17 @@ source change.

## Pinned public model inputs

Device data and optional scenarios are maintained in
Device models and optional simulation data 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.
The application keeps its independent modpoll-wot 0.2.0a2 dependency.
The application keeps its independent modpoll-wot dependency.

Single-device mode can read a fixed HTTPS TM URL directly. Optional scenarios
remain local; scripts require explicit `--allow-scripts`. Managed deployments
Single-device mode can read a fixed HTTPS TM URL and simulation data directly;
scripts stay local and require explicit `--allow-scripts`. Managed deployments
use Unix sockets and require POSIX; native Windows should use single-device
foreground mode or WSL. Independent-wheel CI verifies single-device remote-TM
startup, raw reads and process shutdown on Linux, macOS and native Windows.
Expand Down
31 changes: 28 additions & 3 deletions docs/preview-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# Modsim 2.0.0a6 preview
# Modsim 2.0.0a7 preview

Modsim 2.0.0a7 loads [simulation data](https://github.com/top-maker/modpoll-wot/blob/main/profile.md#simulation-data)
with `--data` and pins modpoll-wot 0.4.0a1. This preview breaks the previous
command line:

- `--scenario` becomes `--data`; deployment devices use `data:` instead of
`scenario:`.
- `--initial-file` is removed: put the values in a data document's `initial`.
- Simulation data carries no code. Behavior scripts move out of the data file
to `--script` (with `--allow-scripts`) or a deployment device's `script:`,
and their values to the device's `scriptParameters:`.
- A modpoll `--export` snapshot is simulation data, so a device read once can
be replayed on this computer:

```sh
uvx --prerelease allow modpoll==2.0.0a6 --config device.tm.json --tcp 192.168.1.10 --once --export snapshot.json
uvx --prerelease allow modsim==2.0.0a7 --config device.tm.json --data snapshot.json
```

Scaled values that modpoll exports, such as `230.10000000000002` for a raw
2301 with multiplier 0.1, are served again unchanged. Snapshot points modpoll
could not read keep their defaults and are listed at startup. Snapshots hold
readings of a real device: keep them on your computer.

### Previous preview

#### Modsim 2.0.0a6

Modsim 2.0.0a6 pins modpoll-wot 0.3.0a3, the same interpreter as modpoll
2.0.0a5. Thing Models no longer carry a `modpoll:audit` plan: a TM that still
Expand All @@ -10,8 +37,6 @@ ports and remote loading are unchanged from 2.0.0a5:
uvx --prerelease allow modsim==2.0.0a6 --config https://example.org/device.tm.json
```

### Previous preview

#### Modsim 2.0.0a5

Without `--port`, modsim now listens on the standard Modbus port: 502 for TCP
Expand Down
2 changes: 1 addition & 1 deletion docs/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ images. Record the separate validation run and tooling SHA.
### Known-value checks

Use the approved TM as the configuration for a local TCP simulator. Seed known
values with `--initial PROPERTY=JSON` or `--initial-file`, then read them with
values with `--initial PROPERTY=JSON` or `--data` with an `initial` object, then read them with
a full modpoll read. Thing Models no longer carry a `modpoll:audit` plan; a
full read covers every property in `modpoll:acquisition`.

Expand Down
4 changes: 2 additions & 2 deletions docs/site/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# modsim v2 development source

modsim runs simulated Modbus devices for development and integration testing.
The current source supports profile 0.2 TM/TD input, scenarios and independent
The current source supports profile 0.2 TM/TD input, simulation data and independent
devices on a single managed Modbus TCP listener. The published `2.0.0a1`
preview does not include all current managed commands; see
[preview notes](https://github.com/top-maker/modsim/blob/v2/docs/preview-notes.md).
Expand Down Expand Up @@ -32,6 +32,6 @@ The CLI rejects non-default `--store` and the unsupported `--slaves` and

## More information

- [Model-driven simulation](model-validation.md): TM/TD, codecs and scenarios.
- [Model-driven simulation](model-validation.md): TM/TD, codecs and simulation data.
- [Managed deployments](managed-deployments.md): YAML, lifecycle and export.
- [Modules](modules.md): API reference.
30 changes: 15 additions & 15 deletions docs/site/managed-deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ server:
port: 5020
devices:
- id: adam-5017uh
model: examples/models/advantech/adam-5017uh/adam-5017uh.tm.json
model: examples/models/products/advantech/adam-5017uh/model.tm.json
parameters:
THING_ID: urn:modsim:example:adam-5017uh
UNIT_ID: 1
scenario: examples/models/advantech/adam-5017uh/simulation/adam-5017uh.sim.json
data: examples/models/products/advantech/adam-5017uh/model.sim.json
```

`devices` may be empty. IDs and deployment names use lowercase letters, digits
and hyphens, starting with a letter or digit (maximum 64 characters). Device IDs,
instantiated TD IDs and Unit IDs must each be unique within the deployment.
Paths in the repository example resolve from the project root; for standalone
deployments, model and scenario paths resolve relative to the deployment file. Scripts
resolve relative to their scenario file. Models may also use bounded HTTPS URLs. Pin remote model revisions
deployments, model, data and script paths resolve relative to the deployment file.
Models may also use bounded HTTPS URLs. Pin remote model revisions
for repeatable runs.

Each device contains only `id`, `model`, optional `parameters` and optional
`scenario`. A model must be a profile 0.2 TM. Its instantiated TD must have a
Each device contains only `id`, `model`, and optional `parameters`, `data`,
`script` and `scriptParameters` (values a script reads as `device.parameters`). A model must be a profile 0.2 TM. Its instantiated TD must have a
stable URI `id`. Supply `THING_ID` when the TM declares that placeholder or has no `id`.
The deployment device ID selects management operations; the TD ID identifies the
Thing; Unit ID selects the device in Modbus requests. A device's TD ID cannot
Expand All @@ -78,19 +78,19 @@ The deployment format is a Modsim contract, not a standard TD object. TD generat
uses `modpoll-wot==0.2.0a2` and its bundled TD/Modbus/profile validation. There is
no private TD parser or arbitrary TD patch mechanism.

Scenarios keep their existing version `"1"` schema, including `initial`, generators,
bindings, seed, tick and optional local behavior scripts. Both JSON and YAML
scenario documents are accepted by managed deployments. There is no duplicate
initial-value field in deployment v2. Omitting a scenario produces valid static
initial values from the model. Scenario state is not exported as TD defaults.
`data` names [simulation data](model-validation.md#simulation-data) or a modpoll
snapshot. Both JSON and YAML documents are accepted by managed deployments.
There is no duplicate initial-value field in deployment v2. Omitting data
produces valid static initial values from the model. Simulation data is not
exported as TD defaults.

Deployment files must use the `.yaml` or `.yml` extension. YAML uses safe loading with a 1 MiB document limit, bounded nesting and JSON
compatible values; aliases, duplicate keys, implicit dates and non-finite numbers
are rejected. Use quoted strings where YAML scalar inference is inappropriate.

## Update and reset behavior

Before changing a runtime, `up` validates every model and scenario and initializes
Before changing a runtime, `up` validates every model and data document and initializes
all new or changed candidates. An invalid candidate leaves the live device set
unchanged. This guarantee covers simulator state, not external side effects in
explicitly enabled Python scripts.
Expand All @@ -99,7 +99,7 @@ explicitly enabled Python scripts.
and script state. Repeating `up` does not rerun their initialization hooks.
* New IDs create independent devices. Removed IDs stop their tasks. Removing the
last device leaves the listener available for a subsequent `up`.
* Changed model, parameters, scenario or behavior source replaces that device and
* Changed model, parameters, data or behavior source replaces that device and
resets its state. Changes are detected by content, not just file paths.
* Listener changes require `down` followed by `up`.

Expand Down Expand Up @@ -129,7 +129,7 @@ during a real application of the update.

In managed mode, a periodic behavior failure takes that device offline and marks
it failed in `ps`; other devices continue. Repeated unchanged `up` preserves that
failure status. Use `reset` to retry or change the scenario and run `up`. The legacy
failure status. Use `reset` to retry or change the data or script and run `up`. The legacy
flag-based startup retains its existing process-wide failure behavior.

## TD export
Expand All @@ -144,7 +144,7 @@ By default, `modsim export` writes every TD to `output/` in the project root.
The directory is ignored by Git. `--output-dir` changes the destination.

Offline export reads the deployment, instantiates its TMs and validates the TDs;
it needs no running process or scenario files and never executes behavior scripts. `--running`
it needs no running process or data files and never executes behavior scripts. `--running`
exports the last successfully applied TDs, so pending file edits cannot be
mistaken for the active configuration. TD export describes interfaces and
advertised endpoints, not current register values or a runtime snapshot.
Expand Down
Loading
Loading