GlobalInfo.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. QString appDataPath = QCoreApplication::applicationDirPath();
  31. appDataPath += "/ACAServerData"; // 应用数据目录
  32. m_wavPath = appDataPath + "/" + m_dirWav;
  33. m_longWavPath = appDataPath + "/" + m_dirLongWav;
  34. m_alarmWavPath = appDataPath + "/" + m_dirAlarm;
  35. // m_configPath = appDataPath + "/" + m_dirConfig;
  36. /* 判断相关文件夹是否存在 */
  37. QDir dirWav(m_wavPath);
  38. if (!dirWav.exists()) {
  39. dirWav.mkpath(m_wavPath); // 创建wav文件夹
  40. }
  41. QDir dirLongWav(m_longWavPath);
  42. if (!dirLongWav.exists()) {
  43. dirLongWav.mkpath(m_longWavPath); // 创建录音长文件文件夹
  44. }
  45. QDir dirAlarmWav(m_alarmWavPath);
  46. if (!dirAlarmWav.exists()) {
  47. dirAlarmWav.mkpath(m_alarmWavPath); // 创建报警文件夹
  48. }
  49. /* 清空wav文件夹中的内容 */
  50. dirWav.setFilter(QDir::Files | QDir::NoDotAndDotDot);
  51. QFileInfoList fileList = dirWav.entryInfoList();
  52. if(!dirWav.removeRecursively())
  53. {
  54. SPDLOG_WARN("清空WAV文件夹失败: {}", m_wavPath.toStdString());
  55. } else {
  56. SPDLOG_INFO("清空WAV文件夹成功: {}", m_wavPath.toStdString());
  57. }
  58. }
  59. /* 初始化默认数据 */
  60. void GlobalInfo::initData()
  61. {
  62. // m_sampleRate = 48000; /* 采样率 */
  63. // m_numChannels = 2; /* 声道数 */
  64. // m_bitsPerSample = 16; /* 每个采样点的位数 */
  65. // m_oneSecondCount = m_sampleRate * m_numChannels * 2; /* 48khz * 2字节/采样点 * 2声道 */
  66. // m_wavFileDuration = 60; /* 默认是1分钟数据 */
  67. /* 初始化环形队列元素数目 */
  68. // m_queueElementCount = 180; /* 默认是3分钟数据 */
  69. /* 噪音检测元素的大小,默认是2秒 */
  70. // m_noiseElementDuration = 2;
  71. /* 平均音量计算所需要的秒数 */
  72. // m_avgDBCalculateSeconds = 5; /* 默认计算音量的平均值是5秒 */
  73. // m_pcmErrorPercent = 10; /* 音频不对称百分比 */
  74. // m_pcmLessPercent = 0; /* 音频少于百分比,默认不开放这个功能 */
  75. /* 静音、过载、反相灵敏度,不知道为什么还要这里设置一个,在对比项参数里已经有这方面的东西了 */
  76. // m_silentSensitivity = 100;
  77. // m_iPhaseSensitivity = 100;
  78. // m_overloadSensitivity = 100;
  79. }