Merge "[Bugfix][T106][task-view-127]Optimize GNSS-5HZ output and file configuration function"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
index 949c1f3..445f51f 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-wifi-demo/files/lynq-wifi-demo.cpp
@@ -12,16 +12,22 @@
 #include <time.h>
 #include <syslog.h>
 #include <pthread.h>
+#include <signal.h>
 
 #include <include/lynq-qser-autosuspend.h>
 #include <include/lynq-qser-wifi.h>
 
+static lynq_wifi_ap_index_e type;
+static int wifi_lock_num;
+
 void lynq_wifi_event_handle_demo(lynq_wifi_event_s *event, void *arg)
 {
     if(event->id == LYNQ_WIFI_EVENT_AP_STATION)
         printf("[lynq-wifi-demo]  %s:event-id = %d - %d\n", __func__, event->id, event->status);
-    else if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
+    else if(event->id == LYNQ_WIFI_EVENT_AP_STA_STATUS)
         printf("[lynq-wifi-demo]  %s:event-id = %d,%d,%s,%s\n", __func__, event->id, event->ap_sta_info.connected, event->ap_sta_info.mac,event->ap_sta_info.hostname);
+    if(event->id == LYNQ_WIFI_EVENT_STA_STATUS)
+        printf("[lynq-wifi-demo]  %s:event-id = %d - %d\n", __func__, event->id, event->status);
     else
         return;
 }
@@ -50,15 +56,27 @@
 	}
 }
 
+void signalHandler(int signum)
+{
+    qser_wifi_ap_stop(type); // Disable ap mode for 2.4G/5G
+    qser_wifi_disable();     // Turn off WiFi
+    int ret = qser_wakelock_unlock(wifi_lock_num);
+    if (ret != 0)
+    {
+        printf("wakelock unlock fail\n");
+        printf("ret=%d\n", ret);
+    }
+    ret = qser_wakelock_destroy(wifi_lock_num);
+    if (ret != 0)
+    {
+        printf("wakelock destroy fail\n");
+        printf("ret=%d\n", ret);
+    }
+    exit(signum);
+}
+
 int main(int argc, char *argv[])
 {
-    int num = qser_wakelock_create("wifi_lock", 10);
-    if(num < 0)
-    {
-        printf("wakelock create fail\n");
-        printf("num=%d\n", num);
-    }
-    lynq_wifi_ap_index_e type;
     if (strcmp(argv[0], "lynq-wifi-demo") == 0)
         type = LYNQ_WIFI_AP_INDEX_AP0; // 2.4G
     else
@@ -67,30 +85,40 @@
     {
         if (strcmp(argv[1], "0") == 0) //Turn off WiFi and uninstall
         {
-            qser_wifi_enable();      // enable wifi
+            int ret = qser_wifi_enable();      // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
             qser_wifi_ap_stop(type); // Disable ap mode for 2.4G/5G
             qser_wifi_disable();     // Turn off WiFi
-            int ret = qser_wakelock_unlock(num);
+            ret = qser_wakelock_unlock(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock unlock fail\n");
                 printf("ret=%d\n", ret);
             }
-            ret = qser_wakelock_destroy(num);
+            ret = qser_wakelock_destroy(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock destroy fail\n");
                 printf("ret=%d\n", ret);
             }
         }
-        else if (strcmp(argv[1], "1") == 0) //Load WiFi and turn on WiFi
+        else if (strcmp(argv[1], "1") == 0) //Set WiFi parameters
         {
             char pw[65] = {0};
             char mac_list[360] = {0};
             srand(time(NULL));
             sprintf(pw, "lynq123456");
             sprintf(mac_list, "AA:BB:CC:DD:EE:%d%d;AA:BB:CC:%d%d:EE:00;AA:BB:%d%d:DD:EE:00",rand()%10,rand()%10,rand()%10,rand()%10,rand()%10,rand()%10);
-            qser_wifi_enable(); // enable wifi
+            int ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
             if (type == LYNQ_WIFI_AP_INDEX_AP0)
                 qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0); // Set 2.4G, and this function must be called after the qser_wifi_enable function
             else
@@ -111,13 +139,8 @@
                 qser_wifi_ap_mode_set(type, LYNQ_WIFI_MODE_80211ANACAX_5G);
             }
             qser_wifi_ap_auth_set(type, LYNQ_WIFI_AUTH_WPA2_PSK, pw); // Set the authentication of 2.4G/5G to wpa2 and the password to lynq123456
-            qser_wifi_ap_start(type);                                 // Set the ap mode of 2.4G/5G
-            int ret = qser_wakelock_lock(num);
-            if(ret != 0)
-            {
-                printf("wakelock lock fail\n");
-                printf("ret=%d\n", ret);
-            }
+            qser_wifi_disable();     // Turn off WiFi
+            
         }
         else if (strcmp(argv[1], "2") == 0) //Callback query that only covers WiFi as an ap
         {
@@ -136,7 +159,9 @@
             lynq_wifi_pkt_stats_t pkt_stat = {0};
             lynq_wifi_bandwidth_type_e bandwidth;
             int ret = -1;
-            qser_wifi_enable();                      // enable wifi
+            ret = qser_wifi_enable();                      // enable wifi
+            if(ret != 0)
+                return -1;
             ret = qser_wifi_ap_ssid_get(type, ssid); // Gets the ssid of 2.4G/5G
             printf("[lynq-wifi-demo]  ssid=%s ret = %d\n", ssid, ret);
             ret = qser_wifi_ap_ssid_hide_get(type, &hidden); // Gets whether the ssid state is hidden
@@ -171,13 +196,30 @@
             printf("[lynq-wifi-demo]ap_pkt_get rx[%llu, %llu, %llu, %llu] tx[%llu, %llu, %llu, %llu] ret=%d\n",
                    pkt_stat.rx_packets, pkt_stat.rx_bytes, pkt_stat.rx_errors, pkt_stat.rx_dropped,
                    pkt_stat.tx_packets, pkt_stat.tx_bytes, pkt_stat.tx_errors, pkt_stat.tx_dropped, ret);
+            qser_wifi_disable();     // Turn off WiFi
         }
         else if (strcmp(argv[1], "3") == 0) //Enable the callback query only when WiFi is used as an ap
         {
             int ret = -1;
-            int args = 3;       // enable ap_sta callback
-            qser_wifi_enable(); // enable wifi
+            int args = 0;       // enable callback
+            ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
+            qser_wifi_ap_start(type); // Set the ap mode of 2.4G/5G
             qser_wifi_register_handle(lynq_wifi_event_handle_demo, NULL, (void *)&args);
+            ret = qser_wakelock_lock(wifi_lock_num);
+            if(ret != 0)
+            {
+                printf("wakelock lock fail\n");
+                printf("ret=%d\n", ret);
+            }
+            signal(SIGINT, signalHandler);
             while (1)
             {
                 char cmdstr[128] = {0};
@@ -206,11 +248,19 @@
         else if (strcmp(argv[1], "4") == 0) //Overlay WiFi callback as ap and scan callback as sta
         {
             int ret = -1;
-            int args = 0; //enable ap_set and ap_sta callback
+            int args = 0; //enable callback
             char ssid[33] = {0};
             char cmdstr[128] = {0};
             lynq_wifi_sta_param_t stat = {0};
-            qser_wifi_enable(); // enable wifi
+            ret = qser_wifi_enable(); // enable wifi
+            if(ret != 0)
+                return -1;
+            wifi_lock_num = qser_wakelock_create("wifi_lock", 10);
+            if(wifi_lock_num < 0)
+            {
+                printf("wakelock create fail\n");
+                printf("wifi_lock_num=%d\n", wifi_lock_num);
+            }
             if (type == LYNQ_WIFI_AP_INDEX_AP0)
                 qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0); // Set 2.4G, and this function must be called after the qser_wifi_enable function
             else
@@ -220,12 +270,13 @@
             qser_wifi_sta_start();
             qser_wifi_sta_start_scan(); // When this function is executed once, sta's scan is called once
             memset(cmdstr, 0, sizeof(cmdstr));
-            ret = qser_wakelock_lock(num);
+            ret = qser_wakelock_lock(wifi_lock_num);
             if(ret != 0)
             {
                 printf("wakelock lock fail\n");
                 printf("ret=%d\n", ret);
             }
+            signal(SIGINT, signalHandler);
             while (1)
             {
                 printf("[lynq-wifi-demo]Enter the ssid and password as shown in the following example:ssid auth paris pw ||sta_pkt_get ||sta_param_get || sta_scan ||sta_stop\n");
@@ -260,6 +311,19 @@
                     {
                         qser_wifi_sta_stop();
                         printf("[lynq-wifi-demo]end \n");
+                        qser_wifi_disable();     // Turn off WiFi
+                        int ret = qser_wakelock_unlock(wifi_lock_num);
+                        if(ret != 0)
+                        {
+                            printf("wakelock unlock fail\n");
+                            printf("ret=%d\n", ret);
+                        }
+                        ret = qser_wakelock_destroy(wifi_lock_num);
+                        if(ret != 0)
+                        {
+                            printf("wakelock destroy fail\n");
+                            printf("ret=%d\n", ret);
+                        }
                         break;
                     }
                     else
@@ -285,8 +349,8 @@
         printf("  [lynq-wifi-demo]4: sta mode to obtain access point information and set ssid and password and other information connection\n");
         printf("  [lynq-wifi-demo]3: Obtain sta data information in ap mode\n");
         printf("  [lynq-wifi-demo]2: View information such as ssid, password, and channel in ap mode\n");
-        printf("  [lynq-wifi-demo]1: initializes wifi and enables and sets ap mode\n");
-        printf("  [lynq-wifi-demo]0: indicates off.\n");
+        printf("  [lynq-wifi-demo]1: initializes wifi\n");
+        printf("  [lynq-wifi-demo]0: Turn off WiFi and turn off the lock\n");
         return 0;
     }
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
index 9f97c14..ff14d7a 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/include/lynq-qser-wifi.h
@@ -45,6 +45,7 @@
 	LYNQ_WIFI_EVENT_ENABLE_STATUS = 0,
 	LYNQ_WIFI_EVENT_DISABLE_STATUS,
 	LYNQ_WIFI_EVENT_AP_STATION,
+	LYNQ_WIFI_EVENT_AP_STA_STATUS,
 	LYNQ_WIFI_EVENT_STA_STATUS,
 	LYNQ_WIFI_EVENT_MAX,
 } lynq_wifi_event_type_e;
@@ -125,24 +126,6 @@
 	char bssid[18];
 }lynq_wifi_ap_status_t;
 
-typedef struct {
-	lynq_wifi_event_type_e id;
-	union {
-	    /* the LYNQ_WIFI_ENABLE_STATUS or LYNQ_WIFI_DISABLE_STATUS event */
-		lynq_wifi_status_e status;
-		struct {
-		    /* 
-		     * If connected is true, the station is connected wifi hotspot.
-		     * If connected is false, the station is disconnected wifi hotspot.
-		     */
-            int connected;
-            char mac[18]; //mac connected to WiFi device
-            char hostname[32]; //Name of the WiFi device
-		} ap_sta_info;
-		lynq_wifi_station_status_e sta_status;
-	};
-} lynq_wifi_event_s;
-
 typedef struct
 {
  	char ssid[33];
@@ -194,6 +177,7 @@
 
 typedef struct
 {
+	lynq_wifi_station_status_e sta_status;
 	lynq_wifi_sta_status_e status;
 	char ifname[32];
 	char ap_bssid[18]; //cur ap mac
@@ -250,6 +234,25 @@
     lynq_lanhost_t array[32];
 } lynq_lanhost_ts;
 
+typedef struct {
+	lynq_wifi_event_type_e id;
+	union {
+	    /* the LYNQ_WIFI_ENABLE_STATUS or LYNQ_WIFI_DISABLE_STATUS event */
+		lynq_wifi_status_e status;
+		struct {
+		    /* 
+		     * If connected is true, the station is connected wifi hotspot.
+		     * If connected is false, the station is disconnected wifi hotspot.
+		     */
+            int connected;
+            char mac[18]; //mac connected to WiFi device
+            char hostname[32]; //Name of the WiFi device
+		} ap_sta_info;
+		lynq_wifi_station_status_e sta_status;
+		lynq_wifi_sta_status_t sta_status_all;
+	};
+} lynq_wifi_event_s;
+
 typedef void (*lynq_wifi_event_handle)(lynq_wifi_event_s *event, void *arg);
 typedef void (*lynq_wifi_event_handle_sta)(lynq_wifi_sta_scan_list_t *event);
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
index 2b23394..c444199 100644
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-wifi/lynq-qser-wifi.cpp
@@ -7,6 +7,7 @@
 extern "C" {
 #endif
 
+#include <cfg_api.h>
 #include "sc_tel_types.h"
 #include "sc_wifi.h"
 #include "lynq-qser-wifi.h"
@@ -152,6 +153,43 @@
 }
 
 /********************************************************************
+* @brief: sc_to_lynq_sta_status, sc_wifi_sta_status_t to lynq_wifi_sta_status_t
+* @return :int, all
+* @todo: NA
+* @see: NA
+* @warning: NA
+*********************************************************************/
+static int sc_to_lynq_sta_status(sc_wifi_sta_status_t *stat, lynq_wifi_sta_status_t *status_stat)
+{
+    status_stat->status = (lynq_wifi_sta_status_e)stat->status;
+    status_stat->signal_level = stat->signal_level;
+    status_stat->has_addr = stat->has_addr;
+    status_stat->has_addr6 = stat->has_addr6;
+    status_stat->reason_code = (lynq_wifi_reason_code_e)stat->reason_code;
+    strncpy(status_stat->ifname, stat->ifname, sizeof(stat->ifname) - 1);
+    strncpy(status_stat->ap_bssid, stat->ap_bssid, sizeof(stat->ap_bssid) - 1);
+    if (status_stat->has_addr == 1)
+    {
+        strncpy(status_stat->addr.addr, stat->addr.addr, sizeof(status_stat->addr.addr) - 1);
+        strncpy(status_stat->addr.netmask, stat->addr.netmask, sizeof(status_stat->addr.netmask) - 1);
+        status_stat->addr.subnet_bits = stat->addr.subnet_bits;
+        strncpy(status_stat->addr.gateway, stat->addr.gateway, sizeof(status_stat->addr.gateway) - 1);
+        strncpy(status_stat->addr.dnsp, stat->addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
+        strncpy(status_stat->addr.dnss, stat->addr.dnss, sizeof(status_stat->addr.dnss) - 1);
+    }
+    if (status_stat->has_addr6 == 1)
+    {
+        strncpy(status_stat->addr6.addr, stat->addr6.addr, sizeof(status_stat->addr6.addr) - 1);
+        strncpy(status_stat->addr6.prefix, stat->addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
+        status_stat->addr6.prefix_bits = stat->addr6.prefix_bits;
+        strncpy(status_stat->addr6.gateway, stat->addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
+        strncpy(status_stat->addr6.dnsp, stat->addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
+        strncpy(status_stat->addr6.dnss, stat->addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
+    }
+    return 0;
+}
+
+/********************************************************************
 * @brief: lynq_user_status, wifi startup callback
 * @return : NA
 * @todo: NA
@@ -191,10 +229,7 @@
         {
             return;
         }
-        if (*(int *)global_arg != LYNQ_WIFI_EVENT_AP_STATION)
-        {
-            LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
-        }
+        LYINFLOG("%s:%d,%d,%s,%d\n", __func__, index, pre_status, p_msg->ifname, p_msg->status);
         event.id = LYNQ_WIFI_EVENT_AP_STATION;
         event.status = (lynq_wifi_status_e)pre_status;
         wifi_event_handle(&event, global_arg);
@@ -219,7 +254,7 @@
     int ret = sc_wifi_get_hostname_by_mac(p_msg->macaddr, hostname, sizeof(hostname));
     if (ret == 0)
     {
-        printf("[wifi_demo]sta ip not assigned, try again later!\n");
+        LYINFLOG("sta ip not assigned, try again later!\n");
     }
     if (wifi_event_handle != NULL && global_arg != NULL)
     {
@@ -227,11 +262,8 @@
         {
             return;
         }
-        if (*(int *)global_arg != LYNQ_WIFI_EVENT_STA_STATUS)
-        {
-            LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
-        }
-        event.id = LYNQ_WIFI_EVENT_STA_STATUS;
+        LYINFLOG("%s:%d,%d,%s,%s\n", __func__, index, p_msg->is_connected, p_msg->macaddr, hostname);
+        event.id = LYNQ_WIFI_EVENT_AP_STA_STATUS;
         event.ap_sta_info.connected = p_msg->is_connected;
         strncpy(event.ap_sta_info.mac, p_msg->macaddr,
                 sizeof(event.ap_sta_info.mac) <= sizeof(p_msg->macaddr) ? sizeof(event.ap_sta_info.mac) : sizeof(p_msg->macaddr));
@@ -282,8 +314,30 @@
 static void lynq_user_sta_status_ind(sc_wifi_sta_status_e pre_status, 
   sc_wifi_sta_status_t *p_msg)
 {	 
-	 LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
-	 print_sta_status(p_msg);
+    if (wifi_event_handle != NULL && global_arg != NULL)
+    {
+        lynq_wifi_event_s event;
+        if (*(int *)global_arg == LYNQ_WIFI_EVENT_DISABLE_STATUS)
+        {
+            return;
+        }
+        LYINFLOG("%s : user_sta_status_ind_cb pre:%d, cur:%d\n", __func__, pre_status, p_msg->status);
+        event.id = LYNQ_WIFI_EVENT_STA_STATUS;
+        if(p_msg->status == SC_WIFI_STA_STATUS_CONNECTED)
+            event.sta_status = LYNQ_WIFI_STATION_CONNECTED;
+        else if(p_msg->status == SC_WIFI_STA_STATUS_DISCONNECTED)
+            event.sta_status = LYNQ_WIFI_STATION_DISCONNECTED;
+        else
+            event.sta_status = LYNQ_WIFI_STATION_DISABLE;
+        sc_to_lynq_sta_status(p_msg, &event.sta_status_all);
+        event.sta_status_all.sta_status = event.sta_status;
+        wifi_event_handle(&event, global_arg);
+    }
+    else
+    {
+        print_sta_status(p_msg);
+    }
+	 
 }
 
 /********************************************************************
@@ -420,6 +474,13 @@
 *********************************************************************/
 int qser_wifi_enable(void)
 {
+    char wifiAvailable[8] = {0};
+    sc_cfg_get("wifiAvailable", wifiAvailable, sizeof(wifiAvailable));
+    if (!strcmp(wifiAvailable, "0"))
+    {
+        LYERRLOG("[%s ] wifiAvailable has been set to 0. If WiFi is used, set 1 to enable it\n", __func__);
+        return -1;
+    }
     int ret = -1;
     ret = sc_wifi_init();
     if (0 != ret)
@@ -1023,7 +1084,7 @@
         return ret;
     }
     lynq_arrays->array_len = 32;
-    ret = ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
+    ret = sc_wifi_lanhost_get_list(array, &lynq_arrays->array_len);
     if (0 != ret)
     {
         LYERRLOG("[%s ] ret = %d\n", __func__, ret);
@@ -1222,31 +1283,7 @@
         return ret;
     }
     print_sta_status(&stat);
-    status_stat->status = (lynq_wifi_sta_status_e)stat.status;
-    status_stat->signal_level = stat.signal_level;
-    status_stat->has_addr = stat.has_addr;
-    status_stat->has_addr6 = stat.has_addr6;
-    status_stat->reason_code = (lynq_wifi_reason_code_e)stat.reason_code;
-    strncpy(status_stat->ifname, stat.ifname, sizeof(stat.ifname) - 1);
-    strncpy(status_stat->ap_bssid, stat.ap_bssid, sizeof(stat.ap_bssid) - 1);
-    if (status_stat->has_addr == 1)
-    {
-        strncpy(status_stat->addr.addr, stat.addr.addr, sizeof(status_stat->addr.addr) - 1);
-        strncpy(status_stat->addr.netmask, stat.addr.netmask, sizeof(status_stat->addr.netmask) - 1);
-        status_stat->addr.subnet_bits = stat.addr.subnet_bits;
-        strncpy(status_stat->addr.gateway, stat.addr.gateway, sizeof(status_stat->addr.gateway) - 1);
-        strncpy(status_stat->addr.dnsp, stat.addr.dnsp, sizeof(status_stat->addr.dnsp) - 1);
-        strncpy(status_stat->addr.dnss, stat.addr.dnss, sizeof(status_stat->addr.dnss) - 1);
-    }
-    if (status_stat->has_addr6 == 1)
-    {
-        strncpy(status_stat->addr6.addr, stat.addr6.addr, sizeof(status_stat->addr6.addr) - 1);
-        strncpy(status_stat->addr6.prefix, stat.addr6.prefix, sizeof(status_stat->addr6.prefix) - 1);
-        status_stat->addr6.prefix_bits = stat.addr6.prefix_bits;
-        strncpy(status_stat->addr6.gateway, stat.addr6.gateway, sizeof(status_stat->addr6.gateway) - 1);
-        strncpy(status_stat->addr6.dnsp, stat.addr6.dnsp, sizeof(status_stat->addr6.dnsp) - 1);
-        strncpy(status_stat->addr6.dnss, stat.addr6.dnss, sizeof(status_stat->addr6.dnss) - 1);
-    }
+    sc_to_lynq_sta_status(&stat, status_stat);
     LYINFLOG("[%s ] ret = %d \n", __func__, ret);
     return 0;
 }