svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2822 9101a72a1da0
parent 2814 2cabc4773885
child 2826 1e5abecc3cde
--- a/svghmi/gen_index_xhtml.xslt	Wed Dec 18 13:31:22 2019 +0100
+++ b/svghmi/gen_index_xhtml.xslt	Fri Jan 10 13:15:07 2020 +0100
@@ -264,6 +264,12 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:text>var heartbeat_index = </xsl:text>
+    <xsl:value-of select="$indexed_hmitree/*[@hmipath = '/HEARTBEAT']/@index"/>
+    <xsl:text>;
+</xsl:text>
+    <xsl:text>
+</xsl:text>
     <xsl:text>var hmitree_types = [
 </xsl:text>
     <xsl:for-each select="$indexed_hmitree/*">
@@ -576,6 +582,32 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:text>// artificially subscribe the watchdog widget to "/heartbeat" hmi variable
+</xsl:text>
+    <xsl:text>// Since dispatch directly calls change_hmi_value, 
+</xsl:text>
+    <xsl:text>// PLC will periodically send variable at given frequency
+</xsl:text>
+    <xsl:text>subscribers[heartbeat_index].add({
+</xsl:text>
+    <xsl:text>    /* type: "Watchdog", */
+</xsl:text>
+    <xsl:text>    frequency: 1,
+</xsl:text>
+    <xsl:text>    indexes: [heartbeat_index],
+</xsl:text>
+    <xsl:text>    dispatch: function(value) {
+</xsl:text>
+    <xsl:text>        console.log("Heartbeat" + value);
+</xsl:text>
+    <xsl:text>        change_hmi_value(this.indexes[0], "+1");
+</xsl:text>
+    <xsl:text>    }
+</xsl:text>
+    <xsl:text>});
+</xsl:text>
+    <xsl:text>
+</xsl:text>
     <xsl:text>function update_subscriptions() {
 </xsl:text>
     <xsl:text>    let delta = [];
@@ -592,6 +624,8 @@
 </xsl:text>
     <xsl:text>
 </xsl:text>
+    <xsl:text>        // subscribing with a zero period is unsubscribing
+</xsl:text>
     <xsl:text>        let new_period = 0;
 </xsl:text>
     <xsl:text>        if(widgets.size &gt; 0) {