GeekTrack/4.Software/GeekTrackSDK/Project/GeekTrack.cpp

83 lines
1.7 KiB
C++
Raw Normal View History

#include"stdafx.h"
#include"GeekTrackSDK.h"
#include<stdio.h>
#include<thread>
#include<winsock2.h>
#include<windows.h>
#pragma comment(lib,"ws2_32.lib")
SOCKET sock;
sockaddr_in from, a;
WSADATA wsdata;
int fromlength = 0;
std::thread* t;
EulerAngles_t Pose;
float yaw = 0.0f, roll = 0.0f, pitch = 0.0f;
void GeekTrackUpdate() {
char buf[256];
int i = 0;
while (1)
{
//<2F>ӹ㲥<D3B9><E3B2A5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󶨵ĵ<F3B6A8B5>ַ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ĵ<EFBFBD>ַ<EFBFBD>Dz<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
recvfrom(sock, buf, 256, 0, (struct sockaddr FAR*) &from, (int FAR*) & fromlength);
Sleep(10);
int ret = sscanf_s(buf, "%f %f %f\n", &yaw, &roll, &pitch);
if (ret > 0) {
Pose.x = pitch;
Pose.y = roll;
Pose.z = yaw;
}
ZeroMemory(buf, 256);
}
}
void GeekTrack_Init() {
bool optval;
//<2F><><EFBFBD><EFBFBD>SOCKET<45><EFBFBD>汾Ϊ2.0
WSAStartup(0x0202, &wsdata);
optval = true;
//Ȼ<><C8BB><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׽<EFBFBD><D7BD>֣<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵĹ㲥<C4B9><E3B2A5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
a.sin_family = AF_INET;
a.sin_addr.s_addr = 0;
a.sin_port = htons(9000);
//from.sin_family = AF_INET;
//from.sin_addr.s_addr = INADDR_BROADCAST;
//from.sin_port = htons(5050);
fromlength = sizeof(SOCKADDR);
//<2F><>UDP<44><50>ʼ<EFBFBD><CABC><EFBFBD>׽<EFBFBD><D7BD><EFBFBD>
sock = socket(AF_INET, SOCK_DGRAM, 0);
// <20><><EFBFBD>ø<EFBFBD><C3B8>׽<EFBFBD><D7BD><EFBFBD>Ϊ<EFBFBD><EFBFBD><E3B2A5><EFBFBD>ͣ<EFBFBD>
//setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char FAR *)&optval, sizeof(optval));
// <20>Ѹ<EFBFBD><D1B8>׽<EFBFBD><D7BD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><D6B7>
bind(sock, (sockaddr*)&a, sizeof(sockaddr_in));
t = new std::thread(GeekTrackUpdate);
Pose.x = -1.0f;
Pose.y = -1.0f;
Pose.z = -1.0f;
}
EulerAngles_t GetEulerAngles() {
return Pose;
}
int main()
{
GeekTrack_Init();
while (1) {
Sleep(50);
printf("%f,%f,%f\n", Pose.x, Pose.y, Pose.z);
}
system("pause");
return 0;
}