[Feature][T108][task-view-1805] sdk_ready framework upgrade - mbtk_source
Only Configure:No
Affected branch:mbtk_source_ds
Affected module:sdk_ready
Is it affected on: only ASR
Self-test: Yes
Doc Update:No
Change-Id: I3fa41224c4facb8b6227f57143582d500c3aa04f
diff --git a/mbtk/mbtk_sdk_ready/src/main.c b/mbtk/mbtk_sdk_ready/src/main.c
index 127684a..999bd42 100755
--- a/mbtk/mbtk_sdk_ready/src/main.c
+++ b/mbtk/mbtk_sdk_ready/src/main.c
@@ -1,6 +1,6 @@
#if 1
#include <stdio.h>
-//#include <stdlib.h>
+#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
@@ -8,6 +8,7 @@
#include <fcntl.h>
//#include <signal.h>
#include <cutils/properties.h>
+#include <stdint.h>
#include "mbtk_log.h"
#include "mbtk_info_api.h"
@@ -18,10 +19,99 @@
#define BOOT_CHECK_TIME 200 //200ms
#define NORMAL_CHECK_TIME 30000 //30s
#define PERIOD_LEN 10
+#define update_ril_digit 0x7 //The last three digits are reserved for RIL service,0x111
+#define update_gnss_digit 1<<4
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;
+static pthread_mutex_t lock;
+int tag = 0;
+void update_ril_value(int value)
+{
+ FILE *fp;
+ char buf[16];
+ char cmd[64];
+ int rd_value = 0;
+ int ret = 0;
+
+ pthread_mutex_lock(&lock);
+
+ fp = popen("uci get lynq_uci.sdk_ready","r");
+ if(fp == NULL)
+ {
+ LOGE("Failed to run uci get lynq_uci.sdk_ready\n");
+ pthread_mutex_unlock(&lock);
+ return;
+ }
+ if(fgets(buf, sizeof(buf) - 1, fp) == NULL)
+ {
+ LOGE("update_ril_value fgets failed");
+ pthread_mutex_unlock(&lock);
+ pclose(fp);
+ return;
+ }
+ if(tag != 0)
+ {
+ rd_value = atoi(buf);
+ }
+ else
+ {
+ tag = 1;
+ }
+
+ rd_value &= ~(update_ril_digit);//The last three digits are reserved for RIL service
+ rd_value |= (value & update_ril_digit);
+ sprintf(cmd,"uci set lynq_uci.sdk_ready='%d'",rd_value);
+ ret = system(cmd);
+ if(ret != 0)
+ {
+ LOGE("Failed to run uci set lynq_uci.sdk_ready\n");
+ }
+
+ pclose(fp);
+ pthread_mutex_unlock(&lock);
+ return;
+}
+
+void update_gnss_value()
+{
+ FILE *fp;
+ char buf[16];
+ char cmd[64];
+ int rd_value = 0;
+ int ret = 0;
+
+ pthread_mutex_lock(&lock);
+
+ fp = popen("uci get lynq_uci.sdk_ready","r");
+ if(fp == NULL)
+ {
+ LOGE("Failed to run uci get lynq_uci.sdk_ready\n");
+ pthread_mutex_unlock(&lock);
+ return;
+ }
+ if(fgets(buf, sizeof(buf) - 1, fp) == NULL)
+ {
+ LOGE("update_gnss_value fgets failed");
+ pthread_mutex_unlock(&lock);
+ pclose(fp);
+ return;
+ }
+ rd_value = atoi(buf);
+ rd_value &= ~(update_gnss_digit);
+ rd_value |= (update_gnss_digit); //The fifth digits is reserved for GNSS service
+ sprintf(cmd,"uci set lynq_uci.sdk_ready='%d'",rd_value);
+ ret = system(cmd);
+ if(ret != 0)
+ {
+ LOGE("Failed to run uci set lynq_uci.sdk_ready\n");
+ }
+ pthread_mutex_unlock(&lock);
+ pclose(fp);
+ return;
+}
+
#if 1
static mbtk_ready_status_type modem_check(void)
{
@@ -67,21 +157,19 @@
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
+ //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;
- }
+ //buf[0] = '0' + now_ready_status;
+ //property_set(MBTK_READY_UCI, buf);
+ update_ril_value(now_ready_status);
+ mbtk_ready_status = now_ready_status;
uptime = get_uptime();
if(uptime < 50)//in 50s
{
@@ -122,6 +210,17 @@
return NULL;
}
+static void* check_gnss()
+{
+ LOGE("[SDK_READY] check_gnss entry.");
+ //update_gnss_value();
+ while(1)
+ {
+ sleep(UINT32_MAX);
+ }
+ return NULL;
+}
+
int main(int argc, char *argv[])
{
mbtk_log_init("radio", "MBTK_SDK_READY");
@@ -139,7 +238,7 @@
#endif
LOGE("[SDK_READY] sdk check init.");
- pthread_t sdk_ready_pid;
+ pthread_t ril_check_pid, gnss_check_pid;
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
@@ -148,9 +247,16 @@
return MBTK_RESULT_FAIL;
}
- if(pthread_create(&sdk_ready_pid, &thread_attr, sdk_ready_check_pthread, NULL))
+ if(pthread_create(&ril_check_pid, &thread_attr, sdk_ready_check_pthread, NULL))
{
- LOGE("[SDK_READY] pthread_create() fail.");
+ LOGE("[SDK_READY] sdk_ready_check_pthread pthread_create() fail.");
+ }
+
+ sleep(1);
+
+ if(pthread_create(&gnss_check_pid, &thread_attr, check_gnss, NULL))
+ {
+ LOGE("[SDK_READY] check_gnss pthread_create() fail.");
}
pthread_attr_destroy(&thread_attr);