@yarkivaev/scada 2.3.89 → 2.3.112

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.
Files changed (35) hide show
  1. package/README.md +6 -1
  2. package/charts/scada/Chart.yaml +6 -0
  3. package/charts/scada/templates/_helpers.tpl +63 -0
  4. package/charts/scada/templates/clickhouse.yaml +57 -0
  5. package/charts/scada/templates/collector.yaml +115 -0
  6. package/charts/scada/templates/postgres.yaml +70 -0
  7. package/charts/scada/templates/rabbitmq.yaml +150 -0
  8. package/charts/scada/templates/site-server.yaml +110 -0
  9. package/charts/scada/templates/supervisor-sink.yaml +64 -0
  10. package/charts/scada/values.yaml +30 -0
  11. package/index.js +10 -0
  12. package/package.json +4 -2
  13. package/src/application/deploy/appReleases.js +50 -0
  14. package/src/application/deploy/applyIncludes.js +31 -0
  15. package/src/application/deploy/expand.js +49 -0
  16. package/src/application/deploy/expandDevices.js +135 -0
  17. package/src/application/deploy/expandFlows.js +281 -0
  18. package/src/application/deploy/expandNamespace.js +193 -0
  19. package/src/application/deploy/expandPattern.js +207 -0
  20. package/src/application/deploy/expandProfiles.js +70 -0
  21. package/src/application/deploy/frozen.js +23 -0
  22. package/src/application/deploy/mergeDocuments.js +98 -0
  23. package/src/application/deploy/paths.js +86 -0
  24. package/src/application/deploy/pointPaths.js +20 -0
  25. package/src/application/deploy/readDocument.js +169 -0
  26. package/src/application/deploy/releaseEdges.js +185 -0
  27. package/src/application/deploy/releaseNodes.js +118 -0
  28. package/src/application/deploy/releaseValues.js +200 -0
  29. package/src/application/deploy/releases.js +115 -0
  30. package/src/application/deploy/withCollectors.js +28 -0
  31. package/src/bin/modbus-to-mqtt.js +57 -0
  32. package/src/infrastructure/ingest/mqtt/addressWindow.js +79 -0
  33. package/src/infrastructure/ingest/mqtt/modbusPublish.js +277 -0
  34. package/src/infrastructure/ingest/mqtt/registerPoint.js +90 -0
  35. package/src/infrastructure/ingest/mqtt/registerPublish.js +84 -0
@@ -0,0 +1,84 @@
1
+ import { decodePoint } from './registerPoint.js';
2
+
3
+ /**
4
+ * Measurement name for one mapped parameter.
5
+ *
6
+ * A stream path plus the parameter id is the document path. An empty
7
+ * stream keeps the parameter id, which is the generic fallback name.
8
+ *
9
+ * @example
10
+ * measurementPath('mill/electrical', 'voltage');
11
+ *
12
+ * @param {string} stream - document path
13
+ * @param {string} key - parameter id
14
+ * @returns {string} MQTT topic
15
+ */
16
+ export function measurementPath(stream, key) {
17
+ if (typeof stream === 'string' && stream.length > 0) {
18
+ return `${stream}/${key}`;
19
+ }
20
+ return String(key);
21
+ }
22
+
23
+ /**
24
+ * Publish plan for one device map.
25
+ *
26
+ * @example
27
+ * measurementPlans('mill/electrical', { voltage: 'holding:4000:cdab' });
28
+ *
29
+ * @param {string} stream - document path
30
+ * @param {object} mapping - parameter id to register point
31
+ * @returns {Array<{point: string, topic: string}>} publish plan
32
+ */
33
+ export function measurementPlans(stream, mapping) {
34
+ return Object.keys(mapping || {}).map((key) => {
35
+ return {
36
+ point: String(mapping[key]),
37
+ topic: measurementPath(stream, key)
38
+ };
39
+ });
40
+ }
41
+
42
+ /**
43
+ * Publishes one MQTT record per holding-register point.
44
+ *
45
+ * Each record is `{topic, payload}` and the payload is JSON `{ts, value}`.
46
+ *
47
+ * @example
48
+ * const transformer = registerPublish(plans, 4000, collector);
49
+ * transformer.accept([0, 16256]);
50
+ *
51
+ * @param {Array<{point: string, topic: string}>} plans - publish plan
52
+ * @param {number} origin - first PDU address in the window
53
+ * @param {object} collector - collector with accept()
54
+ * @returns {object} transformer with accept(registers)
55
+ */
56
+ export default function registerPublish(plans, origin, collector) {
57
+ if (!collector || typeof collector.accept !== 'function') {
58
+ throw new Error('Collector must have an accept() method');
59
+ }
60
+ const rows = (plans || []).map((item) => {
61
+ return Object.freeze({
62
+ point: item.point,
63
+ topic: item.topic
64
+ });
65
+ });
66
+ return {
67
+ /**
68
+ * Decodes the window and publishes one record per point.
69
+ *
70
+ * @param {Array<number>} registers - uint16 window
71
+ */
72
+ accept(registers) {
73
+ rows.forEach((item) => {
74
+ collector.accept({
75
+ payload: JSON.stringify({
76
+ ts: Date.now(),
77
+ value: decodePoint(item.point, origin, registers)
78
+ }),
79
+ topic: item.topic
80
+ });
81
+ });
82
+ }
83
+ };
84
+ }