-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathZLServer.h
More file actions
72 lines (65 loc) · 1.5 KB
/
Copy pathZLServer.h
File metadata and controls
72 lines (65 loc) · 1.5 KB
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
#ifndef _ZLSERVER_H_
#define _ZLSERVER_H_
#include "Connection.h"
#include <modbus.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string>
#include <glib.h>
#include "json.hpp"
using json = nlohmann::json;
class ZLServer : public Connection {
private:
class IOModel {
public:
const int slaveID_;
std::vector<char> inputs_, outputs_;
std::string ip_;
int fd_;
public:
IOModel(const std::string &ip, int id, int ins, int outs);
~IOModel();
bool equal(const std::string &ip) const {
return ip_ == ip ? true : false;
}
/*bool equal(int fd) const {
return fd_ == fd ? true : false;
}*/
bool equal(int id) const {
return slaveID_ == id ? true : false;
}
bool read(modbus_t *ctx);
void write(modbus_t *ctx);
bool setFileDesc(int fd);
private:
int modbusRead(modbus_t *ctx, uint8_t buf[], int size);
bool modbusWrite(modbus_t *ctx, char buf[], int size);
};
const int port_;
int socket_fd_;
sockaddr_in sockaddr_;
std::vector<IOModel*> models_;
std::vector<IOModel*>::iterator moditer_;
modbus_t *modbus_ctx_;
public:
ZLServer(int port);
~ZLServer();
int listenZL();
int clientConnected();
bool readAll();
void createIOModel(const std::string &ip, int id, int ins, int outs);
private:
IOModel* findIOModel(const std::string &ip);
void setIOModel(const std::string &ip, int fd);
};
class ZLDefine {
private:
json js_;
public:
ZLDefine();
~ZLDefine();
ZLServer* createServer();
private:
void addIOModels(ZLServer *server);
};
#endif