b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame^] | 1 | #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"
|
| 12 |
|
| 13 |
|
| 14 | #define SMS_BUF 64
|
| 15 | #define MSG_BUF 100
|
| 16 |
|
| 17 | int flag_init = 0;
|
| 18 |
|
| 19 | typedef uint32_t sim_client_handle_type;
|
| 20 | sms_client_handle_type ph_sms = 2022;
|
| 21 | sms_client_handle_type h_sms = 2022;
|
| 22 |
|
| 23 |
|
| 24 | int (*qser_sms_client_init)(sms_client_handle_type *ph_sms);
|
| 25 | int (*qser_sms_client_deinit)(sms_client_handle_type h_sms);
|
| 26 | int (*qser_sms_send_sms)(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info);
|
| 27 | int (*qser_sms_addrxmsghandler)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr);
|
| 28 | int (*qser_sms_deletefromstorage)(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage);
|
| 29 | int (*qser_sms_getsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *set_sca_cfg);
|
| 30 | //int (*qser_sms_setsmscenteraddress)(sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg);
|
| 31 |
|
| 32 | void qser_sms_handler(QSER_SMS_MsgRef msgRef, void* contextPtr) {
|
| 33 | printf("[%s-%d] sms handler, msgRef->sms_data = %s,addr =%s\n", __FUNCTION__, __LINE__, msgRef->sms_data, msgRef->src_addr);
|
| 34 | }
|
| 35 |
|
| 36 | bool isNumeric(char *phnum) {
|
| 37 | int length = strlen(phnum);
|
| 38 |
|
| 39 | if (length == 0) {
|
| 40 | return false;
|
| 41 | }
|
| 42 |
|
| 43 | if (phnum[0] != '+' && (phnum[0] < '0' || phnum[0] > '9')) {
|
| 44 | return false;
|
| 45 | }
|
| 46 |
|
| 47 | if (phnum[0] == '+' && length < 3) {
|
| 48 | return false;
|
| 49 | }
|
| 50 |
|
| 51 | for (int i = 1; i < length; i++) {
|
| 52 | if (phnum[i] < '0' || phnum[i] > '9') {
|
| 53 | return false;
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 | return true;
|
| 58 | }
|
| 59 |
|
| 60 | //以下示例默认为所有API 执行都æˆåŠŸçš„æƒ…å†µä¸‹ï¼Œä¾æ¬¡æ‰§è¡ŒåŽç»API
|
| 61 | int main(int argc, char *argv[])
|
| 62 | {
|
| 63 | int ret = 0;
|
| 64 | //char phnum[SMS_BUF]={0};
|
| 65 |
|
| 66 | const char *lynq_libpath_sms = "/lib/liblynq-qser-sms.so";
|
| 67 | void *dlHandle_sms = dlopen(lynq_libpath_sms, RTLD_NOW);
|
| 68 |
|
| 69 | if (dlHandle_sms == NULL)
|
| 70 | {
|
| 71 | printf("dlopen dlHandle_sms failed: %s\n", dlerror());
|
| 72 | exit(EXIT_FAILURE);
|
| 73 | }
|
| 74 |
|
| 75 | if(argc != 2 || !isNumeric(argv[1]))
|
| 76 | {
|
| 77 | printf("[%s][%d] please input correct phnum\n",__FUNCTION__,__LINE__);
|
| 78 | exit(1);
|
| 79 | }
|
| 80 |
|
| 81 | qser_sms_client_init = (int(*)(sms_client_handle_type *ph_sms))dlsym(dlHandle_sms,"qser_sms_client_init");
|
| 82 | if(NULL != qser_sms_client_init)
|
| 83 | {
|
| 84 | ret = qser_sms_client_init(&ph_sms);
|
| 85 | if(ret == 0)
|
| 86 | {
|
| 87 | printf("Run qser_sms_client_init\n");
|
| 88 | }else{
|
| 89 | printf("qser_sim_client_init error\n");
|
| 90 | }
|
| 91 | }else{
|
| 92 | printf("qser_sim_client_init dlsym error\n");
|
| 93 | }
|
| 94 |
|
| 95 | sleep(2);
|
| 96 |
|
| 97 | qser_sms_addrxmsghandler = (int(*)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr))dlsym(dlHandle_sms,"qser_sms_addrxmsghandler");
|
| 98 |
|
| 99 | if(NULL != qser_sms_addrxmsghandler)
|
| 100 | {
|
| 101 | ret = qser_sms_addrxmsghandler(qser_sms_handler, NULL);
|
| 102 | if(ret == 0)
|
| 103 | {
|
| 104 | printf("qser_sms_addrxmsghandler success");
|
| 105 | }else{
|
| 106 | printf("qser_sms_addrxmsghandler error, ret = %d\n", ret);
|
| 107 | }
|
| 108 | }else{
|
| 109 | printf("qser_sms_addrxmsghandler dlsym error\n");
|
| 110 | }
|
| 111 |
|
| 112 | QSER_sms_service_center_cfg_t get_sca_cfg;
|
| 113 | 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");
|
| 114 | if(NULL != qser_sms_getsmscenteraddress)
|
| 115 | {
|
| 116 | ret = qser_sms_getsmscenteraddress(h_sms, &get_sca_cfg);
|
| 117 | if(ret == 0)
|
| 118 | {
|
| 119 | printf("get smsc success,service_center_addr = %s\n",get_sca_cfg.service_center_addr);
|
| 120 | }else{
|
| 121 | printf("get smsc error, ret = %d\n", ret);
|
| 122 | }
|
| 123 | }else{
|
| 124 | printf("qser_sms_getsmscenteraddress dlsym error\n");
|
| 125 | }
|
| 126 | sleep(1);
|
| 127 | #if 0
|
| 128 | QSER_sms_service_center_cfg_t set_sca_cfg;
|
| 129 | memset(set_sca_cfg.service_center_addr, 0, sizeof(set_sca_cfg.service_center_addr));
|
| 130 | strncpy(set_sca_cfg.service_center_addr, "+8613800230500", 14);//smsc need userchange
|
| 131 | 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");
|
| 132 | if(NULL != qser_sms_setsmscenteraddress)
|
| 133 | {
|
| 134 | ret = qser_sms_setsmscenteraddress(h_sms, &set_sca_cfg);
|
| 135 | if(ret == 0)
|
| 136 | {
|
| 137 | printf("set smsc success");
|
| 138 | }else{
|
| 139 | printf("set smsc error, ret = %d\n", ret);
|
| 140 | }
|
| 141 | }else{
|
| 142 | printf("qser_sms_setsmscenteraddress dlsym error\n");
|
| 143 | }
|
| 144 | #endif
|
| 145 | // char telephony_num[SMS_BUF] = {};
|
| 146 | char msg[MSG_BUF] = {};
|
| 147 | QSER_sms_info_t pt_sms_info;
|
| 148 | // sprintf(telephony_num,"10086");//è¯·ç”¨æˆ·åŠ¡å¿…æ›¿æ¢æ¤å·ç ï¼Œéšæ„å‘è¿è¥å•†å‘çŸæ¶ˆæ¯æžæœ‰å¯èƒ½è¢«å°å·ã€‚
|
| 149 | sprintf(msg,"\"Chello worrld-7bit-mr!./\"");
|
| 150 | strncpy(pt_sms_info.src_addr, argv[1], SMS_BUF);
|
| 151 | strncpy(pt_sms_info.sms_data, msg, MSG_BUF);
|
| 152 | pt_sms_info.format = QSER_SMS_7BIT;
|
| 153 | // printf("[%s,%d] src_addr=%s, telephony_num = %s\n",__FUNCTION__,__LINE__, pt_sms_info.src_addr, telephony_num);
|
| 154 | printf("[%s,%d] sms_data=%s, msg = %s\n",__FUNCTION__,__LINE__, pt_sms_info.sms_data, msg);
|
| 155 |
|
| 156 | 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");
|
| 157 | if(NULL != qser_sms_send_sms)
|
| 158 | {
|
| 159 | ret = qser_sms_send_sms(h_sms, &pt_sms_info);
|
| 160 | if(ret == 0)
|
| 161 | {
|
| 162 | printf("send sms success");
|
| 163 | }else{
|
| 164 | printf("send sms error, ret = %d\n", ret);
|
| 165 | }
|
| 166 | }else{
|
| 167 | printf("qser_sms_send_sms dlsym error\n");
|
| 168 | }
|
| 169 |
|
| 170 | sleep(120);//åœ¨æ¤æœŸé—´å‘模组å‘é€çŸæ¶ˆæ¯ï¼Œå³å¯è§¦å‘â€œæŽ¥å—æ–°çŸæ¶ˆæ¯äº‹ä»¶â€ã€‚
|
| 171 | qser_sms_client_deinit = (int (*)(sms_client_handle_type h_sms))dlsym(dlHandle_sms,"qser_sms_client_deinit");
|
| 172 | if(NULL != qser_sms_client_deinit)
|
| 173 | {
|
| 174 | ret = qser_sms_client_deinit(h_sms);
|
| 175 | if(ret == 0)
|
| 176 | {
|
| 177 | printf("sms deinit success");
|
| 178 | }else{
|
| 179 | printf("sms deinit error, ret = %d\n", ret);
|
| 180 | }
|
| 181 | }else{
|
| 182 | printf("qser_sms_client_deinit dlsym error\n");
|
| 183 | }
|
| 184 |
|
| 185 | }
|
| 186 |
|