From 87156fa3adfa2e3232a6f6e612584aa8a4ebaea1 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期二, 19 一月 2021 18:40:25 +0800
Subject: [PATCH] 添加模拟灯光

---
 lib/src/main/cpp/common/net.h |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/lib/src/main/cpp/common/net.h b/lib/src/main/cpp/common/net.h
index 48a7c7a..9f5685c 100644
--- a/lib/src/main/cpp/common/net.h
+++ b/lib/src/main/cpp/common/net.h
@@ -5,13 +5,53 @@
 #ifndef RTKBASESTATION_NET_H
 #define RTKBASESTATION_NET_H
 
-int WriteTCP(int fd, const uint8_t * buf, uint32_t len);
-int ReadTCP(int fd, uint8_t * buf, uint32_t len);
-int ConnectTCP(const char *ip, uint16_t port);
-void DisconnectTCP(int fd);
-int EstablishUDP(const char *ip, uint16_t port);
-void RemoveUDP(int fd);
-int WriteUDP(int fd, char *ip, uint16_t port, const uint8_t * buf, uint32_t len);
-int ReadUDP(int fd, uint8_t * buf, uint32_t len);
+#include <string>
+
+enum SERVICE_TYPE {
+    TYPE_SERVER,
+    TYPE_CLIENT
+};
+
+class CTcpPort
+{
+public:
+    SERVICE_TYPE m_iServiceType;
+    std::string m_sIp;
+    int m_nPort;
+    bool m_connected;
+
+    int m_pServerSocket;
+    int m_pClientSocket;
+
+public:
+    CTcpPort();
+    virtual ~CTcpPort();
+
+    bool IsOpen(void);
+    bool CloseTcpPort();
+    bool OpenTcpPort(const char *ip, int port);
+    void set_event_callback(void (*callback)(int, void *, void *), void *context);
+    void set_data_callback(void (*callback)(void *, int, void *, void *), void *context);
+    int WriteTCP(const uint8_t * buf, uint32_t len);
+private:
+    int GetHostIP(const char *host_name, char *net_addr);
+    bool is_domain_name(const char *ip);
+    int socket_set_keepalive(int fd);
+    int tcp_connect(char *ip, uint16_t port);
+
+    void(*event_func)(int, void *, void *);	//鏁版嵁鍥炶皟鍑芥暟鎸囬拡
+    void *event_func_context;	//鏁版嵁鍥炶皟鍑芥暟涓婁笅鏂�
+
+    void(*receive_data_func)(void *, int, void *, void *);	//鏁版嵁鍥炶皟鍑芥暟鎸囬拡
+    void *receive_data_func_context;	//鏁版嵁鍥炶皟鍑芥暟涓婁笅鏂�
+
+    static void *TcpConnectThread(void *p);
+    static void *TcpListenThread(void *p);
+};
+
+//int WriteTCP(int fd, const uint8_t * buf, uint32_t len);
+//int ReadTCP(int fd, uint8_t * buf, uint32_t len);
+//int ConnectTCP(const char *ip, uint16_t port);
+//void DisconnectTCP(int fd);
 
 #endif //RTKBASESTATION_NET_H

--
Gitblit v1.8.0