zhunk 1 maand geleden
bovenliggende
commit
c883686dc6

+ 70 - 0
app_bzy_armhf_7/qml/.cursor/rules/karpathy-guidelines.mdc

@@ -0,0 +1,70 @@
+---
+description: Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.
+alwaysApply: true
+---
+
+# Karpathy behavioral guidelines
+
+Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
+
+**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
+
+## 1. Think Before Coding
+
+**Don't assume. Don't hide confusion. Surface tradeoffs.**
+
+Before implementing:
+- State your assumptions explicitly. If uncertain, ask.
+- If multiple interpretations exist, present them - don't pick silently.
+- If a simpler approach exists, say so. Push back when warranted.
+- If something is unclear, stop. Name what's confusing. Ask.
+
+## 2. Simplicity First
+
+**Minimum code that solves the problem. Nothing speculative.**
+
+- No features beyond what was asked.
+- No abstractions for single-use code.
+- No "flexibility" or "configurability" that wasn't requested.
+- No error handling for impossible scenarios.
+- If you write 200 lines and it could be 50, rewrite it.
+
+Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
+
+## 3. Surgical Changes
+
+**Touch only what you must. Clean up only your own mess.**
+
+When editing existing code:
+- Don't "improve" adjacent code, comments, or formatting.
+- Don't refactor things that aren't broken.
+- Match existing style, even if you'd do it differently.
+- If you notice unrelated dead code, mention it - don't delete it.
+
+When your changes create orphans:
+- Remove imports/variables/functions that YOUR changes made unused.
+- Don't remove pre-existing dead code unless asked.
+
+The test: Every changed line should trace directly to the user's request.
+
+## 4. Goal-Driven Execution
+
+**Define success criteria. Loop until verified.**
+
+Transform tasks into verifiable goals:
+- "Add validation" → "Write tests for invalid inputs, then make them pass"
+- "Fix the bug" → "Write a test that reproduces it, then make it pass"
+- "Refactor X" → "Ensure tests pass before and after"
+
+For multi-step tasks, state a brief plan:
+```
+1. [Step] → verify: [check]
+2. [Step] → verify: [check]
+3. [Step] → verify: [check]
+```
+
+Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
+
+---
+
+**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.

+ 67 - 0
app_bzy_armhf_7/qml/.cursor/skills/karpathy-guidelines/SKILL.md

@@ -0,0 +1,67 @@
+---
+name: karpathy-guidelines
+description: Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.
+license: MIT
+---
+
+# Karpathy Guidelines
+
+Behavioral guidelines to reduce common LLM coding mistakes, derived from [Andrej Karpathy's observations](https://x.com/karpathy/status/2015883857489522876) on LLM coding pitfalls.
+
+**Tradeoff:** These guidelines bias toward caution over speed. For trivial tasks, use judgment.
+
+## 1. Think Before Coding
+
+**Don't assume. Don't hide confusion. Surface tradeoffs.**
+
+Before implementing:
+- State your assumptions explicitly. If uncertain, ask.
+- If multiple interpretations exist, present them - don't pick silently.
+- If a simpler approach exists, say so. Push back when warranted.
+- If something is unclear, stop. Name what's confusing. Ask.
+
+## 2. Simplicity First
+
+**Minimum code that solves the problem. Nothing speculative.**
+
+- No features beyond what was asked.
+- No abstractions for single-use code.
+- No "flexibility" or "configurability" that wasn't requested.
+- No error handling for impossible scenarios.
+- If you write 200 lines and it could be 50, rewrite it.
+
+Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
+
+## 3. Surgical Changes
+
+**Touch only what you must. Clean up only your own mess.**
+
+When editing existing code:
+- Don't "improve" adjacent code, comments, or formatting.
+- Don't refactor things that aren't broken.
+- Match existing style, even if you'd do it differently.
+- If you notice unrelated dead code, mention it - don't delete it.
+
+When your changes create orphans:
+- Remove imports/variables/functions that YOUR changes made unused.
+- Don't remove pre-existing dead code unless asked.
+
+The test: Every changed line should trace directly to the user's request.
+
+## 4. Goal-Driven Execution
+
+**Define success criteria. Loop until verified.**
+
+Transform tasks into verifiable goals:
+- "Add validation" → "Write tests for invalid inputs, then make them pass"
+- "Fix the bug" → "Write a test that reproduces it, then make it pass"
+- "Refactor X" → "Ensure tests pass before and after"
+
+For multi-step tasks, state a brief plan:
+```
+1. [Step] → verify: [check]
+2. [Step] → verify: [check]
+3. [Step] → verify: [check]
+```
+
+Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.

+ 124 - 0
app_bzy_armhf_7/qml/controls/UploadWaterProgress.qml

@@ -0,0 +1,124 @@
+import QtQuick
+import Felgo 4.0
+
+/**
+ * 上传进度圆形控件(灌水效果)。
+ *
+ * 业务背景:本设备一次只上传一张图片(上传队列串行,见 CurlFtpUploader::runLoop),
+ * 所以进度用单个圆形水位表示即可,不需要按图片序号铺多格网格。
+ *
+ * 视觉:外圈细圆环 + 内部自下而上"灌水"填充,水面带正弦波纹并持续流动,
+ * 圆心显示百分比。失败时整只圆环与水体转红,便于现场一眼区分。
+ *
+ * 实现:整块用 Canvas 绘制。
+ * 注意 Item.clip 只裁剪矩形、不裁剪圆角,靠 clip 属性做圆形裁剪会失效;
+ * Canvas 里用 arc + clip() 才是可靠的圆形裁剪方式。
+ */
+Item {
+    id: root
+
+    // 进度 0~100
+    property real percent: 0
+    // 是否失败(决定配色)
+    property bool failed: false
+    // 圆形直径
+    property real diameter: dp(56)
+
+    readonly property color themeColor: failed ? "#e74c3c" : "#28a779"
+    // 圆环线宽
+    readonly property real ringWidth: dp(2)
+
+    implicitWidth: diameter
+    implicitHeight: diameter
+
+    // 波纹相位:由动画驱动,变化时重绘 Canvas
+    property real wavePhase: 0
+    NumberAnimation on wavePhase {
+        from: 0; to: Math.PI * 2
+        duration: 1600
+        loops: Animation.Infinite
+        running: root.visible && root.percent > 0 && root.percent < 100
+    }
+
+    Canvas {
+        id: canvas
+        anchors.fill: parent
+        renderStrategy: Canvas.Cooperative
+
+        onWidthChanged: requestPaint()
+        onHeightChanged: requestPaint()
+
+        // percent / 配色 / 相位变化都要重绘
+        Connections {
+            target: root
+            function onPercentChanged() { canvas.requestPaint() }
+            function onFailedChanged() { canvas.requestPaint() }
+            function onWavePhaseChanged() { canvas.requestPaint() }
+        }
+
+        onPaint: {
+            var ctx = getContext("2d")
+            ctx.reset()
+
+            var w = width
+            var h = height
+            var cx = w / 2
+            var cy = h / 2
+            var r = Math.min(cx, cy) - root.ringWidth
+            if (r <= 0) return
+
+            var p = Math.max(0, Math.min(100, root.percent)) / 100
+
+            // ---------- 底色 ----------
+            ctx.beginPath()
+            ctx.arc(cx, cy, r, 0, Math.PI * 2)
+            ctx.fillStyle = "#66000000"
+            ctx.fill()
+
+            // ---------- 水体(圆形裁剪内自下而上填充)----------
+            if (p > 0) {
+                var levelY = cy + r - p * (r * 2)   // 水面 y:p=0 在底部,p=1 在顶部
+                var amp = Math.min(dp(2), r * 0.12) // 波纹振幅,随半径自适应
+
+                ctx.save()
+                ctx.beginPath()
+                ctx.arc(cx, cy, r, 0, Math.PI * 2)
+                ctx.clip()
+
+                ctx.beginPath()
+                ctx.moveTo(cx - r, h)
+                ctx.lineTo(cx - r, levelY)
+                // 水面:叠加两个谐波形成自然起伏
+                var steps = 48
+                for (var i = 0; i <= steps; i++) {
+                    var x = cx - r + (2 * r) * (i / steps)
+                    var y = levelY
+                            + Math.sin((i / steps) * Math.PI * 4 + root.wavePhase) * amp
+                            + Math.sin((i / steps) * Math.PI * 6 - root.wavePhase * 1.3) * (amp * 0.4)
+                    ctx.lineTo(x, y)
+                }
+                ctx.lineTo(cx + r, h)
+                ctx.closePath()
+                ctx.fillStyle = root.themeColor
+                ctx.fill()
+                ctx.restore()
+            }
+
+            // ---------- 外圈 ----------
+            ctx.beginPath()
+            ctx.arc(cx, cy, r + root.ringWidth / 2, 0, Math.PI * 2)
+            ctx.strokeStyle = root.themeColor
+            ctx.lineWidth = root.ringWidth
+            ctx.stroke()
+        }
+    }
+
+    // ---------- 圆心百分比 ----------
+    AppText {
+        anchors.centerIn: parent
+        text: Math.round(root.percent) + "%"
+        color: "white"
+        font.bold: true
+        font.pixelSize: sp(13)
+    }
+}

+ 826 - 0
app_bzy_armhf_7/qml/pages/ControlsPage.qml

@@ -0,0 +1,826 @@
+import QtQuick
+import QtQuick.Controls
+import QtQuick.Layouts
+import Qt.labs.settings 1.0 as QtLabs
+import QtQuick.Controls.Material 2.0
+import QtLocation 5.5
+import QtPositioning 5.5
+import QtMultimedia
+import Qt5Compat.GraphicalEffects
+import Felgo 4.0
+import "../controls"
+import "../common"
+//import MqttClient 1.0
+
+
+AppPage {
+  id: controlsPage
+
+
+  property string originalString: ""
+  property string collectString: ""
+  property string gps_state: "正在定位..."
+  property string board_version: ""
+  property bool connect_board: false
+  property var tt
+  property bool isonline: false
+  property var net_list:[]
+  property var picinfo_list:[]
+
+  Material.accent: Theme.tintColor
+  rightBarItem: IconButtonBarItem {
+    iconType: IconType.paintbrush
+    onClicked: {
+      themeModal.open()
+    }
+  }
+
+  Component.onCompleted: {
+    originalString = myClass.deviceid
+  }
+
+  // 接收并显示日志消息
+  Connections {
+      target: mqtt
+        onConnected: {
+          console.log("mqtt connect")
+          mqtt_sta.detailText="MQTT已连接"
+        }
+        onDisconnected: {
+          console.log("mqtt disconnect")
+          mqtt_sta.detailText="MQTT已断开"
+        }
+  }
+
+
+  Connections{
+      target: myClass
+  }
+  //串口
+  Connections{
+      target: serial
+      onDataReceived:{
+          var jsonData = JSON.parse(data)
+          console.debug("接收到主板数据:",data.toString())
+          if(jsonData.ext.work_sta==="0"){
+              if(jsonData.ext.ds==="0"){
+                work_header.text =qsTr("<b>设备开关:</b> 关机") + "-" +  qsTr("<b>工作状态:</b> 待机")
+              }else{
+                work_header.text =qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 待机")
+              }
+
+          }else if(jsonData.ext.work_sta==="1"){
+
+              if(jsonData.ext.ds==="0"){
+                work_header.text = qsTr("<b>设备开关:</b> 关机") + "-" + qsTr("<b>工作状态:</b> 采集")
+              }else{
+                work_header.text = qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 采集")
+              }
+          }
+          if(jsonData.ext.gps==="1"){
+              gps_state = "成功"
+          }
+
+          if(jsonData.ext.coll_time){
+              collectString = "   [" +jsonData.ext.coll_time[0] + "," + jsonData.ext.coll_time[1] + "," + jsonData.ext.coll_time[2] + "]";
+          }
+          if(jsonData.ext.dat_f){
+              serial.update_dat_f_main(jsonData.ext.dat_f);
+          }
+          board_version = jsonData.ext.dver
+          work_header.detailText = "电压:" + jsonData.ext.vbat + "    电流:" + jsonData.ext.current +  "    温度:" + jsonData.ext.at + "    湿度:" + jsonData.ext.ah ;
+      }
+      onDisconnect_485:{
+           work_header.text =qsTr("485未连接,读取数据失败");
+      }
+
+  }
+
+
+  MediaPlayer{
+    id: audio
+    audioOutput: AudioOutput{}
+    source: Qt.resolvedUrl("../../assets/mp3/button.mp3")
+  }
+
+  AppFlickable {
+    id: scroll
+    anchors.fill: parent
+    contentHeight: content.height
+
+    // remove focus from controls if clicked outside
+    MouseArea {
+      anchors.fill: parent
+      onClicked: {
+        scroll.forceActiveFocus()
+      }
+    }
+
+
+    Column {
+      id: content
+      width: parent.width
+
+      Timer {
+        interval: 500
+        running: true
+        repeat: true
+        onTriggered: {
+          menutab.title = Date().toString() + "      设备ID:" +  originalString.toLowerCase()  + "                  GPS状态:" + gps_state
+            if(mqtt.checkLink()){
+                mqtt_sta.detailText="MQTT已连接"
+            }else{
+                mqtt_sta.detailText="MQTT已断开"
+            }
+            net_list = mqtt.netMessage()
+            if(net_list){
+                if(net_list[0]==="1"){isonline = true}else{isonline = false}
+                mqtt_sta.text = qsTr("<b>联网状态:</b> %1 (网卡名称:%2) (描述:%3)").arg(isonline? "已联网" : "未联网").arg(net_list[1]).arg(net_list[2])
+                net_mes.text = qsTr("<b>[MAC] </b> %1").arg(net_list[3]) + qsTr("<b>[IPV4] </b> %1").arg(net_list[4])
+                mqtt_sta.detailText += "<服务器地址:>" + net_list[5]
+                mqtt_sta.detailText += "<数据上传间隔:>" + net_list[6] +  "(" +net_list[7] + ")" + "分钟";
+            }
+        }
+      }
+      Section {
+        id: menutab
+        title: Date().toString()
+
+        //SectionItem {
+          //title: "运行状态"
+          //anchors.horizontalCenter: parent.horizontalCenter
+
+          AppCard {
+            id: card
+            width: parent.width
+//            property real resetX: 0
+//            x: resetX
+
+            margin: dp(5)
+            paper.radius: dp(5)
+
+            header: SimpleRow {
+              id: work_header
+              //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+              text: qsTr("<b>设备开关:</b> 开机") + qsTr("<b>工作状态:</b> 待机")
+              detailText: "电压:" + jsonData.ext.vbat + "    电流:" + jsonData.ext.current +  "    温度:" + jsonData.ext.at + "    湿度:" + jsonData.ext.ah ;
+              badgeColor: "green"
+              image.radius: image.width / 2
+              image.fillMode: Image.PreserveAspectCrop
+              style: StyleSimpleRow {
+                showDisclosure: false
+                backgroundColor: "transparent"
+              }
+            }
+
+            media: AppImage {
+              width: card.width
+              fillMode: Image.PreserveAspectFit
+              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+            }
+
+            content: AppText{
+              id: work_apptext
+              width: card.width
+              padding: dp(15)
+              text: "设定采集时间:" + collectString;
+            }
+
+          }
+
+
+          AppCard {
+            id: card_net
+            width: parent.width
+
+            property real resetX: 0
+            x: resetX
+            margin: dp(5)
+
+
+            paper.radius: dp(5)
+
+            header: SimpleRow {
+              id: mqtt_sta
+              //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+              text: qsTr("<b>联网状态:</b> %1 (%2)").arg(app.isOnline ? "已联网" : "未联网").arg(nativeUtils.connectionType)
+              detailText: "AppCard detailed text"
+
+              image.radius: image.width / 2
+              image.fillMode: Image.PreserveAspectCrop
+              style: StyleSimpleRow {
+                showDisclosure: false
+                backgroundColor: "transparent"
+              }
+            }
+
+            media: AppImage {
+              width: parent.width
+              fillMode: Image.PreserveAspectFit
+              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+            }
+
+            content: AppText{
+              id: net_mes
+              width: parent.width
+              padding: dp(15)
+              text: "Mac" + "ipv4:";
+            }
+
+          }
+
+          // ============ 有线网卡 (eth) 状态与配置 ============
+          // 通过 EnjoySDK 走系统 EthernetService 配置,无需 root。
+          // 关键:mode=STATIC 必须与 IP 参数**一次性下发** ——
+          //      setEthernetConfig 会校验整个配置,静态模式下 IP/掩码不合法会被拒(-101),
+          //      所以不能"先只切模式、再填 IP"分两步提交(见 EthernetBridge.setStaticIp)。
+          AppCard {
+            id: card_eth
+            width: parent.width
+            margin: dp(5)
+            paper.radius: dp(5)
+
+            // ---- 状态 ----
+            property string ethIface: "eth1"      // 目标网卡,可切换 eth0/eth1
+            property int    ethLinkState: -1       // 0未连接 1连接中 2已连接 3断开中 4未知
+            property int    ethMode: 0              // 1=DHCP 2=静态 3=PPPOE 4=未知
+            property bool   ethEnabled: false
+            property string ethMac: ""
+            property string ethIp: ""
+            property string ethMask: ""
+            property string ethGateway: ""
+            property string ethDns: ""
+
+            // ---- 配置输入 ----
+            // 默认值:与 GigE 相机同网段的 192.168.100.101 + Jumbo 帧 MTU 9000。
+            // 若网卡已有配置,refresh() 会用实际值覆盖这两项。
+            property bool useDhcp: true            // true=DHCP false=静态
+            property string ipInput: "192.168.100.101"
+            property string maskInput: "255.255.255.0"
+            property string gatewayInput: ""
+            property string dnsInput: ""
+            property string mtuInput: "9000"
+            property string ethMessage: ""
+            property bool   ethBusy: false
+
+            // 链路状态文字
+            readonly property string linkText: {
+              switch (ethLinkState) {
+                case 0:  return "未连接"
+                case 1:  return "连接中"
+                case 2:  return "已连接"
+                case 3:  return "断开中"
+                default: return "未知"
+              }
+            }
+            readonly property string linkColor: {
+              switch (ethLinkState) {
+                case 2:  return "#28a779"   // 已连接=绿
+                case 1:
+                case 3:  return "#e8a33d"   // 连接中/断开中=黄
+                case 0:  return "#e74c3c"   // 未连接=红
+                default: return "#999999"
+              }
+            }
+            readonly property string modeText: {
+              switch (ethMode) {
+                case 1:  return "DHCP"
+                case 2:  return "静态"
+                case 3:  return "PPPOE"
+                default: return "未知"
+              }
+            }
+
+            // 读取指定网卡状态
+            // keepMode: 为 true 时不覆盖 useDhcp —— 设置模式下发的瞬间系统返回值
+            // 可能还没刷新,若此时用 r.mode 回写会把用户刚选的模式弹回去。
+            function refresh(iface, keepMode) {
+              if (iface !== undefined && iface !== "")
+                card_eth.ethIface = iface
+              var r = ethernet.status(card_eth.ethIface)
+              if (!r || r.ok !== true) {
+                card_eth.ethMessage = "读取失败: " + (r && r.msg ? r.msg : ethernet.lastError())
+                card_eth.ethLinkState = -1
+                return
+              }
+              card_eth.ethLinkState = r.linkState !== undefined ? r.linkState : -1
+              card_eth.ethMode      = r.mode !== undefined ? r.mode : 0
+              card_eth.ethEnabled   = (r.enabled === true)
+              card_eth.ethMac       = r.mac || ""
+              card_eth.ethIp        = r.ip || ""
+              card_eth.ethMask      = r.subnetMask || ""
+              card_eth.ethGateway   = r.gateway || ""
+              card_eth.ethDns       = r.dns || ""
+              // 用当前实际配置回填输入框
+              if (r.ip && r.ip !== "0.0.0.0") {
+                card_eth.ipInput      = r.ip
+                card_eth.maskInput    = r.subnetMask || "255.255.255.0"
+                card_eth.gatewayInput = r.gateway || ""
+                card_eth.dnsInput     = r.dns || ""
+              }
+              if (keepMode !== true) {
+                card_eth.useDhcp = (r.mode === 1)
+              }
+              card_eth.ethMessage = ""
+            }
+
+            // 切换为 DHCP 模式。
+            // 注意:静态模式**不能**在这里单独下发 —— setEthernetConfig 会校验整个配置,
+            // 静态模式下 IP/掩码必须合法,只改 mode 会被拒(-101)。
+            // 所以切静态只改界面状态,等用户填好 IP 后由 applyStaticIp() 一次性下发。
+            function applyDhcp() {
+              card_eth.ethBusy = true
+              var r = ethernet.setDhcp(card_eth.ethIface, true)   // true = DHCP
+              card_eth.ethBusy = false
+              if (r && r.ok === true) {
+                card_eth.ethMessage = "已切换为 DHCP 模式"
+                card_eth.refresh(undefined, true)
+              } else {
+                card_eth.ethMessage = "切换失败: " + (r && r.msg ? r.msg : ethernet.lastError())
+              }
+            }
+
+            // 应用静态配置:先 MTU,再静态 IP
+            // 【顺序很重要】setMtu 内部会 ifconfig down/up,会重置网卡;
+            // 若先下发 IP 再改 MTU,刚设好的 IP 可能被 down/up 冲掉。
+            function applyStaticIp() {
+              if (!card_eth.ipInput) {
+                card_eth.ethMessage = "请输入 IP 地址"
+                return
+              }
+              card_eth.ethBusy = true
+
+              // 步骤 1:设置 MTU(Jumbo 帧)。
+              // EnjoySDK 没有 MTU 接口,只能走 ifconfig + su,需要 root;
+              // 失败不影响后续 IP 下发,单独在提示里说明。
+              var mtuMsg = ""
+              var mtu = parseInt(card_eth.mtuInput)
+              if (!isNaN(mtu) && mtu > 0) {
+                var m = ethernet.setMtu(card_eth.ethIface, mtu)
+                if (m && m.ok === true) {
+                  mtuMsg = ",MTU=" + mtu
+                } else {
+                  var why = ethernet.lastError()
+                  mtuMsg = ",MTU 未生效" + (why ? "(" + why + ")" : "")
+                }
+              }
+
+              // 步骤 2:一次性下发 mode=STATIC + IP
+              // (setStaticIp 内部把 mode 与 IP 字段一起提交;
+              //   若只切模式再设 IP,静态模式下配置校验不过会被拒 -101)
+              var r = ethernet.setStaticIp(card_eth.ethIface,
+                                           card_eth.ipInput,
+                                           card_eth.maskInput,
+                                           card_eth.gatewayInput,
+                                           card_eth.dnsInput)
+              card_eth.ethBusy = false
+              if (!r || r.ok !== true) {
+                card_eth.ethMessage = "设置失败: " + (r && r.msg ? r.msg : ethernet.lastError())
+                return
+              }
+              card_eth.useDhcp = false
+              card_eth.ethMessage = "静态 IP 已应用: " + card_eth.ipInput + mtuMsg
+              card_eth.refresh(undefined, true)
+            }
+
+            header: SimpleRow {
+              id: eth_sta
+              text: qsTr("<b>有线网卡:</b> %1 (%2)").arg(card_eth.ethIface).arg(card_eth.linkText)
+              detailText: qsTr("模式: %1  IP: %2").arg(card_eth.modeText)
+                                              .arg(card_eth.ethIp === "" ? "未分配" : card_eth.ethIp)
+              image.radius: image.width / 2
+              image.fillMode: Image.PreserveAspectCrop
+              style: StyleSimpleRow {
+                showDisclosure: false
+                backgroundColor: "transparent"
+              }
+            }
+
+            media: Rectangle {
+              width: parent.width
+              height: dp(4)
+              color: card_eth.linkColor
+            }
+
+            content: ColumnLayout {
+              id: eth_content
+              width: card_eth.width
+              spacing: dp(10)
+
+              // ---- 网卡选择 ----
+              RowLayout {
+                Layout.fillWidth: true
+                spacing: dp(10)
+
+                AppText {
+                  text: "网卡"
+                  color: Theme.textColor
+                }
+
+                // 目标网卡:默认 eth1,可切换
+                RowLayout {
+                  spacing: dp(6)
+                  Repeater {
+                    model: ["eth0", "eth1"]
+                    delegate: AppButton {
+                      // 用 var 而非 string:与下面对象数组的 delegate 保持一致,
+                      // 避免 Qt 版本对 modelData 类型推断的差异
+                      required property var modelData
+                      text: modelData
+                      flat: true
+                      // 用 opacity 而非 visible 表达选中态,避免切换时按钮宽度跳变
+                      opacity: card_eth.ethIface === modelData ? 1 : 0.5
+                      onClicked: {
+                        card_eth.ethIface = modelData
+                        card_eth.refresh()
+                      }
+                    }
+                  }
+                }
+
+                Item { Layout.fillWidth: true }
+
+                AppButton {
+                  text: "刷新"
+                  onClicked: card_eth.refresh()
+                }
+              }
+
+              // ---- 当前状态明细 ----
+              AppText {
+                Layout.fillWidth: true
+                text: "MAC: " + (card_eth.ethMac === "" ? "-" : card_eth.ethMac)
+                color: Theme.textColor
+                font.pixelSize: sp(12)
+                elide: Text.ElideMiddle
+              }
+              AppText {
+                Layout.fillWidth: true
+                text: "模式: " + card_eth.modeText
+                     + "    子网掩码: " + (card_eth.ethMask === "" ? "-" : card_eth.ethMask)
+                     + "    网关: " + (card_eth.ethGateway === "" ? "-" : card_eth.ethGateway)
+                color: Theme.textColor
+                font.pixelSize: sp(12)
+                elide: Text.ElideMiddle
+              }
+
+              // ---- DHCP / 静态 切换 ----
+              RowLayout {
+                Layout.fillWidth: true
+                spacing: dp(10)
+
+                AppText {
+                  text: "IP 模式"
+                  color: Theme.textColor
+                }
+
+                RowLayout {
+                  spacing: dp(6)
+                  Repeater {
+                    model: [{ label: "DHCP",   value: true },
+                            { label: "静态IP", value: false }]
+                    delegate: AppButton {
+                      required property var modelData
+                      text: modelData.label
+                      flat: true
+                      opacity: card_eth.useDhcp === modelData.value ? 1 : 0.5
+                      onClicked: {
+                        if (card_eth.useDhcp === modelData.value)
+                          return
+                        card_eth.useDhcp = modelData.value
+                        if (modelData.value === true) {
+                          // 切 DHCP:直接下发(DHCP 不需要调用方提供 IP)
+                          card_eth.applyDhcp()
+                        } else {
+                          // 切静态:只展开参数表单,**暂不下发**。
+                          // 静态模式要求 IP/掩码齐全,单独改 mode 会被系统拒(-101);
+                          // 等用户填好后点「应用静态IP」时 mode+IP 一次性提交。
+                          card_eth.ethMessage = "请填写静态 IP 参数,然后点「应用静态IP」"
+                        }
+                      }
+                    }
+                  }
+                }
+
+                Item { Layout.fillWidth: true }
+
+                // 网卡开关
+                AppButton {
+                  text: card_eth.ethEnabled ? "关闭网卡" : "启用网卡"
+                  enabled: !card_eth.ethBusy
+                  onClicked: {
+                    var r = ethernet.setEnabled(card_eth.ethIface, !card_eth.ethEnabled)
+                    if (r && r.ok === true) {
+                      card_eth.refresh()
+                    } else {
+                      card_eth.ethMessage = "操作失败: " + (r && r.msg ? r.msg : ethernet.lastError())
+                    }
+                  }
+                }
+              }
+
+              // ---- 静态 IP 参数(仅静态模式下可编辑)----
+              // 这里用 visible(而非 opacity)是有意的:DHCP 模式下要让整块参数
+              // 真正收起、不占布局空间;用 opacity 隐藏的话输入框仍会占位。
+              // 下方"模式"按钮与网卡开关是固定行,不受这里影响。
+              ColumnLayout {
+                Layout.fillWidth: true
+                spacing: dp(6)
+                visible: !card_eth.useDhcp
+                enabled: !card_eth.useDhcp && !card_eth.ethBusy
+
+                AppText {
+                  text: "静态 IP 参数"
+                  color: Theme.textColor
+                  font.pixelSize: sp(12)
+                }
+
+                GridLayout {
+                  Layout.fillWidth: true
+                  columns: 2
+                  columnSpacing: dp(10)
+                  rowSpacing: dp(8)
+
+                  AppText { text: "IP 地址"; color: Theme.textColor }
+                  AppTextField {
+                    Layout.fillWidth: true
+                    text: card_eth.ipInput
+                    placeholderText: "如 192.168.100.101"
+                    onTextChanged: card_eth.ipInput = text
+                  }
+
+                  AppText { text: "子网掩码"; color: Theme.textColor }
+                  AppTextField {
+                    Layout.fillWidth: true
+                    text: card_eth.maskInput
+                    placeholderText: "255.255.255.0"
+                    onTextChanged: card_eth.maskInput = text
+                  }
+
+                  AppText { text: "网关"; color: Theme.textColor }
+                  AppTextField {
+                    Layout.fillWidth: true
+                    text: card_eth.gatewayInput
+                    placeholderText: "可留空"
+                    onTextChanged: card_eth.gatewayInput = text
+                  }
+
+                  AppText { text: "DNS"; color: Theme.textColor }
+                  AppTextField {
+                    Layout.fillWidth: true
+                    text: card_eth.dnsInput
+                    placeholderText: "可留空"
+                    onTextChanged: card_eth.dnsInput = text
+                  }
+
+                  AppText { text: "MTU"; color: Theme.textColor }
+                  AppTextField {
+                    Layout.fillWidth: true
+                    text: card_eth.mtuInput
+                    placeholderText: "如 9000 (Jumbo 帧)"
+                    inputMethodHints: Qt.ImhDigitsOnly
+                    onTextChanged: card_eth.mtuInput = text
+                  }
+                }
+
+                // MTU 说明:EnjoySDK 没有 MTU 接口,只能走 ifconfig + su,
+                // 需要设备已 root;失败不影响上面已下发的 IP 配置。
+                AppText {
+                  Layout.fillWidth: true
+                  text: "MTU(9000) 用于 GigE 大帧,需设备已 root;失败不影响 IP 配置"
+                  color: "#999999"
+                  font.pixelSize: sp(11)
+                  wrapMode: Text.Wrap
+                }
+
+                RowLayout {
+                  Layout.fillWidth: true
+                  spacing: dp(10)
+                  Item { Layout.fillWidth: true }
+                  AppButton {
+                    text: card_eth.ethBusy ? "应用中..." : "应用静态IP"
+                    enabled: !card_eth.ethBusy
+                    onClicked: card_eth.applyStaticIp()
+                  }
+                }
+              }
+
+              // ---- 结果提示 ----
+              AppText {
+                Layout.fillWidth: true
+                text: card_eth.ethMessage
+                color: card_eth.ethMessage === "" ? Theme.textColor : "#e8a33d"
+                font.pixelSize: sp(12)
+                wrapMode: Text.Wrap
+              }
+            }
+
+            Component.onCompleted: {
+              // 默认展示 eth1 状态(eth0 用于 GigE 相机,由程序启动时自动配置)
+              card_eth.ethIface = "eth1"
+              card_eth.refresh()
+            }
+          }
+
+//          AppCard {
+//            id: card_cfg
+//            width: parent.width
+//            height: width*1.5
+//            property real resetX: 0
+//            x: resetX
+//            margin: dp(5)
+
+//            paper.radius: dp(5)
+
+//            header: SimpleRow {
+//              imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+//              text: "参数"
+//              detailText: "AppCard detailed text"
+
+//              image.radius: image.width / 2
+//              image.fillMode: Image.PreserveAspectCrop
+//              style: StyleSimpleRow {
+//                showDisclosure: false
+//                backgroundColor: "transparent"
+//              }
+//            }
+
+//            media: AppImage {
+//              width: card_cfg.width
+//              fillMode: Image.PreserveAspectFit
+//              source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
+//            }
+
+//            content: AppText{
+//              width: card_cfg.width
+//              padding: dp(15)
+//              text: "此界面显示参数等信息,运行时间等"
+//            }
+
+//            cardSwipeArea.onSwipeOutCompleted: {
+//              card_cfg.x = card_cfg.resetX
+//              card_cfg.rotation = 0
+//            }
+//          }
+
+        //} // AppCard section
+
+      } // convenience controls section
+
+
+
+      Timer {
+        interval: 1000
+        running: true
+        repeat: true
+        onTriggered: {
+          picinfo_list = serial.pathinfo()
+          pic_path.text = "图片存储目录:" + picinfo_list[0]
+          pic_count.text = "文件数量:" + picinfo_list[1]
+          pic_total.text = "占用大小:" + picinfo_list[2] + "(Mb)"
+        }
+      }
+
+      Section {
+        title: "存储信息"
+        bottomPadding: dp(Theme.navigationBar.defaultBarItemPadding)
+
+        Grid {
+          anchors.horizontalCenter: parent.horizontalCenter
+          columns: 2
+          rows: 4
+          //horizontalItemAlignment: Grid.AlignHCenter
+          Column{
+              AppButton {
+                text: "查询"
+                flat: false
+                onClicked: {
+                    serial.readPathinfo()
+                }
+              }
+              AppButton {
+                text: "清理"
+                flat: false
+                onClicked: {
+                    serial.removepic()
+                }
+              }
+          }
+
+
+          Column{
+
+              AppText {
+                  id: pic_path
+                  text: "图片存储目录:" + picinfo_list[0]
+              }
+
+              AppText{
+                  id: pic_count
+                  text: "文件数量:" + picinfo_list[1]
+              }
+
+              AppText{
+                  id: pic_total
+                  text: "占用大小:" + picinfo_list[2]
+              }
+          }
+
+
+
+
+
+        }
+      } // native utils section             }
+
+      Section {
+        title: "Device Info"
+        bottomPadding: dp(15)
+
+        Row {
+          width: parent.width - dp(30)
+          anchors.horizontalCenter: parent.horizontalCenter
+          spacing: dp(5)
+
+          Column {
+            id: firstInfoColumn
+            spacing: dp(5)
+            width: (parent.width - parent.spacing) * 0.5
+            AppText {
+              text: "<b>OS Type:</b> " + system.osType
+              font.pixelSize: sp(11)
+              visible: system.osType !== "undefined"
+            }
+            AppText {
+              text: "<b>OS Version:</b> " + system.osVersion
+              font.pixelSize: sp(11)
+              visible: system.osVersion !== "undefined"
+            }
+            AppText {
+              text: "<b>Device Model:</b> " + nativeUtils.deviceModel()
+              font.pixelSize: sp(11)
+              visible: nativeUtils.deviceModel() !== "undefined"
+            }
+            AppText {
+              text: qsTr("<b>Device Online:</b> %1 (%2)").arg(app.isOnline ? "Yes" : "No").arg(nativeUtils.connectionType)
+              font.pixelSize: sp(11)
+            }
+            AppText {
+              text: "<b>MAC Address:</b> " + system.macAddress
+              font.pixelSize: sp(11)
+              width: parent.width
+              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+              visible: system.macAddress !== "undefined"
+            }
+            AppText {
+              text: "<b>Unique Device Id:</b> " + system.UDID
+              font.pixelSize: sp(11)
+              width: parent.width
+              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+              visible: system.UDID !== "undefined"
+            }
+          }
+
+          Column {
+            id: secondInfoColumn
+            spacing: dp(5)
+            width: firstInfoColumn.width
+            AppText {
+              text: "<b>Orientation:</b> " + (Theme.isPortrait ? "portrait" : "landscape")
+              font.pixelSize: sp(11)
+            }
+            AppText {
+              text: "<b>Statusbar Height:</b> " + Theme.statusBarHeight
+              font.pixelSize: sp(11)
+            }
+            AppText {
+              text: "<b>App Identifier:</b> " + system.appIdentifier
+              font.pixelSize: sp(11)
+              width: parent.width
+              wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+              visible: system.appIdentifier !== "undefined"
+            }
+            AppText {
+              text: "<b>App Version:</b> " + system.appVersionCode
+              font.pixelSize: sp(11)
+            }
+            AppText {
+              text: "<b>Qt Version:</b> " + system.qtVersion
+              font.pixelSize: sp(11)
+            }
+            AppText {
+              text: "<b>Felgo Version:</b> " + system.felgoVersion + " (" + system.felgoVersionRef + ")"
+              font.pixelSize: sp(11)
+            }
+          }
+        }
+      } // device info section
+    } // content column
+  } // flickable
+
+  ThemeModal {
+    id: themeModal
+    pushBackContent: navigationStack
+  } // theme modal
+} // page
+

+ 270 - 0
app_bzy_armhf_7/qml/pages/PermissionPage.qml

@@ -0,0 +1,270 @@
+import Felgo
+import QtQuick
+import QtQuick.Controls
+
+import "../controls"
+import "../common"
+
+/**
+ * 权限管理页。
+ *
+ * 背景:Android 把权限分两类,平台强制不可绕过——
+ *   1) 运行时权限(定位/电话/文件与媒体/相机):应用可主动弹窗申请,用户点"允许"即授予;
+ *   2) 特殊权限(修改系统设置/所有文件访问/悬浮窗):平台禁止静默授予,只能跳系统设置页;
+ *      若用户已为本应用开启"无障碍服务",可由无障碍服务代为点击开关。
+ *
+ * 本页职责:展示各权限状态、提供授权入口、一键补齐全部缺失项。
+ * 数据源为 C++ 侧 PermissionBridge(上下文属性名 permission)。
+ */
+AppPage {
+    id: page
+
+    title: qsTr("权限管理")
+    backgroundColor: app.theme_backgroundColor
+
+    // 本页是被 ProfilePage 用 navigationStack.push() 压入的第二层页面(栈深度 > 0),
+    // 返回按钮由 Felgo 渲染在导航栏的左侧,因此绝不能隐藏导航栏 ——
+    // 否则界面上没有任何返回入口,只能靠 Android 物理返回键。
+    // 参照同文件的既有写法:ProfilePage.qml 中的 sqlite_component 也是 push 进去的
+    // AppPage,同样保留导航栏(仅配 rightBarItem)。
+    // 导航栏外观已在 Main.qml 的 onInitTheme 中统一配置:
+    //   Theme.navigationBar.backgroundColor = app.cardColor
+    //   Theme.navigationBar.titleColor     = app.fontColor
+    //   Theme.navigationBar.height         = dp(56)
+    navigationBarHidden: false
+
+    // 权限项数据由 C++ 侧提供;PC 调试时 C++ 侧返回占位数据,页面照常渲染
+    property var items: permission ? permission.permissionList : []
+    property int missing: permission ? permission.missingCount : 0
+    property bool accOn: permission ? permission.accessibilityEnabled : false
+
+    Column {
+        id: rootCol
+        width: parent.width
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.margins: dp(16)
+        spacing: dp(10)
+
+        // ---------- 顶部:无障碍服务状态与说明 ----------
+        Rectangle {
+            width: parent.width
+            height: accTipCol.height + dp(24)
+            radius: dp(8)
+            color: page.accOn ? "#e6f4ea" : "#fff4e5"
+            border.color: page.accOn ? "#34a853" : "#e8a33d"
+            border.width: 1
+
+            Column {
+                id: accTipCol
+                anchors.left: parent.left
+                anchors.right: parent.right
+                anchors.top: parent.top
+                anchors.margins: dp(12)
+                spacing: dp(6)
+
+                AppText {
+                    text: page.accOn ? "无障碍服务已开启" : "无障碍服务未开启"
+                    color: page.accOn ? "#1e7e34" : "#a06000"
+                    fontSize: 15
+                    font.bold: true
+                }
+
+                AppText {
+                    width: parent.width
+                    text: page.accOn
+                        ? "“修改系统设置”“所有文件访问”可自动点击开启,无需手动到设置页操作。"
+                        : "开启无障碍服务后,本应用可自动点击系统设置里的权限开关(Android 要求必须由用户手动授权开启一次,程序无法绕过)。未开启也可使用,但特殊权限需手动点击。"
+                    color: "#555555"
+                    fontSize: 12
+                    wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+                }
+
+                AppButton {
+                    id: accBtn
+                    text: page.accOn ? "无障碍设置" : "去开启无障碍服务"
+                    textColor: "white"
+                    backgroundColor: page.accOn ? "#5f6368" : "#1a73e8"
+                    flat: false
+                    onClicked: {
+                        permission.openAccessibilitySettings()
+                    }
+                }
+            }
+        }
+
+        // ---------- 一键补齐 ----------
+        Row {
+            width: parent.width
+            spacing: dp(10)
+
+            AppButton {
+                id: btnAll
+                text: page.missing > 0 ? ("一键补齐缺失权限(" + page.missing + ")")
+                                       : "全部权限已就绪"
+                textColor: "white"
+                backgroundColor: page.missing > 0 ? "#1a73e8" : "#9aa0a6"
+                flat: false
+                enabled: page.missing > 0
+                onClicked: {
+                    permission.requestAll()
+                }
+            }
+
+            AppButton {
+                id: btnRefresh
+                text: "刷新状态"
+                textColor: "white"
+                backgroundColor: "#5f6368"
+                flat: false
+                onClicked: {
+                    permission.checkAll()
+                }
+            }
+        }
+
+        // ---------- 操作结果提示 ----------
+        Rectangle {
+            id: msgBox
+            width: parent.width
+            height: visible ? msgText.height + dp(16) : 0
+            visible: permission && permission.lastMessage !== ""
+            radius: dp(6)
+            color: "#e8f0fe"
+
+            AppText {
+                id: msgText
+                anchors.left: parent.left
+                anchors.right: parent.right
+                anchors.top: parent.top
+                anchors.margins: dp(8)
+                text: permission ? permission.lastMessage : ""
+                color: "#174ea6"
+                fontSize: 12
+                wrapMode: Text.WrapAtWordBoundaryOrAnywhere
+            }
+
+            MouseArea {
+                anchors.fill: parent
+                onClicked: permission.clearMessage()
+            }
+        }
+    }
+
+    // ---------- 权限列表 ----------
+    // 放在 Column 之外用锚点定位:避免 Column 依据 ListView 隐式高度、
+    // ListView 又依赖 Column 高度计算剩余空间的布局循环
+    ListView {
+        id: list
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: rootCol.bottom
+        anchors.bottom: parent.bottom
+        anchors.margins: dp(16)
+        clip: true
+        spacing: dp(6)
+        model: page.items
+        boundsBehavior: Flickable.StopAtBounds
+
+        // 行高复用,减少重复布局开销
+        delegate: Item {
+            id: rowItem
+            width: list.width
+            height: dp(52)
+
+            Rectangle {
+                anchors.fill: parent
+                radius: dp(6)
+                color: modelData.granted ? "#ffffff" : "#fff8f8"
+                border.color: modelData.granted ? "#d0d0d0" : "#e07a7a"
+                border.width: 1
+
+                Row {
+                    anchors.left: parent.left
+                    anchors.leftMargin: dp(12)
+                    anchors.verticalCenter: parent.verticalCenter
+                    spacing: dp(10)
+
+                    // 状态圆点
+                    Rectangle {
+                        width: dp(12)
+                        height: dp(12)
+                        radius: width / 2
+                        anchors.verticalCenter: parent.verticalCenter
+                        color: modelData.granted ? "#34a853" : "#d93025"
+                    }
+
+                    Column {
+                        anchors.verticalCenter: parent.verticalCenter
+                        spacing: dp(2)
+
+                        AppText {
+                            text: modelData.name
+                            color: app.fontColor
+                            fontSize: 14
+                            font.bold: true
+                        }
+
+                        AppText {
+                            text: {
+                                if (modelData.granted)
+                                    return "已开启"
+                                if (modelData.group === "accessibility")
+                                    return "未开启(自动点击的前置条件)"
+                                if (modelData.autoClickSupport && page.accOn)
+                                    return "未开启(将自动点击)"
+                                if (modelData.special)
+                                    return "未开启(特殊权限,需在系统设置手动开启)"
+                                return "未开启"
+                            }
+                            color: modelData.granted ? "#188038" : "#c5221f"
+                            fontSize: 11
+                        }
+                    }
+                }
+
+                // 右侧操作按钮
+                Row {
+                    anchors.right: parent.right
+                    anchors.rightMargin: dp(10)
+                    anchors.verticalCenter: parent.verticalCenter
+                    spacing: dp(6)
+
+                    // 无障碍已开启时,支持自动点击的项提供"自动开启"入口
+                    AppButton {
+                        visible: !modelData.granted
+                                 && modelData.autoClickSupport
+                                 && page.accOn
+                        text: "自动开启"
+                        textColor: "white"
+                        backgroundColor: "#1a73e8"
+                        flat: false
+                        onClicked: {
+                            permission.request(modelData.group)
+                        }
+                    }
+
+                    AppButton {
+                        visible: !modelData.granted
+                                 && !(modelData.autoClickSupport && page.accOn)
+                        text: modelData.group === "accessibility" ? "去开启" : "去设置"
+                        textColor: "white"
+                        backgroundColor: modelData.special ? "#5f6368" : "#1a73e8"
+                        flat: false
+                        onClicked: {
+                            if (modelData.group === "accessibility")
+                                permission.openAccessibilitySettings()
+                            else
+                                permission.request(modelData.group)
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    Component.onCompleted: {
+        if (permission) permission.checkAll()
+    }
+}