Fix mbtk_sdk_ready_v2

Change-Id: I842ad2cfccefb30a254d1ba5dd79c48e8cee71f0
diff --git a/mbtk/Makefile b/mbtk/Makefile
index 7924744..d4b4e99 100755
--- a/mbtk/Makefile
+++ b/mbtk/Makefile
@@ -14,12 +14,12 @@
 
 # Build bin file.
 ifeq ($(MBTK_SOURCE_VERSION), 2)
-DIRS += mbtk_rild_v2 mbtk_servicesd_v2
+DIRS += mbtk_rild_v2 mbtk_servicesd_v2 mbtk_sdk_ready_v2
 else
-DIRS += mbtk_rild mbtk_servicesd
+DIRS += mbtk_rild mbtk_servicesd mbtk_sdk_ready
 endif
 
-DIRS += mbtk_sdk_ready aboot-tiny mbtk_adbd mbtk_logd mbtk_utils mbtk_utils_linux mbtk_gnssd
+DIRS += aboot-tiny mbtk_adbd mbtk_logd mbtk_utils mbtk_utils_linux mbtk_gnssd
 
 # Build test file.
 DIRS += test
diff --git a/mbtk/mbtk_sdk_ready_v2/Makefile b/mbtk/mbtk_sdk_ready_v2/Makefile
new file mode 100755
index 0000000..da63071
--- /dev/null
+++ b/mbtk/mbtk_sdk_ready_v2/Makefile
@@ -0,0 +1,46 @@
+BUILD_ROOT = $(shell pwd)/..
+include $(BUILD_ROOT)/Make.defines
+
+LOCAL_PATH=$(BUILD_ROOT)/mbtk_sdk_ready_v2
+
+INC_DIR += \
+		-I$(BUILD_ROOT)/libmbtk_ril
+
+LIB_DIR +=
+
+LIBS += -lmbtk_lib -lmbtk_ril -lprop2uci
+
+CFLAGS +=
+
+DEFINE +=
+
+#MY_FILES_PATH:=$(LOCAL_PATH)/src
+#ifeq ($(CONFIG_MBTK_QL_SUPPORT),y)
+#MY_FILES_PATH += $(LOCAL_PATH)/ql
+#endif
+
+#ifeq ($(CONFIG_MBTK_PLATFORM),linux)
+#MY_FILES_PATH += $(LOCAL_PATH)/platform/linux
+#endif
+
+LOCAL_SRC_FILES = $(wildcard src/*.c) $(wildcard src/*.cpp)
+OBJS = $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(LOCAL_SRC_FILES)))
+$(info OBJS = $(OBJS))
+
+dtarget := $(OUT_DIR)/bin/mbtk_sdk_ready
+
+all: $(dtarget)
+
+$(dtarget): $(OBJS)
+	@echo "  BIN     $@"
+	$(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $(OBJS) -o $@
+
+%.o:%.c
+	$(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+%.o:%.cpp
+	$(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+clean:
+	rm -f $(OBJS) $(dtarget)
+
diff --git a/mbtk/mbtk_sdk_ready_v2/src/main.c b/mbtk/mbtk_sdk_ready_v2/src/main.c
new file mode 100755
index 0000000..9da6ab0
--- /dev/null
+++ b/mbtk/mbtk_sdk_ready_v2/src/main.c
@@ -0,0 +1,125 @@
+#if 1
+#include <stdio.h>
+//#include <stdlib.h>
+//#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
+//#include <string.h>
+#include <fcntl.h>
+//#include <signal.h>
+
+#include "mbtk_log.h"
+#include "mbtk_ril_api.h"
+
+#define MBTK_RESULT_FAIL -1
+#define MBTK_RESULT_SUCCESS 0
+
+typedef enum{
+    MBTK_READY_INIT = -1,
+    MBTK_READY_SUCCESS,
+    MBTK_READY_MODEM_FAIL,
+    MBTK_READY_RESPONSE_FAIL,
+    MBTK_READY_SOCKET_FAIL,
+    MBTK_READY_RIL_FAIL
+}mbtk_ready_status_type;
+
+static mbtk_ready_status_type mbtk_ready_status = MBTK_READY_INIT;
+static bool ril_inited = FALSE;
+#if 1
+static mbtk_ready_status_type modem_check(void)
+{
+    char imei[16]= {0};
+    int cme_err = 0;
+
+    mbtk_ril_err_enum ret;
+    if(!ril_inited) {
+        ret = mbtk_ril_init();
+        if(ret != MBTK_RIL_ERR_SUCCESS) {
+            return MBTK_READY_RIL_FAIL;
+        }
+        ril_inited = TRUE;
+    }
+
+    ret = mbtk_imei_get(imei);
+    //LOGE("[SDK_READY] imei = [%s], cme_err = [%d]", imei, cme_err);
+    if(ret != MBTK_RIL_ERR_SUCCESS || strlen(imei) == 0)
+    {
+        return MBTK_READY_RIL_FAIL;
+    }
+
+    return MBTK_READY_SUCCESS;
+}
+#endif
+
+static void* sdk_ready_check_pthread(void *arg)
+{
+    UNUSED(arg);
+    LOGE("[SDK_READY] sdk_ready_check_pthread entry.");
+
+    mbtk_ready_status_type now_ready_status = MBTK_READY_INIT;
+    char buf[2] = {0};
+    int sleep_time = 30;
+    while(1)
+    {
+        now_ready_status = modem_check();
+        if(now_ready_status != mbtk_ready_status)
+        {
+            buf[0] = '0' + now_ready_status;
+            property_set("persist.mbtk.sdk.state", buf);
+            mbtk_ready_status = now_ready_status;
+        }
+
+        if(now_ready_status != MBTK_READY_SUCCESS)
+        {
+            sleep_time += 2;
+        }
+        else
+        {
+            sleep_time = 30;
+        }
+
+        sleep(sleep_time);
+    }
+    LOGE("[SDK_READY] sdk_ready_check_pthread exit.");
+    return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+    if(mbtk_ready_status != MBTK_READY_INIT)
+    {
+        LOGE("[SDK_READY] sdk has check.");
+        return MBTK_RESULT_FAIL;
+    }
+
+#ifdef MBTK_DUMP_SUPPORT
+    mbtk_debug_open(NULL, TRUE);
+#endif
+
+	LOGE("[SDK_READY] sdk check init.");
+    pthread_t sdk_ready_pid;
+    pthread_attr_t thread_attr;
+    pthread_attr_init(&thread_attr);
+    if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
+    {
+        LOGE("[SDK_READY] pthread_attr_setdetachstate() fail.");
+        return MBTK_RESULT_FAIL;
+    }
+
+    if(pthread_create(&sdk_ready_pid, &thread_attr, sdk_ready_check_pthread, NULL))
+    {
+        LOGE("[SDK_READY] pthread_create() fail.");
+    }
+
+    pthread_attr_destroy(&thread_attr);
+
+    LOGE("[SDK_READY] sdk check start.");
+    while(1)
+    {
+        sleep(24 * 60 * 60);
+    }
+
+    LOGE("[SDK_READY]!!!mbtk_sdk_ready exit!!!");
+    return MBTK_RESULT_SUCCESS;
+}
+#endif
\ No newline at end of file
diff --git a/mbtk/test/libmbtk_lib/mbtk_timer_test.c b/mbtk/test/libmbtk_lib/mbtk_timer_test.c
new file mode 100755
index 0000000..7b24ef2
--- /dev/null
+++ b/mbtk/test/libmbtk_lib/mbtk_timer_test.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "mbtk_utils.h"
+#include "mbtk_log.h"
+
+#define KMSG "/dev/kmsg"
+
+static int fd = -1;
+
+void timer_alrm_cb(int signo)
+{
+    char *str = "----------------------Timeout---------------------------\n";
+    if(fd > 0) {
+        write(fd, str, strlen(str));
+    }
+
+    printf("%s", str);
+    LOGI("%s", str);
+}
+
+
+int main(int argc, char *argv[])
+{
+    if(argc != 2) {
+        printf("mbtk_timer_test <time>\n");
+        return -1;
+    }
+    mbtk_log_init("radio", "MBTK");
+
+    int time = atoi(argv[1]);
+    if(time > 0) {
+        mbtk_timer_set(timer_alrm_cb, time * 1000);
+    }
+
+    fd = open(KMSG, O_WRONLY);
+    if(fd > 0) {
+        printf("Open kmsg success.");
+    }
+
+    while(1) {
+        sleep(24 * 60 * 60);
+    }
+
+    return 0;
+}
+
diff --git a/mbtk/test/libmbtk_ril/Makefile b/mbtk/test/libmbtk_ril/Makefile
index 7acd22f..6974260 100755
--- a/mbtk/test/libmbtk_ril/Makefile
+++ b/mbtk/test/libmbtk_ril/Makefile
@@ -7,11 +7,16 @@
 
 LIBS += -lmbtk_lib -lmbtk_ril
 
-CFLAGS += 
+CFLAGS +=
 
 DEFINE +=
 
-LOCAL_SRC_FILES = $(wildcard *.c) $(wildcard *.cpp)
+#LOCAL_SRC_FILES = $(wildcard *.c) $(wildcard *.cpp)
+ifeq ($(MBTK_SOURCE_VERSION), 2)
+LOCAL_SRC_FILES = mbtk_ril_test.c
+else
+LOCAL_SRC_FILES = mbtk_info_test.c
+endif
 
 $(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
 
diff --git a/mbtk/test/libmbtk_ril_v2/mbtk_ril_test.c b/mbtk/test/libmbtk_ril/mbtk_ril_test.c
similarity index 100%
rename from mbtk/test/libmbtk_ril_v2/mbtk_ril_test.c
rename to mbtk/test/libmbtk_ril/mbtk_ril_test.c
diff --git a/mbtk/test/libmbtk_ril_v2/Makefile.backup b/mbtk/test/libmbtk_ril_v2/Makefile.backup
deleted file mode 100755
index 7acd22f..0000000
--- a/mbtk/test/libmbtk_ril_v2/Makefile.backup
+++ /dev/null
@@ -1,34 +0,0 @@
-BUILD_ROOT = $(shell pwd)/../..
-include $(BUILD_ROOT)/Make.defines
-
-INC_DIR +=
-
-LIB_DIR +=
-
-LIBS += -lmbtk_lib -lmbtk_ril
-
-CFLAGS += 
-
-DEFINE +=
-
-LOCAL_SRC_FILES = $(wildcard *.c) $(wildcard *.cpp)
-
-$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
-
-OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(LOCAL_SRC_FILES)))
-BINS = $(patsubst %.o,%,$(OBJS))
-
-all: $(BINS)
-
-$(BINS):$(OBJS)
-	@echo "  BIN     $@"
-	$(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $@.o -o $(OUT_DIR)/bin/$@
-
-%.o:%.c
-	$(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
-
-%.o:%.cpp
-	$(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
-
-clean:
-	rm -f $(OBJS)
diff --git a/mbtk/test/others/proc_demo.c b/mbtk/test/others/proc_demo.c
new file mode 100755
index 0000000..7712b4c
--- /dev/null
+++ b/mbtk/test/others/proc_demo.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int pub_int_d = 4;
+char *str = "abc";
+int bss_1;
+
+//int bss_1;
+//static int static_bss_2;
+
+void test(int c)
+{
+    int d = 10;
+    //printf("函数参数:test_c = %p, 局部变量:d = %p\n", &c, &d);
+}
+
+int main(int argc, char *argv[])
+{
+    printf("[栈]函数参数:argc = %p, argv = %p\n", &argc, argv);
+
+    int int_a;
+    static int static_int_b;
+    char *temp_malloc = (char*)malloc(10);
+    const char temp[10];
+
+    printf("[栈]局部变量:int_a[%d] = %p, [BSS]局部静态变量:static_int_b[%d] = %p\n", int_a, &int_a, static_int_b, &static_int_b);
+    printf("[DATA]全局变量:pub_int_d[%d] = %p\n", pub_int_d, &pub_int_d);
+    printf("常量:str = %p, 堆空间:temp_malloc = %p\n", str, temp_malloc);
+    printf("函数:test_func = %p\n", test);
+    printf("const_str = %p, &(temp[3]) = %p\n", temp, &(temp[3]));
+    printf("BSS : %d, %p\n", bss_1, &bss_1);
+
+    test(5);
+
+    while(1) {
+        sleep(24 * 60 * 60);
+    }
+
+    return 0;
+}
+