| #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 <cutils/properties.h> |
| |
| #include "mbtk_log.h" |
| #include "mbtk_info_api.h" |
| #include "mbtk_utils.h" |
| |
| #define MBTK_RESULT_FAIL -1 |
| #define MBTK_RESULT_SUCCESS 0 |
| #define BOOT_CHECK_TIME 200 //200ms |
| #define NORMAL_CHECK_TIME 30000 //30s |
| #define PERIOD_LEN 10 |
| int in_period[PERIOD_LEN] = {100,100,200,200,500,500,500,500,2000,5000};//ms |
| |
| static mbtk_ready_status_type mbtk_ready_status = MBTK_READY_INIT; |
| static mbtk_info_handle_t* mbtk_handle = NULL; |
| #if 1 |
| static mbtk_ready_status_type modem_check(void) |
| { |
| char imei[16]= {0}; |
| int cme_err = 0; |
| |
| if(mbtk_handle == NULL) |
| { |
| mbtk_handle = mbtk_info_handle_get(); |
| if(mbtk_handle == NULL) |
| { |
| LOGE("[SDK_READY] mbtk_info_handle_get fail."); |
| return MBTK_READY_RIL_FAIL; |
| } |
| } |
| |
| mbtk_handle->info_err = 0; |
| cme_err = mbtk_imei_get(mbtk_handle, imei); |
| //LOGE("[SDK_READY] imei = [%s], cme_err = [%d]", imei, cme_err); |
| if(cme_err == 0 && strlen(imei) == 0) |
| { |
| mbtk_info_handle_free(&mbtk_handle); |
| mbtk_handle = NULL; |
| return MBTK_READY_RIL_FAIL; |
| } |
| if(cme_err != 0 || strlen(imei) == 0) |
| { |
| mbtk_info_handle_free(&mbtk_handle); |
| mbtk_handle = NULL; |
| return MBTK_READY_MODEM_FAIL; |
| } |
| return MBTK_READY_SUCCESS; |
| } |
| #endif |
| long get_uptime() |
| { |
| struct timespec start_time; |
| clock_gettime(CLOCK_MONOTONIC, &start_time); |
| return start_time.tv_sec; |
| } |
| 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[MBTK_READY_STRING_SIZE_MAX] = {0}; |
| buf[0] = '0' + now_ready_status; |
| property_set(MBTK_READY_UCI, buf);// init state value |
| int sleep_time = 30; |
| long uptime = 0; |
| int count = 0; |
| while(1) |
| { |
| now_ready_status = modem_check(); |
| if(now_ready_status != mbtk_ready_status) |
| { |
| buf[0] = '0' + now_ready_status; |
| property_set(MBTK_READY_UCI, buf); |
| mbtk_ready_status = now_ready_status; |
| } |
| uptime = get_uptime(); |
| if(uptime < 50)//in 50s |
| { |
| if(now_ready_status != MBTK_READY_SUCCESS) |
| { |
| sleep_time = BOOT_CHECK_TIME; |
| } |
| else |
| { |
| sleep_time = NORMAL_CHECK_TIME; |
| } |
| } |
| else |
| { |
| if(now_ready_status != MBTK_READY_SUCCESS) |
| { |
| if(count < PERIOD_LEN) |
| { |
| sleep_time = in_period[count]; |
| } |
| else |
| { |
| count = 0; |
| sleep_time = in_period[count]; |
| } |
| count++; |
| } |
| else |
| { |
| sleep_time = NORMAL_CHECK_TIME; |
| count = 0; |
| } |
| |
| } |
| usleep(sleep_time*1000); |
| } |
| LOGE("[SDK_READY] sdk_ready_check_pthread exit."); |
| return NULL; |
| } |
| |
| int main(int argc, char *argv[]) |
| { |
| mbtk_log_init("radio", "MBTK_SDK_READY"); |
| |
| MBTK_SOURCE_INFO_PRINT("mbtk_sdk_ready"); |
| |
| 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 |