Add toolchain and mbtk source
Change-Id: Ie12546301367ea59240bf23d5e184ad7e36e40b3
diff --git a/mbtk/lynq_lib/src/lynq_audio.c b/mbtk/lynq_lib/src/lynq_audio.c
new file mode 100755
index 0000000..21640ac
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_audio.c
@@ -0,0 +1,333 @@
+/**
+ * \file lynq_audio_api.c
+ * \brief A Documented file.
+ *
+ * Detailed description
+ * \Author: luojian
+ * \Version: 1.0.0
+ * \Date: 2022-10-27
+ */
+#include <fcntl.h>
+#include <stdint.h>
+#include <limits.h>
+#include <termios.h>
+#include <stdarg.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <time.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <signal.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+#include "mbtk_log.h"
+#include "mbtk_type.h"
+#include "mbtk_audio.h"
+
+static int rec_fd = 0;
+static int play_fd = 0;
+static mbtk_audio_handle play_hdl = NULL;
+static mbtk_audio_handle record_hdl = NULL;
+int volume_size = 0;
+pthread_t paly_thread;
+
+
+void dtmf_cb(char dtmf)
+{
+ printf("%s:%c\n", __FUNCTION__, dtmf);
+}
+
+void audio_volume_cb(int volume)
+{
+ volume_size = volume;
+ printf("%s:%d\n", __FUNCTION__, volume);
+}
+
+int lynq_memscpy
+(
+ void *dst,
+ int dst_size,
+ const void *src,
+ int src_size
+)
+{
+ if(dst_size == 0 || src_size == 0 || dst == NULL || src == NULL)
+ {
+ return 0;
+ }
+ else
+ {
+ return memcpy( dst, src,src_size);
+ }
+} /* dsatutil_free_memory() */
+
+static int lynq_get_path_name ( const char* path_name,char* path )
+{
+ int i=0;
+ int last = -1;
+ int len = strlen ( path_name );
+ if ( len > 0 )
+ {
+ for ( i=len - 1; i >= 0; i-- )
+ {
+ if ( path_name[i] == '/' )
+ {
+ last = i;
+ break;
+ }
+ }
+ if ( i != -1 )
+ {
+ lynq_memscpy ( path, ( i + 1 ) * sizeof ( char ), path_name, ( i + 1 ) * sizeof ( char ) );
+ printf ( "mbtk_get_path %s", path );
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int lynq_create_audio_dir(const char *dirname)
+{
+ DIR *p_dir;
+ int res = -1, i = 0;;
+ char str[512];
+ strncpy(str, dirname, 512);
+ int len=strlen(str);
+
+ if(NULL == (p_dir = opendir((const char *)dirname)))
+ {
+ for(i=0; i<len; i++ )
+ {
+ if( str[i]=='/' )
+ {
+ str[i] = '\0';
+ if( access(str,0)!=0 )
+ {
+ if(mkdir(dirname, 0777) == 0)
+ {
+ res = 0;
+ }
+ else
+ {
+ fprintf(stderr, "create audio dir error \n");
+ res = -1;
+ }
+ }
+ str[i]='/';
+ }
+ }
+ if( len>0 && access(str,0)!=0 )
+ {
+ if(mkdir(dirname, 0777) == 0)
+ {
+ res = 0;
+ }
+ else
+ {
+ fprintf(stderr, "create audio dir error \n");
+ res = -1;
+ }
+ }
+ }
+ else
+ {
+ closedir(p_dir);
+ res = 0;
+ }
+ return res;
+}
+
+void lynq_record_cb_func(int cb_result, char* databuf, unsigned int len)
+{
+ int rc;
+ // printf("lynq_record_cb_func() len:%d, rec_fd:%d\n", len, rec_fd);
+ if(NULL == databuf)
+ {
+ printf("NULL == databuf\n");
+ }
+
+ if(NULL != databuf && len > 0 && rec_fd > 0)
+ {
+ //for debug:save into file
+ rc = write(rec_fd, databuf, len);
+ if (rc < 0) {
+ printf("%s: error writing to file!\n", __FUNCTION__);
+ } else if (rc < len) {
+ printf("%s: wrote less the buffer size!\n", __FUNCTION__);
+ }
+ }
+}
+
+int lynq_media_rec_audio(const char *path)
+{
+ int ret = 0;
+ char audio_dir[50] ={0};
+ char audio_wav[10] = {0};
+ lynq_get_path_name(path, audio_dir);
+ printf("path:%s, audio_dir:%s\n", path, audio_dir);
+
+ record_hdl = mbtk_audio_open(MBTK_AUTIO_TYPE_IN, 1, 8000, NULL);
+ if (record_hdl == 0)
+ {
+ printf("AudRecorder open error\n");
+ return -1;
+ }
+
+ lynq_create_audio_dir(audio_dir);
+ rec_fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0644);
+ if (rec_fd <= 0)
+ {
+ printf("file open error\n");
+ goto err;
+ }
+
+ if(-1 == mbtk_audio_record(record_hdl, lynq_record_cb_func, NULL))
+ {
+ printf("file write error\n");
+ goto err;
+ }
+
+ return 0;
+// sleep(10);
+err:
+// Ql_AudRecorder_Close();
+ if(rec_fd > 0)
+ {
+ close(rec_fd);
+ rec_fd = 0;
+ }
+
+ return -1;
+}
+
+
+
+//停止录制音频文件
+void lynq_media_rec_stop_audio(void)
+{
+// sleep(10);
+ mbtk_audio_close(record_hdl);
+ if(rec_fd > 0)
+ {
+ close(rec_fd);
+ rec_fd = 0;
+ }
+ return 0;
+}
+
+//播放音频文件
+int lynq_media_play_audio_thread_handle(void *argv)
+{
+ char databuf[1024];
+ int size;
+
+ char *path = (char *)argv;
+ printf("lynq_media_play_audio() start \npath:%s\n",path);
+ LOGI("%s %d", __FUNCTION__, __LINE__);
+ play_hdl = mbtk_audio_open(MBTK_AUTIO_TYPE_OUT, 1, 8000, NULL);
+ if(NULL == play_hdl)
+ printf("mbtk_audio_open fail\n");
+
+ play_fd = open(path, O_RDWR);
+ if (play_fd <= 0)
+ {
+ printf("file open error\n");
+ goto err;
+ }
+ memset(databuf, 0, sizeof(databuf));
+ while(0 < (size = read(play_fd, databuf, sizeof(databuf))))
+ {
+ if(-1 == mbtk_audio_play_stream(play_hdl, databuf, size))
+ break;
+ }
+ printf("aplay Stream end \n");
+
+err:
+ if(play_fd > 0)
+ {
+ close(play_fd);
+ play_fd = 0;
+ }
+
+ pthread_exit(&paly_thread);
+ mbtk_audio_close(play_hdl);
+ return 0;
+}
+
+//创建线程播放音频文件
+int lynq_media_play_audio(const char *path)
+{
+ int ret = pthread_create(&paly_thread, NULL, lynq_media_play_audio_thread_handle, (void *)path);
+ if (ret != 0) {
+ printf("create thread failed!\n");
+ return -1;
+ }
+
+ pthread_detach(paly_thread);
+ return 0;
+}
+
+
+//停止播放音频文件
+void lynq_media_stop_audio(void)
+{
+ printf("lynq_media_stop_audio()----\n");
+ if(play_fd > 0)
+ {
+ int ret = pthread_cancel(paly_thread);
+ if (ret != 0) {
+ printf("cancle paly_thread fail\n");
+ return ;
+ }
+ close(play_fd);
+ play_fd = 0;
+ }
+ mbtk_audio_close(play_hdl);
+}
+
+
+int lynq_audio_ubus_client_init(mbtk_audio_client_handle_type *ph_audio, mbtk_dtmf_cb cb)
+{
+ if(rec_fd > 0 || play_fd > 0)
+ {
+ printf("rec or play need close\n");
+ return -1;
+ }
+ return mbtk_audio_ubus_client_init(ph_audio, cb);
+}
+
+int lynq_audio_ubus_client_deinit(mbtk_audio_client_handle_type h_audio)
+{
+ if(rec_fd > 0 || play_fd > 0)
+ {
+ printf("rec or play need close\n");
+ return -1;
+ }
+ return mbtk_audio_ubus_client_deinit(h_audio);
+}
+
+
+int lynq_get_spk_volume(int * volume)
+{
+ mbtk_audio_ubus_volume_get(audio_volume_cb);
+ *volume = volume_size;
+ return 0;
+}
+
+
+int lynq_set_spk_volume(const int volume)
+{
+ mbtk_audio_ubus_volume_set(volume);
+ return 0;
+}
+
+
+
+
diff --git a/mbtk/lynq_lib/src/lynq_call_api.c b/mbtk/lynq_lib/src/lynq_call_api.c
new file mode 100755
index 0000000..1645803
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_call_api.c
@@ -0,0 +1,439 @@
+#include "lynq/lynq_call_api.h"
+#include "mbtk_info_api.h"
+
+static mbtk_info_handle_t* info_handle = NULL;
+int lynq_volume_size = 0;
+mbtk_audio_client_handle_type lynq_dtmf_handle;
+mbtk_call_info_t lynq_reg[5]={0};
+int *handle_ptr=null;
+void (*incoming_call_cb_p)(int x)=NULL;
+void lynq_call_state_change_cb(const void* data, int data_len)
+{
+ mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
+ switch (reg->call_wait)
+ {
+ case MBTK_CLCC:
+ {
+ lynq_reg[reg->dir1].dir1 = reg->dir1;
+ lynq_reg[reg->dir1].dir = reg->dir;
+ lynq_reg[reg->dir1].state = reg->state;
+ lynq_reg[reg->dir1].mode = reg->mode;
+ lynq_reg[reg->dir1].mpty = reg->mpty;
+ memset(lynq_reg[reg->dir1].phone_number,0,strlen(reg->phone_number));
+ memcpy(lynq_reg[reg->dir1].phone_number,reg->phone_number,strlen(reg->phone_number));
+ lynq_reg[reg->dir1].type = reg->type;
+ printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type,strlen(reg->phone_number));
+ if(handle_ptr != null)
+ {
+ if(*handle_ptr != reg->dir1)
+ {
+ *handle_ptr = reg->dir1;
+ printf("reg->dir1 : %d\r\n handle=%d\n", reg->dir1,*handle_ptr);
+ handle_ptr = NULL;
+ }
+ }
+ if(reg->dir == 1)
+ (*incoming_call_cb_p)(reg->dir1);
+ break;
+ }
+ case MBTK_DISCONNECTED:
+ memset(&(lynq_reg[reg->disconnected_id]),0,sizeof(lynq_reg[reg->disconnected_id]));
+ printf("\r\nRING : call dis connected: %d!\r\n", reg->disconnected_id);
+ printf("phone number : %s",lynq_reg[reg->disconnected_id].phone_number);
+ lynq_set_mute_mic(0);
+ break;
+ case MBTK_CPAS:
+ printf("\r\nCALL : Call state = %d\r\n", reg->pas);
+ /*
+ MBTK_CALL_RADY, //MT allows commands from TA/TE
+ MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE
+ MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions
+ MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active
+ MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress
+ MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state
+ MBTK_CALL_ACTIVE,
+ */
+ switch (reg->pas)
+ {
+ case MBTK_CALL_RADY:
+ printf("CALL: call READY\r\n");
+ break;
+ case MBTK_CALL_UNAVAILABLE:
+ printf("CALL: call unavaliable\r\n");
+ break;
+ case MBTK_CALL_UNKNOWN:
+ printf("CALL: call unknown\r\n");
+ break;
+ case MBTK_CALL_RINGING:
+ printf("CALL: call ringing\r\n");
+ break;
+ case MBTK_CALL_PROGRESS:
+ printf("CALL: call progress\r\n");
+ break;
+ case MBTK_CALL_ASLEEP:
+ printf("CALL: call asleep\r\n");
+ break;
+ case MBTK_CALL_ACTIVE:
+ printf("CALL: call active\r\n");
+ break;
+ default:
+ printf("\r\n");
+ break;
+ }
+ break;
+ default:
+ printf("\r\nRING : None call_wait = %d\r\n", reg->call_wait);
+ break;
+ }
+ /*
+ if(reg->call_wait == ) //CLCC
+ {
+ printf("\r\nRING : %d, %d, %d, %d, %d, %s, %d\r\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
+ }
+ else if(reg->call_wait == 2) //Disconnected
+ {
+ printf("\r\nRING : call dis connected!\r\n");
+ }
+ else
+ {
+ printf("\r\nRING : None\r\n");
+ }
+ */
+}
+
+
+void lynq_dtmf_cb(char dtmf)
+{
+ printf("%s:%c\n", __FUNCTION__, dtmf);
+}
+
+int lynq_init_call(int uToken)
+{
+ UNUSED(uToken);
+ mbtk_audio_ubus_client_init(&lynq_dtmf_handle, lynq_dtmf_cb);
+ if(info_handle == NULL)
+ {
+ info_handle = mbtk_info_handle_get();
+ if(info_handle)
+ {
+ int err = mbtk_call_state_change_cb_reg(info_handle, lynq_call_state_change_cb);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+int lynq_deinit_call(void)
+{
+ if(info_handle)
+ {
+ return mbtk_info_handle_free(&info_handle);
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+int lynq_call(int *handle, char addr[])
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ if(strlen(addr)>=90)
+ {
+ printf("\ninput phone number over load!\n");
+ return -1;
+ }
+ char *buf = addr;
+ int err = mbtk_call_start(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ handle_ptr = handle;
+ return 0;
+ }
+}
+
+int lynq_call_answer()
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_call_answer(info_handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_call_hungup_all()
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_call_hang(info_handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_call_hungup(int *handle)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_a_call_hang(info_handle, *handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_hangup_waiting_or_background(void)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_waiting_or_background_call_hang(info_handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_hangup_foreground_resume_background(void)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_foreground_resume_background_call_hang(info_handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_switch_waiting_or_holding_and_active(void)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_call_answer(info_handle);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_wait_incoming_call(void *incoming_call_cb)
+{
+ if(incoming_call_cb == NULL)
+ return -1;
+ incoming_call_cb_p = incoming_call_cb;
+ return 0;
+}
+
+int lynq_get_mute_mic (int *status)
+{
+ if(status == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_mute_state_get(info_handle, status);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_set_mute_mic(const int enable)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_mute_state_set(info_handle, enable);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_set_DTMF(const char callnum)
+{
+ //0......9 A B C D * #
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ char callnum_default[17]="0123456789ABCD*#";
+ if((strchr(callnum_default,callnum))==NULL)
+ {
+ printf("please input 0123456789ABCD*#\n");
+ return -1;
+ }
+ mbtk_call_dtmf_info_t dtmf_character;
+ dtmf_character.character = callnum;
+ dtmf_character.duration = 500;
+ int err = mbtk_dtmf_send(info_handle, &dtmf_character);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_get_current_call_state(int *handle,int *call_state,int*toa,int *direction,char addr[])
+{
+ int flag=0;
+ int i;
+ for (i = 0; i < 5; i++)
+ {
+ if(lynq_reg[i].dir1 == *handle)
+ {
+ *direction = lynq_reg[i].dir;
+ *toa = lynq_reg[i].type;
+ memset(addr,0,sizeof(addr));
+ memcpy(addr, lynq_reg[i].phone_number, strlen(lynq_reg[i].phone_number));
+ int len = strlen(lynq_reg[i].phone_number);
+ addr[len]='\0';
+ switch (lynq_reg[i].state)
+ {
+ case MBTK_ACTIVE:
+ *call_state = LYNQ_CALL_ACTIVE;
+ break;
+ case MBTK_HELD:
+ *call_state = LYNQ_CALL_HOLDING;
+ break;
+ case MBTK_DIALING:
+ *call_state = LYNQ_CALL_DIALING;
+ break;
+ case MBTK_ALERTING:
+ *call_state = LYNQ_CALL_ALERTING;
+ break;
+ case MBTK_INCOMING:
+ *call_state = LYNQ_CALL_INCOMING;
+ break;
+ case MBTK_WAITING:
+ *call_state = LYNQ_CALL_WAITING;
+ break;
+ case MBTK_OFFERING:
+ *call_state = LYNQ_CALL_OFFERING;
+ break;
+ default:
+ break;
+ }
+ flag = 1;
+ break;
+ }
+ }
+ if(flag == 0)
+ {
+ return -1;
+ }
+ return 0;
+
+ /*
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ int err = mbtk_call_reg_get(info_handle, ®);
+ if(err) {
+ return -1;
+ } else {
+ printf("CLCC : %d, %d, %d, %d, %d, %s, %d", reg.dir1, reg.dir, reg.state, reg.mode, reg.mpty, reg.phone_number, reg.type);
+ *direction = reg.dir;
+ *toa = reg.type;
+ memcpy(addr, reg.phone_number, strlen(reg.phone_number));
+ switch (reg.state)
+ {
+ case MBTK_ACTIVE:
+ *call_state = LYNQ_CALL_ACTIVE;
+ break;
+ case MBTK_HELD:
+ *call_state = LYNQ_CALL_HOLDING;
+ break;
+ case MBTK_DIALING:
+ *call_state = LYNQ_CALL_DIALING;
+ break;
+ case MBTK_ALERTING:
+ *call_state = LYNQ_CALL_ALERTING;
+ break;
+ case MBTK_INCOMING:
+ *call_state = LYNQ_CALL_INCOMING;
+ break;
+ case MBTK_WAITING:
+ *call_state = LYNQ_CALL_WAITING;
+ break;
+ case MBTK_OFFERING:
+ *call_state = LYNQ_CALL_OFFERING;
+ break;
+ default:
+ break;
+ }
+ return 0;
+ }
+ */
+
+}
+
+void lynq_audio_volume_cb(int volume)
+{
+ lynq_volume_size = volume;
+ if(lynq_volume_size <= 0 || lynq_volume_size > 100)
+ {
+
+ }
+ else
+ {
+ //printf("%s:%d\n", __FUNCTION__, volume);
+ printf("%s:%d\n", __FUNCTION__, lynq_volume_size);
+ }
+}
+
+int lynq_set_speech_volume(const int volume)
+{
+ if(volume <= 0 || volume >= 101)
+ {
+ printf("input error\n");
+ return -1;
+ }
+ else
+ {
+ int set_volume = 0;
+ set_volume = volume;
+ mbtk_audio_ubus_volume_set(set_volume);
+ return 0;
+ }
+}
+
+int lynq_get_speech_volume(int * volume)
+{
+ mbtk_audio_ubus_volume_get(lynq_audio_volume_cb);
+ sleep(1);
+ *volume = lynq_volume_size;
+ return 0;
+}
\ No newline at end of file
diff --git a/mbtk/lynq_lib/src/lynq_gnss.c b/mbtk/lynq_lib/src/lynq_gnss.c
new file mode 100755
index 0000000..b746c31
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_gnss.c
@@ -0,0 +1,151 @@
+/**
+ * \file gnss_test.c
+ * \brief A Documented file.
+ *
+ * Detailed description
+ * \Author: Sniper <e190@163.com>
+ * \Version: 1.0.0
+ * \Date: 2022-03-26
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include "mbtk_type.h"
+#include "mbtk_gnss.h"
+#include "lynq/lynq_gnss.h"
+
+static mbtk_gnss_client_handle _gnss_handle = 0;
+
+static lynq_gnss_rx_ind_msg_handler_t handler_ptr = NULL;
+
+void lynq_gnss_handler_function
+(
+ mbtk_gnss_client_handle h_loc,
+ int e_msg_id,
+ void *pv_data,
+ void *context_ptr
+)
+{
+ if(NULL == handler_ptr)
+ return;
+
+ if(E_LYNQ_LOC_MSG_ID_NMEA_INFO == e_msg_id) {
+ handler_ptr(h_loc, e_msg_id, pv_data, context_ptr);
+ } else {
+ }
+}
+
+//该函数用于进行GNSS初始化
+int lynq_gnss_init(void)
+{
+ int ret=0;
+
+ ret = mbtk_gnss_client_init(&_gnss_handle);
+ if(ret < 0) {
+ printf("mopen_gnss_client_init FAIL. ret:%d\n",ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+//该函数用于取消GNSS初始化
+int lynq_gnss_deinit(void)
+{
+ int ret;
+ if(0 == _gnss_handle) {
+ return -1;
+ }
+
+ ret = mbtk_gnss_client_deinit(_gnss_handle);
+ if(ret < 0) {
+ printf("mopen_gnss_client_deinit FAIL. ret:%d\n",ret);
+ return -1;
+ }
+
+ _gnss_handle = 0;
+ return 0;
+}
+
+//该函数用于GNSS回调函数初始化
+
+int lynq_gnss_callback_reg(lynq_gnss_rx_ind_msg_handler_t handlerPtr)
+{
+ int ret;
+
+ if(0 == _gnss_handle) {
+ return -1;
+ }
+ mbtk_gnss_print_version(_gnss_handle);
+
+ ret = mbtk_gnss_add_rx_msg_handler(_gnss_handle, lynq_gnss_handler_function);
+ if(0 == ret && handlerPtr)
+ handler_ptr = handlerPtr;
+ else
+ return -1;
+ return 0;
+}
+
+//该函数用于启动GNSS。
+int lynq_gnss_start(void)
+{
+ if(0 == _gnss_handle) {
+ return -1;
+ }
+
+ mbtk_gnss_set_mode(_gnss_handle, 0);
+ return mbtk_gnss_set_mode(_gnss_handle, 3);
+}
+
+//该函数用于关闭GNSS。
+int lynq_gnss_stop(void)
+{
+ if(0 == _gnss_handle) {
+ return -1;
+ }
+
+ return mbtk_gnss_set_mode(_gnss_handle, 0);
+}
+
+
+int lynq_gnss_agps_dataconnopen(void)
+{
+ int ret;
+
+ ret = mbtk_gnss_download_tle();
+ if(ret)
+ {
+ printf("%s: download injects failed!!\n", __FUNCTION__);
+ return -1;
+ }
+ return mbtk_gnss_injects_aidpos(_gnss_handle);
+}
+
+int lynq_gnss_dev_reset(void)
+{
+ int ret = 0;
+ if(_gnss_handle < 0)
+ {
+ return -1;
+ }
+ ret = mbtk_gnss_dev_reset(_gnss_handle, 0, 0);
+ return ret;
+}
+
+int lynq_gnss_enable_glonass(void)
+{
+ mbtk_gnss_firmware_update();
+ return 0;
+}
diff --git a/mbtk/lynq_lib/src/lynq_net_api.c b/mbtk/lynq_lib/src/lynq_net_api.c
new file mode 100755
index 0000000..f2195e0
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_net_api.c
@@ -0,0 +1,708 @@
+#include "lynq/lynq_net_api.h"
+
+static mbtk_info_handle_t* info_handle = NULL;
+
+typedef struct
+{
+ uint8 *operator_l;
+ uint8 *operator_s;
+ uint32 mcc_mnc;
+} operator_mcc_mnc_t;
+
+static operator_mcc_mnc_t operator_mcc_mnc[] =
+{
+ {"China Mobile","CMCC",46000},
+ {"China Unicom","CU",46001},
+ {"China Mobile","CMCC",46002},
+ {"China Telecom","CT",46003},
+ {"China Mobile","CMCC",46004},
+ {"China Telecom","CT",46005},
+ {"China Unicom","CU",46006},
+ {"China Mobile","CMCC",46007},
+ {"China Mobile","CMCC",46008},
+ {"China Unicom","CU",46009},
+ {"China Telecom","CT",46011}
+};
+
+int lynq_network_init(int uToken)
+{
+ UNUSED(uToken);
+ if(info_handle == NULL)
+ {
+ info_handle = mbtk_info_handle_get();
+ if(info_handle)
+ {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int lynq_network_deinit(void)
+{
+ if(info_handle)
+ {
+ return mbtk_info_handle_free(&info_handle);
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+int lynq_get_version(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_version_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_get_imei(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_imei_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_get_sn(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_sn_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_get_zone_tmp(ZONE_NUM num, int *temp)
+{
+ if(info_handle == NULL || temp == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_temp_get(info_handle, num, temp);
+}
+
+int lynq_shutdown(char options[])
+{
+ if(options == NULL)
+ {
+ return -1;
+ }
+
+ if(!strcmp(options, "reboot")) {
+ return mbtk_system_reboot(0);
+ } else if(!strcmp(options, "poweroff")) {
+ return mbtk_system_reboot(1);
+ } else if(!strcmp(options, "halt")) {
+ return mbtk_system_reboot(2);
+ } else {
+ return -1;
+ }
+ return 0;
+}
+
+int lynq_time_set(mbtk_time_type_enum time_type, char* time_str)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_time_set(info_handle, time_type, time_str);
+}
+
+int lynq_get_sim_status(int *card_status)
+{
+ if(info_handle == NULL || card_status == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_sim_state_enum sim;
+ int err = mbtk_sim_state_get(info_handle, &sim);
+ if(err) {
+ return -1;
+ } else {
+ *card_status = sim;
+ return 0;
+ }
+}
+
+int lynq_get_imsi(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_imsi_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_get_iccid(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_iccid_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_query_phone_number(char buf[])
+{
+ if(info_handle == NULL || buf == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_phone_number_get(info_handle, buf);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_sim_power (int mode)
+{
+ if(mode != 0 && mode != 1)
+ {
+ return -1;
+ }
+
+ return mbtk_sim_power_set(mode);
+}
+
+int lynq_query_operater(char *OperatorFN,char *OperatorSH,char *MccMnc)
+{
+ if(info_handle == NULL || OperatorFN == NULL || OperatorSH == NULL || MccMnc == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(info_handle, &net) && net.plmn > 0)
+ {
+ // printf("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
+ int i = 0;
+ while(i < ARRAY_SIZE(operator_mcc_mnc))
+ {
+ if(operator_mcc_mnc[i].mcc_mnc == net.plmn)
+ break;
+ i++;
+ }
+
+ if(i == ARRAY_SIZE(operator_mcc_mnc)) // No found mcc&mnc
+ {
+ strcpy(OperatorFN, "UNKNOWN");
+ strcpy(OperatorSH, "UNKNOWN");
+ sprintf(MccMnc, "%d", net.plmn);
+ }
+ else
+ {
+ strcpy(OperatorFN, operator_mcc_mnc[i].operator_l);
+ strcpy(OperatorSH, operator_mcc_mnc[i].operator_s);
+ sprintf(MccMnc, "%d", operator_mcc_mnc[i].mcc_mnc);
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
+int lynq_query_network_selection_mode (int *netselMode)
+{
+ if(info_handle == NULL || netselMode == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_net_info_t net;
+ if(!mbtk_net_sel_mode_get(info_handle, &net))
+ {
+ // printf("Net : %d, %d, %d\n", net.net_sel_mode, net.net_type, net.plmn);
+ *netselMode = net.net_sel_mode;
+ return 0;
+ }
+
+ return -1;
+}
+
+int lynq_set_network_selection_mode(const char *mode, const char* mccmnc)
+{
+ if(info_handle == NULL || str_empty(mode))
+ {
+ return -1;
+ }
+
+ mbtk_net_info_t net;
+ net.net_type = 0xFF;
+ if(!strcmp(mode, "Auto"))
+ {
+ net.net_sel_mode = 0;
+ net.plmn = 0;
+ }
+ else if(!strcmp(mode, "Manual") && !str_empty(mccmnc))
+ {
+ net.net_sel_mode = 1;
+ net.plmn = (uint32)atoi(mccmnc);
+ }
+ else
+ {
+ return -1;
+ }
+ if(!mbtk_net_sel_mode_set(info_handle, &net))
+ {
+ return 0;
+ }
+
+ return -1;
+}
+
+int lynq_query_available_network(list_node_t** net_list)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_available_net_get(info_handle, net_list);
+}
+
+int lynq_query_registration_state(const char *type, int* regState,int *imsRegState,char * LAC,char *CID,int *netType,int * radioTechFam,int *netRejected)
+{
+ if(info_handle == NULL || str_empty(type) || regState == NULL || imsRegState == NULL
+ || LAC == NULL || CID == NULL || netType == NULL || radioTechFam == NULL || netRejected == NULL)
+ {
+ return -1;
+ }
+ mbtk_net_reg_info_t reg;
+ int err = mbtk_net_reg_get(info_handle, ®);
+ if(err) {
+ *netRejected = err;
+ return -1;
+ } else {
+ //printf("REG : %d, %d, %d, %04x, %08o\n", reg.state, reg.type, reg.ims_reg, reg.lac, reg.ci);
+ // Voice/Data/IMS
+ if(strcmp("Voice", type) == 0) {
+ *regState = reg.call_state;
+ } else if(strcmp("Data", type) == 0) {
+ *regState = reg.data_state;
+ } else if(strcmp("IMS", type) == 0) {
+ *imsRegState = reg.ims_state;
+ } else {
+ return -1;
+ }
+
+ if(reg.call_state != MBTK_NET_REG_STATE_NON || reg.data_state != MBTK_NET_REG_STATE_NON || reg.ims_state != MBTK_NET_REG_STATE_NON) {
+ sprintf(LAC, "%04x", reg.lac);
+ sprintf(CID, "%08o", reg.ci);
+ *netType = reg.type;
+ *radioTechFam = RADIO_TECH_3GPP;
+ }
+ return 0;
+ }
+}
+
+int lynq_query_prefferred_networktype (int *preNetType)
+{
+ if(info_handle == NULL || preNetType == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_band_info_t band;
+ int err = mbtk_current_band_get(info_handle, &band);
+ if(err) {
+ return -1;
+ } else {
+ //printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band);
+ *preNetType = band.net_pref;
+ return 0;
+ }
+}
+
+int lynq_set_prefferred_networktype (const int preNetType)
+{
+
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+ if(preNetType < 0 || preNetType > 15)
+ {
+ return -2;
+ }
+ mbtk_band_info_t band;
+ memset(&band, 0, sizeof(mbtk_band_info_t));
+ band.net_pref = preNetType;
+ int err = mbtk_current_band_set(info_handle, &band);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_set_band_mode(int gsm_band, int umts_band, int tdlte_band, int fddlte_band)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_band_info_t band;
+ band.net_pref = 0xFF; // No change network pref.
+ band.gsm_band = (uint16)gsm_band;
+ band.umts_band = (uint16)umts_band;
+ band.tdlte_band = (uint32)tdlte_band;
+ band.fddlte_band = (uint32)fddlte_band;
+ int err = mbtk_current_band_set(info_handle, &band);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_query_available_bandmode (int *gsm_band, int *umts_band, int *tdlte_band, int *fddlte_band)
+{
+ if(info_handle == NULL || gsm_band == NULL || umts_band == NULL || tdlte_band == NULL || fddlte_band == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_band_info_t band;
+ int err = mbtk_support_band_get(info_handle, &band);
+ if(err) {
+ return -1;
+ } else {
+ //printf("Band : %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band);
+ *gsm_band = band.gsm_band;
+ *umts_band = band.umts_band;
+ *tdlte_band = band.tdlte_band;
+ *fddlte_band = band.fddlte_band;
+ return 0;
+ }
+}
+
+int lynq_radio_on (const int data)
+{
+ if(info_handle == NULL || (data != 0 && data != 1))
+ {
+ return -1;
+ }
+
+ int err = mbtk_radio_state_set(info_handle, data);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_query_radio_tech (int* radioTech)
+{
+ if(info_handle == NULL || radioTech == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_radio_state_get(info_handle, radioTech);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_solicited_signal_strength (signalStrength_t *solSigStren)
+{
+ if(info_handle == NULL || solSigStren == NULL)
+ {
+ return -1;
+ }
+
+ mbtk_signal_info_t signal;
+ int err = mbtk_net_signal_get(info_handle, &signal);
+ if(err) {
+ return -1;
+ } else {
+ memset(solSigStren, 0, sizeof(signalStrength_t));
+ switch(mbtk_net_type_get(signal.type))
+ {
+ case MBTK_NET_TYPE_GSM:
+ solSigStren->gsm_sig_valid = 1;
+ break;
+ case MBTK_NET_TYPE_UMTS:
+ solSigStren->umts_sig_valid = 1;
+ break;
+ case MBTK_NET_TYPE_LTE:
+ solSigStren->lte_sig_valid = 1;
+ break;
+ default:
+ break;
+ }
+ solSigStren->rssi = signal.rssi;
+ solSigStren->ber = signal.ber;
+ solSigStren->rxlev = signal.rxlev;
+ solSigStren->rscp = signal.rscp;
+ solSigStren->ecno = signal.ecno;
+ solSigStren->rsrq = signal.rsrq;
+ solSigStren->rsrp = signal.rsrp;
+ return 0;
+ }
+}
+
+int lynq_set_ims (const int ims_mode)
+{
+ if(info_handle == NULL || (ims_mode != 0 && ims_mode != 1))
+ {
+ return -1;
+ }
+
+ int err = mbtk_volte_state_set(info_handle, ims_mode);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+int lynq_init_cell(void)
+{
+ if(info_handle == NULL)
+ {
+ info_handle = mbtk_info_handle_get();
+ if(info_handle)
+ {
+ printf("creat info_handle is success\n");
+ }
+ else{
+ printf("creat info_handle is fail\n");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int lynq_deinit_cell(void)
+{
+ if(info_handle)
+ {
+ return mbtk_info_handle_free(&info_handle);
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+/*
+* Get current cell infomation.
+*/
+int lynq_query_cell_info(int *type, list_node_t **cell_list)
+{
+ if(info_handle == NULL || type == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_cell_get(info_handle, type, cell_list);
+}
+
+/*
+* set current cell infomation.
+*/
+void lynq_set_cell_info(char *mem)
+{
+ if(info_handle == NULL || mem == NULL)
+ {
+ return -1;
+ }
+
+ char resp[1024] = {0};
+ mbtk_cell_set(info_handle, mem, resp);
+
+ return ;
+}
+
+/*
+* Set specific APN informations.
+*
+* cid : 2-7
+*/
+int lynq_apn_set(int cid, mbtk_ip_type_enum ip_type, const void* apn_name,
+ const void *user_name, const void *user_pass, const void *auth)
+{
+ if(info_handle == NULL || str_empty(apn_name))
+ {
+ return -1;
+ }
+
+ return mbtk_apn_set(info_handle, cid, ip_type, apn_name, user_name, user_pass, auth);
+}
+
+/*
+* Get current all APN informations.
+*/
+int lynq_apn_get(int *apn_num, mbtk_apn_info_t apns[])
+{
+ if(info_handle == NULL || apn_num == NULL || apns == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_apn_get(info_handle, apn_num, apns);
+}
+
+/*
+* Start data call.
+*/
+int lynq_data_call_start(int cid, int timeout)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_data_call_start(info_handle, cid, 0, FALSE, timeout);
+}
+
+/*
+* Stop data call.
+*/
+int lynq_data_call_stop(int cid, int timeout)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_data_call_stop(info_handle, cid, timeout);
+}
+
+/*
+* Query data call state.
+*/
+int lynq_data_call_query(int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
+{
+ if(info_handle == NULL || ipv4 == NULL || ipv6 == NULL)
+ {
+ return -1;
+ }
+
+ return mbtk_data_call_state_get(info_handle, cid, ipv4, ipv6);
+}
+
+/*
+ * Get the native ip and free port.
+ */
+int lynq_get_ip_and_port(char *ipBuf_out,int *port,int iptype)
+{
+ char psz_port_cmd[128];
+ int i=0;
+
+ *port = rand() % (60000 - 50000 + 1) + 50000;
+ sprintf(psz_port_cmd, "netstat -an | grep :%d > /dev/null", *port);
+
+ char ipBuf[32] = "";
+ FILE *fstream=NULL;
+
+ char buff[1024];
+ char iptype_str[8];
+ memset(buff,0,sizeof(buff));
+ /*eth0????eth1?docker0?em1?lo?*/
+ if(iptype == 1)
+ {
+
+ if(NULL==(fstream=popen("ifconfig ccinet0 | grep \"inet6 addr: 2\" | awk '{print $3}'","r")))
+ {
+ snprintf(ipBuf, 39, "%s","0:0:0:0:0:0:0:0");
+ }
+ if(NULL!=fgets(buff, sizeof(buff), fstream))
+ {
+ snprintf(ipBuf, 39, "%s",buff);
+ }
+ else
+ {
+ snprintf(ipBuf, 39, "%s","0:0:0:0:0:0:0:0");
+ pclose(fstream);
+ }
+ }
+ else if(iptype == 0)
+ {
+ if(NULL==(fstream=popen("ifconfig ccinet0 | grep \"inet addr:\" | awk \'{print $2}\' | cut -c 6-","r")))
+ {
+ snprintf(ipBuf, 18, "%s","0.0.0.0");
+ }
+ if(NULL!=fgets(buff, sizeof(buff), fstream))
+ {
+ snprintf(ipBuf, 18, "%s",buff);
+ }
+ else
+ {
+ snprintf(ipBuf, 18, "%s","0.0.0.0");
+ pclose(fstream);
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ pclose(fstream);
+
+ printf("ip:%s\n", ipBuf);
+ memcpy(ipBuf_out, ipBuf, 32);
+ return 0;
+}
+
+int lynq_get_modem_fun(MBTK_DEV_MODEM_FUNCTION *fun)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_get_modem_fun(info_handle, fun);
+ if(err) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
diff --git a/mbtk/lynq_lib/src/lynq_sms_api.c b/mbtk/lynq_lib/src/lynq_sms_api.c
new file mode 100755
index 0000000..4fa4007
--- /dev/null
+++ b/mbtk/lynq_lib/src/lynq_sms_api.c
@@ -0,0 +1,291 @@
+#include "lynq/lynq_sms_api.h"
+#include "mbtk_info_api.h"
+
+
+static mbtk_info_handle_t* info_handle = NULL;
+
+
+void lynq_sms_state_change_cb(const void* data, int data_len)
+{
+ LOGV("sms_state_change_cb()----------start\n");
+ uint8 *ptr = (uint8*)data;
+ printf("3sms_state_change_cb() : %s\n", ptr);
+
+ struct SMS_Struct s = PDUDecoding(ptr);
+ printf("服务中心地址: %s\n", s.SCA);
+ printf("发送方地址: %s\n", s.OA);
+ printf("服务中心时间戳: %s\n", s.SCTS);
+ printf("消息内容: %s\n", s.UD);
+ printf("数据编码方案: %s\n", DSC_to_msg(s.DCS));
+}
+
+
+int lynq_init_sms(int uToken)
+{
+ UNUSED(uToken);
+ if(info_handle == NULL)
+ {
+ info_handle = mbtk_info_handle_get();
+ if(info_handle)
+ {
+ printf("creat info_handle is success\n");
+ }
+ else{
+ printf("creat info_handle is fail\n");
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int lynq_deinit_sms(void)
+{
+ if(info_handle)
+ {
+ return mbtk_info_handle_free(&info_handle);
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+
+/*
+*AT+CMGS="10086", CMGS TEST // Send a SMS
+> CMGS TEST
++CMGS: 17
+OK
+*/
+/*
+int charset: send sms mode
+ 0:pdu, 1:text
+
+*/
+
+int lynq_send_sms(char *telephony_num, int state, char *msg)
+{
+ if(info_handle == NULL || msg == NULL || telephony_num == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ char resp[RES_NUM_MIN] = {0};
+ int mode = 0;
+ int err = 0;
+ if(strlen(msg) > 512 || strlen(msg) == 0 || strlen(telephony_num) == 0)
+ {
+ printf("strlen(telephony_num):%d\n", strlen(telephony_num));
+ printf("strlen(msg):%d\n", strlen(msg));
+ return -1;
+ }
+
+ if(state) // text
+ {
+ mode = 1;
+ }
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+ sprintf(cmgs,"%s,%s",telephony_num, msg);
+ printf("cmgs:%s\n", cmgs);
+
+/* char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgs, 0, sizeof(cmgs));
+ memcpy(cmgs, ptr, strlen(ptr));
+ printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs));
+ }
+*/
+
+ memset(resp, 0, sizeof(resp));
+
+ err = mbtk_sms_cmgs_set(info_handle, cmgs, resp);
+ if(err) {
+ printf("Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgs set success . resp:%s\n", resp);
+ }
+
+ return 0;
+}
+
+int lynq_wait_receive_new_sms(int *handle)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ int ret = mbtk_sms_cnmi_set(info_handle);
+ if(ret)
+ {
+ printf("set cnmi fail\n");
+ return -1;
+ }
+
+ mbtk_sms_state_change_cb_reg(info_handle, lynq_sms_state_change_cb);
+ return 0;
+}
+
+/*
+ AT+CMGD=<index>[,<delflag>]
+
+ Deletes message based on index
+ node:
+ index is -1, delete all message
+ delflag set 4
+*/
+int lynq_delete_sms(int index)
+{
+ char cmgd[128] = {0};
+ int err = 0;
+
+ if(index == -1) //delete all
+ {
+ memcpy(cmgd, ",4", strlen(",4"));
+ }
+ else
+ {
+ sprintf(cmgd,"%d",index);
+ }
+
+ printf("cmgd:%s\n", cmgd);
+
+ err = mbtk_sms_cmgd_set(info_handle, cmgd);
+ if(err) {
+ printf("lynq_delete_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("lynq_delete_sms set success\n");
+ }
+
+ return 0;
+}
+
+
+/*
+function: lynq_list_sms
+stat:0:pud, 1:text
+index: 0, list index;
+ > 0,
+
+*/
+int lynq_list_sms(int stat, int index, char *data)
+{
+ if(info_handle == NULL)
+ {
+ return -1;
+ }
+
+ char cmgs[MSM_NUMBER_MAX] = {0};
+ int mode = 0;
+ int err = 0;
+
+ if(stat) // text
+ {
+ mode = 1;
+ }
+
+ err = mbtk_sms_cmgf_set(info_handle, mode);
+ if(err) {
+ printf("cmgf set error : %d\n", err);
+ } else {
+ printf("cmgf set success\n");
+ }
+
+
+ char cmgl[128] = {0};
+ char resp[1024+1] ={0};
+ sprintf(cmgl,"%d,%s", index, data);
+/*
+ char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
+ if(ptr != NULL)
+ {
+ ptr = strstr(cmd, ",");
+ ptr++;
+ memset(cmgl, 0, sizeof(cmgl));
+ memcpy(cmgl, ptr, strlen(ptr));
+ printf("0cmgl:%s\n", cmgl);
+ }
+*/
+ memset(resp, 0, sizeof(resp));
+ err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
+ if(err) {
+ printf("lynq_list_sms Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cmgl set success, reg:%s\n",resp);
+ }
+
+ return 0;
+}
+
+
+int lynq_query_sms_storage_status(void)
+{
+ char mem[128] = {0};
+ int err = mbtk_sms_cpms_get(info_handle, mem);
+ if(err) {
+ printf("cpms query is fail Error : %d\n", err);
+ return -1;
+ } else {
+ printf("cpms query is success : %s\n", mem);
+ }
+
+ return 0;
+}
+
+
+int lynq_get_smsc_address(char *serviceNumber)
+{
+ char csca[128] = {0};
+ if(info_handle == NULL || serviceNumber == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_get(info_handle, serviceNumber);
+ if(err) {
+ printf("lynq_get_smsc_address Error : %d\n", err);
+ return err;
+ } else {
+ printf("lynq_get_smsc_address success\n");
+ }
+
+ return 0;
+}
+
+
+int lynq_set_smsc_address(const char* service_num)
+{
+ if(info_handle == NULL || service_num == NULL)
+ {
+ return -1;
+ }
+
+ int err = mbtk_sms_csca_set(info_handle, service_num);
+ if(err) {
+ printf("Error : %d\n", err);
+ return err;
+ } else {
+ printf("lynq_set_smsc_address success\n");
+ }
+ return 0;
+}
+
+
+
+
+