113 |
113 |
114 // subscription state as needed by widget now |
114 // subscription state as needed by widget now |
115 // hmitree indexed array of Sets of widgets objects |
115 // hmitree indexed array of Sets of widgets objects |
116 var subscribers = hmitree_types.map(_ignored => new Set()); |
116 var subscribers = hmitree_types.map(_ignored => new Set()); |
117 |
117 |
|
118 // artificially subscribe the watchdog widget to "/heartbeat" hmi variable |
|
119 // Since dispatch directly calls change_hmi_value, |
|
120 // PLC will periodically send variable at given frequency |
|
121 subscribers[heartbeat_index].add({ |
|
122 /* type: "Watchdog", */ |
|
123 frequency: 1, |
|
124 indexes: [heartbeat_index], |
|
125 dispatch: function(value) { |
|
126 console.log("Heartbeat" + value); |
|
127 change_hmi_value(this.indexes[0], "+1"); |
|
128 } |
|
129 }); |
|
130 |
118 function update_subscriptions() { |
131 function update_subscriptions() { |
119 let delta = []; |
132 let delta = []; |
120 for(let index = 0; index < subscribers.length; index++){ |
133 for(let index = 0; index < subscribers.length; index++){ |
121 let widgets = subscribers[index]; |
134 let widgets = subscribers[index]; |
122 |
135 |
123 // periods are in ms |
136 // periods are in ms |
124 let previous_period = subscriptions[index]; |
137 let previous_period = subscriptions[index]; |
125 |
138 |
|
139 // subscribing with a zero period is unsubscribing |
126 let new_period = 0; |
140 let new_period = 0; |
127 if(widgets.size > 0) { |
141 if(widgets.size > 0) { |
128 let maxfreq = 0; |
142 let maxfreq = 0; |
129 for(let widget of widgets) |
143 for(let widget of widgets) |
130 if(maxfreq < widget.frequency) |
144 if(maxfreq < widget.frequency) |