-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break out status as own node, add radio connection states
- Loading branch information
1 parent
e5e5d08
commit e4041b6
Showing
7 changed files
with
162 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script type="text/javascript"> | ||
RED.nodes.registerType('flexradio-status', { | ||
category: 'flexradio', | ||
color: '#a6bbcf', | ||
defaults: { | ||
name: {value: ''}, | ||
radio: {value: '', type: 'flexradio-radio', required: true}, | ||
client_handle: {value: ''} | ||
}, | ||
inputs: 0, | ||
outputs: 1, | ||
icon: 'file.png', | ||
label: function() { | ||
return this.name || 'flexradio-status'; | ||
} | ||
}); | ||
</script> | ||
|
||
<script type="text/html" data-template-name="flexradio-status"> | ||
<div class="form-row"> | ||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label> | ||
<input type="text" id="node-input-name" placeholder="Name"> | ||
</div> | ||
<div class="form-row"> | ||
<label for="node-input-radio"><i class="fa fa-sign-in"></i> FlexRadio</label> | ||
<input type="text" id="node-input-radio" placeholder="FlexRadio"> | ||
</div> | ||
<div id="client-handle" class="form-row" style="padding-left:20px;"> | ||
<label for="node-input-client_handle"><i class="fa fa-tag"></i> Handle</label> | ||
<input type="text" id="node-input-client_handle" placeholder="Client Handle (optional)"> | ||
</div> | ||
</script> | ||
|
||
<script type="text/html" data-help-name="flexradio-status"> | ||
<p>Receives FlexRadio 6xxx series status messages and inects them into the flow. This includes radio connection changes.</p> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
module.exports = function(RED) { | ||
"use strict" | ||
|
||
function FlexRadioStatusNode(config) { | ||
RED.nodes.createNode(this, config); | ||
|
||
const node = this; | ||
node.name = config.name; | ||
node.radio = RED.nodes.getNode(config.radio); | ||
node.clientHandle = config.client_handle; | ||
|
||
if (!node.radio) { // No config node configured, should not happen | ||
node.status({fill:'red', shape:'circle', text:'not configured'}); | ||
return; | ||
} | ||
|
||
const radio = node.radio; | ||
radio.on('connecting', function() { | ||
updateNodeStatus(); | ||
}); | ||
|
||
radio.on('connected', function() { | ||
updateNodeStatus(); | ||
}); | ||
|
||
radio.on('disconnected', function() { | ||
updateNodeStatus(); | ||
}); | ||
|
||
radio.on('status', function(status_data) { | ||
node.log(JSON.stringify(status_data)); | ||
const topic = extractMessageTopic(status_data); | ||
const status_msg = { | ||
topic: topic, | ||
client: status_data.client, | ||
payload: status_data[topic] | ||
}; | ||
|
||
node.send(status_msg); | ||
}); | ||
|
||
function extractMessageTopic(message) { | ||
// remove 'header' fields and find topical fields of message | ||
const topics = Object.keys(message).filter(function(key) { | ||
return !(['type', 'client'].includes(key)); | ||
}); | ||
|
||
if (topics.length != 1) { | ||
node.log("ERROR: message from radio has more than one TOPIC!"); | ||
node.log(topics); | ||
} | ||
|
||
if (topics.length >= 1) { | ||
return topics[0]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function updateNodeStatus() { | ||
switch (radio.state) { | ||
case 'connecting': | ||
node.status({fill:'green', shape:'circle', text:'connecting'}); | ||
break; | ||
case 'connected': | ||
node.status({fill:'green', shape:'dot', text:radio.radioName()}); | ||
break; | ||
case 'disconnected': | ||
node.status({fill:'red', shape:'dot', text:'not connected'}); | ||
break; | ||
default: | ||
node.status({fill:'red', shape:'circle', text:radio.state}); | ||
break; | ||
} | ||
|
||
// Inject changes in radio state to the flow | ||
const status_msg = { | ||
topic: 'connection', | ||
client: null, | ||
payload: radio.state | ||
}; | ||
|
||
node.send(status_msg); | ||
} | ||
|
||
updateNodeStatus(); | ||
} | ||
|
||
RED.nodes.registerType("flexradio-status", FlexRadioStatusNode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters