blob: 358464c42176759d0a4d8bbb262592daf5c658f1 [file] [log] [blame]
/**
* \file dtmf_test.c
* \brief A Documented file.
*
* Detailed description
* \Author: jinLuo
* \Version: 1.0.0
* \Date: 2022-12-1
*/
/******************************************************************************\
* Include files
\******************************************************************************/
#include <pthread.h>
#include <time.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <poll.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "lynq_qser_sms.h"
#if 0
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <dlfcn.h>
#include <stdint.h>
#include <ctype.h>
//#include"lynq-qser-sms-demo.h"
#define SMS_BUF 64
#define MSG_BUF 100
int flag_init = 0;
typedef uint32_t sim_client_handle_type;
sms_client_handle_type ph_sms = 2022;
sms_client_handle_type h_sms = 2022;
int (*qser_sms_client_init)(sms_client_handle_type *ph_sms);
int (*qser_sms_client_deinit)(sms_client_handle_type h_sms);
int (*qser_sms_send_sms)(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info);
int (*qser_sms_addrxmsghandler)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr);
int (*qser_sms_deletefromstorage)(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage);
int (*qser_sms_getsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *set_sca_cfg);
int (*qser_sms_setsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg);
void qser_sms_handler(QSER_SMS_MsgRef msgRef, void* contextPtr) {
printf("[%s-%d] sms handler, msgRef->sms_data = %s\n", __FUNCTION__, __LINE__, msgRef->sms_data);
}
bool isNumeric(char *phnum) {
int length = strlen(phnum);
if (length == 0) {
return false;
}
if (phnum[0] != '+' && (phnum[0] < '0' || phnum[0] > '9')) {
return false;
}
if (phnum[0] == '+' && length < 3) {
return false;
}
for (int i = 1; i < length; i++) {
if (phnum[i] < '0' || phnum[i] > '9') {
return false;
}
}
return true;
}
//以下示例默认为所有API 执行都成功的情况下,依次执行后续API
int main(int argc, char *argv[])
{
int ret = 0;
//char phnum[SMS_BUF]={0};
//const char *lynq_libpath_sms = "/lib/liblynq-qser-sms.so";
const char *lynq_libpath_sms = "/lib/liblynq_lib.so";
void *dlHandle_sms = dlopen(lynq_libpath_sms, RTLD_NOW);
if (dlHandle_sms == NULL)
{
printf("dlopen dlHandle_sms failed: %s\n", dlerror());
exit(EXIT_FAILURE);
}
if(argc != 2 || !isNumeric(argv[1]))
{
printf("[%s][%d] please input correct phnum\n",__FUNCTION__,__LINE__);
exit(1);
}
qser_sms_client_init = (int(*)(sms_client_handle_type *ph_sms))dlsym(dlHandle_sms,"qser_sms_client_init");
if(NULL != qser_sms_client_init)
{
ret = qser_sms_client_init(&ph_sms);
if(ret == 0)
{
printf("Run qser_sms_client_init\n");
}else{
printf("qser_sim_client_init error\n");
}
}else{
printf("qser_sim_client_init dlsym error\n");
}
sleep(2);
qser_sms_addrxmsghandler = (int(*)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr))dlsym(dlHandle_sms,"qser_sms_addrxmsghandler");
if(NULL != qser_sms_addrxmsghandler)
{
ret = qser_sms_addrxmsghandler(qser_sms_handler, NULL);
if(ret == 0)
{
printf("qser_sms_addrxmsghandler success");
}else{
printf("qser_sms_addrxmsghandler error, ret = %d\n", ret);
}
}else{
printf("qser_sms_addrxmsghandler dlsym error\n");
}
QSER_sms_service_center_cfg_t get_sca_cfg;
qser_sms_getsmscenteraddress = (int (*)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg))dlsym(dlHandle_sms,"qser_sms_getsmscenteraddress");
if(NULL != qser_sms_getsmscenteraddress)
{
ret = qser_sms_getsmscenteraddress(h_sms, &get_sca_cfg);
if(ret == 0)
{
printf("get smsc success,service_center_addr = %s\n",get_sca_cfg.service_center_addr);
}else{
printf("get smsc error, ret = %d\n", ret);
}
}else{
printf("qser_sms_getsmscenteraddress dlsym error\n");
}
sleep(1);
QSER_sms_service_center_cfg_t set_sca_cfg;
strncpy(set_sca_cfg.service_center_addr, "+8613800280500", 14);//smsc +8613800280500成都号码 +8613800230500黑龙江
qser_sms_setsmscenteraddress = (int (*)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *set_sca_cfg))dlsym(dlHandle_sms,"qser_sms_setsmscenteraddress");
if(NULL != qser_sms_setsmscenteraddress)
{
ret = qser_sms_setsmscenteraddress(h_sms, &set_sca_cfg);
if(ret == 0)
{
printf("set smsc success");
}else{
printf("set smsc error, ret = %d\n", ret);
}
}else{
printf("qser_sms_setsmscenteraddress dlsym error\n");
}
//再次查询是否设置成功
sleep(1);
qser_sms_getsmscenteraddress = (int (*)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg))dlsym(dlHandle_sms,"qser_sms_getsmscenteraddress");
if(NULL != qser_sms_getsmscenteraddress)
{
ret = qser_sms_getsmscenteraddress(h_sms, &get_sca_cfg);
if(ret == 0)
{
printf("get smsc success,service_center_addr = %s\n",get_sca_cfg.service_center_addr);
}else{
printf("get smsc error, ret = %d\n", ret);
}
}else{
printf("qser_sms_getsmscenteraddress dlsym error\n");
}
//test 7bit
//char telephony_num[SMS_BUF] = {};
char msg[MSG_BUF] = {};
QSER_sms_info_t pt_sms_info;
//sprintf(telephony_num,"18981904623");//请用户务必替换此号码,随意向运营商发短消息极有可能被封号。
sprintf(msg,"hello");
strncpy(pt_sms_info.src_addr, argv[1], SMS_BUF);
strncpy(pt_sms_info.sms_data, msg, MSG_BUF);
pt_sms_info.format = QSER_SMS_7BIT;
// printf("[%s,%d] src_addr=%s, telephony_num = %s\n",__FUNCTION__,__LINE__, pt_sms_info.src_addr, telephony_num);
printf("[%s,%d] sms_data=%s, msg = %s\n",__FUNCTION__,__LINE__, pt_sms_info.sms_data, msg);
sleep(120);
//test ucs2
//char telephony_num[SMS_BUF] = {};
char msg[MSG_BUF] = {};
QSER_sms_info_t pt_sms_info;
//sprintf(telephony_num,"18981904623");//请用户务必替换此号码,随意向运营商发短消息极有可能被封号。
sprintf(msg,"你好吗");
strncpy(pt_sms_info.src_addr, argv[1], SMS_BUF);
strncpy(pt_sms_info.sms_data, msg, MSG_BUF);
pt_sms_info.format = QSER_SMS_UCS2;
// printf("[%s,%d] src_addr=%s, telephony_num = %s\n",__FUNCTION__,__LINE__, pt_sms_info.src_addr, telephony_num);
printf("[%s,%d] sms_data=%s, msg = %s\n",__FUNCTION__,__LINE__, pt_sms_info.sms_data, msg);
qser_sms_send_sms = (int (*)(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info))dlsym(dlHandle_sms,"qser_sms_send_sms");
if(NULL != qser_sms_send_sms)
{
ret = qser_sms_send_sms(h_sms, &pt_sms_info);
if(ret == 0)
{
printf("send sms success");
}else{
printf("send sms error, ret = %d\n", ret);
}
}else{
printf("qser_sms_send_sms dlsym error\n");
}
sleep(120);//在此期间向模组发送短消息,即可触发“接受新短消息事件”。
qser_sms_client_deinit = (int (*)(sms_client_handle_type h_sms))dlsym(dlHandle_sms,"qser_sms_client_deinit");
if(NULL != qser_sms_client_deinit)
{
ret = qser_sms_client_deinit(h_sms);
if(ret == 0)
{
printf("sms deinit success");
}else{
printf("sms deinit error, ret = %d\n", ret);
}
}else{
printf("qser_sms_client_deinit dlsym error\n");
}
}
#else
void qser_sms_handler(QSER_SMS_MsgRef msgRef, void* contextPtr) {
printf("[%s-%d] sms handler, msgRef->sms_data = %s\n", __FUNCTION__, __LINE__, msgRef->sms_data);
}
int main(int argc, char *argv[])
{
char operator[10];
char serNum[50] = {0};
char phonenumter[20] ={0};
int opt;
int ret, uToken;
sms_client_handle_type handle = -1;
QSER_sms_info_t test_sms_info;
QSER_sms_service_center_cfg_t test_sca_cfg;
QSER_sms_storage_info_t test_sms_storage;
while(1)
{
printf("=========sms main=========\n"
"\t0 exit\n"
"\t1 sms init\n"
"\t2 send text sms\n"
"\t3 wait receive new sms\n"
"\t4 send PDU sms\n"
"\t5 //list sms\n"
"\t6 delete sms\n"
"\t7 query service number\n"
"\t8 set service number\n"
"\t9 deinit sms\n"
"operator: >> ");
fgets(operator, sizeof(operator), stdin);
fflush(stdin);
opt = atoi(operator);
switch (opt)
{
case 0:
printf("main exit\n");
return 0;
case 1:
{
ret = qser_sms_client_init(&handle);
if(ret == 0)
{
printf("Run qser_sms_client_init\n");
}else{
printf("qser_sim_client_init error\n");
}
sleep(2);
//printf("test>>: handle = %d\n",handle);
break;
}
case 2:
{
memset(&test_sms_info, 0x00, sizeof(QSER_sms_info_t));
char *tmp = "all man hello world";
char *num = "+8618981904623";//目的手机卡
int len = strlen(tmp);
int num_len = strlen(num);
test_sms_info.format = 0;
test_sms_info.storage = 1; //默认 ME
//test_sms_info.sms_data_len = len;
memcpy(test_sms_info.sms_data, tmp, len);
memcpy(test_sms_info.src_addr, num, num_len);
qser_sms_send_sms(handle, &test_sms_info);
break;
}
case 3:
qser_sms_addrxmsghandler(qser_sms_handler, NULL);
break;
case 4:
{
memset(&test_sms_info, 0x00, sizeof(QSER_sms_info_t));
char *tmp = "你好";
char *num = "+8618981904623";//目的手机卡
int len = strlen(tmp);
int num_len = strlen(num);
test_sms_info.format = 2;
test_sms_info.storage = 1; //默认 ME
//test_sms_info.sms_data_len = len;
memcpy(test_sms_info.sms_data, tmp, len);
memcpy(test_sms_info.src_addr, num, num_len);
qser_sms_send_sms(handle, &test_sms_info);
break;
}
break;
case 5:
{
printf("No such interface \n");
/*
memset(operator, 0x00, sizeof(operator));
printf("please input index (0~50): \n");
fgets(operator, sizeof(operator), stdin);
fflush(stdin);
opt = atoi(operator);
*/
break;
}
case 6:
{
memset(&test_sms_storage, 0x00, sizeof(QSER_sms_storage_info_t));
memset(operator,0x00, sizeof(operator));
printf("please input index \n");
fgets(operator, sizeof(operator), stdin);
fflush(stdin);
opt = atoi(operator);
int t_index = opt;
memset(operator,0x00, sizeof(operator));
printf("please input Storage area\n"
"\t 0 : Message store to UIM(SIM) \n"
"\t 1 : Message store to NV(ME) \n"
"\t default : store to NV(ME) \n");
fgets(operator, sizeof(operator), stdin);
fflush(stdin);
opt = atoi(operator);
if (opt == 0 || opt == 1)
{
test_sms_storage.storage = opt;
}
else
{
test_sms_storage.storage = 1;
}
test_sms_storage.storage_idx = t_index;
qser_sms_deletefromstorage(handle, &test_sms_storage);
break;
}
case 7:
{
memset(&test_sca_cfg, 0x00, sizeof(QSER_sms_service_center_cfg_t));
ret = qser_sms_getsmscenteraddress(handle,&test_sca_cfg);
if(!ret)
printf("get_smsc:%s\n", test_sca_cfg.service_center_addr);
break;
}
case 8:
{
memset(&test_sca_cfg, 0x00, sizeof(QSER_sms_service_center_cfg_t));
char *num = "+8613800280500";//成都移动中心号码不用更改(根据情况可以写死值或者动态获取)
int len = strlen(num);
memcpy(test_sca_cfg.service_center_addr, num, len);
ret= qser_sms_setsmscenteraddress(handle, &test_sca_cfg);
break;
}
case 9:
qser_sms_client_deinit(handle);
break;
default:
break;
}
}
return 0;
}
#endif