blob: 127684a808374bfe25e028fdcc41e766c58050ed [file] [log] [blame]
wangyouqiang16aadb02024-04-12 15:47:13 +08001#if 1
2#include <stdio.h>
3//#include <stdlib.h>
b.liu9e8584b2024-11-06 19:21:28 +08004#include <unistd.h>
wangyouqiang16aadb02024-04-12 15:47:13 +08005#include <errno.h>
6#include <pthread.h>
7//#include <string.h>
8#include <fcntl.h>
9//#include <signal.h>
b.liu9e8584b2024-11-06 19:21:28 +080010#include <cutils/properties.h>
wangyouqiang16aadb02024-04-12 15:47:13 +080011
12#include "mbtk_log.h"
13#include "mbtk_info_api.h"
b.liu9e8584b2024-11-06 19:21:28 +080014#include "mbtk_utils.h"
wangyouqiang16aadb02024-04-12 15:47:13 +080015
16#define MBTK_RESULT_FAIL -1
17#define MBTK_RESULT_SUCCESS 0
hong.liuc05984a2025-06-24 21:49:16 +080018#define BOOT_CHECK_TIME 200 //200ms
19#define NORMAL_CHECK_TIME 30000 //30s
20#define PERIOD_LEN 10
21int in_period[PERIOD_LEN] = {100,100,200,200,500,500,500,500,2000,5000};//ms
b.liubcf86c92024-08-19 19:48:28 +080022
wangyouqiang16aadb02024-04-12 15:47:13 +080023static mbtk_ready_status_type mbtk_ready_status = MBTK_READY_INIT;
24static mbtk_info_handle_t* mbtk_handle = NULL;
25#if 1
26static mbtk_ready_status_type modem_check(void)
27{
28 char imei[16]= {0};
29 int cme_err = 0;
30
31 if(mbtk_handle == NULL)
32 {
33 mbtk_handle = mbtk_info_handle_get();
34 if(mbtk_handle == NULL)
35 {
36 LOGE("[SDK_READY] mbtk_info_handle_get fail.");
37 return MBTK_READY_RIL_FAIL;
38 }
39 }
40
41 mbtk_handle->info_err = 0;
42 cme_err = mbtk_imei_get(mbtk_handle, imei);
43 //LOGE("[SDK_READY] imei = [%s], cme_err = [%d]", imei, cme_err);
44 if(cme_err == 0 && strlen(imei) == 0)
45 {
46 mbtk_info_handle_free(&mbtk_handle);
47 mbtk_handle = NULL;
48 return MBTK_READY_RIL_FAIL;
49 }
50 if(cme_err != 0 || strlen(imei) == 0)
51 {
52 mbtk_info_handle_free(&mbtk_handle);
53 mbtk_handle = NULL;
54 return MBTK_READY_MODEM_FAIL;
55 }
56 return MBTK_READY_SUCCESS;
57}
58#endif
hong.liuc05984a2025-06-24 21:49:16 +080059long get_uptime()
60{
61 struct timespec start_time;
62 clock_gettime(CLOCK_MONOTONIC, &start_time);
63 return start_time.tv_sec;
64}
wangyouqiang16aadb02024-04-12 15:47:13 +080065static void* sdk_ready_check_pthread(void *arg)
66{
67 UNUSED(arg);
68 LOGE("[SDK_READY] sdk_ready_check_pthread entry.");
wangyouqiang16aadb02024-04-12 15:47:13 +080069 mbtk_ready_status_type now_ready_status = MBTK_READY_INIT;
q.huang15cf93d2025-06-27 17:26:59 +080070 char buf[MBTK_READY_STRING_SIZE_MAX] = {0};
hong.liuc05984a2025-06-24 21:49:16 +080071 buf[0] = '0' + now_ready_status;
q.huang15cf93d2025-06-27 17:26:59 +080072 property_set(MBTK_READY_UCI, buf);// init state value
wangyouqiang16aadb02024-04-12 15:47:13 +080073 int sleep_time = 30;
hong.liuc05984a2025-06-24 21:49:16 +080074 long uptime = 0;
75 int count = 0;
wangyouqiang16aadb02024-04-12 15:47:13 +080076 while(1)
77 {
78 now_ready_status = modem_check();
79 if(now_ready_status != mbtk_ready_status)
80 {
81 buf[0] = '0' + now_ready_status;
q.huang15cf93d2025-06-27 17:26:59 +080082 property_set(MBTK_READY_UCI, buf);
wangyouqiang16aadb02024-04-12 15:47:13 +080083 mbtk_ready_status = now_ready_status;
84 }
hong.liuc05984a2025-06-24 21:49:16 +080085 uptime = get_uptime();
86 if(uptime < 50)//in 50s
wangyouqiang16aadb02024-04-12 15:47:13 +080087 {
hong.liuc05984a2025-06-24 21:49:16 +080088 if(now_ready_status != MBTK_READY_SUCCESS)
89 {
90 sleep_time = BOOT_CHECK_TIME;
91 }
92 else
93 {
94 sleep_time = NORMAL_CHECK_TIME;
95 }
wangyouqiang16aadb02024-04-12 15:47:13 +080096 }
97 else
98 {
hong.liuc05984a2025-06-24 21:49:16 +080099 if(now_ready_status != MBTK_READY_SUCCESS)
100 {
101 if(count < PERIOD_LEN)
102 {
103 sleep_time = in_period[count];
104 }
105 else
106 {
107 count = 0;
108 sleep_time = in_period[count];
109 }
110 count++;
111 }
112 else
113 {
114 sleep_time = NORMAL_CHECK_TIME;
115 count = 0;
116 }
b.liubcf86c92024-08-19 19:48:28 +0800117
hong.liuc05984a2025-06-24 21:49:16 +0800118 }
119 usleep(sleep_time*1000);
wangyouqiang16aadb02024-04-12 15:47:13 +0800120 }
121 LOGE("[SDK_READY] sdk_ready_check_pthread exit.");
122 return NULL;
123}
124
125int main(int argc, char *argv[])
126{
b.liubcf86c92024-08-19 19:48:28 +0800127 mbtk_log_init("radio", "MBTK_SDK_READY");
128
129 MBTK_SOURCE_INFO_PRINT("mbtk_sdk_ready");
130
wangyouqiang16aadb02024-04-12 15:47:13 +0800131 if(mbtk_ready_status != MBTK_READY_INIT)
132 {
133 LOGE("[SDK_READY] sdk has check.");
134 return MBTK_RESULT_FAIL;
135 }
136
b.liubb590492024-06-13 16:42:08 +0800137#ifdef MBTK_DUMP_SUPPORT
138 mbtk_debug_open(NULL, TRUE);
139#endif
140
wangyouqiang16aadb02024-04-12 15:47:13 +0800141 LOGE("[SDK_READY] sdk check init.");
142 pthread_t sdk_ready_pid;
143 pthread_attr_t thread_attr;
144 pthread_attr_init(&thread_attr);
145 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
146 {
147 LOGE("[SDK_READY] pthread_attr_setdetachstate() fail.");
148 return MBTK_RESULT_FAIL;
149 }
b.liubcf86c92024-08-19 19:48:28 +0800150
wangyouqiang16aadb02024-04-12 15:47:13 +0800151 if(pthread_create(&sdk_ready_pid, &thread_attr, sdk_ready_check_pthread, NULL))
152 {
153 LOGE("[SDK_READY] pthread_create() fail.");
154 }
155
156 pthread_attr_destroy(&thread_attr);
157
158 LOGE("[SDK_READY] sdk check start.");
159 while(1)
160 {
161 sleep(24 * 60 * 60);
162 }
163
164 LOGE("[SDK_READY]!!!mbtk_sdk_ready exit!!!");
165 return MBTK_RESULT_SUCCESS;
166}
q.huang15cf93d2025-06-27 17:26:59 +0800167#endif