[Feature][T108][task-view-1608][thermal]add gsw_get_modem_temperture and demo
Only Configure: No
Affected branch: GSW_V1453
Affected module: thermal
Is it affected on IC: only ASR
Self-test: yes
Doc Update: no
Change-Id: I99f8e68b342dfe2bc5289cd6eb30e709ab6eb36c
diff --git a/mbtk/libgsw_lib/gsw_at_interface.c b/mbtk/libgsw_lib/gsw_at_interface.c
index 2f48b47..cbf2c21 100755
--- a/mbtk/libgsw_lib/gsw_at_interface.c
+++ b/mbtk/libgsw_lib/gsw_at_interface.c
@@ -339,3 +339,30 @@
 {
     return GSW_HAL_SUCCESS;
 }
+
+int gsw_get_modem_temperture(ZONE_NUM num,int *temp)
+{
+    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;
+    }
+    else
+     return GSW_HAL_FUNC_UNSUPPORT;
+}
diff --git a/mbtk/test/libgsw_lib/gsw_thermal_test.c b/mbtk/test/libgsw_lib/gsw_thermal_test.c
new file mode 100755
index 0000000..a3e996d
--- /dev/null
+++ b/mbtk/test/libgsw_lib/gsw_thermal_test.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <termios.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <dlfcn.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef enum{
+    soc_max=0,
+    cpu0,
+    cpu1,
+    cpu2,
+    cpu3,
+    gpu0,
+    gpu1,
+    dramc,
+    mmsys,
+    md_5g,
+    md_4g,
+    md_3g,
+    soc_dram_ntc,
+    pa_5g,
+    pa_4g,
+    rf_ntc,
+    pmic,
+    pmic_vcore,
+    pmic_vpro,
+    pmic_vgpu=19,
+ }ZONE_NUM;
+
+int (*gsw_get_modem_temperture)(ZONE_NUM,int *temp);
+void *dlHandle_pm;
+char *lynqLib_pm = "/lib/libgsw_lib.so";
+int main(void)
+{
+    int ret;
+    int opt = 0;
+    int temp;
+    dlHandle_pm = dlopen(lynqLib_pm, RTLD_NOW);
+    gsw_get_modem_temperture=(int32_t(*)())dlsym(dlHandle_pm, "gsw_get_modem_temperture");
+    ret = gsw_get_modem_temperture(0,&temp);
+    if(ret < 0)
+    {
+        printf("gsw_autosleep_enable FAIL.\n");
+        return -1;
+    }
+        printf("gsw_autosleep_enable success.temp : %d\n",temp);
+        dlclose(dlHandle_pm);
+    return 0;
+}
\ No newline at end of file