main.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef MAIN_H
  2. #define MAIN_H
  3. #include <QApplication>
  4. #include <FelgoApplication>
  5. #include <QQmlApplicationEngine>
  6. #include <QtQml>
  7. #include <QQuickItem>
  8. #include <QTabBar>
  9. #include <QDebug>
  10. #include <QGeoPositionInfo>
  11. #include <QGeoPositionInfoSource>
  12. #include <QGeoSatelliteInfoSource>
  13. #include <QGeoCoordinate>
  14. #include <QString>
  15. #include <QtCore>
  16. #include <QDir>
  17. #include <QFileInfo>
  18. #include <QtCore/private/qandroidextras_p.h>
  19. #include <QThread>
  20. #include <QStandardPaths>
  21. #include <qjniobject.h>
  22. #include <QtTextToSpeech/QTextToSpeech>
  23. #include <QtMultimedia/QMediaPlayer>
  24. #include <QAudioOutput>
  25. //JSON
  26. #include <QJsonDocument>
  27. #include <opencv2/core/core.hpp>
  28. #include <opencv2/imgcodecs/imgcodecs.hpp>
  29. #include <opencv2/highgui/highgui.hpp>
  30. #include <opencv2/calib3d.hpp>
  31. #include <opencv2/stitching.hpp>
  32. #include <opencv2/xfeatures2d.hpp>
  33. #include <opencv2/features2d/features2d.hpp>
  34. #include <opencv2/xfeatures2d/nonfree.hpp>
  35. #define APP_VERSION "2.8.39"
  36. //【主板固件路径必须唯一】FTP 下载(.rbl 落盘) 与 ymodem 发送必须指向同一个文件。
  37. // 历史缺陷: main.cpp 下载到 <appDataPath>/rtthread.rbl
  38. // (= .../Android/data/com.yfkj.bzyv1/files/rtthread.rbl),
  39. // 而 main.cpp / mserial.cpp 里传给 ymodem 的是 GenericDataLocation+"/rtthread.rbl"
  40. // (= /storage/emulated/0/rtthread.rbl)。
  41. // 于是每次升级发送的都是根目录下那个历史遗留旧包; 主板 bootloader 比对 RBL 头版本
  42. // 发现与当前运行版本相同, 直接跳过搬运(= 打印 "No upgrade: fm_area[x] == app[x]"),
  43. // 现场表现为"升级流程走完了, 但版本号没变", 且没有任何报错。
  44. #define BZY_APP_FILES_DIR "/Android/data/com.yfkj.bzyv1/files/"
  45. static inline QString otaFirmwarePath()
  46. {
  47. return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
  48. + QString::fromLatin1(BZY_APP_FILES_DIR "rtthread.rbl");
  49. }
  50. #define AUFOCU_VIDEO 1
  51. using namespace std;
  52. #pragma pack(push,4) //保存对齐状态设定为4字节对齐
  53. using namespace cv;
  54. //全局变量类继承自QObject,用于qml访问
  55. class param
  56. {
  57. public:
  58. //explicit param();
  59. //db表Q_DECL_ALIGN(1)
  60. static QString table_mqtt;
  61. static QString table_mqtt_other;
  62. static QString table_ftp;
  63. static QString table_ftp_other;
  64. static QString table_location;
  65. static QString table_camera;
  66. static QString table_config;
  67. //type
  68. static QString dtype;
  69. static QString imei;
  70. //sim
  71. static QString iccid;
  72. static QString csq;
  73. //mqtt
  74. static QString mqtt_main_ip;
  75. static QString mqtt_other_ip;
  76. static int mqtt_main_port;
  77. static int mqtt_other_port;
  78. static int mqtt_main_keepalive;
  79. static int mqtt_other_keepalive;
  80. static int mqtt_main_qos;
  81. static int mqtt_other_qos;
  82. static QString mqtt_main_clientid;
  83. static QString mqtt_other_clientid;
  84. static QString mqtt_main_uid;
  85. static QString mqtt_other_uid;
  86. static QString mqtt_main_pwd;
  87. static QString mqtt_other_pwd;
  88. static QString mqtt_main_sub;
  89. static QString mqtt_other_sub;
  90. static QString mqtt_main_pub;
  91. static QString mqtt_other_pub;
  92. static QString mqtt_main_offline;
  93. static QString mqtt_other_offline;
  94. static int dat_f_main; //数据上传间隔,单位。分钟
  95. static int dat_f_other;
  96. //ftp
  97. static QString ftp_main_ip;
  98. static QString ftp_other_ip;
  99. static int ftp_main_port;
  100. static int ftp_other_port;
  101. static QString ftp_main_dir;
  102. static QString ftp_other_dir;
  103. static QString ftp_main_uid;
  104. static QString ftp_other_uid;
  105. static QString ftp_main_pwd;
  106. static QString ftp_other_pwd;
  107. static int ftp_main_mode; //主动模式? 被动模式
  108. static int ftp_other_mode; //主动模式? 被动模式
  109. //location
  110. static QString gps_state;
  111. static QString lbs_lat;
  112. static QString lbs_lng;
  113. static QString gps_lat;
  114. static QString gps_lng;
  115. //环境温湿度(MCU 上报 ext.at/ah 的最新值),用于图片水印"温湿度 [20℃,65%RH]"
  116. static QString env_temp;
  117. static QString env_humi;
  118. static QString gps_elevation;
  119. //Android 面板 GNSS 卫星数(可视/已用,main.cpp GPSInfo 经 QGeoSatelliteInfoSource 写入)
  120. static QString gps_sat_view;
  121. static QString gps_sat_used;
  122. //camera&photo
  123. static QString camera_type; //相机类型
  124. static QString stitch_mode; //拼接模式
  125. static int stitch_photonum; //拼接数量
  126. static int photo_width; //图片宽度
  127. static int photo_height; //图片高度
  128. static QString auto_focus; //对焦,全流程
  129. static QString movZ_f_l;
  130. static QString movZ_b_l;
  131. static QString movX_f_l;
  132. static QString movX_b_l;
  133. static int camera_tc; //已采集图片数量
  134. static QStringList ptlist; //存放图片路径
  135. static QStringList ptlist_res; //存放图片拼接结果路径
  136. static int jsonCacheEnable;
  137. static int imageCacheEnable;;
  138. static int maxJsonEntries;
  139. static int maxImageEntries;
  140. static int x_init;
  141. static int y_init;
  142. //景深融合开关(1=开 0=关,默认开):MQTT fusion_sw 下发,持久化在 sqlite config.fusion_enable
  143. //关闭时录制视频只分析最清晰帧并上传,跳过景深融合
  144. static int fusion_enable;
  145. //对焦/融合算法选择(MQTT focus_algo 下发,持久化在 sqlite config.focus_algo)
  146. // 0 = SLView 引导滤波融合 GFF(默认)
  147. // 1 = SLView 多尺度金字塔融合 MS
  148. // 2 = 本工程原有算法(AGD 多尺度权重 + Laplacian/Tenengrad/Brenner 加权评分)
  149. //同时决定两处:①帧评分 evaluateFocusScore 的度量 ②fuseAdvanced 的融合链路
  150. static int focus_algo;
  151. //网络
  152. static bool net_alive;
  153. static QString net_name;
  154. static QString net_description;
  155. static QString net_mac;
  156. static QString net_ipv4;
  157. static int datupload_remain;
  158. //=================== 图片路径列表的线程安全访问 ===================
  159. //【为什么需要】ptlist / ptlist_res 是 QStringList(隐式共享 + 堆数组),
  160. // 跨线程 clear() 与 append() 并发是真实崩溃点(引用计数非原子 + 数组重分配):
  161. // - 相机/分析线程: cameramanager.cpp 拍照后 append
  162. // - 串口线程: mserial.cpp 收到 auto_takephoto/autofocus 指令时 clear
  163. // - MQTT 线程: mqtthandler.cpp 收到 reset 指令时 clear
  164. // - GUI 线程: ImageStitcher 通过 Qt property 整体赋值
  165. // 串口指令可在采集流程中途到达,与相机线程的 append 直接竞争。
  166. //【范围】只保护 QStringList 这两个最容易崩的成员(append/clear 会真分配内存);
  167. // 其余 QString/int 成员为整体赋值,撕裂风险低,待后续按需收敛。
  168. static QMutex& photoListMutex();
  169. //以下两个便捷接口请优先于直接访问 param::ptlist / param::ptlist_res
  170. static void appendPhotoPath(const QString &path);
  171. static void clearPhotoLists();
  172. static QStringList photoPathsSnapshot();
  173. static int photoPathCount();
  174. private:
  175. };
  176. #pragma pack(pop)
  177. #endif // MAIN_H