node-red-contrib-uos-nats 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/icons/white/datahub-input.svg +4 -0
- package/icons/white/datahub-output.svg +4 -0
- package/lib/auth.js +27 -0
- package/lib/config.js +23 -0
- package/lib/consumer.js +41 -0
- package/lib/fbs/weidmueller/ucontrol/hub/duration.js +67 -0
- package/lib/fbs/weidmueller/ucontrol/hub/provider-definition-changed-event.js +69 -0
- package/lib/fbs/weidmueller/ucontrol/hub/provider-definition-state.js +20 -0
- package/lib/fbs/weidmueller/ucontrol/hub/provider-definition.js +118 -0
- package/lib/fbs/weidmueller/ucontrol/hub/provider-list.js +76 -0
- package/lib/fbs/weidmueller/ucontrol/hub/provider.js +59 -0
- package/lib/fbs/weidmueller/ucontrol/hub/providers-changed-event.js +69 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-provider-definition-query-request.js +51 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-provider-definition-query-response.js +68 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-providers-query-request.js +51 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-providers-query-response.js +69 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-variables-query-request.js +88 -0
- package/lib/fbs/weidmueller/ucontrol/hub/read-variables-query-response.js +69 -0
- package/lib/fbs/weidmueller/ucontrol/hub/state-changed-event.js +67 -0
- package/lib/fbs/weidmueller/ucontrol/hub/state.js +14 -0
- package/lib/fbs/weidmueller/ucontrol/hub/timestamp.js +62 -0
- package/lib/fbs/weidmueller/ucontrol/hub/uuid.js +43 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-access-type.js +17 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-data-type.js +15 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-definition.js +115 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-list.js +106 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-quality.js +31 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-boolean.js +57 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-duration.js +58 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-float64.js +57 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-int64.js +57 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-string.js +58 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value-timestamp.js +58 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable-value.js +45 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variable.js +131 -0
- package/lib/fbs/weidmueller/ucontrol/hub/variables-changed-event.js +71 -0
- package/lib/fbs/weidmueller/ucontrol/hub/write-variables-command.js +69 -0
- package/lib/fbs/weidmueller/ucontrol/hub.js +17 -0
- package/lib/models.js +1 -0
- package/lib/payloads.js +182 -0
- package/lib/provider.js +51 -0
- package/lib/simulation.js +54 -0
- package/lib/subjects.js +11 -0
- package/nodes/datahub-input.html +157 -0
- package/nodes/datahub-input.js +129 -0
- package/nodes/datahub-output.html +36 -0
- package/nodes/datahub-output.js +189 -0
- package/nodes/uos-config.html +48 -0
- package/nodes/uos-config.js +173 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# node-red-contrib-uos-nats
|
|
2
|
+
|
|
3
|
+
**Note:** This custom Node-RED package is built and maintained by [IoTUeli](https://www.iotueli.ch) and is **not** an official Weidmüller product. For questions, feature requests, or support please contact IoTUeli directly.
|
|
4
|
+
|
|
5
|
+
Node-RED nodes to read and write u-OS Data Hub variables via NATS. This package exposes three building blocks:
|
|
6
|
+
|
|
7
|
+
1. **u-OS Config** – stores host, OAuth client credentials and manages the shared NATS connection.
|
|
8
|
+
2. **DataHub Input** – subscribes to an existing provider, lets you pick individual variables and emits JSON messages.
|
|
9
|
+
3. **DataHub Output** – automatically registers a provider (default `nodered`), flattens incoming JSON structures and publishes them to the Data Hub.
|
|
10
|
+
|
|
11
|
+
The nodes reuse the FlatBuffer helpers from the standalone Node sample, so they speak the native NATS API.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd ~/App/NATS-NodeRED
|
|
17
|
+
npm install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then install the nodes into your Node-RED user directory (e.g. `~/.node-red`):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
cd ~/.node-red
|
|
24
|
+
npm install ~/App/NATS-NodeRED
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Restart Node-RED. You will find the nodes under the *u-OS Data Hub* category.
|
|
28
|
+
|
|
29
|
+
## u-OS Config Node
|
|
30
|
+
|
|
31
|
+
Fields:
|
|
32
|
+
|
|
33
|
+
- **Host / Port** – IP address of your controller (e.g. `192.168.10.100`) and the NATS port `49360`.
|
|
34
|
+
- **Client Name** – used for the NATS inbox prefix (`_INBOX.<name>`).
|
|
35
|
+
- **Client ID / Secret** – OAuth2 client credentials created in the Control Center.
|
|
36
|
+
- **Token URL** – optional override, defaults to `https://<host>/oauth2/token`.
|
|
37
|
+
- **Scope** – usually `hub.variables.provide hub.variables.readwrite`.
|
|
38
|
+
|
|
39
|
+
The config node automatically fetches tokens via Client Credentials flow and exposes helper endpoints so other nodes can list providers and variables.
|
|
40
|
+
|
|
41
|
+
## DataHub Input Node
|
|
42
|
+
|
|
43
|
+
- Select the u-OS config node and pick a provider from the drop-down. The node queries `/datahub/v1/providers` and lists all registry entries.
|
|
44
|
+
- Choose whether you want **all variables**, **single variable**, or **multi selection**. The variable selector is populated from `/datahub/v1/providers/<provider>/variables`.
|
|
45
|
+
- The node outputs messages with the structure:
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"type": "snapshot" | "change",
|
|
49
|
+
"variables": [
|
|
50
|
+
{
|
|
51
|
+
"providerId": "sampleprovider",
|
|
52
|
+
"id": 5,
|
|
53
|
+
"key": "diagnostics.status_text",
|
|
54
|
+
"value": "running",
|
|
55
|
+
"quality": "GOOD",
|
|
56
|
+
"timestampNs": 1700000000000
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
- Deploy multiple nodes if you want to monitor different providers.
|
|
62
|
+
|
|
63
|
+
## DataHub Output Node
|
|
64
|
+
|
|
65
|
+
- Reuses the u-OS config node. The provider ID defaults to `nodered` and is created automatically.
|
|
66
|
+
- Send a JSON object to the input pin. Nested objects become dot-separated keys (e.g. `{ "line1": { "status": "ok" } }` ⇒ `line1.status`).
|
|
67
|
+
- The node infers data types (INT64/FLOAT64/BOOLEAN/STRING) and publishes `VariablesChangedEvent`s. New keys trigger an automatic provider definition update.
|
|
68
|
+
- Read requests (`v1.loc.<provider>.vars.qry.read`) are answered using the most recent values, so other consumers can subscribe to your Node-RED provider.
|
|
69
|
+
|
|
70
|
+
## Docker (optional)
|
|
71
|
+
|
|
72
|
+
A simple Dockerfile is included for development/testing:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
docker build -t node-red-uos-nats .
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Run with environment overrides for host and credentials if needed.
|
|
79
|
+
|
|
80
|
+
## Example Flow
|
|
81
|
+
|
|
82
|
+
1. Drop a **u-OS Config** node, fill in host/port and OAuth credentials from the Control Center.
|
|
83
|
+
2. Add a **DataHub Input** node, select the config, pick an existing provider (e.g. `u_os_adm`) and choose the variables you want to observe. Connect the output to a Debug node.
|
|
84
|
+
3. Add a **DataHub Output** node, leave provider ID = `nodered` and send structured JSON (e.g. from a Function node). The values instantly appear in the Data Hub under the provider `nodered`.
|
|
85
|
+
|
|
86
|
+
> Tip: Because both nodes rely on the Control Center HTTP API for metadata they inherit the same permissions as your OAuth client. Make sure the client has at least `hub.variables.readonly` for the input node and `hub.variables.provide hub.variables.readwrite` for the output node.
|
|
87
|
+
|
|
88
|
+
## TODO
|
|
89
|
+
|
|
90
|
+
- Export a sample Node-RED flow (`flows.json`).
|
|
91
|
+
- Optional helper node for write commands targeting existing providers.
|
|
92
|
+
- Automated tests.
|
package/lib/auth.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fetch from 'node-fetch';
|
|
2
|
+
import { CLIENT_ID, CLIENT_SECRET, TOKEN_ENDPOINT, TOKEN_SCOPE } from './config.js';
|
|
3
|
+
export async function requestToken() {
|
|
4
|
+
const params = new URLSearchParams({
|
|
5
|
+
grant_type: 'client_credentials',
|
|
6
|
+
scope: TOKEN_SCOPE,
|
|
7
|
+
});
|
|
8
|
+
const basic = Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64');
|
|
9
|
+
const response = await fetch(TOKEN_ENDPOINT, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: `Basic ${basic}`,
|
|
13
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
14
|
+
Accept: 'application/json',
|
|
15
|
+
},
|
|
16
|
+
body: params,
|
|
17
|
+
});
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
const text = await response.text();
|
|
20
|
+
throw new Error(`Token request failed: ${response.status} ${text}`);
|
|
21
|
+
}
|
|
22
|
+
const json = (await response.json());
|
|
23
|
+
if (!json.access_token) {
|
|
24
|
+
throw new Error('Token response missing access_token');
|
|
25
|
+
}
|
|
26
|
+
return json.access_token;
|
|
27
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
export const HUB_HOST = process.env.HUB_HOST ?? '192.168.10.108';
|
|
3
|
+
export const HUB_PORT = Number(process.env.HUB_PORT ?? 49360);
|
|
4
|
+
export const PROVIDER_ID = process.env.PROVIDER_ID ?? 'sampleprovider';
|
|
5
|
+
export const CLIENT_NAME = process.env.CLIENT_NAME ?? 'sampleprovider';
|
|
6
|
+
export const CLIENT_ID = process.env.CLIENT_ID ?? '';
|
|
7
|
+
export const CLIENT_SECRET = process.env.CLIENT_SECRET ?? '';
|
|
8
|
+
export const TOKEN_SCOPE = process.env.TOKEN_SCOPE ?? 'hub.variables.provide hub.variables.readwrite';
|
|
9
|
+
export const TOKEN_ENDPOINT = process.env.TOKEN_ENDPOINT ?? `https://${HUB_HOST}/oauth2/token`;
|
|
10
|
+
export const PUBLISH_INTERVAL_MS = Number(process.env.PUBLISH_INTERVAL_MS ?? 1000);
|
|
11
|
+
export const NATS_SERVER = process.env.NATS_SERVER ?? `nats://${HUB_HOST}:${HUB_PORT}`;
|
|
12
|
+
if (!process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
|
|
13
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
14
|
+
}
|
|
15
|
+
if (!CLIENT_ID || !CLIENT_SECRET) {
|
|
16
|
+
console.warn('[config] CLIENT_ID/CLIENT_SECRET fehlen – bitte .env ausfüllen.');
|
|
17
|
+
}
|
|
18
|
+
export const VARIABLE_DEFINITIONS = [
|
|
19
|
+
{ id: 5, key: 'diagnostics.status_text', dataType: 'STRING', access: 'READ_WRITE' },
|
|
20
|
+
{ id: 6, key: 'diagnostics.error_count', dataType: 'INT64', access: 'READ_WRITE' },
|
|
21
|
+
{ id: 7, key: 'diagnostics.temperature', dataType: 'FLOAT64', access: 'READ_ONLY' },
|
|
22
|
+
{ id: 8, key: 'diagnostics.is_running', dataType: 'BOOLEAN', access: 'READ_WRITE' },
|
|
23
|
+
];
|
package/lib/consumer.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { connect } from 'nats';
|
|
2
|
+
import * as flatbuffers from 'flatbuffers';
|
|
3
|
+
import { requestToken } from './auth.js';
|
|
4
|
+
import { CLIENT_NAME, NATS_SERVER, PROVIDER_ID } from './config.js';
|
|
5
|
+
import { buildReadVariablesQuery, decodeVariableList } from './payloads.js';
|
|
6
|
+
import { readVariablesQuery, varsChangedEvent } from './subjects.js';
|
|
7
|
+
import { ReadVariablesQueryResponse } from './fbs/weidmueller/ucontrol/hub/read-variables-query-response.js';
|
|
8
|
+
import { VariablesChangedEvent } from './fbs/weidmueller/ucontrol/hub/variables-changed-event.js';
|
|
9
|
+
async function main() {
|
|
10
|
+
console.log(`[consumer] Lausche auf Provider ${PROVIDER_ID}`);
|
|
11
|
+
const token = await requestToken();
|
|
12
|
+
const nc = await connect({
|
|
13
|
+
servers: NATS_SERVER.split(','),
|
|
14
|
+
token,
|
|
15
|
+
name: `${CLIENT_NAME}-node-consumer`,
|
|
16
|
+
inboxPrefix: `_INBOX.${CLIENT_NAME}`,
|
|
17
|
+
});
|
|
18
|
+
console.log('[consumer] NATS verbunden:', nc.getServer());
|
|
19
|
+
const snapshotMsg = await nc.request(readVariablesQuery(PROVIDER_ID), buildReadVariablesQuery(), {
|
|
20
|
+
timeout: 2000,
|
|
21
|
+
});
|
|
22
|
+
const snapshotBuffer = new flatbuffers.ByteBuffer(snapshotMsg.data);
|
|
23
|
+
const snapshotResponse = ReadVariablesQueryResponse.getRootAsReadVariablesQueryResponse(snapshotBuffer);
|
|
24
|
+
const initialStates = decodeVariableList(snapshotResponse.variables());
|
|
25
|
+
console.log('[consumer] Snapshot:', initialStates);
|
|
26
|
+
const sub = nc.subscribe(varsChangedEvent(PROVIDER_ID));
|
|
27
|
+
(async () => {
|
|
28
|
+
for await (const msg of sub) {
|
|
29
|
+
const buffer = new flatbuffers.ByteBuffer(msg.data);
|
|
30
|
+
const event = VariablesChangedEvent.getRootAsVariablesChangedEvent(buffer);
|
|
31
|
+
const states = decodeVariableList(event.changedVariables());
|
|
32
|
+
if (states.length === 0)
|
|
33
|
+
continue;
|
|
34
|
+
console.log('[consumer] Änderung erhalten:', states);
|
|
35
|
+
}
|
|
36
|
+
})().catch((err) => console.error('[consumer] Subscription error', err));
|
|
37
|
+
}
|
|
38
|
+
main().catch((err) => {
|
|
39
|
+
console.error('[consumer] Fehler:', err);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/**
|
|
3
|
+
* A Duration represents a signed, fixed-length span of time represented
|
|
4
|
+
* as a count of seconds and fractions of seconds at nanosecond
|
|
5
|
+
* resolution. It is independent of any calendar and concepts like "day"
|
|
6
|
+
* or "month". It is related to Timestamp in that the difference between
|
|
7
|
+
* two Timestamp values is a Duration and it can be added or subtracted
|
|
8
|
+
* from a Timestamp. Range is approximately +-10,000 years.
|
|
9
|
+
*
|
|
10
|
+
* Based on google protobuf duration definition: <https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/duration.proto>
|
|
11
|
+
*/
|
|
12
|
+
export class Duration {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.bb = null;
|
|
15
|
+
this.bb_pos = 0;
|
|
16
|
+
}
|
|
17
|
+
__init(i, bb) {
|
|
18
|
+
this.bb_pos = i;
|
|
19
|
+
this.bb = bb;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Signed seconds of the span of time. Must be from -315,576,000,000
|
|
24
|
+
* to +315,576,000,000 inclusive. Note: these bounds are computed from:
|
|
25
|
+
* 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
|
|
26
|
+
*/
|
|
27
|
+
seconds() {
|
|
28
|
+
return this.bb.readInt64(this.bb_pos);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Signed fractions of a second at nanosecond resolution of the span
|
|
32
|
+
* of time. Durations less than one second are represented with a 0
|
|
33
|
+
* `seconds` field and a positive or negative `nanos` field. For durations
|
|
34
|
+
* of one second or more, a non-zero value for the `nanos` field must be
|
|
35
|
+
* of the same sign as the `seconds` field. Must be from -999,999,999
|
|
36
|
+
* to +999,999,999 inclusive.
|
|
37
|
+
*/
|
|
38
|
+
nanos() {
|
|
39
|
+
return this.bb.readInt32(this.bb_pos + 8);
|
|
40
|
+
}
|
|
41
|
+
static sizeOf() {
|
|
42
|
+
return 16;
|
|
43
|
+
}
|
|
44
|
+
static createDuration(builder, seconds, nanos) {
|
|
45
|
+
builder.prep(8, 16);
|
|
46
|
+
builder.pad(4);
|
|
47
|
+
builder.writeInt32(nanos);
|
|
48
|
+
builder.writeInt64(BigInt(seconds ?? 0));
|
|
49
|
+
return builder.offset();
|
|
50
|
+
}
|
|
51
|
+
unpack() {
|
|
52
|
+
return new DurationT(this.seconds(), this.nanos());
|
|
53
|
+
}
|
|
54
|
+
unpackTo(_o) {
|
|
55
|
+
_o.seconds = this.seconds();
|
|
56
|
+
_o.nanos = this.nanos();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class DurationT {
|
|
60
|
+
constructor(seconds = BigInt('0'), nanos = 0) {
|
|
61
|
+
this.seconds = seconds;
|
|
62
|
+
this.nanos = nanos;
|
|
63
|
+
}
|
|
64
|
+
pack(builder) {
|
|
65
|
+
return Duration.createDuration(builder, this.seconds, this.nanos);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
import * as flatbuffers from 'flatbuffers';
|
|
4
|
+
import { ProviderDefinition } from '../../../weidmueller/ucontrol/hub/provider-definition.js';
|
|
5
|
+
/**
|
|
6
|
+
* An event that describes a provider's definition that has just changed.
|
|
7
|
+
*/
|
|
8
|
+
export class ProviderDefinitionChangedEvent {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.bb = null;
|
|
11
|
+
this.bb_pos = 0;
|
|
12
|
+
}
|
|
13
|
+
__init(i, bb) {
|
|
14
|
+
this.bb_pos = i;
|
|
15
|
+
this.bb = bb;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
static getRootAsProviderDefinitionChangedEvent(bb, obj) {
|
|
19
|
+
return (obj || new ProviderDefinitionChangedEvent()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
20
|
+
}
|
|
21
|
+
static getSizePrefixedRootAsProviderDefinitionChangedEvent(bb, obj) {
|
|
22
|
+
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
23
|
+
return (obj || new ProviderDefinitionChangedEvent()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A definition that has just been changed.
|
|
27
|
+
* If the provider_definition is null, the provider is removed.
|
|
28
|
+
*/
|
|
29
|
+
providerDefinition(obj) {
|
|
30
|
+
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
31
|
+
return offset ? (obj || new ProviderDefinition()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
|
32
|
+
}
|
|
33
|
+
static startProviderDefinitionChangedEvent(builder) {
|
|
34
|
+
builder.startObject(1);
|
|
35
|
+
}
|
|
36
|
+
static addProviderDefinition(builder, providerDefinitionOffset) {
|
|
37
|
+
builder.addFieldOffset(0, providerDefinitionOffset, 0);
|
|
38
|
+
}
|
|
39
|
+
static endProviderDefinitionChangedEvent(builder) {
|
|
40
|
+
const offset = builder.endObject();
|
|
41
|
+
return offset;
|
|
42
|
+
}
|
|
43
|
+
static finishProviderDefinitionChangedEventBuffer(builder, offset) {
|
|
44
|
+
builder.finish(offset);
|
|
45
|
+
}
|
|
46
|
+
static finishSizePrefixedProviderDefinitionChangedEventBuffer(builder, offset) {
|
|
47
|
+
builder.finish(offset, undefined, true);
|
|
48
|
+
}
|
|
49
|
+
static createProviderDefinitionChangedEvent(builder, providerDefinitionOffset) {
|
|
50
|
+
ProviderDefinitionChangedEvent.startProviderDefinitionChangedEvent(builder);
|
|
51
|
+
ProviderDefinitionChangedEvent.addProviderDefinition(builder, providerDefinitionOffset);
|
|
52
|
+
return ProviderDefinitionChangedEvent.endProviderDefinitionChangedEvent(builder);
|
|
53
|
+
}
|
|
54
|
+
unpack() {
|
|
55
|
+
return new ProviderDefinitionChangedEventT((this.providerDefinition() !== null ? this.providerDefinition().unpack() : null));
|
|
56
|
+
}
|
|
57
|
+
unpackTo(_o) {
|
|
58
|
+
_o.providerDefinition = (this.providerDefinition() !== null ? this.providerDefinition().unpack() : null);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class ProviderDefinitionChangedEventT {
|
|
62
|
+
constructor(providerDefinition = null) {
|
|
63
|
+
this.providerDefinition = providerDefinition;
|
|
64
|
+
}
|
|
65
|
+
pack(builder) {
|
|
66
|
+
const providerDefinition = (this.providerDefinition !== null ? this.providerDefinition.pack(builder) : 0);
|
|
67
|
+
return ProviderDefinitionChangedEvent.createProviderDefinitionChangedEvent(builder, providerDefinition);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
/**
|
|
4
|
+
* The state of the provider definition. The state will be set by the registry.
|
|
5
|
+
*/
|
|
6
|
+
export var ProviderDefinitionState;
|
|
7
|
+
(function (ProviderDefinitionState) {
|
|
8
|
+
/**
|
|
9
|
+
* The state is unspecified.
|
|
10
|
+
*/
|
|
11
|
+
ProviderDefinitionState[ProviderDefinitionState["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
12
|
+
/**
|
|
13
|
+
* The provider definition is ok and valid.
|
|
14
|
+
*/
|
|
15
|
+
ProviderDefinitionState[ProviderDefinitionState["OK"] = 1] = "OK";
|
|
16
|
+
/**
|
|
17
|
+
* The provider definition is invalid => variable_definitions.size = 0
|
|
18
|
+
*/
|
|
19
|
+
ProviderDefinitionState[ProviderDefinitionState["INVALID"] = 2] = "INVALID";
|
|
20
|
+
})(ProviderDefinitionState || (ProviderDefinitionState = {}));
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
import * as flatbuffers from 'flatbuffers';
|
|
4
|
+
import { ProviderDefinitionState } from '../../../weidmueller/ucontrol/hub/provider-definition-state.js';
|
|
5
|
+
import { VariableDefinition } from '../../../weidmueller/ucontrol/hub/variable-definition.js';
|
|
6
|
+
/**
|
|
7
|
+
* A definition of a provider's provided variables.
|
|
8
|
+
*
|
|
9
|
+
* Definition elements have a flat list instead of a hierarchy structure.
|
|
10
|
+
* They support the folder concept as a means of grouping definitions by using
|
|
11
|
+
* a shared key prefix for the grouped definitions.
|
|
12
|
+
* This means that the grouped definitions have keys that begin with a common
|
|
13
|
+
* string.
|
|
14
|
+
* This common string, or shared prefix, is the folder key.
|
|
15
|
+
*
|
|
16
|
+
* For security reasons, the provider id must be extracted from the
|
|
17
|
+
* communication channel.
|
|
18
|
+
*/
|
|
19
|
+
export class ProviderDefinition {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.bb = null;
|
|
22
|
+
this.bb_pos = 0;
|
|
23
|
+
}
|
|
24
|
+
__init(i, bb) {
|
|
25
|
+
this.bb_pos = i;
|
|
26
|
+
this.bb = bb;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
static getRootAsProviderDefinition(bb, obj) {
|
|
30
|
+
return (obj || new ProviderDefinition()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
31
|
+
}
|
|
32
|
+
static getSizePrefixedRootAsProviderDefinition(bb, obj) {
|
|
33
|
+
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
34
|
+
return (obj || new ProviderDefinition()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The fingerprint is a version identification of the provider definition.
|
|
38
|
+
*
|
|
39
|
+
* Therefore, the fingerprint can be used by a consumer to check whether
|
|
40
|
+
* the provider's definition matches the values received.
|
|
41
|
+
* Whenever a provider definition changed, the provider must change the
|
|
42
|
+
* fingerprint.
|
|
43
|
+
*/
|
|
44
|
+
fingerprint() {
|
|
45
|
+
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
46
|
+
return offset ? this.bb.readUint64(this.bb_pos + offset) : BigInt('0');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The list of variable definitions.
|
|
50
|
+
*/
|
|
51
|
+
variableDefinitions(index, obj) {
|
|
52
|
+
const offset = this.bb.__offset(this.bb_pos, 6);
|
|
53
|
+
return offset ? (obj || new VariableDefinition()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
|
54
|
+
}
|
|
55
|
+
variableDefinitionsLength() {
|
|
56
|
+
const offset = this.bb.__offset(this.bb_pos, 6);
|
|
57
|
+
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The current state of the provider definition. The state will be set by the registry.
|
|
61
|
+
*/
|
|
62
|
+
state() {
|
|
63
|
+
const offset = this.bb.__offset(this.bb_pos, 8);
|
|
64
|
+
return offset ? this.bb.readUint8(this.bb_pos + offset) : ProviderDefinitionState.UNSPECIFIED;
|
|
65
|
+
}
|
|
66
|
+
static startProviderDefinition(builder) {
|
|
67
|
+
builder.startObject(3);
|
|
68
|
+
}
|
|
69
|
+
static addFingerprint(builder, fingerprint) {
|
|
70
|
+
builder.addFieldInt64(0, fingerprint, BigInt('0'));
|
|
71
|
+
}
|
|
72
|
+
static addVariableDefinitions(builder, variableDefinitionsOffset) {
|
|
73
|
+
builder.addFieldOffset(1, variableDefinitionsOffset, 0);
|
|
74
|
+
}
|
|
75
|
+
static createVariableDefinitionsVector(builder, data) {
|
|
76
|
+
builder.startVector(4, data.length, 4);
|
|
77
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
78
|
+
builder.addOffset(data[i]);
|
|
79
|
+
}
|
|
80
|
+
return builder.endVector();
|
|
81
|
+
}
|
|
82
|
+
static startVariableDefinitionsVector(builder, numElems) {
|
|
83
|
+
builder.startVector(4, numElems, 4);
|
|
84
|
+
}
|
|
85
|
+
static addState(builder, state) {
|
|
86
|
+
builder.addFieldInt8(2, state, ProviderDefinitionState.UNSPECIFIED);
|
|
87
|
+
}
|
|
88
|
+
static endProviderDefinition(builder) {
|
|
89
|
+
const offset = builder.endObject();
|
|
90
|
+
return offset;
|
|
91
|
+
}
|
|
92
|
+
static createProviderDefinition(builder, fingerprint, variableDefinitionsOffset, state) {
|
|
93
|
+
ProviderDefinition.startProviderDefinition(builder);
|
|
94
|
+
ProviderDefinition.addFingerprint(builder, fingerprint);
|
|
95
|
+
ProviderDefinition.addVariableDefinitions(builder, variableDefinitionsOffset);
|
|
96
|
+
ProviderDefinition.addState(builder, state);
|
|
97
|
+
return ProviderDefinition.endProviderDefinition(builder);
|
|
98
|
+
}
|
|
99
|
+
unpack() {
|
|
100
|
+
return new ProviderDefinitionT(this.fingerprint(), this.bb.createObjList(this.variableDefinitions.bind(this), this.variableDefinitionsLength()), this.state());
|
|
101
|
+
}
|
|
102
|
+
unpackTo(_o) {
|
|
103
|
+
_o.fingerprint = this.fingerprint();
|
|
104
|
+
_o.variableDefinitions = this.bb.createObjList(this.variableDefinitions.bind(this), this.variableDefinitionsLength());
|
|
105
|
+
_o.state = this.state();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export class ProviderDefinitionT {
|
|
109
|
+
constructor(fingerprint = BigInt('0'), variableDefinitions = [], state = ProviderDefinitionState.UNSPECIFIED) {
|
|
110
|
+
this.fingerprint = fingerprint;
|
|
111
|
+
this.variableDefinitions = variableDefinitions;
|
|
112
|
+
this.state = state;
|
|
113
|
+
}
|
|
114
|
+
pack(builder) {
|
|
115
|
+
const variableDefinitions = ProviderDefinition.createVariableDefinitionsVector(builder, builder.createObjectOffsetList(this.variableDefinitions));
|
|
116
|
+
return ProviderDefinition.createProviderDefinition(builder, this.fingerprint, variableDefinitions, this.state);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
import * as flatbuffers from 'flatbuffers';
|
|
4
|
+
import { Provider } from '../../../weidmueller/ucontrol/hub/provider.js';
|
|
5
|
+
/**
|
|
6
|
+
* A list of providers that provide variables to consumers.
|
|
7
|
+
*/
|
|
8
|
+
export class ProviderList {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.bb = null;
|
|
11
|
+
this.bb_pos = 0;
|
|
12
|
+
}
|
|
13
|
+
__init(i, bb) {
|
|
14
|
+
this.bb_pos = i;
|
|
15
|
+
this.bb = bb;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
static getRootAsProviderList(bb, obj) {
|
|
19
|
+
return (obj || new ProviderList()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
20
|
+
}
|
|
21
|
+
static getSizePrefixedRootAsProviderList(bb, obj) {
|
|
22
|
+
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
23
|
+
return (obj || new ProviderList()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The list of providers.
|
|
27
|
+
*/
|
|
28
|
+
items(index, obj) {
|
|
29
|
+
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
30
|
+
return offset ? (obj || new Provider()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
|
31
|
+
}
|
|
32
|
+
itemsLength() {
|
|
33
|
+
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
34
|
+
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
|
35
|
+
}
|
|
36
|
+
static startProviderList(builder) {
|
|
37
|
+
builder.startObject(1);
|
|
38
|
+
}
|
|
39
|
+
static addItems(builder, itemsOffset) {
|
|
40
|
+
builder.addFieldOffset(0, itemsOffset, 0);
|
|
41
|
+
}
|
|
42
|
+
static createItemsVector(builder, data) {
|
|
43
|
+
builder.startVector(4, data.length, 4);
|
|
44
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
45
|
+
builder.addOffset(data[i]);
|
|
46
|
+
}
|
|
47
|
+
return builder.endVector();
|
|
48
|
+
}
|
|
49
|
+
static startItemsVector(builder, numElems) {
|
|
50
|
+
builder.startVector(4, numElems, 4);
|
|
51
|
+
}
|
|
52
|
+
static endProviderList(builder) {
|
|
53
|
+
const offset = builder.endObject();
|
|
54
|
+
return offset;
|
|
55
|
+
}
|
|
56
|
+
static createProviderList(builder, itemsOffset) {
|
|
57
|
+
ProviderList.startProviderList(builder);
|
|
58
|
+
ProviderList.addItems(builder, itemsOffset);
|
|
59
|
+
return ProviderList.endProviderList(builder);
|
|
60
|
+
}
|
|
61
|
+
unpack() {
|
|
62
|
+
return new ProviderListT(this.bb.createObjList(this.items.bind(this), this.itemsLength()));
|
|
63
|
+
}
|
|
64
|
+
unpackTo(_o) {
|
|
65
|
+
_o.items = this.bb.createObjList(this.items.bind(this), this.itemsLength());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export class ProviderListT {
|
|
69
|
+
constructor(items = []) {
|
|
70
|
+
this.items = items;
|
|
71
|
+
}
|
|
72
|
+
pack(builder) {
|
|
73
|
+
const items = ProviderList.createItemsVector(builder, builder.createObjectOffsetList(this.items));
|
|
74
|
+
return ProviderList.createProviderList(builder, items);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// automatically generated by the FlatBuffers compiler, do not modify
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
|
3
|
+
import * as flatbuffers from 'flatbuffers';
|
|
4
|
+
/**
|
|
5
|
+
* A provider that provides variables to consumers.
|
|
6
|
+
*/
|
|
7
|
+
export class Provider {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.bb = null;
|
|
10
|
+
this.bb_pos = 0;
|
|
11
|
+
}
|
|
12
|
+
__init(i, bb) {
|
|
13
|
+
this.bb_pos = i;
|
|
14
|
+
this.bb = bb;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
static getRootAsProvider(bb, obj) {
|
|
18
|
+
return (obj || new Provider()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
19
|
+
}
|
|
20
|
+
static getSizePrefixedRootAsProvider(bb, obj) {
|
|
21
|
+
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
|
22
|
+
return (obj || new Provider()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
|
23
|
+
}
|
|
24
|
+
id(optionalEncoding) {
|
|
25
|
+
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
26
|
+
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
|
27
|
+
}
|
|
28
|
+
static startProvider(builder) {
|
|
29
|
+
builder.startObject(1);
|
|
30
|
+
}
|
|
31
|
+
static addId(builder, idOffset) {
|
|
32
|
+
builder.addFieldOffset(0, idOffset, 0);
|
|
33
|
+
}
|
|
34
|
+
static endProvider(builder) {
|
|
35
|
+
const offset = builder.endObject();
|
|
36
|
+
builder.requiredField(offset, 4); // id
|
|
37
|
+
return offset;
|
|
38
|
+
}
|
|
39
|
+
static createProvider(builder, idOffset) {
|
|
40
|
+
Provider.startProvider(builder);
|
|
41
|
+
Provider.addId(builder, idOffset);
|
|
42
|
+
return Provider.endProvider(builder);
|
|
43
|
+
}
|
|
44
|
+
unpack() {
|
|
45
|
+
return new ProviderT(this.id());
|
|
46
|
+
}
|
|
47
|
+
unpackTo(_o) {
|
|
48
|
+
_o.id = this.id();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class ProviderT {
|
|
52
|
+
constructor(id = null) {
|
|
53
|
+
this.id = id;
|
|
54
|
+
}
|
|
55
|
+
pack(builder) {
|
|
56
|
+
const id = (this.id !== null ? builder.createString(this.id) : 0);
|
|
57
|
+
return Provider.createProvider(builder, id);
|
|
58
|
+
}
|
|
59
|
+
}
|