-
Notifications
You must be signed in to change notification settings - Fork 11
/
ads-notification.js
87 lines (76 loc) · 2.63 KB
/
ads-notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
module.exports = function (RED) {
'use strict'
// var util = require('util')
var debug = require('debug')('node-red-contrib-ads:adsNotificationNode')
function adsNotificationNode(config) {
RED.nodes.createNode(this, config)
var node = this
node.adsDatasource = RED.nodes.getNode(config.datasource)
if (node.adsDatasource) {
node.useIndex = config.useIndex,
node.symname = config.varName,
node.indexGroup = config.indexGroup,
node.indexOffset = config.indexOffset,
node.adstype = config.varTyp
node.bytelength = config.varSize
node.array = config.isArray
node.lowindex = config.varLowIndex
node.highindex = config.varHighIndex
node.timezone = config.timezone
node.transmissionMode = config.transmissionMode
node.maxDelay = config.maxDelay
node.cycleTime = config.cycleTime
node.property = config.property||'payload'
node.topic = config.topic||''
node.hasTopic = String(node.topic).length > 0
if (node.useIndex) {
delete(node.symname)
node.indexGroup = parseInt(node.indexGroup.toString())
if (isNaN(node.indexGroup)) {
node.indexGroup = 0
}
node.indexOffset = parseInt(node.indexOffset.toString())
if (isNaN(node.indexOffset)) {
node.indexOffset = 0
}
} else {
delete(node.indexGroup)
delete(node.indexOffset)
}
debug('config:',node)
node.onAdsData = function (handle){
debug('onAdsData:','node.id',node.id,'node.symname',node.symname,'handle.value',handle.value)
var msg = {}
RED.util.setMessageProperty(msg, node.property, handle.value)
if (node.hasTopic) {
msg.topic = node.topic
}
node.send(msg)
debug('onAdsData:','node.id',node.id,'node.symname',node.symname,'msg',msg)
// node.setStatus()
}
// node.setStatus = function (nodeState,txt){
// node.setAdsState = function (nodeState,txt){
// switch (nodeState)
// case NOTCONNECTED:
// break
// case NOTCONNECTFEHLER:
// break
// case CONNECTEDOTHER:
// break
// case CONNECTEDRUN:
// break
//red, green, yellow, blue or grey
// if (txt) {
// node.status({fill:"red",shape:"ring",text:node.status.txt})
// }
// }
node.adsDatasource.subscribe(node)
node.on('close', function (done) {
debug('close:','enter')
node.adsDatasource.unsubscribe(node,done)
})
}
}
RED.nodes.registerType('ADS Notification', adsNotificationNode)
}