node-red-contrib-multiplexer 1.0.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 ADDED
@@ -0,0 +1,33 @@
1
+ # node-red-contrib-rpo-multiplexer
2
+
3
+ A Node-RED node: **Multiplexer**
4
+
5
+ Routes one of 8 input channels (ch0–ch7) to a single output. Switch the active channel by sending a message with topic `select` and payload `ch0`–`ch7`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install node-red-contrib-rpo-multiplexer
11
+ ```
12
+
13
+ Or via the Node-RED Palette Manager.
14
+
15
+ ## Inputs
16
+
17
+ - **topic=ch0..ch7**: Value update for that channel
18
+ - **topic=select, payload=ch0..ch7**: Switch active channel
19
+
20
+ ## Outputs
21
+
22
+ - **Output 1**: Value of the currently selected channel
23
+
24
+ ## Configuration
25
+
26
+ | Parameter | Description |
27
+ |-----------|-------------|
28
+ | Active channel | Initially selected channel (ch0–ch7) |
29
+ | Pass-through mode | Forward all channels or only the active one |
30
+
31
+ ## License
32
+
33
+ MIT
@@ -0,0 +1,19 @@
1
+ {
2
+ "multiplexer": {
3
+ "label": "Multiplexer",
4
+ "channel": "Eingangskanäle",
5
+ "selectedChannel": "Aktiver Kanal",
6
+ "passthroughAll": "Durchleitungsmodus",
7
+ "passthroughAll_opt": {
8
+ "false": "Nur aktiver Kanal",
9
+ "true": "Alle Kanäle"
10
+ },
11
+ "tip": "Topic 'select' mit Payload ch0–ch7 sendet um den Kanal zu wechseln.",
12
+ "input": {
13
+ "payload": "Wert für den adressierten Kanal (topic=ch0..ch7) oder Kanalauswahl (topic=select, payload=ch0..ch7)"
14
+ },
15
+ "output": {
16
+ "payload": "Wert des aktuell aktiven Kanals"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "multiplexer": {
3
+ "label": "Multiplexer",
4
+ "channel": "Input channels",
5
+ "selectedChannel": "Active channel",
6
+ "passthroughAll": "Pass-through mode",
7
+ "passthroughAll_opt": {
8
+ "false": "Active channel only",
9
+ "true": "All channels"
10
+ },
11
+ "tip": "Send topic 'select' with payload ch0–ch7 to switch channel.",
12
+ "input": {
13
+ "payload": "Value for the addressed channel (topic=ch0..ch7) or channel selector (topic=select, payload=ch0..ch7)"
14
+ },
15
+ "output": {
16
+ "payload": "Value of the currently active channel"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "multiplexer": {
3
+ "label": "Multiplexor",
4
+ "channel": "Canales de entrada",
5
+ "selectedChannel": "Canal activo",
6
+ "passthroughAll": "Modo paso completo",
7
+ "passthroughAll_opt": {
8
+ "false": "Solo canal activo",
9
+ "true": "Todos los canales"
10
+ },
11
+ "tip": "Envíe topic 'select' con payload ch0–ch7 para cambiar canal.",
12
+ "input": {
13
+ "payload": "Valor para el canal direccionado (topic=ch0..ch7) o selector de canal (topic=select, payload=ch0..ch7)"
14
+ },
15
+ "output": {
16
+ "payload": "Valor del canal activo actualmente"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,53 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('multiplexer', {
3
+ category: 'rpo',
4
+ color: '#D4600A',
5
+ defaults: {
6
+ "name": {
7
+ "value": ""
8
+ },
9
+ "channels": {
10
+ "value": 8
11
+ },
12
+ "initialChannel": {
13
+ "value": 0
14
+ }
15
+ },
16
+ inputs: 1,
17
+ outputs: 1,
18
+ icon: 'font-awesome/fa-random',
19
+ label: function() { return this.name || 'multiplexer'; },
20
+ labelStyle: function() { return this.name ? 'node_label_italic' : ''; }
21
+ });
22
+ </script>
23
+
24
+ <script type="text/html" data-template-name="multiplexer">
25
+ <div class="form-row">
26
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
27
+ <input type="text" id="node-input-name" placeholder="Name">
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-channels"><i class="fa fa-list"></i> Channels</label>
31
+ <select id="node-input-channels" style="width:70%">
32
+ <option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option>
33
+ </select>
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-input-initialChannel"><i class="fa fa-hand-o-right"></i> Initial Channel</label>
37
+ <input type="number" id="node-input-initialChannel" min="0" max="7" style="width:70%">
38
+ </div>
39
+ </script>
40
+
41
+ <script type="text/html" data-help-name="multiplexer">
42
+ <p>8-channel multiplexer. Forwards the selected input channel to the output.</p>
43
+ <h3>Topics</h3>
44
+ <ul>
45
+ <li><code>select</code> + payload 0–7: select active channel</li>
46
+ <li><code>ch0</code>–<code>ch7</code>: store value for that channel</li>
47
+ </ul>
48
+ <h3>Output</h3>
49
+ <dl class="message-properties">
50
+ <dt>payload</dt><dd>Value of selected channel</dd>
51
+ <dt>multiplexer</dt><dd>{ selectedChannel, value, channels }</dd>
52
+ </dl>
53
+ </script>
package/multiplexer.js ADDED
@@ -0,0 +1,69 @@
1
+ module.exports = function(RED) {
2
+ function MultiplexerNode(config) {
3
+ RED.nodes.createNode(this, config);
4
+ var node = this;
5
+
6
+ node.numChannels = parseInt(config.channels, 10) || 8;
7
+ node.selectedChannel = parseInt(config.initialChannel, 10) || 0;
8
+ node.channelValues = {};
9
+
10
+ updateStatus(node);
11
+
12
+ node.on('input', function(msg) {
13
+ if (msg.reset === true) {
14
+ node.channelValues = {};
15
+ node.selectedChannel = parseInt(config.initialChannel, 10) || 0;
16
+ updateStatus(node);
17
+ return;
18
+ }
19
+
20
+ var topic = (msg.topic !== undefined) ? String(msg.topic) : '';
21
+
22
+ if (topic === 'select') {
23
+ var ch = parseInt(msg.payload, 10);
24
+ if (isNaN(ch) || ch < 0 || ch >= node.numChannels) {
25
+ node.warn('Channel out of range: ' + msg.payload + ' (0–' + (node.numChannels - 1) + ')');
26
+ return;
27
+ }
28
+ node.selectedChannel = ch;
29
+ } else if (/^ch[0-7]$/.test(topic)) {
30
+ var idx = parseInt(topic.slice(2), 10);
31
+ if (idx >= node.numChannels) {
32
+ node.warn('Channel ' + topic + ' out of range (configured: ' + node.numChannels + ')');
33
+ return;
34
+ }
35
+ node.channelValues[topic] = msg.payload;
36
+ } else {
37
+ node.warn('Unknown topic: ' + topic + ' (use "select" or "ch0"–"ch' + (node.numChannels - 1) + '")');
38
+ return;
39
+ }
40
+
41
+ var selKey = 'ch' + node.selectedChannel;
42
+ if (!(selKey in node.channelValues)) {
43
+ node.status({ fill:'grey', shape:'ring', text:'CH' + node.selectedChannel + ' → (no value yet)' });
44
+ return;
45
+ }
46
+
47
+ var val = node.channelValues[selKey];
48
+ msg.payload = val;
49
+ msg.multiplexer = {
50
+ selectedChannel: node.selectedChannel,
51
+ value: val,
52
+ channels: Object.assign({}, node.channelValues)
53
+ };
54
+ node.status({ fill:'green', shape:'dot', text:'CH' + node.selectedChannel + ' → ' + val });
55
+ node.send(msg);
56
+ });
57
+
58
+ function updateStatus(n) {
59
+ var selKey = 'ch' + n.selectedChannel;
60
+ if (selKey in n.channelValues) {
61
+ n.status({ fill:'green', shape:'dot', text:'CH' + n.selectedChannel + ' → ' + n.channelValues[selKey] });
62
+ } else {
63
+ n.status({ fill:'grey', shape:'ring', text:'CH' + n.selectedChannel + ' → (no value yet)' });
64
+ }
65
+ }
66
+ }
67
+
68
+ RED.nodes.registerType('multiplexer', MultiplexerNode);
69
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "node-red-contrib-multiplexer",
3
+ "version": "1.0.0",
4
+ "description": "8-channel multiplexer - selects and forwards one of N input channels",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Wobi848/node-red-contrib-rpo-suite.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/Wobi848/node-red-contrib-rpo-suite/issues"
11
+ },
12
+ "files": [
13
+ "multiplexer.js",
14
+ "multiplexer.html",
15
+ "locales",
16
+ "examples"
17
+ ],
18
+ "keywords": [
19
+ "node-red",
20
+ "multiplexer",
21
+ "selector",
22
+ "channel",
23
+ "mux"
24
+ ],
25
+ "author": "sr.rpo",
26
+ "license": "MIT",
27
+ "node-red": {
28
+ "version": "1.0.0",
29
+ "nodes": {
30
+ "multiplexer": "multiplexer.js"
31
+ }
32
+ },
33
+ "engines": {
34
+ "node": ">=14.0.0"
35
+ },
36
+ "scripts": {
37
+ "test": "mocha \"test/**/*_spec.js\" --exit"
38
+ },
39
+ "devDependencies": {
40
+ "mocha": "^10.2.0",
41
+ "node-red": "^3.1.0",
42
+ "node-red-node-test-helper": "^0.3.6"
43
+ }
44
+ }