blob: 4fa400730784ce69902fa6fa7a420c14a5aa47cc [file] [log] [blame]
#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;
}