#include "GlobalInfo.h" #include #include #include "spdlog/spdlog.h" GlobalInfo::~GlobalInfo() { } /* 初始化全局信息 */ void GlobalInfo::initGlobalInfo() { /* 初始化文件夹 */ initDirectories(); /* 初始化数据 */ initData(); } void GlobalInfo::setMqttInfo(const QString& ip, int port) { m_mqttIP = ip; /* 设置MQTT服务器IP */ m_mqttPort = port; /* 设置MQTT服务器端口 */ } void GlobalInfo::setWebAPIInfo(const QString& url, const QString& id) { m_webAPIUrl = url; /* 设置WebAPI地址 */ m_webAPIID = id; /* 设置WebAPI ID */ } /* 初始化文件夹 */ void GlobalInfo::initDirectories() { /* 拼接文件夹路径 */ QString appDataPath = QCoreApplication::applicationDirPath(); appDataPath += "/ACAServerData"; // 应用数据目录 m_wavPath = appDataPath + "/" + m_dirWav; m_longWavPath = appDataPath + "/" + m_dirLongWav; m_alarmWavPath = appDataPath + "/" + m_dirAlarm; // m_configPath = appDataPath + "/" + m_dirConfig; /* 判断相关文件夹是否存在 */ QDir dirWav(m_wavPath); if (!dirWav.exists()) { dirWav.mkpath(m_wavPath); // 创建wav文件夹 } QDir dirLongWav(m_longWavPath); if (!dirLongWav.exists()) { dirLongWav.mkpath(m_longWavPath); // 创建录音长文件文件夹 } QDir dirAlarmWav(m_alarmWavPath); if (!dirAlarmWav.exists()) { dirAlarmWav.mkpath(m_alarmWavPath); // 创建报警文件夹 } /* 清空wav文件夹中的内容 */ dirWav.setFilter(QDir::Files | QDir::NoDotAndDotDot); QFileInfoList fileList = dirWav.entryInfoList(); if(!dirWav.removeRecursively()) { SPDLOG_WARN("清空WAV文件夹失败: {}", m_wavPath.toStdString()); } else { SPDLOG_INFO("清空WAV文件夹成功: {}", m_wavPath.toStdString()); } } /* 初始化默认数据 */ void GlobalInfo::initData() { // m_sampleRate = 48000; /* 采样率 */ // m_numChannels = 2; /* 声道数 */ // m_bitsPerSample = 16; /* 每个采样点的位数 */ // m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */ // m_wavFileDuration = 60; /* 默认是1分钟数据 */ /* 初始化环形队列元素数目 */ // m_queueElementCount = 180; /* 默认是3分钟数据 */ /* 噪音检测元素的大小,默认是2秒 */ // m_noiseElementDuration = 2; /* 平均音量计算所需要的秒数 */ // m_avgDBCalculateSeconds = 5; /* 默认计算音量的平均值是5秒 */ // m_pcmErrorPercent = 10; /* 音频不对称百分比 */ // m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */ /* 静音、过载、反相灵敏度,不知道为什么还要这里设置一个,在对比项参数里已经有这方面的东西了 */ // m_silentSensitivity = 100; // m_iPhaseSensitivity = 100; // m_overloadSensitivity = 100; }