123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "GlobalInfo.h"
- #include <QCoreApplication>
- #include <QDir>
- #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_pcmErrorPercent = 10; /* 音频不对称百分比 */
- m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */
- }
|