Files
node-red-contrib-xilica/nodes/xilica-subscribe.html
2025-12-31 10:21:33 +01:00

170 lines
5.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script type="text/javascript">
RED.nodes.registerType('xilica-subscribe', {
category: 'Xilica',
color: '#dddddd',
defaults: {
name: { value: "" },
action: { value: "subscribe" },
connection: { value: "", type: "xilica-connection" },
rules: { value: [] },
transport: { value: "TCP" }
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-plug",
label: function () {
var act = (this.action || "subscribe").toLowerCase();
if (this.name) {
return this.name;
}
return "xilica " + act;
},
oneditprepare: function () {
var node = this;
var rules = node.rules || [];
if (typeof rules === "string") {
try {
rules = JSON.parse(rules);
} catch (e) {
rules = [];
}
}
if (!Array.isArray(rules)) {
rules = [];
}
$("#node-input-rules").editableList({
addItem: function (container, index, rule) {
rule = rule || {};
var row = $('<div/>').appendTo(container);
var typeField = $('<select/>', {
class: "node-input-rule-type",
style: "width: 120px; margin-right: 5px;"
}).appendTo(row);
$('<option/>', { value: "eq", text: "==" }).appendTo(typeField);
$('<option/>', { value: "idx", text: "Indexed" }).appendTo(typeField);
var valueField = $('<input/>', {
class: "node-input-rule-value",
type: "text",
style: "width: 180px; margin-right: 5px;"
}).appendTo(row);
var fromField = $('<input/>', {
class: "node-input-rule-from",
type: "number",
style: "width: 80px; margin-right: 5px;",
placeholder: "From"
}).appendTo(row);
var toField = $('<input/>', {
class: "node-input-rule-to",
type: "number",
style: "width: 80px;",
placeholder: "To"
}).appendTo(row);
function updateVisibility() {
var t = typeField.val();
if (t === "idx") {
fromField.show();
toField.show();
} else {
fromField.hide();
toField.hide();
}
}
typeField.on("change", updateVisibility);
typeField.val(rule.t || "eq");
valueField.val(rule.v || "");
if (rule.from !== undefined) {
fromField.val(rule.from);
}
if (rule.to !== undefined) {
toField.val(rule.to);
}
updateVisibility();
},
removable: true,
sortable: true
});
(rules || []).forEach(function (r) {
$("#node-input-rules").editableList('addItem', r);
});
},
oneditsave: function () {
var rules = [];
$("#node-input-rules").editableList('items').each(function () {
var row = $(this);
var type = $(".node-input-rule-type", row).val() || "eq";
var value = $(".node-input-rule-value", row).val() || "";
var from = $(".node-input-rule-from", row).val();
var to = $(".node-input-rule-to", row).val();
var rule = { t: type, v: value };
if (type === "idx") {
if (from !== "") {
rule.from = parseInt(from, 10);
}
if (to !== "") {
rule.to = parseInt(to, 10);
}
}
rules.push(rule);
});
this.rules = rules;
}
});
</script>
<script type="text/x-red" data-template-name="xilica-subscribe">
<div class="form-row">
<label for="node-input-name">Name</label>
<input type="text" id="node-input-name">
</div>
<div class="form-row">
<label for="node-input-connection">Connection</label>
<input type="text" id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-action">Action</label>
<select id="node-input-action">
<option value="subscribe">Subscribe</option>
<option value="unsubscribe">Unsubscribe</option>
</select>
</div>
<div class="form-row">
<label>Rules</label>
<ol id="node-input-rules"></ol>
</div>
<div class="form-row">
<label for="node-input-transport">Transport</label>
<select id="node-input-transport">
<option value="TCP">TCP</option>
<option value="UDP">UDP</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="xilica-subscribe">
<p>Builds <code>SUBSCRIBE</code> or <code>UNSUBSCRIBE</code> commands for a Xilica Solaro processor.</p>
<p>On each input message, the node builds the commands and sends them directly to the selected <code>xilica-connection</code>. It then outputs a message with the commands that were sent.</p>
<p><strong>Action</strong> selects whether to generate <code>SUBSCRIBE</code> or <code>UNSUBSCRIBE</code> commands.</p>
<p><strong>Rules</strong> define which control names to generate, similar to the Switch node's rule list:</p>
<ul>
<li><strong>Type ==</strong>: the Value field is used as a full control name (e.g. <code>MASTER_GAIN</code>).</li>
<li><strong>Type Indexed</strong>: the Value field is a base string (e.g. <code>CH</code>), and the From/To fields define a numeric range (e.g. 148 <code>CH1</code><code>CH48</code>).</li>
</ul>
<p><strong>Transport</strong> selects the subscription transport (<code>TCP</code> or <code>UDP</code>). The node generates commands like <code>SUBSCRIBE CH1 "TCP"</code> or <code>SUBSCRIBE CH1 "UDP"</code> and sends them over the selected connection.</p>
<p>The Xilica device connection (IP/port/password) is chosen directly on this node via the <strong>Connection</strong> field.</p>
</script>