blob: dc8f9af397b6491b0d2d7cfed54133cd8ab1c469 [file] [log] [blame]
b.liu8583dce2024-04-03 13:30:08 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <pthread.h>
6#include <unistd.h>
7#include <dlfcn.h>
8#include <stdint.h>
9#include <ctype.h>
10
11#include"lynq-qser-sms-demo.h"
r.xiaoa2527d12024-04-04 01:47:40 -070012#include "mbtk_log.h"
b.liu8583dce2024-04-03 13:30:08 +080013
14
15#define SMS_BUF 64
16#define MSG_BUF 100
17
18int flag_init = 0;
19
20typedef uint32_t sim_client_handle_type;
r.xiaoa2527d12024-04-04 01:47:40 -070021//sms_client_handle_type ph_sms = 2022;
b.liu8583dce2024-04-03 13:30:08 +080022sms_client_handle_type h_sms = 2022;
23
24
r.xiaoa2527d12024-04-04 01:47:40 -070025int (*qser_sms_client_init)(sms_client_handle_type *h_sms);
b.liu8583dce2024-04-03 13:30:08 +080026int (*qser_sms_client_deinit)(sms_client_handle_type h_sms);
27int (*qser_sms_send_sms)(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info);
28int (*qser_sms_addrxmsghandler)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr);
29int (*qser_sms_deletefromstorage)(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage);
30int (*qser_sms_getsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *set_sca_cfg);
31//int (*qser_sms_setsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg);
32
33void qser_sms_handler(QSER_SMS_MsgRef msgRef, void* contextPtr) {
34 printf("[%s-%d] sms handler, msgRef->sms_data = %s,addr =%s\n", __FUNCTION__, __LINE__, msgRef->sms_data, msgRef->src_addr);
35}
36
37bool isNumeric(char *phnum) {
38 int length = strlen(phnum);
39
40 if (length == 0) {
41 return false;
42 }
43
44 if (phnum[0] != '+' && (phnum[0] < '0' || phnum[0] > '9')) {
45 return false;
46 }
47
48 if (phnum[0] == '+' && length < 3) {
49 return false;
50 }
51
52 for (int i = 1; i < length; i++) {
53 if (phnum[i] < '0' || phnum[i] > '9') {
54 return false;
55 }
56 }
57
58 return true;
59}
60
61//以下示例默认为所有API 执行都成功的情况下,依次执行后续API
62int main(int argc, char *argv[])
63{
64 int ret = 0;
65 //char phnum[SMS_BUF]={0};
r.xiaoa2527d12024-04-04 01:47:40 -070066 mbtk_log_init("radio", "MBTK");
b.liu8583dce2024-04-03 13:30:08 +080067
68 const char *lynq_libpath_sms = "/lib/liblynq-qser-sms.so";
69 void *dlHandle_sms = dlopen(lynq_libpath_sms, RTLD_NOW);
70
71 if (dlHandle_sms == NULL)
72 {
73 printf("dlopen dlHandle_sms failed: %s\n", dlerror());
74 exit(EXIT_FAILURE);
75 }
76
77 if(argc != 2 || !isNumeric(argv[1]))
78 {
79 printf("[%s][%d] please input correct phnum\n",__FUNCTION__,__LINE__);
80 exit(1);
81 }
82
r.xiaoa2527d12024-04-04 01:47:40 -070083 qser_sms_client_init = (int(*)(sms_client_handle_type *h_sms))dlsym(dlHandle_sms,"qser_sms_client_init");
b.liu8583dce2024-04-03 13:30:08 +080084 if(NULL != qser_sms_client_init)
85 {
r.xiaoa2527d12024-04-04 01:47:40 -070086 ret = qser_sms_client_init(&h_sms);
b.liu8583dce2024-04-03 13:30:08 +080087 if(ret == 0)
88 {
89 printf("Run qser_sms_client_init\n");
90 }else{
91 printf("qser_sim_client_init error\n");
92 }
93 }else{
94 printf("qser_sim_client_init dlsym error\n");
95 }
96
97 sleep(2);
98
99 qser_sms_addrxmsghandler = (int(*)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr))dlsym(dlHandle_sms,"qser_sms_addrxmsghandler");
100
101 if(NULL != qser_sms_addrxmsghandler)
102 {
103 ret = qser_sms_addrxmsghandler(qser_sms_handler, NULL);
104 if(ret == 0)
105 {
106 printf("qser_sms_addrxmsghandler success");
107 }else{
108 printf("qser_sms_addrxmsghandler error, ret = %d\n", ret);
109 }
110 }else{
111 printf("qser_sms_addrxmsghandler dlsym error\n");
112 }
113
114 QSER_sms_service_center_cfg_t get_sca_cfg;
115 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");
116 if(NULL != qser_sms_getsmscenteraddress)
117 {
118 ret = qser_sms_getsmscenteraddress(h_sms, &get_sca_cfg);
119 if(ret == 0)
120 {
121 printf("get smsc success,service_center_addr = %s\n",get_sca_cfg.service_center_addr);
122 }else{
123 printf("get smsc error, ret = %d\n", ret);
124 }
125 }else{
126 printf("qser_sms_getsmscenteraddress dlsym error\n");
127 }
128 sleep(1);
129#if 0
130 QSER_sms_service_center_cfg_t set_sca_cfg;
131 memset(set_sca_cfg.service_center_addr, 0, sizeof(set_sca_cfg.service_center_addr));
132 strncpy(set_sca_cfg.service_center_addr, "+8613800230500", 14);//smsc need userchange
133 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");
134 if(NULL != qser_sms_setsmscenteraddress)
135 {
136 ret = qser_sms_setsmscenteraddress(h_sms, &set_sca_cfg);
137 if(ret == 0)
138 {
139 printf("set smsc success");
140 }else{
141 printf("set smsc error, ret = %d\n", ret);
142 }
143 }else{
144 printf("qser_sms_setsmscenteraddress dlsym error\n");
145 }
146#endif
147 // char telephony_num[SMS_BUF] = {};
148 char msg[MSG_BUF] = {};
149 QSER_sms_info_t pt_sms_info;
150 // sprintf(telephony_num,"10086");//请用户务必替换此号码,随意向运营商发短消息极有可能被封号。
151 sprintf(msg,"\"Chello worrld-7bit-mr!./\"");
152 strncpy(pt_sms_info.src_addr, argv[1], SMS_BUF);
153 strncpy(pt_sms_info.sms_data, msg, MSG_BUF);
154 pt_sms_info.format = QSER_SMS_7BIT;
155 // printf("[%s,%d] src_addr=%s, telephony_num = %s\n",__FUNCTION__,__LINE__, pt_sms_info.src_addr, telephony_num);
156 printf("[%s,%d] sms_data=%s, msg = %s\n",__FUNCTION__,__LINE__, pt_sms_info.sms_data, msg);
157
158 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");
159 if(NULL != qser_sms_send_sms)
160 {
161 ret = qser_sms_send_sms(h_sms, &pt_sms_info);
162 if(ret == 0)
163 {
164 printf("send sms success");
165 }else{
166 printf("send sms error, ret = %d\n", ret);
167 }
168 }else{
169 printf("qser_sms_send_sms dlsym error\n");
170 }
171
172 sleep(120);//在此期间向模组发送短消息,即可触发“接受新短消息事件”。
173 qser_sms_client_deinit = (int (*)(sms_client_handle_type h_sms))dlsym(dlHandle_sms,"qser_sms_client_deinit");
174 if(NULL != qser_sms_client_deinit)
175 {
176 ret = qser_sms_client_deinit(h_sms);
177 if(ret == 0)
178 {
179 printf("sms deinit success");
180 }else{
181 printf("sms deinit error, ret = %d\n", ret);
182 }
183 }else{
184 printf("qser_sms_client_deinit dlsym error\n");
185 }
186
187}
188