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"
|
r.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 12 | #include "mbtk_log.h"
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 13 |
|
| 14 |
|
| 15 | #define SMS_BUF 64
|
| 16 | #define MSG_BUF 100
|
| 17 |
|
| 18 | int flag_init = 0;
|
| 19 |
|
| 20 | typedef uint32_t sim_client_handle_type;
|
r.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 21 | //sms_client_handle_type ph_sms = 2022;
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 22 | sms_client_handle_type h_sms = 2022;
|
| 23 |
|
| 24 |
|
r.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 25 | int (*qser_sms_client_init)(sms_client_handle_type *h_sms);
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 26 | int (*qser_sms_client_deinit)(sms_client_handle_type h_sms);
|
| 27 | int (*qser_sms_send_sms)(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info);
|
| 28 | int (*qser_sms_addrxmsghandler)(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr);
|
| 29 | int (*qser_sms_deletefromstorage)(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage);
|
| 30 | int (*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 |
|
| 33 | void 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 |
|
| 37 | bool 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
|
| 62 | int main(int argc, char *argv[])
|
| 63 | {
|
| 64 | int ret = 0;
|
| 65 | //char phnum[SMS_BUF]={0};
|
r.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 66 | mbtk_log_init("radio", "MBTK");
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 67 |
|
| 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.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 83 | qser_sms_client_init = (int(*)(sms_client_handle_type *h_sms))dlsym(dlHandle_sms,"qser_sms_client_init");
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 84 | if(NULL != qser_sms_client_init)
|
| 85 | {
|
r.xiao | a2527d1 | 2024-04-04 01:47:40 -0700 | [diff] [blame^] | 86 | ret = qser_sms_client_init(&h_sms);
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 87 | 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 |
|