|
@@ -85,6 +85,11 @@ void NoiseDetectThread::task()
|
|
|
|
|
|
SPDLOG_LOGGER_INFO(m_logger, " ★ {} 噪音检测线程开始运行 ", m_logBase);
|
|
SPDLOG_LOGGER_INFO(m_logger, " ★ {} 噪音检测线程开始运行 ", m_logBase);
|
|
// std::chrono::system_clock::time_point startTime = std::chrono::system_clock::now();
|
|
// std::chrono::system_clock::time_point startTime = std::chrono::system_clock::now();
|
|
|
|
+#if(CREATE_NOISE_WARN)
|
|
|
|
+ int noiseWarnCount = 0;
|
|
|
|
+ bool isNoise = false;
|
|
|
|
+#endif /* CREATE_NOISE_WARN */
|
|
|
|
+
|
|
while(m_isRunning)
|
|
while(m_isRunning)
|
|
{
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(detectInterval));
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(detectInterval));
|
|
@@ -118,17 +123,19 @@ void NoiseDetectThread::task()
|
|
{
|
|
{
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #if(CREATE_NOISE_WARN)
|
|
/* 这里模拟报警 */
|
|
/* 这里模拟报警 */
|
|
- // auto now = std::chrono::system_clock::now();
|
|
|
|
|
|
+ if( noiseWarnCount >= 12)
|
|
|
|
+ {
|
|
|
|
+ isNoise = !isNoise;
|
|
|
|
+ noiseWarnCount = 0;
|
|
|
|
+ }
|
|
|
|
+ noiseWarnCount++;
|
|
|
|
|
|
- // if(now - startTime > std::chrono::seconds(10) && now - startTime < std::chrono::seconds(20))
|
|
|
|
- // {
|
|
|
|
- // SPDLOG_LOGGER_WARN(m_logger, "{} 模拟噪音开始", m_logBase);
|
|
|
|
- // m_currentIsNoise = true; // 模拟噪音检测到
|
|
|
|
- // }else
|
|
|
|
- // {
|
|
|
|
- // m_currentIsNoise = false;
|
|
|
|
- // }
|
|
|
|
|
|
+ m_currentIsNoise = isNoise;
|
|
|
|
+
|
|
|
|
+ #endif /* CREATE_NOISE_WARN */
|
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------
|
|
/*------------------------------------------------------------------------
|
|
@@ -261,9 +268,9 @@ bool NoiseDetectThread::detectNoise()
|
|
|
|
|
|
std::chrono::duration<double> duration = std::chrono::steady_clock::now() - startTime;
|
|
std::chrono::duration<double> duration = std::chrono::steady_clock::now() - startTime;
|
|
std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
|
std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 计算噪音耗时: {}ms", m_logBase, ms.count());
|
|
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "{} 计算噪音耗时: {}ms", m_logBase, ms.count());
|
|
|
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "{} 左声道噪音检测结果: {}, 右声道噪音检测结果: {}", m_logBase, isNoiseLeft, isNoiseRight);
|
|
|
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "{} 左声道噪音检测结果: {}, 右声道噪音检测结果: {}, 耗时:{}", m_logBase, isNoiseLeft, isNoiseRight, ms.count());
|
|
|
|
|
|
/* -------------------------- 和以往的结果对比 --------------------------*/
|
|
/* -------------------------- 和以往的结果对比 --------------------------*/
|
|
m_currentIsNoise = (isNoiseLeft || isNoiseRight); /* 是否检测到噪音 */
|
|
m_currentIsNoise = (isNoiseLeft || isNoiseRight); /* 是否检测到噪音 */
|
|
@@ -409,8 +416,8 @@ void NoiseDetectThread::saveResultOnlyOneItem()
|
|
}else {
|
|
}else {
|
|
m_isNoise.store(false);
|
|
m_isNoise.store(false);
|
|
}
|
|
}
|
|
- // SPDLOG_LOGGER_INFO(m_logger, "{} 当前噪音检测结果: {}, 噪音预警: {}, 连续噪音个数: {}, 噪音所占百分比: {:.2f}%",
|
|
|
|
- // m_logBase, m_currentIsNoise, m_isNoiseWarning.load(), numCountinueNoise, percentNoise);
|
|
|
|
|
|
+ SPDLOG_LOGGER_INFO(m_logger, "{} 当前噪音检测结果: {}, 噪音预警: {}, 连续噪音个数: {}, 噪音所占百分比: {:.2f}%",
|
|
|
|
+ m_logBase, m_currentIsNoise, m_isNoiseWarning.load(), numCountinueNoise, percentNoise);
|
|
/* 噪音报警信息 */
|
|
/* 噪音报警信息 */
|
|
if(m_isNoise.load())
|
|
if(m_isNoise.load())
|
|
{
|
|
{
|