@yarkivaev/scada 2.6.23 → 2.6.25
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarkivaev/scada",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.25",
|
|
4
4
|
"description": "SCADA domain objects, state persistence, and plant monitoring",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@clickhouse/client": "^1.0.0",
|
|
41
41
|
"@modelcontextprotocol/sdk": "^1.24.3",
|
|
42
42
|
"@yarkivaev/simple-server": "1.0.2",
|
|
43
|
-
"@yarkivaev/source-to-sink": "2.0.
|
|
43
|
+
"@yarkivaev/source-to-sink": "^2.0.1",
|
|
44
44
|
"amqplib": "^0.10.9",
|
|
45
45
|
"better-sqlite3": "^11.0.0",
|
|
46
46
|
"modbus-serial": "^8.0.0",
|
|
@@ -30,17 +30,27 @@ function decode(low, high) {
|
|
|
30
30
|
* @param {object} collector - Collector with accept(record)
|
|
31
31
|
* @returns {object} Transformer with accept(registers)
|
|
32
32
|
*/
|
|
33
|
+
function publish(collector, device, channel, ts, value) {
|
|
34
|
+
return collector.accept({
|
|
35
|
+
topic: `MX210/${device}/GET/${channel}/VALUE`,
|
|
36
|
+
ts,
|
|
37
|
+
value
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
export function mx210Metrics(device, collector) {
|
|
34
42
|
return {
|
|
35
43
|
accept(registers) {
|
|
36
44
|
const ts = Date.now();
|
|
37
|
-
return Promise.all(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
return Promise.all([
|
|
46
|
+
...layout.map((entry) => {
|
|
47
|
+
return publish(collector, device, entry.channel, ts, decode(registers[entry.offset], registers[entry.offset + 1]));
|
|
48
|
+
}),
|
|
49
|
+
publish(collector, device, 'source_alive', ts, 1)
|
|
50
|
+
]);
|
|
51
|
+
},
|
|
52
|
+
miss(row) {
|
|
53
|
+
return publish(collector, device, 'source_alive', Number(row?.ts) || Date.now(), 0);
|
|
44
54
|
}
|
|
45
55
|
};
|
|
46
56
|
}
|
|
@@ -53,6 +53,28 @@ export function measurementPlans(stream, mapping) {
|
|
|
53
53
|
* @param {object} collector - collector with accept()
|
|
54
54
|
* @returns {object} transformer with accept(registers)
|
|
55
55
|
*/
|
|
56
|
+
function aliveTopic(topic) {
|
|
57
|
+
const parts = String(topic).split('/');
|
|
58
|
+
const index = parts.indexOf('GET');
|
|
59
|
+
if (index >= 0 && index + 1 < parts.length) {
|
|
60
|
+
parts[index + 1] = 'source_alive';
|
|
61
|
+
return parts.join('/');
|
|
62
|
+
}
|
|
63
|
+
parts[parts.length - 1] = 'source_alive';
|
|
64
|
+
return parts.join('/');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function emit(collector, topic, value, ts) {
|
|
68
|
+
return collector.accept({
|
|
69
|
+
payload: JSON.stringify({ ts, value }),
|
|
70
|
+
topic
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function marks(rows) {
|
|
75
|
+
return [...new Set(rows.map((item) => { return aliveTopic(item.topic); }))];
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
export default function registerPublish(plans, origin, collector) {
|
|
57
79
|
if (!collector || typeof collector.accept !== 'function') {
|
|
58
80
|
throw new Error('Collector must have an accept() method');
|
|
@@ -70,15 +92,22 @@ export default function registerPublish(plans, origin, collector) {
|
|
|
70
92
|
* @param {Array<number>} registers - uint16 window
|
|
71
93
|
*/
|
|
72
94
|
accept(registers) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
const ts = Date.now();
|
|
96
|
+
return Promise.all([
|
|
97
|
+
...rows.map((item) => {
|
|
98
|
+
return emit(collector, item.topic, decodePoint(item.point, origin, registers), ts);
|
|
99
|
+
}),
|
|
100
|
+
...marks(rows).map((topic) => { return emit(collector, topic, 1, ts); })
|
|
101
|
+
]);
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Publishes a collector-clock watermark while the register source is dark.
|
|
105
|
+
*
|
|
106
|
+
* @param {{ts?: number}} row - collector timestamp
|
|
107
|
+
*/
|
|
108
|
+
miss(row) {
|
|
109
|
+
const ts = Number(row?.ts) || Date.now();
|
|
110
|
+
return Promise.all(marks(rows).map((topic) => { return emit(collector, topic, 0, ts); }));
|
|
82
111
|
}
|
|
83
112
|
};
|
|
84
113
|
}
|