[Feature][ZXW-107] add libpoweralarm demo code
Only Configure:No
Affected branch:master
Affected module:Rtc
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update:Need
Change-Id: Iaf4f1e7a10055192d54aa96b9e9d10e6e93cee44
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 10afd74..4201487 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
@@ -259,7 +259,7 @@
lynq-qser-fota-demo \
lynq-qser-gnss-demo \
lynq-qser-network-demo \
- "
+ poweralarm-demo"
zxic_app_open += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'RIL', 'rild', '', d)}"
zxic_app_open += "${@bb.utils.contains('CONFIG_TEL_API_SUPPORT', 'BL', 'tel-svr', '', d)}"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp
new file mode 100755
index 0000000..199106b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/files/poweralarm-demo.cpp
@@ -0,0 +1,186 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <stdint.h>
+
+typedef struct
+{
+ int cmdIdx;
+ char *funcName;
+} st_api_test_case;
+
+//for server test
+st_api_test_case at_api_testcases[] =
+{
+ {0, "print_help"},
+ {1, "poweralarm"},
+ {2, "wakealarm"},
+ {3, "cancel_wakealarm"},
+ {4, "lynq_set_poweralarm"},
+ {5, "lynq_set_wakealarm"},
+ {-1, NULL}
+};
+
+
+int (*poweralarm)(char *buffer);
+int (*wakealarm)(char *buffer);
+int (*cancel_wakealarm)();
+int (*lynq_set_poweralarm)(unsigned long time_sec);
+int (*lynq_set_wakealarm)(unsigned long time_sec);
+
+void *dlHandle_poweralarm = NULL;
+
+
+void print_help(void)
+{
+ int i;
+ printf("Supported test cases:\n");
+ for(i = 0; ; i++)
+ {
+ if(at_api_testcases[i].cmdIdx == -1)
+ {
+ break;
+ }
+ printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
+ }
+}
+
+int main(int argc,char *argv[])
+{
+
+ int flag = 0;
+ int cmdIdx = 0;
+ printf("Enter main function\n");
+
+ const char *dlHandle_Path_poweralarm = "/lib/libpoweralarm.so";
+ dlHandle_poweralarm = dlopen(dlHandle_Path_poweralarm, RTLD_NOW);
+ if (dlHandle_poweralarm == NULL)
+ {
+ printf("dlopen dlHandle_fota failed: %s\n", dlerror());
+ return -1;
+ }
+
+ poweralarm = (int (*)(char *buffer))dlsym(dlHandle_poweralarm, "poweralarm");
+ if(poweralarm == NULL)
+ {
+ printf("poweralarm is null\n");
+ return -1;
+ }
+
+ wakealarm = (int (*)(char *buffer))dlsym(dlHandle_poweralarm, "wakealarm");
+ if(wakealarm == NULL)
+ {
+ printf("wakealarm is null\n");
+ return -1;
+ }
+ lynq_set_poweralarm = (int (*)(unsigned long))dlsym(dlHandle_poweralarm,"lynq_set_poweralarm");
+ if(lynq_set_poweralarm == NULL)
+ {
+ printf("lynq_set_poweralarm is null\n");
+ return -1;
+ }
+ lynq_set_wakealarm = (int (*)(unsigned long))dlsym(dlHandle_poweralarm,"lynq_set_wakealarm");
+ if(lynq_set_wakealarm == NULL)
+ {
+ printf("lynq_set_wakealarm is null\n");
+ return -1;
+ }
+
+ cancel_wakealarm = (int (*)())dlsym(dlHandle_poweralarm, "cancel_wakealarm");
+ if(cancel_wakealarm == NULL)
+ {
+ printf("cancel_wakealarm is null\n");
+ return -1;
+ }
+ print_help();
+ while(1)
+ {
+ printf("\nplease input cmd index(-1 exit): ");
+ scanf("%d", &cmdIdx);
+ if(cmdIdx == -1)
+ {
+ break;
+ }
+ switch(cmdIdx)
+ {
+ case 0:
+ print_help();
+ break;
+ case 1:
+ {
+ int ret = 0;
+ char tmp_time[32] = {0};
+ printf("Set poweralarm time,e.g: 60 (seconds)\n");
+ scanf("%s",tmp_time);
+ ret = poweralarm(tmp_time);
+ if(ret != 0)
+ {
+ printf("set poweralarm failed\n");
+ return -1;
+ }
+ break;
+ }
+ case 2:
+ {
+ int ret = 0;
+ char tmp_time[32]={0};
+ printf("Set wakealarm time ,e.g: 60 (seconds)\n");
+ scanf("%s",tmp_time);
+ ret = wakealarm(tmp_time);
+ if(ret != 0)
+ {
+ printf("set poweralarm failed\n");
+ return -1;
+ }
+ break;
+ }
+ case 3:
+ {
+ int ret = 0;
+ ret = cancel_wakealarm();
+ if(ret != 0)
+ {
+ printf("Cancel_wakealarm failed!!!");
+ return -1;
+ }
+ break;
+ }
+ case 4:
+ {
+ int ret = 0;
+ unsigned long time_sec = 0;
+ printf("Input time_sec you want poweralarm,e.g:60 (seconds)\n");
+ scanf("%lu",&time_sec);
+ ret =lynq_set_poweralarm(time_sec);
+ if(ret != 0)
+ {
+ printf("lynq_set_poweralarm failed\n");
+ return -1;
+ }
+
+ }
+ case 5:
+ {
+ int ret = 0;
+ unsigned long time_sec = 0;
+ printf("Input time_sec you want poweralarm,e.g:60 (seconds)\n");
+ scanf("%lu",&time_sec);
+ ret =lynq_set_wakealarm(time_sec);
+ if(ret != 0)
+ {
+ printf("lynq_set_wakealarm failed\n");
+ return -1;
+ }
+ }
+
+ default:
+ break;
+ }
+ }
+ return 0;
+
+}
+
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/poweralarm-demo.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/poweralarm-demo.bb
new file mode 100644
index 0000000..978dd0b
--- /dev/null
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/poweralarm-demo/poweralarm-demo.bb
@@ -0,0 +1,33 @@
+# Package summary
+SUMMARY = "poweralarm-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://poweralarm-demo.cpp"
+
+SRC-DIR = "${S}/../poweralarm-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 -lstdc++"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+S = "${WORKDIR}"
+
+#INHIBIT_PACKAGE_STRIP = "1"
+do_compile () {
+
+ ${CXX} -Wall poweralarm-demo.cpp ${LOCAL_LIBS} ${LOCAL_C_INCLUDES} -o poweralarm-demo
+}
+
+do_install() {
+ install -d ${D}${bindir}/
+ install -m 0755 ${S}/poweralarm-demo ${D}${bindir}/
+}