diff --git a/Makefile b/Makefile index 268a535..1710a68 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ SHELL := /bin/bash -COMPILE_SH ?= /home/hyx/work/ap05_dev_gaiban/APP_AP05_1.1.22_tuxi_shengchan/compile.sh +COMPILE_SH ?= /home/hyx/work/dev_doc/ap05_dev_gaiban/APP_AP05_1.1.22_tuxi_shengchan/compile.sh SRC := update_mac_pdd.c TARGET_ARM64 := update_mac_pdd TARGET_NATIVE := update_mac_pdd_native diff --git a/update_mac_pdd b/update_mac_pdd index ef07871..fcbf1e9 100755 Binary files a/update_mac_pdd and b/update_mac_pdd differ diff --git a/update_mac_pdd.c b/update_mac_pdd.c index e631614..9739850 100644 --- a/update_mac_pdd.c +++ b/update_mac_pdd.c @@ -1184,7 +1184,7 @@ static int detect_resetkey_gesture(void) { } last_press_ms = t; - if (press_count >= 3) { + if (press_count >= 4) { long long hold_start = now_ms(); while (1) { int v = read_resetkey_value(); @@ -1242,6 +1242,39 @@ static void* reset_key_monitor_thread(void* arg) { stop_yellow_blink(); start_yellow_fast_blink(); + fprintf(stderr, "resetkey trigger: backup network config\n"); + resetkey_log("resetkey trigger: backup network config\n"); + + // 备份网络配置文件 + if (system("cp /etc/network/interfaces /etc/network/interfaces.bak") == 0) { + resetkey_log("network config backed up\n"); + + // 创建动态IP配置 + FILE* fp = fopen("/etc/network/interfaces", "w"); + if (fp) { + fprintf(fp, "# This file describes the network interfaces available on your system\n"); + fprintf(fp, "# and how to activate them. For more information, see interfaces(5).\n"); + fprintf(fp, "\n"); + fprintf(fp, "source /etc/network/interfaces.d/*\n"); + fprintf(fp, "\n"); + fprintf(fp, "# The loopback network interface\n"); + fprintf(fp, "auto lo\n"); + fprintf(fp, "iface lo inet loopback\n"); + fprintf(fp, "\n"); + fprintf(fp, "# The primary network interface\n"); + fprintf(fp, "auto eth0\n"); + fprintf(fp, "iface eth0 inet dhcp\n"); + fclose(fp); + resetkey_log("network config changed to DHCP\n"); + + // 重启网络接口 + fprintf(stderr, "restarting network interface...\n"); + resetkey_log("restarting network interface...\n"); + system("ifdown eth0 --force && ifup eth0"); + sleep(3); // 等待网络启动 + } + } + fprintf(stderr, "resetkey trigger: copy %s:%s -> %s\n", remote_host, remote_dir, local_dir); resetkey_log("resetkey trigger: copy %s:%s -> %s\n", remote_host, remote_dir, local_dir); @@ -1252,10 +1285,39 @@ static void* reset_key_monitor_thread(void* arg) { sleep(2); set_yellow_off(); resetkey_log("resetkey copy ok\n"); + + // 恢复网络配置 + fprintf(stderr, "restoring network config...\n"); + resetkey_log("restoring network config...\n"); + + if (system("cp /etc/network/interfaces.bak /etc/network/interfaces") == 0) { + resetkey_log("network config restored\n"); + + // 清理网络接口地址,避免冲突 + system("ip addr flush dev eth0"); + sleep(1); // 等待接口清理完成 + + // 再次重启网络接口 + system("ifdown eth0 --force && ifup eth0"); + resetkey_log("network interface restarted\n"); + } } else { stop_yellow_blink(); set_yellow_off(); resetkey_log("resetkey copy failed\n"); + + // 即使复制失败也要恢复网络配置 + fprintf(stderr, "copy failed, restoring network config...\n"); + resetkey_log("copy failed, restoring network config...\n"); + + if (system("cp /etc/network/interfaces.bak /etc/network/interfaces") == 0) { + // 清理网络接口地址,避免冲突 + system("ip addr flush dev eth0"); + sleep(1); // 等待接口清理完成 + + system("ifdown eth0 --force && ifup eth0"); + resetkey_log("network config restored after failure\n"); + } } while (read_resetkey_value() == resetkey_pressed_level) {