[Bugfix][T108-GSW][bug-view-1717] gsw modem state monitor doesn't work
Only Configure: No
Affected branch: unknown
Affected module: network
Is it affected on both ZXIC and ASR: only ASR
Self-test: yes
Doc Update: no
Change-Id: I04bf7f66fced67e33ec0e7118210b747be121f04
diff --git a/mbtk/libgsw_lib/gsw_nw_interface.c b/mbtk/libgsw_lib/gsw_nw_interface.c
index b63690d..b613a1a 100755
--- a/mbtk/libgsw_lib/gsw_nw_interface.c
+++ b/mbtk/libgsw_lib/gsw_nw_interface.c
@@ -2,7 +2,10 @@
#include <dlfcn.h>
#include <time.h>
#include <pthread.h>
+#include <cutils/properties.h>
#define SIG_TIMER 5
+#define MODEM_TIMER 5
+
//mbtk include
#define LYNQ_AIR_PLANE_MODE_OFF 1 //at+cfun = 1
#define LYNQ_AIR_PLANE_MODE_ON 4 // at+cfun = 4
@@ -35,6 +38,21 @@
typedef unsigned short uint16;
typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
+#define MBTK_READY_UCI "persist.mbtk.sdk.state"
+#define MBTK_READY_STRING_SIZE_MAX (3+1)
+
+
+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;
+
+bool str_empty(const void *str);
+
typedef enum
{
MBTK_DEV_MODEM_MIN_FUN, //Modem 最小功能
@@ -1247,6 +1265,48 @@
}
+/*
+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;
+
+typedef enum gsw_hal_nw_mode_state_type
+{
+ GSW_MODEM_STATE_UNKNOWN = 0,
+ GSW_MODEM_STATE_ONLINE,
+ GSW_MODEM_STATE_OFFLINE,
+ GSW_SDK_STATE_SERVICE_DOWN,
+ GSW_SDK_STATE_SERVICE_UP,// service down->up 需要routectl 重启
+ GSW_SDK_STATE_GPS_DOWN,
+ GSW_SDK_STATE_GPS_UP,
+} gsw_mode_state_e;
+
+*/
+
+static void convert_uci_to_gsw_modem_state(int uci, int *state)
+{
+ switch(uci)
+ {
+ case MBTK_READY_SUCCESS:
+ *state=GSW_MODEM_STATE_ONLINE;
+ return;
+ case MBTK_READY_INIT:
+ *state=GSW_MODEM_STATE_UNKNOWN;
+ return;
+ }
+ *state=GSW_MODEM_STATE_OFFLINE;
+ return;
+}
+
+
+
+
+
static void gsw_serving_info_callback_thread()
{
@@ -1437,23 +1497,57 @@
if(ret != 0)
{
LOGE("mbtk_net_signal_get fail, ret is %d\n",ret);
+
}
-
else
{
convert_mbtk_sig_info_to_gsw_sig_info(&signal,&sig_strength);
-
+ if(sig_cb != NULL)
+ {
+ sig_cb(sig_strength);
+ }
}
-
- if(sig_cb != NULL)
- {
- sig_cb(sig_strength);
- }
-
sleep(SIG_TIMER);
}
}
+int gsw_get_modem_state(int *state)
+{
+ char buf[MBTK_READY_STRING_SIZE_MAX];
+ if(property_get(MBTK_READY_UCI, buf, "") > 0 && !str_empty(buf))
+ {
+ int uci_value=atoi(buf);
+ convert_uci_to_gsw_modem_state(uci_value,state);
+ return GSW_HAL_SUCCESS;
+ }
+ return GSW_HAL_NORMAL_FAIL;
+}
+
+int g_mode_state=((int)(GSW_MODEM_STATE_UNKNOWN))-1;
+void gsw_modem_state_timer()
+{
+ while(nw_init_flag)
+ {
+ if(modem_cb != NULL)
+ {
+ int state;
+ int ret = gsw_get_modem_state(&state);
+ if(ret != 0)
+ {
+ LOGE("gsw_get_modem_state fail, ret is %d",ret);
+ }
+ else if(state!=g_mode_state)
+ {
+ LOGE("modem state changed from %d to %d",g_mode_state,state);
+ g_mode_state=state;
+ modem_cb(state);
+ }
+ }
+ sleep(MODEM_TIMER);
+ }
+}
+
+
/**
* @brief SDK interface to call back serving info
@@ -1497,7 +1591,8 @@
if(handle_ptr == NULL)
{
LOGE("handle_ptr is NULL\n");
- return GSW_HAL_NORMAL_FAIL;
+ sig_cb=NULL;
+ return GSW_HAL_SUCCESS;
}
sig_cb = handle_ptr;
@@ -1587,14 +1682,24 @@
return GSW_HAL_NORMAL_FAIL;
}
+ nw_init_flag = 1;
+
ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_sig_info_timer, NULL);
if (ret != 0)
{
- LOGE("pthread_create fail\n");
- return GSW_HAL_NORMAL_FAIL;
+ LOGE("pthread_create fail,ret is %d", ret);
+ nw_init_flag = 0;
+ return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;
}
- nw_init_flag = 1;
+
+ ret = pthread_create(&nw_info_thread, NULL, (void*)gsw_modem_state_timer, NULL);
+ if (ret != 0)
+ {
+ LOGE("pthread_create fail 2,ret is %d", ret);
+ nw_init_flag = 0;
+ return GSW_HAL_ERROR_GNSS_NO_THRESHOLDS;
+ }
return GSW_HAL_SUCCESS;
}
@@ -2478,7 +2583,8 @@
if(handle_ptr == NULL)
{
LOGE("handle_ptr is NULL\n");
- return GSW_HAL_NORMAL_FAIL;
+ modem_cb=NULL;
+ return GSW_HAL_SUCCESS;
}
modem_cb = handle_ptr;