msousa@1909: /* File generated by Beremiz (PlugGenerate_C method of modbus Plugin instance) */ msousa@1909: msousa@1909: /* msousa@1909: * Copyright (c) 2016 Mario de Sousa (msousa@fe.up.pt) msousa@1909: * msousa@1909: * This file is part of the Modbus library for Beremiz and matiec. msousa@1909: * msousa@1909: * This Modbus library is free software: you can redistribute it and/or modify msousa@1909: * it under the terms of the GNU Lesser General Public License as published by msousa@1909: * the Free Software Foundation, either version 3 of the License, or msousa@1909: * (at your option) any later version. msousa@1909: * msousa@1909: * This program is distributed in the hope that it will be useful, but msousa@1909: * WITHOUT ANY WARRANTY; without even the implied warranty of msousa@1909: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser msousa@1909: * General Public License for more details. msousa@1909: * msousa@1909: * You should have received a copy of the GNU Lesser General Public License msousa@1909: * along with this Modbus library. If not, see . msousa@1909: * msousa@1909: * This code is made available on the understanding that it will not be msousa@1909: * used in safety-critical situations without a full and competent review. msousa@1909: */ msousa@1909: msousa@1909: #include "mb_addr.h" msousa@1909: #include "mb_tcp_private.h" msousa@1909: #include "mb_master_private.h" msousa@1909: msousa@1909: msousa@1909: msousa@1909: #define DEF_REQ_SEND_RETRIES 0 msousa@1909: msousa@1909: // Used by the Modbus server node msousa@1909: #define MEM_AREA_SIZE 65536 msousa@1909: typedef struct{ msousa@1909: u16 ro_bits [MEM_AREA_SIZE]; msousa@1909: u16 rw_bits [MEM_AREA_SIZE]; msousa@1909: u16 ro_words[MEM_AREA_SIZE]; msousa@1909: u16 rw_words[MEM_AREA_SIZE]; msousa@1909: } server_mem_t; msousa@1909: msousa@1909: typedef struct{ msousa@1909: const char *location; msousa@1909: u8 slave_id; msousa@1909: node_addr_t node_address; msousa@1909: int mb_nd; // modbus library node used for this server msousa@1909: int init_state; // store how far along the server's initialization has progressed msousa@1909: pthread_t thread_id; // thread handling this server msousa@1909: server_mem_t mem_area; msousa@1909: } server_node_t; msousa@1909: msousa@1909: msousa@1909: // Used by the Modbus client node msousa@1909: typedef struct{ msousa@1909: const char *location; msousa@1909: node_addr_t node_address; msousa@1909: int mb_nd; msousa@1909: int init_state; // store how far along the client's initialization has progressed msousa@1909: u64 comm_period; msousa@1909: int prev_error; // error code of the last printed error message (0 when no error) msousa@1909: pthread_t thread_id; // thread handling all communication with this client msousa@1909: } client_node_t; msousa@1909: msousa@1909: msousa@1909: // Used by the Modbus client plugin msousa@1909: typedef enum { msousa@1909: req_input, msousa@1909: req_output, msousa@1909: no_request /* just for tests to quickly disable a request */ msousa@1909: } iotype_t; msousa@1909: msousa@1909: #define REQ_BUF_SIZE 2000 msousa@1909: typedef struct{ msousa@1909: const char *location; msousa@1909: int client_node_id; msousa@1909: u8 slave_id; msousa@1909: iotype_t req_type; msousa@1909: u8 mb_function; msousa@1909: u16 address; msousa@1909: u16 count; msousa@1909: int retries; msousa@1909: u8 error_code; // modbus error code (if any) of current request msousa@1909: int prev_error; // error code of the last printed error message (0 when no error) msousa@1909: struct timespec resp_timeout; msousa@1909: // buffer used to store located PLC variables msousa@1909: u16 plcv_buffer[REQ_BUF_SIZE]; msousa@1909: // buffer used to store data coming from / going to server msousa@1909: u16 coms_buffer[REQ_BUF_SIZE]; msousa@1909: pthread_mutex_t coms_buf_mutex; // mutex to access coms_buffer[] msousa@1909: } client_request_t; msousa@1909: msousa@1909: msousa@1909: /* The total number of nodes, needed to support _all_ instances of the modbus plugin */ msousa@1909: #define TOTAL_TCPNODE_COUNT %(total_tcpnode_count)s msousa@1909: #define TOTAL_RTUNODE_COUNT %(total_rtunode_count)s msousa@1909: #define TOTAL_ASCNODE_COUNT %(total_ascnode_count)s msousa@1909: msousa@1909: /* Values for instance %(locstr)s of the modbus plugin */ msousa@1909: #define MAX_NUMBER_OF_TCPCLIENTS %(max_remote_tcpclient)s msousa@1909: msousa@1909: #define NUMBER_OF_TCPSERVER_NODES %(tcpserver_node_count)s msousa@1909: #define NUMBER_OF_TCPCLIENT_NODES %(tcpclient_node_count)s msousa@1909: #define NUMBER_OF_TCPCLIENT_REQTS %(tcpclient_reqs_count)s msousa@1909: msousa@1909: #define NUMBER_OF_RTUSERVER_NODES %(rtuserver_node_count)s msousa@1909: #define NUMBER_OF_RTUCLIENT_NODES %(rtuclient_node_count)s msousa@1909: #define NUMBER_OF_RTUCLIENT_REQTS %(rtuclient_reqs_count)s msousa@1909: msousa@1909: #define NUMBER_OF_ASCIISERVER_NODES %(ascserver_node_count)s msousa@1909: #define NUMBER_OF_ASCIICLIENT_NODES %(ascclient_node_count)s msousa@1909: #define NUMBER_OF_ASCIICLIENT_REQTS %(ascclient_reqs_count)s msousa@1909: msousa@1909: #define NUMBER_OF_SERVER_NODES (NUMBER_OF_TCPSERVER_NODES + \ msousa@1909: NUMBER_OF_RTUSERVER_NODES + \ msousa@1909: NUMBER_OF_ASCIISERVER_NODES) msousa@1909: msousa@1909: #define NUMBER_OF_CLIENT_NODES (NUMBER_OF_TCPCLIENT_NODES + \ msousa@1909: NUMBER_OF_RTUCLIENT_NODES + \ msousa@1909: NUMBER_OF_ASCIICLIENT_NODES) msousa@1909: msousa@1909: #define NUMBER_OF_CLIENT_REQTS (NUMBER_OF_TCPCLIENT_REQTS + \ msousa@1909: NUMBER_OF_RTUCLIENT_REQTS + \ msousa@1909: NUMBER_OF_ASCIICLIENT_REQTS) msousa@1909: msousa@1909: msousa@1909: /*initialization following all parameters given by user in application*/ msousa@1909: msousa@1909: static client_node_t client_nodes[NUMBER_OF_CLIENT_NODES] = { msousa@1909: %(client_nodes_params)s msousa@1909: }; msousa@1909: msousa@1909: msousa@1909: static client_request_t client_requests[NUMBER_OF_CLIENT_REQTS] = { msousa@1909: %(client_req_params)s msousa@1909: }; msousa@1909: msousa@1909: msousa@1909: static server_node_t server_nodes[NUMBER_OF_SERVER_NODES] = { msousa@1909: %(server_nodes_params)s msousa@1909: } msousa@1909: ; msousa@1909: msousa@1909: /*******************/ msousa@1909: /*located variables*/ msousa@1909: /*******************/ msousa@1909: msousa@1909: %(loc_vars)s msousa@1909: