Просмотр исходного кода

修改udhcpc在eth0口启动参数,防止引起看门狗复位

guohui 1 год назад
Родитель
Сommit
16ce66d4b0
3 измененных файлов с 30 добавлено и 25 удалено
  1. 7 7
      pro/src/switch_ctrl.c
  2. 16 11
      pro/src/sys.c
  3. 7 7
      pro/src/wifi.c

+ 7 - 7
pro/src/switch_ctrl.c

@@ -155,7 +155,7 @@ int g_switch_get_ac_single_s_all_cur_info(void* manger,int saddr,int nNumb,Power
         }
         else {
             val = (data_temp[11 + Index] << 16) | data_temp[10 + Index];
-            _power[i].factor = val / 1000.0;
+            _power[i].factor = val / 1000.0f;
             if(_power[i].factor>0.0f && _power[i].factor<0.1f) {
                 _power[i].power = 0.0f;
                 _power[i].current = 0.0f;
@@ -170,10 +170,10 @@ int g_switch_get_ac_single_s_all_cur_info(void* manger,int saddr,int nNumb,Power
         }
 
         val = (data_temp[7 + Index] << 16) | data_temp[6 + Index];
-        _power[i].freq = val / 1000.0;
+        _power[i].freq = val / 1000.0f;
         
         val = (data_temp[9 + Index] << 16) | data_temp[8 + Index];
-        _power[i].consumption = val / 1000.0;
+        _power[i].consumption = val / 1000.0f;
     }
 
     offset = _SWITCH_AC_SINGLE_S_STS_INFO;
@@ -1822,10 +1822,10 @@ int g_switch_get_t_ac_all_out_info(void* manger,int saddr,int nNumb,PowerInfo* _
             }
             else {
                 val = (data_temp[3 + Index] << 16) | data_temp[2 + Index];
-                _power[i].current = val / 1000.0;
+                _power[i].current = val / 1000.0f;
 
                 val = (data_temp[5 + Index] << 16) | data_temp[4 + Index];
-                _power[i].power = val / 1000.0;
+                _power[i].power = val / 1000.0f;
 
                 // 无功
                 //val = (data_temp[7+Index] << 16) + data_temp[6+Index];
@@ -1835,10 +1835,10 @@ int g_switch_get_t_ac_all_out_info(void* manger,int saddr,int nNumb,PowerInfo* _
         }
 
         val = (data_temp[11 + Index] << 16) | data_temp[10+ Index];
-        _power[i].freq = val / 1000.0;
+        _power[i].freq = val / 1000.0f;
         
         val = (data_temp[13 + Index] << 16) | data_temp[12 + Index];
-        _power[i].consumption = val / 1000.0;
+        _power[i].consumption = val / 1000.0f;
     }
     //获取通道开关状态及零线状态 
     //_SWITCH_T_AC_OUT_ENABLE +18

+ 16 - 11
pro/src/sys.c

@@ -269,7 +269,7 @@ static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
                 if(addr) {
                     char *p = (char*)inet_ntop(family, &sa->sin_addr, addr, INET6_ADDRSTRLEN);
                     if(p && strcmp(p, "127.0.0.1") && strcmp(p, "172.17.0.1")) {
-                        printf("___addr4: %s\n", addr);
+                        //printf("___addr4: %s\n", addr);
                         r = 0;
                     }
                 }
@@ -289,7 +289,7 @@ static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
                 if(addr) {
                     char *p = (char*)inet_ntop(family, &sa->sin6_addr, addr, INET6_ADDRSTRLEN);
                     if(p && strcmp(p, "::1")) {
-                        printf("___addr6: %s\n", addr);
+                        //printf("___addr6: %s\n", addr);
                         r = 0;
                     }
                 }
@@ -443,13 +443,18 @@ finish:
 }
 static int set_dhcp(int on)
 {
+    int r;
+    char tmp[200],path[100];
+
+    sprintf(path, "/var/run/udhcpc_%s.pid", DFLT_NIC);
+    sprintf(tmp, "kill $(cat %s)", path);
+    r = system(tmp);
+
     if(on) {
-        system("killall udhcpc && udhcpc –i eth0 –s /usr/share/udhcpc/default.script &");
+        sprintf(tmp, "udhcpc -R -b -t 1 -A 1 -i %s -p %s –s /usr/share/udhcpc/default.script", DFLT_NIC, path);
+        r = system(tmp);
     }
-    else {
-        system("killall udhcpc");
-    }
-    return 0;
+    return r;
 }
 static int is_number(char *str)
 {
@@ -1561,13 +1566,13 @@ int sys_get_ip_ver(char *addr)
 static int net_check(void)
 {
     int r,pid;
-    char tmp[200];
+    char tmp[200],path[100];
     char ipaddr[64],mask[64];
     NetworkInfo_t net4,net6;
     static uint32_t dhcp_cnt=0;
 
     if(dhcp_cnt%10==0) {
-        printf("__ dhcp check\n");
+        //printf("__ dhcp check\n");
         r = get_net(&net4, IP_V4);
         if(r==0) {
             r = get_ipaddr(AF_INET, DFLT_NIC, ipaddr, mask);
@@ -1580,7 +1585,7 @@ static int net_check(void)
                         kill(pid, SIGUSR2);
                     }
 #else
-                    system("killall udhcpc; udhcpc");
+                    set_dhcp(1);
 #endif
                 }
                 else {
@@ -1596,7 +1601,7 @@ static int net_check(void)
             if(r) {
                 if(net6.mode==IP_DHCP) {
                     pid = get_pid("udhcpc6");
-                    printf("___udhcpc6 pid: %d\n", pid);
+                    //printf("___udhcpc6 pid: %d\n", pid);
                     if(pid>=0) {
                         kill(pid, SIGUSR2);
                     }

+ 7 - 7
pro/src/wifi.c

@@ -561,10 +561,8 @@ static int nl_get_signal(ap_stat_t *stat)
     nl_cb_set(h->cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
     nl_cb_set(h->cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
     r = nl_cb_set(h->cb, NL_CB_VALID, NL_CB_CUSTOM, callback_stat, stat);
-    printf("_______________stat 111, %d\n", r);
 
-    r = genlmsg_put(h->msg, NL_AUTO_PORT, NL_AUTO_SEQ, h->nl_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0);  // Setup which command to run.
-    printf("_______________stat 222, %d\n", r);
+    genlmsg_put(h->msg, NL_AUTO_PORT, NL_AUTO_SEQ, h->nl_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0);  // Setup which command to run.
 
     nla_put_u32(h->msg, NL80211_ATTR_IFINDEX, h->ifindex);  // Add message attribute, which interface to use.
     r = nl_send_auto(h->sock, h->msg);
@@ -687,12 +685,12 @@ static int nl_disconn(void)
     
     return r;
 }
-static int nl_set_link(int on)
+static int nl_link(int on)
 {
     int r,fd;
     struct ifreq ifr;
 
-    fd = socket(AF_INET, SOCK_DGRAM, 0); 
+    fd = socket(AF_INET, SOCK_DGRAM, 0);
     if (fd>=0) { 
         strcpy(ifr.ifr_name, WLAN_IFNAME); 
         r = ioctl(fd, SIOCGIFFLAGS, &ifr);
@@ -755,12 +753,14 @@ int wifi_set(WIFIManager *wm)
     wifi_handle_t *h=&wfHandle;
 
 #ifdef USE_WIFI
-    r = nl_set_link(wm->mode);
+    r = nl_link(wm->mode);
     if(wm->mode) {
         memset(&info, 0, sizeof(info));
 
         strcpy(info.ssid, wm->WIFI_name);
         strcpy(info.password, wm->WIFI_code);
+
+        sta_start(&info, 0);
         r = sta_start(&info, 1);
     }  
     else {
@@ -801,7 +801,7 @@ int wifi_sta_stat(ap_stat_t *stat)
     if(r==0) {
         stat->link = 1; //不知道何原因导致获取信号强度的回调函数触发不了,暂时绕过
     }
-    //printf("______ link: %d, signal: %d, ip: %s\n", stat->link, stat->signal, stat->ipaddr);   
+    printf("______ link: %d, signal: %d, ip: %s\n", stat->link, stat->signal, stat->ipaddr);   
 #endif
     
     return r;