svghmi/svghmi.js
branchsvghmi
changeset 3080 e5fa1f49f0b9
parent 3078 d345673610b0
child 3082 20a5eb6a02e6
equal deleted inserted replaced
3079:1021c6c74dde 3080:e5fa1f49f0b9
     1 // svghmi.js
     1 // svghmi.js
     2 
     2 
     3 var updates = {};
     3 var updates = {};
     4 var need_cache_apply = []; 
     4 var need_cache_apply = [];
     5 
     5 
     6 
     6 
     7 function dispatch_value(index, value) {
     7 function dispatch_value(index, value) {
     8     let widgets = subscribers(index);
     8     let widgets = subscribers(index);
     9 
     9 
    39     INT: (dv,offset) => [dv.getInt16(offset, true), 2],
    39     INT: (dv,offset) => [dv.getInt16(offset, true), 2],
    40     BOOL: (dv,offset) => [dv.getInt8(offset, true), 1],
    40     BOOL: (dv,offset) => [dv.getInt8(offset, true), 1],
    41     NODE: (dv,offset) => [dv.getInt8(offset, true), 1],
    41     NODE: (dv,offset) => [dv.getInt8(offset, true), 1],
    42     REAL: (dv,offset) => [dv.getFloat32(offset, true), 4],
    42     REAL: (dv,offset) => [dv.getFloat32(offset, true), 4],
    43     STRING: (dv, offset) => {
    43     STRING: (dv, offset) => {
    44         size = dv.getInt8(offset);
    44         const size = dv.getInt8(offset);
    45         return [
    45         return [
    46             String.fromCharCode.apply(null, new Uint8Array(
    46             String.fromCharCode.apply(null, new Uint8Array(
    47                 dv.buffer, /* original buffer */
    47                 dv.buffer, /* original buffer */
    48                 offset + 1, /* string starts after size*/
    48                 offset + 1, /* string starts after size*/
    49                 size /* size of string */
    49                 size /* size of string */
   130         // force reload ignoring cache
   130         // force reload ignoring cache
   131         location.reload(true);
   131         location.reload(true);
   132     }
   132     }
   133 };
   133 };
   134 
   134 
       
   135 hmi_hash_u8 = new Uint8Array(hmi_hash);
   135 
   136 
   136 function send_blob(data) {
   137 function send_blob(data) {
   137     if(data.length > 0) {
   138     if(data.length > 0) {
   138         ws.send(new Blob([new Uint8Array(hmi_hash)].concat(data)));
   139         ws.send(new Blob([hmi_hash_u8].concat(data)));
   139     };
   140     };
   140 };
   141 };
   141 
   142 
   142 const typedarray_types = {
   143 const typedarray_types = {
   143     INT: (number) => new Int16Array([number]),
   144     INT: (number) => new Int16Array([number]),
   146     STRING: (str) => {
   147     STRING: (str) => {
   147         // beremiz default string max size is 128
   148         // beremiz default string max size is 128
   148         str = str.slice(0,128);
   149         str = str.slice(0,128);
   149         binary = new Uint8Array(str.length + 1);
   150         binary = new Uint8Array(str.length + 1);
   150         binary[0] = str.length;
   151         binary[0] = str.length;
   151         for(var i = 0; i < str.length; i++){
   152         for(let i = 0; i < str.length; i++){
   152             binary[i+1] = str.charCodeAt(i);
   153             binary[i+1] = str.charCodeAt(i);
   153         }
   154         }
   154         return binary;
   155         return binary;
   155     }
   156     }
   156     /* TODO */
   157     /* TODO */
   340     }
   341     }
   341 
   342 
   342     if(old_desc){
   343     if(old_desc){
   343         old_desc.widgets.map(([widget,relativeness])=>widget.unsub());
   344         old_desc.widgets.map(([widget,relativeness])=>widget.unsub());
   344     }
   345     }
   345     var new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
   346     const new_offset = page_index == undefined ? 0 : page_index - new_desc.page_index;
   346 
   347 
   347     container_id = page_name + (page_index != undefined ? page_index : "");
   348     const container_id = page_name + (page_index != undefined ? page_index : "");
   348 
   349 
   349     new_desc.widgets.map(([widget,relativeness])=>widget.sub(new_offset,relativeness,container_id));
   350     new_desc.widgets.map(([widget,relativeness])=>widget.sub(new_offset,relativeness,container_id));
   350 
   351 
   351     update_subscriptions();
   352     update_subscriptions();
   352 
   353 
   409     //window.setTimeout(() => location.reload(true), 10000);
   410     //window.setTimeout(() => location.reload(true), 10000);
   410     alert("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+".");
   411     alert("Connection closed. code:"+evt.code+" reason:"+evt.reason+" wasClean:"+evt.wasClean+".");
   411 
   412 
   412 };
   413 };
   413 
   414 
   414 var xmlns = "http://www.w3.org/2000/svg";
   415 const xmlns = "http://www.w3.org/2000/svg";
   415 var edit_callback;
   416 var edit_callback;
   416 const localtypes = {"PAGE_LOCAL":null, "HMI_LOCAL":null}
   417 const localtypes = {"PAGE_LOCAL":null, "HMI_LOCAL":null}
   417 function edit_value(path, valuetype, callback, initial, size) {
   418 function edit_value(path, valuetype, callback, initial, size) {
   418     if(valuetype in localtypes){
   419     if(valuetype in localtypes){
   419         valuetype = (typeof initial) == "number" ? "HMI_REAL" : "HMI_STRING";
   420         valuetype = (typeof initial) == "number" ? "HMI_REAL" : "HMI_STRING";