Skip to content

Commit

Permalink
feat(device): new device config
Browse files Browse the repository at this point in the history
feat(instance): new instance config
fix(upgrade): upgrade to the new github state of bacstack from @biancoroyal/bacstack release
docs(example): new example
feat(errors): translating errors from enum to text
fix(read): improved read and read multiple
fix(write): improved write and multiple write
  • Loading branch information
biancode committed May 21, 2018
1 parent 8cead2e commit 5bad469
Show file tree
Hide file tree
Showing 18 changed files with 459 additions and 195 deletions.
218 changes: 122 additions & 96 deletions examples/bacnet-simple-demo.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"node-red": {
"nodes": {
"BACnet-Client": "bacnet/bacnet-client.js",
"BACnet-Device": "bacnet/bacnet-device.js",
"BACnet-Instance": "bacnet/bacnet-instance.js",
"BACnet-Read": "bacnet/bacnet-read.js",
"BACnet-Write": "bacnet/bacnet-write.js",
"BACnet-Command": "bacnet/bacnet-command.js"
Expand Down
6 changes: 3 additions & 3 deletions src/bacnet-command.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
isUtc: {value: true},
lowLimit: {value: 0},
highLimit: {value: 0},
deviceIPAddress: {value: ""},
device: {type: "BACnet-Device", required:true},
server: {type: "BACnet-Client", required:true}
},
credentials: {
Expand Down Expand Up @@ -247,8 +247,8 @@ <h4>Device</h4>
<hr>
</div>
<div class="form-row">
<label for="node-input-deviceIPAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.deviceIPAddress"></span></label>
<input type="text" id="node-input-deviceIPAddress" placeholder="127.0.0.1">
<label for="node-input-device"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.device"></span></label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.server"></span></label>
Expand Down
14 changes: 10 additions & 4 deletions src/bacnet-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ module.exports = function (RED) {
this.isUtc = config.isUtc || true
this.lowLimit = config.lowLimit || null
this.highLimit = config.highLimit || null
this.deviceIPAddress = config.deviceIPAddress || '127.0.0.1'
this.credentials = config.credentials

this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress || '127.0.0.1'

this.connector = RED.nodes.getNode(config.server)

let node = this
Expand Down Expand Up @@ -64,7 +66,9 @@ module.exports = function (RED) {
options,
function (err, value) {
if (err) {
node.error(err, msg)
let translatedError = bacnetCore.translateErrorMessage(err)
bacnetCore.internalDebugLog(translatedError)
node.error(translatedError, msg)
} else {
bacnetCore.internalDebugLog('value: ', value)
msg.input = msg.payload
Expand All @@ -80,7 +84,9 @@ module.exports = function (RED) {
options,
function (err, value) {
if (err) {
node.error(err, msg)
let translatedError = bacnetCore.translateErrorMessage(err)
bacnetCore.internalDebugLog(translatedError)
node.error(translatedError, msg)
} else {
bacnetCore.internalDebugLog('value: ', value)
msg.input = msg.payload
Expand Down Expand Up @@ -148,7 +154,7 @@ module.exports = function (RED) {
})

RED.httpAdmin.get('/bacnet/BacnetReinitializedStates', RED.auth.needsPermission('bacnet.CMD.read'), function (req, res) {
let typeList = BACnet.enum.ReinitializedStates
let typeList = BACnet.enum.ReinitializedState
let invertedTypeList = _.toArray(_.invert(typeList))
let resultTypeList = []

Expand Down
40 changes: 40 additions & 0 deletions src/bacnet-device.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
The MIT License
Copyright (c) 2017 - Klaus Landsdorf (http://bianco-royal.de/)
All rights reserved.
node-red-contrib-bacnet
-->

<script type="text/javascript">
RED.nodes.registerType('BACnet-Device', {
category: 'config',
defaults: {
name: {value: ""},
deviceAddress: {value: ''}
},
label: function () {
return this.name || "BACnet Device";
}
});
</script>

<script type="text/x-red" data-template-name="BACnet-Device">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-deviceAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.deviceAddress"></span></label>
<input type="text" id="node-config-input-deviceAddress" placeholder="127.0.0.1">
</div>
</script>

<script type="text/x-red" data-help-name="BACnet-Device">
<h2>BACnet Device node</h2>

<h3>BETA</h3>
<a href="https://fh1ch.github.io/node-bacstack/" target="_blank">API Docs</a>

The device to address via BACnet.
</script>
18 changes: 18 additions & 0 deletions src/bacnet-device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
The MIT License
Copyright (c) 2017 - Klaus Landsdorf (http://bianco-royal.de/)
All rights reserved.
node-red-contrib-bacnet
*/
'use strict'

module.exports = function (RED) {
function BACnetDevice (config) {
RED.nodes.createNode(this, config)
this.name = config.name
this.deviceAddress = config.deviceAddress || '127.0.0.1'
}

RED.nodes.registerType('BACnet-Device', BACnetDevice)
}
40 changes: 40 additions & 0 deletions src/bacnet-instance.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
The MIT License
Copyright (c) 2017 - Klaus Landsdorf (http://bianco-royal.de/)
All rights reserved.
node-red-contrib-bacnet
-->

<script type="text/javascript">
RED.nodes.registerType('BACnet-Instance', {
category: 'config',
defaults: {
name: {value: ""},
instanceAddress: {value: 0}
},
label: function () {
return this.name || "BACnet Instance";
}
});
</script>

<script type="text/x-red" data-template-name="BACnet-Instance">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-instanceAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.instanceAddress"></span></label>
<input type="text" id="node-config-input-instanceAddress" placeholder="0">
</div>
</script>

<script type="text/x-red" data-help-name="BACnet-Instance">
<h2>BACnet Instance node</h2>

<h3>BETA</h3>
<a href="https://fh1ch.github.io/node-bacstack/" target="_blank">API Docs</a>

The Instance to address via BACnet.
</script>
18 changes: 18 additions & 0 deletions src/bacnet-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
The MIT License
Copyright (c) 2017 - Klaus Landsdorf (http://bianco-royal.de/)
All rights reserved.
node-red-contrib-bacnet
*/
'use strict'

module.exports = function (RED) {
function BACnetInstance (config) {
RED.nodes.createNode(this, config)
this.name = config.name
this.instanceAddress = parseInt(config.instanceAddress) || 0
}

RED.nodes.registerType('BACnet-Instance', BACnetInstance)
}
20 changes: 8 additions & 12 deletions src/bacnet-read.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
defaults: {
name: {value: ''},
objectType: {value: ''},
objectInstance: {value: ''},
instance: {type: "BACnet-Instance", required:true},
propertyId: {value: ''},
arrayIndex: {value: ''},
deviceIPAddress: {value: ''},
device: {type: "BACnet-Device", required:true},
server: {type: "BACnet-Client", required:true},
multipleRead: {value: false}
},
Expand Down Expand Up @@ -122,8 +121,8 @@
<a id="node-lookup-objectType" class="btn"><i id="node-lookup-topic-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-input-objectInstance"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.objectInstance"></span></label>
<input type="text" id="node-input-objectInstance" placeholder="400001">
<label for="node-input-instance"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.instance"></span></label>
<input type="text" id="node-input-instance">
</div>
<div class="form-row">
<h4>Properties</h4>
Expand All @@ -135,16 +134,13 @@ <h4>Properties</h4>
<a id="node-lookup-propertyId" class="btn"><i id="node-lookup-topic-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-input-arrayIndex"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.arrayIndex"></span></label>
<input type="text" id="node-input-arrayIndex" placeholder="all">
</div>
<div class="form-row">
<h4>Device</h4>
<hr>
<h4>Device and Interface</h4>
<hr>
</div>
<div class="form-row">
<label for="node-input-deviceIPAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.deviceIPAddress"></span></label>
<input type="text" id="node-input-deviceIPAddress" placeholder="127.0.0.1">
<label for="node-input-device"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.device"></span></label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.server"></span></label>
Expand Down
53 changes: 37 additions & 16 deletions src/bacnet-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ module.exports = function (RED) {
RED.nodes.createNode(this, config)

this.name = config.name
this.objectType = config.objectType || 0
this.objectInstance = config.objectInstance || 0
this.propertyId = config.propertyId || 0
this.arrayIndex = config.arrayIndex || 0xFFFFFFFF
this.deviceIPAddress = config.deviceIPAddress || '127.0.0.1'
this.objectType = parseInt(config.objectType)
this.propertyId = parseInt(config.propertyId)
this.multipleRead = config.multipleRead

this.instance = RED.nodes.getNode(config.instance)
this.objectInstance = this.instance.instanceAddress || 0

this.device = RED.nodes.getNode(config.device)
this.deviceIPAddress = this.device.deviceAddress || '127.0.0.1'

this.connector = RED.nodes.getNode(config.server)

let node = this
Expand All @@ -41,22 +44,31 @@ module.exports = function (RED) {
let defaultRequestArray = [{
objectId: {
type: node.objectType,
instance: node.objectInstance
instance: parseInt(node.objectInstance)
},
properties: [{id: node.propertyId}]
properties: [{id: parseInt(node.propertyId)}]
}]

try {
bacnetCore.internalDebugLog('readPropertyMultiple default requestArray: ' + JSON.stringify(defaultRequestArray))
bacnetCore.internalDebugLog('readPropertyMultiple msg.payload.requestArray: ' + JSON.stringify(msg.payload.requestArray))
bacnetCore.internalDebugLog('readProperty node.propertyId: ' + node.propertyId)
} catch (e) {
bacnetCore.internalDebugLog('writeProperty error: ' + e)
}

node.connector.client.readPropertyMultiple(
msg.payload.deviceIPAddress || node.deviceIPAddress,
msg.payload.requestArray || defaultRequestArray,
options,
function (err, value) {
function (err, result) {
if (err) {
node.error(err, msg)
let translatedError = bacnetCore.translateErrorMessage(err)
bacnetCore.internalDebugLog(translatedError)
node.error(translatedError, msg)
} else {
bacnetCore.internalDebugLog('value: ', value)
msg.input = msg.payload
msg.payload = value
msg.payload = result
node.send(msg)
}
})
Expand All @@ -65,21 +77,30 @@ module.exports = function (RED) {

let objectId = {
type: node.objectType,
instance: node.objectInstance
instance: parseInt(node.objectInstance)
}

try {
bacnetCore.internalDebugLog('readProperty default objectId: ' + JSON.stringify(objectId))
bacnetCore.internalDebugLog('readProperty msg.payload.objectId: ' + JSON.stringify(msg.payload.objectId))
bacnetCore.internalDebugLog('readProperty node.propertyId: ' + node.propertyId)
} catch (e) {
bacnetCore.internalDebugLog('writeProperty error: ' + e)
}

node.connector.client.readProperty(
msg.payload.deviceIPAddress || node.deviceIPAddress,
msg.payload.objectId || objectId,
msg.payload.propertyId || node.propertyId,
options,
function (err, value) {
function (err, result) {
if (err) {
node.error(err, msg)
let translatedError = bacnetCore.translateErrorMessage(err)
bacnetCore.internalDebugLog(translatedError)
node.error(translatedError, msg)
} else {
bacnetCore.internalDebugLog('value: ', value)
msg.input = msg.payload
msg.payload = value
msg.payload = result
node.send(msg)
}
})
Expand Down
28 changes: 8 additions & 20 deletions src/bacnet-write.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
color: "#16BAC4",
defaults: {
name: {value: ''},
deviceIPAddress: {value: ''},
objectType: {value: ''},
objectInstance: {value: ''},
instance: {type: "BACnet-Instance", required:true},
valueTag: {value: ''},
valueValue: {value: ''},
propertyId: {value: ''},
arrayIndex: {value: ''},
device: {type: "BACnet-Device", required:true},
server: {type: "BACnet-Client", required:true},
multipleWrite: {value: false}
},
Expand Down Expand Up @@ -153,8 +152,8 @@
<a id="node-lookup-objectType" class="btn"><i id="node-lookup-topic-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-input-objectInstance"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.objectInstance"></span></label>
<input type="text" id="node-input-objectInstance" placeholder="4194303">
<label for="node-input-instance"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.instance"></span></label>
<input type="text" id="node-input-instance">
</div>
<div class="form-row">
<h4>Value</h4>
Expand All @@ -179,24 +178,13 @@ <h4>Properties</h4>
<a id="node-lookup-propertyId" class="btn"><i id="node-lookup-topic-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-input-invokeId"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.invokeId"></span></label>
<input type="text" id="node-input-invokeId" placeholder="auto">
</div>
<div class="form-row">
<label for="node-input-arrayIndex"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.arrayIndex"></span></label>
<input type="text" id="node-input-arrayIndex" placeholder="all">
</div>
<div class="form-row">
<label for="node-input-priority"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.priority"></span></label>
<input type="text" id="node-input-priority" placeholder="15">
</div>
<div class="form-row">
<h4>Device</h4>
<hr>
<h4>Device and Interface</h4>
<hr>
</div>
<div class="form-row">
<label for="node-input-deviceIPAddress"><i class="icon-tag"></i> <span data-i18n="bacnet-contrib.label.deviceIPAddress"></span></label>
<input type="text" id="node-input-deviceIPAddress" placeholder="127.0.0.1">
<label for="node-input-device"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.device"></span></label>
<input type="text" id="node-input-device">
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-globe"></i> <span data-i18n="bacnet-contrib.label.server"></span></label>
Expand Down

0 comments on commit 5bad469

Please sign in to comment.