Skip to content
codincodee edited this page Dec 21, 2017 · 23 revisions

CE30驱动开发库

版本号

推荐配置

  • 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);
}

接口描述

附录