svghmi/svghmi.c
author Edouard Tisserant
Wed, 11 Sep 2019 12:24:30 +0200
branchsvghmi
changeset 2771 361366b891ca
parent 2768 31785529a657
child 2775 3b93409ba22c
permissions -rw-r--r--
WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
     1
#include <pthread.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
     2
#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
     3
#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
     4
#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
     5
#include "beremiz.h"
2750
2694170cd88e intermediate commit, work in progress
Edouard Tisserant
parents:
diff changeset
     6
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
     7
#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
     8
#define HMI_BUFFER_SIZE %(buffer_size)d
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
     9
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    10
/* PLC reads from that buffer */
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    11
static char rbuf[HMI_BUFFER_SIZE];
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    12
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    13
/* PLC writes to that buffer */
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    14
static char wbuf[HMI_BUFFER_SIZE];
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    15
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    16
%(extern_variables_declarations)s
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    17
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
    18
#define ticktime_ns %(PLC_ticktime)d
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
    19
uint16_t ticktime_ms = (ticktime_ns>1000000)?
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    20
                     ticktime_ns/1000000:
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    21
                     1;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    22
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    23
typedef enum {
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    24
    buf_free = 0,
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    25
    buf_set,
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    26
    buf_tosend
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    27
} buf_state_t;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    28
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    29
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
    30
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
    31
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
    32
    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
    33
    __IEC_types_enum type;
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    34
    uint32_t buf_index;
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    35
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    36
    /* 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
    37
    long wlock;
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    38
    /* zero means not subscribed */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    39
    uint16_t refresh_period_ms;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    40
    uint16_t age_ms;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    41
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    42
    buf_state_t wstate;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    43
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    44
    /* 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
    45
    long rlock;
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    46
    buf_state_t rstate;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    47
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
    48
} 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
    49
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
    50
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
    51
%(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
    52
};
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
    53
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    54
typedef void(*hmi_tree_iterator)(hmi_tree_item_t*);
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    55
void traverse_hmi_tree(hmi_tree_iterator fp)
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    56
{
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    57
    unsigned int i;
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    58
    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
    59
        hmi_tree_item_t *dsc = &hmi_tree_item[i];
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    60
        if(dsc->type != UNKNOWN_ENUM) 
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    61
            (*fp)(dsc);
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    62
    }
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    63
}
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    64
2767
302347f48193 svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents: 2766
diff changeset
    65
#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
    66
2767
302347f48193 svghmi.c : deduplicated variable access code borrowed from plc_debug.c. Added targets/var_access.c.
Edouard Tisserant
parents: 2766
diff changeset
    67
%(var_access_code)s
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
    68
2766
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    69
void write_iterator(hmi_tree_item_t *dsc)
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    70
{
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    71
    void *dest_p = &wbuf[dsc->buf_index];
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    72
    void *real_value_p = NULL;
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    73
    char flags = 0;
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    74
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    75
    void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags);
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
    76
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    77
    /* Try take lock */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    78
    long was_locked = AtomicCompareExchange(&dsc->wlock, 0, 1);
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    79
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    80
    if(was_locked) {
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    81
        /* was locked. give up*/
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    82
        return;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    83
    }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    84
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
    85
    if(dsc->wstate == buf_set){
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    86
        /* if being subscribed */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    87
        if(dsc->refresh_period_ms){
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    88
            if(dsc->age_ms + ticktime_ms < dsc->refresh_period_ms){
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    89
                dsc->age_ms += ticktime_ms;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    90
            }else{
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    91
                dsc->wstate = buf_tosend;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    92
            }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    93
        }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    94
    }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    95
    
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    96
    /* if new value differs from previous one */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    97
    if(memcmp(dest_p, visible_value_p, __get_type_enum_size(dsc->type)) != 0){
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    98
        /* copy and flag as set */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
    99
        memcpy(dest_p, visible_value_p, __get_type_enum_size(dsc->type));
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   100
        if(dsc->wstate == buf_free) {
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   101
            dsc->wstate = buf_set;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   102
            dsc->age_ms = 0;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   103
        }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   104
        global_write_dirty = 1;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   105
    }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   106
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   107
    /* unlock - use AtomicComparExchange to have memory barrier */
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   108
    AtomicCompareExchange(&dsc->wlock, 1, 0);
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   109
}
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   110
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   111
struct timespec sending_now;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   112
struct timespec next_sending;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   113
void send_iterator(hmi_tree_item_t *dsc)
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   114
{
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   115
    while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield();
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   116
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   117
    // check for variable being modified
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
   118
    if(dsc->wstate == buf_tosend){
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   119
        // send 
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   120
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
   121
        // TODO call the python callback 
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   122
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   123
        dsc->wstate = buf_free; 
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   124
    }
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   125
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   126
    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
   127
}
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   128
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   129
void read_iterator(hmi_tree_item_t *dsc)
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   130
{
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   131
    void *src_p = &rbuf[dsc->buf_index];
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   132
    void *real_value_p = NULL;
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   133
    char flags = 0;
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   134
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   135
    void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags);
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   136
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   137
2766
3f3b1b8ccba4 SVGHMI: Added iterators in svghmi.c copy-pasted form plc_debug.c
Edouard Tisserant
parents: 2765
diff changeset
   138
    memcpy(visible_value_p, src_p, __get_type_enum_size(dsc->type));
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   139
}
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   140
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
   141
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
   142
{
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   143
    bzero(rbuf,sizeof(rbuf));
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   144
    bzero(wbuf,sizeof(wbuf));
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   145
    
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
   146
    // TODO - sending pthread condition variable
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   147
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
   148
    return 0;
2750
2694170cd88e intermediate commit, work in progress
Edouard Tisserant
parents:
diff changeset
   149
}
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
   150
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   151
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
   152
{
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   153
}
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   154
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   155
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
   156
{
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   157
    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
   158
}
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   159
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   160
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
   161
{
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   162
    global_write_dirty = 0;
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   163
    traverse_hmi_tree(write_iterator);
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   164
    if(global_write_dirty) {
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
   165
        // TODO : set condition variable to wakeup sending collector
2765
887aba5ef178 SVGHMI: svghmi.c now has mutex, iterator, and read/write buffer.
Edouard Tisserant
parents: 2764
diff changeset
   166
    }
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   167
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
   168
}
b75cc2cf4e50 SVGHMI: draft for svghmi.c. It has all PLC variables pointed in HMI tree in an array.
Edouard Tisserant
parents: 2754
diff changeset
   169
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
   170
void* collect_updates_to_send(void* args){
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
   171
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
   172
    // TODO : get callback from args
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
   173
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   174
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   175
    // TODO : wait for 
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
   176
    //        - condition variable
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
   177
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
   178
    // TODO add arg to traverse_hmi_tree to pass callback
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   179
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   180
    traverse_hmi_tree(send_iterator);
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
   181
2768
31785529a657 SVGHMI: Intermediate state while working on svghmi.c
Edouard Tisserant
parents: 2767
diff changeset
   182
}