modbus/mb_runtime.h
author Edouard Tisserant <edouard.tisserant@gmail.com>
Thu, 10 Nov 2022 19:36:30 +0100
branchwxPython4
changeset 3669 ca25c686cd97
parent 2723 cde2e410b874
child 3733 d1acf20e8e7c
permissions -rw-r--r--
Tests: UI tests can now load projects from tests/projects
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     1
/* File generated by Beremiz (PlugGenerate_C method of modbus Plugin instance) */
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     2
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     3
/*
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     4
 * Copyright (c) 2016 Mario de Sousa (msousa@fe.up.pt)
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     5
 *
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     6
 * This file is part of the Modbus library for Beremiz and matiec.
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     7
 *
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     8
 * This Modbus library is free software: you can redistribute it and/or modify
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
     9
 * it under the terms of the GNU Lesser General Public License as published by
2019
92f02bb17c7e Make Modbus extension license compatible with the rest of Beremiz IDE python code : GPLv2.
Edouard Tisserant
parents: 1912
diff changeset
    10
 * the Free Software Foundation, either version 2 of the License, or
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    11
 * (at your option) any later version.
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    12
 *
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    13
 * This program is distributed in the hope that it will be useful, but
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    16
 * General Public License for more details.
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    17
 *
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    18
 * You should have received a copy of the GNU Lesser General Public License
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    19
 * along with this Modbus library.  If not, see <http://www.gnu.org/licenses/>.
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    20
 *
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    21
 * This code is made available on the understanding that it will not be
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    23
 */
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    24
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    25
#include "mb_addr.h"
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    26
#include "mb_tcp_private.h"
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    27
#include "mb_master_private.h"
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    28
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    29
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    30
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    31
#define DEF_REQ_SEND_RETRIES 0
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    32
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    33
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    34
#define MODBUS_PARAM_STRING_SIZE 64
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    35
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    36
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    37
  // Used by the Modbus server node
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    38
#define MEM_AREA_SIZE 65536
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    39
typedef struct{
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    40
	    u16		ro_bits [MEM_AREA_SIZE];
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    41
	    u16		rw_bits [MEM_AREA_SIZE];
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    42
	    u16		ro_words[MEM_AREA_SIZE];
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    43
	    u16		rw_words[MEM_AREA_SIZE];
2721
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
    44
            /* Two flags to count the number of Modbus requests (read and write) we have 
2722
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    45
             * successfully received from any remote Modbus master.
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    46
             * Two boolean flags that are set whenever we successfully process a
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    47
             * Modbus request sent from a remote client.
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    48
             * These flags will be mapped onto located variables
2721
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
    49
             * so the user's IEC 61131-3 code can check whether we are being
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
    50
             * polled by a Modbus master.
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
    51
             * The counters will roll over to 0 upon reaching maximum value.
2722
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    52
             * The user will probably periodically reset the boolean flags to false,
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    53
             * and use this as a communication timeout 
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    54
             * (when it remains false in two consecutive periods)
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    55
             * 
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    56
             * u8  for BOOL  variable/flag
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    57
             * u32 for UDINT variable/counter
2721
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
    58
             */
2722
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    59
        u8   flag_write_req_flag;
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    60
        u8   flag_read_req_flag;
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    61
        u32  flag_write_req_counter;
5d72a52b8f9c modbus plugin: add (user accessible) transaction bool flags for servers/slaves; FIX BUG in previous commit affecting RTU slaves.
Mario de Sousa <msousa@fe.up.pt>
parents: 2721
diff changeset
    62
        u32  flag_read_req_counter;
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    63
	} server_mem_t;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
    64
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    65
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    66
/*
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    67
 * Beremiz has a program to run on the PLC (Beremiz_service.py)
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    68
 * to handle downloading of compiled programs, start/stop of PLC, etc.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    69
 * (see runtime/PLCObject.py for start/stop, loading, ...)
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    70
 * 
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    71
 * This service also includes a web server to access PLC state (start/stop)
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    72
 * and to change some basic confiuration parameters.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    73
 * (see runtime/NevowServer.py for the web server)
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    74
 * 
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    75
 * The web server allows for extensions, where additional configuration
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    76
 * parameters may be changed on the running/downloaded PLC.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    77
 * Modbus plugin also comes with an extension to the web server, through
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    78
 * which the basic Modbus plugin configuration parameters may be changed
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    79
 *
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    80
 * This means that most values in the server_node_t and client_node_t
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    81
 * may be changed after the co,piled code (.so file) is loaded into 
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    82
 * memory, and before the code starts executing.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    83
 * Since the we will also want to change the host and port (TCP) and the
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    84
 * serial device (RTU) at this time, it is best if we allocate memory for
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    85
 * these strings that may be overwritten by the web server (i.e., do not use
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    86
 * const strings) in the server_node_t and client_node_t structures.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    87
 *
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    88
 * The following structure members
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    89
 *    - node_addr_t.addr.tcp.host
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    90
 *    - node_addr_t.addr.tcp.service  (i.e. the port)
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    91
 *    - node_addr_t.addr.rtu.device
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    92
 * are all char *, and do not allocate memory for the strings.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    93
 * 
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    94
 * We therefore include two generic char arrays, str1 and str2,
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    95
 * that will store the above strings, and the C code will initiliaze
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    96
 * the node_addre_t.addr string pointers to these strings.
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    97
 * i.e., either addr.rtu.device will point to str1,
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    98
 *          or
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
    99
 *        addr.tcp.host and addr.tcp.service 
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   100
 *        will point to str1 and str2 respectively
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   101
 */
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   102
typedef struct{
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   103
	    const char *location;
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   104
        const char *config_name;
2655
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   105
              char  str1[MODBUS_PARAM_STRING_SIZE];
d2b2ee04bfa1 Add web extension: configure Modbus Server plugin parameters
Mario de Sousa <msousa@fe.up.pt>
parents: 2654
diff changeset
   106
              char  str2[MODBUS_PARAM_STRING_SIZE]; 
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   107
	    u8		slave_id;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   108
	    node_addr_t	node_address;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   109
	    int		mb_nd;      // modbus library node used for this server 
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   110
	    int		init_state; // store how far along the server's initialization has progressed
2721
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
   111
            /* entries from this point forward are not statically initialized when the variable is declared */
367eb26972b1 modbus plugin: add (user accessible) transaction counters for servers/slaves
Mario de Sousa <msousa@fe.up.pt>
parents: 2715
diff changeset
   112
            /* they will be initialized by the  code itself in the init() function */
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   113
	    pthread_t	thread_id;  // thread handling this server
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   114
	    server_mem_t	mem_area;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   115
	} server_node_t;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   116
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   117
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   118
  // Used by the Modbus client node
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   119
typedef struct{
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   120
	    const char *location;
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   121
        const char *config_name;
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   122
              char  str1[MODBUS_PARAM_STRING_SIZE];
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2647
diff changeset
   123
              char  str2[MODBUS_PARAM_STRING_SIZE]; 
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   124
	    node_addr_t	node_address;
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   125
	    int		mb_nd;      // modbus library node used for this client
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   126
	    int		init_state; // store how far along the client's initialization has progressed
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   127
	    u64		comm_period;// period to use when periodically sending requests to remote server
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   128
	    int		prev_error; // error code of the last printed error message (0 when no error) 
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   129
	    pthread_t   thread_id;  // thread handling all communication for this client node
2683
5d8a4deacfe1 Modbus add a timer thread, and switch timer to SIGEV_THREAD_ID to follow xenomai posix skin restrictions.
Edouard Tisserant
parents: 2655
diff changeset
   130
	    pthread_t	timer_thread_id;  // thread handling periodical timer for this client node
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   131
	    pthread_mutex_t mutex;  // mutex to be used with the following condition variable
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   132
        pthread_cond_t  condv;  // used to signal the client thread when to start new modbus transactions
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   133
        int       execute_req;  /* used, in association with condition variable,  
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   134
                                 *   to signal when to send the modbus request to the server
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   135
                                 * Note that we cannot simply rely on the condition variable to signal
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   136
                                 *   when to activate the client thread, as the call to 
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   137
                                 *   pthread_cond_wait() may return without having been signaled!
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   138
                                 *   From the manual:
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   139
                                 *      Spurious  wakeups  from  the
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   140
                                 *      pthread_cond_timedwait() or pthread_cond_wait()  functions  may  occur.
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   141
                                 *      Since  the  return from pthread_cond_timedwait() or pthread_cond_wait()
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   142
                                 *      does not imply anything about the value of this predicate,  the  predi-
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   143
                                 *      cate should be re-evaluated upon such return.
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   144
                                 */
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   145
        int      periodic_act;  /* (boolen) flag will be set when the client node's thread was activated 
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   146
                                 * (by signaling the above condition variable) by the periodic timer.
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   147
                                 * Note that this same thread may also be activated (condition variable is signaled)
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   148
                                 * by other sources, such as when the user program requests that a specific 
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   149
                                 * client MB transation be executed (flag_exec_req in client_request_t)
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   150
                                 */
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   151
	} client_node_t;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   152
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   153
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   154
  // Used by the Modbus client plugin
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   155
typedef enum {
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   156
	    req_input,
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   157
	    req_output,
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   158
	    no_request		/* just for tests to quickly disable a request */
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   159
	} iotype_t;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   160
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   161
#define REQ_BUF_SIZE 2000
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   162
typedef struct{
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   163
	    const char *location;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   164
	    int		client_node_id;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   165
	    u8		slave_id;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   166
	    iotype_t	req_type;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   167
	    u8		mb_function;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   168
	    u16		address;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   169
	    u16		count;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   170
	    int		retries;
2713
680ea4684209 Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents: 2655
diff changeset
   171
	    u8		mb_error_code; // modbus      error code (if any) of last executed request
680ea4684209 Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents: 2655
diff changeset
   172
	    u8		tn_error_code; // transaction error code (if any) of last executed request
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   173
	    int		prev_error; // error code of the last printed error message (0 when no error) 
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   174
	    struct timespec resp_timeout;
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   175
	    u8		write_on_change; // boolean flag. If true => execute MB request when data to send changes
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   176
	      // buffer used to store located PLC variables
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   177
	    u16		plcv_buffer[REQ_BUF_SIZE];
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   178
	      // buffer used to store data coming from / going to server
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   179
	    u16		coms_buffer[REQ_BUF_SIZE]; 
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   180
	    pthread_mutex_t coms_buf_mutex; // mutex to access coms_buffer[]
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   181
          /* boolean flag that will be mapped onto a (BOOL) located variable 
2715
1215a6b741d5 Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents: 2714
diff changeset
   182
           * (u8 because IEC 61131-3 BOOL are mapped onto u8 in C code! )
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   183
           *    -> allow PLC program to request when to start the MB transaction
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   184
           *    -> will be reset once the MB transaction has completed
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   185
           */
2715
1215a6b741d5 Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents: 2714
diff changeset
   186
        u8     flag_exec_req;  
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   187
          /* flag that works in conjunction with flag_exec_req
2715
1215a6b741d5 Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents: 2714
diff changeset
   188
           * (does not really need to be u8 as it is not mapped onto a located variable. )
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   189
           *    -> used by internal logic to indicate that the client thread 
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   190
           *       that will be executing the MB transaction
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   191
           *       requested by flag exec_req has already been activated.
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   192
           *    -> will be reset once the MB transaction has completed
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   193
           */
2715
1215a6b741d5 Modbus plugin: fix bug - map BOOL flag onto C u8 (was incorrectly mapped onto u16)
Mario de Sousa <msousa@fe.up.pt>
parents: 2714
diff changeset
   194
        u8     flag_exec_started;  
2714
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   195
          /* flag that will be mapped onto a (BYTE) located variable 
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   196
           * (u8 because the flag is a BYTE! )
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   197
           *    -> will store the result of the last executed MB transaction
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   198
           *         1 -> error accessing IP network, or serial interface
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   199
           *         2 -> reply received from server was an invalid frame
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   200
           *         3 -> server did not reply before timeout expired
2713
680ea4684209 Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents: 2655
diff changeset
   201
           *         4 -> server returned a valid Modbus error frame
2647
990004083eb8 Modbus plugin: Add "exec. req. flag" and "write on change" features
Mario de Sousa <msousa@fe.up.pt>
parents: 2019
diff changeset
   202
           *    -> will be reset (set to 0) once this MB transaction has completed sucesfully
2713
680ea4684209 Modbus plugin: provide user programs feedback on current connection status mapped onto a WORD located variable
Mario de Sousa <msousa@fe.up.pt>
parents: 2655
diff changeset
   203
           * 
2714
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   204
           * In other words, this variable is a copy of tn_error_code, reset after each request attempt completes.
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   205
           * We map this copy (instead of tn_error_code) onto a located variable in case the user program decides
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   206
           * to overwrite its value and mess up the plugin logic.
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   207
           */
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   208
        u8      flag_tn_error_code;  
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   209
          /* flag that will be mapped onto a (BYTE) located variable 
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   210
           * (u8 because the flag is a BYTE! )
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   211
           *    -> if flag_tn_error_code is 4, this flag will store the MB error code returned by the MB server in a MB error frame
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   212
           *    -> will be reset (set to 0) once this MB transaction has completed succesfully
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   213
           * 
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   214
           * In other words, this variable is a copy of mb_error_code, reset after each request attempt completes.
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   215
           * We map this copy (instead of mb_error_code) onto a located variable in case the user program decides
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   216
           * to overwrite its value and mess up the plugin logic.
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   217
           */
0b636dc947a2 Modbus plugin: map status of MB transaction onto 2 located BYTE vars (instead of a singlw WORD var).
Mario de Sousa <msousa@fe.up.pt>
parents: 2713
diff changeset
   218
        u8      flag_mb_error_code;  
1912
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   219
	} client_request_t;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   220
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   221
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   222
/* The total number of nodes, needed to support _all_ instances of the modbus plugin */
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   223
#define TOTAL_TCPNODE_COUNT       %(total_tcpnode_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   224
#define TOTAL_RTUNODE_COUNT       %(total_rtunode_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   225
#define TOTAL_ASCNODE_COUNT       %(total_ascnode_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   226
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   227
/* Values for instance %(locstr)s of the modbus plugin */
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   228
#define MAX_NUMBER_OF_TCPCLIENTS  %(max_remote_tcpclient)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   229
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   230
#define NUMBER_OF_TCPSERVER_NODES %(tcpserver_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   231
#define NUMBER_OF_TCPCLIENT_NODES %(tcpclient_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   232
#define NUMBER_OF_TCPCLIENT_REQTS %(tcpclient_reqs_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   233
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   234
#define NUMBER_OF_RTUSERVER_NODES %(rtuserver_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   235
#define NUMBER_OF_RTUCLIENT_NODES %(rtuclient_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   236
#define NUMBER_OF_RTUCLIENT_REQTS %(rtuclient_reqs_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   237
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   238
#define NUMBER_OF_ASCIISERVER_NODES %(ascserver_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   239
#define NUMBER_OF_ASCIICLIENT_NODES %(ascclient_node_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   240
#define NUMBER_OF_ASCIICLIENT_REQTS %(ascclient_reqs_count)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   241
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   242
#define NUMBER_OF_SERVER_NODES (NUMBER_OF_TCPSERVER_NODES + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   243
                                NUMBER_OF_RTUSERVER_NODES + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   244
                                NUMBER_OF_ASCIISERVER_NODES)
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   245
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   246
#define NUMBER_OF_CLIENT_NODES (NUMBER_OF_TCPCLIENT_NODES + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   247
                                NUMBER_OF_RTUCLIENT_NODES + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   248
                                NUMBER_OF_ASCIICLIENT_NODES)
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   249
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   250
#define NUMBER_OF_CLIENT_REQTS (NUMBER_OF_TCPCLIENT_REQTS + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   251
                                NUMBER_OF_RTUCLIENT_REQTS + \
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   252
                                NUMBER_OF_ASCIICLIENT_REQTS)
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   253
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   254
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   255
/*initialization following all parameters given by user in application*/
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   256
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   257
static client_node_t		client_nodes[NUMBER_OF_CLIENT_NODES] = {
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   258
%(client_nodes_params)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   259
};
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   260
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   261
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   262
static client_request_t	client_requests[NUMBER_OF_CLIENT_REQTS] = {
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   263
%(client_req_params)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   264
};
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   265
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   266
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   267
static server_node_t		server_nodes[NUMBER_OF_SERVER_NODES] = {
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   268
%(server_nodes_params)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   269
}
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   270
;
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   271
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   272
/*******************/
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   273
/*located variables*/
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   274
/*******************/
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   275
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   276
%(loc_vars)s
8391c11477f4 Merged Mario's modbus branch. Fixed line endings.
Edouard Tisserant
parents: 1909
diff changeset
   277