forked from PLCHome/node-red-contrib-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathads-notification.js
66 lines (56 loc) · 1.96 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
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.symname = config.varName
node.adstype = config.varTyp
node.bytelength = config.varSize
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 = node.topic.length > 0
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 () {
debug('close:','enter')
node.adsDatasource.unsubscribe(node)
})
}
}
RED.nodes.registerType('ADS Notification', adsNotificationNode)
}