返回
多御红包活动

UDP获取字节信息

发布时间:2023-01-17 07:36:16 33
# git# 数据# 信息
void CALLBACK XIONGAAPP::XIONGAAGPSRecvCallback(char *pRecvBuf, int nRecvLen, void *pUserData)
{
LOG4CPLUS_INFO(LOGGERTAG, "开始接收回调信息");

char szTVer2Fram[512] = { 0 };
char szVer2Body[512] = { 0 };

//截取需要的数据部分
memcpy(szTVer2Fram, pRecvBuf + 9, sizeof(szTVer2Fram));

//根据发送的结构体定义一个相同的结构体接收数据
TVer2Fram* szbuff = (TVer2Fram*)szTVer2Fram;
TVer2DataBody* szbuff1 = (TVer2DataBody*)szVer2Body;

memcpy(szVer2Body, szTVer2Fram + 21, sizeof(szVer2Body));

std::string strGpsID;
double dx ;
double dy ;
unsigned short speed ;
unsigned short dir ;
unsigned short height ;
unsigned short precision ;
unsigned short year ;

BYTE month ;
BYTE day ;
BYTE hour ;
BYTE minute ;
BYTE second ;

strGpsID = szbuff->id; //GPSID
dx = szbuff1->dx; // 纬度
dy = szbuff1->dy; //经度
speed = szbuff1->speed; //速度
dir = szbuff1->dir; //方向
height = szbuff1->height; //高度
precision = szbuff1->precision; //精度
year = szbuff1->date.year; //时间 年
month = szbuff1->date.month; //月
day = szbuff1->date.day; //日
hour = szbuff1->date.hour; //时
minute = szbuff1->date.minute; //分
second = szbuff1->date.second; //秒

unsigned short sYear = ntohs(year);
unsigned short sSpeed = ntohs(speed);
unsigned short sDir = ntohs(dir);
unsigned short sHeight = ntohs(height);
unsigned short sPrecision = ntohs(precision);

int nmonth = (int)month;
int nday=(int)day;
int nhour = (int)hour;
int nminute = (int)minute;
int nsecond = (int)second;

std::string strYear = boost::lexical_cast<std::string>(sYear);
std::string strMonth = boost::lexical_cast<std::string>(nmonth);
std::string strDay = boost::lexical_cast<std::string>(nday);
std::string strHour = boost::lexical_cast<std::string>(nhour);
std::string strMinute = boost::lexical_cast<std::string>(nminute);
std::string strSecond = boost::lexical_cast<std::string>(nsecond);

stringstream sstream;
sstream << strYear << "-" << setw(2) << setfill('0') << strMonth << "-" << setw(2) << setfill('0') << strDay << " " << setw(2) << setfill('0') << strHour << ":" << setw(2) << setfill('0') << strMinute << ":" << setw(2) << setfill('0') << strSecond;
std::string strDateTime = sstream.str();

Json::Value root;
root["CmdType"] = QPID_GPS_INFO;
root["Type"] = eGpsTypeHikEnforcement;
root["DeviceIdentify"] = strGpsID;
root["Longitude"] = dx;
root["Latitude"] = dy;
root["Speed"] = sSpeed;
root["Dir"] = sDir;
root["Height"] = sHeight;
root["Precision"] =sPrecision;
root["DateTime"] = strDateTime;

std::string strQpidGPSTrackMsg = root.toStyledString();
LOG4CPLUS_INFO(LOGGERTAG, strQpidGPSTrackMsg);
CMessageCenter::GetInstance().AddQpidMessage(strQpidGPSTrackMsg);

}

CUDPServer *g_pXAUDPServer = NULL;
boost::asio::io_service io_service_;

void XIONGAAPP::XIONGAHKGPSMessageFun()
{
int nPort = 0;
CConfigCenter::GetInstance().GetXIONGAHKUpdPort(nPort);
if (nPort > 0)
{
if (g_pXAUDPServer == NULL)
{
g_pXAUDPServer = new CUDPServer(io_service_, nPort);
g_pXAUDPServer->SetRecvCallback(XIONGAAGPSRecvCallback, 0);
io_service_.run();
}
else
{
if (io_service_.stopped())
{
g_pXAUDPServer->SetRecvCallback(XIONGAAGPSRecvCallback, 0);
io_service_.reset();
io_service_.run();
}
}
}
}

void XIONGAAPP::StartXIONGAMonitorGPS()
{
boost::thread XIONGAhkGPSMessageThread(&XIONGAAPP::XIONGAHKGPSMessageFun);
XIONGAhkGPSMessageThread.detach();
}

void XIONGAAPP::StopXIONGAMonitorGPS()
{
io_service_.stop();
g_pXAUDPServer->SetRecvCallback(NULL, NULL);
if (g_pXAUDPServer != NULL)
delete g_pXAUDPServer;
}

使用boost库链接udp

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
公网和内网 2023-01-17 07:19:31