modbus/mb_runtime.h
changeset 2654 7575050a80c5
parent 2647 990004083eb8
child 2655 d2b2ee04bfa1
equal deleted inserted replaced
2649:db68cb0e6bdc 2654:7575050a80c5
    27 #include "mb_master_private.h"
    27 #include "mb_master_private.h"
    28 
    28 
    29 
    29 
    30 
    30 
    31 #define DEF_REQ_SEND_RETRIES 0
    31 #define DEF_REQ_SEND_RETRIES 0
       
    32 
       
    33 
       
    34 #define MODBUS_PARAM_STRING_SIZE 64
       
    35 
    32 
    36 
    33   // Used by the Modbus server node
    37   // Used by the Modbus server node
    34 #define MEM_AREA_SIZE 65536
    38 #define MEM_AREA_SIZE 65536
    35 typedef struct{
    39 typedef struct{
    36 	    u16		ro_bits [MEM_AREA_SIZE];
    40 	    u16		ro_bits [MEM_AREA_SIZE];
    37 	    u16		rw_bits [MEM_AREA_SIZE];
    41 	    u16		rw_bits [MEM_AREA_SIZE];
    38 	    u16		ro_words[MEM_AREA_SIZE];
    42 	    u16		ro_words[MEM_AREA_SIZE];
    39 	    u16		rw_words[MEM_AREA_SIZE];
    43 	    u16		rw_words[MEM_AREA_SIZE];
    40 	} server_mem_t;
    44 	} server_mem_t;
    41 
    45 
       
    46 
       
    47 /*
       
    48  * Beremiz has a program to run on the PLC (Beremiz_service.py)
       
    49  * to handle downloading of compiled programs, start/stop of PLC, etc.
       
    50  * (see runtime/PLCObject.py for start/stop, loading, ...)
       
    51  * 
       
    52  * This service also includes a web server to access PLC state (start/stop)
       
    53  * and to change some basic confiuration parameters.
       
    54  * (see runtime/NevowServer.py for the web server)
       
    55  * 
       
    56  * The web server allows for extensions, where additional configuration
       
    57  * parameters may be changed on the running/downloaded PLC.
       
    58  * Modbus plugin also comes with an extension to the web server, through
       
    59  * which the basic Modbus plugin configuration parameters may be changed
       
    60  *
       
    61  * This means that most values in the server_node_t and client_node_t
       
    62  * may be changed after the co,piled code (.so file) is loaded into 
       
    63  * memory, and before the code starts executing.
       
    64  * Since the we will also want to change the host and port (TCP) and the
       
    65  * serial device (RTU) at this time, it is best if we allocate memory for
       
    66  * these strings that may be overwritten by the web server (i.e., do not use
       
    67  * const strings) in the server_node_t and client_node_t structures.
       
    68  *
       
    69  * The following structure members
       
    70  *    - node_addr_t.addr.tcp.host
       
    71  *    - node_addr_t.addr.tcp.service  (i.e. the port)
       
    72  *    - node_addr_t.addr.rtu.device
       
    73  * are all char *, and do not allocate memory for the strings.
       
    74  * 
       
    75  * We therefore include two generic char arrays, str1 and str2,
       
    76  * that will store the above strings, and the C code will initiliaze
       
    77  * the node_addre_t.addr string pointers to these strings.
       
    78  * i.e., either addr.rtu.device will point to str1,
       
    79  *          or
       
    80  *        addr.tcp.host and addr.tcp.service 
       
    81  *        will point to str1 and str2 respectively
       
    82  */
    42 typedef struct{
    83 typedef struct{
    43 	    const char *location;
    84 	    const char *location;
       
    85         const char *config_name;
    44 	    u8		slave_id;
    86 	    u8		slave_id;
    45 	    node_addr_t	node_address;
    87 	    node_addr_t	node_address;
    46 	    int		mb_nd;      // modbus library node used for this server 
    88 	    int		mb_nd;      // modbus library node used for this server 
    47 	    int		init_state; // store how far along the server's initialization has progressed
    89 	    int		init_state; // store how far along the server's initialization has progressed
    48 	    pthread_t	thread_id;  // thread handling this server
    90 	    pthread_t	thread_id;  // thread handling this server
    51 
    93 
    52 
    94 
    53   // Used by the Modbus client node
    95   // Used by the Modbus client node
    54 typedef struct{
    96 typedef struct{
    55 	    const char *location;
    97 	    const char *location;
       
    98         const char *config_name;
       
    99               char  str1[MODBUS_PARAM_STRING_SIZE];
       
   100               char  str2[MODBUS_PARAM_STRING_SIZE]; 
    56 	    node_addr_t	node_address;
   101 	    node_addr_t	node_address;
    57 	    int		mb_nd;      // modbus library node used for this client
   102 	    int		mb_nd;      // modbus library node used for this client
    58 	    int		init_state; // store how far along the client's initialization has progressed
   103 	    int		init_state; // store how far along the client's initialization has progressed
    59 	    u64		comm_period;// period to use when periodically sending requests to remote server
   104 	    u64		comm_period;// period to use when periodically sending requests to remote server
    60 	    int		prev_error; // error code of the last printed error message (0 when no error) 
   105 	    int		prev_error; // error code of the last printed error message (0 when no error)