2024-04-08 02:38:51 +00:00
|
|
|
#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_.iConnectType = config_["base"]["connect_type"].as<int>();
|
|
|
|
|
this->baseConfig_.bUpResult = config_["base"]["up_result"].as<bool>();
|
|
|
|
|
this->baseConfig_.bHaveMagnetSteel = config_["base"]["have_magnet_steel"].as<bool>();
|
|
|
|
|
this->baseConfig_.strMagnetSteelOrder = config_["base"]["magnet_steel_order"].as<std::string>();
|
|
|
|
|
this->baseConfig_.strRfidPath = config_["base"]["rfid_path"].as<std::string>();
|
|
|
|
|
this->baseConfig_.strLogPath = config_["base"]["log_path"].as<std::string>();
|
|
|
|
|
this->baseConfig_.strResultPath = config_["base"]["result_path"].as<std::string>();
|
|
|
|
|
this->baseConfig_.iResultSaveDays = config_["base"]["result_save_days"].as<int>();
|
|
|
|
|
|
|
|
|
|
// 日志参数
|
|
|
|
|
this->logConfig_.strLevel = config_["log"]["level"].as<std::string>();
|
|
|
|
|
|
|
|
|
|
// 串口通讯参数
|
|
|
|
|
this->serialConfig_.strComName = config_["serial"]["com_name"].as<std::string>();
|
|
|
|
|
this->serialConfig_.iBaud = config_["serial"]["baud"].as<int>();
|
|
|
|
|
this->serialConfig_.iDataBits = config_["serial"]["data_bits"].as<int>();
|
|
|
|
|
this->serialConfig_.strParityBits = config_["serial"]["parity_bits"].as<std::string>();
|
|
|
|
|
this->serialConfig_.iStopBits = config_["serial"]["stop_bits"].as<int>();
|
|
|
|
|
|
|
|
|
|
// 识别参数
|
|
|
|
|
this->ethernetConfig_.strIp = config_["ethernet"]["ip"].as<std::string>();
|
|
|
|
|
this->ethernetConfig_.iPort = config_["ethernet"]["port"].as<int>();
|
|
|
|
|
|
2024-04-25 09:53:34 +00:00
|
|
|
// 视频识别辅助来车状态检测
|
|
|
|
|
this->videoAuxiliaryConfig_.bUseVideoAuxiliary = config_["video_auxiliary"]["use_video_auxiliary"].as<bool>();
|
|
|
|
|
this->videoAuxiliaryConfig_.strIp = config_["video_auxiliary"]["ip"].as<std::string>();
|
|
|
|
|
this->videoAuxiliaryConfig_.iPort = config_["video_auxiliary"]["port"].as<int>();
|
|
|
|
|
this->videoAuxiliaryConfig_.iDelayedUpload = config_["video_auxiliary"]["delayed_upload"].as<int>();
|
2024-04-08 02:38:51 +00:00
|
|
|
|
|
|
|
|
// 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_.strUserName = config_["http_server"]["username"].as<std::string>();
|
|
|
|
|
this->httpServerConfig_.strPassword = config_["http_server"]["password"].as<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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SerialConfig Config::getSerialConfig() const
|
|
|
|
|
{
|
|
|
|
|
return this->serialConfig_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Config::setSerialConfig(const SerialConfig serialConfig)
|
|
|
|
|
{
|
|
|
|
|
this->serialConfig_ = serialConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EthernetConfig Config::getEthernetConfig() const
|
|
|
|
|
{
|
|
|
|
|
return this->ethernetConfig_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Config::setEthernetConfig(const EthernetConfig ethernetConfig)
|
|
|
|
|
{
|
|
|
|
|
this->ethernetConfig_ = ethernetConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 09:53:34 +00:00
|
|
|
VideoAuxiliaryConfig Config::getVideoAuxiliaryConfig() const
|
2024-04-08 02:38:51 +00:00
|
|
|
{
|
2024-04-25 09:53:34 +00:00
|
|
|
return this->videoAuxiliaryConfig_;
|
2024-04-08 02:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-25 09:53:34 +00:00
|
|
|
void Config::setVideoAuxiliaryConfig(const VideoAuxiliaryConfig videoAuxiliaryConfig)
|
2024-04-08 02:38:51 +00:00
|
|
|
{
|
2024-04-25 09:53:34 +00:00
|
|
|
this->videoAuxiliaryConfig_ = videoAuxiliaryConfig;
|
2024-04-08 02:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HttpServerConfig Config::getHttpServerConfig() const
|
|
|
|
|
{
|
|
|
|
|
return this->httpServerConfig_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Config::setHttpServerConfig(const HttpServerConfig httpServerConfig) {
|
|
|
|
|
this->httpServerConfig_ = httpServerConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|