GlobalInfo.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "GlobalInfo.h"
  2. #include <QCoreApplication>
  3. #include <QDir>
  4. GlobalInfo::~GlobalInfo()
  5. {
  6. }
  7. /* 初始化全局信息 */
  8. void GlobalInfo::initGlobalInfo()
  9. {
  10. /* 初始化文件夹 */
  11. initDirectories();
  12. /* 初始化数据 */
  13. initData();
  14. }
  15. void GlobalInfo::setMqttInfo(const QString& ip, int port)
  16. {
  17. m_mqttIP = ip; /* 设置MQTT服务器IP */
  18. m_mqttPort = port; /* 设置MQTT服务器端口 */
  19. }
  20. void GlobalInfo::setWebAPIInfo(const QString& url, const QString& id)
  21. {
  22. m_webAPIUrl = url; /* 设置WebAPI地址 */
  23. m_webAPIID = id; /* 设置WebAPI ID */
  24. }
  25. /* 初始化文件夹 */
  26. void GlobalInfo::initDirectories()
  27. {
  28. /* 拼接文件夹路径 */
  29. QString appDataPath = QCoreApplication::applicationDirPath();
  30. m_wavPath = appDataPath + "/" + m_dirWav;
  31. m_longWavPath = appDataPath + "/" + m_dirLongWav;
  32. m_alarmWavPath = appDataPath + "/" + m_dirAlarm;
  33. m_configPath = appDataPath + "/" + m_dirConfig;
  34. /* 判断相关文件夹是否存在 */
  35. QDir dirWav(m_wavPath);
  36. if (!dirWav.exists()) {
  37. dirWav.mkpath(m_wavPath); // 创建wav文件夹
  38. }
  39. QDir dirLongWav(m_longWavPath);
  40. if (!dirLongWav.exists()) {
  41. dirLongWav.mkpath(m_longWavPath); // 创建录音长文件文件夹
  42. }
  43. QDir dirAlarmWav(m_alarmWavPath);
  44. if (!dirAlarmWav.exists()) {
  45. dirAlarmWav.mkpath(m_alarmWavPath); // 创建报警文件夹
  46. }
  47. /* 清空wav文件夹中的内容 */
  48. dirWav.setFilter(QDir::Files | QDir::NoDotAndDotDot);
  49. QFileInfoList fileList = dirWav.entryInfoList();
  50. for (const QFileInfo &fileInfo : fileList)
  51. {
  52. QFile::remove(fileInfo.filePath()); // 删除文件
  53. }
  54. }
  55. /* 初始化默认数据 */
  56. void GlobalInfo::initData()
  57. {
  58. m_sampleRate = 48000; /* 采样率 */
  59. m_numChannels = 2; /* 声道数 */
  60. m_bitsPerSample = 16; /* 每个采样点的位数 */
  61. m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */
  62. m_wavQueueElementCount = 60; /* 环形队列元素数目,默认是1分钟数据 */
  63. m_wavFileDuration = 60; /* 默认是1分钟数据 */
  64. /* 初始化环形队列元素数目 */
  65. m_wavQueueElementCount = 60; /* 默认是1分钟数据 */
  66. m_pcmErrorPercent = 10; /* 音频不对称百分比 */
  67. m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */
  68. }