Pārlūkot izejas kodu

1、完善wifi相关的配置及功能

liyuezong 1 gadu atpakaļ
vecāks
revīzija
60bef3e7dd

+ 1 - 1
pro/src/Cellular.c

@@ -636,7 +636,7 @@ static int send_cmd(cell_handle_t *h, int cmd, char *para, char *rcv, int rcvlen
         }
     }
     //AT不通重启串口
-    if (cmd != AT_CMD_QIDEACT )
+    if (cmd != AT_CMD_QIDEACT && cmd != AT_CMD_CFUN )
     {
         port_deinit(h);
         port_init(h);

+ 6 - 8
pro/src/appweb_handle.c

@@ -3900,11 +3900,10 @@ static void communicationManagement(void *conn)
         ack_str = ctrl_sts_ack_to_json(); 
     }
 
-#ifdef USE_WIFI
     else if(strcmp(reqInfo.type,"listWIFIPZQuery")==0) // WIFI处理
     {
         ap_stat_t stat;
-        WIFIManager *wm=&_globalWIFIManager;
+        WIFIInfo_t *wm=& __globalDeviceManage._globalDevInfo.wifi;
 
         wifi_sta_stat(&stat);
         wm->Link_status = stat.link;
@@ -3913,16 +3912,15 @@ static void communicationManagement(void *conn)
     }
      else if (strcmp(reqInfo.type, "WIFIPZSave") == 0) // WIFI处理
     {
-        _globalWIFIManager.mode = reqInfo._4g_wifi_info.WIFI_mode;
-         strcpy(_globalWIFIManager.WIFI_name, reqInfo._4g_wifi_info.WIFI_name);
-         strcpy(_globalWIFIManager.WIFI_code, reqInfo._4g_wifi_info.WIFI_code);
+        WIFIInfo_t *wm=& __globalDeviceManage._globalDevInfo.wifi;
+        wm->mode = reqInfo._4g_wifi_info.WIFI_mode;
+         strcpy(wm->WIFI_name, reqInfo._4g_wifi_info.WIFI_name);
+         strcpy(wm->WIFI_code, reqInfo._4g_wifi_info.WIFI_code);
 
-         wifi_set(&_globalWIFIManager);
-         __globalDeviceManage._globalDevInfo.wifi = _globalWIFIManager;
+         wifi_set(wm);
          paras_save();
          ack_str = ctrl_sts_ack_to_json(); 
     }
-#endif
 
     cJSON_Delete(cjson);
     http_reply(conn, 200, ack_str);

+ 9 - 12
pro/src/common.c

@@ -30,7 +30,6 @@ char _GlobalUserToken[64];
 MenuAuthority _GlobalMenuAuthority;
 NTPManager _globalNTPManager;
 SNMPManager _globalSNMPManager;
-WIFIManager _globalWIFIManager;
 
 
 void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo)
@@ -810,16 +809,14 @@ void SetMenuAuthority(int RoleID)
         _GlobalMenuAuthority.WkszEnabled = true;
         _GlobalMenuAuthority.RsszEnabled = true;
         if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
-
             _GlobalMenuAuthority.CellularEnabled = true;
         else
             _GlobalMenuAuthority.CellularEnabled = false;
 
-#ifdef USE_WIFI
-        _GlobalMenuAuthority.WifiEnabled = true;
-#else
-        _GlobalMenuAuthority.WifiEnabled = false;
-#endif
+        if (__globalDeviceManage._globalDevInfo.wifi.WIFI_enable)
+            _GlobalMenuAuthority.WifiEnabled = true;
+        else
+            _GlobalMenuAuthority.WifiEnabled = false;
 
         // 7、服务管理菜单
         _GlobalMenuAuthority.SmtpszEnabled = true;
@@ -886,11 +883,11 @@ void SetMenuAuthority(int RoleID)
         else
             _GlobalMenuAuthority.CellularEnabled = false;
 
-#ifdef USE_WIFI
-        _GlobalMenuAuthority.WifiEnabled = true;
-#else
-        _GlobalMenuAuthority.WifiEnabled = false;
-#endif
+        if (__globalDeviceManage._globalDevInfo.wifi.WIFI_enable)
+            _GlobalMenuAuthority.WifiEnabled = true;
+        else
+            _GlobalMenuAuthority.WifiEnabled = false;
+
         // 7、服务管理菜单
         _GlobalMenuAuthority.SmtpszEnabled = false;
         _GlobalMenuAuthority.SnmpszEnabled = false;

+ 12 - 12
pro/src/common.h

@@ -413,6 +413,17 @@ typedef struct
 
 } CellInfo_t;
 
+// WIFI信息
+typedef struct
+{
+    bool WIFI_enable; // WIFI模块启用状态
+    int mode;         // WIFI模块启用状态
+    bool Link_status; // wifi网络连接状态
+    char WIFI_ip[64]; // wifi ip address
+    char WIFI_name[64];// WIFI网络SSID名称
+    char WIFI_code[64];// WIFI密码
+} WIFIInfo_t;
+
 typedef struct {
     char        name[256];
     char        site[256];
@@ -429,15 +440,6 @@ typedef struct
     int          brdMax;
 }PowerTotal_t; 
 
-// WIFI信息
-typedef struct
-{
-    int mode;         // WIFI模块启用状态
-    bool Link_status; // wifi网络连接状态
-    char WIFI_ip[64]; // wifi ip address
-    char WIFI_name[64];// WIFI网络SSID名称
-    char WIFI_code[64];// WIFI密码
-} WIFIManager;
 
 typedef struct
 {
@@ -451,7 +453,7 @@ typedef struct
     MiscInfo_t      misc;
 
     CellInfo_t      cell;
-    WIFIManager     wifi;
+    WIFIInfo_t     wifi;
 }GlobalDeviceInfo;
 ///////////////////////////////////////////////////////////////////////////////////
 //自定义共享内存类
@@ -1303,8 +1305,6 @@ extern MenuAuthority _GlobalMenuAuthority;////角色菜单权限
 extern NTPManager _globalNTPManager;
 extern SNMPManager _globalSNMPManager;
 
-extern WIFIManager _globalWIFIManager;
-
 
 void initLogger(void);
 

+ 7 - 3
pro/src/dflt.c

@@ -120,9 +120,13 @@ GlobalDeviceInfo DFLT_PARAS={
             .password = "",
         },
 
-        .wifi = {
-            .mode = 0,
-        },
+    .wifi = {
+        .WIFI_enable = false,
+        .mode = 0,
+        .WIFI_ip = "",
+        .WIFI_name = "",
+        .WIFI_code= "",
+    },
 };
 
 

+ 3 - 3
pro/src/json_handle.c

@@ -615,7 +615,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(children5_data3_filed,"component","txgl/fourgsz/index");  
     cJSON* children5_meta3_data1_filed = cJSON_CreateObject(); 
     cJSON_AddStringToObject(children5_meta3_data1_filed,"title",language_4G_install[dm->_globalDevInfo.product.language]);   
-    cJSON_AddStringToObject(children5_meta3_data1_filed,"icon","build");   
+    cJSON_AddStringToObject(children5_meta3_data1_filed,"icon","international");   
     cJSON_AddBoolToObject(children5_meta3_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children5_meta3_data1_filed,"link","");    
     cJSON_AddItemToObject(children5_data3_filed, "meta", children5_meta3_data1_filed);
@@ -627,7 +627,7 @@ char* user_routers_info_to_json(void)
     cJSON_AddStringToObject(children5_data4_filed,"component","txgl/wifisz/index");  
     cJSON* children5_meta4_data1_filed = cJSON_CreateObject(); 
     cJSON_AddStringToObject(children5_meta4_data1_filed,"title",language_WIFI_install[dm->_globalDevInfo.product.language]);   
-    cJSON_AddStringToObject(children5_meta4_data1_filed,"icon","build");   
+    cJSON_AddStringToObject(children5_meta4_data1_filed,"icon","size");   
     cJSON_AddBoolToObject(children5_meta4_data1_filed,"noCache",false); 
     cJSON_AddStringToObject(children5_meta4_data1_filed,"link","");    
     cJSON_AddItemToObject(children5_data4_filed, "meta", children5_meta4_data1_filed);
@@ -4709,7 +4709,7 @@ char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType)
 /// @brief 返回RS485信息
 /// @param _networkInfo_t 
 /// @return 
-char* communication_WIFI_ack_to_json(WIFIManager* _WIFIManagertemp,int nWSType)
+char* communication_WIFI_ack_to_json(WIFIInfo_t* _WIFIManagertemp,int nWSType)
 {
     char temp[32] = {0};
     char* str = NULL;

+ 1 - 1
pro/src/json_handle.h

@@ -634,7 +634,7 @@ char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t);
 
 char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType);
 
-char* communication_WIFI_ack_to_json(WIFIManager* _WIFIManagertemp,int nWSType);
+char* communication_WIFI_ack_to_json(WIFIInfo_t* _WIFIManagertemp,int nWSType);
 
 char* service_ds_ack_to_json(char* chn_name,char* chn_id,_PowerDSManage_t* __powerDSManage_t);
 char* service_ds_all_ack_to_json(char* pDate,char* Name,char* nchID,GlobalPowerManger* __powerDSManage_t);

+ 23 - 2
pro/src/paras.c

@@ -1110,7 +1110,7 @@ static int proc_cellular(dictionary *dic, int op, CellInfo_t *cell)
 
     return r;
 }
-static int proc_wifi(dictionary *dic, int op, WIFIManager *pWIFIManager)
+static int proc_wifi(dictionary *dic, int op, WIFIInfo_t *pWIFIManager)
 {
     int r=0;
     char temp[100];
@@ -1135,6 +1135,26 @@ static int proc_wifi(dictionary *dic, int op, WIFIManager *pWIFIManager)
 
     }
 
+    token = "wifi:enable";
+    if(op==PARAS_READ) {
+        r = iniparser_getint(dic, token, -1);
+        if(r==-1) {
+            LOGE("___ iniparser_getint %s failed\n", token);
+            return -1;
+        } else {
+            pWIFIManager->WIFI_enable = r;
+        }
+    }
+    else {
+        /*
+        sprintf(temp, "%d", pWIFIManager->WIFI_enable);
+        r = iniparser_set(dic, token, temp);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+        }*/
+    }
+
     token = "wifi:mode";
     if(op==PARAS_READ) {
         r = iniparser_getint(dic, token, -1);
@@ -3655,7 +3675,7 @@ static int ini_reset(paras_handle_t *h)
     fprintf(fp, "\n");
 
     fprintf(fp, "[cellular]\n");
-     fprintf(fp, "enable        = \"%d\"\n", info->cell.Cellular_enable);
+    fprintf(fp, "enable        = \"%d\"\n", info->cell.Cellular_enable);
     fprintf(fp, "mode        = \"%d\"\n", info->cell.mode);
     fprintf(fp, "apn         = \"%s\"\n", info->cell.apn);
     fprintf(fp, "username    = \"%s\"\n", info->cell.username);
@@ -3663,6 +3683,7 @@ static int ini_reset(paras_handle_t *h)
     fprintf(fp, "\n");
     
     fprintf(fp, "[wifi]\n");
+    fprintf(fp, "enable        = \"%d\"\n", info->wifi.WIFI_enable);
     fprintf(fp, "mode        = \"%d\"\n", info->wifi.mode);
     fprintf(fp, "ip          = \"%s\"\n", info->wifi.WIFI_ip);
     fprintf(fp, "ssid        = \"%s\"\n", info->wifi.WIFI_name);

+ 13 - 11
pro/src/websocket_handle.c

@@ -264,20 +264,22 @@ static int ws_WIFI_update(ws_handle_t *h)
 {
     char *json;
 
-#ifdef USE_WIFI
-    ap_stat_t stat;
-    WIFIManager *wm=&_globalWIFIManager;
+    if (__globalDeviceManage._globalDevInfo.wifi.WIFI_enable)
+    {
+        ap_stat_t stat;
+        WIFIInfo_t *wm = &__globalDeviceManage._globalDevInfo.wifi;
 
-    wifi_sta_stat(&stat);
-    wm->Link_status = stat.link;
-    strcpy(wm->WIFI_ip, stat.ipaddr);
+        wifi_sta_stat(&stat);
+        wm->Link_status = stat.link;
+        strcpy(wm->WIFI_ip, stat.ipaddr);
 
-    json = communication_WIFI_ack_to_json(wm,1);
-    if(json) {
-        ws_send_data(h, json, strlen(json));
-        cJSON_free(json);
+        json = communication_WIFI_ack_to_json(wm, 1);
+        if (json)
+        {
+            ws_send_data(h, json, strlen(json));
+            cJSON_free(json);
+        }
     }
-#endif
 
     return 0;
 }

+ 5 - 26
pro/src/wifi.c

@@ -17,8 +17,6 @@
 #include "paras.h"
 #include "cfg.h"
 
-
-#ifdef USE_WIFI
 #include <netlink/msg.h>
 #include <netlink/attr.h>
 #include <netlink/netlink.h>
@@ -27,7 +25,7 @@
 #include <netlink/genl/ctrl.h>
 #include <netlink/route/link.h>
 #include <netlink/route/addr.h>
-#endif
+
 
 
 #define ONCE_CNT            20
@@ -50,11 +48,10 @@ typedef struct {
     int             ifindex;
     char            *ifname;
     int             nl_id;     //nl80211_id
-#ifdef USE_WIFI
+
     struct nl_cb    *cb;
     struct nl_msg   *msg;
     struct nl_sock  *sock;
-#endif
 }nl_handle_t;
 typedef struct {
     int             flag;
@@ -62,7 +59,6 @@ typedef struct {
 static wifi_handle_t wfHandle={0};
 
 
-#ifdef USE_WIFI
 const char *auth_str[AUTH_MAX]={
     "NONE",
     "ERR",
@@ -712,21 +708,18 @@ static int nl_link(int on)
 
     return r;
 }
-#endif
+
 
 ////////////////////////////////////////////////////////////////
 int wifi_init(void)
 {
     int r=-1;
-    WIFIManager *wm=&_globalWIFIManager;
+    WIFIInfo_t *wm=&__globalDeviceManage._globalDevInfo.wifi;
     wifi_handle_t *h=&wfHandle;
 
-    *wm = __globalDeviceManage._globalDevInfo.wifi;
-#ifdef USE_WIFI
     system("insmod /lib/modules/5.4.61/cfg80211.ko");
     system("insmod /lib/modules/5.4.61/lib80211.ko");
     r = wifi_set(wm);
-#endif
     
     return r;
 }
@@ -738,26 +731,23 @@ int wifi_scan(ap_list_t *list)
     result_t res;
     wifi_handle_t *h=&wfHandle;
 
-#ifdef USE_WIFI
     r = nl_scan(&res);
     if(r==0) {
         if(list) {
             *list = res.list;
         }
     }
-#endif
 
     return r;
 }
 
 
-int wifi_set(WIFIManager *wm)
+int wifi_set(WIFIInfo_t *wm)
 {
     int r=-1;
     ap_info_t info;
     wifi_handle_t *h=&wfHandle;
 
-#ifdef USE_WIFI
     r = nl_link(wm->mode);
     if(wm->mode) {
         memset(&info, 0, sizeof(info));
@@ -772,7 +762,6 @@ int wifi_set(WIFIManager *wm)
     else {
         sta_start(&info, 0);
     } 
-#endif
 
     return r;
 }
@@ -784,10 +773,6 @@ int wifi_sta_info(ap_info_t *info)
     int r=-1;
     wifi_handle_t *h=&wfHandle;
     
-#ifdef USE_WIFI
-    
-#endif
-    
     return 0;
 }
 
@@ -801,14 +786,12 @@ int wifi_sta_stat(ap_stat_t *stat)
         return -1;
     }
 
-#ifdef USE_WIFI
     nl_get_signal(stat);
     r = nl_get_ip(stat);
     if(r==0) {
         stat->link = 1; //不知道何原因导致获取信号强度的回调函数触发不了,暂时绕过
     }
     //printf("______ link: %d, signal: %d, ip: %s\n", stat->link, stat->signal, stat->ipaddr);   
-#endif
     
     return r;
 }
@@ -820,10 +803,6 @@ int wifi_ap_info(ap_info_t *info)
     int r=-1;
     wifi_handle_t *h=&wfHandle;
     
-#ifdef USE_WIFI
-
-#endif
-    
     return 0;
 }
 

+ 1 - 1
pro/src/wifi.h

@@ -57,7 +57,7 @@ int wifi_init(void);
 int wifi_scan(ap_list_t *list);
 int wifi_list_free(ap_list_t *list);
 
-int wifi_set(WIFIManager *wm);
+int wifi_set(WIFIInfo_t *wm);
 int wifi_sta_stat(ap_stat_t *stat);
 int wifi_sta_info(ap_info_t *info);
 int wifi_ap_info(ap_info_t *info);