[Feature][T8TSK-86][Factory-test]The 800 SZZT branch synchronizes the factory test section

Change-Id: I77e3f255188613a422ba88d24f4b4ceb50ffef02
diff --git a/src/lynq/framework/lynq-ril-service/src/factory/lynq_factory.cpp b/src/lynq/framework/lynq-ril-service/src/factory/lynq_factory.cpp
index b1ed3f9..ca8effd 100755
--- a/src/lynq/framework/lynq-ril-service/src/factory/lynq_factory.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/factory/lynq_factory.cpp
@@ -62,6 +62,7 @@
 #include <string.h>
 #include<pthread.h>
 #include <cutils/properties.h>
+#include "lynq_at.h"
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -72,7 +73,10 @@
 int enable_nema = 0;
 int sustain = 1;
 char rgmii[32] = {0};
-//char sgmii[32] = {0};
+char sgmii[32] = {0};
+int gps_set = 2;
+int g_set_output = 0;
+int ttyGS0_fd;
 pthread_t lynq_gps_tid;
 // static pthread_mutex_t s_gps_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
 // static pthread_cond_t s_gps_change_cond = PTHREAD_COND_INITIALIZER;
@@ -102,46 +106,44 @@
     return;
 }
 
-static void lynq_get_sim_state(RIL_SIM_COUNT id){
-    char *argv[MAX_ARGS];
-    if(utils::is_support_dsds()) {
-        id = (RIL_SIM_COUNT)get_default_sim_all_except_data();
-    } else if(utils::is_suppport_dsss()) {
-        id = (RIL_SIM_COUNT)Phone_utils::get_enable_sim_for_dsss();
-    }
-    RequestInfo *pRI  = creatRILInfoAndInit(RIL_REQUEST_GET_SIM_STATUS, UDP, (RIL_SOCKET_ID)(id));
-    getIccCardStatus(RIL_REQUEST_GET_SIM_STATUS,argv,(RIL_SOCKET_ID)id,pRI);
-}
+
 void *thread_test(void *arg){
-    lynq_factory_response_ttyGS3("GPS OPNE\n");
-    #if 0
+    /*open vcom port*/
+    int ttyGS3_fd = open("/dev/ttyGS0",O_RDWR);
+    /*open vcom port*/
+    char gnss_buf[128] = {0};
+    lynq_factory_response_ttyGS3("+GPS OPEN:OK\n");
+    sprintf(gnss_buf, "%s%d%s", "echo \"GNSS_MODE=", gps_set, "\">>/etc/gnss/mnl.prop");
+    system(gnss_buf);
+    sleep(1);
     FILE *fp;
     char test[100] = {0};
-    sprintf(test, "mnld_test start & %s", "2>&1");
+    sprintf(test, "lynq-gnss-test %s", "2>&1");
     char lynq_factory_buf[1024] = {0};
     fp=popen(test, "r");
     if(NULL == fp){
-        printf("popen errorn\n");
+        lynq_factory_response_ttyGS3("popen errorn\n");
         return 0;
     }
-    // pthread_mutex_lock(&s_gps_state_change_mutex);
-    // pthread_cond_wait(&s_gps_change_cond, &s_gps_state_change_mutex);
-    // pthread_mutex_unlock(&s_gps_state_change_mutex);
     while (sustain)
-    {   
+    {
         if(fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp)){
             if(enable_nema == 1){
-                lynq_factory_response_ttyGS3(lynq_factory_buf);
+                if(g_set_output == 0)
+                {
+                    lynq_factory_response_ttyGS3(lynq_factory_buf);
+                }
+                /*output nema into vcom port*/
+                if(g_set_output == 1)
+                {
+                    write(ttyGS3_fd,lynq_factory_buf,strlen(lynq_factory_buf));
+                }
+                /*output nema into vcom port*/
             }
         }
-        else{
-            break;
-        }
     }
+    close(ttyGS3_fd);
     pclose(fp);
-    #endif
-    system("echo \"debug.dbg2file=1\">/etc/gnss/mnl.prop");
-    system("mnld_test start &");
     return 0;
 }
 
@@ -172,105 +174,112 @@
 }
 
 void *thread_test_RGMII(void *arg){
+    char cmd[128] = {0};
     FILE *fp;
-    char ipv4[128] = {0};
-    fp= popen("ifconfig 'eth2' | grep \"inet addr\" | cut -f 2 -d \":\" | cut -f 1 -d \" \" 2>&1", "r");
+    sprintf(cmd, "%s %s %s %s", "ping -I eth2", rgmii, "-c4", "2>&1");
+    fp=popen(cmd, "r");
     if(NULL == fp){
         lynq_factory_response_ttyGS3("popen errorn\n");
-        return 0;
+        return NULL;
     }
-    fgets(ipv4,sizeof(ipv4),fp);
-    if(strstr(ipv4, "error"))
+    char lynq_factory_buf[1024] = {0};
+    while (NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp))
     {
-        lynq_factory_response_ttyGS3("RGMII don't insert\n");
-        return 0;
-    }
-    else
-    {
-        parse_ipv4(ipv4);
-        char cmd[128] = {0};
-        sprintf(cmd, "%s %s %s %s", "ping -I eth2", ipv4, "-c4", "2>&1");
-        fp=popen(cmd, "r");
-        if(NULL == fp){
-            lynq_factory_response_ttyGS3("popen errorn\n");
-            return 0;
-        }
-        char lynq_factory_buf[1024] = {0};
-        while (NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp))
-        {   
-            lynq_factory_response_ttyGS3(lynq_factory_buf);
-        }
-        pclose(fp);
-        return 0;
-    }
-}
-
-static void lynq_test_RGMII(void){
-    pthread_t thid;
-    if(pthread_create(&thid, NULL, thread_test_RGMII, NULL) != 0) {
-        return;
-    }
-    pthread_join(thid, NULL);
-    return;
-}
-
-/**
- * @brief factory test for sgmii
- * 
- */
-void *thread_test_SGMII(void *arg){
-    FILE *fp;
-    char ipv4[128] = {0};
-    fp= popen("ifconfig 'eth1' | grep \"inet addr\" | cut -f 2 -d \":\" | cut -f 1 -d \" \" 2>&1", "r");
-    if(NULL == fp){
-        lynq_factory_response_ttyGS3("popen errorn\n");
-        return 0;
-    }
-    fgets(ipv4,sizeof(ipv4),fp);
-    if(strstr(ipv4, "error"))
-    {
-        lynq_factory_response_ttyGS3("SGMII don't insert\n");
-        return 0;
-    }
-    else
-    {
-        parse_ipv4(ipv4);
-        char cmd[128] = {0};
-        sprintf(cmd, "%s %s %s %s", "ping -I eth1", ipv4, "-c4", "2>&1");
-        fp=popen(cmd, "r");
-        if(NULL == fp){
-            lynq_factory_response_ttyGS3("popen errorn\n");
-            return 0;
-        }
-        char lynq_factory_buf[1024] = {0};
-        while (NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp))
+        if(strstr(lynq_factory_buf, "Usage"))
         {
-            lynq_factory_response_ttyGS3(lynq_factory_buf);
+            lynq_factory_response_ttyGS3("RGMII cannot recognize IP addresses\n");
+            lynq_factory_response_ttyGS3("ERROR\n");
+            pclose(fp);
+            return NULL;
         }
-        pclose(fp);
-        return 0;
+        lynq_factory_response_ttyGS3(lynq_factory_buf);
     }
+    lynq_factory_response_ttyGS3("OK\n");
+    pclose(fp);
+    return NULL;
+}
+
+static void lynq_test_RGMII(char *argv){
+    if(argv == NULL)
+    {
+        lynq_factory_response_ttyGS3("\nERROR\n");
+        return;
+    }
+    strcpy(rgmii, argv);
+    pthread_t thid;
+    pthread_attr_t a;
+    pthread_attr_init(&a);
+    pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
+    if(pthread_create(&thid, &a, thread_test_RGMII, NULL) != 0) {
+        return;
+    }
+    //pthread_join(thid, NULL);
+    return;
 }
 
 /**
  * @brief factory test for sgmii
  * 
  */
-static void lynq_test_SGMII(void){
-    pthread_t thid;
-    if(pthread_create(&thid, NULL, thread_test_SGMII, NULL) != 0) {
+void *thread_test_SGMII_wtf(void *arg){
+    FILE *fp;
+    char cmd[128] = {0};
+    sprintf(cmd, "%s %s %s %s", "ping -I eth1", sgmii, "-c4", "2>&1");
+    fp=popen(cmd, "r");
+    if(NULL == fp){
+        lynq_factory_response_ttyGS3("popen errorn\n");
+        return NULL;
+    }
+    char lynq_factory_buf[1024] = {0};
+    while (NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp))
+    {
+        if(strstr(lynq_factory_buf, "Usage"))
+        {
+            lynq_factory_response_ttyGS3("SGMII cannot recognize IP addresses\n");
+            lynq_factory_response_ttyGS3("ERROR\n");
+            pclose(fp);
+            return NULL;
+        }
+        lynq_factory_response_ttyGS3(lynq_factory_buf);
+    }
+    lynq_factory_response_ttyGS3("OK\n");
+    pclose(fp);
+    return NULL;
+}
+
+/**
+ * @brief factory test for sgmii
+ * 
+ */
+static void lynq_test_SGMII(char *argv){
+    if(argv == NULL)
+    {
+        lynq_factory_response_ttyGS3("\nERROR\n");
         return;
     }
-    pthread_join(thid, NULL);
+    strcpy(sgmii, argv);
+    pthread_t thid;
+    pthread_attr_t a;
+    pthread_attr_init(&a);
+    pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
+    if(pthread_create(&thid, &a, thread_test_SGMII_wtf, NULL) != 0) {
+        return;
+    }
+    //pthread_join(thid, NULL);
     return;
 }
 
 
-static void lynq_gps_open(void){
+static void lynq_gps_open(char *num){
     if(already_gps == 1){
         lynq_factory_response_ttyGS3("gps already open\n");
         return;
     }
+    if(num == NULL)
+    {
+        return;
+    }
+    gps_set = atoi(num);
     pthread_attr_t attr;
     pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -284,93 +293,41 @@
     return;
 }
 
-static void lynq_gps_close(void){
-    #if 0
-    enable_nema = 0;
-    sustain = 1;
-    int res = -1;
-    res = pthread_cancel(lynq_gps_tid);
-    if(res){
-        lynq_factory_response_ttyGS3("pthread cancel fail\n");
-        return;
-    }
-    pthread_join(lynq_gps_tid,NULL);
-    int ret = system("killall mnld_test");
-    already_gps = 0;
-    if(!ret){
-        lynq_factory_response_ttyGS3("GPS CLOSE SUCCESS\n");
-    }
-    else{
-        lynq_factory_response_ttyGS3("GPS CLOSE Failed\n");
-    }
-    #endif
-    system("killall mnld_test");
-    FILE *fp;
-    char test[100] = {0};
-    sleep(1);
-    sprintf(test, "cat /etc/gnss/*.nma %s", "2>&1");
-    char lynq_factory_buf[1024] = {0};
-    fp=popen(test, "r");
-    if(NULL == fp){
-        lynq_factory_response_ttyGS3("popen errorn\n");
-        return;
-    }
-    while(NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp)){
-        lynq_factory_response_ttyGS3(lynq_factory_buf);
-    }
-    pclose(fp);
+static void lynq_gps_enable(void){
+    enable_nema = 1;
+    lynq_factory_response_ttyGS3("+GPS ENABLE:OK\n");
     return;
 }
 
-static void lynq_wifi_open(void){
-    FILE *fp;
-    char test[100] = {0};
-    sprintf(test, "connmanctl enable wifi %s", "2>&1");
-    char lynq_factory_buf[1024] = {0};
-    fp=popen(test, "r");
-    if(NULL == fp){
-        lynq_factory_response_ttyGS3("popen errorn\n");
-        return;
-    }
-    while(NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp)){
-        if(strlen(lynq_factory_buf) > 0)
-        {
-            lynq_factory_response_ttyGS3(lynq_factory_buf);
-        }else{
-            lynq_factory_response_ttyGS3("+CME: ERROR TIMEOUT\n");
-        }
-    }
-    pclose(fp);
+static void lynq_gps_disable(void)
+{
+    enable_nema = 0;
+    lynq_factory_response_ttyGS3("+GPS DISABLE:OK\n");
+    return;
 }
 
-static void lynq_wifi_close(void){
-    FILE *fp;
-    char test[100] = {0};
-    sprintf(test, "connmanctl disable wifi %s", "2>&1");
-    char lynq_factory_buf[1024] = {0};
-    fp=popen(test, "r");
-    if(NULL == fp){
-        lynq_factory_response_ttyGS3("popen errorn\n");
-        return;
-    }
-    while(NULL != fgets(lynq_factory_buf,sizeof(lynq_factory_buf),fp)){
-        if(strlen(lynq_factory_buf) > 0)
-        {
-            lynq_factory_response_ttyGS3(lynq_factory_buf);
-        }else{
-            lynq_factory_response_ttyGS3("+CME: ERROR TIMEOUT\n");
-        }
-    }
-    pclose(fp);
+static void lynq_gps_close(void)
+{
+    already_gps = 0;
+    enable_nema = 0;
+    sustain = 0;
+    system("killall lynq-gnss-test");
+    lynq_factory_response_ttyGS3("+GPS CLOSE:OK\n");
+    return;
 }
 
-
 int lynq_dispose_factory_adc(int num,char *argv[MAX_ARGS])
 {
+    if(num != 5)
+    {
+        lynq_factory_response_ttyGS3("+ADC ERROR: 100");
+        return -1;
+    }
     FILE *fp;
     char lynq_adc_dev[126] = {0};
-    char lynq_adc_buf[64] = {0};
+    char lynq_adc_buf[32] = {0};
     int lynq_adc_num = atoi(argv[4]);
+    char flag[64] = {0};
     if(lynq_adc_num == 0)
     {
         sprintf(lynq_adc_dev,"cat /sys/bus/iio/devices/iio:device1/in_voltage0_input  2>&1");
@@ -387,44 +344,37 @@
     {
         sprintf(lynq_adc_dev,"cat /sys/bus/iio/devices/iio:device1/in_voltage3_input  2>&1");
     }
-    else
-    {
-        lynq_factory_response_ttyGS3("[adc][errror]:no adc device \n");
-        return 0;
-    }
     fp=popen(lynq_adc_dev, "r");
     fgets(lynq_adc_buf,sizeof(lynq_adc_buf),fp);
-    lynq_factory_response_ttyGS3(lynq_adc_buf);
+    sprintf(flag,"%s %s", "ADC:", lynq_adc_buf);
+    lynq_factory_response_ttyGS3(flag);
+    lynq_factory_response_ttyGS3("OK\n");
     pclose(fp);
     return 1;
 }
 
 int lynq_dispose_factory_usb(int num,char *argv[MAX_ARGS])
 {
-        FILE *fp;
-        char lynq_usb_dev[512] = {0};
-        char lynq_usb_buf[512];
-
-        bzero(lynq_usb_buf, 512);
-        bzero(lynq_usb_dev,512);
-        sprintf(lynq_usb_dev,"cat /sys/devices/platform/11201000.usb/udc/11201000.usb/current_speed  2>&1");
-
-        fp=popen(lynq_usb_dev, "r");
-        fgets(lynq_usb_buf,sizeof(lynq_usb_buf),fp);
-        if(!strncmp(lynq_usb_buf,usb3_speed,strlen(usb3_speed)))
-        {   
-            lynq_factory_response_ttyGS3("[usb][result],3.0 \n");
-        }
-        else if(!strncmp(lynq_usb_buf,usb2_speed,strlen(usb2_speed)))
-        {
-            lynq_factory_response_ttyGS3("[usb][result],2.0 \n");
-        }
-        else
-        {
-            lynq_factory_response_ttyGS3("[usb][rat][UNKNOWN] \n");
-        }
-        pclose(fp);
-        return 1;
+    FILE *fp;
+    char lynq_usb_dev[512] = {0};
+    char lynq_usb_buf[512];
+    bzero(lynq_usb_buf, 512);
+    bzero(lynq_usb_dev,512);
+    sprintf(lynq_usb_dev,"cat /sys/devices/platform/11201000.usb/udc/11201000.usb/current_speed  2>&1");
+    fp=popen(lynq_usb_dev, "r");
+    fgets(lynq_usb_buf,sizeof(lynq_usb_buf),fp);
+    if(!strncmp(lynq_usb_buf,usb3_speed,strlen(usb3_speed)))
+    {   
+        lynq_factory_response_ttyGS3("[usb][result],3.0 \n");
+        lynq_factory_response_ttyGS3("OK\n");
+    }
+    else if(!strncmp(lynq_usb_buf,usb2_speed,strlen(usb2_speed)))
+    {
+        lynq_factory_response_ttyGS3("[usb][result],2.0 \n");
+        lynq_factory_response_ttyGS3("OK\n");
+    }
+    pclose(fp);
+    return 1;
 }
 
 void *lynq_deal_witch_audio(void *arg)
@@ -432,6 +382,7 @@
     char lynq_adudio_time_arr[128] = {0};
     char *lynq_argv  = (char *)arg;
     pthread_mutex_lock(&lynq_audio_mutex);
+    lynq_factory_response_ttyGS3("OK\n");
     system("echo write_reg,0x002c,0x0008 > /sys/kernel/debug/mtksocaudio");
     system("echo write_reg,0x0030,0x0010 > /sys/kernel/debug/mtksocaudio");
     sprintf(lynq_adudio_time_arr,"arecord -D plughw:0,1 --buffer-size=1024 -r 16000 -d %s -f S16_LE -c1 | aplay -D plughw:0,7 --buffer-size=1024 -r 16000 -d %s -f S16_LE -c1",lynq_argv,lynq_argv);
@@ -458,10 +409,28 @@
     {
         return ret;
     }
-    pthread_join(id,NULL);
+    //pthread_join(id,NULL);
     return 0;
 }
 
+void lynq_nema_set(char *choice)
+{
+    /*open vcom port*/
+    ttyGS0_fd = open("/dev/ttyGS0",O_RDWR);
+    if(ttyGS0_fd == -1)
+    {
+        lynq_factory_response_ttyGS3("\n+SET NEMA:ERROR\n");
+    }
+    /*open vcom port*/
+    if(choice == NULL)
+    {
+        lynq_factory_response_ttyGS3("INPUT ERROR\n");
+    }
+    g_set_output = atoi(choice);
+    lynq_factory_response_ttyGS3("+SET NEMA:OK\n");
+    return;
+}
+
 int lynq_check_emmc()
 {
     FILE *fp;
@@ -474,100 +443,104 @@
         return -1;
     }
     while(fgets(buf, sizeof(buf), fp) != NULL){
-        lynq_factory_response_ttyGS3("[EMMC] EMMC OK \n"); 
+        lynq_factory_response_ttyGS3("+EMMC: OK \n"); 
         pclose(fp);
         return 0;   
     }
-    lynq_factory_response_ttyGS3("\033[47;31m[EMMC] NO EMMC\033[0m\n");
+    lynq_factory_response_ttyGS3("\033[47;31m+EMMC: ERROR\033[0m\n");
     pclose(fp);
     return 0;
 }
 
-static void lynq_gpsinfo(char *argv){
-    if(argv ==NULL)
-        return;
-    // pthread_mutex_lock(&s_gps_state_change_mutex);
-    enable_nema = atoi(argv);
-    // pthread_cond_signal(&s_gps_change_cond);
-    // pthread_mutex_unlock(&s_gps_state_change_mutex);
-    if(enable_nema == 1){
-        lynq_factory_response_ttyGS3("enable neam\n"); 
-    }
-    else if(enable_nema == 0){
-        lynq_factory_response_ttyGS3("disable neam\n"); 
-    }
-    else{
-        lynq_factory_response_ttyGS3("invalid value\n"); 
-    }
-}
-
 int lynq_check_gpio()
 {
-    #if 0
+    #if 1
     FILE *fp;
-    int lynq_gpio_arr[88] = {6,230,231,232,233,234,102,104,103,101,186,188,187,185,194,196,195,193,205,204,203,202,199,200,201,190,192,191,189,173,174,175,176,170,169,184,183,182,181,24,25,23,25,157,158,155,156,143,144,140,141,153,154,180,179,29,30,178,177,7,5,4,113,112,116,115,114,107,108,105,106,100,99,98,97,94,93,92,91,1,130,41,67,69,68,63};
-    char lynq_show_gpio_state[64] = {0};
+    
+    int lynq_gpio_arr[85] = {230,231,232,233,234,102,104,103,101,186 ,188 ,187 ,185 ,194 ,196 ,195 ,193 ,205 ,204 ,203 ,202, 201 ,190 ,192 ,191 ,189 ,173 ,174 ,175 ,176 ,170 ,169 ,184 ,183 ,182 ,181 ,24 ,25 ,157 ,158 ,155 ,156 ,143 ,144 ,140 ,141 ,153 ,154 ,180 ,179 ,29 ,30 ,178, 177, 7 ,5 ,4 ,113 ,112, 116 ,115 ,114, 107, 108, 105, 106, 100 ,99 ,98, 97, 94, 93, 92, 91, 1 ,130 ,41 ,67 ,69, 68, 63, 22, 23, 199, 200};
     char lynq_set_gpio_arr[256] = {0};
     char lynq_get_gpio_state[512] = {0};
+    char lynq_show_gpio_state[64] = {0};
     int lynq_gpio_low = 0;
     int lynq_gpio_hig = 0;
-    int i = 0;
-    for(i = 0; i < 58; i++)
+    int i = 0,m = 0;
+    int lynq_gpio_beta_state = 1;
+
+    for(m = 0; m < 85; m++)
+    {
+        bzero(lynq_set_gpio_arr, 256);
+        sprintf(lynq_set_gpio_arr,"echo mode %d 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio",(char*)lynq_gpio_arr[m]);
+        system(lynq_set_gpio_arr);
+        bzero(lynq_set_gpio_arr, 256);
+        sprintf(lynq_set_gpio_arr,"echo out %d 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio",(char*)lynq_gpio_arr[m]);
+        system(lynq_set_gpio_arr);
+    }
+
+    for(i = 0; i < 85; i++)
     {
         lynq_gpio_low = 0;
         lynq_gpio_hig = 0;
+
         bzero(lynq_set_gpio_arr, 256);
-        sprintf(lynq_set_gpio_arr,"echo mode %d 0 >/sys/devices/platform/10005000.pinctrl/mt_gpio & echo dir %d 1 >/sys/devices/platform/10005000.pinctrl/mt_gpio & echo out %d 0 >/sys/devices/platform/10005000.pinctrl/mt_gpio",lynq_gpio_arr[i],lynq_gpio_arr[i],lynq_gpio_arr[i]);
+        sprintf(lynq_set_gpio_arr,"echo mode %d 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio",(char*)lynq_gpio_arr[i]);
         system(lynq_set_gpio_arr);
+
         bzero(lynq_set_gpio_arr, 256);
-        sprintf(lynq_set_gpio_arr,"cat /sys/devices/platform/10005000.pinctrl/mt_gpio |grep %03d",lynq_gpio_arr[i]);
+        sprintf(lynq_set_gpio_arr,"echo out %d 1 > /sys/devices/platform/10005000.pinctrl/mt_gpio",(char*)lynq_gpio_arr[i]);
+        system(lynq_set_gpio_arr);
+
+        bzero(lynq_set_gpio_arr, 256);
+        sprintf(lynq_set_gpio_arr,"cat /sys/devices/platform/10005000.pinctrl/mt_gpio | grep 006");
         fp=popen(lynq_set_gpio_arr, "r");
         bzero(lynq_get_gpio_state, 512);
         fgets(lynq_get_gpio_state,sizeof(lynq_get_gpio_state),fp);
-        pclose(fp);
-        if(lynq_get_gpio_state[6] == '0')
+/*     
+        if(strlen(lynq_get_gpio_state) > 0)
         {
-            lynq_gpio_low = 1;
+            lynq_factory_response_ttyGS3(lynq_get_gpio_state);
+            lynq_factory_response_ttyGS3("\n");
         }
-        bzero(lynq_set_gpio_arr, 256);
-        sprintf(lynq_set_gpio_arr,"echo mode %d 0 >/sys/devices/platform/10005000.pinctrl/mt_gpio & echo dir %d 1 >/sys/devices/platform/10005000.pinctrl/mt_gpio & echo out %d 1 >/sys/devices/platform/10005000.pinctrl/mt_gpio",lynq_gpio_arr[i],lynq_gpio_arr[i],lynq_gpio_arr[i]);
-        system(lynq_set_gpio_arr);
-        bzero(lynq_set_gpio_arr, 256);
-        sprintf(lynq_set_gpio_arr,"cat /sys/devices/platform/10005000.pinctrl/mt_gpio |grep %03d:",lynq_gpio_arr[i]);
-        fp=popen(lynq_set_gpio_arr, "r");
-        bzero(lynq_get_gpio_state, 512);
-        fgets(lynq_get_gpio_state,sizeof(lynq_get_gpio_state),fp);
+*/
         pclose(fp);
-        if(lynq_get_gpio_state[6] == '1')
+        if(lynq_get_gpio_state[7] == '1')
         {
             lynq_gpio_hig = 1;
         }
-        bzero(lynq_show_gpio_state, 64);
-        if((lynq_gpio_low == 1) && (lynq_gpio_hig == 1))
+
+        bzero(lynq_set_gpio_arr, 256);
+        sprintf(lynq_set_gpio_arr,"echo out %d 0 > /sys/devices/platform/10005000.pinctrl/mt_gpio",(char*)lynq_gpio_arr[i]);
+        system(lynq_set_gpio_arr);
+        
+        bzero(lynq_set_gpio_arr, 256);
+        sprintf(lynq_set_gpio_arr,"cat /sys/devices/platform/10005000.pinctrl/mt_gpio | grep 006");
+        fp=popen(lynq_set_gpio_arr, "r");
+        bzero(lynq_get_gpio_state, 512);
+        fgets(lynq_get_gpio_state,sizeof(lynq_get_gpio_state),fp);
+        pclose(fp);
+        if(lynq_get_gpio_state[7] == '0')
         {
-            sprintf(lynq_show_gpio_state,"[gpio%d][result]:PASS \n",lynq_gpio_arr[i]);
+            lynq_gpio_low = 1;
+        }
+        bzero(lynq_show_gpio_state, 64);
+        if((lynq_gpio_low != 1) || (lynq_gpio_hig != 1))
+        {
+            lynq_gpio_beta_state = 0;
+            sprintf(lynq_show_gpio_state,"[gpio%d][result]:FAIL \n",(char *)lynq_gpio_arr[i]);
+            lynq_factory_response_ttyGS3(lynq_show_gpio_state);
         }
         else
         {
-            sprintf(lynq_show_gpio_state,"[gpio%d][result]:FAIL \n",lynq_gpio_arr[i]);
+            sprintf(lynq_show_gpio_state,"gpio%d\n",(char *)lynq_gpio_arr[i]);
+            lynq_factory_response_ttyGS3(lynq_show_gpio_state);
         }
-        printf("%s\n",lynq_show_gpio_state);
     }
+    if(lynq_gpio_beta_state == 1)
+    {
+        sprintf(lynq_show_gpio_state,"[gpio][result]:PASS \n");
+        lynq_factory_response_ttyGS3(lynq_show_gpio_state);
+    }
+    return 0;
     #endif
-    FILE *fp;
-    char lynq_usb_dev[52] = {0};
-    sprintf(lynq_usb_dev,"source /data/test/T800_GPIO_TEST.sh  2>&1");
-    fp=popen(lynq_usb_dev, "r");
-    char lynq_usb_buf[512];
-    if(NULL == fp){
-        lynq_factory_response_ttyGS3("popen errorn\n");
-        return 0;
-    }
-    while(NULL != fgets(lynq_usb_buf,sizeof(lynq_usb_buf),fp)){
-        lynq_factory_response_ttyGS3(lynq_usb_buf);
-    }
-    pclose(fp);
-   return 0;
 }
 
 int lynq_test_sink(){
@@ -580,8 +553,9 @@
     int i;
     int j;
     int k = 15;
-    int cnt = 1;
+    char flag_buf[64] = {0};
     for(i = 0;i < 3;i++){
+        bzero(flag_buf, 64);
         bzero(lynq_usb_buf, 512);
         bzero(buf, 512);
         k = 15;
@@ -593,10 +567,12 @@
         usleep(10000);
         sprintf(lynq_usb_buf,"cat /sys/bus/iio/devices/iio:device1/in_voltage4_input  2>&1");
         fp=popen(lynq_usb_buf, "r");
-        fgets(buf,sizeof(buf),fp);
-        strcat(buf, "\n");
-        lynq_factory_response_ttyGS3(buf); 
+        
+        fgets(buf, sizeof(buf), fp);
+        sprintf(flag_buf, "%s%d%s%s%s", "SINK[", i+1, "]: ", buf, "\n");
+        lynq_factory_response_ttyGS3(flag_buf);
     }
+    lynq_factory_response_ttyGS3("OK\n");
     pclose(fp);
     return 1;
 }
@@ -611,14 +587,16 @@
     pclose(fp);
     if(lynq_get_gpio_state[6] == '1')
     {
-        lynq_factory_response_ttyGS3("PCIE SUCCESS\n");
+        lynq_factory_response_ttyGS3("+PCIE: OK\n");
     }
-    else{
-        lynq_factory_response_ttyGS3("PCIE ERROR\n");
+    else
+    {
+        lynq_factory_response_ttyGS3("+PCIE: ERROR\n");
     }
     return 0;
 }
 
+
 void lynq_sendRequestToMd(int request, int id) {
     RequestInfo* info = creatRILInfoAndInit(request, INIT, (RIL_SOCKET_ID) ((id)));
     info->lynqEvent = 1;
@@ -679,18 +657,17 @@
         {
             lynq_sendRequestToMd(RIL_REQUEST_DEVICE_IDENTITY,i);
         }
-        //lynq_get_imei(num, argv);
     }
     if(num < 4)
         return -1;
-    // if(!strcmp(argv[3], "wifi")){
-    //     lynq_wifi_open();
-    // }
-    // else if(!strcmp(argv[3], "wifi_close")){
-    //     lynq_wifi_close();
-    // }
-    else if(!strcmp(argv[3], "gps")){
-        lynq_gps_open();
+    else if(!strcmp(argv[3], "gps_open")){
+        lynq_gps_open(argv[4]);
+    }
+    else if(!strcmp(argv[3], "gps_enable")){
+        lynq_gps_enable();
+    }
+    else if(!strcmp(argv[3], "gps_disable")){
+        lynq_gps_disable();
     }
     else if(!strcmp(argv[3], "gps_close")){
         lynq_gps_close();
@@ -698,22 +675,11 @@
     else if(!strcmp(argv[3], "sink")){
         lynq_test_sink();
     }
-    #if 0
-    else if(!strcmp(argv[3], "gpsinfo")){
-        lynq_gpsinfo(argv[4]);
-    }
-    else if(!strcmp(argv[3], "sim1")){
-        lynq_get_sim_state(sim1);
-    }
-    else if(!strcmp(argv[3], "sim2")){
-        lynq_get_sim_state(sim2);
-    }
-    #endif
     else if(!strcmp(argv[3], "rgmii")){
-        lynq_test_RGMII();
+        lynq_test_RGMII(argv[4]);
     }
     else if(!strcmp(argv[3], "sgmii")){
-        lynq_test_SGMII();
+        lynq_test_SGMII(argv[4]);
     }
     else if((!strcmp(argv[3],"adc")))
     {
@@ -721,7 +687,7 @@
     }
     else if((!strcmp(argv[3],"usb")))
     {
-         lynq_dispose_factory_usb(num,argv);
+        lynq_dispose_factory_usb(num,argv);
     }
     // else if((!strcmp(argv[3],"audio")))
     // {
@@ -739,6 +705,10 @@
     {
         lynq_check_pcie();
     }
+    else if((!strcmp(argv[3],"nema_set")))
+    {
+        lynq_nema_set(argv[4]);
+    }
     else{
         lynq_factory_response_ttyGS3("invalid command\n"); 
     }
diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_at_transfer_table.h b/src/lynq/framework/lynq-ril-service/src/lynq_at_transfer_table.h
index a8d09b7..35d9ecb 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_at_transfer_table.h
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_at_transfer_table.h
@@ -21,6 +21,7 @@
 {LYNQ_REQUEST_FACTORY,"LYNQFACTORY",7},

 {LYNQ_REQUEST_LINFO,"LINFO",7},

 {LYNQ_REQUEST_FOTA,"LYNQFOTA",7},

+{LYNQ_REQUEST_INSIDE_VERSION,"CGIR",7},

 {LYNQ_REQUEST_FACTORY,"CGSN",7},

 

 

diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_commands.h b/src/lynq/framework/lynq-ril-service/src/lynq_commands.h
index ae1d99e..4cf36a7 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_commands.h
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_commands.h
@@ -14,6 +14,7 @@
 {LYNQ_USER_REQUEST_OTHRE,NULL,"LYNQOTHER",NULL,lynqOther},
 {LYNQ_REQUEST_SWITCH_SIM,"SET_DEFAULT_SIM_ALL","LCSUS",lynq_dsds_support,NULL},
 {LYNQ_REQUEST_SCREEN_STATE,"RIL_REQUEST_SCREEN_STATE","SCREEN",lynq_screen,NULL},
+{LYNQ_REQUEST_INSIDE_VERSION,"LYNQ_PLAT_LGMDS","CGIR",NULL,lynq_get_inside_version},
 {LYNQ_PLAT_LGMDS,"LYNQ_PLAT_LGMDS","LGMDS",NULL,getMDstate},
 {LYNQ_REQUEST_RST,"LYNQ_REQUEST_RST","RST",NULL,rst},
 {-1,NULL,NULL,NULL,NULL},
diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp b/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
index 258f066..65803ff 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_common.cpp
@@ -20,6 +20,7 @@
 #include <liblog/lynq_deflog.h>
 #include <sys/time.h>
 #include "Phone_utils.h"
+#include "utils.h"
 #include "pms/lynq_pms.h"
 usb_cmd_t Usb_commands[] = {
 #include "lynq_commands.h"
@@ -113,6 +114,7 @@
         }
         case LYNQ_USER_REQUEST_GNSS:
         case LYNQ_USER_REQUEST_OTHRE:
+		case LYNQ_REQUEST_INSIDE_VERSION:
         case LYNQ_REQUEST_RST:
         case LYNQ_PLAT_LGMDS:
         {
@@ -641,6 +643,28 @@
     return 0;
 }
 
+void* lynq_get_inside_version(int argc,char*argv[],int uToken)
+{
+    int request = RIL_REQUEST_OEM_HOOK_RAW;
+    RIL_SOCKET_ID id = RIL_SOCKET_1;
+    if(utils::is_support_dsds())
+    {
+        id = (RIL_SOCKET_ID)get_default_sim_all_except_data();
+    }
+    else if(utils::is_suppport_dsss())
+    {
+        id = (RIL_SOCKET_ID)Phone_utils::get_enable_sim_for_dsss();
+    }
+    RequestInfo *pRI  = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID)(id));
+    //only for factory test
+    /*lei add for factory test*/
+    pRI->lynqEvent=3;
+    argv[1] = "AT+CGMR";
+    /*lei add for factory test*/
+    sendATCMD(2, argv,id,pRI);
+    return 0;
+}
+
 int lynqATWaitWithTime(int time)
 {
     int ret = 0;
diff --git a/src/lynq/framework/lynq-ril-service/src/lynq_common.h b/src/lynq/framework/lynq-ril-service/src/lynq_common.h
index a5de38a..a25ef22 100755
--- a/src/lynq/framework/lynq-ril-service/src/lynq_common.h
+++ b/src/lynq/framework/lynq-ril-service/src/lynq_common.h
@@ -68,6 +68,7 @@
 #define LYNQ_REQUEST_MWAKEUPCFG (LYNQ_VERSION +22)
 #define LYNQ_REQUEST_CFSN (LYNQ_VERSION +23)
 #define LYNQ_REQUEST_RST (LYNQ_VERSION +25)
+#define LYNQ_REQUEST_INSIDE_VERSION (LYNQ_VERSION +26)
 /*lei add*/
 #define LYNQ_USER_REQUEST_GNSS (LYNQ_VERSION +100)
 #define LYNQ_USER_REQUEST_OTHRE (LYNQ_VERSION +101)
@@ -145,6 +146,7 @@
 int lynq_dsds_support(int argc,char*argv[],char *rilReq, int uToken);
 int lynq_screen(int argc,char*argv[],char *rilReq, int uToken);
 void* getMDstate(int argc,char*argv[],int uToken);
+void* lynq_get_inside_version(int argc,char*argv[],int uToken);
 int lynqATWaitWithTime(int time);//time(s)
 void lynqAtRespWatingEvent();
 int syncRespToUsb(int error_code);
diff --git a/src/lynq/framework/lynq-ril-service/src/ril.cpp b/src/lynq/framework/lynq-ril-service/src/ril.cpp
index d51720c..7dcb1f7 100755
--- a/src/lynq/framework/lynq-ril-service/src/ril.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/ril.cpp
@@ -3187,7 +3187,8 @@
             }
 #ifdef TELEMATIC_5G_SUPPORT
             case RIL_CELL_INFO_TYPE_NR: {
-                appendPrintBuf("%s NR id: mcc=%d,mnc=%d,nci=%d,pci=%d,tac=%d", printBuf,
+                /*Typethree add for T800 5G cid 2022/06/09 start*/
+                appendPrintBuf("%s NR id: mcc=%d,mnc=%d,nci=%llu,pci=%d,tac=%d", printBuf,
                     p_cur->CellInfo.nr.cellidentity.mcc,
                     p_cur->CellInfo.nr.cellidentity.mnc,
                     p_cur->CellInfo.nr.cellidentity.nci,
@@ -3197,11 +3198,11 @@
 
                 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mcc);
                 p.writeInt32(p_cur->CellInfo.nr.cellidentity.mnc);
-                p.writeInt32(p_cur->CellInfo.nr.cellidentity.nci);
+                p.writeUint64(p_cur->CellInfo.nr.cellidentity.nci);
                 p.writeInt32(p_cur->CellInfo.nr.cellidentity.pci);
                 p.writeInt32(p_cur->CellInfo.nr.cellidentity.tac);
                 p.writeInt32(p_cur->CellInfo.nr.cellidentity.nrarfcn);
-
+                /*Typethree add for T800 5G cid 2022/06/09 end*/
                 appendPrintBuf("%s NRSS: ssRsrp=%d,ssRsrq=%d,ssSinr=%d,csiRsrp=%d,csiRsrq=%d,csiSinr=%d", printBuf,
                     p_cur->CellInfo.nr.signalStrength.ssRsrp,
                     p_cur->CellInfo.nr.signalStrength.ssRsrq,
@@ -3894,6 +3895,50 @@
     return;
 }
 
+static int lynq_get_inside_version(){
+    FILE *fp;
+    char buf[128] = {0};
+    char cgmr[128] = {0};
+    sprintf(buf, "uci get lynq_uci_ro.lynq_version.LYNQ_SW_VERSION 2>&1");
+    fp=popen(buf, "r");
+    int n;
+    while(fgets(buf, sizeof(buf), fp) != NULL)
+    {
+    }
+    //parse_version_buf(buf);
+    sprintf(cgmr, "%s %s", "+CGIR:", buf);
+    n = write(ttyGS3_fd,cgmr,strlen(cgmr));
+    if(n<0)
+    {
+        perror("lynq resp write:");
+    }
+    pclose(fp);
+    return 0;
+}
+
+/**
+ * @brief cgmr ---> cgir
+ * 
+ * @param response 
+ */
+static void parse_inside_version(void *response)
+{
+    char *p = (char *)response;
+    while (*p != 0)
+    {
+        if(*p == 'M')
+        {
+            *p = 'I';
+            break;
+        }
+        else
+        {
+            *p ++;
+        }
+    }
+    return;
+}
+
 /**
  * @brief To handle comma-separated strings, take the character before the first comma  eg:123456,78 ->123456
  * 
@@ -4160,6 +4205,22 @@
                         }
                         printf("n = %d\n",n);
                    }
+                   /*lei add only for factory test 2022/5/19*/
+                   if(pRI->lynqEvent==3)
+                   {
+                       /*lei add for at+cgir*/
+                        if(strstr((const char*)response,"+CGMR")){
+                            lynq_get_inside_version();
+                        }
+                        /*lei add for at+cgir*/
+                        parse_inside_version(response);
+                        int n = write(ttyGS3_fd,response,responselen);
+                        if(n<0)
+                        {
+                            perror("lynq resp write:");
+                        }
+                        printf("n = %d\n",n);
+                   }
                    break;
                }
                 /*lei add for AT+CGSN 2022/8/4*/
@@ -6009,11 +6070,7 @@
 int LYNQ_RIL_respSocket(Parcel &p,RIL_Token t)
 {
     RLOGD("LYNQ_RIL_respSocket send start");
-    int ret =0;
-    bool sendResult =false;
     ssize_t sent = 0;
-    uint8_t dataLength[4];
-    int verify = 0x55aa;
     RequestInfo *pRI = (RequestInfo *)t;
     if(pRI->lynqEvent!=2)
     {
@@ -6247,7 +6304,7 @@
         }
         else
         {
-            if(!strcmp(at_buf_ext[i], buf))
+            if(strstr(buf, at_buf_ext[i]))
             {
                 return 1;
             }
@@ -6339,12 +6396,12 @@
     int recv = 0;
     char display[1024] = {0};
     /*For at extension to receive at buffer*/
-    int count_recv = 0;
+    bool flag = false;
     int count_at_cmd = 0;
     len = sizeof(*cli);
     while(1)
     {
-        if(count_recv == 0)
+        if(!flag)
         {
             RLOGE("receive third at cmd\n");
             recv = recvfrom(sockfd, buffer_at, LYNQ_AT_SOCKET_BUFFER, 0, cli, &len);
@@ -6362,6 +6419,7 @@
                 continue;;
             }
             lynq_parse_at_cmd(buffer_at, at_buf_ext, 0);
+            flag = true;
         }
         else
         {
@@ -6384,7 +6442,6 @@
                 }
             }
         }
-        count_recv++;
     }
     return NULL;
 }
@@ -6428,7 +6485,7 @@
         perror("--test--");
         //kill(0, SIGKILL);
     }
-    RLOGD("[%s]open %s successfully!!!\n",__FUNCTION__,ttyname(ttyGS3_fd));
+    RLOGD("[%s]open %s successfully ttyGS3_d %d!!!\n",__FUNCTION__,ttyname(ttyGS3_fd), ttyGS3_fd);
     while(1)
     {
         bzero(buffer, 1024);