Merge "[Bugfix][T106BUG-197][T106BUG-199][T106BUG-200][T106BUG-201] fix qser sms demo error"
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-sms-demo/files/lynq-qser-sms-demo.cpp b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-sms-demo/files/lynq-qser-sms-demo.cpp
index 16be058..7e4c03c 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-sms-demo/files/lynq-qser-sms-demo.cpp
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-qser-sms-demo/files/lynq-qser-sms-demo.cpp
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <dlfcn.h>
#include <stdint.h>
+#include <ctype.h>
#include"lynq-qser-sms-demo.h"
@@ -28,260 +29,156 @@
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);
-
-typedef struct
-{
- int cmdIdx;
- const char *funcName;
-} st_api_test_case;
-
-//for server test
-st_api_test_case at_api_testcases[] =
-{
- {0, "qser_sms_client_init"},
- {1, "qser_sms_client_deinit"},
- {2, "qser_sms_send_sms"},
- {3, "qser_sms_addrxmsghandler"},
- {4, "qser_sms_deletefromstorage"},
- {5, "qser_sms_getsmscenteraddress"},
- {6, "qser_sms_setsmscenteraddress"},
- {-1, NULL}
-};
-
-void print_help(void)
-{
- int i;
- printf("Supported test cases:\n");
- for(i = 0; ; i++)
- {
- if(at_api_testcases[i].cmdIdx == -1)
- {
- break;
- }
- printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
- }
-}
-
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 cmdIdx = 0;
int ret = 0;
-
+ //char phnum[SMS_BUF]={0};
+
const char *lynq_libpath_sms = "/lib/liblynq-qser-sms.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);
}
- print_help();
- while(1)
+ if(argc != 2 || !isNumeric(argv[1]))
{
- printf("\nplease input cmd index(-1 exit): ");
- scanf("%d", &cmdIdx);
- if(cmdIdx == -1)
- {
- break;
- }
-
- switch(cmdIdx)
- {
- //"qser_sms_client_init"
- case 0:
- {
- if(flag_init == 1)
- {
- printf("init is already\n");
- break;
- }
- else{
- //int token;
- printf("input token\n");
- //scanf("%d", &token);
-
- 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");
- flag_init = 1;
- }else{
- printf("qser_sim_client_init error\n");
- }
- }else{
- printf("qser_sim_client_init dlsym error\n");
- }
- break;
- }
- }
- //"qser_sms_client_deinit"
- case 1:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- 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");
- }
- }
- break;
- }
- //"qser_sms_send_sms"
- case 2:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- char telephony_num[SMS_BUF] = {};
- char msg[MSG_BUF] = {};
- QSER_sms_info_t pt_sms_info;
- sprintf(telephony_num,"10086");
- sprintf(msg,"hello");
- strncpy(pt_sms_info.src_addr, telephony_num, SMS_BUF);
- strncpy(pt_sms_info.sms_data, msg, MSG_BUF);
- pt_sms_info.format = QSER_SMS_8BIT;
- 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");
- }
- }
- break;
- }
- //"qser_sms_addrxmsghandler"
- case 3:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
-
- 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");
- }
- }
- break;
- }
- //"qser_sms_deletefromstorage"
- case 4:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- QSER_sms_storage_info_t pt_sms_storage;
- pt_sms_storage.storage_idx = 1;
- qser_sms_deletefromstorage = (int (*)(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage))dlsym(dlHandle_sms,"qser_sms_deletefromstorage");
- if(NULL != qser_sms_deletefromstorage)
- {
- ret = qser_sms_deletefromstorage(h_sms, &pt_sms_storage);
- if(ret == 0)
- {
- printf("ret= %d\n",ret);
- }else{
- printf("del sms error, ret = %d\n", ret);
- }
- }else{
- printf("qser_sms_deletefromstorage dlsym error\n");
- }
- }
- break;
- }
- //"qser_sms_getsmscenteraddress"
- case 5:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- 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");
- }
- }
- break;
- }
- //"qser_sms_setsmscenteraddress"
- case 6:
- {
- if(flag_init == 0){
- printf("must init first\n");
- }
- else{
- QSER_sms_service_center_cfg_t set_sca_cfg;
- strncpy(set_sca_cfg.service_center_addr, "+8613800230500", 14);
- 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");
- }
- }
- break;
- }
- default:
- print_help();
- break;
- }
+ printf("[%s][%d] please input correct phnum\n",__FUNCTION__,__LINE__);
+ exit(1);
}
- return 0;
+ 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, "+8613800230500", 14);//smsc ÊǸù¾Ý²»Í¬ÔËÓªÉÌ£¬²»Í¬¿¨À´ÅäÖõÄ
+ 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");
+ }
+
+ // char telephony_num[SMS_BUF] = {};
+ char msg[MSG_BUF] = {};
+ QSER_sms_info_t pt_sms_info;
+ // sprintf(telephony_num,"10086");//è¯·ç”¨æˆ·åŠ¡å¿…æ›¿æ¢æ¤å·ç ï¼Œéšæ„å‘è¿è¥å•†å‘çŸæ¶ˆæ¯æžæœ‰å¯èƒ½è¢«å°å·ã€‚
+ 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_8BIT;
+ // 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");
+ }
+
}
+