mb_addr.h
changeset 0 ae252e0fd9b8
equal deleted inserted replaced
-1:000000000000 0:ae252e0fd9b8
       
     1 /*
       
     2  * Copyright (c) 2002,2016 Mario de Sousa (msousa@fe.up.pt)
       
     3  *
       
     4  * This file is part of the Modbus library for Beremiz and matiec.
       
     5  *
       
     6  * This Modbus library is free software: you can redistribute it and/or modify
       
     7  * it under the terms of the GNU Lesser General Public License as published by
       
     8  * the Free Software Foundation, either version 3 of the License, or
       
     9  * (at your option) any later version.
       
    10  *
       
    11  * This program is distributed in the hope that it will be useful, but
       
    12  * WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
       
    14  * General Public License for more details.
       
    15  *
       
    16  * You should have received a copy of the GNU Lesser General Public License
       
    17  * along with this Modbus library.  If not, see <http://www.gnu.org/licenses/>.
       
    18  *
       
    19  * This code is made available on the understanding that it will not be
       
    20  * used in safety-critical situations without a full and competent review.
       
    21  */
       
    22 
       
    23 
       
    24 #ifndef MODBUS_LAYER2_H
       
    25 #define MODBUS_LAYER2_H
       
    26 
       
    27 #include <time.h> /* struct timespec data type */
       
    28 
       
    29 //#include <sys/socket.h>
       
    30 //#include <netinet/in.h>
       
    31 #include <netinet/ip.h> /* superset of previous */ // Required for INADDR_ANY
       
    32        
       
    33        
       
    34 /* Library Error codes */
       
    35 #define PORT_FAILURE   -101
       
    36 #define INTERNAL_ERROR -102
       
    37 #define TIMEOUT        -103
       
    38 #define INVALID_FRAME  -104
       
    39 #define MODBUS_ERROR   -105
       
    40 
       
    41 /* NOTE: Modbus error codes are defined in mb_util.h */
       
    42 
       
    43 
       
    44 
       
    45 
       
    46 typedef enum {optimize_speed, optimize_size} optimization_t;
       
    47 
       
    48 
       
    49 typedef enum {
       
    50         naf_ascii,
       
    51         naf_rtu,
       
    52         naf_tcp,
       
    53   } node_addr_family_t;
       
    54 
       
    55 typedef struct {
       
    56         const char *host;
       
    57         const char *service;
       
    58         int         close_on_silence;  
       
    59   } node_addr_tcp_t;
       
    60 
       
    61 typedef struct {
       
    62         const char *device;
       
    63         int         baud;       /* plain baud rate, eg 2400; zero for the default 9600 */
       
    64         int         parity;     /* 0 for none, 1 for odd, 2 for even                   */
       
    65         int         data_bits;
       
    66         int         stop_bits;
       
    67         int         ignore_echo; /* 1 => ignore echo; 0 => do not ignore echo */
       
    68   } node_addr_rtu_t;
       
    69 
       
    70 typedef node_addr_rtu_t node_addr_ascii_t;
       
    71 
       
    72 typedef union {
       
    73         node_addr_ascii_t ascii;
       
    74         node_addr_rtu_t   rtu;
       
    75         node_addr_tcp_t   tcp;
       
    76   } node_addr_common_t;
       
    77 
       
    78 typedef struct {
       
    79         node_addr_family_t  naf;
       
    80         node_addr_common_t  addr;
       
    81   } node_addr_t;
       
    82 
       
    83 #endif  /* MODBUS_LAYER2_H */
       
    84 
       
    85 
       
    86 
       
    87 
       
    88 
       
    89 
       
    90 
       
    91