1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#ifndef ZABBIX_SYSINFO_COMMON_MODBTYPE_H
#define ZABBIX_SYSINFO_COMMON_MODBTYPE_H
#include "zbxsysinfo.h"
extern int CONFIG_TIMEOUT;
#define ZBX_MODBUS_TCP_PORT_DEFAULT 502
#define ZBX_MODBUS_FUNCTION_EMPTY 0
#define ZBX_MODBUS_FUNCTION_COIL 1
#define ZBX_MODBUS_FUNCTION_DISCRETE_INPUT 2
#define ZBX_MODBUS_FUNCTION_HOLDING_REGISTERS 3
#define ZBX_MODBUS_FUNCTION_INPUT_REGISTERS 4
#define ZBX_MODBUS_SERIAL_PARAMS_PARITY_NONE 'N'
#define ZBX_MODBUS_SERIAL_PARAMS_PARITY_EVEN 'E'
#define ZBX_MODBUS_SERIAL_PARAMS_PARITY_ODD 'O'
#define ZBX_MODBUS_BYTE_SWAP_16(t_int16) (((t_int16 >> 8) & 0xFF) | ((t_int16 & 0xFF) << 8))
#define ZBX_MODBUS_32BE(t_int16) \
(((uint32_t)t_int16[0]) << 16) | t_int16[1]
#define ZBX_MODBUS_32MLE(t_int16) \
(((uint32_t)t_int16[1]) << 16) | t_int16[0]
#define ZBX_MODBUS_32MBE(t_int16) \
(((uint32_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[0])) << 16) | \
ZBX_MODBUS_BYTE_SWAP_16(t_int16[1])
#define ZBX_MODBUS_32LE(t_int16) \
(((uint32_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[1])) << 16) | \
ZBX_MODBUS_BYTE_SWAP_16(t_int16[0])
#define ZBX_MODBUS_64BE(t_int16) \
(((uint64_t)t_int16[0]) << 48) | \
(((uint64_t)t_int16[1]) << 32) | \
(((uint64_t)t_int16[2]) << 16) | t_int16[3]
#define ZBX_MODBUS_64MLE(t_int16) \
(((uint64_t)t_int16[3]) << 48) | \
(((uint64_t)t_int16[2]) << 32) | \
(((uint64_t)t_int16[1]) << 16) | t_int16[0]
#define ZBX_MODBUS_64MBE(t_int16) \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[0])) << 48) | \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[1])) << 32) | \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[2])) << 16) | \
ZBX_MODBUS_BYTE_SWAP_16(t_int16[3])
#define ZBX_MODBUS_64LE(t_int16) \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[3])) << 48) | \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[2])) << 32) | \
(((uint64_t)ZBX_MODBUS_BYTE_SWAP_16(t_int16[1])) << 16) | \
ZBX_MODBUS_BYTE_SWAP_16(t_int16[0])
typedef enum
{
ZBX_MODBUS_PROTOCOL_TCP,
ZBX_MODBUS_PROTOCOL_RTU
} modbus_protocol_t;
typedef struct
{
char *ip;
char *port;
}
zbx_modbus_connection_tcp;
typedef struct
{
char *port;
int baudrate;
unsigned char data_bits;
unsigned char parity;
unsigned char stop_bits;
}
zbx_modbus_connection_serial;
typedef struct
{
modbus_protocol_t protocol;
union
{
zbx_modbus_connection_tcp tcp;
zbx_modbus_connection_serial serial;
} conn_info;
}
zbx_modbus_endpoint_t;
typedef enum
{
ZBX_MODBUS_DATATYPE_BIT,
ZBX_MODBUS_DATATYPE_INT8,
ZBX_MODBUS_DATATYPE_UINT8,
ZBX_MODBUS_DATATYPE_INT16,
ZBX_MODBUS_DATATYPE_UINT16,
ZBX_MODBUS_DATATYPE_INT32,
ZBX_MODBUS_DATATYPE_UINT32,
ZBX_MODBUS_DATATYPE_FLOAT,
ZBX_MODBUS_DATATYPE_UINT64,
ZBX_MODBUS_DATATYPE_DOUBLE
} modbus_datatype_t;
typedef enum
{
ZBX_MODBUS_ENDIANNESS_BE,
ZBX_MODBUS_ENDIANNESS_LE,
ZBX_MODBUS_ENDIANNESS_MBE,
ZBX_MODBUS_ENDIANNESS_MLE
} modbus_endianness_t;
int modbus_get(AGENT_REQUEST *request, AGENT_RESULT *result);
int zbx_init_modbus(char **error);
void zbx_deinit_modbus(void);
#endif /* ZABBIX_SYSINFO_COMMON_MODBTYPE_H */
|