-
Notifications
You must be signed in to change notification settings - Fork 10
Home
codincodee edited this page Dec 21, 2017
·
23 revisions
- Ubuntu 16.04 x86_64 或 Windows 10 64位
- Boost 1.65.0
- CMake 2.8.1
- GCC-C++ 5.4.0 或 MSVC 2015 64位
- C++11
#include <ce30_driver/udp_socket.h>
#include <iostream>
using namespace std;
using namespace ce30_driver;
int main() {
// 建立Socket
UDPSocket socket;
if (socket.Connect() != Diagnose::connect_successful) {
cerr << "Connection Failed" << endl;
return -1;
}
// 请求开始测距
StartRequestPacket start_request;
socket.SendPacket(start_request);
while (true) {
// 接收数据包
Packet packet;
if (socket.GetPacket(packet) != Diagnose::receive_successful) {
continue;
}
// 解析数据包
unique_ptr<ParsedPacket> parsed = packet.Parse();
if (parsed) {
// 打印所有列
for (Column& column : parsed->columns) {
// 打印列数据
// 打印横向角
cout << column.azimuth << endl;
// 打印列上的每个感光元数据
for (Channel& channel : column.channels) {
// 打印(距离,光强)
cout << "(" << channel.distance << ", " << channel.amplitude << ") ";
}
cout << endl;
}
} else {
cerr << "Unable to Parse" << endl;
}
}
// 请求停止测距
StopRequestPacket stop_request;
socket.SendPacket(stop_request);
}
- class UDPSocket
- enum class Diagnose
- struct PacketBase
- struct Packet
- struct ParsedPacket
- struct Column
- struct Channel
- struct VersionRequestPacket
- struct VersionResponsePacket
- struct SetIDRequestPacket
- struct SetIDResponsePacket
- struct GetIDRequestPacket
- struct GetIDResponsePacket
- struct StartRequestPacket
- struct StopRequestPacket
北醒(北京)光子科技有限公司