-
Notifications
You must be signed in to change notification settings - Fork 987
Feature/add simulator api skeleton #2274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
janiversen
merged 19 commits into
pymodbus-dev:dev
from
efdx:feature/add-simulator-api-skeleton
Aug 24, 2024
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5159b80
pytest: Change default event_loop scope
efdx e5f6759
simulator-api: Change json endpoints to restapi
efdx 9258bee
simulator-api: Change json endpoint names
efdx 3abe685
simulator-api: Fix json endpoint base
efdx b0b0be2
simulator-api: Remove generated dict from json
efdx 91a5c16
simulator-api: Remove endpoint json dict usage
efdx 4b72280
simulator-api: Use aiohttp json data and response
efdx 5cee66a
simulator-api: Report unhandled errors as json
efdx 3fb55e3
simualtor-api: Rename page_type in handle_json
efdx d38f393
simulator-api: Change submit handling html specific
efdx f5084af
simulator-api: Implement registers json endpoint
efdx 0e9a935
simulator-api: Add calls_json endpoint
efdx 0d51303
simulator-api: Mark unimplemented json endpoints
efdx 759f486
tests: Add a base for testing simulator API
efdx f17a0dc
tests: Add json_registers endpoint tests
efdx 19c7c04
tests: Add json_calls endpoint tests
efdx 333c98b
tests: Add some placeholder json endpoint tests
efdx 9fa8808
docs: Add simulator REST API documentation
efdx 25e593c
Update doc/source/library/simulator/restapi.rst
janiversen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.. code-block:: json | ||
{ | ||
"submit": "Simulate" | ||
"response_clear_after": 0, | ||
"response_cr": "", | ||
"response_cr_pct": 0, | ||
"response_split": "", | ||
"split_delay": 1 | ||
"response_delay": 0, | ||
"response_error": 0, | ||
"response_junk_datalen": 0, | ||
"response_type": 0, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
.. code-block:: json | ||
{ | ||
"simulation_action": "ACTIVE", | ||
"range_start": null, | ||
"range_stop": null, | ||
"function_codes": [ | ||
{ | ||
"value": 3, | ||
"text": "read_holding_registers", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 2, | ||
"text": "read_discrete_input", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 4, | ||
"text": "read_input_registers", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 1, | ||
"text": "read_coils", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 15, | ||
"text": "write_coils", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 16, | ||
"text": "write_registers", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 6, | ||
"text": "write_register", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 5, | ||
"text": "write_coil", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 23, | ||
"text": "read_write_multiple_registers", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 8, | ||
"text": "diagnostic_status", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 7, | ||
"text": "read_exception_status", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 11, | ||
"text": "get_event_counter", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 12, | ||
"text": "get_event_log", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 17, | ||
"text": "report_slave_id", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 20, | ||
"text": "read_file_record", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 21, | ||
"text": "write_file_record", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 22, | ||
"text": "mask_write_register", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 24, | ||
"text": "read_fifo_queue", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 43, | ||
"text": "read_device_information", | ||
"selected": false | ||
} | ||
], | ||
"function_show_hex_checked": false, | ||
"function_show_decoded_checked": false, | ||
"function_response_normal_checked": true, | ||
"function_response_error_checked": false, | ||
"function_response_empty_checked": false, | ||
"function_response_junk_checked": false, | ||
"function_response_split_checked": true, | ||
"function_response_split_delay": 1, | ||
"function_response_cr_checked": false, | ||
"function_response_cr_pct": 0, | ||
"function_response_delay": 0, | ||
"function_response_junk": 0, | ||
"function_error": [ | ||
{ | ||
"value": 1, | ||
"text": "IllegalFunction", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 2, | ||
"text": "IllegalAddress", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 3, | ||
"text": "IllegalValue", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 4, | ||
"text": "SlaveFailure", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 5, | ||
"text": "Acknowledge", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 6, | ||
"text": "SlaveBusy", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 7, | ||
"text": "MemoryParityError", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 10, | ||
"text": "GatewayPathUnavailable", | ||
"selected": false | ||
}, | ||
{ | ||
"value": 11, | ||
"text": "GatewayNoResponse", | ||
"selected": false | ||
} | ||
], | ||
"function_response_clear_after": 1, | ||
"call_rows": [], | ||
"foot": "not active", | ||
"result": "ok" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. code-block:: json | ||
{ | ||
"range_start": 16, | ||
"range_end": 16, | ||
"submit": "Register" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.. code-block:: json | ||
{ | ||
"result": "ok", | ||
"footer": "Operation completed successfully", | ||
"register_types": { | ||
"bits": 1, | ||
"uint16": 2, | ||
"uint32": 3, | ||
"float32": 4, | ||
"string": 5, | ||
"next": 6, | ||
"invalid": 0 | ||
}, | ||
"register_actions": { | ||
"null": 0, | ||
"increment": 1, | ||
"random": 2, | ||
"reset": 3, | ||
"timestamp": 4, | ||
"uptime": 5 | ||
}, | ||
"register_rows": [ | ||
{ | ||
"index": "16", | ||
"type": "uint16", | ||
"access": "True", | ||
"action": "none", | ||
"value": "3124", | ||
"count_read": "0", | ||
"count_write": "0" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,120 @@ | ||
Pymodbus simulator ReST API | ||
=========================== | ||
|
||
TO BE DOCUMENTED. | ||
This is still a Work In Progress. There may be large changes to the API in the | ||
future. | ||
|
||
There is a skeleton API for the Pymodbus simulator. The API is a simple copy of | ||
having most of the same features as in the Web UI. | ||
|
||
The API provides the following endpoints: | ||
|
||
- /restapi/registers | ||
- /restapi/calls | ||
- /restapi/server | ||
- /restapi/log | ||
|
||
Registers Endpoint | ||
------------------ | ||
|
||
/restapi/registers | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
The registers endpoint is used to read and write registers. | ||
|
||
**Request Parameters** | ||
|
||
- `submit` (string, required): | ||
The action to perform. Must be one of `Register`, `Set`. | ||
- `range_start` (integer, optional): | ||
The starting register to read from. Defaults to 0. | ||
- `range_end` (integer, optional): | ||
The ending register to read from. Defaults to `range_start`. | ||
|
||
**Response Parameters** | ||
|
||
Returns a json object with the following keys: | ||
|
||
- `result` (string): | ||
The result of the action. Either `ok` or `error`. | ||
- `error` (string, conditional): | ||
The error message if the result is `error`. | ||
- `register_rows` (list): | ||
A list of objects containing the data of the registers. | ||
- `footer` (string): | ||
A cleartext status of the action. HTML leftover. | ||
- `register_types` (list): | ||
A static list of register types. HTML leftover. | ||
- `register_actions` (list): | ||
A static list of register actions. HTML leftover. | ||
|
||
**Example Request and Response** | ||
|
||
Request Example: | ||
|
||
.. include:: registers_request.rst | ||
|
||
Response Example: | ||
|
||
.. include:: registers_response.rst | ||
|
||
Calls Endpoint | ||
-------------- | ||
|
||
The calls endpoint is used to handle ModBus response manipulation. | ||
|
||
/restapi/calls | ||
^^^^^^^^^^^^^^ | ||
|
||
The calls endpoint is used to simulate different conditions for ModBus | ||
responses. | ||
|
||
**Request Parameters** | ||
|
||
- `submit` (string, required): | ||
The action to perform. Must be one of `Simulate`, `Reset`. | ||
|
||
The following must be present if `submit` is `Simulate`: | ||
|
||
- `response_clear_after` (integer, required): | ||
The number of packet to clear simulation after. | ||
- `response_cr` (string, required): | ||
Must be present but can be any value. Turns on change rate simulation (WIP). | ||
- `response_cr_pct` (integer, required): | ||
The percentage of change rate, how many percent of packets should be | ||
changed. | ||
- `response_split` (string, required): | ||
Must be present but can be any value. Turns on split response simulation (WIP). | ||
- `split_delay` (integer, required): | ||
The delay in seconds to wait before sending the second part of the split response. | ||
- `response_delay` (integer, required): | ||
The delay in seconds to wait before sending the response. | ||
- `response_error` (integer, required): | ||
The error code to send in the response. The valid values can be one from | ||
the response `function_error` list. | ||
|
||
When `submit` is `Reset`, no other parameters are required. It resets all | ||
simulation options to their defaults (off). | ||
|
||
**Example Request and Response** | ||
|
||
Request: | ||
|
||
.. include:: calls_request.rst | ||
|
||
Response: | ||
|
||
Unfortunately, the endpoint response contains extra clutter due to | ||
not being finalized. | ||
|
||
.. include:: calls_response.rst | ||
|
||
Server Endpoint | ||
--------------- | ||
|
||
The server endpoint has not yet been implemented. | ||
|
||
Log Endpoint | ||
------------ | ||
|
||
The log endpoint has not yet been implemented. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.