[Bugfix][T108][bug-view-1499]Optimize the code for the temperature section

Only Configure: No
Affected branch: GSW_V1453
Affected module: themal
Is it affected on IC: only ASR
Self-test: yes
Doc Update: no

Change-Id: I7c16a5c674c342d07ec0e18a12eca549fb82b233
diff --git a/mbtk/libgsw_lib/gsw_at_interface.c b/mbtk/libgsw_lib/gsw_at_interface.c
index cbf2c21..67a61a1 100755
--- a/mbtk/libgsw_lib/gsw_at_interface.c
+++ b/mbtk/libgsw_lib/gsw_at_interface.c
@@ -342,27 +342,40 @@
 

 int gsw_get_modem_temperture(ZONE_NUM num,int *temp)

 {

-    if (num == soc_max)

+    if (num != soc_max)

     {

-        char *cmd = "/sys/class/thermal/thermal_zone0/temp";

-        FILE *fp;

-        char buf[128];

-        fp = fopen(cmd, "r");

-        if (fp == NULL)

-        {

-            perror("Unable to open file");

-            return GSW_HAL_NORMAL_FAIL;

-        }

-        

-        if (fgets(buf, sizeof(buf), fp) != NULL)

-        {

-            *temp = atoi(buf) * 0.001;

-            //printf("Temperature: %d °C\n", *temp);

-        }

-

-        fclose(fp);

-        return GSW_HAL_SUCCESS;

+        LOGE("temperture if not support,num is %d\n",num);

+        return GSW_HAL_FUNC_UNSUPPORT;

     }

-    else

-     return GSW_HAL_FUNC_UNSUPPORT;

+    if (NULL == temp)

+    {

+        LOGE("temperture is null\n");

+        return GSW_HAL_ARG_INVALID;

+    }

+

+    char *cmd = "/sys/class/thermal/thermal_zone0/temp";

+    FILE *fp = NULL;

+    char buf[128] = {0};

+    fp = fopen(cmd, "r");

+    if (fp == NULL)

+    {

+        LOGE("Unable to open file");

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    if (fgets(buf, sizeof(buf), fp) == NULL)

+    {

+        LOGE("fgets fail");

+        fclose(fp);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+    if (strlen(buf) == 0)

+    {

+        LOGE("read len == 0\n");

+        fclose(fp);

+        return GSW_HAL_NORMAL_FAIL;

+    }

+

+    *temp = atoi(buf) / 1000;

+    fclose(fp);

+    return GSW_HAL_SUCCESS;

 }