106 lines
2.1 KiB
C++
106 lines
2.1 KiB
C++
|
#ifndef UDPQT_H
|
||
|
#define UDPQT_H
|
||
|
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <boost/asio.hpp>
|
||
|
#include <boost/thread/thread.hpp>
|
||
|
#include <boost/lexical_cast.hpp>
|
||
|
#include <json/json.h>
|
||
|
#include <boost/array.hpp>
|
||
|
#include "../utility/SH_MySingleton.hpp"
|
||
|
#include "../common/SH_global.h"
|
||
|
|
||
|
|
||
|
|
||
|
#define MULTICAST_PORT_SEND 7302 //根据接收组播udp发送端口
|
||
|
|
||
|
#define SYSUDPIP "127.0.0.1"
|
||
|
#define SYSUDPPORT "9999"
|
||
|
|
||
|
#define RECIEVE_CONNECT_STATUS 1 //QT连接确认
|
||
|
#define RECIEVE_CONFIG_GET 3 //获取配置信息
|
||
|
#define RECIEVE_WIFI_CONTROL 4 //wifi操作
|
||
|
#define RECIEVE_WAVEDATA_CONTROL 7 //原始数据操作
|
||
|
|
||
|
|
||
|
#define CMD_TYPE_CONNECTQT 1
|
||
|
#define RECIEVE_CONFIG_GET 3
|
||
|
#define RECIEVE_WIFI_CONTROL 4
|
||
|
#define RECIEVE_WAVEDATA_CONTROL 7
|
||
|
|
||
|
|
||
|
class UdpSys : public MySingleton<UdpSys> {
|
||
|
public:
|
||
|
UdpSys();
|
||
|
~UdpSys();
|
||
|
/**
|
||
|
* @brief 发送数据
|
||
|
* @param pData 发送的字符串数据
|
||
|
* @return void
|
||
|
*/
|
||
|
void SendUdpToSingle(std::string pData);
|
||
|
|
||
|
/**
|
||
|
* @brief 连接子程序
|
||
|
* @return void
|
||
|
*/
|
||
|
void StartConnectSysUdp();
|
||
|
|
||
|
/**
|
||
|
* @brief 清除连接
|
||
|
* @return void
|
||
|
*/
|
||
|
void ClearConnect();
|
||
|
|
||
|
/**
|
||
|
* @brief 确认连接
|
||
|
* @return void
|
||
|
*/
|
||
|
// void ConfirmStatus();
|
||
|
|
||
|
private:
|
||
|
|
||
|
/**
|
||
|
* @brief 发送数据的回调函数
|
||
|
* @return void
|
||
|
*/
|
||
|
void handle_send_to(const boost::system::error_code& ec,
|
||
|
size_t trans);
|
||
|
|
||
|
/**
|
||
|
* @brief 接收数据
|
||
|
* @return void
|
||
|
*/
|
||
|
void recvUdpData();
|
||
|
|
||
|
/**
|
||
|
* @brief 数据分析
|
||
|
* @return void
|
||
|
*/
|
||
|
void AnalysisDataSys(std::string cmd);
|
||
|
|
||
|
/**
|
||
|
* @brief 接收数据的回调函数
|
||
|
* @return void
|
||
|
*/
|
||
|
void HandleRead(const boost::system::error_code& pEc,
|
||
|
std::size_t pBytesTransferred);
|
||
|
private:
|
||
|
boost::mutex udpMutex;
|
||
|
std::string remoteIp;
|
||
|
int remoteport;
|
||
|
boost::asio::ip::udp::endpoint remoteEndPoint;
|
||
|
boost::asio::ip::udp::endpoint senderEndPoint;
|
||
|
boost::asio::io_service mIoSev;
|
||
|
boost::asio::ip::udp::socket udpSock;
|
||
|
boost::array<char,8192> m_buffer;
|
||
|
std::string mData;
|
||
|
bool status;
|
||
|
int times;
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif
|
||
|
|