node-red-contrib-bitunloader
Version:
Unload numbers to a binary string, array of bits, array of bools, object of bits, or object of bools.
98 lines (94 loc) • 4.32 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('bitunloader',{
category: 'function',
color: '#AAAA66',
defaults: {
name: {value:''},
mode: {value:'string',required:true},
prop: {value:'payload'},
padding: {value:'none'},
},
inputs:1,
outputs:1,
icon: 'binary_40x60.png',
label: function() {
return this.name || 'bitunloader';
},
labelStyle: function() {
return this.name?'node_label_italic':'';
},
outputLabels: function() {
let mode;
switch (this.mode) {
case 'string':
mode = 'binary string';
break;
case 'arrayBits':
mode = 'array of bits';
break;
case 'arrayBools':
mode = 'array of bools';
break;
case 'objectBits':
mode = 'object of bits';
break;
case 'objectBools':
mode = 'object of bools'
break;
}
return `msg.${this.prop} to ${mode}`;
},
oneditprepare: function() {
$("#node-input-prop").typedInput({default:'msg',types:['msg']});
},
oneditsave: function() {
if (this.prop === undefined) {
$("#node-input-prop").val("payload");
}
}
});
</script>
<script type="text/html" data-template-name="bitunloader">
<div class="form-row">
<label for="node-input-prop" style="width:120px;"><i class="fa fa-ellipsis-h"></i> Property</label>
<input type="text" id="node-input-prop" placeholder="payload" style="width:70%;">
</div>
<div class="form-row">
<label for="node-input-mode" style="width:120px;"><i class="fa fa-sign-out"></i> Output</label>
<select id="node-input-mode">
<option value="string" selected="selected">Binary string</option>
<option value="arrayBits">Array of bits</option>
<option value="arrayBools">Array of bools</option>
<option value="objectBits">Object of bits</option>
<option value="objectBools">Object of bools</option>
</select>
</div>
<div class="form-row">
<label for="node-input-padding" style="width:120px;"><i class="fa fa-angle-double-left"></i> Pad with zeros</label>
<select id="node-input-padding">
<option value="none" selected="selected">None</option>
<option value="8">8 bit length</option>
<option value="16">16 bit length</option>
<option value="32">32 bit length</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name" style="width:120px;"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="bitunloader">
<p>Converts whole numbers to a form of binary output.</p>
<h3>Details</h3>
<p><b>Note: works with positive numbers only</b></p>
<p>The property specified in the <code>Property</code> field is converted to a binary output form based on the <code>Output</code> option:<br>
<ul>
<li><code>Binary String</code> outputs a binary string with LSB on the right.</li>
<li><code>Array of bits</code> outputs an array of 1s and/or 0s.</li>
<li><code>Array of bools</code> outputs an array of boolean <code>true</code> or <code>false</code>.</li>
<li><code>Object of bits</code> outputs an Object of 1s and/or 0s with the Object keys representing the bit address.</li>
<li><code>Object of bools</code> outputs an Object of boolean <code>true</code> or <code>false</code> with the Object keys representing the bit address.</li>
</ul>
</p>
<p><code>Pad with zeros</code> adds the specified number of leading zeros to the output to fill the result to the length configured. eg. <code>"101"</code> bedcomes <code>"00000101"</code> when set to 8.</p>
</script>