# HG changeset patch # User Edouard Tisserant # Date 1579274745 -3600 # Node ID 4c2c50f6073033f65a410ab18e6e5cf2e1c1704c # Parent be947a338760bbf2fbbf22b39d2fa3a4e1441433 SVGHMI : HMI_STRING now also supported from HMI to PLC diff -r be947a338760 -r 4c2c50f60730 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed Jan 15 11:13:39 2020 +0100 +++ b/svghmi/gen_index_xhtml.xslt Fri Jan 17 16:25:45 2020 +0100 @@ -470,7 +470,7 @@ - // Register message reception handler + // Register message reception handler ws.onmessage = function (evt) { @@ -564,9 +564,29 @@ const typedarray_types = { - INT: Int16Array, - - BOOL: Uint8Array + INT: (number) => new Int16Array([number]), + + BOOL: (truth) => new Int16Array([truth]), + + STRING: (str) => { + + // beremiz default string max size is 128 + + str = str.slice(0,128); + + binary = new Uint8Array(str.length + 1); + + binary[0] = str.length; + + for(var i = 0; i < str.length; i++){ + + binary[i+1] = str.charCodeAt(i); + + } + + return binary; + + } /* TODO */ @@ -600,7 +620,7 @@ // artificially subscribe the watchdog widget to "/heartbeat" hmi variable - // Since dispatch directly calls change_hmi_value, + // Since dispatch directly calls change_hmi_value, // PLC will periodically send variable at given frequency @@ -616,7 +636,7 @@ // console.log("Heartbeat" + value); - change_hmi_value(this.indexes[0], "+1"); + change_hmi_value(heartbeat_index, "+1"); } @@ -690,15 +710,15 @@ let iectype = hmitree_types[index]; - let jstype = typedarray_types[iectype]; + let tobinary = typedarray_types[iectype]; send_blob([ new Uint8Array([0]), /* setval = 0 */ - new Uint32Array([index]), - - new jstype([value])]); + new Uint32Array([index]), + + tobinary(value)]); @@ -796,8 +816,6 @@ dispatch_value_to_widget(widget, index, cached_val, cached_val); - - } } @@ -967,6 +985,19 @@ }, + + + + + + + + + + + + + frequency: 5, @@ -996,7 +1027,7 @@ evt => alert('XXX TODO : Edit value')); - + document.getElementById(" ").addEventListener( @@ -1004,7 +1035,7 @@ "click", evt => {let new_val = change_hmi_value(this.indexes[0], " - + "); this.value_elt.textContent = String(new_val);}); diff -r be947a338760 -r 4c2c50f60730 svghmi/gen_index_xhtml.ysl2 --- a/svghmi/gen_index_xhtml.ysl2 Wed Jan 15 11:13:39 2020 +0100 +++ b/svghmi/gen_index_xhtml.ysl2 Fri Jan 17 16:25:45 2020 +0100 @@ -373,6 +373,21 @@ | }, } + def "func:escape_quotes" { + param "txt"; + // have to use a python string to enter escaped quote + const "frst", !"substring-before($txt,'\"')"!; + const "frstln", "string-length($frst)"; + choose { + when "$frstln > 0 and string-length($txt) > $frstln" { + result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!; + } + otherwise { + result "$txt"; + } + } + } + template "widget[@type='Input']", mode="widget_defs" { param "hmi_element"; | frequency: 5, @@ -387,10 +402,10 @@ | "click", | evt => alert('XXX TODO : Edit value')); } - foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-][0-9]+')]" { + foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { | document.getElementById("«@id»").addEventListener( | "click", - | evt => {let new_val = change_hmi_value(this.indexes[0], "«@inkscape:label»"); + | evt => {let new_val = change_hmi_value(this.indexes[0], "«func:escape_quotes(@inkscape:label)»"); | this.value_elt.textContent = String(new_val);}); /* could gray out value until refreshed */ } diff -r be947a338760 -r 4c2c50f60730 svghmi/svghmi.c --- a/svghmi/svghmi.c Wed Jan 15 11:13:39 2020 +0100 +++ b/svghmi/svghmi.c Fri Jan 17 16:25:45 2020 +0100 @@ -300,7 +300,10 @@ void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); void *dst_p = &rbuf[dsc->buf_index]; uint32_t sz = __get_type_enum_size(dsc->type); -#warning TODO: size of string in recv + + if(__Is_a_string(dsc)){ + sz = ((STRING*)valptr)->len + 1; + } if((valptr + sz) <= end) { diff -r be947a338760 -r 4c2c50f60730 svghmi/svghmi.js --- a/svghmi/svghmi.js Wed Jan 15 11:13:39 2020 +0100 +++ b/svghmi/svghmi.js Fri Jan 17 16:25:45 2020 +0100 @@ -59,7 +59,7 @@ } }; -// Register message reception handler +// Register message reception handler ws.onmessage = function (evt) { let data = evt.data; @@ -106,8 +106,18 @@ }; const typedarray_types = { - INT: Int16Array, - BOOL: Uint8Array + INT: (number) => new Int16Array([number]), + BOOL: (truth) => new Int16Array([truth]), + STRING: (str) => { + // beremiz default string max size is 128 + str = str.slice(0,128); + binary = new Uint8Array(str.length + 1); + binary[0] = str.length; + for(var i = 0; i < str.length; i++){ + binary[i+1] = str.charCodeAt(i); + } + return binary; + } /* TODO */ }; @@ -124,7 +134,7 @@ var subscribers = hmitree_types.map(_ignored => new Set()); // artificially subscribe the watchdog widget to "/heartbeat" hmi variable -// Since dispatch directly calls change_hmi_value, +// Since dispatch directly calls change_hmi_value, // PLC will periodically send variable at given frequency subscribers[heartbeat_index].add({ /* type: "Watchdog", */ @@ -132,7 +142,7 @@ indexes: [heartbeat_index], dispatch: function(value) { // console.log("Heartbeat" + value); - change_hmi_value(this.indexes[0], "+1"); + change_hmi_value(heartbeat_index, "+1"); } }); @@ -169,11 +179,11 @@ function send_hmi_value(index, value) { let iectype = hmitree_types[index]; - let jstype = typedarray_types[iectype]; + let tobinary = typedarray_types[iectype]; send_blob([ new Uint8Array([0]), /* setval = 0 */ - new Uint32Array([index]), - new jstype([value])]); + new Uint32Array([index]), + tobinary(value)]); cache[index] = value; }; @@ -222,7 +232,6 @@ let cached_val = cache[index]; if(cached_val != undefined) dispatch_value_to_widget(widget, index, cached_val, cached_val); - } } svg_root.setAttribute('viewBox',new_desc.bbox.join(" ")); diff -r be947a338760 -r 4c2c50f60730 tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed Jan 15 11:13:39 2020 +0100 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Fri Jan 17 16:25:45 2020 +0100 @@ -31,6 +31,17 @@ + + + + @@ -113,14 +124,14 @@ inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:document-units="px" - inkscape:current-layer="hmi0" + inkscape:current-layer="g208" showgrid="false" units="px" - inkscape:zoom="1.2321777" - inkscape:cx="398.68209" - inkscape:cy="328.86048" - inkscape:window-width="1920" - inkscape:window-height="2105" + inkscape:zoom="2" + inkscape:cx="275.28708" + inkscape:cy="344.53292" + inkscape:window-width="1600" + inkscape:window-height="886" inkscape:window-x="0" inkscape:window-y="27" inkscape:window-maximized="0" @@ -902,13 +913,13 @@ xml:space="preserve" style="font-style:normal;font-weight:normal;font-size:80px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.5px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" x="98.164062" - y="489.12109" + y="469.12109" id="text134" inkscape:label="HMI:Display@/PUMP0/STROUT">8888 8888 + + 8888 + + + + dhu + + + + plop + + + + mhoo + + + + yodl + + + + mhe + +