| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003 |
- #include <main.h>
- //#include "userfunc.h"
- #include <cameramanager.h>
- #include <mqtthandler.h>
- #include <mserial.h>
- #include <mysql.h>
- #include <EasyTableModel.h>
- #include <customitem.h>
- #include <m_loger.h>
- #include <TreeModel.h>
- #include <app_curlFunc.h>
- #include <wif_service.h>
- #include <ethernet_service.h>
- #include <QProcess>
- #include <QVariantMap>
- #include <QQuickWindow>
- #include <app_credentials.h>
- #include <PermissionBridge.h>
- #include <logviewer.h>
- #include <oamanager.h>
- #include <systemmonitor.h>
- //uncomment this line to add the Live Client Module and use live reloading with your custom C++ code
- //#include <FelgoLiveClient>
- class param;
- QString param::table_mqtt = "mqtt"; //mqtt配置表
- QString param::table_mqtt_other = "mqtt_other"; //mqtt对接配置表
- QString param::table_ftp = "ftp"; //FTP配置表
- QString param::table_ftp_other = "ftp_other"; //FTP对接配置表
- QString param::table_camera = "camera"; //相机参数配置表
- QString param::table_location = "location"; //定位信息参数配置表
- QString param::table_config = "config"; //参数配置表
- void traverseQmlObject(QObject *qmlObject, int depth = 0) {
- QString indentation = QString(" ").repeated(depth);
- LOG("{}Type: {} Name: {}", indentation.toStdString(),
- qmlObject->metaObject()->className(),
- qmlObject->objectName().toStdString());
- for (QObject *child : qmlObject->children()) {
- traverseQmlObject(child, depth + 1);
- }
- }
- // 网口相机(GigE)链路配置:eth0 静态IP 192.168.100.101 + Jumbo帧(优先 MTU 9000)
- //
- // 【2026-09-30 重要调整:改用 EnjoySDK,不再依赖 su】
- // 之前用 shell 的 ifconfig + su 改网卡,现场反复失败,根因是:
- // 修改 MTU / 静态 IP 需要 CAP_NET_ADMIN,普通 app uid 进程一定被内核拒绝
- // (errno=EPERM,即 "Operation not permitted")。设备若未 root,su 也拿不到权限。
- // EnjoySDK 走的是系统 EthernetService(system uid),普通应用即可下发配置,无需 root,
- // 且由系统服务负责持久化 —— 这是本平台配置网卡的正确路径。
- //
- // 【关键约束:mode=STATIC 必须与 IP 一次性下发】
- // setEthernetConfig 会校验整个配置对象:静态模式下 IP/子网掩码必须合法,
- // 否则返回 ERR_CONFIG_INVALID = -101。
- // 所以不能"先只改 mode 提交一次、再填 IP 提交第二次"——第一次提交时 IP 还是
- // DHCP 遗留的 0.0.0.0,校验必然失败。正确做法见 EthernetService::setStaticIp。
- //
- // 【MTU 说明】
- // EnjoySDK 未提供 MTU 接口,Jumbo 帧仍需 ifconfig(依赖 root)。
- // 但 MTU 设不上去不是致命错误:GigE 在 MTU 1500 下仍可通信,仅大帧带宽利用率下降,
- // 因此 MTU 失败只 WARN,不影响整体配置结果。
- //
- // 【现场排查要点】
- // 1) 修改网卡 MTU / 静态 IP 需要 CAP_NET_ADMIN。日志里 ifconfig 报的错误码是 ioctl 请求的
- // 十六进制值,对照表:
- // 8914 = SIOCSIFFLAGS (down/up)
- // 8922 = SIOCSIFMTU (mtu)
- // 8916 = SIOCSIFADDR (ip/netmask)
- // 8915 = SIOCGIFADDR (读 ip)
- // - "Operation not permitted"(EPERM) => 进程缺 CAP_NET_ADMIN,即 su 没生效
- // (设备未 root / su 不存在 / 被 SELinux 拦)。判据是 errno 而非日志字面。
- // - "Invalid argument"(EINVAL) => 已经拿到 root,但驱动拒绝了该 ioctl 的参数。
- // 本平台的 sunxi-gmac 就是这种:设 MTU 9000 会被拒(硬件/驱动上限低于 9000)。
- // 这两种要分清:前者是无权限,后者是有权限但值不被支持,处理方式完全不同。
- //
- // 2) 静态 IP 是 GigE 相机能被搜到的前提,必须成功;失败时重试若干轮等待驱动/链路就绪。
- //
- // 【根治方式】(更推荐在系统侧配置,不依赖应用内 su)
- // 1) 静态 IP:Android 10 EthernetService 支持静态 IP 下发,
- // 在 /system/etc/ethernet/config.xml 为 eth0 增加 StaticIPSettings(192.168.100.101/24),
- // 由系统服务(system uid)完成,无需 root。
- // 2) Jumbo 帧:在 init.rc 或 /system/etc/init.d/ 开机脚本执行 ifconfig eth0 mtu <N>,
- // N 取该平台驱动实际支持的最大值。
- // 3) 必须应用内配置时,APK 需预置为系统应用(platform 签名 + sharedUserId)。
- static void setupEth0()
- {
- const QString kIface = QStringLiteral("eth0");
- const QString kIp = QStringLiteral("192.168.100.101");
- const QString kNetmask = QStringLiteral("255.255.255.0");
- // ================= 步骤 1:MTU 阶梯降级(EnjoySDK 无 MTU 接口,仍走 ifconfig)=================
- // 【顺序很重要】必须在设静态 IP **之前** 调 MTU:
- // ifconfig down/up 会把网卡重置,若先由 EnjoySDK 下发静态 IP 再改 MTU,
- // down/up 可能把刚下发的 IP 冲掉。故 MTU 在前、IP 在后。
- // MTU 只能在网卡 down 时改;驱动可能不支持 9000(返回 EINVAL),逐级下探取最大值。
- // 非致命:GigE 在 1500 下仍可通信,仅带宽利用率下降。
- int mtuApplied = 0;
- {
- QString mtuReason;
- const int kMtuCandidates[] = {9000, 4000, 2000, 1500};
- for (int mtu : kMtuCandidates) {
- const QVariantMap m = EthernetService().setMtu(kIface, mtu);
- mtuReason = m.value(QStringLiteral("msg")).toString();
- if (m.value(QStringLiteral("ok")).toBool()) {
- mtuApplied = mtu;
- break;
- }
- // 无 root → 整项跳过(MTU 只是可选的 Jumbo 帧优化,不影响 GigE 连通)
- // 驱动不支持该值(EINVAL) → 继续降档试;两种情况都不该刷报错
- if (m.value(QStringLiteral("skipped")).toBool()) {
- break;
- }
- }
- if (mtuApplied > 0) {
- LOG("setupEth0: MTU 已设置为 {}", mtuApplied);
- } else {
- // 不是致命问题:GigE 在 MTU 1500 下仍可通信,仅大帧带宽利用率下降
- LOG("setupEth0: MTU 未设置({}),GigE 仍可通信,仅大帧带宽受限",
- mtuReason.toStdString().c_str());
- }
- }
- // ================= 步骤 2:静态 IP 走 EnjoySDK(主路径,无需 root)=================
- // 注意:静态 IP 是 GigE 搜到相机的前提,必须成功。
- // 放在 MTU 之后,避免被 ifconfig down/up 冲掉(见步骤 1 说明)。
- bool okIp = false;
- {
- EthernetService eth;
- if (!eth.isSupported()) {
- WARN("setupEth0: 当前平台不支持 EnjoySDK,静态IP 未能下发。"
- "请改走 /system/etc/ethernet/config.xml 的 StaticIPSettings。");
- } else {
- // 一次性下发 mode=STATIC + IP(分两步提交会被系统拒 -101)
- const QVariantMap r = eth.setStaticIp(kIface, kIp, kNetmask, QString(), QString());
- if (r.value(QStringLiteral("ok")).toBool()) {
- okIp = true;
- LOG("setupEth0: EnjoySDK 配置静态IP 成功 {} on {} (方案={})",
- kIp.toStdString().c_str(), kIface.toStdString().c_str(),
- r.value(QStringLiteral("via")).toString().toStdString().c_str());
- // 若厂商服务强制要求网关/DNS,Java 侧会自动补一个同网段网关(.1)和公网 DNS。
- // 这会让 eth0 在系统看来是"有默认网关的网络",可能被选为默认网络,
- // 从而影响 MQTT/FTP 的出口 —— 必须显式提醒。
- if (r.value(QStringLiteral("via")).toString() == QStringLiteral("with-gateway")) {
- WARN("setupEth0: 静态配置使用了自动补的网关/DNS(厂商要求必填)。"
- "eth0 可能被系统选为默认网络,若 MQTT/FTP 异常请检查路由优先级。");
- }
- } else {
- ERROR("setupEth0: EnjoySDK 配置静态IP 失败 code={} msg={}",
- r.value(QStringLiteral("code")).toInt(),
- eth.lastError().toStdString().c_str());
- }
- }
- }
- // ================= 收尾:打印最终状态 =================
- if (!okIp) {
- ERROR("setupEth0: eth0 静态IP {} 未配置成功,GigE 相机可能搜不到。"
- "请检查 EthernetService 是否运行,或改用 /system/etc/ethernet/config.xml 下发静态IP。",
- kIp.toStdString().c_str());
- }
- {
- EthernetService eth;
- const QVariantMap st = eth.status(kIface);
- LOG("setupEth0: eth0 最终状态 IP配置={} 当前IP={} mode={} linkState={} | MTU={}",
- okIp ? "OK" : "FAIL",
- st.value(QStringLiteral("ip")).toString().toStdString().c_str(),
- st.value(QStringLiteral("mode")).toInt(),
- st.value(QStringLiteral("linkState")).toInt(),
- mtuApplied > 0 ? QString::number(mtuApplied).toStdString().c_str() : "默认");
- }
- }
- class MyCppClass : public QObject {
- Q_OBJECT
- public:
- void setQmlRootObject(QObject *rootObject) {
- m_qmlRootObject = rootObject;
- }
- void JumpToCamera(){
- }
- public slots:
- void qmlSlot() {
- LOG("Received from QML");
- emit recvqmlslot();
- }
- void systemPage(){
- LOG("systemPage");
- emit tosystempage();
- }
- void openbar_btnClicked(){
- LOG("openbar_btnClicked");
- emit opensystembar();
- }
- void closebar_btnClicked(){
- LOG("closebar_btnClicked");
- emit closesystembar();
- }
- void opennav_btnClicked(){
- LOG("opennav_btnClicked");
- emit opensystemnav();
- }
- void closenav_btnClicked(){
- LOG("closenav_btnClicked");
- emit closesystemnav();
- }
- signals:
- void recvqmlslot();
- void tosystempage();
- void opensystembar();
- void closesystembar();
- void opensystemnav();
- void closesystemnav();
- private:
- QObject *m_qmlRootObject = nullptr;
- };
- class GPSInfo : public QObject
- {
- Q_OBJECT
- public:
- double nowGroundSpeed=0.0;
- double nowVerticalSpeed=0.0;
- double nowMagneticVariation=0.0;
- double nowHorizontalAccuracy=0.0;
- double nowVerticalAccuracy=0.0;
- double nowLongitude=0.0;
- double nowLatitude=0.0;
- double nowDirection=0.0;
- double nowAltitude=0.0;
- QString nowTimes="";
- int recv_cnt = 0;
- QGeoPositionInfoSource *positionSource;
- //卫星信息源:给主页"定位信息"卡片提供 可视/已用卫星数
- //-1 表示尚未收到过卫星数据(QML 侧显示 --)
- QGeoSatelliteInfoSource *satelliteSource = nullptr;
- int nowSatInView = -1;
- int nowSatInUse = -1;
- public:
- GPSInfo(SqliteOperator *db,QObject *parent = nullptr)
- : QObject(parent) // 注入外部数据库对象
- , gpsConfig(db)
- {
- param::gps_state = "0";
- positionSource = QGeoPositionInfoSource::createDefaultSource(this);
- if (positionSource) {
- connect(positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
- this, SLOT(positionUpdated(QGeoPositionInfo)));
- positionSource->setUpdateInterval(1000);//设置刷新时间 单位毫秒
- positionSource->startUpdates();//启动设备
- }
- //启用卫星信息源:可视/已用卫星数持续刷新(独立于定位源,不受定位停止影响;
- //面板为市电/蓄电池供电,持续GNSS监听功耗可接受)
- satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
- if (satelliteSource) {
- connect(satelliteSource, &QGeoSatelliteInfoSource::satellitesInViewUpdated,
- this, &GPSInfo::onSatellitesInView);
- connect(satelliteSource, &QGeoSatelliteInfoSource::satellitesInUseUpdated,
- this, &GPSInfo::onSatellitesInUse);
- satelliteSource->startUpdates();
- } else {
- LOG("QGeoSatelliteInfoSource 不可用,卫星数量将显示 --");
- }
- }
- signals:
- void position_success();
- private:
- SqliteOperator *gpsConfig = nullptr; // 不再在内部创建
- private slots://槽函数中实现了GPS部分信息的读取
- void onSatellitesInView(const QList<QGeoSatelliteInfo> &sats)
- {
- nowSatInView = sats.size();
- param::gps_sat_view = QString::number(nowSatInView);
- LOG("可视卫星数:{}",nowSatInView);
- }
- void onSatellitesInUse(const QList<QGeoSatelliteInfo> &sats)
- {
- nowSatInUse = sats.size();
- param::gps_sat_used = QString::number(nowSatInUse);
- LOG("已用卫星数:{}",nowSatInUse);
- }
- void positionUpdated(const QGeoPositionInfo &info)
- {
- nowLongitude = info.coordinate().longitude();//经度
- nowLatitude = info.coordinate().latitude();//纬度
- nowAltitude = info.coordinate().altitude();//海拔(米),无解算时为NaN
- nowDirection = info.attribute(QGeoPositionInfo::Direction);
- nowGroundSpeed = info.attribute(QGeoPositionInfo::GroundSpeed);
- nowVerticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed);
- nowMagneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation);
- nowHorizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy);
- nowVerticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy);
- nowTimes = info.timestamp().toString();
- //海拔仅在有效解算时写param,避免NaN污染显示;定位源停止后保持最后一次值
- if(qIsFinite(nowAltitude)){
- param::gps_elevation = QString::number(nowAltitude, 'f', 1);
- }
- if(param::gps_lat.contains(".")&¶m::gps_lat.size()>3){
- param::gps_state = "1";
- recv_cnt++;
- if(recv_cnt==20){ //定位成功后120S把定位信息保存到数据库中
- emit position_success();
- gpsConfig->OpenDb();
- if(gpsConfig->isTableExist(param::table_location)){
- gpsConfig->UpdateData(param::table_location,"gps_lat",param::gps_lat);
- gpsConfig->UpdateData(param::table_location,"gps_lng",param::gps_lng);
- }
- gpsConfig->CloseDb();
- positionSource->stopUpdates();
- }
- }
- // 保留7位小数(约1厘米精度),避免QString::number默认6位有效数字把经纬度截断到小数点后3位
- param::gps_lat = QString::number(nowLatitude, 'f', 7);
- param::gps_lng = QString::number(nowLongitude, 'f', 7);
- LOG("经度:{:.7f}",nowLongitude);
- LOG("纬度:{:.7f}",nowLatitude);
- LOG("角度:{}",nowDirection);
- LOG("地表速度:{}",nowGroundSpeed);
- LOG("垂直速度:{}",nowVerticalSpeed);
- LOG("磁偏角:{}",nowMagneticVariation);
- LOG("水平精度:{}",nowHorizontalAccuracy);
- LOG("垂直精度:{}",nowVerticalAccuracy);
- LOG("定位次数:{}",recv_cnt);
- }
- };
- void sendBroadcastFromQt(QString btn_type) {
- auto qtContext = QJniObject(QNativeInterface::QAndroidApplication::context()); //activity
- //QJniObject qtContext = activity.callObjectMethod("getApplicationContext","()Landroid/content/Context;");
- if (qtContext.isValid()) {
- if(btn_type=="sleep"){
- QJniObject jClass("com/yfkj/bzyv1/Backlight");
- //jboolean ret = jClass.callMethod<jboolean>("checkWriteSettingPermission","(Landroid/content/Context;I)Z",qtContext.object(),100);
- jClass.callMethod<void>("setScreenLight","(Landroid/content/Context;I)V",qtContext.object(),100);
- }
- //QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
- QJniObject jClass("com/yfkj/bzyv1/Backlight");
- if(btn_type=="openbar_btn"){
- jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),1);
- }else if(btn_type=="closebar_btn"){
- jClass.callMethod<void>("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),0);
- }else if(btn_type=="closenav_btn"){
- jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),0);
- }else if(btn_type=="opennav_btn"){
- jClass.callMethod<void>("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),1);
- }else if(btn_type=="imei"){
- QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
- QJniObject java_imei= jClass.callObjectMethod("getAndroidIMEI","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
- if(java_imei.isValid()){
- QString imei = java_imei.toString();
- if(!imei.isEmpty()&¶m::imei.isEmpty()){
- param::imei = imei;
- }
- LOG("IMEI:{}",param::imei.toStdString());
- }
- }else if(btn_type=="csq"){
- jint rsrp = QJniObject::callStaticMethod<jint>("com/yfkj/bzyv1/StatusBarCtr",
- "getRsrp",
- "(Landroid/content/Context;)I",
- qtContext.object());
- LOG("getRsrp:{}",rsrp);
- }else if(btn_type=="iccid"){
- QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
- QJniObject iccid_java = jClass.callObjectMethod("getICCID","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object());
- if(iccid_java.isValid()){
- QString iccid = iccid_java.toString();
- if(!iccid.isEmpty()){
- param::iccid = iccid;
- }
- LOG("ICCID:{}",param::iccid.toStdString());
- }
- }else if(btn_type=="install"){
- QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr");
- DEBUG("install process start!");
- jClass.callMethod<void>("installApp","(Landroid/content/Context;)V",qtContext.object());
- }else if(btn_type=="rebootSystem"){
- jClass.callMethod<void>("rebootSystem","(Landroid/content/Context;)V",qtContext.object());
- }else if(btn_type=="service"){
- DEBUG("启动android服务");
- QAndroidIntent serviceIntent(qtContext.object(),
- "com/yfkj/bzyv1/QtAndroidService");
- QJniObject result = qtContext.callObjectMethod(
- "startService",
- "(Landroid/content/Intent;)Landroid/content/ComponentName;",
- serviceIntent.handle().object());
- }
- }
- }
- // 定义函数:设置每日8:00重启的定时器
- auto setDailyRebootTimer = []() {
- // 获取当前时间(本地时间)
- QDateTime currentTime = QDateTime::currentDateTime();
- // 构造当天8:00的目标时间(基于本地时间的0点+8小时)
- QDateTime targetTime = currentTime.date().startOfDay().addSecs(8 * 3600); // 8:00 = 8 * 3600秒
- // 如果当前时间已过今日8:00,目标时间调整为次日8:00
- if (currentTime >= targetTime) {
- targetTime = targetTime.addDays(1); // 加1天
- }
- // 计算当前时间到目标时间的毫秒间隔
- qint64 intervalMs = currentTime.msecsTo(targetTime);
- // 设置单次定时器,触发后执行重启逻辑,并重新设置下一日的定时器
- QTimer::singleShot(intervalMs, []() {
- LOG("触发每日8:00重启");
- sendBroadcastFromQt("rebootSystem"); // 发送重启广播
- // 注意:若需要严格每日执行,建议在重启前重新设置定时器(根据实际需求)
- // 若系统重启后会自动启动本程序,可省略此处(程序重启后会重新设置定时器)
- // setDailyRebootTimer();
- });
- };
- //adb shell input keyevent 26 // 224 关
- // ========== 全志A133P缓存清理函数(关键)==========
- void clearAllCaches() {
- #ifndef WIN32
- QDir dir;
- // ========== 1. 标准缓存位置 ==========
- QStringList cacheLocations = {
- QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
- QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation),
- // QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation),
- // QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
- };
-
- // ========== 2. Android特定缓存位置 ==========
- cacheLocations << QDir::homePath() + "/.cache";
- cacheLocations << QDir::homePath() + "/.local/share";
-
- // ========== 3. 所有需要清理的缓存目录 ==========
- QStringList cacheDirs = {
- "qmlsc", "qml", "rhi", "scenegraph", "shaders", "pipelines",
- "graphicsshadercache", "QtShaderCache", "QtQuick", "cache",
- "Qt", "shadercache", "textures", "graphics", "RenderCache",
- "ShaderCache", "TextureCache"
- };
-
- QStringList cacheFileFilters = {"*.qmlc", "*.jsc", "*.cache", "*.tmp"};
-
- // ========== 4. 遍历并清理 ==========
- for (const QString &cachePath : cacheLocations) {
- QDir cacheDir(cachePath);
- if (cacheDir.exists()) {
- DEBUG("Scanning cache location: {}", cachePath.toStdString());
-
- // 清理指定目录
- for (const QString &subDir : cacheDirs) {
- QDir sub(cacheDir.filePath(subDir));
- if (sub.exists()) {
- sub.removeRecursively();
- DEBUG("Cleared cache directory: {}", sub.absolutePath().toStdString());
- }
- }
-
- // 清理匹配的缓存文件
- cacheDir.setNameFilters(cacheFileFilters);
- QStringList files = cacheDir.entryList(QDir::Files);
- for (const QString &file : files) {
- cacheDir.remove(file);
- DEBUG("Removed cache file: {}", cacheDir.filePath(file).toStdString());
- }
- }
- }
-
- // ========== 5. 清理临时文件 ==========
- QDir tempDir(QDir::tempPath());
- if (tempDir.exists()) {
- QStringList filters;
- filters << "Qt*" << "qml*" << "shader*" << "rhi*";
- tempDir.setNameFilters(filters);
- QStringList tempFiles = tempDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
- for (const QString &tempFile : tempFiles) {
- QFileInfo info(tempDir.filePath(tempFile));
- if (info.isDir()) {
- QDir(tempDir.filePath(tempFile)).removeRecursively();
- } else {
- tempDir.remove(tempFile);
- }
- DEBUG("Removed temp file/dir: {}", tempDir.filePath(tempFile).toStdString());
- }
- }
-
- DEBUG("All caches cleared successfully!");
- #endif
- }
- int main(int argc, char *argv[])
- {
- QtAndroidPrivate::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
- QtAndroidPrivate::requestPermission("android.permission.WRITE_EXTERNAL_STORAGE");
- INITLOG();
- sendBroadcastFromQt("sleep");
- QGuiApplication app(argc, argv);
- // ========== 第二阶段:QGuiApplication创建后再次清理缓存 ==========
- // 有些缓存只有在QGuiApplication创建后才能正确访问
- clearAllCaches();
- LOG("Second cache clear completed!");
- // 注:setupEth0() 已移到 engine.load() 之后调用。
- // 原因:它现在走 EnjoySDK,需要 Android Context(由 QtAndroidActivity 持有),
- // 而 Context 只有在 Activity 创建后才可取;此处 QGuiApplication 刚建好、取不到。
- MyCppClass myCppClass;
- #if WIN32
- QString subDirPath = "logs/run_log.txt";
- QString appDataPath ="./";
- #else
- // 获取应用程序内部存储空间路径
- QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + BZY_APP_FILES_DIR;
- LOG("appDataPath:{}",appDataPath.toStdString());
- QString appPicPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Android/data/com.yfkj.bzyv1/files/Pictures";
- LOG("appPicPath:{}",appPicPath.toStdString());
- #endif
- sendBroadcastFromQt("iccid");
- sendBroadcastFromQt("csq");
- //创建并打开SQLite数据库
- QString db_config = "config.db";
- // QString db_data = "data.db";
- SqliteOperator *sqlConfig;
- sqlConfig = new SqliteOperator(db_config);
- sqlConfig->OpenDb();
- //判断数据表是否存在
- config_db_type config_class;
- if(!sqlConfig->isTableExist(param::table_mqtt)){
- sqlConfig->CreateTable(param::table_mqtt);
- //插入数据
- //【安全】凭据改由 app_credentials.h 统一提供,不再硬编码散落各处
- config_class.mqtt_db = {1,"bzy",CRED_MQTT_HOST,CRED_MQTT_PORT,"",
- CRED_MQTT_UID,CRED_MQTT_PWD,"",0,60,
- CRED_MQTT_SUB_PREFIX,CRED_MQTT_PUB_PREFIX,
- CRED_MQTT_OFF_PREFIX,10};
- sqlConfig->InsertData(config_class,param::table_mqtt);
- //查询全部数据
- sqlConfig->QueryAllData(param::table_mqtt);
- }else{
- sqlConfig->QueryAllData(param::table_mqtt);
- }
- if(param::imei.isEmpty()){
- sendBroadcastFromQt("imei");
- QTimer::singleShot(1000, [&]() {
- sqlConfig->OpenDb();
- if(sqlConfig->isTableExist(param::table_mqtt)){
- LOG("Update imei:{}",param::imei.toStdString());
- sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei);
- }
- sqlConfig->CloseDb();
- });
- }
- if(!sqlConfig->isTableExist(param::table_mqtt_other))
- {
- sqlConfig->CreateTable(param::table_mqtt_other);
- 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};
- sqlConfig->InsertData(config_class,param::table_mqtt_other);
- //查询全部数据
- sqlConfig->QueryAllData(param::table_mqtt_other);
- }else{
- sqlConfig->QueryAllData(param::table_mqtt_other);
- }
- if(!sqlConfig->isTableExist(param::table_ftp))
- {
- sqlConfig->CreateTable(param::table_ftp);
- config_class.ftp_db = {1,CRED_FTP_HOST,CRED_FTP_PORT,"",
- CRED_FTP_UID,CRED_FTP_PWD,0};
- sqlConfig->InsertData(config_class,param::table_ftp);
- sqlConfig->QueryAllData(param::table_ftp);
- }else{
- sqlConfig->QueryAllData(param::table_ftp);
- }
- if(!sqlConfig->isTableExist(param::table_ftp_other))
- {
- sqlConfig->CreateTable(param::table_ftp_other);
- config_class.ftp_db = {1,CRED_FTP_OTHER_HOST,21,"",
- CRED_FTP_OTHER_UID,CRED_FTP_OTHER_PWD,0};
- sqlConfig->InsertData(config_class,param::table_ftp_other);
- sqlConfig->QueryAllData(param::table_ftp_other);
- }else{
- sqlConfig->QueryAllData(param::table_ftp_other);
- }
- if(!sqlConfig->isTableExist(param::table_location))
- {
- sqlConfig->CreateTable(param::table_location);
- config_class.location_db = {1,"0","0","0","0","0"};
- sqlConfig->InsertData(config_class,param::table_location);
- sqlConfig->QueryAllData(param::table_location);
- }else{
- sqlConfig->QueryAllData(param::table_location);
- }
- //相机图像参数
- if(!sqlConfig->isTableExist(param::table_camera)){
- sqlConfig->CreateTable(param::table_camera);
- config_class.camera_db = {"hikrobot","static",2,1000,1000,"0","f80","b80","f80","b80"};
- sqlConfig->InsertData(config_class,param::table_camera);
- sqlConfig->QueryAllData(param::table_camera);
- }else{
- sqlConfig->QueryAllData(param::table_camera);
- }
- //配置
- if(!sqlConfig->isTableExist(param::table_config)){
- sqlConfig->CreateTable(param::table_config);
- config_class.config_db = {1,1,1000,500,0,0,1,0};
- sqlConfig->InsertData(config_class,param::table_config);
- sqlConfig->QueryAllData(param::table_config);
- }else{
- //旧版本库没有 fusion_enable 列(景深融合开关):补列后再读,保证老设备升级后可用
- ensureColumnExist(param::table_config,"fusion_enable","fusion_enable INT NOT NULL DEFAULT 1");
- //旧版本库没有 focus_algo 列(对焦/融合算法选择):补列,默认 0=SLView 引导滤波融合
- ensureColumnExist(param::table_config,"focus_algo","focus_algo INT NOT NULL DEFAULT 0");
- ensureConfigRow(); //表被清空时补默认行,保证后续配置 UPDATE 能生效
- sqlConfig->QueryAllData(param::table_config);
- }
- sqlConfig->CloseDb();
- //InsertJson_mqtt();
- qRegisterMetaType<QByteArray>("QByteArray");
- FelgoApplication felgo;
- QQmlApplicationEngine engine;
- felgo.initialize(&engine);
- //felgo.setLicenseKey("6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C8B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397");
- LOG("信息(Info)");
- TreeModel model;
- engine.setOfflineStoragePath(appDataPath); //设置数据库存储路径
- engine.rootContext()->setContextProperty("appdir", qApp->applicationDirPath()); //使用QApplication::applicationDirPath()获取,并注册到qml中
- engine.rootContext()->setContextProperty("treeModel",&model);
- qmlRegisterType<EasyTableModel>("EasyModel",1,0,"EasyTableModel"); //注册C++模块到QML中
- qmlRegisterType<DatabaseInterface>("com.example.database", 1, 0, "DatabaseInterface");
- qmlRegisterType<CustomItem>("ExampleCustomMaterial",1,0,"CustomItem");
- // Set an optional license key from project file
- // This does not work if using Felgo Live, only for Felgo Cloud Builds and local builds
- //felgo.setLicenseKey(PRODUCT_LICENSE_KEY);
- // use this during development
- // for PUBLISHING, use the entry point below
- felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
- // 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
- // this is the preferred deployment option for publishing games to the app stores, because then your qml files and js files are protected
- // to avoid deployment of your qml files and images, also comment the DEPLOYMENTFOLDERS command in the .pro file
- // also see the .pro file for more details
- //felgo.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml"));
- const QUrl url(felgo.mainQmlFileName());
- Qt6QCamera::Frames::registerQmlType();
- SerialThread serialThread;
- serialThread.start();
- engine.rootContext()->setContextProperty("serial", &serialThread);
- CurlFtpUploader uploader_ftp; // 成员变量
- //【安全】凭据改由 app_credentials.h 统一提供
- QString remotepath = QString(CRED_FTP_DIR_PREFIX) + param::imei;
- uploader_ftp.setFtpParams(CRED_FTP_UID, CRED_FTP_PWD, CRED_FTP_HOST,
- CRED_FTP_PORT, remotepath);
- //【日志查看/上传】系统设置 -> 查看日志页使用:
- // 读取 app 运行日志(run_log*.txt)与 MCU 串口日志(mcu_console*.txt),
- // 支持 tail -f 增量刷新;上传复用同一套 FTP 凭据/远端目录,但用独立的上传器实例
- // (图片上传器失败时会删除 .txt 文件,日志不能冒这个险)。
- LogViewer logViewer;
- logViewer.setFtpParams(CRED_FTP_UID, CRED_FTP_PWD, CRED_FTP_HOST,
- CRED_FTP_PORT, remotepath);
- engine.rootContext()->setContextProperty("logViewer", &logViewer);
- MqttHandler mqttHandler;
- mqttHandler.storage()->setJsonCacheEnabled(param::jsonCacheEnable);
- mqttHandler.storage()->setImageCacheEnabled(param::imageCacheEnable);
- mqttHandler.storage()->setMaxJsonEntries(param::maxJsonEntries);
- mqttHandler.storage()->setMaxImageEntries(param::maxImageEntries);
- CurlHandler curlHandler(CRED_OTA_APP_URL, appDataPath+"/app.apk"); //app升级
- NetworkInfoHelper networkMonitor;
- //【工作状态卡片】工控机自身 CPU/内存占用:读 /proc/stat 与 /proc/meminfo,
- // 2s 采一次,换算成百分比后由 QML 直接显示
- SystemMonitor sysMonitor;
- engine.rootContext()->setContextProperty("sysMonitor", &sysMonitor);
- engine.rootContext()->setContextProperty("mqtt", &mqttHandler);
- engine.rootContext()->setContextProperty("curl", &curlHandler);
- //engine.rootContext()->setContextProperty("ymodem",serialThread.getYmodem());
- engine.rootContext()->setContextProperty("curl_picture",&uploader_ftp);
- engine.rootContext()->setContextProperty("networkMonitor", &networkMonitor);
- //【运维App】com.rd.client 自动更新/安装/守护:
- // 联网成功后每 10 分钟巡检 FTP 目录取最高版本 → 下载 → 静默安装
- // → 自动授权 → 自动拉起,并持续守护(掉线自动重启)。
- // 该目录与 OTA 同在 _UPDATE_FILE 仓库,用 cbd_user 账号;
- // bzy_user(图片上传账号)对该仓库可能被拒(550),这里登记为备用账号。
- OaAppManager oaAppManager;
- oaAppManager.setServer(CRED_OTA_UID, CRED_OTA_PWD, CRED_OA_APP_URL_BASE,
- CRED_OA_APP_PKG, appDataPath + "/oa_app");
- oaAppManager.setFallbackAccount(CRED_FTP_UID, CRED_FTP_PWD);
- engine.rootContext()->setContextProperty("oaApp", &oaAppManager);
- // 注册OpenCV图像融合功能到QML
- OpencvFunc opencvFunc;
- engine.rootContext()->setContextProperty("opencvFunc", &opencvFunc);
- // 注册权限管理到QML(定位/电话/文件与媒体/相机/系统设置修改等)
- PermissionBridge permissionBridge;
- engine.rootContext()->setContextProperty("permission", &permissionBridge);
- // 网飞系统基础服务 AIDL 集成: 绑定 service 并把 wrapper 暴露给 QML.
- WifService *wifService = new WifService(&app);
- QObject::connect(wifService, &WifService::connectedChanged, [&](bool connected) {
- if (connected) {
- // 服务已连接,可以安全调用
- wifService->setKioskMode(true);
- }
- });
- wifService->bind();
- engine.rootContext()->setContextProperty("wifService", wifService);
- // 有线网卡配置 (基于 EnjoySDK, 走系统 EthernetService, 无需 root).
- // 供 QML 状态界面查询 eth0/eth1 状态并切换 DHCP / 静态 IP。
- // 注意:设置静态 IP 时,mode=STATIC 与 IP 参数必须一次性下发(Java 侧已如此实现),
- // 分两步提交会被系统 EthernetService 拒为 -101。
- EthernetService *ethernetService = new EthernetService(&app);
- engine.rootContext()->setContextProperty("ethernet", ethernetService);
- //串口到MQTT(信号1参,槽2参,publish_m的默认qos在指针式连接中不生效,必须用lambda补参数)
- QObject::connect(&serialThread,&SerialThread::dataUpload,&mqttHandler,[&mqttHandler](const QByteArray &data){ mqttHandler.publish_m(data); });
- QObject::connect(&mqttHandler,&MqttHandler::dataReceived,&serialThread,&SerialThread::mqtttoserial);//MQTT到串口
- QObject::connect(&networkMonitor,&NetworkInfoHelper::reachabilityChanged,[&](QNetworkInformation::Reachability newReachability){
- if(newReachability==QNetworkInformation::Reachability::Online){
- WARN("网络连接!");
- param::net_alive = 1;
- }else{
- param::net_alive = 0;
- WARN("网络断开!");
- mqttHandler.disconnectFromBroker();
- }
- });
- QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
- &mqttHandler,&MqttHandler::storage_Picture);
- QObject::connect(&mqttHandler, &MqttHandler::signal_reupload_image,
- &uploader_ftp, static_cast<void (CurlFtpUploader::*)(const QString&, const QString&)>(&CurlFtpUploader::uploadFileAsync));
- QObject::connect(&mqttHandler, &MqttHandler::signal_upload_log,
- &uploader_ftp, static_cast<void (CurlFtpUploader::*)(const QString&)>(&CurlFtpUploader::uploadFileAsync));
- QObject::connect(&mqttHandler,&MqttHandler::updateStm32,[&](){
- curlHandler.seturl(CRED_OTA_MCU_URL); //【安全】凭据改由 app_credentials.h 统一提供
- //升级包仓库是 cbd_user 账号,与图片上传账号不同;用错账号服务器会回 550(code=9)
- curlHandler.setuserpwd(CRED_OTA_UID,CRED_OTA_PWD);
- //【路径统一】必须与 mserial.cpp / downloadFinished 里传给 ymodem 的路径一致
- curlHandler.setfilepath(otaFirmwarePath());
- curlHandler.settype("主板升级文件更新");
- curlHandler.start();
- //sendBroadcastFromQt("install");
- });
- QObject::connect(&mqttHandler,&MqttHandler::appdownload,[&](){
- curlHandler.seturl(CRED_OTA_APP_URL); //【安全】凭据改由 app_credentials.h 统一提供
- //升级包仓库是 cbd_user 账号,与图片上传账号不同;用错账号服务器会回 550(code=9)
- curlHandler.setuserpwd(CRED_OTA_UID,CRED_OTA_PWD);
- //curlHandler.setfilepath(appDataPath+"/app.apk");
- curlHandler.setfilepath("/sdcard/app.apk");
- curlHandler.settype("App升级文件更新");
- curlHandler.start();
- //
- });
- QObject::connect(&mqttHandler,&MqttHandler::sysReboot,[&](){
- WARN("系统重启");
- sendBroadcastFromQt("rebootSystem");
- });
- //配置项变更(拼接数量等)持久化到 camera 表
- QObject::connect(&mqttHandler,&MqttHandler::configChange,[&](){
- sqlConfig->OpenDb();
- if(sqlConfig->isTableExist(param::table_camera)){
- LOG("UpdateData stitch_photonum !!!!!");
- sqlConfig->UpdateData(param::table_camera,"stitch_photonum",QString::number(param::stitch_photonum));
- }
- sqlConfig->CloseDb();
- });
- QObject::connect(&mqttHandler,&MqttHandler::signal_imei_change,[&](QString NEW_IMEI){
- sqlConfig->OpenDb();
- if(sqlConfig->isTableExist(param::table_mqtt)){
- LOG("Update Data imei:{}",NEW_IMEI.toStdString());
- sqlConfig->UpdateData(param::table_mqtt,"imei",NEW_IMEI);
- }
- sqlConfig->CloseDb();
- });
- QObject::connect(&curlHandler,&CurlHandler::downloadFinished,[&](bool result,QString mtype){
- LOG("downloadFinished:{}-{}",result,mtype.toStdString());
- if(result&&mtype.contains("App")){
- // QByteArray download_success("{\"cmd\":\"warn\",\"ext\":{\"status\":\"App DownLoad Success!\"}}");
- // mqttHandler.publish_m(download_success);
- emit mqttHandler.appInstall();
- }
- if(result&&mtype.contains("主板升级文件更新")){
- //【路径统一】这里原来重新拼的是 GenericDataLocation+"/rtthread.rbl"
- //(= /storage/emulated/0/rtthread.rbl), 而 updateStm32 下载保存的是
- //appDataPath+"/rtthread.rbl", 两个不是同一个文件: ymodem 一直发的是根目录
- //下遗留的旧包 -> 主板 bootloader 判定"版本相同"-> 不搬运 -> 升级后版本号不变。
- const QString subDirPath = otaFirmwarePath();
- QFileInfo fi(subDirPath);
- LOG("升级文件路径:{} (exists={} size={})",subDirPath.toStdString(),
- fi.exists()?"1":"0", fi.size());
- emit serialThread.updatestart(subDirPath);
- }
- });
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- &app, [url](QObject *obj, const QUrl &objUrl) {
- if (!obj && url == objUrl)
- QCoreApplication::exit(-1);
- }, Qt::QueuedConnection);
- // 将位置信息源暴露给QML界面
- engine.load(QUrl(felgo.mainQmlFileName()));
- // 网口相机(GigE)链路配置:eth0 静态IP + Jumbo 帧 MTU。
- // 放在 engine.load() 之后:EnjoySDK 需要 Android Context,
- // 而 Context 由 QtAndroidActivity 持有,只有 QML 引擎起来后才保证可用。
- // 内部对 eth0 做幂等配置,重复执行不会破坏已有网络。
- setupEth0();
- //FelgoLiveClient liveClient(&engine);
- //UserFunc myClass(engine.rootObjects()); // 获取QML对象
- #if WIN32
- app.installNativeEventFilter(myClass.mySerialEvent); // 安装window串口拔插事件
- #endif
- //engine.rootContext()->setContextProperty("myClass", &myClass); // 将C++类添加进QML使用
- //engine.rootContext()->setContextProperty("mySerial", myClass.serial_main); // 将C++类添加进QML使用
- QObject *rootItem = engine.rootObjects().value(0);
- //traverseQmlObject(rootItem);
- #if 1
- if(rootItem)
- {
- QObject::connect(&mqttHandler,&MqttHandler::autotakephoto,[&](bool stat){
- QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
- if(Navigation_main){
- DEBUG("Navigation_main is !!!!! {}", stat);
- QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
- //打开相机
- QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
- if(autoFocus_Page){
- QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,stat));
- //将param::stitchphoto保存
- }
- }
- }); //mqtt到QML,控制qml跳转到自动对焦界面,开始对焦拍照
- QObject::connect(&serialThread,&SerialThread::auto_takephoto,[&](){
- QObject *Navigation_main = rootItem->findChild<QObject*>("Navigation_main");
- if(Navigation_main){
- DEBUG("Navigation_main is !!!!!");
- QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1));
- //打开相机
- QObject *autoFocus_Page = rootItem->findChild<QObject*>("autoFocus_Page");
- if(autoFocus_Page){
- QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,true));
- }
- }
- }); //串口到QML,控制qml跳转到自动对焦界面,结束对焦拍照
- //获取按钮点击事件
- QObject *systemset_Item = rootItem->findChild<QObject*>("systemset_Item");
- if(systemset_Item){
- QObject::connect(systemset_Item, SIGNAL(selected()),&myCppClass,SLOT(systemPage()));
- QObject::connect(&myCppClass, &MyCppClass::tosystempage,[&](){
- QObject *openbar_btn = rootItem->findChild<QObject*>("openbar_btn"); //打开状态栏
- if(openbar_btn){
- QObject::connect(openbar_btn, SIGNAL(opernBar()),&myCppClass,SLOT(openbar_btnClicked()));
- QObject::connect(&myCppClass, &MyCppClass::opensystembar,[&](){
- sendBroadcastFromQt("openbar_btn");
- });
- QObject::connect(openbar_btn, SIGNAL(closeBar()),&myCppClass,SLOT(closebar_btnClicked()));
- QObject::connect(&myCppClass, &MyCppClass::closesystembar,[&](){
- sendBroadcastFromQt("closebar_btn");
- });
- }
- QObject *opennav_btn = rootItem->findChild<QObject*>("opennav_btn"); //控制导航栏
- if(opennav_btn){
- QObject::connect(opennav_btn, SIGNAL(opernNav()),&myCppClass,SLOT(opennav_btnClicked()));
- QObject::connect(&myCppClass, &MyCppClass::opensystemnav,[&](){
- sendBroadcastFromQt("opennav_btn");
- });
- QObject::connect(opennav_btn, SIGNAL(closeNav()),&myCppClass,SLOT(closenav_btnClicked()));
- QObject::connect(&myCppClass, &MyCppClass::closesystemnav,[&](){
- sendBroadcastFromQt("closenav_btn");
- });
- }
- });
- }
- // 获取根 QML 对象
- QObject *autofocus_item = rootItem->findChild<QObject*>("autofocus_Item");
- if(autofocus_item){
- bool isConnect_frame = true;
- //const QMetaObject *metaObj = autofocus_item->metaObject();
- LOG("Found autofocus_item!");
- QObject::connect(autofocus_item, SIGNAL(selected()),&myCppClass,SLOT(qmlSlot()));
- QObject::connect(&myCppClass, &MyCppClass::recvqmlslot,[&](){
- LOG("connect myCppClass");
- Qt6QCamera::Frames *m_frames = qobject_cast<Qt6QCamera::Frames*>(rootItem->findChild<QObject*>("Frames"));
- if(!m_frames) {ERROR("m_frames is null!!!");}
- if(m_frames&&isConnect_frame){
- LOG("m_frames connected!");
- //engine.addImageProvider("ucamera",m_frames->getImageProvider());
- QObject::connect(m_frames,&Qt6QCamera::Frames::serial_data,&serialThread,&SerialThread::sendData); //Frame到串口
- QObject::connect(&serialThread,&SerialThread::takephotodone,m_frames,&Qt6QCamera::Frames::saveImage); //串口到QML,控制qml跳转到自动对焦界面
- QObject::connect(&serialThread,&SerialThread::signal_movy,m_frames,&Qt6QCamera::Frames::onMovDone);
- //串口 record_stop:停止录制并处理视频流(分析/融合/删除录制文件/上传融合图)
- QObject::connect(&serialThread,&SerialThread::recordStop,m_frames,&Qt6QCamera::Frames::handleRecordStop);
- //主板对焦完成(auto_focus):步进扫描结束即刻收尾。
- // 旧流程靠 RECORD_TIMEOUT_MS 看门狗等超时才处理,最后一步要白等 10 秒;
- // 这里直接停止录制并进入"分析最清晰帧 -> 融合 -> 上传"。
- // handleRecordStop 内部对"未在录制"有幂等保护,重复触发不会出错。
- QObject::connect(&serialThread,&SerialThread::autoFocusDone,m_frames,&Qt6QCamera::Frames::handleRecordStop);
- QObject::connect(m_frames,&Qt6QCamera::Frames::dataUpload,&mqttHandler,[&mqttHandler](const QByteArray &data){ mqttHandler.publish_m(data); }); //frames到MQTT(信号1参,槽2参需lambda补默认qos)
- // 修改信号槽连接方式
- QObject::connect(m_frames, &Qt6QCamera::Frames::signal_wait_upload,
- &uploader_ftp, static_cast<void (CurlFtpUploader::*)(const QString&)>(&CurlFtpUploader::uploadFileAsync));
- QObject::connect(&uploader_ftp, &CurlFtpUploader::finished,
- m_frames,&Qt6QCamera::Frames::handle_reult_upload);
- QObject::connect(m_frames, &Qt6QCamera::Frames::signal_cache_image,
- &mqttHandler, &MqttHandler::storage_Picture_Takephoto);
- isConnect_frame = false;
- }else{
- ERROR("m_frames no !!!!!");
- }
- });
- }else{
- DEBUG("autofocus_item no !!!!!");
- }
- }else{
- ERROR("rootItem is null !!!!!");
- }
- #endif
- LOG("app start!");
- // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...",
- // and uncomment the line below
- //FelgoLiveClient client (&engine);
- GPSInfo *gps_start = new GPSInfo(sqlConfig,&app);
- QObject::connect(gps_start,&GPSInfo::position_success,[&](){
- emit serialThread.gpsSuccess();
- });
- serialThread.recoverMcuParam();
- return app.exec();
- }
- #include "main.moc"
|