main.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. #include <main.h>
  2. //#include "userfunc.h"
  3. #include <cameramanager.h>
  4. #include <mqtthandler.h>
  5. #include <mserial.h>
  6. #include <mysql.h>
  7. #include <EasyTableModel.h>
  8. #include <customitem.h>
  9. #include <m_loger.h>
  10. #include <TreeModel.h>
  11. #include <app_curlFunc.h>
  12. #include <QQuickWindow>
  13. //uncomment this line to add the Live Client Module and use live reloading with your custom C++ code
  14. //#include <FelgoLiveClient>
  15. class param;
  16. QString param::table_mqtt = "mqtt"; //mqtt配置表
  17. QString param::table_mqtt_other = "mqtt_other"; //mqtt对接配置表
  18. QString param::table_ftp = "ftp"; //FTP配置表
  19. QString param::table_ftp_other = "ftp_other"; //FTP对接配置表
  20. QString param::table_camera = "camera"; //相机参数配置表
  21. QString param::table_location = "location"; //定位信息参数配置表
  22. QString param::table_config = "config"; //参数配置表
  23. void traverseQmlObject(QObject *qmlObject, int depth = 0) {
  24. QString indentation = QString(" ").repeated(depth);
  25. qDebug() << indentation << "Type:" << qmlObject->metaObject()->className()
  26. << "Name:" << qmlObject->objectName();
  27. for (QObject *child : qmlObject->children()) {
  28. traverseQmlObject(child, depth + 1);
  29. }
  30. }
  31. class MyCppClass : public QObject {
  32. Q_OBJECT
  33. public:
  34. void setQmlRootObject(QObject *rootObject) {
  35. m_qmlRootObject = rootObject;
  36. }
  37. void JumpToCamera(){
  38. }
  39. public slots:
  40. void qmlSlot() {
  41. LOG("Received from QML");
  42. emit recvqmlslot();
  43. }
  44. void systemPage(){
  45. LOG("systemPage");
  46. emit tosystempage();
  47. }
  48. void openbar_btnClicked(){
  49. LOG("openbar_btnClicked");
  50. emit opensystembar();
  51. }
  52. void closebar_btnClicked(){
  53. LOG("closebar_btnClicked");
  54. emit closesystembar();
  55. }
  56. void opennav_btnClicked(){
  57. LOG("opennav_btnClicked");
  58. emit opensystemnav();
  59. }
  60. void closenav_btnClicked(){
  61. LOG("closenav_btnClicked");
  62. emit closesystemnav();
  63. }
  64. signals:
  65. void recvqmlslot();
  66. void tosystempage();
  67. void opensystembar();
  68. void closesystembar();
  69. void opensystemnav();
  70. void closesystemnav();
  71. private:
  72. QObject *m_qmlRootObject = nullptr;
  73. };
  74. class GPSInfo : public QObject
  75. {
  76. Q_OBJECT
  77. public:
  78. double nowGroundSpeed=0.0;
  79. double nowVerticalSpeed=0.0;
  80. double nowMagneticVariation=0.0;
  81. double nowHorizontalAccuracy=0.0;
  82. double nowVerticalAccuracy=0.0;
  83. double nowLongitude=0.0;
  84. double nowLatitude=0.0;
  85. double nowDirection=0.0;
  86. QString nowTimes="";
  87. int recv_cnt = 0;
  88. QGeoPositionInfoSource *positionSource;
  89. public:
  90. GPSInfo(SqliteOperator *db,QObject *parent = nullptr)
  91. : QObject(parent) // 注入外部数据库对象
  92. , gpsConfig(db)
  93. {
  94. param::gps_state = "0";
  95. positionSource = QGeoPositionInfoSource::createDefaultSource(this);
  96. //QGeoSatelliteInfoSource *satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
  97. if (positionSource) {
  98. connect(positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
  99. this, SLOT(positionUpdated(QGeoPositionInfo)));
  100. positionSource->setUpdateInterval(1000);//设置刷新时间 单位毫秒
  101. positionSource->startUpdates();//启动设备
  102. }
  103. }
  104. signals:
  105. void position_success();
  106. private:
  107. SqliteOperator *gpsConfig = nullptr; // 不再在内部创建
  108. private slots://槽函数中实现了GPS部分信息的读取
  109. void positionUpdated(const QGeoPositionInfo &info)
  110. {
  111. nowLongitude = info.coordinate().longitude();//经度
  112. nowLatitude = info.coordinate().latitude();//纬度
  113. nowDirection = info.attribute(QGeoPositionInfo::Direction);
  114. nowGroundSpeed = info.attribute(QGeoPositionInfo::GroundSpeed);
  115. nowVerticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed);
  116. nowMagneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation);
  117. nowHorizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy);
  118. nowVerticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy);
  119. nowTimes = info.timestamp().toString();
  120. if(param::gps_lat.contains(".")&&param::gps_lat.size()>3){
  121. param::gps_state = "1";
  122. recv_cnt++;
  123. if(recv_cnt==20){ //定位成功后120S把定位信息保存到数据库中
  124. emit position_success();
  125. gpsConfig->OpenDb();
  126. if(gpsConfig->isTableExist(param::table_location)){
  127. gpsConfig->UpdateData(param::table_location,"gps_lat",param::gps_lat);
  128. gpsConfig->UpdateData(param::table_location,"gps_lng",param::gps_lng);
  129. }
  130. gpsConfig->CloseDb();
  131. positionSource->stopUpdates();
  132. }
  133. }
  134. param::gps_lat = QString::number(nowLatitude);
  135. param::gps_lng = QString::number(nowLongitude);
  136. LOG("经度:{}",nowLongitude);
  137. LOG("纬度:{}",nowLatitude);
  138. LOG("角度:{}",nowDirection);
  139. LOG("地表速度:{}",nowGroundSpeed);
  140. LOG("垂直速度:{}",nowVerticalSpeed);
  141. LOG("磁偏角:{}",nowMagneticVariation);
  142. LOG("水平精度:{}",nowHorizontalAccuracy);
  143. LOG("垂直精度:{}",nowVerticalAccuracy);
  144. LOG("定位次数:{}",recv_cnt);
  145. }
  146. };
  147. void sendBroadcastFromQt(QString btn_type) {
  148. //QJniObject activity = QJniObject::callStaticObjectMethod("com/yfkj/cb/Q6iot/MyQtActivity","getCurrentActivity","()Landroid/app/Activity;");
  149. auto qtContext = QJniObject(QNativeInterface::QAndroidApplication::context()); //activity
  150. //QJniObject qtContext = activity.callObjectMethod("getApplicationContext","()Landroid/content/Context;");
  151. if (qtContext.isValid()) {
  152. if(btn_type=="sleep"){
  153. QJniObject jClass("com/yfkj/bzyv1/Backlight");
  154. //jboolean ret = jClass.callMethod<jboolean>("checkWriteSettingPermission","(Landroid/content/Context;I)Z",qtContext.object(),100);
  155. jClass.callMethod<void>("setScreenLight","(Landroid/content/Context;I)V",qtContext.object(),100);
  156. }
  157. //QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  158. QJniObject jClass("com/yfkj/bzyv1/Backlight");
  159. if(btn_type=="openbar_btn"){
  160. jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),1);
  161. }else if(btn_type=="closebar_btn"){
  162. jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),0);
  163. }else if(btn_type=="closenav_btn"){
  164. jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),0);
  165. }else if(btn_type=="opennav_btn"){
  166. jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),1);
  167. }else if(btn_type=="imei"){
  168. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  169. QJniObject java_imei= jClass.callObjectMethod("getAndroidIMEI","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
  170. if(java_imei.isValid()){
  171. QString imei = java_imei.toString();
  172. if(!imei.isEmpty()&&param::imei.isEmpty()){
  173. param::imei = imei;
  174. }
  175. LOG("IMEI:{}",param::imei.toStdString());
  176. }
  177. }else if(btn_type=="csq"){
  178. jint rsrp = QJniObject::callStaticMethod<jint>("com/yfkj/bzyv1/StatusBarCtr",
  179. "getRsrp",
  180. "(Landroid/content/Context;)I",
  181. qtContext.object());
  182. LOG("getRsrp:{}",rsrp);
  183. }else if(btn_type=="iccid"){
  184. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  185. QJniObject iccid_java = jClass.callObjectMethod("getICCID","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
  186. if(iccid_java.isValid()){
  187. QString iccid = iccid_java.toString();
  188. if(!iccid.isEmpty()){
  189. param::iccid = iccid;
  190. }
  191. LOG("ICCID:{}",param::iccid.toStdString());
  192. }
  193. }else if(btn_type=="install"){
  194. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  195. qDebug() << "install process start!";
  196. jClass.callMethod<void>("installApp","(Landroid/content/Context;)V",qtContext.object());
  197. }else if(btn_type=="rebootSystem"){
  198. jClass.callMethod<void>("rebootSystem","(Landroid/content/Context;)V",qtContext.object());
  199. }else if(btn_type=="service"){
  200. qDebug() <<"启动android服务";
  201. QAndroidIntent serviceIntent(qtContext.object(),
  202. "com/yfkj/bzyv1/QtAndroidService");
  203. QJniObject result = qtContext.callObjectMethod(
  204. "startService",
  205. "(Landroid/content/Intent;)Landroid/content/ComponentName;",
  206. serviceIntent.handle().object());
  207. }
  208. }
  209. }
  210. // 定义函数:设置每日8:00重启的定时器
  211. auto setDailyRebootTimer = []() {
  212. // 获取当前时间(本地时间)
  213. QDateTime currentTime = QDateTime::currentDateTime();
  214. // 构造当天8:00的目标时间(基于本地时间的0点+8小时)
  215. QDateTime targetTime = currentTime.date().startOfDay().addSecs(8 * 3600); // 8:00 = 8 * 3600秒
  216. // 如果当前时间已过今日8:00,目标时间调整为次日8:00
  217. if (currentTime >= targetTime) {
  218. targetTime = targetTime.addDays(1); // 加1天
  219. }
  220. // 计算当前时间到目标时间的毫秒间隔
  221. qint64 intervalMs = currentTime.msecsTo(targetTime);
  222. // 设置单次定时器,触发后执行重启逻辑,并重新设置下一日的定时器
  223. QTimer::singleShot(intervalMs, []() {
  224. LOG("触发每日8:00重启");
  225. sendBroadcastFromQt("rebootSystem"); // 发送重启广播
  226. // 注意:若需要严格每日执行,建议在重启前重新设置定时器(根据实际需求)
  227. // 若系统重启后会自动启动本程序,可省略此处(程序重启后会重新设置定时器)
  228. // setDailyRebootTimer();
  229. });
  230. };
  231. //adb shell input keyevent 26 // 224 关
  232. // 构建权限列表
  233. QStringList m_permissions = {
  234. "android.permission.WRITE_EXTERNAL_STORAGE",
  235. "android.permission.READ_EXTERNAL_STORAGE",
  236. "android.permission.MANAGE_EXTERNAL_STORAGE",
  237. "android.permission.ACCESS_MEDIA_LOCATION",
  238. "android.permission.CAMERA",
  239. "android.permission.ACCESS_FINE_LOCATION",
  240. "android.permission.ACCESS_COARSE_LOCATION",
  241. "android.permission.WRITE_SETTINGS",
  242. "android.permission.READ_PHONE_STATE",
  243. "android.permission.INTERNET",
  244. "android.permission.ACCESS_NETWORK_STATE",
  245. "android.permission.WAKE_LOCK",
  246. "android.permission.VIBRATE"
  247. };
  248. // ========== 全志A133P缓存清理函数(关键)==========
  249. void clearAllCaches() {
  250. #ifndef WIN32
  251. QDir dir;
  252. // ========== 1. 标准缓存位置 ==========
  253. QStringList cacheLocations = {
  254. QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
  255. QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation),
  256. QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation),
  257. QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
  258. };
  259. // ========== 2. Android特定缓存位置 ==========
  260. cacheLocations << QDir::homePath() + "/.cache";
  261. cacheLocations << QDir::homePath() + "/.local/share";
  262. // ========== 3. 所有需要清理的缓存目录 ==========
  263. QStringList cacheDirs = {
  264. "qmlsc", "qml", "rhi", "scenegraph", "shaders", "pipelines",
  265. "graphicsshadercache", "QtShaderCache", "QtQuick", "cache",
  266. "Qt", "shadercache", "textures", "graphics", "RenderCache",
  267. "ShaderCache", "TextureCache"
  268. };
  269. QStringList cacheFileFilters = {"*.qmlc", "*.jsc", "*.cache", "*.tmp"};
  270. // ========== 4. 遍历并清理 ==========
  271. for (const QString &cachePath : cacheLocations) {
  272. QDir cacheDir(cachePath);
  273. if (cacheDir.exists()) {
  274. qDebug() << "Scanning cache location:" << cachePath;
  275. // 清理指定目录
  276. for (const QString &subDir : cacheDirs) {
  277. QDir sub(cacheDir.filePath(subDir));
  278. if (sub.exists()) {
  279. sub.removeRecursively();
  280. qDebug() << "Cleared cache directory:" << sub.absolutePath();
  281. }
  282. }
  283. // 清理匹配的缓存文件
  284. cacheDir.setNameFilters(cacheFileFilters);
  285. QStringList files = cacheDir.entryList(QDir::Files);
  286. for (const QString &file : files) {
  287. cacheDir.remove(file);
  288. qDebug() << "Removed cache file:" << cacheDir.filePath(file);
  289. }
  290. }
  291. }
  292. // ========== 5. 清理临时文件 ==========
  293. QDir tempDir(QDir::tempPath());
  294. if (tempDir.exists()) {
  295. QStringList filters;
  296. filters << "Qt*" << "qml*" << "shader*" << "rhi*";
  297. tempDir.setNameFilters(filters);
  298. QStringList tempFiles = tempDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
  299. for (const QString &tempFile : tempFiles) {
  300. QFileInfo info(tempDir.filePath(tempFile));
  301. if (info.isDir()) {
  302. QDir(tempDir.filePath(tempFile)).removeRecursively();
  303. } else {
  304. tempDir.remove(tempFile);
  305. }
  306. qDebug() << "Removed temp file/dir:" << tempDir.filePath(tempFile);
  307. }
  308. }
  309. qDebug() << "All caches cleared successfully!";
  310. #endif
  311. }
  312. int main(int argc, char *argv[])
  313. {
  314. #if 0
  315. // ========== 第一阶段:在任何Qt对象创建前先清理所有缓存 ==========
  316. // 这是解决"第一次正常,第二次花屏"的关键!
  317. clearAllCaches();
  318. // ========== 全志A133P ARM32渲染修复(终极版)==========
  319. // 在QGuiApplication创建前设置环境变量
  320. // ========== 核心图形API配置 ==========
  321. qputenv("QSG_RHI_BACKEND", "opengl");
  322. qputenv("QSG_RENDERING_BACKEND", "opengl");
  323. qputenv("QT_QUICK_BACKEND", "opengl");
  324. // ========== OpenGL ES版本强制配置(全志A133P关键)==========
  325. qputenv("QT_OPENGL_FORCE_GLES2", "1"); // 强制使用OpenGL ES 2.0
  326. qputenv("QT_OPENGL_NO_ES3", "1"); // 禁用OpenGL ES 3.0
  327. qputenv("QT_OPENGL_NO_ES31", "1"); // 禁用OpenGL ES 3.1
  328. qputenv("QT_OPENGL_NO_ES32", "1"); // 禁用OpenGL ES 3.2
  329. // ========== 渲染循环配置 ==========
  330. qputenv("QSG_RENDER_LOOP", "basic"); // 使用basic渲染循环,ARM32更稳定
  331. // ========== 颜色格式配置(解决花屏关键)==========
  332. qputenv("QT_OPENGL_NO_BGRA", "1");
  333. qputenv("QT_QPA_EGLFS_FORCE888", "1"); // 强制24位色深
  334. // ========== 缓冲和缓存禁用(避免ARM32兼容性问题)==========
  335. qputenv("QSG_DISABLE_DEPTH_BUFFER", "1"); // 禁用深度缓冲
  336. qputenv("QSG_DISABLE_STENCIL_BUFFER", "1"); // 禁用模板缓冲
  337. qputenv("QSG_DISABLE_ATLAS", "1"); // 禁用纹理图集
  338. qputenv("QSG_DISABLE_MIPMAP", "1"); // 禁用MIP映射
  339. // ========== 所有类型的缓存完全禁用 ==========
  340. qputenv("QML_DISABLE_DISK_CACHE", "1"); // 禁用QML磁盘缓存
  341. qputenv("QML_FORCE_DISK_CACHE", "0");
  342. qputenv("QSG_RHI_DISABLE_PIPELINE_CACHE", "1"); // 禁用RHI管线缓存
  343. qputenv("QT_GL_USE_DISK_SHADER_CACHE", "0"); // 禁用磁盘着色器缓存
  344. qputenv("QSG_DISTANCEFIELD_CACHE_SIZE", "0"); // 禁用距离场缓存
  345. qputenv("QSG_TEXTURE_CACHE_SIZE", "0"); // 禁用纹理缓存
  346. qputenv("QSG_SHADER_CACHE_SIZE", "0"); // 禁用着色器缓存
  347. // ========== 更多缓存禁用设置 ==========
  348. qputenv("QT_DISABLE_SHADER_CACHE", "1"); // 禁用Qt着色器缓存
  349. qputenv("QT_DISABLE_OPENGL_SHADER_CACHE", "1"); // 禁用OpenGL着色器缓存
  350. qputenv("QSG_DISABLE_VBO_CACHE", "1"); // 禁用VBO缓存
  351. // ========== 渲染风格和质量(降低为最兼容级别)==========
  352. qputenv("QSG_SIMPLE_STYLE", "1"); // 使用简单渲染风格
  353. qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
  354. qputenv("QSG_ANTIALIASING_METHOD", "disabled"); // 禁用抗锯齿
  355. // ========== 调试和信息输出 ==========
  356. qputenv("QSG_INFO", "1");
  357. qputenv("QSG_VISUALIZE", "0");
  358. // ========== 软件渲染器禁用(确保使用硬件加速)==========
  359. qputenv("QSG_SOFTWARE_RENDERER", "0");
  360. // ========== EGL配置优化(全志A133P特定)==========
  361. qputenv("QT_QPA_EGLFS_ALWAYS_SET_MODE", "1");
  362. qputenv("QT_QPA_EGLFS_INTEGRATION", "none");
  363. #endif
  364. // ========== Android权限申请 ==========
  365. // 在应用启动时申请所有必要的权限
  366. // 使用正确的API逐个申请权限
  367. for (const QString &permission : m_permissions) {
  368. QtAndroidPrivate::checkPermission(permission);
  369. QtAndroidPrivate::requestPermission(permission);
  370. }
  371. INITLOG();
  372. sendBroadcastFromQt("sleep");
  373. QGuiApplication app(argc, argv);
  374. // ========== 第二阶段:QGuiApplication创建后再次清理缓存 ==========
  375. // 有些缓存只有在QGuiApplication创建后才能正确访问
  376. clearAllCaches();
  377. LOG("Second cache clear completed!");
  378. // ========== 全志A133P窗口配置优化(关键) ==========
  379. QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
  380. LOG("Graphics API forced: OpenGL");
  381. QQuickWindow::setDefaultAlphaBuffer(false); // 禁用透明缓冲
  382. //QQuickWindow::setPersistentOpenGLContext(false); // 不使用持久化GL上下文
  383. QQuickWindow::setSceneGraphBackend("opengl");
  384. MyCppClass myCppClass;
  385. #if WIN32
  386. QString subDirPath = "logs/run_log.txt";
  387. QString appDataPath ="./";
  388. #else
  389. // 获取应用程序内部存储空间路径
  390. QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Android/data/com.yfkj.bzyv1/files/";
  391. LOG("appDataPath:{}",appDataPath.toStdString());
  392. QString appPicPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Android/data/com.yfkj.bzyv1/files/Pictures";
  393. LOG("appPicPath:{}",appPicPath.toStdString());
  394. #endif
  395. sendBroadcastFromQt("iccid");
  396. sendBroadcastFromQt("csq");
  397. //创建并打开SQLite数据库
  398. QString db_config = "config.db";
  399. // QString db_data = "data.db";
  400. SqliteOperator *sqlConfig;
  401. sqlConfig = new SqliteOperator(db_config);
  402. sqlConfig->OpenDb();
  403. //判断数据表是否存在
  404. config_db_type config_class;
  405. if(!sqlConfig->isTableExist(param::table_mqtt)){
  406. sqlConfig->CreateTable(param::table_mqtt);
  407. //插入数据
  408. config_class.mqtt_db = {1,"bzy","8.136.98.49",61883,"","user","f335bf402c655ee5fd2b5300905124e","",0,60,"/yfkj/bzyL/s2c/","/yfkj/bzyL/c2s/","/yfkj/bzyL/offline/",10};
  409. sqlConfig->InsertData(config_class,param::table_mqtt);
  410. //查询全部数据
  411. sqlConfig->QueryAllData(param::table_mqtt);
  412. }else{
  413. sqlConfig->QueryAllData(param::table_mqtt);
  414. }
  415. if(param::imei.isEmpty()){
  416. sendBroadcastFromQt("imei");
  417. QTimer::singleShot(1000, [&]() {
  418. sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei);
  419. });
  420. }
  421. if(!sqlConfig->isTableExist(param::table_mqtt_other))
  422. {
  423. sqlConfig->CreateTable(param::table_mqtt_other);
  424. config_class.mqtt_db = {1,"bzy","0.0.0.0",1883,"","uid","pwd","clientid",0,60,"/yfkj/bzy/s2c/","/yfkj/bzy/c2s/","/yfkj/bzy/offline/",10};
  425. sqlConfig->InsertData(config_class,param::table_mqtt_other);
  426. //查询全部数据
  427. sqlConfig->QueryAllData(param::table_mqtt_other);
  428. }else{
  429. sqlConfig->QueryAllData(param::table_mqtt_other);
  430. }
  431. if(!sqlConfig->isTableExist(param::table_ftp))
  432. {
  433. sqlConfig->CreateTable(param::table_ftp);
  434. config_class.ftp_db = {1,"8.136.98.49",21,"","bzy_user","YFkj@6O2O",0};
  435. sqlConfig->InsertData(config_class,param::table_ftp);
  436. sqlConfig->QueryAllData(param::table_ftp);
  437. }else{
  438. sqlConfig->QueryAllData(param::table_ftp);
  439. }
  440. if(!sqlConfig->isTableExist(param::table_ftp_other))
  441. {
  442. sqlConfig->CreateTable(param::table_ftp_other);
  443. config_class.ftp_db = {1,"0.0.0.0",21,"","cbd_user","YFkj@6O2O",0};
  444. sqlConfig->InsertData(config_class,param::table_ftp_other);
  445. sqlConfig->QueryAllData(param::table_ftp_other);
  446. }else{
  447. sqlConfig->QueryAllData(param::table_ftp_other);
  448. }
  449. if(!sqlConfig->isTableExist(param::table_location))
  450. {
  451. sqlConfig->CreateTable(param::table_location);
  452. config_class.location_db = {1,"0","0","0","0","0"};
  453. sqlConfig->InsertData(config_class,param::table_location);
  454. sqlConfig->QueryAllData(param::table_location);
  455. }else{
  456. sqlConfig->QueryAllData(param::table_location);
  457. }
  458. //相机图像参数
  459. if(!sqlConfig->isTableExist(param::table_camera)){
  460. sqlConfig->CreateTable(param::table_camera);
  461. config_class.camera_db = {"hikrobot","static",2,1000,1000,"0","f80","b80","f80","b80"};
  462. sqlConfig->InsertData(config_class,param::table_camera);
  463. sqlConfig->QueryAllData(param::table_camera);
  464. }else{
  465. sqlConfig->QueryAllData(param::table_camera);
  466. }
  467. //配置
  468. if(!sqlConfig->isTableExist(param::table_config)){
  469. sqlConfig->CreateTable(param::table_config);
  470. config_class.config_db = {1,1,1000,500,0,0};
  471. sqlConfig->InsertData(config_class,param::table_config);
  472. sqlConfig->QueryAllData(param::table_config);
  473. }else{
  474. sqlConfig->QueryAllData(param::table_config);
  475. }
  476. sqlConfig->CloseDb();
  477. //InsertJson_mqtt();
  478. qRegisterMetaType<QByteArray>("QByteArray");
  479. FelgoApplication felgo;
  480. QQmlApplicationEngine engine;
  481. felgo.initialize(&engine);
  482. felgo.setLicenseKey("6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C8B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397");
  483. LOG("信息(Info)");
  484. TreeModel model;
  485. engine.setOfflineStoragePath(appDataPath); //设置数据库存储路径
  486. engine.rootContext()->setContextProperty("appdir", qApp->applicationDirPath()); //使用QApplication::applicationDirPath()获取,并注册到qml中
  487. engine.rootContext()->setContextProperty("treeModel",&model);
  488. qmlRegisterType<EasyTableModel>("EasyModel",1,0,"EasyTableModel"); //注册C++模块到QML中
  489. qmlRegisterType<DatabaseInterface>("com.example.database", 1, 0, "DatabaseInterface");
  490. qmlRegisterType<CustomItem>("ExampleCustomMaterial",1,0,"CustomItem");
  491. // Set an optional license key from project file
  492. // This does not work if using Felgo Live, only for Felgo Cloud Builds and local builds
  493. //felgo.setLicenseKey(PRODUCT_LICENSE_KEY);
  494. // use this during development
  495. // for PUBLISHING, use the entry point below
  496. felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
  497. // use this instead of the above call to avoid deployment of the qml files and compile them into the binary with qt's resource system qrc
  498. // this is the preferred deployment option for publishing games to the app stores, because then your qml files and js files are protected
  499. // to avoid deployment of your qml files and images, also comment the DEPLOYMENTFOLDERS command in the .pro file
  500. // also see the .pro file for more details
  501. //felgo.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml"));
  502. const QUrl url(felgo.mainQmlFileName());
  503. Qt6QCamera::Frames::registerQmlType();
  504. SerialThread serialThread;
  505. serialThread.start();
  506. engine.rootContext()->setContextProperty("serial", &serialThread);
  507. CurlFtpUploader uploader_ftp; // 成员变量
  508. QString remotepath ="/photo_hard/" + param::imei;
  509. uploader_ftp.setFtpParams("bzy_user", "YFkj@6O2O", "8.136.98.49", 21, remotepath);
  510. MqttHandler mqttHandler;
  511. mqttHandler.storage()->setJsonCacheEnabled(param::jsonCacheEnable);
  512. mqttHandler.storage()->setImageCacheEnabled(param::imageCacheEnable);
  513. mqttHandler.storage()->setMaxJsonEntries(param::maxJsonEntries);
  514. mqttHandler.storage()->setMaxImageEntries(param::maxImageEntries);
  515. CurlHandler curlHandler("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/armv7a/app.apk",appDataPath+"/app.apk"); //app升级
  516. NetworkInfoHelper networkMonitor;
  517. engine.rootContext()->setContextProperty("mqtt", &mqttHandler);
  518. engine.rootContext()->setContextProperty("curl", &curlHandler);
  519. //engine.rootContext()->setContextProperty("ymodem",serialThread.getYmodem());
  520. engine.rootContext()->setContextProperty("curl_picture",&uploader_ftp);
  521. engine.rootContext()->setContextProperty("networkMonitor", &networkMonitor);
  522. QObject::connect(&serialThread,&SerialThread::dataUpload,&mqttHandler,&MqttHandler::publish_m); //串口到MQTT
  523. QObject::connect(&mqttHandler,&MqttHandler::dataReceived,&serialThread,&SerialThread::mqtttoserial);//MQTT到串口
  524. QObject::connect(&networkMonitor,&NetworkInfoHelper::reachabilityChanged,[&](QNetworkInformation::Reachability newReachability){
  525. if(newReachability==QNetworkInformation::Reachability::Online){
  526. WARN("网络连接!");
  527. param::net_alive = 1;
  528. }else{
  529. param::net_alive = 0;
  530. WARN("网络断开!");
  531. mqttHandler.disconnectFromBroker();
  532. }
  533. });
  534. QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
  535. &mqttHandler,&MqttHandler::storage_Picture);
  536. QObject::connect(&mqttHandler, &MqttHandler::signal_reupload_image,
  537. &uploader_ftp,&CurlFtpUploader::uploadFileAsync);
  538. QObject::connect(&mqttHandler, &MqttHandler::signal_upload_log,
  539. &uploader_ftp,&CurlFtpUploader::uploadFileAsync);
  540. QObject::connect(&mqttHandler,&MqttHandler::updateStm32,[&](){
  541. curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/A7/STM32/Application_BZYV2.rbl");
  542. curlHandler.setfilepath(appDataPath+"/rtthread.rbl");
  543. curlHandler.settype("主板升级文件更新");
  544. curlHandler.start();
  545. //sendBroadcastFromQt("install");
  546. });
  547. QObject::connect(&mqttHandler,&MqttHandler::appdownload,[&](){
  548. curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/app.apk");
  549. //curlHandler.setfilepath(appDataPath+"/app.apk");
  550. curlHandler.setfilepath("/sdcard/app.apk");
  551. curlHandler.settype("App升级文件更新");
  552. curlHandler.start();
  553. //
  554. });
  555. QObject::connect(&mqttHandler,&MqttHandler::sysReboot,[&](){
  556. WARN("系统重启");
  557. sendBroadcastFromQt("rebootSystem");
  558. });
  559. QObject::connect(&mqttHandler,&MqttHandler::configChange,[&](){
  560. sqlConfig->OpenDb();
  561. if(sqlConfig->isTableExist(param::table_camera)){
  562. qDebug() << "UpdateData stitch_photonum !!!!!";
  563. sqlConfig->UpdateData(param::table_camera,"stitch_photonum",QString::number(param::stitch_photonum));
  564. }
  565. sqlConfig->CloseDb();
  566. });
  567. QObject::connect(&mqttHandler,&MqttHandler::signal_imei_change,[&](QString NEW_IMEI){
  568. sqlConfig->OpenDb();
  569. if(sqlConfig->isTableExist(param::table_mqtt)){
  570. qDebug() << "UpdateData imei !!!!!";
  571. sqlConfig->UpdateData(param::table_mqtt,"imei",NEW_IMEI);
  572. }
  573. sqlConfig->CloseDb();
  574. });
  575. QObject::connect(&curlHandler,&CurlHandler::downloadFinished,[&](bool result,QString mtype){
  576. LOG("downloadFinished:{}-{}",result,mtype.toStdString());
  577. if(result&&mtype.contains("App")){
  578. // QByteArray download_success("{\"cmd\":\"warn\",\"ext\":{\"status\":\"App DownLoad Success!\"}}");
  579. // mqttHandler.publish_m(download_success);
  580. emit mqttHandler.appInstall();
  581. }
  582. });
  583. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  584. &app, [url](QObject *obj, const QUrl &objUrl) {
  585. if (!obj && url == objUrl)
  586. QCoreApplication::exit(-1);
  587. }, Qt::QueuedConnection);
  588. // 将位置信息源暴露给QML界面
  589. engine.load(QUrl(felgo.mainQmlFileName()));
  590. //FelgoLiveClient liveClient(&engine);
  591. //UserFunc myClass(engine.rootObjects()); // 获取QML对象
  592. #if WIN32
  593. app.installNativeEventFilter(myClass.mySerialEvent); // 安装window串口拔插事件
  594. #endif
  595. //engine.rootContext()->setContextProperty("myClass", &myClass); // 将C++类添加进QML使用
  596. //engine.rootContext()->setContextProperty("mySerial", myClass.serial_main); // 将C++类添加进QML使用
  597. QObject *rootItem = engine.rootObjects().value(0);
  598. //traverseQmlObject(rootItem);
  599. #if 1
  600. if(rootItem)
  601. {
  602. QObject::connect(&mqttHandler,&MqttHandler::autotakephoto,[&](bool stat){
  603. QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
  604. if(Navigation_main){
  605. qDebug() << "Navigation_main is !!!!!"<<stat;
  606. QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
  607. //打开相机
  608. QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
  609. if(autoFocus_Page){
  610. QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,stat));
  611. //将param::stitchphoto保存
  612. }
  613. }
  614. }); //mqtt到QML,控制qml跳转到自动对焦界面,开始对焦拍照
  615. QObject::connect(&serialThread,&SerialThread::auto_takephoto,[&](){
  616. QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
  617. if(Navigation_main){
  618. qDebug() << "Navigation_main is !!!!!";
  619. QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
  620. //打开相机
  621. QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
  622. if(autoFocus_Page){
  623. QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,true));
  624. }
  625. }
  626. }); //串口到QML,控制qml跳转到自动对焦界面,结束对焦拍照
  627. //获取按钮点击事件
  628. QObject *systemset_Item = rootItem->findChild<QObject*>("systemset_Item");
  629. if(systemset_Item){
  630. QObject::connect(systemset_Item, SIGNAL(selected()),&myCppClass,SLOT(systemPage()));
  631. QObject::connect(&myCppClass, &MyCppClass::tosystempage,[&](){
  632. QObject *openbar_btn = rootItem->findChild<QObject*>("openbar_btn"); //打开状态栏
  633. if(openbar_btn){
  634. QObject::connect(openbar_btn, SIGNAL(opernBar()),&myCppClass,SLOT(openbar_btnClicked()));
  635. QObject::connect(&myCppClass, &MyCppClass::opensystembar,[&](){
  636. sendBroadcastFromQt("openbar_btn");
  637. });
  638. QObject::connect(openbar_btn, SIGNAL(closeBar()),&myCppClass,SLOT(closebar_btnClicked()));
  639. QObject::connect(&myCppClass, &MyCppClass::closesystembar,[&](){
  640. sendBroadcastFromQt("closebar_btn");
  641. });
  642. }
  643. QObject *opennav_btn = rootItem->findChild<QObject*>("opennav_btn"); //控制导航栏
  644. if(opennav_btn){
  645. QObject::connect(opennav_btn, SIGNAL(opernNav()),&myCppClass,SLOT(opennav_btnClicked()));
  646. QObject::connect(&myCppClass, &MyCppClass::opensystemnav,[&](){
  647. sendBroadcastFromQt("opennav_btn");
  648. });
  649. QObject::connect(opennav_btn, SIGNAL(closeNav()),&myCppClass,SLOT(closenav_btnClicked()));
  650. QObject::connect(&myCppClass, &MyCppClass::closesystemnav,[&](){
  651. sendBroadcastFromQt("closenav_btn");
  652. });
  653. }
  654. });
  655. }
  656. // 获取根 QML 对象
  657. QObject *autofocus_item = rootItem->findChild<QObject*>("autofocus_Item");
  658. if(autofocus_item){
  659. bool isConnect_frame = true;
  660. //const QMetaObject *metaObj = autofocus_item->metaObject();
  661. LOG("Found autofocus_item!");
  662. QObject::connect(autofocus_item, SIGNAL(selected()),&myCppClass,SLOT(qmlSlot()));
  663. QObject::connect(&myCppClass, &MyCppClass::recvqmlslot,[&](){
  664. LOG("connect myCppClass");
  665. Qt6QCamera::Frames *m_frames = qobject_cast<Qt6QCamera::Frames*>(rootItem->findChild<QObject*>("Frames"));
  666. if(!m_frames) {ERROR("m_frames is null!!!");}
  667. if(m_frames&&isConnect_frame){
  668. LOG("m_frames connected!");
  669. //engine.addImageProvider("ucamera",m_frames->getImageProvider());
  670. QObject::connect(m_frames,&Qt6QCamera::Frames::serial_data,&serialThread,&SerialThread::sendData); //Frame到串口
  671. QObject::connect(&serialThread,&SerialThread::takephotodone,m_frames,&Qt6QCamera::Frames::saveImage); //串口到QML,控制qml跳转到自动对焦界面
  672. //QObject::connect(m_frames,&Qt6QCamera::Frames::signal_stitch,&imagestitcher,&ImageStitcher::stitch_thread);
  673. QObject::connect(&serialThread,&SerialThread::signal_movy,m_frames,&Qt6QCamera::Frames::onMovDone);
  674. QObject::connect(m_frames,&Qt6QCamera::Frames::dataUpload,&mqttHandler,&MqttHandler::publish_m); //frames到MQTT
  675. // 修改信号槽连接方式
  676. QObject::connect(m_frames, &Qt6QCamera::Frames::signal_wait_upload,
  677. &uploader_ftp, &CurlFtpUploader::uploadFileAsync);
  678. QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
  679. m_frames,&Qt6QCamera::Frames::handle_reult_upload);
  680. isConnect_frame = false;
  681. }else{
  682. ERROR("m_frames no !!!!!");
  683. }
  684. });
  685. }else{
  686. qDebug() << "autofocus_item no !!!!!";
  687. }
  688. }else{
  689. ERROR("rootItem is null !!!!!");
  690. }
  691. #endif
  692. LOG("app start!");
  693. // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
  694. // and uncomment the line below
  695. //FelgoLiveClient client (&engine);
  696. GPSInfo *gps_start = new GPSInfo(sqlConfig,&app);
  697. QObject::connect(gps_start,&GPSInfo::position_success,[&](){
  698. emit serialThread.gpsSuccess();
  699. });
  700. return app.exec();
  701. }
  702. #include "main.moc"