GlobalInfo.cpp 3.0 KB

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