feat: 初始化 Go2 导航代码与配置

This commit is contained in:
2026-10-14 11:08:44 +08:00
parent 8e16ecceba
commit 9dab37e8c8
1258 changed files with 1936673 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.0)
set(DEMO_NAME livox_lidar_ip_set)
add_executable(${DEMO_NAME} main.cpp)
target_link_libraries(${DEMO_NAME}
PUBLIC
livox_lidar_sdk_static
)

View File

@@ -0,0 +1,21 @@
{
"Avia2": {
"lidar_net_info" : {
"cmd_data_port" : 56100,
"push_msg_port" : 56200,
"point_data_port": 56300,
"imu_data_port" : 56400,
"log_data_port" : 56500
},
"host_net_info" : [
{
"host_ip" : "192.168.1.5",
"cmd_data_port" : 56101,
"push_msg_port" : 56201,
"point_data_port": 56301,
"imu_data_port" : 56401,
"log_data_port" : 56501
}
]
}
}

View File

@@ -0,0 +1,107 @@
//
// The MIT License (MIT)
//
// Copyright (c) 2022 Livox. All rights reserved.
//
#include "livox_lidar_def.h"
#include "livox_lidar_api.h"
#ifdef _WIN32
#include <winsock2.h>
#else
#include <unistd.h>
#include <arpa/inet.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atomic>
#include <thread>
#include <chrono>
#include <iostream>
// Target lidar IP config to apply. Override via CLI: <config> <ip> <mask> <gw>
static char g_target_ip[16] = "192.168.1.10";
static char g_target_mask[16] = "255.255.255.0";
static char g_target_gw[16] = "192.168.1.1";
static std::atomic<bool> g_done{false};
void RebootCallback(livox_status status, uint32_t handle, LivoxLidarRebootResponse* response, void*) {
if (response == nullptr) {
printf("Reboot response is null, status:%u handle:%u\n", status, handle);
return;
}
printf("Reboot ack, status:%u handle:%u ret_code:%u\n", status, handle, response->ret_code);
g_done.store(true);
}
void SetIpInfoCallback(livox_status status, uint32_t handle, LivoxLidarAsyncControlResponse* response, void*) {
if (response == nullptr) {
printf("SetIp response is null, status:%u handle:%u\n", status, handle);
return;
}
printf("SetLivoxLidarIp ack, status:%u handle:%u ret_code:%u error_key:%u\n",
status, handle, response->ret_code, response->error_key);
if (status == kLivoxLidarStatusSuccess && response->ret_code == 0 && response->error_key == 0) {
printf("SetLivoxLidarIp OK, rebooting lidar to apply new IP...\n");
LivoxLidarRequestReboot(handle, RebootCallback, nullptr);
} else {
printf("SetLivoxLidarIp failed, skip reboot.\n");
g_done.store(true);
}
}
void LidarInfoChangeCallback(const uint32_t handle, const LivoxLidarInfo* info, void*) {
if (info == nullptr) {
printf("LidarInfoChangeCallback: info is null.\n");
return;
}
struct in_addr addr;
addr.s_addr = handle;
printf("Lidar online, handle:%u ip:%s sn:%s dev_type:%u\n",
handle, inet_ntoa(addr), info->sn, info->dev_type);
LivoxLidarIpInfo lidar_ip_info;
memset(&lidar_ip_info, 0, sizeof(lidar_ip_info));
strncpy(lidar_ip_info.ip_addr, g_target_ip, sizeof(lidar_ip_info.ip_addr) - 1);
strncpy(lidar_ip_info.net_mask, g_target_mask, sizeof(lidar_ip_info.net_mask) - 1);
strncpy(lidar_ip_info.gw_addr, g_target_gw, sizeof(lidar_ip_info.gw_addr) - 1);
printf("Apply lidar ip -> %s / mask %s / gw %s\n",
lidar_ip_info.ip_addr, lidar_ip_info.net_mask, lidar_ip_info.gw_addr);
SetLivoxLidarIp(handle, &lidar_ip_info, SetIpInfoCallback, nullptr);
}
int main(int argc, const char* argv[]) {
if (argc < 2 || argc > 5) {
printf("Usage: %s <config.json> [lidar_ip] [subnet_mask] [gateway]\n", argv[0]);
printf(" defaults: %s %s %s\n", g_target_ip, g_target_mask, g_target_gw);
return -1;
}
const std::string path = argv[1];
if (argc >= 3) strncpy(g_target_ip, argv[2], sizeof(g_target_ip) - 1);
if (argc >= 4) strncpy(g_target_mask, argv[3], sizeof(g_target_mask) - 1);
if (argc >= 5) strncpy(g_target_gw, argv[4], sizeof(g_target_gw) - 1);
if (!LivoxLidarSdkInit(path.c_str())) {
printf("Livox Init Failed\n");
LivoxLidarSdkUninit();
return -1;
}
SetLivoxLidarInfoChangeCallback(LidarInfoChangeCallback, nullptr);
const int timeout_sec = 60;
for (int i = 0; i < timeout_sec && !g_done.load(); ++i) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
LivoxLidarSdkUninit();
printf("set_lidar_ip demo end.\n");
return 0;
}