remove dependency on APR library

This commit is contained in:
Livox-SDK
2020-12-04 22:01:38 +08:00
parent eb19d42ce4
commit 7cf759a760
564 changed files with 2880 additions and 181270 deletions
-7
View File
@@ -7,13 +7,6 @@ endif ()
set(DEMO_NAME lidar_utc_sync)
add_executable(${DEMO_NAME} main.cpp lds_lidar.cpp synchro.cpp)
if (WIN32)
add_custom_command(TARGET ${DEMO_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/third_party/apr/bin/libapr-1.dll"
$<TARGET_FILE_DIR:${DEMO_NAME}>)
endif()
target_link_libraries(${DEMO_NAME}
PRIVATE
${PROJECT_NAME}_static
+1 -1
View File
@@ -156,7 +156,7 @@ void LdsLidar::OnDeviceBroadcast(const BroadcastDeviceInfo *info) {
}
}
bool result = false;
livox_status result = kStatusFailure;
uint8_t handle = 0;
result = AddLidarToConnect(info->broadcast_code, &handle);
if (result == kStatusSuccess && handle < kMaxLidarCount) {
+24 -92
View File
@@ -24,16 +24,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <thread>
#include <chrono>
#include <string.h>
#include <apr_general.h>
#include <apr_getopt.h>
#include "cmdline.h"
#include "lds_lidar.h"
#include "synchro.h"
@@ -44,91 +38,33 @@ static std::vector<std::string> cmdline_broadcast_code;
/** Set the program options.
* You can input the registered device broadcast code and decide whether to save the log file.
*/
static int SetProgramOption(int argc, const char *argv[]) {
apr_status_t rv;
apr_pool_t *mp = NULL;
static const apr_getopt_option_t opt_option[] = {
/** Long-option, short-option, has-arg flag, description */
{ "code", 'c', 1, "Register device broadcast code" },
{ "log", 'l', 0, "Save the log file" },
{ "help", 'h', 0, "Show help" },
{ NULL, 0, 0, NULL },
};
apr_getopt_t *opt = NULL;
int optch = 0;
const char *optarg = NULL;
if (apr_initialize() != APR_SUCCESS) {
return -1;
}
if (apr_pool_create(&mp, NULL) != APR_SUCCESS) {
return -1;
}
rv = apr_getopt_init(&opt, mp, argc, argv);
if (rv != APR_SUCCESS) {
printf("Program options initialization failed.\n");
return -1;
}
/** Parse the all options based on opt_option[] */
bool is_help = false;
while ((rv = apr_getopt_long(opt, opt_option, &optch, &optarg)) == APR_SUCCESS) {
switch (optch) {
case 'c': {
printf("Register broadcast code: %s\n", optarg);
char *sn_list = (char *)malloc(sizeof(char)*(strlen(optarg) + 1));
strncpy(sn_list, optarg, sizeof(char)*(strlen(optarg) + 1));
char *sn_list_head = sn_list;
sn_list = strtok(sn_list, "&");
cmdline_broadcast_code.clear();
while (sn_list) {
cmdline_broadcast_code.push_back(sn_list);
sn_list = strtok(nullptr, "&");
}
free(sn_list_head);
sn_list_head = nullptr;
break;
}
case 'l': {
printf("Save the log file.\n");
SaveLoggerFile();
break;
}
case 'h': {
printf(
" [-c] Register device broadcast code\n"
" [-l] Save the log file\n"
" [-h] Show help\n"
);
is_help = true;
break;
}
default: {
break;
}
void SetProgramOption(int argc, const char *argv[]) {
cmdline::parser cmd;
cmd.add<std::string>("code", 'c', "Register device broadcast code", false);
cmd.add("log", 'l', "Save the log file");
cmd.add("help", 'h', "Show help");
cmd.parse_check(argc, const_cast<char **>(argv));
if (cmd.exist("code")) {
std::string sn_list = cmd.get<std::string>("code");
printf("Register broadcast code: %s\n", sn_list.c_str());
size_t pos = 0;
cmdline_broadcast_code.clear();
while ((pos = sn_list.find("&")) != std::string::npos) {
cmdline_broadcast_code.push_back(sn_list.substr(0, pos));
sn_list.erase(0, pos + 1);
}
cmdline_broadcast_code.push_back(sn_list);
}
if (rv != APR_EOF) {
printf("Invalid options.\n");
if (cmd.exist("log")) {
printf("Save the log file.\n");
SaveLoggerFile();
}
apr_pool_destroy(mp);
mp = NULL;
apr_terminate();
if (is_help)
return 1;
return 0;
return;
}
int main(int argc, const char *argv[]) {
/** Set the program options. */
if (SetProgramOption(argc, argv)) {
return 0;
}
SetProgramOption(argc, argv);
LdsLidar& read_lidar = LdsLidar::GetInstance();
@@ -162,11 +98,7 @@ int main(int argc, const char *argv[]) {
return 0;
}
#ifdef WIN32
Sleep(100000);
#else
sleep(100);
#endif
std::this_thread::sleep_for(std::chrono::seconds(100));
synchro.Stop();
read_lidar.DeInitLdsLidar();
+7 -10
View File
@@ -268,10 +268,8 @@ void Synchro::Close() {
/* Sets up the port parameters */
int Synchro::Setup(enum BaudRate baud, enum Parity parity) {
static uint32_t baud_map[19] = {\
B2400, B4800, B9600, B19200, B38400, B57600,B115200, B230400,\
B460800, B500000, B576000,B921600,B1152000, B1500000, B2000000,\
B2500000, B3000000, B3500000, B4000000\
static uint32_t baud_map[19] = {
B2400, B4800, B9600, B19200, B38400, B57600,B115200, B230400
};
tcflag_t baudrate;
struct termios options;
@@ -284,19 +282,18 @@ int Synchro::Setup(enum BaudRate baud, enum Parity parity) {
usleep(10000);
/* Minimum number of characters to read */
options.c_cc[VMIN] = 0;
options.c_cc[VMIN] = 0;
/* Time to wait for data */
options.c_cc[VTIME] = 100;
options.c_cc[VTIME] = 100;
/* Enable the receiver and set local mode... */
options.c_cflag |= (CLOCAL | CREAD);
/* Set boadrate */
options.c_cflag &= ~CBAUD;
baudrate = baud_map[baud];
options.c_cflag |= baudrate;
printf("[Baudrate]: %d %d\r\n", baud, baudrate);
cfsetispeed(&options, baudrate);
cfsetospeed(&options, baudrate);
printf("[Baudrate]: %d %u\r\n", baud, baudrate);
switch (parity) {
case P_8N1: