guohui преди 1 година
родител
ревизия
728292fdf6
променени са 4 файла, в които са добавени 87 реда и са изтрити 6 реда
  1. 4 4
      pro/config/cfg.h
  2. 75 1
      pro/src/sys.c
  3. 1 0
      pro/src/sys.h
  4. 7 1
      pro/ui/ui.c

+ 4 - 4
pro/config/cfg.h

@@ -176,10 +176,6 @@
     #define CHANNEL_DELAY                       8
 
     #define PROD_POWER_TYPE                     5
-
-    #define USE_UI
-    #define USE_SCREEN_LED
-    //#define USE_SCREEN_LCD
 #elif defined PRJ_TEST_AC_I1_O1
     #define LANGUAGE                            0           //chinese
     #define SMPLE_TIME                          30          //ms
@@ -222,6 +218,10 @@
     #define CHANNEL_DELAY                       8
 
     #define PROD_POWER_TYPE                     1
+
+    #define USE_UI
+    #define USE_SCREEN_LED
+    //#define USE_SCREEN_LCD
 #else
     #error define a PRJ_XXXX please!
 #endif

+ 75 - 1
pro/src/sys.c

@@ -1516,12 +1516,86 @@ int sys_chmod(void)
 
     return 0;
 }
+
+
+static void dhcp_restart(void)
+{
+    int r;
+    char ipaddr[64],mask[64];
+    NetworkInfo_t net4,net6;
+
+    r = get_net(&net4, IP_V4);
+    if(r==0) {
+        r = get_ipaddr(AF_INET, DFLT_NIC, ipaddr, mask);
+        if(r && net4.mode==IP_DHCP) {
+            set_dhcp(1);
+        }
+    }
+
+    r = get_net(&net6, IP_V6);
+    if(r==0) {
+        r = get_ipaddr(AF_INET6, DFLT_NIC, ipaddr, mask);
+        if(r && net6.mode==IP_DHCP) {
+            
+        }
+    }
+
+}
+
 static void net_init(void)
 {
     nic_restart();
     nic_set_mac();
 }
 
+#include <dirent.h>
+#include <signal.h>
+#include <sys/wait.h>
+static int get_pid(char *proc)
+{
+    DIR *dir;
+    int pid=-1;
+    struct dirent *entry;
+ 
+    dir = opendir("/proc");
+    if (!dir) {
+        perror("opendir");
+        return -1;
+    }
+ 
+    while ((entry = readdir(dir))) {
+        if (entry->d_type != DT_DIR || !isdigit(entry->d_name[0])) {
+            continue;
+        }
+ 
+        char path[500];
+        snprintf(path, sizeof(path), "/proc/%s/cmdline", entry->d_name);
+        FILE *f = fopen(path, "r");
+        if (f) {
+            char cmd[64];
+            if (fgets(cmd, sizeof(cmd), f) && strstr(cmd, proc)) {
+                pid = atoi(entry->d_name);
+                break;
+            }
+            fclose(f);
+        }
+    }
+ 
+    closedir(dir);
+    return pid;
+}
+int sys_kill(char *proc)
+{
+    int status;
+    int pid=get_pid(proc);
+    if(pid<0) {
+        return -1;
+    }
+    kill(pid, SIGKILL);
+    waitpid(pid, &status, 0);
+    return 0;
+}
+
 
 
 #include "ui.h"
@@ -1535,7 +1609,7 @@ int sys_init(void)
     init_hash_table();
     
     ui_init();
-    //net_init();
+    net_init();
     thread_start(THREAD_ID_POLLING, polling_thread, NULL);
 
     return 0;

+ 1 - 0
pro/src/sys.h

@@ -32,5 +32,6 @@ int sys_get_mac(char *mac, int maclen);
 int sys_get_chip_id(int *id);
 int sys_ip_check(char *ip);
 int sys_get_prod(GlobalDeviceInfo *info);
+int sys_kill(char *proc);
 
 #endif

+ 7 - 1
pro/ui/ui.c

@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include "menu.h"
+#include "sys.h"
 #include "thread.h"
 #include "cfg.h"
 
@@ -44,7 +45,12 @@ static void *ui_thread(void *arg)
 /////////////////////////////////////////////////////
 static void rm_qt(void)
 {
+#if 0
+    sys_kill("Qt_Test");
+    remove("/root/run/app/Qt_Test");
+#else
     system("killall Qt_Test; rm /root/run/app/Qt_Test");
+#endif
 }
 
 int ui_init(void)
@@ -52,7 +58,7 @@ int ui_init(void)
     ui_handle_t *h=&uiHandle;
 
 #ifdef USE_UI
-    //rm_qt();
+    rm_qt();
     thread_start(THREAD_ID_UI, ui_thread, h);
 #endif