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