GlobalInfo.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "GlobalInfo.h"
  2. #include <QCoreApplication>
  3. #include <QDir>
  4. #include "spdlog/spdlog.h"
  5. GlobalInfo::~GlobalInfo()
  6. {
  7. }
  8. /* 初始化全局信息 */
  9. void GlobalInfo::init()
  10. {
  11. /* 初始化文件夹 */
  12. initDirectories();
  13. /* 初始化数据 */
  14. initData();
  15. }
  16. /* 清空历史文件夹 */
  17. void GlobalInfo::clearHistoryDirectories()
  18. {
  19. QDir dir(m_wavPath);
  20. if(dir.exists())
  21. {
  22. dir.removeRecursively(); // 删除整个目录及其内容
  23. }
  24. dir.mkpath(m_wavPath); // 重新创建目录
  25. dir.setPath(m_longWavPath);
  26. if(dir.exists())
  27. {
  28. dir.removeRecursively();
  29. }
  30. dir.mkpath(m_longWavPath);
  31. dir.setPath(m_alarmWavPath);
  32. if(dir.exists())
  33. {
  34. dir.removeRecursively();
  35. }
  36. dir.mkpath(m_alarmWavPath);
  37. }
  38. void GlobalInfo::setMqttInfo(const QString& ip, int port)
  39. {
  40. m_mqttIP = ip; /* 设置MQTT服务器IP */
  41. m_mqttPort = port; /* 设置MQTT服务器端口 */
  42. }
  43. void GlobalInfo::setWebAPIInfo(const QString& url, const QString& id)
  44. {
  45. m_webAPIUrl = url; /* 设置WebAPI地址 */
  46. m_webAPIID = id; /* 设置WebAPI ID */
  47. }
  48. /* 初始化文件夹 */
  49. void GlobalInfo::initDirectories()
  50. {
  51. /* 拼接文件夹路径,确保最后以 / 结尾 */
  52. if(!m_rootPath.endsWith('/'))
  53. {
  54. m_rootPath += '/';
  55. }
  56. // QString appDataPath = m_rootPath;
  57. // appDataPath += "/ACAServerData"; // 应用数据目录
  58. m_wavPath = m_rootPath + m_dirWav;
  59. m_longWavPath = m_rootPath + m_dirLongWav;
  60. m_alarmWavPath = m_rootPath + m_dirAlarm;
  61. /* 判断相关文件夹是否存在 */
  62. QDir dirWav(m_wavPath);
  63. if (!dirWav.exists()) {
  64. dirWav.mkpath(m_wavPath); // 创建wav文件夹
  65. }
  66. QDir dirLongWav(m_longWavPath);
  67. if (!dirLongWav.exists()) {
  68. dirLongWav.mkpath(m_longWavPath); // 创建录音长文件文件夹
  69. }
  70. QDir dirAlarmWav(m_alarmWavPath);
  71. if (!dirAlarmWav.exists()) {
  72. dirAlarmWav.mkpath(m_alarmWavPath); // 创建报警文件夹
  73. }
  74. /* 清空wav文件夹中的内容 */
  75. dirWav.setFilter(QDir::Files | QDir::NoDotAndDotDot);
  76. QFileInfoList fileList = dirWav.entryInfoList();
  77. if(!dirWav.removeRecursively())
  78. {
  79. SPDLOG_WARN("清空WAV文件夹失败: {}", m_wavPath.toStdString());
  80. } else {
  81. SPDLOG_INFO("清空WAV文件夹成功: {}", m_wavPath.toStdString());
  82. }
  83. }
  84. /* 初始化默认数据 */
  85. void GlobalInfo::initData()
  86. {
  87. // m_sampleRate = 48000; /* 采样率 */
  88. // m_numChannels = 2; /* 声道数 */
  89. // m_bitsPerSample = 16; /* 每个采样点的位数 */
  90. // m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */
  91. // m_wavFileDuration = 60; /* 默认是1分钟数据 */
  92. /* 初始化环形队列元素数目 */
  93. // m_queueElementCount = 180; /* 默认是3分钟数据 */
  94. /* 噪音检测元素的大小,默认是2秒 */
  95. // m_noiseElementDuration = 2;
  96. /* 平均音量计算所需要的秒数 */
  97. // m_avgDBCalculateSeconds = 5; /* 默认计算音量的平均值是5秒 */
  98. // m_pcmErrorPercent = 10; /* 音频不对称百分比 */
  99. // m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */
  100. /* 静音、过载、反相灵敏度,不知道为什么还要这里设置一个,在对比项参数里已经有这方面的东西了 */
  101. // m_silentSensitivity = 100;
  102. // m_iPhaseSensitivity = 100;
  103. // m_overloadSensitivity = 100;
  104. }