#include "GlobalInfo.h" #include #include 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(); 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(); for (const QFileInfo &fileInfo : fileList) { QFile::remove(fileInfo.filePath()); // 删除文件 } } /* 初始化默认数据 */ void GlobalInfo::initData() { m_sampleRate = 48000; /* 采样率 */ m_numChannels = 2; /* 声道数 */ m_bitsPerSample = 16; /* 每个采样点的位数 */ m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */ m_wavQueueElementCount = 60; /* 环形队列元素数目,默认是1分钟数据 */ m_wavFileDuration = 60; /* 默认是1分钟数据 */ /* 初始化环形队列元素数目 */ m_wavQueueElementCount = 60; /* 默认是1分钟数据 */ m_pcmErrorPercent = 10; /* 音频不对称百分比 */ m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */ }