main.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #include <main.h>
  2. #include <m_loger.h>
  3. #include <cameramanager.h>
  4. #include <EasyTableModel.h>
  5. #include <mqtthandler.h>
  6. #include <mserial.h>
  7. #include <ymodem.h>
  8. #include <mysql.h>
  9. #include <TreeModel.h>
  10. #include <app_curlFunc.h>
  11. // Uncomment this line to add Felgo Hot Reload and use hot reloading with your custom C++ code
  12. //#include <FelgoHotReload>
  13. class param;
  14. QString param::table_mqtt = "mqtt"; //mqtt配置表
  15. QString param::table_mqtt_other = "mqtt_other"; //mqtt对接配置表
  16. QString param::table_ftp = "ftp"; //FTP配置表
  17. QString param::table_ftp_other = "ftp_other"; //FTP对接配置表
  18. QString param::table_camera = "camera"; //相机参数配置表
  19. QString param::table_location = "location"; //定位信息参数配置表
  20. QString param::table_config = "config"; //参数配置表
  21. void traverseQmlObject(QObject *qmlObject, int depth = 0) {
  22. QString indentation = QString(" ").repeated(depth);
  23. qDebug() << indentation << "Type:" << qmlObject->metaObject()->className()
  24. << "Name:" << qmlObject->objectName();
  25. for (QObject *child : qmlObject->children()) {
  26. traverseQmlObject(child, depth + 1);
  27. }
  28. }
  29. class MyCppClass : public QObject {
  30. Q_OBJECT
  31. public:
  32. void setQmlRootObject(QObject *rootObject) {
  33. m_qmlRootObject = rootObject;
  34. }
  35. void JumpToCamera(){
  36. }
  37. public slots:
  38. void qmlSlot() {
  39. LOG("Received from QML");
  40. emit recvqmlslot();
  41. }
  42. void systemPage(){
  43. LOG("systemPage");
  44. emit tosystempage();
  45. }
  46. void openbar_btnClicked(){
  47. LOG("openbar_btnClicked");
  48. emit opensystembar();
  49. }
  50. void closebar_btnClicked(){
  51. LOG("closebar_btnClicked");
  52. emit closesystembar();
  53. }
  54. void opennav_btnClicked(){
  55. LOG("opennav_btnClicked");
  56. emit opensystemnav();
  57. }
  58. void closenav_btnClicked(){
  59. LOG("closenav_btnClicked");
  60. emit closesystemnav();
  61. }
  62. signals:
  63. void recvqmlslot();
  64. void tosystempage();
  65. void opensystembar();
  66. void closesystembar();
  67. void opensystemnav();
  68. void closesystemnav();
  69. private:
  70. QObject *m_qmlRootObject = nullptr;
  71. };
  72. class GPSInfo : public QObject
  73. {
  74. Q_OBJECT
  75. public:
  76. double nowGroundSpeed=0.0;
  77. double nowVerticalSpeed=0.0;
  78. double nowMagneticVariation=0.0;
  79. double nowHorizontalAccuracy=0.0;
  80. double nowVerticalAccuracy=0.0;
  81. double nowLongitude=0.0;
  82. double nowLatitude=0.0;
  83. double nowDirection=0.0;
  84. QString nowTimes="";
  85. int recv_cnt = 0;
  86. QGeoPositionInfoSource *positionSource;
  87. public:
  88. GPSInfo(SqliteOperator *db,QObject *parent = nullptr)
  89. : QObject(parent) // 注入外部数据库对象
  90. , gpsConfig(db)
  91. {
  92. param::gps_state = "0";
  93. positionSource = QGeoPositionInfoSource::createDefaultSource(this);
  94. //QGeoSatelliteInfoSource *satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
  95. if (positionSource) {
  96. connect(positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
  97. this, SLOT(positionUpdated(QGeoPositionInfo)));
  98. positionSource->setUpdateInterval(1000);//设置刷新时间 单位毫秒
  99. positionSource->startUpdates();//启动设备
  100. }
  101. }
  102. signals:
  103. void position_success();
  104. private:
  105. SqliteOperator *gpsConfig = nullptr; // 不再在内部创建
  106. private slots://槽函数中实现了GPS部分信息的读取
  107. void positionUpdated(const QGeoPositionInfo &info)
  108. {
  109. nowLongitude = info.coordinate().longitude();//经度
  110. nowLatitude = info.coordinate().latitude();//纬度
  111. nowDirection = info.attribute(QGeoPositionInfo::Direction);
  112. nowGroundSpeed = info.attribute(QGeoPositionInfo::GroundSpeed);
  113. nowVerticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed);
  114. nowMagneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation);
  115. nowHorizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy);
  116. nowVerticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy);
  117. nowTimes = info.timestamp().toString();
  118. if(param::gps_lat.contains(".")&&param::gps_lat.size()>3){
  119. param::gps_state = "1";
  120. recv_cnt++;
  121. if(recv_cnt==20){ //定位成功后120S把定位信息保存到数据库中
  122. emit position_success();
  123. gpsConfig->OpenDb();
  124. if(gpsConfig->isTableExist(param::table_location)){
  125. gpsConfig->UpdateData(param::table_location,"gps_lat",param::gps_lat);
  126. gpsConfig->UpdateData(param::table_location,"gps_lng",param::gps_lng);
  127. }
  128. gpsConfig->CloseDb();
  129. positionSource->stopUpdates();
  130. }
  131. }
  132. param::gps_lat = QString::number(nowLatitude);
  133. param::gps_lng = QString::number(nowLongitude);
  134. LOG("经度:{}",nowLongitude);
  135. LOG("纬度:{}",nowLatitude);
  136. LOG("角度:{}",nowDirection);
  137. LOG("地表速度:{}",nowGroundSpeed);
  138. LOG("垂直速度:{}",nowVerticalSpeed);
  139. LOG("磁偏角:{}",nowMagneticVariation);
  140. LOG("水平精度:{}",nowHorizontalAccuracy);
  141. LOG("垂直精度:{}",nowVerticalAccuracy);
  142. LOG("定位次数:{}",recv_cnt);
  143. }
  144. };
  145. void sendBroadcastFromQt(QString btn_type) {
  146. //QJniObject activity = QJniObject::callStaticObjectMethod("com/yfkj/bzyv1/MyQtActivity","getCurrentActivity","()Landroid/app/Activity;");
  147. auto qtContext = QJniObject(QNativeInterface::QAndroidApplication::context()); //activity
  148. //QJniObject qtContext = activity.callObjectMethod("getApplicationContext","()Landroid/content/Context;");
  149. if (qtContext.isValid()) {
  150. if(btn_type=="sleep"){
  151. QJniObject jClass("com/yfkj/bzyv1/Backlight");
  152. //jboolean ret = jClass.callMethod<jboolean>("checkWriteSettingPermission","(Landroid/content/Context;I)Z",qtContext.object(),100);
  153. jClass.callMethod<void>("setScreenLight","(Landroid/content/Context;I)V",qtContext.object(),100);
  154. }
  155. //QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  156. QJniObject jClass("com/yfkj/bzyv1/Backlight");
  157. if(btn_type=="openbar_btn"){
  158. jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),1);
  159. }else if(btn_type=="closebar_btn"){
  160. jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),0);
  161. }else if(btn_type=="closenav_btn"){
  162. jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),0);
  163. }else if(btn_type=="opennav_btn"){
  164. jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),1);
  165. }else if(btn_type=="imei"){
  166. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  167. QJniObject java_imei= jClass.callObjectMethod("getAndroidIMEI","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
  168. if(java_imei.isValid()){
  169. QString imei = java_imei.toString();
  170. if(!imei.isEmpty()&&param::imei.isEmpty()){
  171. param::imei = imei;
  172. }
  173. LOG("IMEI:{}",param::imei.toStdString());
  174. }
  175. }else if(btn_type=="csq"){
  176. jClass.callMethod<void>("getMobileNetworkSignal","(Landroid/content/Context;)V",qtContext.object());
  177. }else if(btn_type=="iccid"){
  178. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  179. QJniObject iccid_java = jClass.callObjectMethod("getICCID","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
  180. if(iccid_java.isValid()){
  181. QString iccid = iccid_java.toString();
  182. if(!iccid.isEmpty()){
  183. param::iccid = iccid;
  184. }
  185. LOG("ICCID:{}",param::iccid.toStdString());
  186. }
  187. }else if(btn_type=="install"){
  188. QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
  189. qDebug() << "install process start!";
  190. jClass.callMethod<void>("installApp","(Landroid/content/Context;)V",qtContext.object());
  191. }else if(btn_type=="rebootSystem"){
  192. jClass.callMethod<void>("rebootSystem","(Landroid/content/Context;)V",qtContext.object());
  193. }else if(btn_type=="service"){
  194. qDebug() <<"启动android服务";
  195. QAndroidIntent serviceIntent(qtContext.object(),
  196. "com/yfkj/bzyv1/QtAndroidService");
  197. QJniObject result = qtContext.callObjectMethod(
  198. "startService",
  199. "(Landroid/content/Intent;)Landroid/content/ComponentName;",
  200. serviceIntent.handle().object());
  201. }
  202. }
  203. }
  204. int main(int argc, char *argv[])
  205. {
  206. INITLOG();
  207. if (QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result() == QtAndroidPrivate::Denied)
  208. {
  209. QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).waitForFinished();
  210. }
  211. qInfo() << "anroid storage permission status: " << QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result();
  212. sendBroadcastFromQt("sleep");
  213. MyCppClass myCppClass;
  214. QApplication app(argc, argv);
  215. FelgoApplication felgo;
  216. QQmlApplicationEngine engine;
  217. felgo.initialize(&engine);
  218. #if WIN32
  219. QString subDirPath = "logs/run_log.txt";
  220. QString appDataPath ="./";
  221. #else
  222. // 获取应用程序内部存储空间路径
  223. QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
  224. LOG("appDataPath:{}",appDataPath.toStdString());
  225. QString appPicPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
  226. LOG("appPicPath:{}",appPicPath.toStdString());
  227. #endif
  228. sendBroadcastFromQt("iccid");
  229. sendBroadcastFromQt("csq");
  230. QString db_config = "config.db";
  231. SqliteOperator *sqlConfig;
  232. sqlConfig = new SqliteOperator(db_config);
  233. sqlConfig->OpenDb();
  234. //判断数据表是否存在
  235. config_db_type config_class;
  236. if(!sqlConfig->isTableExist(param::table_mqtt)){
  237. sqlConfig->CreateTable(param::table_mqtt);
  238. //插入数据
  239. 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};
  240. sqlConfig->InsertData(config_class,param::table_mqtt);
  241. //查询全部数据
  242. sqlConfig->QueryAllData(param::table_mqtt);
  243. }else{
  244. sqlConfig->QueryAllData(param::table_mqtt);
  245. }
  246. if(param::imei.isEmpty()){
  247. sendBroadcastFromQt("imei");
  248. QTimer::singleShot(1000, [&]() {
  249. sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei);
  250. });
  251. }
  252. if(!sqlConfig->isTableExist(param::table_mqtt_other))
  253. {
  254. sqlConfig->CreateTable(param::table_mqtt_other);
  255. 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};
  256. sqlConfig->InsertData(config_class,param::table_mqtt_other);
  257. //查询全部数据
  258. sqlConfig->QueryAllData(param::table_mqtt_other);
  259. }else{
  260. sqlConfig->QueryAllData(param::table_mqtt_other);
  261. }
  262. if(!sqlConfig->isTableExist(param::table_ftp))
  263. {
  264. sqlConfig->CreateTable(param::table_ftp);
  265. config_class.ftp_db = {1,"8.136.98.49",21,"","bzy_user","YFkj@6O2O",0};
  266. sqlConfig->InsertData(config_class,param::table_ftp);
  267. sqlConfig->QueryAllData(param::table_ftp);
  268. }else{
  269. sqlConfig->QueryAllData(param::table_ftp);
  270. }
  271. if(!sqlConfig->isTableExist(param::table_ftp_other))
  272. {
  273. sqlConfig->CreateTable(param::table_ftp_other);
  274. config_class.ftp_db = {1,"0.0.0.0",21,"","cbd_user","YFkj@6O2O",0};
  275. sqlConfig->InsertData(config_class,param::table_ftp_other);
  276. sqlConfig->QueryAllData(param::table_ftp_other);
  277. }else{
  278. sqlConfig->QueryAllData(param::table_ftp_other);
  279. }
  280. if(!sqlConfig->isTableExist(param::table_location))
  281. {
  282. sqlConfig->CreateTable(param::table_location);
  283. config_class.location_db = {1,"0","0","0","0","0"};
  284. sqlConfig->InsertData(config_class,param::table_location);
  285. sqlConfig->QueryAllData(param::table_location);
  286. }else{
  287. sqlConfig->QueryAllData(param::table_location);
  288. }
  289. //相机图像参数
  290. if(!sqlConfig->isTableExist(param::table_camera)){
  291. sqlConfig->CreateTable(param::table_camera);
  292. config_class.camera_db = {"hikrobot","static",2,1000,1000,"0","f80","b80","f80","b80"};
  293. sqlConfig->InsertData(config_class,param::table_camera);
  294. sqlConfig->QueryAllData(param::table_camera);
  295. }else{
  296. sqlConfig->QueryAllData(param::table_camera);
  297. }
  298. //配置
  299. if(!sqlConfig->isTableExist(param::table_config)){
  300. sqlConfig->CreateTable(param::table_config);
  301. config_class.config_db = {1,1,1000,500,0,0};
  302. sqlConfig->InsertData(config_class,param::table_config);
  303. sqlConfig->QueryAllData(param::table_config);
  304. }else{
  305. sqlConfig->QueryAllData(param::table_config);
  306. }
  307. sqlConfig->CloseDb();
  308. // Set an optional license key from project file
  309. // This does not work if using Felgo Developer App, only for Felgo Cloud Builds and local builds
  310. //felgo.setLicenseKey(PRODUCT_LICENSE_KEY);
  311. TreeModel model;
  312. engine.setOfflineStoragePath(appDataPath); //设置数据库存储路径
  313. engine.rootContext()->setContextProperty("appdir", qApp->applicationDirPath()); //使用QApplication::applicationDirPath()获取,并注册到qml中
  314. engine.rootContext()->setContextProperty("treeModel",&model);
  315. qmlRegisterType<EasyTableModel>("EasyModel",1,0,"EasyTableModel"); //注册C++模块到QML中
  316. qmlRegisterType<DatabaseInterface>("com.example.database", 1, 0, "DatabaseInterface");
  317. // use this during development
  318. // for PUBLISHING, use the entry point below
  319. felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
  320. const QUrl url(felgo.mainQmlFileName());
  321. Qt6QCamera::Frames::registerQmlType();
  322. SerialThread serialThread;
  323. engine.rootContext()->setContextProperty("serial", &serialThread);
  324. CurlFtpUploader uploader_ftp; // 成员变量
  325. QString remotepath ="/photo_hard/" + param::imei;
  326. uploader_ftp.setFtpParams("bzy_user", "YFkj@6O2O", "8.136.98.49", 21, remotepath);
  327. YMODEM m_ymodem(&serialThread);
  328. serialThread.setSerialPortSettings("/dev/ttyS3", QSerialPort::Baud115200, QSerialPort::Data8,
  329. QSerialPort::NoParity, QSerialPort::OneStop,
  330. QSerialPort::NoFlowControl);
  331. MqttHandler mqttHandler;
  332. mqttHandler.storage()->setJsonCacheEnabled(param::jsonCacheEnable);
  333. mqttHandler.storage()->setImageCacheEnabled(param::imageCacheEnable);
  334. mqttHandler.storage()->setMaxJsonEntries(param::maxJsonEntries);
  335. mqttHandler.storage()->setMaxImageEntries(param::maxImageEntries);
  336. CurlHandler curlHandler("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/app.apk",appDataPath+"/app.apk"); //app升级
  337. NetworkInfoHelper networkMonitor;
  338. engine.rootContext()->setContextProperty("mqtt", &mqttHandler);
  339. engine.rootContext()->setContextProperty("curl", &curlHandler);
  340. engine.rootContext()->setContextProperty("ymodem",&m_ymodem);
  341. engine.rootContext()->setContextProperty("curl_picture",&uploader_ftp);
  342. engine.rootContext()->setContextProperty("networkMonitor", &networkMonitor);
  343. serialThread.start();
  344. QObject::connect(&serialThread,&SerialThread::dataUpload,&mqttHandler,&MqttHandler::publish_m); //串口到MQTT
  345. QObject::connect(&mqttHandler,&MqttHandler::dataReceived,&serialThread,&SerialThread::mqtttoserial);//MQTT到串口
  346. QObject::connect(&serialThread,&SerialThread::updatestart,&m_ymodem,&YMODEM::start_ymodem); //串口到Ymodem
  347. QObject::connect(&m_ymodem,&YMODEM::modem_result,&serialThread,&SerialThread::getmodemresult); //Ymodem到串口
  348. QObject::connect(&networkMonitor,&NetworkInfoHelper::reachabilityChanged,[&](QNetworkInformation::Reachability newReachability){
  349. if(newReachability==QNetworkInformation::Reachability::Online){
  350. WARN("网络连接!");
  351. param::net_alive = 1;
  352. }else{
  353. param::net_alive = 0;
  354. WARN("网络断开!");
  355. mqttHandler.disconnectFromBroker();
  356. }
  357. });
  358. QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
  359. &mqttHandler,&MqttHandler::storage_Picture);
  360. QObject::connect(&mqttHandler, &MqttHandler::signal_reupload_image,
  361. &uploader_ftp,&CurlFtpUploader::uploadFileAsync);
  362. QObject::connect(&mqttHandler,&MqttHandler::updateStm32,[&](){
  363. curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/A7/STM32/Application_BZYV2.rbl");
  364. curlHandler.setfilepath(appDataPath+"/rtthread.rbl");
  365. curlHandler.settype("主板升级文件更新");
  366. curlHandler.start();
  367. //sendBroadcastFromQt("install");
  368. });
  369. QObject::connect(&mqttHandler,&MqttHandler::appdownload,[&](){
  370. curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/app.apk");
  371. //curlHandler.setfilepath(appDataPath+"/app.apk");
  372. curlHandler.setfilepath("/sdcard/app.apk");
  373. curlHandler.settype("App升级文件更新");
  374. curlHandler.start();
  375. //
  376. });
  377. QObject::connect(&mqttHandler,&MqttHandler::sysReboot,[&](){
  378. WARN("系统重启");
  379. sendBroadcastFromQt("rebootSystem");
  380. });
  381. QObject::connect(&mqttHandler,&MqttHandler::configChange,[&](){
  382. sqlConfig->OpenDb();
  383. if(sqlConfig->isTableExist(param::table_camera)){
  384. qDebug() << "UpdateData stitch_photonum !!!!!";
  385. sqlConfig->UpdateData(param::table_camera,"stitch_photonum",QString::number(param::stitch_photonum));
  386. }
  387. sqlConfig->CloseDb();
  388. });
  389. QObject::connect(&mqttHandler,&MqttHandler::signal_imei_change,[&](QString NEW_IMEI){
  390. sqlConfig->OpenDb();
  391. if(sqlConfig->isTableExist(param::table_mqtt)){
  392. qDebug() << "UpdateData imei !!!!!";
  393. sqlConfig->UpdateData(param::table_mqtt,"imei",NEW_IMEI);
  394. }
  395. sqlConfig->CloseDb();
  396. });
  397. QObject::connect(&curlHandler,&CurlHandler::downloadFinished,[&](bool result,QString mtype){
  398. LOG("downloadFinished:{}-{}",result,mtype.toStdString());
  399. if(result&&mtype.contains("App")){
  400. // QByteArray download_success("{\"cmd\":\"warn\",\"ext\":{\"status\":\"App DownLoad Success!\"}}");
  401. // mqttHandler.publish_m(download_success);
  402. emit mqttHandler.appInstall();
  403. }
  404. });
  405. // QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  406. // &app, [url](QObject *obj, const QUrl &objUrl) {
  407. // if (!obj && url == objUrl)
  408. // QCoreApplication::exit(-1);
  409. // }, Qt::QueuedConnection);
  410. // 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
  411. // this is the preferred deployment option for publishing apps to the app stores, because then your qml files and js files are protected
  412. // to avoid deployment of your qml files and images, also comment the deploy_resources command in the CMakeLists file
  413. // also see the CMakeLists.txt file for more details
  414. //felgo.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml"));
  415. engine.load(QUrl(felgo.mainQmlFileName()));
  416. QObject *rootItem = engine.rootObjects().value(0);
  417. if(rootItem)
  418. {
  419. QObject::connect(&mqttHandler,&MqttHandler::autotakephoto,[&](bool stat){
  420. QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
  421. if(Navigation_main){
  422. qDebug() << "Navigation_main is !!!!!"<<stat;
  423. QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
  424. //打开相机
  425. QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
  426. if(autoFocus_Page){
  427. QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,stat));
  428. //将param::stitchphoto保存
  429. }
  430. }
  431. }); //mqtt到QML,控制qml跳转到自动对焦界面,开始对焦拍照
  432. QObject::connect(&serialThread,&SerialThread::auto_takephoto,[&](){
  433. QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
  434. if(Navigation_main){
  435. qDebug() << "Navigation_main is !!!!!";
  436. QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
  437. //打开相机
  438. QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
  439. if(autoFocus_Page){
  440. QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,true));
  441. }
  442. }
  443. }); //串口到QML,控制qml跳转到自动对焦界面,结束对焦拍照
  444. //获取按钮点击事件
  445. QObject *systemset_Item = rootItem->findChild<QObject*>("systemset_Item");
  446. if(systemset_Item){
  447. QObject::connect(systemset_Item, SIGNAL(selected()),&myCppClass,SLOT(systemPage()));
  448. QObject::connect(&myCppClass, &MyCppClass::tosystempage,[&](){
  449. QObject *openbar_btn = rootItem->findChild<QObject*>("openbar_btn"); //打开状态栏
  450. if(openbar_btn){
  451. QObject::connect(openbar_btn, SIGNAL(opernBar()),&myCppClass,SLOT(openbar_btnClicked()));
  452. QObject::connect(&myCppClass, &MyCppClass::opensystembar,[&](){
  453. sendBroadcastFromQt("openbar_btn");
  454. });
  455. QObject::connect(openbar_btn, SIGNAL(closeBar()),&myCppClass,SLOT(closebar_btnClicked()));
  456. QObject::connect(&myCppClass, &MyCppClass::closesystembar,[&](){
  457. sendBroadcastFromQt("closebar_btn");
  458. });
  459. }
  460. QObject *opennav_btn = rootItem->findChild<QObject*>("opennav_btn"); //控制导航栏
  461. if(opennav_btn){
  462. QObject::connect(opennav_btn, SIGNAL(opernNav()),&myCppClass,SLOT(opennav_btnClicked()));
  463. QObject::connect(&myCppClass, &MyCppClass::opensystemnav,[&](){
  464. sendBroadcastFromQt("opennav_btn");
  465. });
  466. QObject::connect(opennav_btn, SIGNAL(closeNav()),&myCppClass,SLOT(closenav_btnClicked()));
  467. QObject::connect(&myCppClass, &MyCppClass::closesystemnav,[&](){
  468. sendBroadcastFromQt("closenav_btn");
  469. });
  470. }
  471. });
  472. }
  473. // 获取根 QML 对象
  474. QObject *autofocus_item = rootItem->findChild<QObject*>("autofocus_Item");
  475. if(autofocus_item){
  476. bool isConnect_frame = true;
  477. //const QMetaObject *metaObj = autofocus_item->metaObject();
  478. LOG("Found autofocus_item!");
  479. QObject::connect(autofocus_item, SIGNAL(selected()),&myCppClass,SLOT(qmlSlot()));
  480. QObject::connect(&myCppClass, &MyCppClass::recvqmlslot,[&](){
  481. LOG("connect myCppClass");
  482. Qt6QCamera::Frames *m_frames = qobject_cast<Qt6QCamera::Frames*>(rootItem->findChild<QObject*>("Frames"));
  483. if(!m_frames) {ERROR("m_frames is null!!!");}
  484. if(m_frames&&isConnect_frame){
  485. LOG("m_frames connected!");
  486. //engine.addImageProvider("ucamera",m_frames->getImageProvider());
  487. QObject::connect(m_frames,&Qt6QCamera::Frames::serial_data,&serialThread,&SerialThread::sendData); //Frame到串口
  488. QObject::connect(&serialThread,&SerialThread::takephotodone,m_frames,&Qt6QCamera::Frames::saveImage); //串口到QML,控制qml跳转到自动对焦界面
  489. //QObject::connect(m_frames,&Qt6QCamera::Frames::signal_stitch,&imagestitcher,&ImageStitcher::stitch_thread);
  490. QObject::connect(&serialThread,&SerialThread::signal_movy,m_frames,&Qt6QCamera::Frames::onMovDone);
  491. QObject::connect(m_frames,&Qt6QCamera::Frames::dataUpload,&mqttHandler,&MqttHandler::publish_m); //frames到MQTT
  492. // 修改信号槽连接方式
  493. QObject::connect(m_frames, &Qt6QCamera::Frames::signal_wait_upload,
  494. &uploader_ftp, &CurlFtpUploader::uploadFileAsync);
  495. QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
  496. m_frames,&Qt6QCamera::Frames::handle_reult_upload);
  497. isConnect_frame = false;
  498. }else{
  499. ERROR("m_frames no !!!!!");
  500. }
  501. });
  502. }else{
  503. qDebug() << "autofocus_item no !!!!!";
  504. }
  505. }else{
  506. ERROR("rootItem is null !!!!!");
  507. }
  508. LOG("app start!");
  509. GPSInfo *gps_start = new GPSInfo(sqlConfig,&app);
  510. QObject::connect(gps_start,&GPSInfo::position_success,[&](){
  511. emit serialThread.gpsSuccess();
  512. });
  513. // to start your project with Felgo Hot Reload, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
  514. // and uncomment the line below
  515. //FelgoHotReload felgoHotReload(&engine);
  516. return app.exec();
  517. }
  518. #include "main.moc"