Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
449 lines (430 loc) · 14.6 KB
/
Copy pathopenapi.yaml
File metadata and controls
449 lines (430 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
openapi: 3.1.0
info:
title: MTUI HTTP API
description: |
HTTP API exposed by MTUI for reading and writing Modbus
registers on the currently connected device, sending raw function
codes, plus a health probe.
The server binds to `0.0.0.0` on a configurable port and proxies requests
to the live Modbus device backing the TUI. When no device is connected,
register operations return `503 Service Unavailable`.
version: 1.0.0
license:
name: GPL-2.0-only
identifier: GPL-2.0-only
servers:
- url: http://{host}:{port}
description: mtui API server
variables:
host:
default: localhost
port:
default: "8080"
description: Configured API port (set in mtui; 0 selects an ephemeral port)
paths:
/read:
post:
summary: Read registers or bits
description: |
Reads `count` items of the given `type` starting at `address` from the
connected device. `holding` and `input` return raw 16-bit values;
`coil` and `discrete` return `0` or `1` per bit.
An optional `unit_id` targets a specific Modbus unit for this
request only; the device's configured unit is restored afterwards.
When omitted, the configured unit is used. Specifying `unit_id`
requires the "API unit id override" setting to be enabled; otherwise
the request is rejected with `403`.
operationId: readRegisters
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ReadRequest"
examples:
holdings:
summary: Read 4 holding registers from address 0
value:
type: holding
address: 0
count: 4
coils:
summary: Read 8 coils from address 0
value:
type: coil
address: 0
count: 8
unit:
summary: Read 2 holding registers from unit 5
value:
type: holding
address: 0
count: 2
unit_id: 5
responses:
"200":
description: Values read successfully
content:
application/json:
schema:
$ref: "#/components/schemas/ReadResponse"
examples:
registers:
summary: holding/input register values
value:
values: [230, 0, 4998, 12]
bits:
summary: coil/discrete values (0 or 1)
value:
values: [1, 1, 1, 1, 0, 1, 1, 0]
"403":
description: |
A `unit_id` was specified but the "API unit id override" setting
is disabled.
"503":
description: No device is currently connected
"502":
description: The device read failed (Modbus / transport error)
content:
application/json:
schema:
$ref: "#/components/schemas/FailureResponse"
/write:
post:
summary: Write registers or coils
description: |
Writes one or more consecutive items starting at `address`. The
`type` selects `holding` (16-bit registers) or
`coil` (bits, where `0` is off and any non-zero value is on).
Read-only types (`input`, `discrete`) are rejected with `400`, and
all writes are rejected with `403` when the server is in read-only
mode.
An optional `unit_id` targets a specific Modbus unit for this
request only; the device's configured unit is restored afterwards.
When omitted, the configured unit is used. Specifying `unit_id`
requires the "API unit id override" setting to be enabled; otherwise
the request is rejected with `403`.
operationId: writeRegisters
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/WriteRequest"
examples:
single:
summary: Write one holding register
value:
type: holding
address: 50
values: [1234]
multiple:
summary: Write three consecutive holding registers
value:
type: holding
address: 50
values: [1234, 5678, 9012]
coils:
summary: Write three consecutive coils (on, off, on)
value:
type: coil
address: 0
values: [1, 0, 1]
unit:
summary: Write one holding register to unit 5
value:
type: holding
address: 50
values: [1234]
unit_id: 5
responses:
"204":
description: Values written successfully (no body)
"400":
description: The requested type is read-only (input or discrete)
"403":
description: |
The write is forbidden: the server is in read-only mode, or a
`unit_id` was specified while the "API unit id override" setting
is disabled.
"503":
description: No device is currently connected
"502":
description: The device write failed (Modbus / transport error)
content:
application/json:
schema:
$ref: "#/components/schemas/FailureResponse"
/raw:
post:
summary: Send a raw Modbus function
description: |
Sends an arbitrary function `code` with `data` as the request bytes
and returns the bytes the device answered with. Nothing is
interpreted on either side.
The endpoint is disabled by default and every request is rejected
with `501` until the "API raw function" setting is enabled. Read-only
mode does not apply here: the server cannot tell whether a raw
function writes, so enabling the setting is the opt-in.
An optional `unit_id` targets a specific Modbus unit for this
request only; the device's configured unit is restored afterwards.
When omitted, the configured unit is used. Specifying `unit_id`
requires the "API unit id override" setting to be enabled; otherwise
the request is rejected with `422`.
operationId: rawFunction
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/RawRequest"
examples:
diagnostics:
summary: Diagnostics (0x08) return query data
value:
code: 8
data: [0, 0, 18, 52]
report_server_id:
summary: Report server id (0x11) without data
value:
code: 17
unit:
summary: Diagnostics (0x08) sent to unit 5
value:
code: 8
data: [0, 0, 18, 52]
unit_id: 5
responses:
"200":
description: The device answered
content:
application/json:
schema:
$ref: "#/components/schemas/RawResponse"
examples:
echo:
value:
data: [0, 0, 18, 52]
"422":
description: |
A `unit_id` was specified but the "API unit id override" setting
is disabled.
"501":
description: The "API raw function" setting is disabled
"503":
description: No device is currently connected
"502":
description: The device call failed (Modbus / transport error)
content:
application/json:
schema:
$ref: "#/components/schemas/FailureResponse"
/health:
get:
summary: Health probe
description: |
Reports server health. Returns `200` only when a device is present and
its connection status is serving (`unknown`, `reading`, or
`connected`); otherwise `503` with the same body.
In the TUI the status follows the app's own device polling. In
`--headless` mode nothing polls the device, so the status starts as
`unknown` and then reflects the outcome of the latest API read or
write.
operationId: health
responses:
"200":
description: Device present and serving
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
examples:
connected:
value:
status: connected
device_present: true
read_only: false
"503":
description: No device present, or status is not serving
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
examples:
disconnected:
value:
status: error
device_present: false
read_only: false
components:
schemas:
RegisterType:
type: string
description: |
Modbus data class. `holding` (16-bit, read/write) and `input` (16-bit,
read-only) are register types; `coil` (1-bit, read/write) and
`discrete` (1-bit, read-only) are bit types. Reads of bit types return
`0` or `1` per item.
enum:
- holding
- input
- coil
- discrete
ReadRequest:
type: object
required: [type, address, count]
properties:
type:
$ref: "#/components/schemas/RegisterType"
address:
type: integer
format: uint16
minimum: 0
maximum: 65535
description: Starting register address.
count:
type: integer
format: uint16
minimum: 0
maximum: 65535
description: Number of registers to read.
unit_id:
type: integer
format: uint8
minimum: 0
maximum: 255
description: |
Modbus unit id to target for this request only. Defaults to
the device's configured unit when omitted. Requires the "API unit
id override" setting to be enabled; a request that sets this while
the setting is disabled is rejected with `403`.
FailureResponse:
type: object
required: [exception, timed_out]
properties:
exception:
type: integer
format: uint8
minimum: 0
maximum: 255
nullable: true
description: |
Modbus exception code answered by the device, or `null` when the
failure was not a Modbus exception (timeout, transport error).
timed_out:
type: boolean
description: |
`true` when the device did not answer within the configured
timeout, `false` otherwise.
ReadResponse:
type: object
required: [values]
properties:
values:
type: array
description: |
Values in address order: raw 16-bit for `holding`/`input`, or
`0`/`1` for `coil`/`discrete`.
items:
type: integer
format: uint16
minimum: 0
maximum: 65535
WriteRequest:
type: object
required: [type, address, values]
properties:
type:
allOf:
- $ref: "#/components/schemas/RegisterType"
description: |
Target data class. Only `holding` and `coil` are writable;
`input` and `discrete` are rejected with `400`.
address:
type: integer
format: uint16
minimum: 0
maximum: 65535
description: Starting address.
values:
type: array
description: |
Values to write to consecutive items. For coils, `0` is off and
any non-zero value is on.
items:
type: integer
format: uint16
minimum: 0
maximum: 65535
unit_id:
type: integer
format: uint8
minimum: 0
maximum: 255
description: |
Modbus unit id to target for this request only. Defaults to
the device's configured unit when omitted. Requires the "API unit
id override" setting to be enabled; a request that sets this while
the setting is disabled is rejected with `403`.
RawRequest:
type: object
required: [code]
properties:
code:
type: integer
format: uint8
minimum: 0
maximum: 255
description: Modbus function code to send.
data:
type: array
description: Request bytes sent after the function code. Defaults to none.
items:
type: integer
format: uint8
minimum: 0
maximum: 255
unit_id:
type: integer
format: uint8
minimum: 0
maximum: 255
description: |
Modbus unit id to target for this request only. Defaults to
the device's configured unit when omitted. Requires the "API unit
id override" setting to be enabled; a request that sets this while
the setting is disabled is rejected with `422`.
RawResponse:
type: object
required: [data]
properties:
data:
type: array
description: Response bytes the device answered after the function code.
items:
type: integer
format: uint8
minimum: 0
maximum: 255
HealthResponse:
type: object
required: [version, status, device_present, read_only]
properties:
version:
type: string
description: MTUI version serving the API.
status:
type: string
description: Connection status label.
enum:
- unknown
- reading
- connected
- reconnecting
- error
device_present:
type: boolean
description: Whether a Modbus device is currently connected.
read_only:
type: boolean
description: Whether the server rejects writes.