-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbpoll.h
66 lines (57 loc) · 1.42 KB
/
mbpoll.h
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
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <string.h>
#ifndef _WIN32
#include <arpa/inet.h>
#else
#include <Ws2tcpip.h>
/*#include <winsock2.h>*/
#endif
#include <modbus/modbus.h>
#ifndef _WIN32
extern const char *__progname;
#else
const char *__progname;
#endif
typedef enum {
S_SHORT,
S_LONG,
U_SHORT,
U_LONG,
BINARY,
FLOAT_T,
ASCII
} format_type;
struct modbus_db_params {
int starting_register;
int num_registers;
format_type format;
};
struct modbus_comm_params {
char *ip_address;
int port;
int response_timeout;
int rtu_address;
int slave;
};
/* declarations */
void usage();
int is_valid_ip(char *ip_addr);
void validate_params(struct modbus_comm_params *mbcp,
struct modbus_db_params *mbdp);
int parse_args(struct modbus_comm_params *mbcp, struct modbus_db_params *mbdp,
int argc, char **argv);
int poll(struct modbus_comm_params *mbcp, struct modbus_db_params *mbdp,
uint16_t *tab_reg);
void print_results(struct modbus_db_params *mbdp,
uint16_t *tab_reg, int num_results);
void print_s_short(uint16_t value);
void print_s_long(uint16_t value1, uint16_t value2);
void print_u_short(uint16_t value);
void print_u_long(uint16_t value1, uint16_t value2);
void print_binary(uint16_t value);
void print_float(uint16_t value1, uint16_t value2);
void print_ascii(uint16_t value);