优化LYNQ_SMS接口以及添加对应测试demo
Change-Id: Ic3e4f4c86bd6eaa14b8ea81fbc9780032e54f118
diff --git a/mbtk/lynq_lib/src/lynq_sms.c b/mbtk/lynq_lib/src/lynq_sms.c
index c7fa721..1d28ce9 100755
--- a/mbtk/lynq_lib/src/lynq_sms.c
+++ b/mbtk/lynq_lib/src/lynq_sms.c
@@ -19,26 +19,60 @@
static mbtk_info_handle_t* sms_info_handle = NULL;
static char sms_center_address[128] = {0};
+typedef struct
+{
+ QSER_SMS_RxMsgHandlerFunc_t handlerPtr;
+ void* contextPtr;
+} lynq_sms_cb_func;
+
+static lynq_sms_cb_func lynq_sms_func_cb_handle;
+
+sms_client_handle_type g_sms_val = -1;
+
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);
+ //printf("3sms_state_change_cb() : %s\n", ptr);
+
+ if (!strncmp("+CMT:", ptr, 5))//丢弃无用消息
+ return ;
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));
+ */
+ QSER_SMS_Msg_t* tmp_data = NULL;
+
+ tmp_data = (QSER_SMS_Msg_t*)malloc(sizeof(QSER_SMS_Msg_t));
+ memset(tmp_data,0x00, sizeof(QSER_SMS_Msg_t));
+
+ tmp_data->format = s.DCS;
+ //printf("t数据编码方案: %d\n", tmp_data->format);
+ memcpy(tmp_data->src_addr, s.OA, strlen(s.OA));
+ //printf("t发送方地址: %s\n", tmp_data->src_addr);
+ memcpy(tmp_data->timestamp, s.SCTS, strlen(s.SCTS));
+ //printf("t服务中心时间戳: %s\n", tmp_data->timestamp);
+ tmp_data->sms_data_len = strlen(s.UD);
+ //printf("t消息内容长度: %d\n", tmp_data->sms_data_len);
+ memcpy(tmp_data->sms_data, s.UD, strlen(s.UD));
+ //printf("t消息内容: %s\n", tmp_data->sms_data);
+
+ lynq_sms_func_cb_handle.handlerPtr(tmp_data, NULL);
+
+ free(tmp_data);
+
}
int qser_sms_client_init(sms_client_handle_type *ph_sms)//out
{
- UNUSED(ph_sms);
- int ret = SMS_OK;
+ //UNUSED(ph_sms);
if(sms_info_handle == NULL)
{
@@ -46,46 +80,64 @@
if(sms_info_handle)
{
printf("creat sms_info_handle is success\n");
+ *ph_sms = sms_info_handle->client_fd;
+ g_sms_val = sms_info_handle->client_fd;
}
else
{
printf("creat sms_info_handle is fail\n");
- ret = SMS_UNKNONW;
+ return -1;
}
}
- return ret;
+ return 0;
}
int qser_sms_client_deinit(sms_client_handle_type h_sms)//in
{
- UNUSED(h_sms);
- int ret = SMS_OK;
+ //UNUSED(h_sms);
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ printf("handle NULL\n");
+ return -1;
+ }
+
if(sms_info_handle)
{
- ret = mbtk_info_handle_free(&sms_info_handle);
+ mbtk_info_handle_free(&sms_info_handle);
+ printf("deinit sms_info_handle is succuess\n");
}
else
{
printf("deinit sms_info_handle is fail\n");
- ret = SMS_UNKNONW;
+ return -1;
}
- return ret;
+ return 0;
}
int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码
{
- UNUSED(h_sms);
+ //UNUSED(h_sms);
//UNUSED(pt_sms_info);
- int ret = SMS_OK;
- uint8_t *phone_num = NULL, *data = NULL;
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ printf("handle NULL\n");
+ return -1;
+ }
+
+
+ if (pt_sms_info == NULL)
+ {
+ printf("QSER_sms_info_t NULL\n");
+ return -1;
+ }
if(sms_info_handle == NULL)
{
printf("qser_sms_send_sms sms_info_handle NULL\n");
- return SMS_ERR;
+ return -1;
}
//QSER_sms_info_t get_sms_info;
@@ -102,6 +154,8 @@
//get_sms_info.user_data_head = pt_sms_info->user_data_head;//长短信用户头部信息
//get_sms_info.user_data_head_valid = pt_sms_info->user_data_head_valid;//是否是长短信
+ uint8_t *phone_num = NULL, *data = NULL;
+
char cmgs[MSM_NUMBER_MAX] = {0};
char resp[RES_NUM_MIN] = {0};
char pdu_data[512] = {0};
@@ -122,33 +176,28 @@
else if (pt_sms_info->format == 2)//USC2
mode = 0;
else
- return SMS_ERR;
+ return -1;
if(data == NULL)
{
printf("qser_sms_send_sms data NULL\n");
- return SMS_ERR;
+ return -1;
}
if(phone_num == NULL)
{
printf("qser_sms_send_sms phone_num NULL\n");
- return SMS_ERR;
+ return -1;
}
- if((pt_sms_info->sms_data_len > 512) || (pt_sms_info->sms_data_len == 0))
+
+ if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
{
- if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
- {
- printf("strlen(telephony_num):%d\n", strlen(phone_num));
- printf("strlen(msg):%d\n", strlen(data));
- return SMS_ERR;
- }
- printf("strlen(msg_len):%d\n", pt_sms_info->sms_data_len);
- return SMS_UNKNONW;//可能data_len没有赋值
+ printf("strlen(telephony_num):%d\n", strlen(phone_num));
+ printf("strlen(msg):%d\n", strlen(data));
+ return -1;
}
-
if (mode == 0)// PDU
{
#if 1
@@ -204,7 +253,7 @@
if(err)
{
printf("Error : %d\n", err);
- ret = SMS_ERR;
+ return -1;
}
else
{
@@ -232,7 +281,7 @@
if(err)
{
printf("Error : %d\n", err);
- ret = SMS_ERR;
+ return -1;
}
else
{
@@ -242,56 +291,65 @@
else
{
printf("Error : mode\n");
- ret = SMS_ERR;
+ return -1;
}
- return ret;
+
+ return 0;
}
//注册接收新短信
int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容
{
- UNUSED(handlerPtr);
- UNUSED(contextPtr);
- int ret = SMS_OK;
+ //UNUSED(handlerPtr);
+ //UNUSED(contextPtr);
if(sms_info_handle == NULL)
{
printf("qser_sms_addrxmsghandler sms_info_handle NULL\n");
- return SMS_ERR;
+ return -1;
}
int err = mbtk_sms_cnmi_set(sms_info_handle);
if(err)
{
printf("set cnmi fail\n");
- ret = SMS_ERR;
+ return -1;
}
+ lynq_sms_func_cb_handle.handlerPtr = handlerPtr;
+ lynq_sms_func_cb_handle.contextPtr = contextPtr;
+
mbtk_sms_state_change_cb_reg(sms_info_handle, lynq_sms_state_change_cb);
- return ret;
+ return 0;
}
//删除短信
int qser_sms_deletefromstorage(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage)//in in 删除短信的信息
{
- UNUSED(h_sms);
+ //UNUSED(h_sms);
//UNUSED(pt_sms_storage);
char cmgd[128] = {0};
int err = 0;
int id_x = -1;
- int ret = SMS_OK;
- if(sms_info_handle == NULL)
+ if (h_sms != g_sms_val || g_sms_val == -1)
{
- printf("qser_sms_deletefromstorage sms_info_handle NULL\n");
- return SMS_ERR;
+ printf("handle NULL\n");
+ return -1;
}
+
if(pt_sms_storage == NULL)
{
printf("qser_sms_deletefromstorage pt_sms_storage NULL\n");
- return SMS_ERR;
+ return -1;
+ }
+
+ if(sms_info_handle == NULL)
+ {
+ printf("qser_sms_deletefromstorage sms_info_handle NULL\n");
+ return -1;
}
id_x = pt_sms_storage->storage_idx;//获取idx的值
@@ -311,38 +369,50 @@
if(err)
{
printf("qser_sms_deletefromstorage Error : %d\n", err);
- ret = SMS_ERR;
+ return -1;
}
else
{
printf("qser_sms_deletefromstorage set success\n");
}
- return ret;
+ return 0;
}
//获取短信中心号码
int qser_sms_getsmscenteraddress( sms_client_handle_type h_sms,QSER_sms_service_center_cfg_t *set_sca_cfg)//in out
{
- UNUSED(h_sms);
+ //UNUSED(h_sms);
//UNUSED(set_sca_cfg);
char sms_center_addree[254] = {0};
int len_t;
char *p1, *p2 ,*substr;
- int ret = SMS_OK;
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ printf("handle NULL\n");
+ return -1;
+ }
+
+
+ if (set_sca_cfg == NULL)
+ {
+ printf("QSER_sms_service_center_cfg_t NULL\n");
+ return -1;
+ }
+
if(sms_info_handle == NULL)
{
printf("qser_sms_getsmscenteraddress sms_info_handle NULL\n");
- return SMS_ERR;
+ return -1;
}
int err = mbtk_sms_csca_get(sms_info_handle, sms_center_addree);
if(sms_center_addree[0] == '\0')
{
printf("qser_sms_getsmscenteraddress Error : %d\n", err);
- return SMS_ERR;
+ return -1;
}
else
{
@@ -365,31 +435,37 @@
else
{
printf("未找到双引号内的字符串\n"); // 输出结果
- ret = SMS_ERR;
+ return -1;
}
}
- return ret;
+ return 0;
}
//设置短信中心号码
int qser_sms_setsmscenteraddress( sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg)//in in
{
- UNUSED(h_sms);
+ //UNUSED(h_sms);
//UNUSED(get_sca_cfg);
char *destNum = NULL;
- int ret = SMS_OK;
+
+ if (h_sms != g_sms_val || g_sms_val == -1)
+ {
+ printf("handle NULL\n");
+ return -1;
+ }
+
if(sms_info_handle == NULL)
{
printf("qser_sms_setsmscenteraddress sms_info_handle NULL\n");
- return SMS_ERR;
+ return -1;
}
if(get_sca_cfg == NULL)
{
printf("qser_sms_setsmscenteraddress get_sca_cfg NULL\n");
- return SMS_ERR;
+ return -1;
}
destNum = get_sca_cfg->service_center_addr;
@@ -401,14 +477,14 @@
if (destNum == NULL)
{
printf("qser_sms_setsmscenteraddress destNum NULL\n");
- return SMS_ERR;
+ return -1;
}
int err = mbtk_sms_csca_set(sms_info_handle, destNum);
if(err)
{
printf("Error : %d\n", err);
- ret = SMS_ERR;
+ return -1;
}
else
{
@@ -418,6 +494,6 @@
printf("qser_sms_setsmscenteraddress success\n");
}
- return ret;
+ return 0;
}