# HG changeset patch
# User Edouard Tisserant
# Date 1572208690 -3600
# Node ID e521e0d133d5032d8e1d998245434abfcc49f4aa
# Parent a6be58a1a8b7540f46c8851cc27997fa2e854bc9
SVGHMI: fixed HMI->PLC dataflow : not updates as expected, and not initialized properly after subscribe.
diff -r a6be58a1a8b7 -r e521e0d133d5 svghmi/gen_index_xhtml.xslt
--- a/svghmi/gen_index_xhtml.xslt Thu Oct 24 11:20:04 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt Sun Oct 27 21:38:10 2019 +0100
@@ -330,6 +330,12 @@
+ let oldval = cache[index];
+
+ cache[index] = value;
+
+
+
if(widgets.size > 0) {
for(let widget of widgets){
@@ -346,11 +352,11 @@
if(typeof(d) == "function" && idxidx == 0){
- return d.call(widget,value);
+ return d.call(widget, value, oldval);
}else if(typeof(d) == "object" && d.length >= idxidx){
- d[idxidx].call(widget,value);
+ return d[idxidx].call(widget, value, oldval);
}/* else dispatch_0, ..., dispatch_n ? */
@@ -364,12 +370,6 @@
}
-
-
- cache[index] = value;
-
-
-
};
diff -r a6be58a1a8b7 -r e521e0d133d5 svghmi/svghmi.c
--- a/svghmi/svghmi.c Thu Oct 24 11:20:04 2019 +0200
+++ b/svghmi/svghmi.c Sun Oct 27 21:38:10 2019 +0100
@@ -31,6 +31,7 @@
typedef enum {
buf_free = 0,
+ buf_new,
buf_set,
buf_tosend
} buf_state_t;
@@ -89,6 +90,7 @@
dsc->age_ms += ticktime_ms;
}else{
dsc->wstate = buf_tosend;
+ global_write_dirty = 1;
}
}
}
@@ -100,14 +102,18 @@
/* if new value differs from previous one */
USINT sz = __get_type_enum_size(dsc->type);
- if(memcmp(dest_p, visible_value_p, sz) != 0){
+ if(dsc->wstate == buf_new || memcmp(dest_p, visible_value_p, sz) != 0){
/* copy and flag as set */
memcpy(dest_p, visible_value_p, sz);
- if(dsc->wstate == buf_free) {
- dsc->wstate = buf_set;
+ if(dsc->wstate == buf_new || dsc->wstate == buf_free) {
+ if(dsc->wstate == buf_new || ticktime_ms > dsc->refresh_period_ms){
+ dsc->wstate = buf_tosend;
+ global_write_dirty = 1;
+ } else {
+ dsc->wstate = buf_set;
+ }
dsc->age_ms = 0;
}
- global_write_dirty = 1;
}
AtomicCompareExchange(&dsc->wlock, 1, 0);
@@ -168,6 +174,11 @@
{
while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield();
dsc->refresh_period_ms = refresh_period_ms;
+ if(refresh_period_ms) {
+ dsc->wstate = buf_new;
+ } else {
+ dsc->wstate = buf_free;
+ }
AtomicCompareExchange(&dsc->wlock, 1, 0);
}
diff -r a6be58a1a8b7 -r e521e0d133d5 svghmi/svghmi.js
--- a/svghmi/svghmi.js Thu Oct 24 11:20:04 2019 +0200
+++ b/svghmi/svghmi.js Sun Oct 27 21:38:10 2019 +0100
@@ -5,6 +5,9 @@
function dispatch_value(index, value) {
let widgets = subscribers[index];
+ let oldval = cache[index];
+ cache[index] = value;
+
if(widgets.size > 0) {
for(let widget of widgets){
let idxidx = widget.indexes.indexOf(index);
@@ -13,18 +16,15 @@
}
let d = widget.dispatch;
if(typeof(d) == "function" && idxidx == 0){
- return d.call(widget,value);
+ return d.call(widget, value, oldval);
}else if(typeof(d) == "object" && d.length >= idxidx){
- d[idxidx].call(widget,value);
+ return d[idxidx].call(widget, value, oldval);
}/* else dispatch_0, ..., dispatch_n ? */
/*else {
throw new Error("Dunno how to dispatch to widget at index = " + index);
}*/
}
}
-
- cache[index] = value;
-
};
function init_widgets() {
diff -r a6be58a1a8b7 -r e521e0d133d5 tests/svghmi/plc.xml
--- a/tests/svghmi/plc.xml Thu Oct 24 11:20:04 2019 +0200
+++ b/tests/svghmi/plc.xml Sun Oct 27 21:38:10 2019 +0100
@@ -1,7 +1,7 @@
-
+
@@ -34,64 +34,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TargetPressure
-
-
-
-
-
-
- 1
-
@@ -140,7 +82,7 @@
-
+
@@ -149,59 +91,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Pressure
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -213,15 +102,33 @@
-
+
-
-
-
+
- AddOut
+ Sloth
+
+
+
+
+
+
+
+
+
+
+
+ Pressure
+
+
+
+
+
+
+ TargetPressure
+
diff -r a6be58a1a8b7 -r e521e0d133d5 tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Thu Oct 24 11:20:04 2019 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Sun Oct 27 21:38:10 2019 +0100
@@ -76,12 +76,12 @@
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:document-units="px"
- inkscape:current-layer="g84"
+ inkscape:current-layer="hmi0"
showgrid="false"
units="px"
inkscape:zoom="0.84375"
- inkscape:cx="-12.406671"
- inkscape:cy="380.60108"
+ inkscape:cx="-391.07334"
+ inkscape:cy="346.23071"
inkscape:window-width="1600"
inkscape:window-height="886"
inkscape:window-x="0"
@@ -195,8 +195,8 @@
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#e6e6e6;fill-opacity:1;fill-rule:nonzero;stroke:#ff6600;stroke-width:5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="path89"
sodipodi:sides="3"
- sodipodi:cx="580.74072"
- sodipodi:cy="-236.2599"
+ sodipodi:cx="596.74072"
+ sodipodi:cy="-216.2599"
sodipodi:r1="59.825443"
sodipodi:r2="29.912722"
sodipodi:arg1="0.52359878"
@@ -204,13 +204,13 @@
inkscape:flatsided="true"
inkscape:rounded="0"
inkscape:randomized="0"
- d="m 632.55108,-206.34718 -103.62071,0 51.81035,-89.73817 z"
+ d="m 648.55108,-186.34718 -103.62071,0 51.81035,-89.73817 z"
inkscape:transform-center-y="14.956363"
inkscape:label="-100" />
+ inkscape:label="HMI:Meter@/PUMP/SLOTH">