svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2829 4c2c50f60730
parent 2828 be947a338760
child 2833 e74123b966ac
equal deleted inserted replaced
2828:be947a338760 2829:4c2c50f60730
   468 </xsl:text>
   468 </xsl:text>
   469     <xsl:text>};
   469     <xsl:text>};
   470 </xsl:text>
   470 </xsl:text>
   471     <xsl:text>
   471     <xsl:text>
   472 </xsl:text>
   472 </xsl:text>
   473     <xsl:text>// Register message reception handler 
   473     <xsl:text>// Register message reception handler
   474 </xsl:text>
   474 </xsl:text>
   475     <xsl:text>ws.onmessage = function (evt) {
   475     <xsl:text>ws.onmessage = function (evt) {
   476 </xsl:text>
   476 </xsl:text>
   477     <xsl:text>
   477     <xsl:text>
   478 </xsl:text>
   478 </xsl:text>
   562 </xsl:text>
   562 </xsl:text>
   563     <xsl:text>
   563     <xsl:text>
   564 </xsl:text>
   564 </xsl:text>
   565     <xsl:text>const typedarray_types = {
   565     <xsl:text>const typedarray_types = {
   566 </xsl:text>
   566 </xsl:text>
   567     <xsl:text>    INT: Int16Array,
   567     <xsl:text>    INT: (number) =&gt; new Int16Array([number]),
   568 </xsl:text>
   568 </xsl:text>
   569     <xsl:text>    BOOL: Uint8Array
   569     <xsl:text>    BOOL: (truth) =&gt; new Int16Array([truth]),
       
   570 </xsl:text>
       
   571     <xsl:text>    STRING: (str) =&gt; {
       
   572 </xsl:text>
       
   573     <xsl:text>        // beremiz default string max size is 128
       
   574 </xsl:text>
       
   575     <xsl:text>        str = str.slice(0,128);
       
   576 </xsl:text>
       
   577     <xsl:text>        binary = new Uint8Array(str.length + 1);
       
   578 </xsl:text>
       
   579     <xsl:text>        binary[0] = str.length;
       
   580 </xsl:text>
       
   581     <xsl:text>        for(var i = 0; i &lt; str.length; i++){
       
   582 </xsl:text>
       
   583     <xsl:text>            binary[i+1] = str.charCodeAt(i);
       
   584 </xsl:text>
       
   585     <xsl:text>        }
       
   586 </xsl:text>
       
   587     <xsl:text>        return binary;
       
   588 </xsl:text>
       
   589     <xsl:text>    }
   570 </xsl:text>
   590 </xsl:text>
   571     <xsl:text>    /* TODO */
   591     <xsl:text>    /* TODO */
   572 </xsl:text>
   592 </xsl:text>
   573     <xsl:text>};
   593     <xsl:text>};
   574 </xsl:text>
   594 </xsl:text>
   598 </xsl:text>
   618 </xsl:text>
   599     <xsl:text>
   619     <xsl:text>
   600 </xsl:text>
   620 </xsl:text>
   601     <xsl:text>// artificially subscribe the watchdog widget to "/heartbeat" hmi variable
   621     <xsl:text>// artificially subscribe the watchdog widget to "/heartbeat" hmi variable
   602 </xsl:text>
   622 </xsl:text>
   603     <xsl:text>// Since dispatch directly calls change_hmi_value, 
   623     <xsl:text>// Since dispatch directly calls change_hmi_value,
   604 </xsl:text>
   624 </xsl:text>
   605     <xsl:text>// PLC will periodically send variable at given frequency
   625     <xsl:text>// PLC will periodically send variable at given frequency
   606 </xsl:text>
   626 </xsl:text>
   607     <xsl:text>subscribers[heartbeat_index].add({
   627     <xsl:text>subscribers[heartbeat_index].add({
   608 </xsl:text>
   628 </xsl:text>
   614 </xsl:text>
   634 </xsl:text>
   615     <xsl:text>    dispatch: function(value) {
   635     <xsl:text>    dispatch: function(value) {
   616 </xsl:text>
   636 </xsl:text>
   617     <xsl:text>        // console.log("Heartbeat" + value);
   637     <xsl:text>        // console.log("Heartbeat" + value);
   618 </xsl:text>
   638 </xsl:text>
   619     <xsl:text>        change_hmi_value(this.indexes[0], "+1");
   639     <xsl:text>        change_hmi_value(heartbeat_index, "+1");
   620 </xsl:text>
   640 </xsl:text>
   621     <xsl:text>    }
   641     <xsl:text>    }
   622 </xsl:text>
   642 </xsl:text>
   623     <xsl:text>});
   643     <xsl:text>});
   624 </xsl:text>
   644 </xsl:text>
   688 </xsl:text>
   708 </xsl:text>
   689     <xsl:text>function send_hmi_value(index, value) {
   709     <xsl:text>function send_hmi_value(index, value) {
   690 </xsl:text>
   710 </xsl:text>
   691     <xsl:text>    let iectype = hmitree_types[index];
   711     <xsl:text>    let iectype = hmitree_types[index];
   692 </xsl:text>
   712 </xsl:text>
   693     <xsl:text>    let jstype = typedarray_types[iectype];
   713     <xsl:text>    let tobinary = typedarray_types[iectype];
   694 </xsl:text>
   714 </xsl:text>
   695     <xsl:text>    send_blob([
   715     <xsl:text>    send_blob([
   696 </xsl:text>
   716 </xsl:text>
   697     <xsl:text>        new Uint8Array([0]),  /* setval = 0 */
   717     <xsl:text>        new Uint8Array([0]),  /* setval = 0 */
   698 </xsl:text>
   718 </xsl:text>
   699     <xsl:text>        new Uint32Array([index]), 
   719     <xsl:text>        new Uint32Array([index]),
   700 </xsl:text>
   720 </xsl:text>
   701     <xsl:text>        new jstype([value])]);
   721     <xsl:text>        tobinary(value)]);
   702 </xsl:text>
   722 </xsl:text>
   703     <xsl:text>
   723     <xsl:text>
   704 </xsl:text>
   724 </xsl:text>
   705     <xsl:text>    cache[index] = value;
   725     <xsl:text>    cache[index] = value;
   706 </xsl:text>
   726 </xsl:text>
   793     <xsl:text>                let cached_val = cache[index];
   813     <xsl:text>                let cached_val = cache[index];
   794 </xsl:text>
   814 </xsl:text>
   795     <xsl:text>                if(cached_val != undefined)
   815     <xsl:text>                if(cached_val != undefined)
   796 </xsl:text>
   816 </xsl:text>
   797     <xsl:text>                    dispatch_value_to_widget(widget, index, cached_val, cached_val);
   817     <xsl:text>                    dispatch_value_to_widget(widget, index, cached_val, cached_val);
   798 </xsl:text>
       
   799     <xsl:text>                
       
   800 </xsl:text>
   818 </xsl:text>
   801     <xsl:text>            }
   819     <xsl:text>            }
   802 </xsl:text>
   820 </xsl:text>
   803     <xsl:text>        }
   821     <xsl:text>        }
   804 </xsl:text>
   822 </xsl:text>
   965     <xsl:text>    this.origin = this.needle_elt.getPointAtLength(0);
   983     <xsl:text>    this.origin = this.needle_elt.getPointAtLength(0);
   966 </xsl:text>
   984 </xsl:text>
   967     <xsl:text>},
   985     <xsl:text>},
   968 </xsl:text>
   986 </xsl:text>
   969   </xsl:template>
   987   </xsl:template>
       
   988   <func:function name="func:escape_quotes">
       
   989     <xsl:param name="txt"/>
       
   990     <xsl:variable name="frst" select="substring-before($txt,'&quot;')"/>
       
   991     <xsl:variable name="frstln" select="string-length($frst)"/>
       
   992     <xsl:choose>
       
   993       <xsl:when test="$frstln &gt; 0 and string-length($txt) &gt; $frstln">
       
   994         <func:result select="concat($frst,'\&quot;',func:escape_quotes(substring-after($txt,'&quot;')))"/>
       
   995       </xsl:when>
       
   996       <xsl:otherwise>
       
   997         <func:result select="$txt"/>
       
   998       </xsl:otherwise>
       
   999     </xsl:choose>
       
  1000   </func:function>
   970   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  1001   <xsl:template mode="widget_defs" match="widget[@type='Input']">
   971     <xsl:param name="hmi_element"/>
  1002     <xsl:param name="hmi_element"/>
   972     <xsl:text>frequency: 5,
  1003     <xsl:text>frequency: 5,
   973 </xsl:text>
  1004 </xsl:text>
   974     <xsl:call-template name="defs_by_labels">
  1005     <xsl:call-template name="defs_by_labels">
   994       <xsl:text>        "click", 
  1025       <xsl:text>        "click", 
   995 </xsl:text>
  1026 </xsl:text>
   996       <xsl:text>        evt =&gt; alert('XXX TODO : Edit value'));
  1027       <xsl:text>        evt =&gt; alert('XXX TODO : Edit value'));
   997 </xsl:text>
  1028 </xsl:text>
   998     </xsl:if>
  1029     </xsl:if>
   999     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-][0-9]+')]">
  1030     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
  1000       <xsl:text>    document.getElementById("</xsl:text>
  1031       <xsl:text>    document.getElementById("</xsl:text>
  1001       <xsl:value-of select="@id"/>
  1032       <xsl:value-of select="@id"/>
  1002       <xsl:text>").addEventListener(
  1033       <xsl:text>").addEventListener(
  1003 </xsl:text>
  1034 </xsl:text>
  1004       <xsl:text>        "click", 
  1035       <xsl:text>        "click", 
  1005 </xsl:text>
  1036 </xsl:text>
  1006       <xsl:text>        evt =&gt; {let new_val = change_hmi_value(this.indexes[0], "</xsl:text>
  1037       <xsl:text>        evt =&gt; {let new_val = change_hmi_value(this.indexes[0], "</xsl:text>
  1007       <xsl:value-of select="@inkscape:label"/>
  1038       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
  1008       <xsl:text>");
  1039       <xsl:text>");
  1009 </xsl:text>
  1040 </xsl:text>
  1010       <xsl:text>                this.value_elt.textContent = String(new_val);});
  1041       <xsl:text>                this.value_elt.textContent = String(new_val);});
  1011 </xsl:text>
  1042 </xsl:text>
  1012     </xsl:for-each>
  1043     </xsl:for-each>