author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Mon, 20 Sep 2021 15:43:10 +0200 | |
changeset 3353 | 962b8ea41c5e |
parent 3295 | 0375d801fff7 |
child 3374 | 9a82918e063c |
permissions | -rw-r--r-- |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
1 |
#include <pthread.h> |
2776
246ae685ab65
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2775
diff
changeset
|
2 |
#include <errno.h> |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
3 |
#include "iec_types_all.h" |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
4 |
#include "POUS.h" |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
5 |
#include "config.h" |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
6 |
#include "beremiz.h" |
2750 | 7 |
|
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
8 |
#define DEFAULT_REFRESH_PERIOD_MS 100 |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
9 |
#define HMI_BUFFER_SIZE %(buffer_size)d |
2776
246ae685ab65
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2775
diff
changeset
|
10 |
#define HMI_ITEM_COUNT %(item_count)d |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
11 |
#define HMI_HASH_SIZE 8 |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
12 |
#define MAX_CONNECTIONS %(max_connections)d |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
13 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
14 |
static uint8_t hmi_hash[HMI_HASH_SIZE] = {%(hmi_hash_ints)s}; |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
15 |
|
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
16 |
/* PLC reads from that buffer */ |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
17 |
static char rbuf[HMI_BUFFER_SIZE]; |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
18 |
|
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
19 |
/* PLC writes to that buffer */ |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
20 |
static char wbuf[HMI_BUFFER_SIZE]; |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
21 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
22 |
/* TODO change that in case of multiclient... */ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
23 |
/* worst biggest send buffer. FIXME : use dynamic alloc ? */ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
24 |
static char sbuf[HMI_HASH_SIZE + HMI_BUFFER_SIZE + (HMI_ITEM_COUNT * sizeof(uint32_t))]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
25 |
static unsigned int sbufidx; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
26 |
|
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
27 |
%(extern_variables_declarations)s |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
28 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
29 |
#define ticktime_ns %(PLC_ticktime)d |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
30 |
static uint16_t ticktime_ms = (ticktime_ns>1000000)? |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
31 |
ticktime_ns/1000000: |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
32 |
1; |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
33 |
|
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
34 |
typedef enum { |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
35 |
buf_free = 0, |
2805
e521e0d133d5
SVGHMI: fixed HMI->PLC dataflow : not updates as expected, and not initialized properly after subscribe.
Edouard Tisserant
parents:
2802
diff
changeset
|
36 |
buf_new, |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
37 |
buf_set, |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
38 |
buf_tosend |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
39 |
} buf_state_t; |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
40 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
41 |
static int global_write_dirty = 0; |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
42 |
|
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
43 |
typedef struct { |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
44 |
void *ptr; |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
45 |
__IEC_types_enum type; |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
46 |
uint32_t buf_index; |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
47 |
|
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
48 |
/* publish/write/send */ |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
49 |
long wlock; |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
50 |
buf_state_t wstate[MAX_CONNECTIONS]; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
51 |
|
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
52 |
/* zero means not subscribed */ |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
53 |
uint16_t refresh_period_ms[MAX_CONNECTIONS]; |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
54 |
uint16_t age_ms[MAX_CONNECTIONS]; |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
55 |
|
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
56 |
/* retrieve/read/recv */ |
2771
361366b891ca
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
2768
diff
changeset
|
57 |
long rlock; |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
58 |
buf_state_t rstate; |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
59 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
60 |
} hmi_tree_item_t; |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
61 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
62 |
static hmi_tree_item_t hmi_tree_item[] = { |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
63 |
%(variable_decl_array)s |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
64 |
}; |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
65 |
|
2789 | 66 |
typedef int(*hmi_tree_iterator)(uint32_t, hmi_tree_item_t*); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
67 |
static int traverse_hmi_tree(hmi_tree_iterator fp) |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
68 |
{ |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
69 |
unsigned int i; |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
70 |
for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){ |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
71 |
hmi_tree_item_t *dsc = &hmi_tree_item[i]; |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
72 |
int res = (*fp)(i, dsc); |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
73 |
if(res != 0){ |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
74 |
return res; |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
75 |
} |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
76 |
} |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
77 |
return 0; |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
78 |
} |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
79 |
|
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2766
diff
changeset
|
80 |
#define __Unpack_desc_type hmi_tree_item_t |
2766
3f3b1b8ccba4
SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents:
2765
diff
changeset
|
81 |
|
2767
302347f48193
svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents:
2766
diff
changeset
|
82 |
%(var_access_code)s |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
83 |
|
2789 | 84 |
static int write_iterator(uint32_t index, hmi_tree_item_t *dsc) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
85 |
{ |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
86 |
uint32_t session_index = 0; |
3273
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
87 |
int value_changed = 0; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
88 |
if(AtomicCompareExchange(&dsc->wlock, 0, 1) == 0) { |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
89 |
void *dest_p = &wbuf[dsc->buf_index]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
90 |
void *real_value_p = NULL; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
91 |
char flags = 0; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
92 |
void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
93 |
USINT sz = __get_type_enum_size(dsc->type); |
2826
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
94 |
if(__Is_a_string(dsc)){ |
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
95 |
sz = ((STRING*)visible_value_p)->len + 1; |
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
96 |
} |
3273
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
97 |
while(session_index < MAX_CONNECTIONS) { |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
98 |
if(dsc->wstate[session_index] == buf_set){ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
99 |
/* if being subscribed */ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
100 |
if(dsc->refresh_period_ms[session_index]){ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
101 |
if(dsc->age_ms[session_index] + ticktime_ms < dsc->refresh_period_ms[session_index]){ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
102 |
dsc->age_ms[session_index] += ticktime_ms; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
103 |
}else{ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
104 |
dsc->wstate[session_index] = buf_tosend; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
105 |
global_write_dirty = 1; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
106 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
107 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
108 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
109 |
|
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
110 |
if(dsc->wstate[session_index] == buf_new /* just subscribed |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
111 |
or already subscribed having value change */ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
112 |
|| (dsc->refresh_period_ms[session_index] > 0 |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
113 |
&& (value_changed || (value_changed=memcmp(dest_p, visible_value_p, sz))) != 0)){ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
114 |
/* if not already marked/signaled, do it */ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
115 |
if(dsc->wstate[session_index] != buf_set && dsc->wstate[session_index] != buf_tosend) { |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
116 |
if(dsc->wstate[session_index] == buf_new || ticktime_ms > dsc->refresh_period_ms[session_index]){ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
117 |
dsc->wstate[session_index] = buf_tosend; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
118 |
global_write_dirty = 1; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
119 |
} else { |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
120 |
dsc->wstate[session_index] = buf_set; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
121 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
122 |
dsc->age_ms[session_index] = 0; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
123 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
124 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
125 |
|
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
126 |
session_index++; |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
127 |
} |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
128 |
/* copy value if changed (and subscribed) */ |
08a5a019bed2
SVGHMI: finished multiclient support. Still needs more testing.
Edouard Tisserant
parents:
3271
diff
changeset
|
129 |
if(value_changed) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
130 |
memcpy(dest_p, visible_value_p, sz); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
131 |
AtomicCompareExchange(&dsc->wlock, 1, 0); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
132 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
133 |
// else ... : PLC can't wait, variable will be updated next turn |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
134 |
return 0; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
135 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
136 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
137 |
static uint32_t send_session_index; |
2789 | 138 |
static int send_iterator(uint32_t index, hmi_tree_item_t *dsc) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
139 |
{ |
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
140 |
while(AtomicCompareExchange(&dsc->wlock, 0, 1)) |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
141 |
nRT_reschedule(); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
142 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
143 |
if(dsc->wstate[send_session_index] == buf_tosend) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
144 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
145 |
uint32_t sz = __get_type_enum_size(dsc->type); |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
146 |
if(sbufidx + sizeof(uint32_t) + sz <= sizeof(sbuf)) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
147 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
148 |
void *src_p = &wbuf[dsc->buf_index]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
149 |
void *dst_p = &sbuf[sbufidx]; |
2826
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
150 |
if(__Is_a_string(dsc)){ |
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
151 |
sz = ((STRING*)src_p)->len + 1; |
1e5abecc3cde
SVGHMI : support for HMI_STRING and HMI_BOOL
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2822
diff
changeset
|
152 |
} |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
153 |
/* TODO : force into little endian */ |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
154 |
memcpy(dst_p, &index, sizeof(uint32_t)); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
155 |
memcpy(dst_p + sizeof(uint32_t), src_p, sz); |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
156 |
dsc->wstate[send_session_index] = buf_free; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
157 |
sbufidx += sizeof(uint32_t) /* index */ + sz; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
158 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
159 |
else |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
160 |
{ |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
161 |
printf("BUG!!! %%d + %%ld + %%d > %%ld \n", sbufidx, sizeof(uint32_t), sz, sizeof(sbuf)); |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
162 |
AtomicCompareExchange(&dsc->wlock, 1, 0); |
2862 | 163 |
return EOVERFLOW; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
164 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
165 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
166 |
|
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
167 |
AtomicCompareExchange(&dsc->wlock, 1, 0); |
2862 | 168 |
return 0; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
169 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
170 |
|
2789 | 171 |
static int read_iterator(uint32_t index, hmi_tree_item_t *dsc) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
172 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
173 |
if(AtomicCompareExchange(&dsc->rlock, 0, 1) == 0) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
174 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
175 |
if(dsc->rstate == buf_set) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
176 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
177 |
void *src_p = &rbuf[dsc->buf_index]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
178 |
void *real_value_p = NULL; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
179 |
char flags = 0; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
180 |
void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
181 |
memcpy(real_value_p, src_p, __get_type_enum_size(dsc->type)); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
182 |
dsc->rstate = buf_free; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
183 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
184 |
AtomicCompareExchange(&dsc->rlock, 1, 0); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
185 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
186 |
// else ... : PLC can't wait, variable will be updated next turn |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
187 |
return 0; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
188 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
189 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
190 |
void update_refresh_period(hmi_tree_item_t *dsc, uint32_t session_index, uint16_t refresh_period_ms) |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
191 |
{ |
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
192 |
while(AtomicCompareExchange(&dsc->wlock, 0, 1)) |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
193 |
nRT_reschedule(); |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
194 |
|
2805
e521e0d133d5
SVGHMI: fixed HMI->PLC dataflow : not updates as expected, and not initialized properly after subscribe.
Edouard Tisserant
parents:
2802
diff
changeset
|
195 |
if(refresh_period_ms) { |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
196 |
if(!dsc->refresh_period_ms[session_index]) |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
197 |
{ |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
198 |
dsc->wstate[session_index] = buf_new; |
2863
e120d6985a2f
SVGHMI: fix wrong updates of HMI variables on each change, especially when not subscribed.
Edouard Tisserant
parents:
2862
diff
changeset
|
199 |
} |
2805
e521e0d133d5
SVGHMI: fixed HMI->PLC dataflow : not updates as expected, and not initialized properly after subscribe.
Edouard Tisserant
parents:
2802
diff
changeset
|
200 |
} else { |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
201 |
dsc->wstate[session_index] = buf_free; |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
202 |
} |
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
203 |
dsc->refresh_period_ms[session_index] = refresh_period_ms; |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
204 |
AtomicCompareExchange(&dsc->wlock, 1, 0); |
2766
3f3b1b8ccba4
SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents:
2765
diff
changeset
|
205 |
} |
3f3b1b8ccba4
SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents:
2765
diff
changeset
|
206 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
207 |
static uint32_t reset_session_index; |
2789 | 208 |
static int reset_iterator(uint32_t index, hmi_tree_item_t *dsc) |
209 |
{ |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
210 |
update_refresh_period(dsc, reset_session_index, 0); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
211 |
return 0; |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
212 |
} |
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
213 |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
214 |
static void *svghmi_handle; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
215 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
216 |
void SVGHMI_SuspendFromPythonThread(void) |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
217 |
{ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
218 |
wait_RT_to_nRT_signal(svghmi_handle); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
219 |
} |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
220 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
221 |
void SVGHMI_WakeupFromRTThread(void) |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
222 |
{ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
223 |
unblock_RT_to_nRT_signal(svghmi_handle); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
224 |
} |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
225 |
|
3281
1fc4274de64e
SVGHMI: Fixed halting problem when there is no session opened.
Edouard Tisserant
parents:
3273
diff
changeset
|
226 |
int svghmi_continue_collect; |
2776
246ae685ab65
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2775
diff
changeset
|
227 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
228 |
int __init_svghmi() |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
229 |
{ |
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
230 |
memset(rbuf,0,sizeof(rbuf)); |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
231 |
memset(wbuf,0,sizeof(wbuf)); |
2819
3b99c908f43b
SVGHMI: change collect/send thread looping condition to fix infinite loop in some cases
Edouard Tisserant
parents:
2817
diff
changeset
|
232 |
|
3281
1fc4274de64e
SVGHMI: Fixed halting problem when there is no session opened.
Edouard Tisserant
parents:
3273
diff
changeset
|
233 |
svghmi_continue_collect = 1; |
2765
887aba5ef178
SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents:
2764
diff
changeset
|
234 |
|
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
235 |
/* create svghmi_pipe */ |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
236 |
svghmi_handle = create_RT_to_nRT_signal("SVGHMI_pipe"); |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
237 |
|
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
238 |
if(!svghmi_handle) |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
239 |
return 1; |
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
240 |
|
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
241 |
return 0; |
2750 | 242 |
} |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
243 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
244 |
void __cleanup_svghmi() |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
245 |
{ |
3281
1fc4274de64e
SVGHMI: Fixed halting problem when there is no session opened.
Edouard Tisserant
parents:
3273
diff
changeset
|
246 |
svghmi_continue_collect = 0; |
2820
d9b5303d43dc
SVGHMI : had to move the problem of wkaing up python thread from plc thread to platform specific code.
Edouard Tisserant
parents:
2819
diff
changeset
|
247 |
SVGHMI_WakeupFromRTThread(); |
3294
e3db472b0dfb
Runtime+SVGHMI: Added a generic way to wakeup non-real-time threads from real-time PLC thread. Replace SVGHMI specific calls in Linux and Xenomai implementations of plc_main.c. Fixed xenomai build, xeno-config making problems with --no-auto-init argument.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3281
diff
changeset
|
248 |
delete_RT_to_nRT_signal(svghmi_handle); |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
249 |
} |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
250 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
251 |
void __retrieve_svghmi() |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
252 |
{ |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
253 |
traverse_hmi_tree(read_iterator); |
2764
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
254 |
} |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
255 |
|
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
256 |
void __publish_svghmi() |
b75cc2cf4e50
SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents:
2754
diff
changeset
|
257 |
{ |
2768
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
258 |
global_write_dirty = 0; |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
259 |
traverse_hmi_tree(write_iterator); |
31785529a657
SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents:
2767
diff
changeset
|
260 |
if(global_write_dirty) { |
2820
d9b5303d43dc
SVGHMI : had to move the problem of wkaing up python thread from plc thread to platform specific code.
Edouard Tisserant
parents:
2819
diff
changeset
|
261 |
SVGHMI_WakeupFromRTThread(); |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
262 |
} |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
263 |
} |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
264 |
|
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
265 |
/* PYTHON CALLS */ |
3271
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
266 |
int svghmi_wait(void){ |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
267 |
|
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
268 |
SVGHMI_SuspendFromPythonThread(); |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
269 |
} |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
270 |
|
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
271 |
int svghmi_send_collect(uint32_t session_index, uint32_t *size, char **ptr){ |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
272 |
|
3281
1fc4274de64e
SVGHMI: Fixed halting problem when there is no session opened.
Edouard Tisserant
parents:
3273
diff
changeset
|
273 |
if(svghmi_continue_collect) { |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
274 |
int res; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
275 |
sbufidx = HMI_HASH_SIZE; |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
276 |
send_session_index = session_index; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
277 |
if((res = traverse_hmi_tree(send_iterator)) == 0) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
278 |
{ |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
279 |
if(sbufidx > HMI_HASH_SIZE){ |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
280 |
memcpy(&sbuf[0], &hmi_hash[0], HMI_HASH_SIZE); |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
281 |
*ptr = &sbuf[0]; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
282 |
*size = sbufidx; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
283 |
return 0; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
284 |
} |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
285 |
return ENODATA; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
286 |
} |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
287 |
// printf("collected BAD result %%d\n", res); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
288 |
return res; |
2775
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
289 |
} |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
290 |
else |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
291 |
{ |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
292 |
return EINTR; |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
293 |
} |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
294 |
} |
3b93409ba22c
SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents:
2771
diff
changeset
|
295 |
|
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
296 |
typedef enum { |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
297 |
setval = 0, |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
298 |
reset = 1, |
2798
ddb2c4668a6b
SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents:
2789
diff
changeset
|
299 |
subscribe = 2 |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
300 |
} cmd_from_JS; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
301 |
|
3271
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
302 |
int svghmi_reset(uint32_t session_index){ |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
303 |
reset_session_index = session_index; |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
304 |
traverse_hmi_tree(reset_iterator); |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
305 |
return 1; |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
306 |
} |
561dbd1e3e04
SVGHMI: Fixing last commit's multiclient implementation, in case of watchdog. To be continued, since multiclient still fail...
Edouard Tisserant
parents:
3270
diff
changeset
|
307 |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
308 |
// Returns : |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
309 |
// 0 is OK, <0 is error, 1 is heartbeat |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
310 |
int svghmi_recv_dispatch(uint32_t session_index, uint32_t size, const uint8_t *ptr){ |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
311 |
const uint8_t* cursor = ptr + HMI_HASH_SIZE; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
312 |
const uint8_t* end = ptr + size; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
313 |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
314 |
int was_hearbeat = 0; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
315 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
316 |
/* match hmitree fingerprint */ |
2789 | 317 |
if(size <= HMI_HASH_SIZE || memcmp(ptr, hmi_hash, HMI_HASH_SIZE) != 0) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
318 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
319 |
printf("svghmi_recv_dispatch MISMATCH !!\n"); |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
320 |
return -EINVAL; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
321 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
322 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
323 |
while(cursor < end) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
324 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
325 |
uint32_t progress; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
326 |
cmd_from_JS cmd = *(cursor++); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
327 |
switch(cmd) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
328 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
329 |
case setval: |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
330 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
331 |
uint32_t index = *(uint32_t*)(cursor); |
2789 | 332 |
uint8_t const *valptr = cursor + sizeof(uint32_t); |
2862 | 333 |
|
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
334 |
if(index == heartbeat_index) |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
335 |
was_hearbeat = 1; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
336 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
337 |
if(index < HMI_ITEM_COUNT) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
338 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
339 |
hmi_tree_item_t *dsc = &hmi_tree_item[index]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
340 |
void *real_value_p = NULL; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
341 |
char flags = 0; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
342 |
void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
343 |
void *dst_p = &rbuf[dsc->buf_index]; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
344 |
uint32_t sz = __get_type_enum_size(dsc->type); |
2829
4c2c50f60730
SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents:
2828
diff
changeset
|
345 |
|
4c2c50f60730
SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents:
2828
diff
changeset
|
346 |
if(__Is_a_string(dsc)){ |
4c2c50f60730
SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents:
2828
diff
changeset
|
347 |
sz = ((STRING*)valptr)->len + 1; |
4c2c50f60730
SVGHMI : HMI_STRING now also supported from HMI to PLC
Edouard Tisserant
parents:
2828
diff
changeset
|
348 |
} |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
349 |
|
2802
64e6f73b9859
SVGHMI - Fixed svghmi.{c,js} about HMI -> PLC data unpack.
Edouard Tisserant
parents:
2799
diff
changeset
|
350 |
if((valptr + sz) <= end) |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
351 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
352 |
// rescheduling spinlock until free |
3295
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
353 |
while(AtomicCompareExchange(&dsc->rlock, 0, 1)) |
0375d801fff7
Runtime+SVGHMI: Add generic wakeup of threads from PLC thread to windows implementation of plc_main.c. Also added nRT_reschedule to abstract sched_yield.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3294
diff
changeset
|
354 |
nRT_reschedule(); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
355 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
356 |
memcpy(dst_p, valptr, sz); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
357 |
dsc->rstate = buf_set; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
358 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
359 |
AtomicCompareExchange(&dsc->rlock, 1, 0); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
360 |
progress = sz + sizeof(uint32_t) /* index */; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
361 |
} |
2862 | 362 |
else |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
363 |
{ |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
364 |
return -EINVAL; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
365 |
} |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
366 |
} |
2862 | 367 |
else |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
368 |
{ |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
369 |
return -EINVAL; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
370 |
} |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
371 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
372 |
break; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
373 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
374 |
case reset: |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
375 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
376 |
progress = 0; |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
377 |
reset_session_index = session_index; |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
378 |
traverse_hmi_tree(reset_iterator); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
379 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
380 |
break; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
381 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
382 |
case subscribe: |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
383 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
384 |
uint32_t index = *(uint32_t*)(cursor); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
385 |
uint16_t refresh_period_ms = *(uint32_t*)(cursor + sizeof(uint32_t)); |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
386 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
387 |
if(index < HMI_ITEM_COUNT) |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
388 |
{ |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
389 |
hmi_tree_item_t *dsc = &hmi_tree_item[index]; |
3270
38f7122ccbf9
SVGHMI: Implemented multiserver+multiclient, but only tested with single client and single server for now. To be continued...
Edouard Tisserant
parents:
2863
diff
changeset
|
390 |
update_refresh_period(dsc, session_index, refresh_period_ms); |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
391 |
} |
2862 | 392 |
else |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
393 |
{ |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
394 |
return -EINVAL; |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
395 |
} |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
396 |
|
2862 | 397 |
progress = sizeof(uint32_t) /* index */ + |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
398 |
sizeof(uint16_t) /* refresh period */; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
399 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
400 |
break; |
2799
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
401 |
default: |
f5da343b9b63
SVGHMI: Many fixes. Subscriptions to HMItree seems to be working, and dispatch function is called in JS with good data. Bidirectional communication now really working.
Edouard Tisserant
parents:
2798
diff
changeset
|
402 |
printf("svghmi_recv_dispatch unknown %%d\n",cmd); |
2788
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
403 |
|
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
404 |
} |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
405 |
cursor += progress; |
2ed9ff826d03
SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents:
2779
diff
changeset
|
406 |
} |
2822
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
407 |
return was_hearbeat; |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
408 |
} |
9101a72a1da0
SVGHMI: added a watchdog. To ensure that the whole chain is checked, watchdog use a periodic echo of a hearteat variable. JS client code systematically register /HEARTBEAT at 1s update freq, and reacts on updates of /HEARTBEAT by systematically incrementing it. C code catch /HEARTBEAT update and feeds python-implemented watchdog. For now, watchdog does nothing when tiggered
Edouard Tisserant
parents:
2820
diff
changeset
|
409 |