Skip to content

Commit

Permalink
enhancement for issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
biancode committed Feb 19, 2018
1 parent 730af27 commit 61d5d2e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 52 deletions.
17 changes: 13 additions & 4 deletions src/bacnet-read.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ <h4>Input</h4>

<p>Example of msg.payload.requestArray:</p>
<pre>
let requestArray = [
{objectId:{type:number, instance:number}, properties:[{id:number}, {id:number} ...]},
{objectId:{type:number, instance:number}, properties:[{id:number}, {id:number} ...]}
]
const requestArray = [{
objectId: {type: 8, instance: 4194303},
properties: [{id: 8}]
}]
</pre>

<pre>
{type: 8, instance: 44301}, 28
</pre>

<p>msg.payload.propertyId</p>
Expand All @@ -209,6 +213,11 @@ <h4>Input</h4>
<p>msg.payload.options.invokeId</p>
<p>msg.payload.options.arrayIndex</p>

<pre>
objectId: {type: 8, instance: 44301}
propertyId: 28
</pre>

<h3>All Modes</h3>
<h4>Output</h4>
<p>msg.payload</p>
Expand Down
2 changes: 1 addition & 1 deletion src/bacnet-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function (RED) {
this.objectType = config.objectType || 0
this.objectInstance = config.objectInstance || 0
this.propertyId = config.propertyId || 0
this.arrayIndex = config.arrayIndex || null
this.arrayIndex = config.arrayIndex || 0xFFFFFFFF
this.deviceIPAddress = config.deviceIPAddress || '127.0.0.1'
this.multipleRead = config.multipleRead

Expand Down
57 changes: 31 additions & 26 deletions src/bacnet-write.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Value</h4>
</div>
<div class="form-row">
<label for="node-input-valueTag"><i class="icon-search"></i> <span data-i18n="bacnet-contrib.label.valueTag"></span></label>
<input type="text" id="node-input-valueTag" style="width:60%;" placeholder="0">
<input type="text" id="node-input-valueTag" style="width:60%;" placeholder="9">
<a id="node-lookup-valueTag" class="btn"><i id="node-lookup-topic-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
Expand All @@ -188,7 +188,7 @@ <h4>Properties</h4>
</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="8">
<input type="text" id="node-input-priority" placeholder="15">
</div>
<div class="form-row">
<h4>Device</h4>
Expand Down Expand Up @@ -240,32 +240,34 @@ <h4>Input</h4>

<p>Example of msg.payload.values:</p>
<pre>
let values = [
{objectId:{type:number, instance:number},
values:[
{ property: {id:number, index:number},
value: [
{tag:ApplicationTag, value:object},
{tag:ApplicationTag, value:object} ...
],
priority:number
},
{ property: {id:number, index:number},
value: [
{tag:ApplicationTag, value:object},
{tag:ApplicationTag, value:object} ...
],
priority:number
} ...
]
let values = [{
objectId: {
type: objectType,
instance: objectInstance
},
values: [{
property: {
id: propertyId,
index: index
},
value: [{
tag: valueTag,
value: valueValue
}],
priority: priority
}]
}]
</pre>

<pre>
const values = [
{objectId: {type: 8, instance: 44301}, values: [
{property: {id: 28, index: 12}, value: [{type: 1, value: true}], priority: 8}
]}
];
const values = [{
objectId: {type: 8, instance: 44301},
values: [{
property: {id: 28, index: 12},
value: [{type: 1, value: true}],
priority: 15
}]
}];
</pre>
<p>priority</p>

Expand Down Expand Up @@ -299,7 +301,10 @@ <h4>Input</h4>
<pre>
objectId: {type: 8, instance: 44301},
propertyId: 28,
values: [{tag: 1, value: true}, ...]
values: [{
type: 4,
value: 100
}]
</pre>

<h3>All Modes</h3>
Expand Down
32 changes: 11 additions & 21 deletions src/bacnet-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ module.exports = function (RED) {
this.deviceIPAddress = config.deviceIPAddress || '127.0.0.1'
this.objectType = config.objectType || 0
this.objectInstance = config.objectInstance || 0
this.valueTag = config.valueTag || 0
this.valueTag = config.valueTag || 9
this.valueValue = config.valueValue || null
this.propertyId = config.propertyId || 0
this.priority = config.priority || 8
this.priority = config.priority || 15
this.invokeId = config.invokeId || null
this.arrayIndex = config.arrayIndex || null
this.arrayIndex = config.arrayIndex || 0xFFFFFFFF
this.maxSegments = config.maxSegments
this.maxAdpu = config.maxAdpu
this.invokeId = config.invokeId
Expand All @@ -40,12 +40,7 @@ module.exports = function (RED) {

node.on('input', function (msg) {
if (!node.connector) {
node.error(new Error('Client Not Ready To Read'), msg)
return
}

if (!msg.payload.hasOwnProperty('values')) {
node.error(new Error('Property values in payload not found for write operation!'))
node.error(new Error('Client Not Ready To Write'), msg)
return
}

Expand All @@ -59,17 +54,17 @@ module.exports = function (RED) {
type: node.objectType,
instance: node.objectInstance
},
values: {
values: [{
property: {
id: node.propertyId,
index: node.arrayIndex
},
value: { // TODO: needs maybe a JS editor to write objects value
value: [{
tag: node.valueTag,
value: JSON.parse(node.valueValue)
},
value: node.valueValue
}],
priority: node.priority
}
}]
}]

node.connector.client.writePropertyMultiple(
Expand All @@ -89,19 +84,14 @@ module.exports = function (RED) {
} else {
bacnetCore.internalDebugLog('Write')

if (options) {
options.arrayIndex = msg.payload.options.arrayIndex || node.arrayIndex
options.priority = msg.payload.options.priority || node.priority
}

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

let defaultValues = [{ // TODO: needs maybe a JS editor to write objects value
let defaultValues = [{
tag: node.valueTag,
value: JSON.parse(node.valueValue)
value: node.valueValue
}]

node.connector.client.writeProperty(
Expand Down

0 comments on commit 61d5d2e

Please sign in to comment.