[Feature][ZXW-212]add thermal api&demo

Only Configure:No,
Affected branch:master,
Affected module:thermal
Is it affected on both ZXIC and MTK:only ZXIC,
Self-test:Yes,
Doc Update:NO.

Change-Id: Ie3b0ab6c1d7f7b9990b8114962ac791f87b791fc
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
index 2b189ba..48d1ab7 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
+++ b/cap/zx297520v3/sources/meta-zxic-custom/conf/distro/vehicle_dc_ref.conf
@@ -187,6 +187,7 @@
         liblynq-qser-voice \
         liblynq-qser-sim \
         liblynq-qser-sms \
+        liblynq-qser-thermal \
         liblynq-qser-data \
         liblynq-qser-network \
         liblynq-qser-gnss \
@@ -279,6 +280,7 @@
         lynq-qser-sim-demo \
         lynq-qser-sms-demo \
         lynq-qser-data-demo \
+        lynq-qser-thermal-demo \
         lynq-autosuspend \
 	lynq-atcid \
         lynq-qser-autosuspend-demo \
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-thermal/liblynq-qser-thermal.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-thermal/liblynq-qser-thermal.bb
new file mode 100755
index 0000000..cdc8bd1
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/liblynq-qser-thermal/liblynq-qser-thermal.bb
@@ -0,0 +1,53 @@
+#inherit externalsrc package
+
+DESCRIPTION = "liblynq-qser-thermal"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+DEPENDS += "liblynq-log"
+#inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/lib/liblynq-qser-thermal/"
+FILESEXTRAPATHS_prepend :="${TOPDIR}/../src/lynq/lib/:"
+SRC_URI = " \
+          file://liblynq-qser-thermal \
+          "
+
+SRC-DIR = "${S}/../liblynq-qser-thermal"
+
+TARGET_CC_ARCH += "${LDFLAGS}"
+BB_INCLUDE_ADD = "--sysroot=${STAGING_DIR_HOST}"
+BB_LDFLAGS_ADD = "--sysroot=${STAGING_DIR_HOST} -Wl,--hash-style=gnu"
+#Parameters passed to do_compile()
+
+FILES_${PN} = "${base_libdir}/*.so "
+
+FILES_${PN}-dev = "/test \
+                   ${includedir}"
+
+FILES_${PN}-doc = "/doc"
+
+FILES_${PN}-dbg ="${base_bindir}/.debug \
+                  ${base_libdir}/.debug \
+                  ${base_sbindir}/.debug"
+
+INSANE_SKIP_${PN} += "already-stripped"
+INSANE_SKIP_${PN} += "installed-vs-shipped"
+
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+		oe_runmake all -C ${SRC-DIR} ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -Os -Wl,--hash-style=gnu -DTELEPHONYWARE"
+}
+
+do_install () {
+    oe_runmake install -C ${SRC-DIR} ROOT=${D}
+	
+    if [ -d "${WORKONSRC}" ] ; then
+        install -d ${D}${includedir}/
+        cp -af ${SRC-DIR}/include/ ${D}${includedir}/
+    fi 
+}
+
+addtask bachclean
+do_bachclean () {
+    oe_runmake clean
+}
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.cpp
new file mode 100755
index 0000000..03a5926
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.cpp
@@ -0,0 +1,49 @@
+#include <sys/types.h>

+#include <dirent.h>

+#include <unistd.h>

+#include <stdio.h>

+#include <string.h>

+#include <fcntl.h>

+#include <stdlib.h>

+#include <unistd.h>

+#include <dlfcn.h>

+

+#include"lynq-qser-thermal-demo.h"

+

+

+int (*get_thermal_zone)(int *numbers, int size);

+

+

+int main(int argc, char *argv[]){

+    int numbers[MAX_SIZE];

+    int ret = 0;

+    const char *lynq_libpath_thermal = "/lib/liblynq-qser-thermal.so";

+

+    void *dlHandle_thermal = dlopen(lynq_libpath_thermal, RTLD_NOW);

+    if (dlHandle_thermal == NULL) 

+    {

+        printf("dlopen dlHandle_thermal failed: %s\n", dlerror());

+        exit(EXIT_FAILURE);

+    }

+    get_thermal_zone = (int(*)(int *numbers, int size))dlsym(dlHandle_thermal,"get_thermal_zone");

+    if(NULL != get_thermal_zone)

+    {

+        ret = get_thermal_zone(numbers, MAX_SIZE);

+        if (ret <= 0) {

+            printf("get_thermal_zone error\n");

+            return -1;

+    }

+    }else{

+            printf("get_thermal_zone dlsym error\n");

+     }

+

+    for (int j = 0; j < ret; ++j) {

+        printf("[%s-%d] temp[%d] = %d \n", __func__, __LINE__, j, numbers[j]);

+    }

+

+    return 0;

+}

+

+

+

+

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.h b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.h
new file mode 100755
index 0000000..6366538
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/lynq-qser-thermal-demo.h
@@ -0,0 +1,5 @@
+#define MAX_SIZE 100

+#define MAX_LINES 5

+#define MAX_LINE_LENGTH 10

+

+

diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/makefile b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/makefile
new file mode 100755
index 0000000..4468ca5
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/files/makefile
@@ -0,0 +1,49 @@
+SHELL = /bin/sh
+RM = rm -rf
+
+LOCAL_CFLAGS := -Wall \
+                -std=gnu++14 \
+                -g -Os \
+                -flto \
+                -fpermissive \
+
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0
+endif
+
+LOCAL_CFLAGS += -Werror=format-security
+
+$(warning ################# rock ROOT: $(ROOT),includedir:$(includedir),)
+
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(LOCAL_PATH)/include/ \
+  -I$(ROOT)$(includedir)/ \
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lstdc++ \
+    -llynq-qser-thermal \
+
+SOURCES = lynq-qser-thermal-demo.cpp
+
+EXECUTABLE = lynq-qser-thermal-demo
+
+OBJECTS=$(SOURCES:.cpp=.o)
+
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.cpp
+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
+	$(RM) $(OBJECTS_TOOL) $(EXECUTABLE)
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/lynq-qser-thermal-demo.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/lynq-qser-thermal-demo.bb
new file mode 100755
index 0000000..bfd0a84
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-thermal-demo/lynq-qser-thermal-demo.bb
@@ -0,0 +1,33 @@
+# Package summary
+SUMMARY = "lynq-qser-thermal-demo"
+# License, for example MIT
+LICENSE = "MIT"
+# License checksum file is always required
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+		  
+SRC_URI = "file://lynq-qser-thermal-demo.h file://lynq-qser-thermal-demo.cpp"
+
+SRC-DIR = "${S}/../lynq-qser-thermal-demo"
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+#Parameters passed to do_compile()
+EXTRA_OEMAKE = "'TARGET_PLATFORM = ${TARGET_PLATFORM}'\"
+EXTRA_OEMAKE += "'MOBILETEK_RIL_CFG = ${MOBILETEK_RIL_CFG}'"
+
+LOCAL_C_INCLUDES = "-I."
+
+LOCAL_LIBS = "-L. -ldl -g -Os -lstdc++"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+S = "${WORKDIR}"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+
+	${CXX} -Wall lynq-qser-thermal-demo.cpp ${LOCAL_LIBS} ${LOCAL_C_INCLUDES} -o lynq-qser-thermal-demo
+}
+
+do_install() {
+	install -d ${D}${bindir}/
+	install -m 0755 ${S}/lynq-qser-thermal-demo ${D}${bindir}/
+}
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/include/lynq_qser_thermal.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/include/lynq_qser_thermal.h
new file mode 100755
index 0000000..d776dde
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/include/lynq_qser_thermal.h
@@ -0,0 +1,12 @@
+#ifndef _LYNQ_QSER_THERMAL_H_

+#define _LYNQ_QSER_THERMAL_H_

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+#define MAX_SIZE 100

+int get_thermal_zone(int *numbers, int size);

+#ifdef __cplusplus

+}

+#endif

+#endif

diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/makefile
new file mode 100755
index 0000000..d1d6061
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/makefile
@@ -0,0 +1,88 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -g -Os \
+                -flto \
+                -fPIC \
+
+$(warning ################# C2K support: $(RAT_CONFIG_C2K_SUPPORT))
+ifeq ($(strip $(RAT_CONFIG_C2K_SUPPORT)), yes)
+    LOCAL_CFLAGS += -DC2K_SUPPORT
+
+endif
+
+ifeq ($(strip $(MTK_MULTI_SIM_SUPPORT)), dsds)
+    LOCAL_CFLAGS += -DANDROID_SIM_COUNT_2 \
+                     -DANDROID_MULTI_SIM \
+                     -DMODE_DSDS
+endif
+
+
+$(warning ################# TARGET_PLATFORM: $(TARGET_PLATFORM))
+ifeq ($(strip $(TARGET_PLATFORM)), mt2731)
+#$(warning #################add for debug $(ROOT), $(includedir))
+$(warning ################# TARGET_PLATFORM_MT2731)
+    LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2731 \
+                    -DMD_93_SUPPORT
+else ifeq ($(strip $(TARGET_PLATFORM)), mt2635)
+$(warning ################# TARGET_PLATFORM_MT2635)
+    LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2635 \
+                    -DMD_90_SUPPORT
+endif
+
+$(warning ################# RITA ROOT: $(ROOT),includedir:$(includedir))
+LOCAL_PATH   = .
+
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(LOCAL_PATH)/include \
+
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lpthread \
+    -luci \
+
+SOURCES = $(wildcard *.c wildcard *.h src/*.c)
+
+EXECUTABLE = liblynq-qser-thermal.so
+
+OBJECTS=$(SOURCES:.c=.o)
+
+DATE_FMT = +%Y-%m-%d
+ifdef SOURCE_DATE_EPOCH
+    BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
+else
+    BUILD_DATE ?= $(shell date "$(DATE_FMT)")
+endif
+
+.PHONY: build clean install pack_rootfs 
+
+all: build
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) -shared -Wl,--no-undefined $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o : %.c
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $< 
+
+build:  $(EXECUTABLE)
+	$(warning ########## build $(EXECUTABLE)  ##########)
+
+install:
+	mkdir -p $(ROOT)$(base_libdir)/
+	install $(EXECUTABLE) $(ROOT)$(base_libdir)/
+	mkdir -p $(ROOT)$(includedir)/$(NAME)/sdk
+
+pack_rootfs:
+	mkdir -p $(PACK_INITRAMFS_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_INITRAMFS_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_INITRAMFS_TO)$(base_libdir)/$(EXECUTABLE)
+	mkdir -p $(PACK_TO)$(base_libdir)/
+	cp -af $(EXECUTABLE) $(PACK_TO)$(base_libdir)/
+	$(CROSS)strip $(PACK_TO)$(base_libdir)/$(EXECUTABLE)
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/src/lynq_qser_thermal.c b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/src/lynq_qser_thermal.c
new file mode 100755
index 0000000..41e5dac
--- /dev/null
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-thermal/src/lynq_qser_thermal.c
@@ -0,0 +1,61 @@
+#include <stdio.h>

+#include "lynq_qser_thermal.h"

+

+

+void parseBuffer(const char *buf, int *numbers, int *count) {
+    int i = 0;

+    int num = 0;
+    while (buf[i] != '\0') {
+        while (buf[i] == ' ' || buf[i] == '\n') {
+            ++i;
+        }
+
+        while (buf[i] >= '0' && buf[i] <= '9') {
+            num = num * 10 + (buf[i] - '0');
+            ++i;
+        }
+
+        numbers[(*count)++] = num;
+    }
+}
+

+

+int get_thermal_zone(int *numbers, int size) {

+    char path[] = "/sys/zx_tsc/tsc_value";

+    int ch;

+    char buf[MAX_SIZE];

+    int i = 0;

+    int count = 0;

+

+    if(NULL == numbers ){

+        printf("Error para\n");

+        return -1;

+    }

+

+    if(size < 6){

+        printf("Error para\n");

+        return -1;

+    }

+

+    FILE *file = fopen(path, "r");

+    if (file == NULL) {

+        printf("Error opening file.\n");

+        return -2;

+    }

+

+    while ((ch = fgetc(file)) != EOF && i < MAX_SIZE - 1) 

+    {

+        if (ch != '\0') {

+            buf[i++] = (char)ch;

+        }

+    }

+    

+    buf[i] = '\0';

+    fclose(file);

+

+    parseBuffer(buf, numbers, &count);

+

+    return count;

+}

+

+