This commit is contained in:
parent
869bb94970
commit
5a1cabe7da
|
|
@ -0,0 +1,219 @@
|
|||
cmake_minimum_required(VERSION 3.21)
|
||||
# cmake_policy(SET CMP0146 NEW)
|
||||
|
||||
message("NVIDIA NX PLATFORM")
|
||||
set(PROJECT_NAME VCarContainer)
|
||||
project(${PROJECT_NAME} VERSION 1.0)
|
||||
|
||||
|
||||
add_definitions(-std=c++11)
|
||||
add_definitions(-DAPI_EXPORTS)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
#add_definitions("-Wall -g")
|
||||
|
||||
find_package(CUDA REQUIRED)
|
||||
#message(STATUS "${CUDA_INCLUDE_DIRS}")
|
||||
|
||||
#opencv
|
||||
find_package(OpenCV REQUIRED)
|
||||
# message(STATUS "${OpenCV_LIBS}")
|
||||
# message(STATUS "${OpenCV_INCLUDE_DIRS}")
|
||||
|
||||
|
||||
|
||||
# 设置编译工具
|
||||
#set(CMAKE_SYSTEM_NAME Linux)
|
||||
#set(CMAKE_C_COMPILER "gcc")
|
||||
#set(CMAKE_CXX_COMPILER "g++")
|
||||
# 设置arm交叉编译工具
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
|
||||
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
|
||||
|
||||
|
||||
# 设置项目生成目录
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/app)
|
||||
|
||||
# 设置调用库文件的位置
|
||||
set(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH "./lib")
|
||||
|
||||
set(SYS_USR_INCLUDE_DIR "/usr/include")
|
||||
set(SYS_USR_LIB_DIR "/usr/lib")
|
||||
set(SYS_USR_LOCAL_INCLUDE_DIR "/usr/local/include")
|
||||
set(SYS_USR_LOCAL_LIB_DIR "/usr/local/lib")
|
||||
#set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/x86_64-linux-gnu")
|
||||
#set(AARCH64_LINUX_LIB_DIR "/usr/lib/x86_64-linux-gnu")
|
||||
set(AARCH64_LINUX_INCLUDE_DIR "/usr/include/aarch64-linux-gnu")
|
||||
set(AARCH64_LINUX_LIB_DIR "/usr/lib/aarch64-linux-gnu")
|
||||
|
||||
#opencv3.2.0的库文件在/usr/lib/aarch64-linux-gnu下 头文件路径在/usr/include/opencv2
|
||||
#opencv4.5.5的库文件在/usr/local/lib下 头文件路径在/usr/local/include/opencv4
|
||||
#目前使用最新版opencv4.5.5
|
||||
set(OPENCV_INCLUDE_DIR ${SYS_USR_LOCAL_INCLUDE_DIR}/opencv4)
|
||||
set(OPENCV_LIB_DIR ${SYS_USR_LOCAL_LIB_DIR})
|
||||
|
||||
#set(CUDA_DIR "/usr/local/cuda-11.2")
|
||||
set(CUDA_DIR "/usr/local/cuda-10.2")
|
||||
set(CUDA_INCLUDE_DIR ${CUDA_DIR}/include)
|
||||
set(CUDA_LIB_DIR ${CUDA_DIR}/lib64)
|
||||
|
||||
set(TENSORRT_INCLUDE_DIR ${AARCH64_LINUX_INCLUDE_DIR}) #tensorrt的头文件在/usr/include/aarch64-linux-gnu下
|
||||
set(TENSORRT_LIB_DIR ${AARCH64_LINUX_LIB_DIR}) #tensorrt的库文件在/usr/lib/aarch64-linux-gnu下
|
||||
|
||||
set(DRM_INCLUDE_DIR ${SYS_USR_INCLUDE_DIR}/libdrm) #DRM的头文件在/usr/include/libdrm下
|
||||
|
||||
set(TEGRA_LIB_DIR ${AARCH64_LINUX_LIB_DIR}/tegra) #tegra库文件路径/usr/lib/aarch64-linux-gnu/tegra
|
||||
|
||||
#set(PCL_INCLUDE ${SYS_USR_LOCAL_INCLUDE_DIR}/pcl-1.7) #pcl头文件路径
|
||||
|
||||
|
||||
# nvidia ascend common include
|
||||
include_directories(
|
||||
#ai_matrix include
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/framework
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/mylog
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/myqueue
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/myshell
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/Utils
|
||||
# ${PROJECT_SOURCE_DIR}/ai_matrix/Http
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/Config
|
||||
|
||||
#nvidia ascend common cann include
|
||||
${PROJECT_SOURCE_DIR}/base/BlockingQueue
|
||||
${PROJECT_SOURCE_DIR}/base/CBase64
|
||||
${PROJECT_SOURCE_DIR}/base/CommandParser
|
||||
${PROJECT_SOURCE_DIR}/base/CommonDataType
|
||||
${PROJECT_SOURCE_DIR}/base/ConfigParser
|
||||
${PROJECT_SOURCE_DIR}/base/ErrorCode
|
||||
${PROJECT_SOURCE_DIR}/base/FileManager
|
||||
${PROJECT_SOURCE_DIR}/base/Log
|
||||
${PROJECT_SOURCE_DIR}/base/
|
||||
|
||||
${PROJECT_SOURCE_DIR}/common
|
||||
${PROJECT_SOURCE_DIR}/interface
|
||||
#common engine include
|
||||
${PROJECT_SOURCE_DIR}/engine/DataSourceEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/DecodeEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/MoveEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveMoveImageEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveMoveInfoEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1DataReadEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1InferenceEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1FilterInferenceEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/DetectDivideEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/Step2DataReadEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/Step2InferenceEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/CharacterConversionEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/SelectBestEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveResultCSVEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/DataUploadEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/ApiEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/ControlEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveDebugImageEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/WSServerEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/CornerInferenceEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/MergeEngine
|
||||
${PROJECT_SOURCE_DIR}/engine/DeleteExpiredFolderEngine
|
||||
|
||||
#common tools rtsp_server include
|
||||
${PROJECT_SOURCE_DIR}/tools/rtsp_server/3rdpart/md5
|
||||
${PROJECT_SOURCE_DIR}/tools/rtsp_server/net/
|
||||
${PROJECT_SOURCE_DIR}/tools/rtsp_server/xop/
|
||||
${PROJECT_SOURCE_DIR}/tools/yolov5/include/
|
||||
${PROJECT_SOURCE_DIR}/tools/Http
|
||||
${PROJECT_SOURCE_DIR}/tools/WebSocket
|
||||
|
||||
${CUDA_INCLUDE_DIR}
|
||||
${TENSORRT_INCLUDE_DIR}
|
||||
${DRM_INCLUDE_DIR}
|
||||
${OpenCV_DIR}
|
||||
${AARCH64_LINUX_INCLUDE_DIR}
|
||||
${SYS_USR_LOCAL_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
link_directories(${SYS_USR_LOCAL_LIB_DIR}
|
||||
${AARCH64_LINUX_LIB_DIR}
|
||||
${OPENCV_LIB_DIR}
|
||||
${CUDA_LIB_DIR}
|
||||
${TENSORRT_LIB_DIR}
|
||||
${TEGRA_LIB_DIR}
|
||||
)
|
||||
|
||||
#源文件
|
||||
#公共源文件
|
||||
file(GLOB_RECURSE COMMON_SRCS_LISTS
|
||||
main.cpp
|
||||
#ai_matrix src
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/framework/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/mylog/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/myqueue/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/myshell/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/Utils/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/Http/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/ai_matrix/Config/*.cpp
|
||||
|
||||
#common cann src
|
||||
${PROJECT_SOURCE_DIR}/base/CommandParser/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/base/ConfigParser/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/base/ErrorCode/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/base/FileManager/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/base/Log/*.cpp
|
||||
|
||||
#common engine src
|
||||
${PROJECT_SOURCE_DIR}/common/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/interface/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/DataSourceEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/DecodeEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/MoveEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveMoveImageEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveMoveInfoEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1DataReadEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1InferenceEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/Step1FilterInferenceEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/DetectDivideEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/Step2DataReadEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/Step2InferenceEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/CharacterConversionEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/SelectBestEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveResultCSVEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/DataUploadEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/ApiEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/ControlEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/SaveDebugImageEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/WSServerEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/CornerInferenceEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/MergeEngine/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/engine/DeleteExpiredFolderEngine/*.cpp
|
||||
|
||||
#common tools rtsp_server src
|
||||
${PROJECT_SOURCE_DIR}/tools/rtsp_server/net/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/tools/rtsp_server/xop/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/tools/yolov5/src/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/tools/yolov5/src/*.cu
|
||||
)
|
||||
|
||||
cuda_add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})
|
||||
# add_executable(${PROJECT_NAME} ${COMMON_SRCS_LISTS} ${SRCS_LISTS})
|
||||
|
||||
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} pthread) #other
|
||||
target_link_libraries(${PROJECT_NAME} nvinfer nvonnxparser nvcaffe_parser nvinfer_plugin) #TensorRT
|
||||
target_link_libraries(${PROJECT_NAME} cudart cuda) #CUDA
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${OpenCV_LIBS} #third party librarys
|
||||
avformat avcodec avutil avfilter swresample swscale postproc #VideoCodecV2
|
||||
yaml-cpp
|
||||
jsoncpp curl boost_system boost_filesystem ssh2
|
||||
-Wl,-z,relro,-z,now,-z,noexecstack -pie -s
|
||||
aws-cpp-sdk-core aws-cpp-sdk-s3
|
||||
)
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
FROM dustynv/jetson-inference:r32.6.1
|
||||
|
||||
#拷贝业务程序
|
||||
COPY --chown=1000:1000 app /app
|
||||
#WORKDIR /app/bin
|
||||
WORKDIR /app
|
||||
|
||||
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/lib
|
||||
|
||||
#CMD echo "$APP_NAME version $APP_VERSION"
|
||||
|
||||
ENTRYPOINT ["./train"]
|
||||
|
|
@ -0,0 +1,335 @@
|
|||
#include "Config.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
Config *Config::pInstance_ = nullptr;
|
||||
Config::GarbageCollector Config::gc_;
|
||||
std::mutex Config::mx_;
|
||||
|
||||
Config *Config::getins()
|
||||
{
|
||||
//双层锁,确保线程安全
|
||||
if (pInstance_ == nullptr)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mx_); //防止异常发生不能解锁
|
||||
if (pInstance_ == nullptr)
|
||||
{
|
||||
pInstance_ = new Config();
|
||||
}
|
||||
}
|
||||
return pInstance_;
|
||||
}
|
||||
|
||||
int Config::readYaml(std::string &strPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
strConfigYamlPath_ = strPath;
|
||||
config_ = YAML::LoadFile(strPath);
|
||||
|
||||
//退出程序
|
||||
if (config_.IsNull())
|
||||
{
|
||||
printf("config.yaml no find");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 控制参数
|
||||
this->baseConfig_.strTrackName = config_["base"]["track_name"].as<std::string>();
|
||||
this->baseConfig_.bTestModel = config_["base"]["test_model"].as<bool>();
|
||||
this->baseConfig_.iApiPort = config_["base"]["api_port"].as<int>();
|
||||
this->baseConfig_.strLogPath = config_["base"]["log_path"].as<std::string>();
|
||||
this->baseConfig_.strResultPath = config_["base"]["result_path"].as<std::string>();
|
||||
this->baseConfig_.strDebugResultPath = config_["base"]["debug_result_path"].as<std::string>();
|
||||
this->baseConfig_.iResultSaveDays = config_["base"]["result_save_days"].as<int>();
|
||||
|
||||
// 日志参数
|
||||
this->logConfig_.strOutLevel = config_["log"]["out_level"].as<std::string>();
|
||||
this->logConfig_.strSaveLevel = config_["log"]["save_level"].as<std::string>();
|
||||
|
||||
std::vector<YAML::Node> vecDataSourceNode = config_["data_source"].as<std::vector<YAML::Node>>();
|
||||
// 数据源参数
|
||||
for (const auto & it : vecDataSourceNode)
|
||||
{
|
||||
DataSourceConfig dataSourceConfig;
|
||||
dataSourceConfig.strUrl = it["url"].as<std::string>();
|
||||
dataSourceConfig.iSkipInterval = it["skip_interval"].as<int>();
|
||||
dataSourceConfig.vecIdentifyAreas = it["identify_areas"].as<std::vector<int>>();
|
||||
this->vecDataSourceConfig_.emplace_back(dataSourceConfig);
|
||||
}
|
||||
|
||||
// 识别参数
|
||||
this->identifyConfig_.strRunModel = config_["identify"]["run_mode"].as<std::string>();
|
||||
this->identifyConfig_.iPartitionFrameSpan = config_["identify"]["partition_frame_span"].as<int>();
|
||||
this->identifyConfig_.iTop_Y_SplitSpanPx = config_["identify"]["top_y_split_span_px"].as<int>();
|
||||
this->identifyConfig_.iSide_X_SplitSpanPx = config_["identify"]["side_x_split_span_px"].as<int>();
|
||||
this->identifyConfig_.iChkstopPx = config_["identify"]["chkstop_px"].as<int>();
|
||||
this->identifyConfig_.iChkstopCount = config_["identify"]["chkstop_count"].as<int>();
|
||||
this->identifyConfig_.iTargetMinHeight = config_["identify"]["target_min_height"].as<int>();
|
||||
this->identifyConfig_.iTargetMinWidth = config_["identify"]["target_min_width"].as<int>();
|
||||
this->identifyConfig_.iTargetMinY = config_["identify"]["target_min_y"].as<int>();
|
||||
this->identifyConfig_.iMaxIdentifyFrame = config_["identify"]["max_identify_frame"].as<int>();
|
||||
|
||||
// websocket server 服务端参数
|
||||
this->wSocketConfig_.bIsUse = config_["wsocket_server"]["is_use"].as<bool>();
|
||||
this->wSocketConfig_.iPort = config_["wsocket_server"]["port"].as<int>();
|
||||
this->wSocketConfig_.iMaxQueueLen = config_["wsocket_server"]["max_queue_len"].as<int>();
|
||||
|
||||
// http服务器参数
|
||||
this->httpServerConfig_.bIsUse = config_["http_server"]["is_use"].as<bool>();
|
||||
this->httpServerConfig_.strIp = config_["http_server"]["http_ip"].as<std::string>();
|
||||
this->httpServerConfig_.iPort = config_["http_server"]["http_port"].as<int>();
|
||||
this->httpServerConfig_.strTokenUrl = config_["http_server"]["token_path"].as<std::string>();
|
||||
this->httpServerConfig_.strUpResultUrl = config_["http_server"]["up_result_path"].as<std::string>();
|
||||
this->httpServerConfig_.strUpDeviceStatusUrl = config_["http_server"]["device_status_url"].as<std::string>();
|
||||
this->httpServerConfig_.strUserName = config_["http_server"]["username"].as<std::string>();
|
||||
this->httpServerConfig_.strPassword = config_["http_server"]["password"].as<std::string>();
|
||||
|
||||
// http服务器参数
|
||||
this->minioConfig_.bIsUse = config_["minio"]["is_use"].as<bool>();
|
||||
this->minioConfig_.strUrl = config_["minio"]["url"].as<std::string>();
|
||||
this->minioConfig_.strAccessKey = config_["minio"]["accesskey"].as<std::string>();
|
||||
this->minioConfig_.strSecretKey = config_["minio"]["secretkey"].as<std::string>();
|
||||
this->minioConfig_.strBucket = config_["minio"]["bucket"].as<std::string>();
|
||||
}
|
||||
catch (...) //捕获所有异常
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Config::readModelYaml(std::string &strPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
strConfigYamlPath_ = strPath;
|
||||
config_ = YAML::LoadFile(strPath);
|
||||
|
||||
//退出程序
|
||||
if (config_.IsNull())
|
||||
{
|
||||
printf("config.yaml no find");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 集装箱第一步模型
|
||||
this->modelConfig_containerStep1_.strModelPath = config_["container_step1_model"]["model_path"].as<std::string>();
|
||||
this->modelConfig_containerStep1_.fScoreThreshold = config_["container_step1_model"]["score_threshold"].as<float>();
|
||||
this->modelConfig_containerStep1_.vecClass = config_["container_step1_model"]["class"].as<std::vector<std::string>>();
|
||||
|
||||
// 集装箱第二步模型
|
||||
this->modelConfig_containerStep2_.strModelPath = config_["container_step2_model"]["model_path"].as<std::string>();
|
||||
this->modelConfig_containerStep2_.fScoreThreshold = config_["container_step2_model"]["score_threshold"].as<float>();
|
||||
this->modelConfig_containerStep2_.vecClass = config_["container_step2_model"]["class"].as<std::vector<std::string>>();
|
||||
|
||||
// 集装箱箱角模型
|
||||
this->modelConfig_corner_.strModelPath = config_["corner_model"]["model_path"].as<std::string>();
|
||||
this->modelConfig_corner_.fScoreThreshold = config_["corner_model"]["score_threshold"].as<float>();
|
||||
this->modelConfig_corner_.vecClass = config_["corner_model"]["class"].as<std::vector<std::string>>();
|
||||
|
||||
}
|
||||
catch (...) //捕获所有异常
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Config::writeYaml()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::ofstream of(strConfigYamlPath_);
|
||||
of << config_;
|
||||
of.close();
|
||||
}
|
||||
catch (...) //捕获所有异常
|
||||
{
|
||||
printf("yaml文件不存在\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Config::getStringValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
|
||||
{
|
||||
if(nullptr == pConfig)
|
||||
{
|
||||
pConfig = &config_;
|
||||
}
|
||||
if (!(*pConfig)[pszKey].IsDefined())
|
||||
{
|
||||
printf("key:[%s] not exist!\n", pszKey);
|
||||
}
|
||||
return (*pConfig)[pszKey].as<std::string>();
|
||||
}
|
||||
|
||||
int Config::getIntValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
|
||||
{
|
||||
if (nullptr == pConfig)
|
||||
{
|
||||
pConfig = &config_;
|
||||
}
|
||||
if (!(*pConfig)[pszKey].IsDefined())
|
||||
{
|
||||
printf("key:[%s] not exist!\n", pszKey);
|
||||
}
|
||||
return (*pConfig)[pszKey].as<int>();
|
||||
}
|
||||
|
||||
bool Config::getBoolValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
|
||||
{
|
||||
if (nullptr == pConfig)
|
||||
{
|
||||
pConfig = &config_;
|
||||
}
|
||||
if (!(*pConfig)[pszKey].IsDefined())
|
||||
{
|
||||
printf("key:[%s] not exist!\n", pszKey);
|
||||
}
|
||||
return (*pConfig)[pszKey].as<bool>();
|
||||
}
|
||||
|
||||
float Config::getFloatValue(const char *pszKey, const YAML::Node *pConfig/*=nullptr*/) const
|
||||
{
|
||||
if (nullptr == pConfig)
|
||||
{
|
||||
pConfig = &config_;
|
||||
}
|
||||
if (!(*pConfig)[pszKey].IsDefined())
|
||||
{
|
||||
printf("key:[%s] not exist!\n", pszKey);
|
||||
}
|
||||
return (*pConfig)[pszKey].as<float>();
|
||||
}
|
||||
|
||||
std::string Config::getPathValue(const char *pszKey, const YAML::Node *pConfig /*=nullptr*/) const
|
||||
{
|
||||
if (nullptr == pConfig)
|
||||
{
|
||||
pConfig = &config_;
|
||||
}
|
||||
if (!(*pConfig)[pszKey].IsDefined())
|
||||
{
|
||||
printf("key:[%s] not exist!\n", pszKey);
|
||||
}
|
||||
std::string strTmp = (*pConfig)[pszKey].as<std::string>();
|
||||
if (strTmp.back() != '/')
|
||||
{
|
||||
strTmp += "/";
|
||||
}
|
||||
return strTmp;
|
||||
}
|
||||
|
||||
RunConfig Config::getRunConfig() const
|
||||
{
|
||||
return this->runConfig_;
|
||||
}
|
||||
|
||||
void Config::setRunConfig(const ai_matrix::RunConfig runConfig)
|
||||
{
|
||||
this->runConfig_ = runConfig;
|
||||
}
|
||||
|
||||
BaseConfig Config::getBaseConfig() const
|
||||
{
|
||||
return this->baseConfig_;
|
||||
}
|
||||
|
||||
void Config::setBaseConfig(const BaseConfig baseConfig)
|
||||
{
|
||||
this->baseConfig_ = baseConfig;
|
||||
}
|
||||
|
||||
LogConfig Config::getLogConfig() const
|
||||
{
|
||||
return this->logConfig_;
|
||||
}
|
||||
|
||||
void Config::setLogConfig(const LogConfig logConfig)
|
||||
{
|
||||
this->logConfig_ = logConfig;
|
||||
}
|
||||
|
||||
std::vector<DataSourceConfig> Config::getAllDataSourceConfig() const
|
||||
{
|
||||
return this->vecDataSourceConfig_;
|
||||
}
|
||||
|
||||
void Config::setDataSourceConfig(int index, const ai_matrix::DataSourceConfig dataSourceConfig)
|
||||
{
|
||||
if (this->vecDataSourceConfig_.size() <= index) return;
|
||||
this->vecDataSourceConfig_[index] = dataSourceConfig;
|
||||
}
|
||||
|
||||
IdentifyConfig Config::getIdentifyConfig() const
|
||||
{
|
||||
return this->identifyConfig_;
|
||||
}
|
||||
|
||||
void Config::setIdentifyConfig(const ai_matrix::IdentifyConfig identifyConfig)
|
||||
{
|
||||
this->identifyConfig_ = identifyConfig;
|
||||
}
|
||||
|
||||
WSocketConfig Config::getWSocketConfig() const
|
||||
{
|
||||
return this->wSocketConfig_;
|
||||
}
|
||||
|
||||
void Config::setWSocketConfig(const ai_matrix::WSocketConfig wSocketConfig)
|
||||
{
|
||||
this->wSocketConfig_ = wSocketConfig;
|
||||
}
|
||||
|
||||
HttpServerConfig Config::getHttpServerConfig() const
|
||||
{
|
||||
return this->httpServerConfig_;
|
||||
}
|
||||
|
||||
void Config::setHttpServerConfig(const HttpServerConfig httpServerConfig)
|
||||
{
|
||||
this->httpServerConfig_ = httpServerConfig;
|
||||
}
|
||||
|
||||
MinioConfig Config::getMinioConfig() const
|
||||
{
|
||||
return this->minioConfig_;
|
||||
}
|
||||
|
||||
void Config::setMinioConfig(const ai_matrix::MinioConfig minioCConfig)
|
||||
{
|
||||
this->minioConfig_ = minioCConfig;
|
||||
}
|
||||
|
||||
ModelConfig Config::getModelByContainerStep1Config() const
|
||||
{
|
||||
return this->modelConfig_containerStep1_;
|
||||
}
|
||||
|
||||
void Config::setModelByContainerStep1Config(const ai_matrix::ModelConfig modelConfig)
|
||||
{
|
||||
this->modelConfig_containerStep1_ = modelConfig;
|
||||
}
|
||||
|
||||
ModelConfig Config::getModelByContainerStep2Config() const
|
||||
{
|
||||
return this->modelConfig_containerStep2_;
|
||||
}
|
||||
|
||||
void Config::setModelByContainerStep2Config(const ai_matrix::ModelConfig modelConfig)
|
||||
{
|
||||
this->modelConfig_containerStep2_ = modelConfig;
|
||||
}
|
||||
|
||||
ModelConfig Config::getModelByCornerConfig() const
|
||||
{
|
||||
return this->modelConfig_corner_;
|
||||
}
|
||||
|
||||
void Config::setModelByCornerConfig(const ai_matrix::ModelConfig modelConfig)
|
||||
{
|
||||
this->modelConfig_corner_ = modelConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-02-08 15:59:33
|
||||
* @LastEditors: your name
|
||||
* @LastEditTime: 2022-02-16 10:39:05
|
||||
* @Description: file content
|
||||
* @FilePath: \lirs\code\MyYaml\MyYaml.h
|
||||
*
|
||||
* Copyright © 2022 <Shandong Matrix Software Engineering Co., Ltd>
|
||||
*/
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
|
||||
struct RunConfig
|
||||
{
|
||||
// 识别状态
|
||||
bool bRun;
|
||||
|
||||
};
|
||||
|
||||
// 基础控制参数
|
||||
struct BaseConfig
|
||||
{
|
||||
// 股道名称
|
||||
std::string strTrackName;
|
||||
// 测试模式
|
||||
bool bTestModel;
|
||||
// Api 监听端口
|
||||
int iApiPort;
|
||||
// 日志文件目录
|
||||
std::string strLogPath;
|
||||
// 识别结果目录
|
||||
std::string strResultPath;
|
||||
// 调试结果目录
|
||||
std::string strDebugResultPath;
|
||||
// 日志存储天数
|
||||
int iResultSaveDays;
|
||||
};
|
||||
|
||||
// 日志参数
|
||||
struct LogConfig {
|
||||
// 输出日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
|
||||
std::string strOutLevel;
|
||||
// 保存日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
|
||||
std::string strSaveLevel;
|
||||
};
|
||||
|
||||
// 数据源参数
|
||||
struct DataSourceConfig {
|
||||
// 数据源地址
|
||||
std::string strUrl;
|
||||
// 跳帧数
|
||||
int iSkipInterval;
|
||||
// 识别区域
|
||||
std::vector<int> vecIdentifyAreas;
|
||||
};
|
||||
|
||||
// 识别参数
|
||||
struct IdentifyConfig {
|
||||
// 运行方式
|
||||
std::string strRunModel;
|
||||
// 大框帧跨度(比一个大框从出现到消失的跨度稍大一点, 跟跳帧有关系)
|
||||
int iPartitionFrameSpan;
|
||||
// 顶部Y轴大框帧跨度的位置像素差异
|
||||
int iTop_Y_SplitSpanPx;
|
||||
// 侧边X轴大框帧跨度的位置像素差异
|
||||
int iSide_X_SplitSpanPx;
|
||||
// 每帧大框位置差异最小值 (持续小于此值,则可能停车)
|
||||
int iChkstopPx;
|
||||
// 持续X次续位置差异小于gc_chkstop_px,则判断为停车。
|
||||
int iChkstopCount;
|
||||
// 过滤最小大框高度(不需要的话就写个很小的值)
|
||||
int iTargetMinHeight;
|
||||
// 过滤最小大框宽度(不需要的话就写个很小的值)
|
||||
int iTargetMinWidth;
|
||||
// 过滤低于指定Y轴的大框
|
||||
int iTargetMinY;
|
||||
// 单次识别最大帧数
|
||||
int iMaxIdentifyFrame;
|
||||
};
|
||||
|
||||
// websocket_server 的服务端参数
|
||||
struct WSocketConfig {
|
||||
// 是否启用
|
||||
bool bIsUse;
|
||||
// 端口
|
||||
int iPort;
|
||||
// 最大链接队列
|
||||
int iMaxQueueLen;
|
||||
};
|
||||
|
||||
// web服务器参数
|
||||
struct HttpServerConfig
|
||||
{
|
||||
// 使用状态
|
||||
bool bIsUse;
|
||||
// 获取接口授权地址
|
||||
std::string strIp;
|
||||
// 通讯端口
|
||||
int iPort;
|
||||
// 获取接口授权地址
|
||||
std::string strTokenUrl;
|
||||
// 识别结果上传地址
|
||||
std::string strUpResultUrl;
|
||||
// 设备状态上传地址
|
||||
std::string strUpDeviceStatusUrl;
|
||||
// 接口用户名
|
||||
std::string strUserName;
|
||||
// 接口密码
|
||||
std::string strPassword;
|
||||
};
|
||||
|
||||
struct MinioConfig
|
||||
{
|
||||
// 使用状态
|
||||
bool bIsUse;
|
||||
// 服务地址
|
||||
std::string strUrl;
|
||||
// 通讯授权
|
||||
std::string strAccessKey;
|
||||
// 密钥授权
|
||||
std::string strSecretKey;
|
||||
// 容器名
|
||||
std::string strBucket;
|
||||
};
|
||||
|
||||
struct ModelConfig
|
||||
{
|
||||
std::string strModelPath;
|
||||
float fScoreThreshold;
|
||||
std::vector<std::string> vecClass;
|
||||
};
|
||||
|
||||
|
||||
class Config final
|
||||
{
|
||||
public:
|
||||
static Config *getins();
|
||||
|
||||
// 读yaml文件
|
||||
int readYaml(std::string &strPath);
|
||||
int readModelYaml(std::string &strPath);
|
||||
// 写yaml文件
|
||||
int writeYaml();
|
||||
std::string getStringValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
|
||||
int getIntValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
|
||||
bool getBoolValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
|
||||
float getFloatValue(const char *pszKey, const YAML::Node *pConfig = nullptr) const;
|
||||
std::string getPathValue(const char *pszKey, const YAML::Node *pConfig =nullptr) const;
|
||||
|
||||
|
||||
RunConfig getRunConfig() const;
|
||||
void setRunConfig(const RunConfig runConfig);
|
||||
|
||||
// 获取控制参数
|
||||
BaseConfig getBaseConfig() const;
|
||||
void setBaseConfig(const BaseConfig baseConfig);
|
||||
// 获取日志参数
|
||||
LogConfig getLogConfig() const;
|
||||
void setLogConfig(const LogConfig logConfig);
|
||||
// 获取数据源参数
|
||||
std::vector<DataSourceConfig> getAllDataSourceConfig() const;
|
||||
void setDataSourceConfig(int index, const ai_matrix::DataSourceConfig dataSourceConfig);
|
||||
// 获取识别参数
|
||||
IdentifyConfig getIdentifyConfig() const;
|
||||
void setIdentifyConfig(const IdentifyConfig identifyConfig);
|
||||
// 获取websocket server 参数
|
||||
WSocketConfig getWSocketConfig() const;
|
||||
void setWSocketConfig(const WSocketConfig wSocketConfig);
|
||||
// 获取web服务器参数
|
||||
HttpServerConfig getHttpServerConfig() const;
|
||||
void setHttpServerConfig(const HttpServerConfig httpServerConfig);
|
||||
// 获取minio服务器参数
|
||||
MinioConfig getMinioConfig() const;
|
||||
void setMinioConfig(const MinioConfig minioCConfig);
|
||||
// 获取集装箱关键区域检测模型参数
|
||||
ModelConfig getModelByContainerStep1Config() const;
|
||||
void setModelByContainerStep1Config(const ModelConfig modelConfig);
|
||||
// 获取集装箱文字检测模型参数
|
||||
ModelConfig getModelByContainerStep2Config() const;
|
||||
void setModelByContainerStep2Config(const ModelConfig modelConfig);
|
||||
// 获取集装箱文字检测模型参数
|
||||
ModelConfig getModelByCornerConfig() const;
|
||||
void setModelByCornerConfig(const ModelConfig modelConfig);
|
||||
|
||||
|
||||
YAML::Node config_;
|
||||
|
||||
private:
|
||||
Config() = default;
|
||||
Config(const Config &) = delete;
|
||||
Config(Config &&) = delete;
|
||||
Config &operator=(const Config &) = delete;
|
||||
Config &operator=(Config &&) = delete;
|
||||
~Config() = default;
|
||||
|
||||
static Config *pInstance_;
|
||||
static std::mutex mx_; //锁,保证线程安全
|
||||
std::string strConfigYamlPath_;
|
||||
|
||||
// (全局)运行实时变量
|
||||
RunConfig runConfig_;
|
||||
|
||||
// 控制参数
|
||||
BaseConfig baseConfig_;
|
||||
|
||||
// 日志参数
|
||||
LogConfig logConfig_;
|
||||
|
||||
// 数据源列表
|
||||
std::vector<DataSourceConfig> vecDataSourceConfig_;
|
||||
|
||||
// 识别参数
|
||||
IdentifyConfig identifyConfig_;
|
||||
|
||||
// websocket server 服务端参数
|
||||
WSocketConfig wSocketConfig_;
|
||||
|
||||
// web服务器参数
|
||||
HttpServerConfig httpServerConfig_;
|
||||
|
||||
// MinIO服务器参数
|
||||
MinioConfig minioConfig_;
|
||||
|
||||
// 集装箱第一步识别
|
||||
ModelConfig modelConfig_containerStep1_;
|
||||
// 集装箱第二步识别
|
||||
ModelConfig modelConfig_containerStep2_;
|
||||
// 集装箱箱角识别
|
||||
ModelConfig modelConfig_corner_;
|
||||
|
||||
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||||
class GarbageCollector
|
||||
{
|
||||
public:
|
||||
~GarbageCollector()
|
||||
{
|
||||
if (Config::pInstance_)
|
||||
{
|
||||
delete Config::pInstance_;
|
||||
Config::pInstance_ = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
static GarbageCollector gc_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,240 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
FileUtil *FileUtil::ins = nullptr;
|
||||
FileUtil::GarbageCollector FileUtil::gc;
|
||||
std::mutex FileUtil::mx;
|
||||
|
||||
FileUtil *FileUtil::getins()
|
||||
{
|
||||
//双层锁,确保线程安全
|
||||
if (ins == nullptr)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
|
||||
if (ins == nullptr)
|
||||
{
|
||||
ins = new FileUtil();
|
||||
}
|
||||
}
|
||||
return ins;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹路径
|
||||
* inParam : std::string strDirPath :文件夹路径
|
||||
* outParam: N/A
|
||||
* return : true/false
|
||||
*/
|
||||
bool FileUtil::createDirPath(std::string strDirPath)
|
||||
{
|
||||
if (strDirPath.back() != '/')
|
||||
{
|
||||
strDirPath += "/";
|
||||
}
|
||||
|
||||
if (access(strDirPath.c_str(), F_OK) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string::size_type pos = strDirPath.find('/');
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
std::string strCur = strDirPath.substr(0, pos);
|
||||
if (!strCur.empty() && access(strCur.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(strCur.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (chmod(strCur.c_str(), 0777) != 0)
|
||||
{
|
||||
perror("chmod fail");
|
||||
}
|
||||
}
|
||||
pos = strDirPath.find('/', pos + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string FileUtil::create_dir_name(std::string root, std::string name)
|
||||
{
|
||||
std::string dir_path = root + "/" + name;
|
||||
if (access(dir_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return dir_path;
|
||||
}
|
||||
|
||||
std::string FileUtil::create_dir_date(std::string root)
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
char tmp_date[20] = {0};
|
||||
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
|
||||
|
||||
std::string dir_path;
|
||||
|
||||
dir_path = root + "/" + std::string(tmp_date); //创建日期目录
|
||||
if (access(dir_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return dir_path;
|
||||
}
|
||||
|
||||
std::string FileUtil::create_dir_date_name_time(std::string root, std::string name)
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
char tmp_date[20] = {0};
|
||||
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
|
||||
|
||||
char tmp_time[20] = {0};
|
||||
sprintf(tmp_time, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
|
||||
|
||||
std::string dir_path;
|
||||
|
||||
dir_path = root + "/" + std::string(tmp_date); //创建日期目录
|
||||
if (access(dir_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
dir_path = dir_path + "/" + name + "_" + std::string(tmp_time); //创建点云目录
|
||||
if (access(dir_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(dir_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
return dir_path;
|
||||
}
|
||||
|
||||
std::string FileUtil::create_file_path(std::string root, std::string name, std::string suffix)
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
char tmp_date[20] = {0};
|
||||
sprintf(tmp_date, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
|
||||
|
||||
char tmp_time[20] = {0};
|
||||
sprintf(tmp_time, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
|
||||
|
||||
std::string file_path;
|
||||
|
||||
file_path = root + "/" + std::string(tmp_date); //创建日期目录
|
||||
if (access(file_path.c_str(), F_OK) != 0)
|
||||
{
|
||||
if (mkdir(file_path.c_str(), 0755) != 0) //如果父目录不存在,会创建失败
|
||||
{
|
||||
perror("mkdir fail");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
file_path = file_path + "/" + name + "_" + std::string(tmp_time) + suffix; //创建文件
|
||||
|
||||
return file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param filePath 源文件位置
|
||||
* @param savePath 将要拷贝的新位置
|
||||
* @return
|
||||
*/
|
||||
bool FileUtil::copyFile(std::string filePath, std::string savePath) {
|
||||
FILE *fp, *sp;
|
||||
fp = fopen(filePath.c_str(), "rb");
|
||||
sp = fopen(savePath.c_str(), "w+b");
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
void *buffer;
|
||||
while (!feof(fp)) {
|
||||
fread(&buffer, 1, 1, fp);
|
||||
fwrite(&buffer, 1, 1, sp);
|
||||
}
|
||||
fclose(fp);
|
||||
fclose(sp);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取json格式文件内容
|
||||
* inParam : std::string &strFilePath :文件路径
|
||||
* outParam: Json::Value &jvFileInfo :json格式内容
|
||||
* return : true/false
|
||||
*/
|
||||
bool FileUtil::readJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath)
|
||||
{
|
||||
try {
|
||||
std::ifstream ifs(strFilePath.c_str(), std::ios::binary);
|
||||
if (!ifs.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Json::Reader reader;
|
||||
if (!reader.parse(ifs, jvFileInfo))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* json格式内容写入文件
|
||||
* inParam : Json::Value &jvFileInfo :json格式内容
|
||||
: std::string &strFilePath :文件路径
|
||||
* outParam: N/A
|
||||
* return : true/false
|
||||
*/
|
||||
bool FileUtil::writeJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath)
|
||||
{
|
||||
Json::StreamWriterBuilder jswBuilder;
|
||||
// 紧密型存储
|
||||
jswBuilder["indentation"] = "";
|
||||
std::string strFrameInfo = Json::writeString(jswBuilder, jvFileInfo);
|
||||
|
||||
std::ofstream ofs(strFilePath.c_str());
|
||||
if (!ofs.is_open())
|
||||
{
|
||||
// LogWarn << "txt:" << strFilePath << " open fail";
|
||||
return false;
|
||||
}
|
||||
ofs.write(strFrameInfo.c_str(), strFrameInfo.length());
|
||||
ofs.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#ifndef TRAIN_RFID_LINUX_FILEUTIL_H
|
||||
#define TRAIN_RFID_LINUX_FILEUTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "json/json.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
class FileUtil final
|
||||
{
|
||||
public:
|
||||
static FileUtil *getins();
|
||||
|
||||
//创建文件夹
|
||||
std::string create_dir_name(std::string root, std::string name);
|
||||
std::string create_dir_date_name_time(std::string root, std::string name);
|
||||
std::string create_dir_date(std::string root);
|
||||
//创建文件路径
|
||||
std::string create_file_path(std::string root, std::string name, std::string suffix);
|
||||
//创建文件夹路径
|
||||
bool createDirPath(std::string strDirPath);
|
||||
|
||||
/**
|
||||
* 拷贝文件
|
||||
* @param filePath 源文件位置
|
||||
* @param savePath 将要拷贝的新位置
|
||||
* @return
|
||||
*/
|
||||
bool copyFile(std::string filePath, std::string savePath);
|
||||
|
||||
//读取json格式文件内容
|
||||
bool readJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
|
||||
//json格式内容写入文件
|
||||
bool writeJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
|
||||
|
||||
|
||||
private:
|
||||
FileUtil() = default;
|
||||
FileUtil(const FileUtil &) = delete;
|
||||
FileUtil(FileUtil &&) = delete;
|
||||
FileUtil &operator=(const FileUtil &) = delete;
|
||||
FileUtil &operator=(FileUtil &&) = delete;
|
||||
~FileUtil() = default;
|
||||
|
||||
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||||
class GarbageCollector
|
||||
{
|
||||
public:
|
||||
~GarbageCollector()
|
||||
{
|
||||
if (FileUtil::ins)
|
||||
{
|
||||
delete FileUtil::ins;
|
||||
FileUtil::ins = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GarbageCollector gc;
|
||||
static FileUtil *ins;
|
||||
static std::mutex mx; //锁,保证线程安全
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //TRAIN_RFID_LINUX_FILEUTIL_H
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#include "StringUtil.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
StringUtil *StringUtil::ins = nullptr;
|
||||
StringUtil::GarbageCollector StringUtil::gc;
|
||||
std::mutex StringUtil::mx;
|
||||
|
||||
StringUtil *StringUtil::getins()
|
||||
{
|
||||
//双层锁,确保线程安全
|
||||
if (ins == nullptr)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
|
||||
if (ins == nullptr)
|
||||
{
|
||||
ins = new StringUtil();
|
||||
}
|
||||
}
|
||||
return ins;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串分割函数
|
||||
* @param str 目标字符串
|
||||
* @param pattern 切割字符
|
||||
* @return vector<std::string>
|
||||
*/
|
||||
std::vector<std::string> StringUtil::split(std::string str, std::string pattern)
|
||||
{
|
||||
std::string::size_type pos;
|
||||
std::vector<std::string> result;
|
||||
str += pattern; //扩展字符串以方便操作
|
||||
int size = str.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
pos = str.find(pattern, i);
|
||||
if (pos < size)
|
||||
{
|
||||
std::string s = str.substr(i, pos - i);
|
||||
result.push_back(s);
|
||||
i = pos + pattern.size() - 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉字符串前后空格
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
std::string StringUtil::trim(const std::string& str) {
|
||||
std::string temp = str;
|
||||
temp.erase(0, temp.find_first_not_of(" \t\n\r\f\v")); // 去除开头的空格
|
||||
temp.erase(temp.find_last_not_of(" \t\n\r\f\v") + 1); // 去除末尾的空格
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换字符串中所有指定字符
|
||||
* @param str 目标字符串
|
||||
* @param old_value 原值
|
||||
* @param new_value 新值
|
||||
* @return 新结果
|
||||
*/
|
||||
std::string StringUtil::replace_all_distinct(std::string str, const std::string old_value, const std::string new_value)
|
||||
{
|
||||
for (std::string::size_type pos(0); pos != std::string::npos; pos += new_value.length()) {
|
||||
if ((pos = str.find(old_value, pos)) != std::string::npos)
|
||||
str.replace(pos, old_value.length(), new_value);
|
||||
else break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anchor行分割
|
||||
* inParam : std::string &strLine Anchor一行内容
|
||||
* : const std::set<char> &setDelimiters 分割符集合
|
||||
* outParam: N/A
|
||||
* return : 分割数据
|
||||
*/
|
||||
std::vector<float> StringUtil::SplitAnchor(std::string &strLine, const std::set<char> &setDelimiters)
|
||||
{
|
||||
std::vector<float> result;
|
||||
if (strLine.empty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
char const *pch = strLine.c_str();
|
||||
char const *start = pch;
|
||||
for (; *pch; ++pch)
|
||||
{
|
||||
if (setDelimiters.find(*pch) != setDelimiters.end())
|
||||
{
|
||||
if (start != pch)
|
||||
{
|
||||
std::string tmp(start, pch);
|
||||
result.push_back(atof(tmp.c_str())); //浮点数
|
||||
}
|
||||
start = pch + 1;
|
||||
}
|
||||
}
|
||||
result.push_back(atof(start)); //最后一个内容
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* float 转 string
|
||||
* @param f
|
||||
* @return
|
||||
*/
|
||||
std::string StringUtil::getStringFromFloat(float f)
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
buffer << f;
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* bool 转 string
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
std::string StringUtil::getStringFromBool(bool b)
|
||||
{
|
||||
std::ostringstream buffer;
|
||||
buffer << b;
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* string 转 int
|
||||
* (会过滤字符串前后的空格)
|
||||
* @param s
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
int StringUtil::string2int(const std::string s, bool &b) {
|
||||
try {
|
||||
b = true;
|
||||
return std::stoi(this->trim(s));
|
||||
} catch (...) {
|
||||
b = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串中是否存在 字母和数字 之外的字符
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
bool StringUtil::containsNonAlphaNum(const std::string &str) {
|
||||
for (char c : str) {
|
||||
if (!std::isalnum(c) && !std::isspace(c)) { // 如果不是字母或数字
|
||||
return true; // 返回true,表示存在非字母数字字符
|
||||
}
|
||||
}
|
||||
return false; // 遍历完成未发现非字母数字字符,返回false
|
||||
}
|
||||
|
||||
bool StringUtil::is_digits(const std::string &str) {
|
||||
return all_of(str.begin(), str.end(), ::isdigit);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#ifndef TRAIN_RFID_LINUX_STRINGUTIL_H
|
||||
#define TRAIN_RFID_LINUX_STRINGUTIL_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
class StringUtil final
|
||||
{
|
||||
public:
|
||||
static StringUtil *getins();
|
||||
|
||||
// 字符串分割函数
|
||||
std::vector<std::string> split(std::string str, std::string pattern);
|
||||
// 去掉字符串前后的空格
|
||||
std::string trim(const std::string& str);
|
||||
|
||||
// 替换string中所有指定字符串
|
||||
std::string replace_all_distinct(std::string str, const std::string old_value, const std::string new_value);
|
||||
//
|
||||
std::vector<float> SplitAnchor(std::string &strLine, const std::set<char> &setDelimiters);
|
||||
|
||||
// float 转 string
|
||||
std::string getStringFromFloat(float f);
|
||||
// bool 转 string
|
||||
std::string getStringFromBool(bool b);
|
||||
// string 转 int
|
||||
int string2int(const std::string s, bool &b);
|
||||
|
||||
// 判断字符串中是否含有 字母和数字 之外的字符
|
||||
bool containsNonAlphaNum(const std::string &str);
|
||||
// 判断字符串中是否仅含有数字
|
||||
// 检查函数
|
||||
bool is_digits(const std::string& str);
|
||||
|
||||
private:
|
||||
StringUtil() = default;
|
||||
StringUtil(const StringUtil &) = delete;
|
||||
StringUtil(StringUtil &&) = delete;
|
||||
StringUtil &operator=(const StringUtil &) = delete;
|
||||
StringUtil &operator=(StringUtil &&) = delete;
|
||||
~StringUtil() = default;
|
||||
|
||||
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||||
class GarbageCollector
|
||||
{
|
||||
public:
|
||||
~GarbageCollector()
|
||||
{
|
||||
if (StringUtil::ins)
|
||||
{
|
||||
delete StringUtil::ins;
|
||||
StringUtil::ins = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GarbageCollector gc;
|
||||
static StringUtil *ins;
|
||||
static std::mutex mx; //锁,保证线程安全
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //TRAIN_RFID_LINUX_STRINGUTIL_H
|
||||
|
|
@ -0,0 +1,227 @@
|
|||
#include <cstring>
|
||||
#include "TimeUtil.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
const int TIME_DIFF = 28800; // 8 hour
|
||||
TimeUtil *TimeUtil::ins = nullptr;
|
||||
TimeUtil::GarbageCollector TimeUtil::gc;
|
||||
std::mutex TimeUtil::mx;
|
||||
|
||||
TimeUtil *TimeUtil::getins()
|
||||
{
|
||||
//双层锁,确保线程安全
|
||||
if (ins == nullptr)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
|
||||
if (ins == nullptr)
|
||||
{
|
||||
ins = new TimeUtil();
|
||||
}
|
||||
}
|
||||
return ins;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用于文件命名的时间戳
|
||||
* @return
|
||||
*/
|
||||
std::string TimeUtil::get_timestamp_file()
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
int msec = tv.tv_usec / 1000;
|
||||
|
||||
char tmp[30] = {0};
|
||||
sprintf(tmp, "%04d-%02d-%02d-%02d-%02d-%02d-%03d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, msec);
|
||||
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用用于日志记录的时间
|
||||
* @return yyyy-MM-dd hh:mm:ss.us
|
||||
*/
|
||||
std::string TimeUtil::getDateTime_usec()
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
int msec = tv.tv_usec / 1000;
|
||||
|
||||
char tmp[30] = {0};
|
||||
sprintf(tmp, "%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, msec);
|
||||
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取北京当前日期
|
||||
* @return : 日期 yyyy-mm-dd
|
||||
*/
|
||||
std::string TimeUtil::getDate()
|
||||
{
|
||||
struct timeval time = {0, 0};
|
||||
gettimeofday(&time, nullptr);
|
||||
time_t timep = time.tv_sec + TIME_DIFF;
|
||||
|
||||
struct tm *p = gmtime(&timep);
|
||||
|
||||
char szTmp[12] = {0};
|
||||
sprintf(szTmp, "%04d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
|
||||
|
||||
return std::string(szTmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取北京当前时间
|
||||
* @return : 时间 hh:mm:ss
|
||||
*/
|
||||
std::string TimeUtil::getTime()
|
||||
{
|
||||
struct timeval time = {0, 0};
|
||||
gettimeofday(&time, nullptr);
|
||||
time_t timep = time.tv_sec + TIME_DIFF;
|
||||
|
||||
struct tm *p = gmtime(&timep);
|
||||
|
||||
char szTmp[10] = {0};
|
||||
sprintf(szTmp, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec);
|
||||
return std::string(szTmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前 日期+时间
|
||||
* @return yyyy-MM-dd hh:mm:ss
|
||||
*/
|
||||
std::string TimeUtil::getDateTime()
|
||||
{
|
||||
struct timeval time = {0, 0};
|
||||
gettimeofday(&time, nullptr);
|
||||
time_t timep = time.tv_sec + TIME_DIFF;
|
||||
|
||||
struct tm *p = gmtime(&timep);
|
||||
int msec = time.tv_usec / 1000;
|
||||
|
||||
char szTmp[32] = {0};
|
||||
sprintf(szTmp, "%04d-%02d-%02d %02d:%02d:%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
|
||||
|
||||
return std::string(szTmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用于文件名的时间
|
||||
* @return hh-mm-ss
|
||||
*/
|
||||
std::string TimeUtil::getTime_file()
|
||||
{
|
||||
time_t timep = time(NULL);
|
||||
struct tm *p = localtime(&timep);
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
int msec = tv.tv_usec / 1000;
|
||||
|
||||
char tmp[10] = { 0 };
|
||||
sprintf(tmp, "%02d-%02d-%02d", p->tm_hour, p->tm_min, p->tm_sec);
|
||||
|
||||
return std::string(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* inParam : N/A
|
||||
* outParam: N/A
|
||||
* return : 时间戳
|
||||
*/
|
||||
/**
|
||||
* 获取当前时间距1970年的秒数(可选毫秒数)
|
||||
* @param usec 是否取毫秒数
|
||||
* @return
|
||||
*/
|
||||
uint64_t TimeUtil::getCurrentTimeMillis(bool usec)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
if (usec)
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
else
|
||||
return tv.tv_sec;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间距1970年的秒数 (入参格式:YYYY-MM-DD hh-mm-ss)
|
||||
* inParam : std::string &strDateTime 日期时间
|
||||
* outParam: N/A
|
||||
* return : 时间戳
|
||||
*/
|
||||
uint64_t TimeUtil::getParamTimeMilliSeconds(std::string &strDateTime)
|
||||
{
|
||||
// LogDebug << "strDateTime:" << strDateTime;
|
||||
if (strDateTime.length() != 19)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iYear = atoi(strDateTime.substr(0, 4).c_str());
|
||||
int iMon = atoi(strDateTime.substr(5, 2).c_str());
|
||||
int iDay = atoi(strDateTime.substr(8, 2).c_str());
|
||||
int iHour = atoi(strDateTime.substr(11, 2).c_str());
|
||||
int iMin = atoi(strDateTime.substr(14, 2).c_str());
|
||||
int iSec = atoi(strDateTime.substr(17, 2).c_str());
|
||||
|
||||
struct tm stm;
|
||||
memset(&stm, 0, sizeof(stm));
|
||||
stm.tm_year = iYear - 1900;
|
||||
stm.tm_mon = iMon - 1;
|
||||
stm.tm_mday = iDay;
|
||||
stm.tm_hour = iHour;
|
||||
stm.tm_min = iMin;
|
||||
stm.tm_sec = iSec;
|
||||
|
||||
uint64_t i64Ret = (uint64_t)mktime(&stm) * 1000;
|
||||
return i64Ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定毫秒数的对应的北京日期时间
|
||||
* inParam : uint64_t i64MilliSeconds
|
||||
* outParam: N/A
|
||||
* return : 日期时间
|
||||
*/
|
||||
std::string TimeUtil::getDateTimeByMilliSeconds(uint64_t i64MilliSeconds)
|
||||
{
|
||||
time_t timep = i64MilliSeconds / 1000 + TIME_DIFF;
|
||||
struct tm *p = gmtime(&timep);
|
||||
|
||||
char szTmp[32] = {0};
|
||||
sprintf(szTmp, "%04d-%02d-%02d %02d-%02d-%02d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
|
||||
|
||||
return std::string(szTmp);
|
||||
}
|
||||
|
||||
//时间戳转化为时间 毫秒级
|
||||
std::string TimeUtil::Stamp2Time(long long timestamp, bool has_msec)
|
||||
{
|
||||
int ms = timestamp % 1000;//取毫秒
|
||||
time_t tick = (time_t)(timestamp/1000);//转换时间
|
||||
struct tm tm;
|
||||
char s[40];
|
||||
tm = *localtime(&tick);
|
||||
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", &tm);
|
||||
std::string str(s);
|
||||
if (has_msec)
|
||||
{
|
||||
str = str+ "." + std::to_string(ms);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef TimeUtil_H_
|
||||
#define TimeUtil_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
class TimeUtil final
|
||||
{
|
||||
public:
|
||||
static TimeUtil *getins();
|
||||
|
||||
//获取时间戳
|
||||
std::string get_timestamp_file();
|
||||
std::string getDateTime_usec();
|
||||
//获取日期
|
||||
// std::string get_date();
|
||||
//获取北京当前日期
|
||||
std::string getDate();
|
||||
//获取北京当前时间
|
||||
std::string getTime();
|
||||
// 获取当前 日期 时间
|
||||
std::string getDateTime();
|
||||
//获取用于文件名的时间
|
||||
std::string getTime_file();
|
||||
//获取当前时间距1970年的毫秒数
|
||||
uint64_t getCurrentTimeMillis(bool usec = false);
|
||||
//获取指定时间距1970年的毫秒数 (入参格式:YYYY-MM-DD hh-mm-ss)
|
||||
uint64_t getParamTimeMilliSeconds(std::string &strDateTime);
|
||||
//获取指定毫秒数的对应的日期时间
|
||||
std::string getDateTimeByMilliSeconds(uint64_t i64MilliSeconds);
|
||||
//时间戳转化为时间 毫秒级
|
||||
std::string Stamp2Time(long long timestamp, bool has_msec = false);
|
||||
|
||||
|
||||
private:
|
||||
TimeUtil() = default;
|
||||
TimeUtil(const TimeUtil &) = delete;
|
||||
TimeUtil(TimeUtil &&) = delete;
|
||||
TimeUtil &operator=(const TimeUtil &) = delete;
|
||||
TimeUtil &operator=(TimeUtil &&) = delete;
|
||||
~TimeUtil() = default;
|
||||
|
||||
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||||
class GarbageCollector
|
||||
{
|
||||
public:
|
||||
~GarbageCollector()
|
||||
{
|
||||
if (TimeUtil::ins)
|
||||
{
|
||||
delete TimeUtil::ins;
|
||||
TimeUtil::ins = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GarbageCollector gc;
|
||||
static TimeUtil *ins;
|
||||
static std::mutex mx; //锁,保证线程安全
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
Utils *Utils::ins = nullptr;
|
||||
Utils::GarbageCollector Utils::gc;
|
||||
std::mutex Utils::mx;
|
||||
|
||||
Utils *Utils::getins()
|
||||
{
|
||||
//双层锁,确保线程安全
|
||||
if (ins == nullptr)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(mx); //防止异常发生不能解锁
|
||||
if (ins == nullptr)
|
||||
{
|
||||
ins = new Utils();
|
||||
}
|
||||
}
|
||||
return ins;
|
||||
}
|
||||
|
||||
float Utils::getMean(const std::vector<float> &data)
|
||||
{
|
||||
int size = data.size();
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float sum = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
sum += data[i];
|
||||
}
|
||||
return sum / size;
|
||||
}
|
||||
|
||||
float Utils::getMax(const std::vector<float> &data)
|
||||
{
|
||||
int size = data.size();
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float max = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
max = data[i];
|
||||
}
|
||||
else if (data[i] > max)
|
||||
{
|
||||
max = data[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
float Utils::getMin(const std::vector<float> &data)
|
||||
{
|
||||
int size = data.size();
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float min = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
min = data[i];
|
||||
}
|
||||
else if (data[i] < min)
|
||||
{
|
||||
min = data[i];
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
float Utils::getMedian(const std::vector<float> &data)
|
||||
{
|
||||
if (data.size() < 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<float> data_tmp;
|
||||
|
||||
int n = data.size();
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
data_tmp.push_back(data[i]);
|
||||
}
|
||||
|
||||
std::sort(data_tmp.begin(), data_tmp.end(), std::less<float>());
|
||||
|
||||
if (n % 2 == 0)
|
||||
{
|
||||
return (data_tmp[n / 2] + data_tmp[n / 2 - 1]) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return data_tmp[(n - 1) / 2];
|
||||
}
|
||||
}
|
||||
|
||||
bool Utils::contains_vec(const std::vector<std::string> &vec, std::string x) {
|
||||
return count(vec.begin(), vec.end(), x) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// Created by matrixai on 4/2/24.
|
||||
//
|
||||
|
||||
#ifndef TRAIN_RFID_LINUX_UTILS_H
|
||||
#define TRAIN_RFID_LINUX_UTILS_H
|
||||
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <dirent.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
class Utils final
|
||||
{
|
||||
public:
|
||||
static Utils *getins();
|
||||
|
||||
//计算均值
|
||||
float getMean(const std::vector<float> &data);
|
||||
//计算最大值
|
||||
float getMax(const std::vector<float> &data);
|
||||
//计算最小值
|
||||
float getMin(const std::vector<float> &data);
|
||||
//计算中位数
|
||||
float getMedian(const std::vector<float> &data);
|
||||
|
||||
bool contains_vec(const std::vector<std::string> &vec, std::string x);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Utils() = default;
|
||||
Utils(const Utils &) = delete;
|
||||
Utils(Utils &&) = delete;
|
||||
Utils &operator=(const Utils &) = delete;
|
||||
Utils &operator=(Utils &&) = delete;
|
||||
~Utils() = default;
|
||||
|
||||
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||||
class GarbageCollector
|
||||
{
|
||||
public:
|
||||
~GarbageCollector()
|
||||
{
|
||||
if (Utils::ins)
|
||||
{
|
||||
delete Utils::ins;
|
||||
Utils::ins = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static GarbageCollector gc;
|
||||
static Utils *ins;
|
||||
static std::mutex mx; //锁,保证线程安全
|
||||
};
|
||||
}
|
||||
|
||||
#endif //TRAIN_RFID_LINUX_UTILS_H
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
#include "EngineBase.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
//初始化engine
|
||||
void EngineBase::AssignInitArgs(const EngineInitArguments &initArgs)
|
||||
{
|
||||
deviceId_ = initArgs.deviceId;
|
||||
|
||||
engineName_ = initArgs.engineName;
|
||||
engineId_ = initArgs.engineId;
|
||||
}
|
||||
|
||||
// get the data from input queue then call Process function in the new thread
|
||||
void EngineBase::ProcessThread()
|
||||
{
|
||||
Process();
|
||||
}
|
||||
|
||||
//设置engine输入队列
|
||||
void EngineBase::SetInputMap(std::string engineAddress, std::shared_ptr<MyQueue<std::shared_ptr<void>>> inputQueue)
|
||||
{
|
||||
inputQueMap_[engineAddress] = inputQueue;
|
||||
}
|
||||
//得到输入队列
|
||||
std::shared_ptr<MyQueue<std::shared_ptr<void>>> EngineBase::GetInputMap(std::string engineAddress)
|
||||
{
|
||||
if (inputQueMap_.find(engineAddress) == inputQueMap_.end())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return inputQueMap_.at(engineAddress);
|
||||
}
|
||||
|
||||
//设置engine输出队列
|
||||
void EngineBase::SetOutputMap(std::string engineAddress, std::shared_ptr<MyQueue<std::shared_ptr<void>>> outputQue)
|
||||
{
|
||||
outputQueMap_[engineAddress] = outputQue;
|
||||
}
|
||||
|
||||
//启动engine
|
||||
APP_ERROR EngineBase::Run()
|
||||
{
|
||||
LogInfo << engineName_ << "[" << engineId_ << "] Run";
|
||||
isStop_ = false;
|
||||
processThr_ = std::thread(&EngineBase::ProcessThread, this);
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
// 停止engine
|
||||
APP_ERROR EngineBase::Stop()
|
||||
{
|
||||
//停止线程
|
||||
isStop_ = true;
|
||||
|
||||
//停止所有输入队列
|
||||
for (auto it = inputQueMap_.begin(); it != inputQueMap_.end(); it++)
|
||||
{
|
||||
it->second->stop();
|
||||
}
|
||||
|
||||
//等待线程结束
|
||||
if (processThr_.joinable())
|
||||
{
|
||||
processThr_.join();
|
||||
}
|
||||
|
||||
//其他清理
|
||||
return DeInit();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* engine基类
|
||||
*/
|
||||
|
||||
#ifndef INC_ENGINE_BASE_H
|
||||
#define INC_ENGINE_BASE_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <atomic>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ErrorCode.h"
|
||||
#include "Log.h"
|
||||
#include "FileManager.h"
|
||||
#include "CommonDataType.h"
|
||||
|
||||
#include "myqueue.h"
|
||||
#include "myshell.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
struct EngineInitArguments
|
||||
{
|
||||
int32_t deviceId = 0;
|
||||
|
||||
std::string engineName = {};
|
||||
int engineId = -1;
|
||||
void *userData = nullptr;
|
||||
};
|
||||
|
||||
class EngineBase
|
||||
{
|
||||
public:
|
||||
EngineBase() {}
|
||||
virtual ~EngineBase() {} //必须是虚函数
|
||||
|
||||
void AssignInitArgs(const EngineInitArguments &initArgs);
|
||||
|
||||
//每个engine自己实现
|
||||
virtual APP_ERROR Init(void) = 0;
|
||||
virtual APP_ERROR DeInit(void) = 0;
|
||||
|
||||
APP_ERROR Run(void);
|
||||
APP_ERROR Stop(void);
|
||||
|
||||
//设置输入队列
|
||||
void SetInputMap(std::string engineAddress, std::shared_ptr<MyQueue<std::shared_ptr<void>>> inputQueue);
|
||||
//得到输入队列
|
||||
std::shared_ptr<MyQueue<std::shared_ptr<void>>> GetInputMap(std::string engineAddress);
|
||||
|
||||
//设置输出队列
|
||||
void SetOutputMap(std::string engineAddress, std::shared_ptr<MyQueue<std::shared_ptr<void>>> outputQue);
|
||||
|
||||
//线程函数
|
||||
void ProcessThread();
|
||||
|
||||
//每个engine自己实现线程执行函数
|
||||
virtual APP_ERROR Process() = 0;
|
||||
|
||||
protected:
|
||||
std::atomic_bool isStop_ = {true}; //线程默认不启动
|
||||
|
||||
int32_t deviceId_ = -1;
|
||||
|
||||
//输入队列map
|
||||
std::map<std::string, std::shared_ptr<MyQueue<std::shared_ptr<void>>>> inputQueMap_ = {};
|
||||
//输出队列map
|
||||
std::map<std::string, std::shared_ptr<MyQueue<std::shared_ptr<void>>>> outputQueMap_ = {};
|
||||
|
||||
int engineId_ = -1; //实例化id
|
||||
std::string engineName_ = {}; //类名
|
||||
|
||||
std::thread processThr_ = {};
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* c++类反射
|
||||
*/
|
||||
|
||||
#ifndef INC_ENGINE_FACTORY_H
|
||||
#define INC_ENGINE_FACTORY_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
//引擎注册宏
|
||||
#define ENGINE_REGIST(class_name) \
|
||||
namespace ai_matrix \
|
||||
{ \
|
||||
class class_name##Helper \
|
||||
{ \
|
||||
public: \
|
||||
class_name##Helper() \
|
||||
{ \
|
||||
EngineFactory::RegisterEngine(#class_name, class_name##Helper::CreatObjFunc); \
|
||||
} \
|
||||
static void *CreatObjFunc() \
|
||||
{ \
|
||||
return new class_name; \
|
||||
} \
|
||||
}; \
|
||||
static class_name##Helper class_name##helper; \
|
||||
}
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
using Constructor = std::function<void *()>;
|
||||
|
||||
class EngineFactory
|
||||
{
|
||||
public:
|
||||
static void RegisterEngine(std::string className, Constructor constructor)
|
||||
{
|
||||
Constructors()[className] = constructor;
|
||||
}
|
||||
|
||||
static void *MakeEngine(const std::string &className)
|
||||
{
|
||||
auto itr = Constructors().find(className);
|
||||
if (itr == Constructors().end())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return ((Constructor)itr->second)();
|
||||
}
|
||||
|
||||
private:
|
||||
inline static std::map<std::string, Constructor> &Constructors()
|
||||
{
|
||||
static std::map<std::string, Constructor> instance;
|
||||
return instance;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
/**
|
||||
* engine管理实现
|
||||
* */
|
||||
|
||||
#include "EngineManager.h"
|
||||
#include "Config.h"
|
||||
#include "TimeUtil.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
EngineManager::EngineManager() {}
|
||||
|
||||
EngineManager::~EngineManager() {}
|
||||
|
||||
//初始化acl
|
||||
APP_ERROR EngineManager::Init()
|
||||
{
|
||||
if (!InitDeviceIds())
|
||||
{
|
||||
LogError << "InitDeviceIds err";
|
||||
return APP_ERR_COMM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
//去初始化acl
|
||||
APP_ERROR EngineManager::DeInit(void)
|
||||
{
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
//加载yaml文件中的配置
|
||||
APP_ERROR EngineManager::load_yaml_config(std::string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadFile(path);
|
||||
//退出程序
|
||||
if (config.IsNull())
|
||||
{
|
||||
LogError << "matrix.yaml err";
|
||||
return APP_ERR_COMM_INVALID_PARAM;
|
||||
}
|
||||
|
||||
//engine使用deviceid
|
||||
mapUseDevice_["ALL"] = *init_deviceIds_.begin(); //默认所有engine使用初始化中最小deviceid
|
||||
if(config["use_deviceid"].IsDefined())
|
||||
{
|
||||
for (YAML::const_iterator it = config["use_deviceid"].begin(); it != config["use_deviceid"].end(); it++)
|
||||
{
|
||||
std::string engineInfo = it->first.as<std::string>();
|
||||
int deviceid = it->second.as<int>();
|
||||
//使用deviceid必须是经过初始化的
|
||||
if (init_deviceIds_.count(deviceid) == 0)
|
||||
{
|
||||
LogError << "use_deviceid set err value:" << deviceid;
|
||||
return APP_ERR_COMM_INVALID_PARAM;
|
||||
}
|
||||
mapUseDevice_[engineInfo] = deviceid;
|
||||
}
|
||||
}
|
||||
|
||||
//engine实例
|
||||
for (YAML::const_iterator it = config["engines"].begin(); it != config["engines"].end(); it++)
|
||||
{
|
||||
std::string engine_name = it->first.as<std::string>();
|
||||
int engine_id = it->second.as<int>();
|
||||
|
||||
//检查是否有重复engine
|
||||
std::string engine_unique = engine_name + "_" + std::to_string(engine_id);
|
||||
auto iter = engine_map_.find(engine_unique);
|
||||
if (iter != engine_map_.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//实例化engine
|
||||
std::shared_ptr<EngineBase> engineInstance = nullptr;
|
||||
EngineBase* base = (static_cast<EngineBase*>(EngineFactory::MakeEngine(engine_name)));
|
||||
if (base == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
engineInstance.reset(base);
|
||||
|
||||
//初始化engine
|
||||
APP_ERROR ret = InitEngineInstance(engineInstance, engine_name, engine_id);
|
||||
if (ret != APP_ERR_OK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//存入map
|
||||
engine_map_[engine_unique] = engineInstance;
|
||||
}
|
||||
|
||||
//engine连接
|
||||
for (YAML::const_iterator it = config["connects"].begin(); it != config["connects"].end(); it++)
|
||||
{
|
||||
std::string from = it->first.as<std::string>();
|
||||
std::string to = it->second.as<std::string>();
|
||||
|
||||
int iPos = to.find(" ");
|
||||
int iQueueSize = 0;
|
||||
if (iPos != std::string::npos)
|
||||
{
|
||||
iQueueSize = atoi(to.substr(iPos+1, to.length()).c_str());
|
||||
to = to.substr(0, iPos);
|
||||
// LogInfo << "iQueueSize:" << iQueueSize;
|
||||
}
|
||||
|
||||
LogInfo << "Add Connect,send:" << from << ",to:" << to;
|
||||
|
||||
std::size_t pos = from.find_last_of("_");
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::string src_engine = from.substr(0, pos);
|
||||
|
||||
pos = to.find_last_of("_");
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::string dst_engine = to.substr(0, pos);
|
||||
|
||||
auto iterSend = engine_map_.find(src_engine);
|
||||
auto iterRecv = engine_map_.find(dst_engine);
|
||||
|
||||
if (iterSend == engine_map_.end() || iterRecv == engine_map_.end())
|
||||
{
|
||||
LogError << "Cann't find engine " << src_engine << " or " << dst_engine;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::shared_ptr<MyQueue<std::shared_ptr<void>>> dataQueue = iterRecv->second->GetInputMap(to);
|
||||
if (dataQueue == nullptr)
|
||||
{
|
||||
dataQueue = std::make_shared<MyQueue<std::shared_ptr<void>>>();
|
||||
if (iQueueSize > 0)
|
||||
{
|
||||
dataQueue->setMaxSize(iQueueSize);
|
||||
}
|
||||
|
||||
//设置engine输入队列
|
||||
iterRecv->second->SetInputMap(to, dataQueue);
|
||||
|
||||
//设置engine输出队列
|
||||
iterSend->second->SetOutputMap(from, dataQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
//设置engine输出队列
|
||||
iterSend->second->SetOutputMap(from, dataQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...) //捕获所有异常
|
||||
{
|
||||
return APP_ERR_COMM_INVALID_PARAM;
|
||||
}
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
//初始化engine实例
|
||||
APP_ERROR EngineManager::InitEngineInstance(std::shared_ptr<EngineBase> engineInstance, std::string engineName, int engineId)
|
||||
{
|
||||
LogInfo << "EngineManager: begin to init engine instance,name=" << engineName << ", engine id = " << engineId << ".";
|
||||
|
||||
//获取egnine使用的上下文
|
||||
std::string engineInfo = engineName + "_" + std::to_string(engineId);
|
||||
int deviceid;
|
||||
if(mapUseDevice_.count(engineInfo) > 0)
|
||||
{
|
||||
deviceid = mapUseDevice_[engineInfo];
|
||||
}
|
||||
else if(mapUseDevice_.count(std::to_string(engineId)) > 0)
|
||||
{
|
||||
deviceid = mapUseDevice_[std::to_string(engineId)];
|
||||
}
|
||||
else
|
||||
{
|
||||
deviceid = mapUseDevice_["ALL"];
|
||||
}
|
||||
|
||||
EngineInitArguments initArgs;
|
||||
initArgs.deviceId = deviceId_;
|
||||
initArgs.engineName = engineName;
|
||||
initArgs.engineId = engineId;
|
||||
|
||||
engineInstance->AssignInitArgs(initArgs); //填充参数
|
||||
|
||||
APP_ERROR ret = engineInstance->Init(); //执行初始化
|
||||
if (ret != APP_ERR_OK)
|
||||
{
|
||||
LogError << "EngineManager: fail to init engine, name = " << engineName << ", engine id = " << engineId << ".";
|
||||
return ret;
|
||||
}
|
||||
LogInfo << "EngineManager: engine " << engineName << "[" << engineId << "] init success.";
|
||||
return ret;
|
||||
}
|
||||
|
||||
//运行所有engine
|
||||
APP_ERROR EngineManager::RunAllEngine()
|
||||
{
|
||||
LogInfo << "begin to run engine.";
|
||||
for (auto it = engine_map_.begin(); it != engine_map_.end(); it++)
|
||||
{
|
||||
it->second->Run();
|
||||
}
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
//停止所有engine
|
||||
APP_ERROR EngineManager::StopAllEngine()
|
||||
{
|
||||
LogInfo << "begin to stop engine.";
|
||||
for (auto it = engine_map_.begin(); it != engine_map_.end(); it++)
|
||||
{
|
||||
it->second->Stop();
|
||||
}
|
||||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
//得到engine指针
|
||||
EngineBase *EngineManager::get_engine(std::string engineName)
|
||||
{
|
||||
auto iter = engine_map_.find(engineName);
|
||||
if (iter == engine_map_.end())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化设备id
|
||||
* inParam : N/A
|
||||
* outParam: N/A
|
||||
* return : true(成功);false(失败)
|
||||
*/
|
||||
bool EngineManager::InitDeviceIds()
|
||||
{
|
||||
init_deviceIds_.insert(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* engine管理类
|
||||
*/
|
||||
|
||||
#ifndef INC_ENGINE_MANAGER_H
|
||||
#define INC_ENGINE_MANAGER_H
|
||||
|
||||
#include "EngineBase.h"
|
||||
#include "EngineFactory.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
//引擎描述
|
||||
struct EngineDesc
|
||||
{
|
||||
std::string engine_name; //引擎名称
|
||||
int engine_id; //引擎id
|
||||
};
|
||||
|
||||
struct EngineConnectDesc
|
||||
{
|
||||
std::string engine_send_name; //发送引擎名称
|
||||
int engine_send_id; //发送引擎id
|
||||
int engine_send_port; //发送引擎端口
|
||||
std::string engine_recv_name; //接收引擎名称
|
||||
int engine_recv_id; //接收引擎id
|
||||
int engine_recv_port; //接收引擎端口
|
||||
};
|
||||
|
||||
class EngineManager
|
||||
{
|
||||
public:
|
||||
EngineManager();
|
||||
~EngineManager();
|
||||
|
||||
//初始化
|
||||
APP_ERROR Init();
|
||||
//去初始化
|
||||
APP_ERROR DeInit(void);
|
||||
|
||||
//使用yaml文件注册engine实例及连接
|
||||
APP_ERROR load_yaml_config(std::string path);
|
||||
|
||||
//初始化engine
|
||||
APP_ERROR InitEngineInstance(std::shared_ptr<EngineBase> engineInstance, std::string engineName, int engineId);
|
||||
|
||||
//运行所有engine
|
||||
APP_ERROR RunAllEngine();
|
||||
|
||||
//停止所有engine
|
||||
APP_ERROR StopAllEngine();
|
||||
|
||||
//得到某个engine的指针
|
||||
EngineBase *get_engine(std::string engineName);
|
||||
|
||||
private:
|
||||
int32_t deviceId_ = 0;
|
||||
|
||||
//engine名和实例map
|
||||
std::map<std::string, std::shared_ptr<EngineBase>> engine_map_ = {};
|
||||
|
||||
//初始化的设备id
|
||||
std::set<int> init_deviceIds_ = {};
|
||||
|
||||
//engine使用deviceid
|
||||
std::map<std::string, int> mapUseDevice_ = {};
|
||||
|
||||
//初始化设备id
|
||||
bool InitDeviceIds();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,989 @@
|
|||
/**
|
||||
某个engine需要多个输入时使用
|
||||
*/
|
||||
|
||||
#ifndef INC_HIAIENGINE_MULTITYPE_QUEUE_H_
|
||||
#define INC_HIAIENGINE_MULTITYPE_QUEUE_H_
|
||||
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
/**
|
||||
* @Name: MultiTypeQueue
|
||||
* @Description: 支持多种类型的消息队列
|
||||
*
|
||||
*/
|
||||
class MultiTypeQueue final
|
||||
{
|
||||
public:
|
||||
static constexpr uint32_t MULTI_QUEUE_MAX_LEN = 1024;
|
||||
static constexpr uint32_t MULTI_QUEUE_1_QUE_NUM = 1;
|
||||
static constexpr uint32_t MULTI_QUEUE_2_QUE_NUM = 2;
|
||||
static constexpr uint32_t MULTI_QUEUE_3_QUE_NUM = 3;
|
||||
static constexpr uint32_t MULTI_QUEUE_4_QUE_NUM = 4;
|
||||
static constexpr uint32_t MULTI_QUEUE_5_QUE_NUM = 5;
|
||||
static constexpr uint32_t MULTI_QUEUE_6_QUE_NUM = 6;
|
||||
static constexpr uint32_t MULTI_QUEUE_7_QUE_NUM = 7;
|
||||
static constexpr uint32_t MULTI_QUEUE_8_QUE_NUM = 8;
|
||||
static constexpr uint32_t MULTI_QUEUE_9_QUE_NUM = 9;
|
||||
static constexpr uint32_t MULTI_QUEUE_10_QUE_NUM = 10;
|
||||
static constexpr uint32_t MULTI_QUEUE_11_QUE_NUM = 11;
|
||||
static constexpr uint32_t MULTI_QUEUE_12_QUE_NUM = 12;
|
||||
static constexpr uint32_t MULTI_QUEUE_13_QUE_NUM = 13;
|
||||
static constexpr uint32_t MULTI_QUEUE_14_QUE_NUM = 14;
|
||||
static constexpr uint32_t MULTI_QUEUE_15_QUE_NUM = 15;
|
||||
static constexpr uint32_t MULTI_QUEUE_16_QUE_NUM = 16;
|
||||
|
||||
using MultiQueueTimeType = std::chrono::time_point<
|
||||
std::chrono::system_clock, std::chrono::milliseconds>;
|
||||
|
||||
~MultiTypeQueue() {}
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: 构造 MultiTypeQueue
|
||||
* @param [in]que_num: 指定队列个数
|
||||
* @param [in]maxQueLen: 指定每个队列的最大长度
|
||||
* @param [in]durationMs: 指定队列成员从入对到出对最大时间间隔。
|
||||
* 当某个成员从入对(Push)起,超过duration_ms 时间后还未出对
|
||||
* ((Pop),则该成员会被自动删除
|
||||
*/
|
||||
explicit MultiTypeQueue(uint32_t queNum,
|
||||
uint32_t maxQueLen = MULTI_QUEUE_MAX_LEN, uint32_t durationMs = 0) : qumNum_(queNum),
|
||||
durationMs_(durationMs),
|
||||
maxQueLen_(maxQueLen),
|
||||
isAutoDel_(durationMs > 0) {}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: GetSize 获取指定队列的大小
|
||||
* @param [in]qIndex: 队列编号(0 ~ queNum-1)
|
||||
* @param [out]uint32_t: 成功则返回队列大小,否则返回0
|
||||
*/
|
||||
uint32_t GetSize(uint32_t qIndex)
|
||||
{
|
||||
// 索引号非法,则返回失败
|
||||
if (qIndex >= qumNum_)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto iter = multiQueue_.find(qIndex);
|
||||
|
||||
if (iter == multiQueue_.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 队列为空时返回false
|
||||
auto qPointer = (*iter).second;
|
||||
if (qPointer->empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return qPointer->size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PushData 往指定队列插入数据
|
||||
* @param [in]q_idx: 队列编号(0 ~ queNum-1)
|
||||
* @param [in]dataPtr: 队列函数指针
|
||||
* @param [out]bool: 成功则返回true,否则返回false(例如队列满等)
|
||||
*/
|
||||
bool PushData(uint32_t qIndex,
|
||||
const std::shared_ptr<void> &dataPtr)
|
||||
{
|
||||
if (dataPtr == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 索引号非法,则返回失败
|
||||
if (qIndex >= qumNum_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto iter = multiQueue_.find(qIndex);
|
||||
|
||||
// 若当前队列非空,则创建一个新的队列,否则插入已有队列
|
||||
std::shared_ptr<std::queue<std::pair<MultiQueueTimeType,
|
||||
std::shared_ptr<void>>>>
|
||||
qPointer = nullptr;
|
||||
if (iter == multiQueue_.end())
|
||||
{
|
||||
qPointer = std::make_shared<std::queue<std::pair<
|
||||
MultiQueueTimeType, std::shared_ptr<void>>>>();
|
||||
try
|
||||
{
|
||||
qPointer = std::make_shared<std::queue<std::pair<
|
||||
MultiQueueTimeType, std::shared_ptr<void>>>>();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (qPointer == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
multiQueue_[qIndex] = qPointer;
|
||||
}
|
||||
else
|
||||
{
|
||||
qPointer = (*iter).second;
|
||||
}
|
||||
|
||||
if (qPointer->size() >= maxQueLen_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto curTime = std::chrono::time_point_cast<
|
||||
std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now());
|
||||
qPointer->push(std::make_pair(curTime, dataPtr));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: FrontData 读取指定队列头部数据(但并不从队列中删除)
|
||||
* @param [in]q_idx: 队列编号(0 ~ queNum-1)
|
||||
* @param [out]dataPtr: 队列函数指针
|
||||
* @param [out]bool: 成功则返回true,否则返回false(例如队列为空等)
|
||||
*/
|
||||
bool FrontData(uint32_t qIndex,
|
||||
std::shared_ptr<void> &dataPtr)
|
||||
{
|
||||
// 仅读取队列头部数据,但不删除
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto iter = multiQueue_.find(qIndex);
|
||||
if (iter == multiQueue_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<std::queue<std::pair<MultiQueueTimeType,
|
||||
std::shared_ptr<void>>>>
|
||||
qPointer = (*iter).second;
|
||||
|
||||
if (qPointer->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dataPtr = (qPointer->front()).second;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopData 读取指定队列头部数据,并从队列中删除
|
||||
* @param [in]q_idx: 队列编号(0 ~ queNum-1)
|
||||
* @param [out]dataPtr: 队列函数指针
|
||||
* @param [out]bool: 成功则返回true,否则返回false(例如队列为空等)
|
||||
*/
|
||||
bool PopData(uint32_t qIndex,
|
||||
std::shared_ptr<void> &dataPtr)
|
||||
{
|
||||
|
||||
// 读取队列头部数据,并删除头部数据
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
auto iter = multiQueue_.find(qIndex);
|
||||
if (iter == multiQueue_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 队列为空时返回false
|
||||
auto qPointer = (*iter).second;
|
||||
if (qPointer->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 根据需要排除超时数据
|
||||
auto curTime = std::chrono::time_point_cast<
|
||||
std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now());
|
||||
auto quePair = qPointer->front();
|
||||
if (isAutoDel_)
|
||||
{
|
||||
std::chrono::milliseconds diffTime(
|
||||
curTime - quePair.first);
|
||||
while (diffTime.count() >= durationMs_)
|
||||
{
|
||||
qPointer->pop();
|
||||
if (qPointer->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
quePair = qPointer->front();
|
||||
diffTime = std::chrono::milliseconds(
|
||||
curTime - quePair.first);
|
||||
}
|
||||
}
|
||||
|
||||
dataPtr = (qPointer->front()).second;
|
||||
qPointer->pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有一个队列时才使用。
|
||||
* @param [out]arg1: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1)
|
||||
{
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_1_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<void> arg;
|
||||
|
||||
if (!PopData(0, arg))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(arg);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有两个队列时才使用。
|
||||
* @param [out]arg1, arg2: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2)
|
||||
{
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_2_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有三个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3)
|
||||
{
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_3_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有四个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4)
|
||||
{
|
||||
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_4_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有五个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5)
|
||||
{
|
||||
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_5_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有六个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_6_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有七个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6, typename T7>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_7_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有八个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8:
|
||||
* 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_8_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有九个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9:
|
||||
* 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_9_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有九个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_10_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十一个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_11_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十二个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11, arg12: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11,
|
||||
std::shared_ptr<T12> &arg12)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_12_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
arg12 = std::static_pointer_cast<T12>(args[11]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十三个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11, arg12, arg13: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11,
|
||||
std::shared_ptr<T12> &arg12, std::shared_ptr<T13> &arg13)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_13_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
arg12 = std::static_pointer_cast<T12>(args[11]);
|
||||
arg13 = std::static_pointer_cast<T13>(args[12]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十四个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11, arg12, arg13, arg14: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13,
|
||||
typename T14>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11,
|
||||
std::shared_ptr<T12> &arg12, std::shared_ptr<T13> &arg13,
|
||||
std::shared_ptr<T14> &arg14)
|
||||
{
|
||||
if (qumNum_ != MULTI_QUEUE_14_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
arg12 = std::static_pointer_cast<T12>(args[11]);
|
||||
arg13 = std::static_pointer_cast<T13>(args[12]);
|
||||
arg14 = std::static_pointer_cast<T14>(args[13]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十五个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11, arg12, arg13, arg14, arg15: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13,
|
||||
typename T14, typename T15>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11,
|
||||
std::shared_ptr<T12> &arg12, std::shared_ptr<T13> &arg13,
|
||||
std::shared_ptr<T14> &arg14, std::shared_ptr<T15> &arg15)
|
||||
{
|
||||
|
||||
if (qumNum_ != MULTI_QUEUE_15_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
arg12 = std::static_pointer_cast<T12>(args[11]);
|
||||
arg13 = std::static_pointer_cast<T13>(args[12]);
|
||||
arg14 = std::static_pointer_cast<T14>(args[13]);
|
||||
arg15 = std::static_pointer_cast<T15>(args[14]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup hiaiengine
|
||||
* @brief: PopAllData 读取所有队列头部数据。
|
||||
* 仅当所有队列头部都有数据时才读取成功,并删除队列头部数据。
|
||||
* 否则,返回失败但并不删除任何数据。
|
||||
* 该函数仅当只有十六个队列时才使用。
|
||||
* @param [out]arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8,
|
||||
* arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16: 队列函数指针
|
||||
* @param [out]bool: 仅当所有队列头部都有数据时才读取成功并返回true,
|
||||
* 否则返回false
|
||||
*/
|
||||
template <typename T1, typename T2, typename T3,
|
||||
typename T4, typename T5, typename T6,
|
||||
typename T7, typename T8, typename T9, typename T10,
|
||||
typename T11, typename T12, typename T13,
|
||||
typename T14, typename T15, typename T16>
|
||||
bool PopAllData(std::shared_ptr<T1> &arg1,
|
||||
std::shared_ptr<T2> &arg2, std::shared_ptr<T3> &arg3,
|
||||
std::shared_ptr<T4> &arg4, std::shared_ptr<T5> &arg5,
|
||||
std::shared_ptr<T6> &arg6, std::shared_ptr<T7> &arg7,
|
||||
std::shared_ptr<T8> &arg8, std::shared_ptr<T9> &arg9,
|
||||
std::shared_ptr<T10> &arg10, std::shared_ptr<T11> &arg11,
|
||||
std::shared_ptr<T12> &arg12, std::shared_ptr<T13> &arg13,
|
||||
std::shared_ptr<T14> &arg14, std::shared_ptr<T15> &arg15,
|
||||
std::shared_ptr<T16> &arg16)
|
||||
{
|
||||
|
||||
// 若队列个数不匹配,则返回出错
|
||||
if (qumNum_ != MULTI_QUEUE_16_QUE_NUM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<void>> args;
|
||||
if (!PopAllData(args))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
arg1 = std::static_pointer_cast<T1>(args[0]);
|
||||
arg2 = std::static_pointer_cast<T2>(args[1]);
|
||||
arg3 = std::static_pointer_cast<T3>(args[2]);
|
||||
arg4 = std::static_pointer_cast<T4>(args[3]);
|
||||
arg5 = std::static_pointer_cast<T5>(args[4]);
|
||||
arg6 = std::static_pointer_cast<T6>(args[5]);
|
||||
arg7 = std::static_pointer_cast<T7>(args[6]);
|
||||
arg8 = std::static_pointer_cast<T8>(args[7]);
|
||||
arg9 = std::static_pointer_cast<T9>(args[8]);
|
||||
arg10 = std::static_pointer_cast<T10>(args[9]);
|
||||
arg11 = std::static_pointer_cast<T11>(args[10]);
|
||||
arg12 = std::static_pointer_cast<T12>(args[11]);
|
||||
arg13 = std::static_pointer_cast<T13>(args[12]);
|
||||
arg14 = std::static_pointer_cast<T14>(args[13]);
|
||||
arg15 = std::static_pointer_cast<T15>(args[14]);
|
||||
arg16 = std::static_pointer_cast<T16>(args[15]);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool PopAllData(std::vector<
|
||||
std::shared_ptr<void>> &args)
|
||||
{
|
||||
|
||||
// 从当前所有队列获取数据,若设置自动删除过期数据,则需要将
|
||||
// 队里中过期数据过滤
|
||||
auto curTime = std::chrono::time_point_cast<
|
||||
std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now());
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
for (uint32_t index = 0; index < qumNum_; ++index)
|
||||
{
|
||||
auto iter = multiQueue_.find(index);
|
||||
if (iter == multiQueue_.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((*iter).second->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
auto quePair = (*iter).second->front();
|
||||
if (isAutoDel_)
|
||||
{
|
||||
std::chrono::milliseconds diffTime(
|
||||
curTime - quePair.first);
|
||||
while (diffTime.count() >= durationMs_)
|
||||
{
|
||||
(*iter).second->pop();
|
||||
if ((*iter).second->empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
quePair = (*iter).second->front();
|
||||
diffTime = std::chrono::milliseconds(
|
||||
curTime - quePair.first);
|
||||
}
|
||||
}
|
||||
args.push_back(quePair.second);
|
||||
}
|
||||
|
||||
for (uint32_t index = 0; index < qumNum_; ++index)
|
||||
{
|
||||
auto iter = multiQueue_.find(index);
|
||||
(*iter).second->pop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
MultiTypeQueue(const MultiTypeQueue &) = delete;
|
||||
MultiTypeQueue(MultiTypeQueue &&) = delete;
|
||||
MultiTypeQueue &operator=(const MultiTypeQueue &) = delete;
|
||||
MultiTypeQueue &operator=(MultiTypeQueue &&) = delete;
|
||||
|
||||
private:
|
||||
uint32_t qumNum_;
|
||||
uint32_t durationMs_;
|
||||
uint32_t maxQueLen_;
|
||||
std::map<uint32_t, std::shared_ptr<std::queue<std::pair<MultiQueueTimeType, std::shared_ptr<void>>>>> multiQueue_;
|
||||
std::mutex mutex_;
|
||||
bool isAutoDel_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // INC_HIAIENGINE_MULTITYPE_QUEUE_H_
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
#include "mylog.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
MyLog::~MyLog()
|
||||
{
|
||||
if (of_.is_open())
|
||||
{
|
||||
of_.close(); //关闭文件
|
||||
}
|
||||
}
|
||||
|
||||
std::string MyLog::get_name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void MyLog::open_file(std::string filename)
|
||||
{
|
||||
if (of_.is_open())
|
||||
{
|
||||
of_.close(); //关闭文件
|
||||
}
|
||||
|
||||
of_.open(filename.c_str(), std::ios_base::out | std::ios_base::app);
|
||||
|
||||
assert(of_.is_open() && "file create failed, please check the file's name and path.");
|
||||
|
||||
name_ = filename;
|
||||
}
|
||||
|
||||
void MyLog::close()
|
||||
{
|
||||
if (of_.is_open())
|
||||
{
|
||||
of_.close(); //关闭文件
|
||||
}
|
||||
}
|
||||
|
||||
bool MyLog::is_open()
|
||||
{
|
||||
return of_.is_open();
|
||||
}
|
||||
|
||||
void MyLog::write(std::string value)
|
||||
{
|
||||
if (of_.is_open() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
long int usValue = 0;
|
||||
struct timeval time = {0, 0};
|
||||
gettimeofday(&time, nullptr);
|
||||
time_t timep = time.tv_sec;
|
||||
struct tm *ptm = gmtime(&timep); //返回tm结构的格林尼治时间(GMT)
|
||||
char timeString[32] = {0};
|
||||
//%F 年-月-日 %X 标准的时间串
|
||||
strftime(timeString, 32, "[%F %X:", ptm);
|
||||
usValue = time.tv_usec;
|
||||
|
||||
//时间
|
||||
of_.fill('0');
|
||||
of_ << timeString << std::setw(3) << usValue / 1000 << "]";
|
||||
|
||||
//位置
|
||||
std::string file = __FILE__;
|
||||
std::string fileName = file.substr(file.rfind('/') + 1);
|
||||
of_ << "[" << fileName << " " << __FUNCTION__ << ":" << __LINE__ << "] ";
|
||||
|
||||
//内容
|
||||
of_ << value << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef MYLOG_H_
|
||||
#define MYLOG_H_
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
class MyLog final
|
||||
{
|
||||
public:
|
||||
MyLog() = default;
|
||||
MyLog(const MyLog &) = delete;
|
||||
MyLog(MyLog &&) = delete;
|
||||
MyLog &operator=(const MyLog &) = delete;
|
||||
MyLog &operator=(MyLog &&) = delete;
|
||||
~MyLog();
|
||||
|
||||
//获取日志文件名
|
||||
std::string get_name() const;
|
||||
|
||||
//创建日志文件
|
||||
void open_file(std::string filename);
|
||||
|
||||
//关闭日志文件
|
||||
void close();
|
||||
|
||||
//判断日志文件是否打开
|
||||
bool is_open();
|
||||
|
||||
//写入日志文件
|
||||
void write(std::string value);
|
||||
|
||||
private:
|
||||
std::ofstream of_;
|
||||
std::string name_; //日志文件名
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
#ifndef MYQUEUE_H_
|
||||
#define MYQUEUE_H_
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
template <typename T>
|
||||
class MyQueue final
|
||||
{
|
||||
public:
|
||||
MyQueue(int max = 1024) : max_size_(max), is_stoped_(false) {}
|
||||
MyQueue(const MyQueue &) = delete;
|
||||
MyQueue(MyQueue &&) = delete;
|
||||
MyQueue &operator=(const MyQueue &) = delete;
|
||||
MyQueue &operator=(MyQueue &&) = delete;
|
||||
~MyQueue() = default;
|
||||
|
||||
int push(const T &value, bool isWait = true)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mutex_);
|
||||
|
||||
while (queue_.size() >= max_size_ && isWait && !is_stoped_)
|
||||
{
|
||||
printf("myqueue full");
|
||||
cond_not_full_.wait(lk);
|
||||
}
|
||||
|
||||
if (is_stoped_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (queue_.size() >= max_size_)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
queue_.push(value);
|
||||
|
||||
cond_not_empty_.notify_one();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pop(T &value, bool isWait = false)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mutex_);
|
||||
|
||||
while (queue_.empty() && isWait && !is_stoped_)
|
||||
{
|
||||
cond_not_empty_.wait(lk);
|
||||
}
|
||||
|
||||
if (is_stoped_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (queue_.empty())
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
value = queue_.front();
|
||||
queue_.pop();
|
||||
|
||||
cond_not_full_.notify_one();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mutex_);
|
||||
is_stoped_ = true;
|
||||
}
|
||||
|
||||
cond_not_full_.notify_all();
|
||||
cond_not_empty_.notify_all();
|
||||
}
|
||||
|
||||
int getSize()
|
||||
{
|
||||
return queue_.size();
|
||||
}
|
||||
|
||||
void setMaxSize(int iMaxSize)
|
||||
{
|
||||
max_size_ = iMaxSize;
|
||||
}
|
||||
|
||||
private:
|
||||
std::queue<T> queue_; //队列
|
||||
|
||||
std::condition_variable cond_not_empty_;
|
||||
std::condition_variable cond_not_full_;
|
||||
|
||||
std::mutex mutex_;
|
||||
|
||||
int max_size_;
|
||||
|
||||
bool is_stoped_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
#include "myshell.h"
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
const int TIME_SIZE = 32;
|
||||
const int TIME_DIFF = 28800; // 8 hour
|
||||
std::mutex MyShell::mutex;
|
||||
uint32_t MyShell::shellLevel = SHELL_LEVEL_INFO;
|
||||
std::vector<std::string> MyShell::levelString{"[Debug]", "[Info ]", "[Warn ]", "[Error]", "[Fatal]"};
|
||||
|
||||
MyShell::MyShell(std::string file, std::string function, int line, uint32_t level)
|
||||
: myLevel_(level), file_(file), function_(function), line_(line)
|
||||
{
|
||||
}
|
||||
|
||||
MyShell::~MyShell()
|
||||
{
|
||||
if (myLevel_ >= shellLevel)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(mutex);
|
||||
// cout to screen
|
||||
std::cout << ss_.str() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostringstream &MyShell::Stream()
|
||||
{
|
||||
if (myLevel_ >= shellLevel)
|
||||
{
|
||||
struct timeval time = {0, 0};
|
||||
gettimeofday(&time, nullptr);
|
||||
time_t timep = time.tv_sec + TIME_DIFF; //加上8小时
|
||||
struct tm *ptm = gmtime(&timep); //返回tm结构的格林尼治时间(GMT)
|
||||
char timeString[TIME_SIZE] = {0};
|
||||
//%F 年-月-日 %X 标准的时间串
|
||||
strftime(timeString, TIME_SIZE, "[%F %X:", ptm);
|
||||
long int usValue = time.tv_usec;
|
||||
|
||||
date_ = timeString;
|
||||
ss_.fill('0');
|
||||
ss_ << levelString[myLevel_] << timeString << std::setw(3) << usValue / 1000 << "]";
|
||||
|
||||
std::string fileName = file_.substr(file_.rfind('/') + 1);
|
||||
ss_ << "[" << fileName << " " << function_ << ":" << line_ << "] ";
|
||||
}
|
||||
return ss_;
|
||||
}
|
||||
|
||||
void MyShell::ShellDebugOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_DEBUG;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellInfoOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_INFO;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellWarnOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_WARN;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellErrorOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_ERROR;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellFatalOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_FATAL;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellAllOn()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_DEBUG;
|
||||
return;
|
||||
}
|
||||
void MyShell::ShellAllOff()
|
||||
{
|
||||
shellLevel = SHELL_LEVEL_NONE;
|
||||
return;
|
||||
}
|
||||
} // namespace matrix_common
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef MYSHELL_H
|
||||
#define MYSHELL_H
|
||||
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sys/time.h>
|
||||
#include <vector>
|
||||
|
||||
namespace ai_matrix
|
||||
{
|
||||
// shell level
|
||||
enum ShellLevels
|
||||
{
|
||||
SHELL_LEVEL_DEBUG = 0,
|
||||
SHELL_LEVEL_INFO = 1,
|
||||
SHELL_LEVEL_WARN = 2,
|
||||
SHELL_LEVEL_ERROR = 3,
|
||||
SHELL_LEVEL_FATAL = 4,
|
||||
SHELL_LEVEL_NONE
|
||||
};
|
||||
|
||||
class MyShell final
|
||||
{
|
||||
public:
|
||||
MyShell(std::string file, std::string function, int line, uint32_t level);
|
||||
~MyShell();
|
||||
std::ostringstream &Stream();
|
||||
|
||||
static void ShellDebugOn();
|
||||
static void ShellInfoOn();
|
||||
static void ShellWarnOn();
|
||||
static void ShellErrorOn();
|
||||
static void ShellFatalOn();
|
||||
static void ShellAllOn();
|
||||
static void ShellAllOff();
|
||||
|
||||
private:
|
||||
std::ostringstream ss_;
|
||||
uint32_t myLevel_;
|
||||
std::string date_;
|
||||
std::string file_;
|
||||
std::string function_;
|
||||
int line_;
|
||||
|
||||
static uint32_t shellLevel;
|
||||
static std::vector<std::string> levelString;
|
||||
static std::mutex mutex;
|
||||
};
|
||||
} // namespace ai_matrix
|
||||
|
||||
#define MyShellDebug ai_matrix::MyShell(__FILE__, __FUNCTION__, __LINE__, ai_matrix::SHELL_LEVEL_DEBUG).Stream()
|
||||
#define MyShellInfo ai_matrix::MyShell(__FILE__, __FUNCTION__, __LINE__, ai_matrix::SHELL_LEVEL_INFO).Stream()
|
||||
#define MyShellWarn ai_matrix::MyShell(__FILE__, __FUNCTION__, __LINE__, ai_matrix::SHELL_LEVEL_WARN).Stream()
|
||||
#define MyShellError ai_matrix::MyShell(__FILE__, __FUNCTION__, __LINE__, ai_matrix::SHELL_LEVEL_ERROR).Stream()
|
||||
#define MyShellFatal ai_matrix::MyShell(__FILE__, __FUNCTION__, __LINE__, ai_matrix::SHELL_LEVEL_FATAL).Stream()
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
#ifndef _NVIDIA_ACL_DATATYPE_H_
|
||||
#define _NVIDIA_ACL_DATATYPE_H_
|
||||
|
||||
//ACL
|
||||
typedef enum {
|
||||
ACL_DT_UNDEFINED = -1,
|
||||
ACL_FLOAT = 0,
|
||||
ACL_FLOAT16 = 1,
|
||||
ACL_INT8 = 2,
|
||||
ACL_INT32 = 3,
|
||||
ACL_UINT8 = 4,
|
||||
ACL_INT16 = 6,
|
||||
ACL_UINT16 = 7,
|
||||
ACL_UINT32 = 8,
|
||||
ACL_INT64 = 9,
|
||||
ACL_UINT64 = 10,
|
||||
ACL_DOUBLE = 11,
|
||||
ACL_BOOL = 12,
|
||||
ACL_STRING = 13,
|
||||
} nvidia_aclDataType;
|
||||
|
||||
typedef enum {
|
||||
ACL_FORMAT_UNDEFINED = -1,
|
||||
ACL_FORMAT_NCHW = 0,
|
||||
ACL_FORMAT_NHWC = 1,
|
||||
ACL_FORMAT_ND = 2,
|
||||
ACL_FORMAT_NC1HWC0 = 3,
|
||||
ACL_FORMAT_FRACTAL_Z = 4,
|
||||
ACL_FORMAT_NC1HWC0_C04 = 12,
|
||||
ACL_FORMAT_FRACTAL_NZ = 29,
|
||||
} nvidia_aclFormat;
|
||||
|
||||
typedef enum {
|
||||
ACL_DEBUG = 0,
|
||||
ACL_INFO = 1,
|
||||
ACL_WARNING = 2,
|
||||
ACL_ERROR = 3,
|
||||
} nvidia_aclLogLevel;
|
||||
|
||||
|
||||
//DVPP
|
||||
// Supported Pixel Format
|
||||
typedef enum nvidia_acldvppPixelFormat {
|
||||
PIXEL_FORMAT_YUV_400 = 0, // 0
|
||||
PIXEL_FORMAT_YUV_SEMIPLANAR_420 = 1, // 1
|
||||
PIXEL_FORMAT_YVU_SEMIPLANAR_420 = 2, // 2
|
||||
PIXEL_FORMAT_YUV_SEMIPLANAR_422 = 3, // 3
|
||||
PIXEL_FORMAT_YVU_SEMIPLANAR_422 = 4, // 4
|
||||
PIXEL_FORMAT_YUV_SEMIPLANAR_444 = 5, // 5
|
||||
PIXEL_FORMAT_YVU_SEMIPLANAR_444 = 6, // 6
|
||||
PIXEL_FORMAT_YUYV_PACKED_422 = 7, // 7
|
||||
PIXEL_FORMAT_UYVY_PACKED_422 = 8, // 8
|
||||
PIXEL_FORMAT_YVYU_PACKED_422 = 9, // 9
|
||||
PIXEL_FORMAT_VYUY_PACKED_422 = 10, // 10
|
||||
PIXEL_FORMAT_YUV_PACKED_444 = 11, // 11
|
||||
PIXEL_FORMAT_RGB_888 = 12, // 12
|
||||
PIXEL_FORMAT_BGR_888 = 13, // 13
|
||||
PIXEL_FORMAT_ARGB_8888 = 14, // 14
|
||||
PIXEL_FORMAT_ABGR_8888 = 15, // 15
|
||||
PIXEL_FORMAT_RGBA_8888 = 16, // 16
|
||||
PIXEL_FORMAT_BGRA_8888 = 17, // 17
|
||||
PIXEL_FORMAT_YUV_SEMI_PLANNER_420_10BIT = 18, // 18
|
||||
PIXEL_FORMAT_YVU_SEMI_PLANNER_420_10BIT = 19, // 19
|
||||
PIXEL_FORMAT_YVU_PLANAR_420 = 20, // 20
|
||||
PIXEL_FORMAT_YVU_PLANAR_422,
|
||||
PIXEL_FORMAT_YVU_PLANAR_444,
|
||||
PIXEL_FORMAT_RGB_444 = 23,
|
||||
PIXEL_FORMAT_BGR_444,
|
||||
PIXEL_FORMAT_ARGB_4444,
|
||||
PIXEL_FORMAT_ABGR_4444,
|
||||
PIXEL_FORMAT_RGBA_4444,
|
||||
PIXEL_FORMAT_BGRA_4444,
|
||||
PIXEL_FORMAT_RGB_555,
|
||||
PIXEL_FORMAT_BGR_555,
|
||||
PIXEL_FORMAT_RGB_565,
|
||||
PIXEL_FORMAT_BGR_565,
|
||||
PIXEL_FORMAT_ARGB_1555,
|
||||
PIXEL_FORMAT_ABGR_1555,
|
||||
PIXEL_FORMAT_RGBA_1555,
|
||||
PIXEL_FORMAT_BGRA_1555,
|
||||
PIXEL_FORMAT_ARGB_8565,
|
||||
PIXEL_FORMAT_ABGR_8565,
|
||||
PIXEL_FORMAT_RGBA_8565,
|
||||
PIXEL_FORMAT_BGRA_8565,
|
||||
PIXEL_FORMAT_RGB_BAYER_8BPP = 50,
|
||||
PIXEL_FORMAT_RGB_BAYER_10BPP,
|
||||
PIXEL_FORMAT_RGB_BAYER_12BPP,
|
||||
PIXEL_FORMAT_RGB_BAYER_14BPP,
|
||||
PIXEL_FORMAT_RGB_BAYER_16BPP,
|
||||
PIXEL_FORMAT_BGR_888_PLANAR = 70,
|
||||
PIXEL_FORMAT_HSV_888_PACKAGE,
|
||||
PIXEL_FORMAT_HSV_888_PLANAR,
|
||||
PIXEL_FORMAT_LAB_888_PACKAGE,
|
||||
PIXEL_FORMAT_LAB_888_PLANAR,
|
||||
PIXEL_FORMAT_S8C1,
|
||||
PIXEL_FORMAT_S8C2_PACKAGE,
|
||||
PIXEL_FORMAT_S8C2_PLANAR,
|
||||
PIXEL_FORMAT_S16C1,
|
||||
PIXEL_FORMAT_U8C1,
|
||||
PIXEL_FORMAT_U16C1,
|
||||
PIXEL_FORMAT_S32C1,
|
||||
PIXEL_FORMAT_U32C1,
|
||||
PIXEL_FORMAT_U64C1,
|
||||
PIXEL_FORMAT_S64C1,
|
||||
PIXEL_FORMAT_YUV_SEMIPLANAR_440 = 1000,
|
||||
PIXEL_FORMAT_YVU_SEMIPLANAR_440,
|
||||
PIXEL_FORMAT_FLOAT32,
|
||||
PIXEL_FORMAT_BUTT,
|
||||
PIXEL_FORMAT_UNKNOWN = 10000
|
||||
} acldvppPixelFormat;
|
||||
|
||||
// Stream Format
|
||||
typedef enum nvidia_acldvppStreamFormat {
|
||||
H265_MAIN_LEVEL = 0,
|
||||
H264_BASELINE_LEVEL,
|
||||
H264_MAIN_LEVEL,
|
||||
H264_HIGH_LEVEL
|
||||
} acldvppStreamFormat;
|
||||
|
||||
// Supported Channel Mode
|
||||
enum nvidia_acldvppChannelMode {
|
||||
DVPP_CHNMODE_VPC = 1,
|
||||
DVPP_CHNMODE_JPEGD = 2,
|
||||
DVPP_CHNMODE_JPEGE = 4
|
||||
};
|
||||
|
||||
// Supported Border Type
|
||||
enum nvidia_acldvppBorderType {
|
||||
BORDER_CONSTANT = 0,
|
||||
BORDER_REPLICATE,
|
||||
BORDER_REFLECT,
|
||||
BORDER_REFLECT_101
|
||||
};
|
||||
|
||||
// Venc parameter type
|
||||
enum nvidia_aclvencChannelDescParamType {
|
||||
ACL_VENC_THREAD_ID_UINT64 = 0,
|
||||
ACL_VENC_CALLBACK_PTR,
|
||||
ACL_VENC_PIXEL_FORMAT_UINT32,
|
||||
ACL_VENC_ENCODE_TYPE_UINT32,
|
||||
ACL_VENC_PIC_WIDTH_UINT32,
|
||||
ACL_VENC_PIC_HEIGHT_UINT32,
|
||||
ACL_VENC_KEY_FRAME_INTERVAL_UINT32,
|
||||
ACL_VENC_BUF_ADDR_PTR,
|
||||
ACL_VENC_BUF_SIZE_UINT32,
|
||||
ACL_VENC_RC_MODE_UINT32,
|
||||
ACL_VENC_SRC_RATE_UINT32,
|
||||
ACL_VENC_MAX_BITRATE_UINT32,
|
||||
ACL_VENC_MAX_IP_PROP_UINT32
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
# 基础控制参数
|
||||
base:
|
||||
# 股道名称
|
||||
track_name: "1"
|
||||
# 测试模式
|
||||
test_model: false
|
||||
# Api 监听端口
|
||||
api_port: 7070
|
||||
# 日志文件目录
|
||||
log_path: "./logs"
|
||||
# 识别结果目录
|
||||
result_path: "./result"
|
||||
# 调试结果目录
|
||||
debug_result_path: "./debug_result"
|
||||
# 结果存储天数
|
||||
result_save_days: 10
|
||||
|
||||
# 日志参数
|
||||
log:
|
||||
# 输出日志级别[DEBUG, INFO, WARN, ERROR, FATAL]
|
||||
out_level: "DEBUG"
|
||||
# 保存日志级别
|
||||
save_level: "DEBUG"
|
||||
|
||||
# 数据源参数
|
||||
data_source:
|
||||
url: "./vedio/buertai2.mp4"
|
||||
# 跳帧数
|
||||
skip_interval: 3
|
||||
# 行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应)
|
||||
direction: 0
|
||||
# 0-向左编号在前 1-向左属性在前 (向右行驶的情况:2-向右编号在前 3-向右属性在前)
|
||||
left_first: 0
|
||||
# (向左行驶的情况:0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前
|
||||
right_first: 3
|
||||
# 识别区域
|
||||
identify_areas: [120, 0, 1800, 1080]
|
||||
|
||||
# 识别参数
|
||||
identify:
|
||||
# 运行方式
|
||||
run_mode: "always" #[always; command]
|
||||
# 是否开启动态检测
|
||||
need_move_detect_flag: true
|
||||
# 识别方向 [LEFT,RIGHT,ALL]
|
||||
identify_direction: "LEFT"
|
||||
# 大框帧跨度(比一个大框从出现到消失的跨度稍大一点, 跟跳帧有关系)
|
||||
partition_frame_span: 20
|
||||
# 大框帧跨度的位置像素差异
|
||||
split_frame_span_px: 200
|
||||
# 每帧大框位置差异最小值 (持续小于此值,则可能停车)
|
||||
chkstop_px: 15
|
||||
# 持续X次续位置差异小于gc_chkstop_px,则判断为停车。
|
||||
chkstop_count: 10
|
||||
# 过滤最小大框高度(不需要的话就写个很小的值)
|
||||
num_frame_height: 150
|
||||
pro_frame_height: 120
|
||||
# 过滤最大框宽度(不需要的话就写个很大的值)
|
||||
space_frame_width: 500
|
||||
# 是否识别车头
|
||||
train_heard_detect: false
|
||||
# 是否识别集装箱
|
||||
container_detect: false
|
||||
|
||||
# websocket_server 的服务端参数
|
||||
wsocket_server:
|
||||
is_use: false
|
||||
port: 7071
|
||||
max_queue_len: 10
|
||||
|
||||
# http 接口
|
||||
http_server:
|
||||
# 使用状态
|
||||
is_use: false
|
||||
# 服务器IP
|
||||
http_ip: 192.168.2.108
|
||||
# 通讯端口
|
||||
http_port: 20004
|
||||
# 获取接口授权地址
|
||||
token_path: "/api/blade-auth/oauth/token"
|
||||
# 识别结果上传地址
|
||||
up_result_path: "/api/train-carriage/identification/rfid-save"
|
||||
# 设备状态上传地址
|
||||
device_status_url: ""
|
||||
# 接口用户名
|
||||
username: "guest_01"
|
||||
# 接口密码
|
||||
password: "d55b0f642e817eea24725d2f2a31dd08"
|
||||
|
||||
# minio 服务配置
|
||||
minio:
|
||||
# 使用状态
|
||||
is_use: false
|
||||
# 服务地址
|
||||
url: "http://192.168.32.134:19000"
|
||||
# 通讯授权
|
||||
accesskey: "OpgVbHoeDLUBWjQkN3NS"
|
||||
# 密钥授权
|
||||
secretkey: "fc0sDwKTq2N7ZVl2iJk36WUZgL5EtNLTjRVtIzNM"
|
||||
# 容器名
|
||||
bucket: "train"
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
#use_deviceid:
|
||||
# #engineid: deviceid
|
||||
# 0: 0
|
||||
|
||||
#engine实例
|
||||
engines:
|
||||
ApiEngine: 0
|
||||
VideoEngine: 0
|
||||
VideoDecodeEngine: 0
|
||||
MoveEngine: 0
|
||||
SaveMoveImageEngine: 0
|
||||
SaveMoveInfoEngine: 0
|
||||
TrainStep1DataReadEngine: 0
|
||||
TrainStep1InferenceEngine: 0
|
||||
TrainStep1FilterEngine: 0
|
||||
TrainDivideEngine: 0
|
||||
TrainStep2DataReadEngine: 0
|
||||
TrainStep2InferenceEngine: 0
|
||||
TrainCharacterConversionEngine: 0
|
||||
SelectBestEngine: 0
|
||||
SaveResultCSVEngine: 0
|
||||
ToHttpSrvEngine: 0
|
||||
ToMinioSrvEngine: 0
|
||||
SaveDebugImageEngine: 0
|
||||
|
||||
#engine连接
|
||||
connects:
|
||||
VideoEngine_0_0: "VideoDecodeEngine_0_0 1024"
|
||||
VideoDecodeEngine_0_0: "MoveEngine_0_0 1024"
|
||||
MoveEngine_0_0: "SaveMoveImageEngine_0_0 1024"
|
||||
MoveEngine_0_1: "SaveMoveInfoEngine_0_0 1024"
|
||||
SaveMoveImageEngine_0_0: "TrainStep1DataReadEngine_0_0 1024"
|
||||
TrainStep1DataReadEngine_0_0: "TrainStep1InferenceEngine_0_0 1024"
|
||||
TrainStep1InferenceEngine_0_0: "TrainStep1FilterEngine_0_0 1024"
|
||||
TrainStep1FilterEngine_0_0: "TrainDivideEngine_0_0 1024"
|
||||
TrainDivideEngine_0_0: "TrainStep2DataReadEngine_0_0 1024"
|
||||
TrainStep2DataReadEngine_0_0: "TrainStep2InferenceEngine_0_0 1024"
|
||||
TrainStep2InferenceEngine_0_0: "TrainCharacterConversionEngine_0_0 1024"
|
||||
TrainCharacterConversionEngine_0_0: "SelectBestEngine_0_0 1024"
|
||||
TrainCharacterConversionEngine_0_1: "SaveDebugImageEngine_0_0 1024"
|
||||
SelectBestEngine_0_0: "SaveResultCSVEngine_0_0 1024"
|
||||
SaveResultCSVEngine_0_0: "ToHttpSrvEngine_0_0 1024"
|
||||
SaveResultCSVEngine_0_1: "ToMinioSrvEngine_0_0 1024"
|
||||
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
# 动态检测
|
||||
move_model:
|
||||
model_path: "./model/step0/step0.engine"
|
||||
score_threshold: 0
|
||||
class: []
|
||||
# 关键区域识别
|
||||
train_step1_model:
|
||||
model_path: "./model/step1/step1.engine"
|
||||
score_threshold: 0.6
|
||||
class: [ "HEADNUM",
|
||||
"PROPERTY",
|
||||
"TYPENUM_K",
|
||||
"TYPENUM_C",
|
||||
"TYPENUM_P",
|
||||
"TYPENUM_G",
|
||||
"TYPENUM_N",
|
||||
"MAINTENFLAG",
|
||||
"TYPENUM_J",
|
||||
"SPACE",
|
||||
"SPACELK",
|
||||
"SPACENX",
|
||||
"SPACEG",
|
||||
"SPACEP",
|
||||
"SPACEJ",
|
||||
"TYPENUM_W",
|
||||
"SPACEW",
|
||||
"SPACEM",
|
||||
"SPACEU"
|
||||
]
|
||||
# 字符识别
|
||||
train_step2_model:
|
||||
model_path: "./model/step2/step2.engine"
|
||||
score_threshold: 0.7
|
||||
class: ["0","1","2","3","4","5","6","7","8","9",
|
||||
"A","B","C","D","E","F","G","H","I","J","K","L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V","W", "X", "Y", "Z",
|
||||
"change", "load", "m", "self", "t", "volume", "meter",")", "(", "?", "-"
|
||||
]
|
||||
# 集装箱关键区域识别
|
||||
container_step1_model:
|
||||
model_path: "./model/container_step1/con1.engine"
|
||||
score_threshold: 0.6
|
||||
class: []
|
||||
# 集装箱字符识别
|
||||
container_step2_model:
|
||||
model_path: "./model/container_step2/con2.engine"
|
||||
score_threshold: 0.7
|
||||
class: []
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue