b.liu | 1c74d69 | 2024-08-14 17:43:59 +0800 | [diff] [blame^] | 1 | //#include "lynq/lynq_sms_api.h"
|
| 2 | #include "mbtk_info_api.h"
|
| 3 | #include "mbtk_pdu_sms.h"
|
| 4 | #include "ql/ql_sms.h"
|
| 5 |
|
| 6 |
|
| 7 | #include <stdio.h>
|
| 8 | #include <stdlib.h>
|
| 9 |
|
| 10 |
|
| 11 | #define TELEPHONE_NUM_MAX 16
|
| 12 | #define MSM_NUMBER_MAX 1024+1
|
| 13 | #define RES_NUM_MIN 128
|
| 14 |
|
| 15 | #define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2"))
|
| 16 |
|
| 17 | static mbtk_info_handle_t* info_handle = NULL;
|
| 18 | static char center_address[15] = {0};
|
| 19 |
|
| 20 |
|
| 21 | // 编码后短信
|
| 22 |
|
| 23 | #if 0
|
| 24 | struct PDUS {
|
| 25 | unsigned int count;
|
| 26 | char **PDU;
|
| 27 | };
|
| 28 | #endif
|
| 29 |
|
| 30 | void lynq_sms_state_change_cb(const void* data, int data_len)
|
| 31 | {
|
| 32 | LOGV("sms_state_change_cb()----------start\n");
|
| 33 | uint8 *ptr = (uint8*)data;
|
| 34 | printf("3sms_state_change_cb() : %s\n", ptr);
|
| 35 |
|
| 36 | struct SMS_Struct s = PDUDecoding(ptr);
|
| 37 | printf("服务中心地址: %s\n", s.SCA);
|
| 38 | printf("发送方地址: %s\n", s.OA);
|
| 39 | printf("服务中心时间戳: %s\n", s.SCTS);
|
| 40 | printf("消息内容: %s\n", s.UD);
|
| 41 | printf("数据编码方案: %s\n", DSC_to_msg(s.DCS));
|
| 42 | }
|
| 43 |
|
| 44 |
|
| 45 | QL_SMS_ERROR_CODE ql_sms_init()
|
| 46 | {
|
| 47 | if(info_handle == NULL)
|
| 48 | {
|
| 49 | info_handle = mbtk_info_handle_get();
|
| 50 | if(info_handle)
|
| 51 | {
|
| 52 | printf("creat info_handle is success\n");
|
| 53 | }
|
| 54 | else{
|
| 55 | printf("creat info_handle is fail\n");
|
| 56 | return QL_SMS_GENERIC_FAILURE;
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | return QL_SMS_SUCCESS;
|
| 61 | }
|
| 62 |
|
| 63 |
|
| 64 | QL_SMS_ERROR_CODE ql_sms_release()
|
| 65 | {
|
| 66 | int ret = QL_SMS_SUCCESS;
|
| 67 | if(info_handle)
|
| 68 | {
|
| 69 | ret = mbtk_info_handle_free(&info_handle);
|
| 70 | }
|
| 71 | else
|
| 72 | {
|
| 73 | ret = QL_SMS_GENERIC_FAILURE;
|
| 74 | }
|
| 75 |
|
| 76 | return ret;
|
| 77 | }
|
| 78 |
|
| 79 |
|
| 80 | /*
|
| 81 | *AT+CMGS="10086", CMGS TEST // Send a SMS
|
| 82 | > CMGS TEST
|
| 83 | +CMGS: 17
|
| 84 | OK
|
| 85 | */
|
| 86 | /*
|
| 87 | int charset: send sms mode
|
| 88 | 0:pdu, 1:text
|
| 89 |
|
| 90 | */
|
| 91 | //当state 设置为 0(pdu)模式时,telephony_num应该设置为pud 数据大小的长度;msg:为pud 数据
|
| 92 |
|
| 93 | QL_SMS_ERROR_CODE ql_sms_send_pdu_msg(uint8_t *phone_num,uint8_t *data,int sms_type)
|
| 94 | {
|
| 95 | if(info_handle == NULL || phone_num == NULL || data == NULL)
|
| 96 | {
|
| 97 | return -1;
|
| 98 | }
|
| 99 |
|
| 100 | char cmgs[MSM_NUMBER_MAX] = {0};
|
| 101 | char resp[RES_NUM_MIN] = {0};
|
| 102 | char pdu_data[512] = {0};
|
| 103 | char phone_lenth[10] = {0};
|
| 104 | char *p = pdu_data;
|
| 105 | int mode = 0;
|
| 106 | int err = 0;
|
| 107 | int i = 0;
|
| 108 |
|
| 109 | if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
|
| 110 | {
|
| 111 | printf("strlen(telephony_num):%d\n", strlen(phone_num));
|
| 112 | printf("strlen(msg):%d\n", strlen(data));
|
| 113 | return -1;
|
| 114 | }
|
| 115 |
|
| 116 | memset(center_address, 0, sizeof(center_address));
|
| 117 | memcpy(center_address, "+8613800280500", strlen("+8613800280500"));
|
| 118 |
|
| 119 | printf("phone_num:%s\n", phone_num);
|
| 120 | printf("center_address:%s\n", center_address);
|
| 121 | printf("data:%s\n", data);
|
| 122 |
|
| 123 |
|
| 124 | mode = 0; // PDU
|
| 125 |
|
| 126 | char* pdu = NULL;
|
| 127 | char* smsc = SCAEncoding(center_address);
|
| 128 | struct PDUS *pdus = PDUEncoding(center_address,phone_num, data, NULL);
|
| 129 |
|
| 130 | for (i = 0; i < pdus->count; i++) {
|
| 131 | printf("第 %d 条:\n", i + 1);
|
| 132 | printf("%s\n", pdus->PDU[i]);
|
| 133 | pdu = pdus->PDU[i];
|
| 134 | }
|
| 135 |
|
| 136 | sprintf(p, "%s",smsc);
|
| 137 | printf("pdu_data:%s\n", pdu_data);
|
| 138 | sprintf(p+strlen(p), "%s", pdu);
|
| 139 | printf("pdu_data:%s\n",pdu_data);
|
| 140 |
|
| 141 |
|
| 142 | err = mbtk_sms_cmgf_set(info_handle, mode);
|
| 143 | if(err) {
|
| 144 | printf("cmgf set error : %d\n", err);
|
| 145 | } else {
|
| 146 | printf("cmgf set success\n");
|
| 147 | }
|
| 148 |
|
| 149 | sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data);
|
| 150 | printf("cmgs:%s\n", cmgs);
|
| 151 |
|
| 152 | memset(resp, 0, sizeof(resp));
|
| 153 |
|
| 154 | err = mbtk_sms_cmgs_set(info_handle, cmgs, resp);
|
| 155 | if(err) {
|
| 156 | printf("Error : %d\n", err);
|
| 157 | return -1;
|
| 158 | } else {
|
| 159 | printf("cmgs set success . resp:%s\n", resp);
|
| 160 | }
|
| 161 |
|
| 162 | return 0;
|
| 163 |
|
| 164 | }
|
| 165 | QL_SMS_ERROR_CODE ql_sms_send_text_msg(uint8_t *phone_num,uint8_t *data,int sms_type)
|
| 166 | {
|
| 167 | if(info_handle == NULL || phone_num == NULL || data == NULL)
|
| 168 | {
|
| 169 | return -1;
|
| 170 | }
|
| 171 |
|
| 172 | char cmgs[MSM_NUMBER_MAX] = {0};
|
| 173 | char resp[RES_NUM_MIN] = {0};
|
| 174 | int mode = 0;
|
| 175 | int err = 0;
|
| 176 | if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0)
|
| 177 | {
|
| 178 | printf("strlen(telephony_num):%d\n", strlen(phone_num));
|
| 179 | printf("strlen(msg):%d\n", strlen(data));
|
| 180 | return -1;
|
| 181 | }
|
| 182 |
|
| 183 | mode = 1; // text
|
| 184 |
|
| 185 | err = mbtk_sms_cmgf_set(info_handle, mode);
|
| 186 | if(err) {
|
| 187 | printf("cmgf set error : %d\n", err);
|
| 188 | } else {
|
| 189 | printf("cmgf set success\n");
|
| 190 | }
|
| 191 |
|
| 192 | sprintf(cmgs,"%s,%s",phone_num, data);
|
| 193 | printf("cmgs:%s\n", cmgs);
|
| 194 |
|
| 195 | /* char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf
|
| 196 | if(ptr != NULL)
|
| 197 | {
|
| 198 | ptr = strstr(cmd, ",");
|
| 199 | ptr++;
|
| 200 | memset(cmgs, 0, sizeof(cmgs));
|
| 201 | memcpy(cmgs, ptr, strlen(ptr));
|
| 202 | printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs));
|
| 203 | }
|
| 204 | */
|
| 205 |
|
| 206 | memset(resp, 0, sizeof(resp));
|
| 207 |
|
| 208 | err = mbtk_sms_cmgs_set(info_handle, cmgs, resp);
|
| 209 | if(err) {
|
| 210 | printf("Error : %d\n", err);
|
| 211 | return -1;
|
| 212 | } else {
|
| 213 | printf("cmgs set success . resp:%s\n", resp);
|
| 214 | }
|
| 215 |
|
| 216 | return 0;
|
| 217 |
|
| 218 | }
|
| 219 |
|
| 220 |
|
| 221 | QL_SMS_ERROR_CODE ql_sms_add_event_handler(QL_SMS_StatusIndMsgHandlerFunc_t handlerPtr, void* contextPtr)
|
| 222 | {
|
| 223 | if(info_handle == NULL)
|
| 224 | {
|
| 225 | return QL_SMS_GENERIC_FAILURE;
|
| 226 | }
|
| 227 |
|
| 228 | int ret = mbtk_sms_cnmi_set(info_handle);
|
| 229 | if(ret)
|
| 230 | {
|
| 231 | printf("set cnmi fail\n");
|
| 232 | return QL_SMS_GENERIC_FAILURE;
|
| 233 | }
|
| 234 |
|
| 235 | mbtk_sms_state_change_cb_reg(info_handle, lynq_sms_state_change_cb);
|
| 236 | return QL_SMS_SUCCESS;
|
| 237 | }
|
| 238 |
|
| 239 |
|
| 240 | /*
|
| 241 | AT+CMGD=<index>[,<delflag>]
|
| 242 |
|
| 243 | Deletes message based on index
|
| 244 | node:
|
| 245 | index is -1, delete all message
|
| 246 | delflag set 4
|
| 247 | */
|
| 248 |
|
| 249 | QL_SMS_ERROR_CODE ql_sms_delete_msg(size_t index)
|
| 250 | {
|
| 251 | char cmgd[128] = {0};
|
| 252 | int err = 0;
|
| 253 |
|
| 254 | if(index == -1) //delete all
|
| 255 | {
|
| 256 | memcpy(cmgd, ",4", strlen(",4"));
|
| 257 | }
|
| 258 | else
|
| 259 | {
|
| 260 | sprintf(cmgd,"%d",index);
|
| 261 | }
|
| 262 |
|
| 263 | printf("cmgd:%s\n", cmgd);
|
| 264 |
|
| 265 | err = mbtk_sms_cmgd_set(info_handle, cmgd);
|
| 266 | if(err) {
|
| 267 | printf("lynq_delete_sms Error : %d\n", err);
|
| 268 | return -1;
|
| 269 | } else {
|
| 270 | printf("lynq_delete_sms set success\n");
|
| 271 | }
|
| 272 |
|
| 273 | return 0;
|
| 274 |
|
| 275 | }
|
| 276 |
|
| 277 |
|
| 278 | QL_SMS_ERROR_CODE ql_search_sms_text_message(int index, recvmessage* payload)
|
| 279 | {
|
| 280 | if(info_handle == NULL)
|
| 281 | {
|
| 282 | return -1;
|
| 283 | }
|
| 284 |
|
| 285 | char cmgs[MSM_NUMBER_MAX] = {0};
|
| 286 | int mode = 1; // text
|
| 287 | int err = 0;
|
| 288 | char *data = "ALL";
|
| 289 |
|
| 290 | err = mbtk_sms_cmgf_set(info_handle, mode);
|
| 291 | if(err) {
|
| 292 | printf("cmgf set error : %d\n", err);
|
| 293 | } else {
|
| 294 | printf("cmgf set success\n");
|
| 295 | }
|
| 296 |
|
| 297 |
|
| 298 | char cmgl[128] = {0};
|
| 299 | char resp[1024+1] ={0};
|
| 300 | sprintf(cmgl,"%d,%s", index, data);
|
| 301 | /*
|
| 302 | char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
|
| 303 | if(ptr != NULL)
|
| 304 | {
|
| 305 | ptr = strstr(cmd, ",");
|
| 306 | ptr++;
|
| 307 | memset(cmgl, 0, sizeof(cmgl));
|
| 308 | memcpy(cmgl, ptr, strlen(ptr));
|
| 309 | printf("0cmgl:%s\n", cmgl);
|
| 310 | }
|
| 311 | */
|
| 312 | memset(resp, 0, sizeof(resp));
|
| 313 | err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
|
| 314 | if(err) {
|
| 315 | printf("lynq_list_sms Error : %d\n", err);
|
| 316 | return -1;
|
| 317 | } else {
|
| 318 | printf("cmgl set success, reg:%s\n",resp);
|
| 319 | }
|
| 320 |
|
| 321 | return 0;
|
| 322 |
|
| 323 | }
|
| 324 | QL_SMS_ERROR_CODE ql_search_sms_pdu_message(int index, recvmessage* payload)
|
| 325 | {
|
| 326 | if(info_handle == NULL)
|
| 327 | {
|
| 328 | return -1;
|
| 329 | }
|
| 330 |
|
| 331 | char cmgs[MSM_NUMBER_MAX] = {0};
|
| 332 | int mode = 0; // pud
|
| 333 | int err = 0;
|
| 334 | char *data = "ALL";
|
| 335 |
|
| 336 |
|
| 337 | err = mbtk_sms_cmgf_set(info_handle, mode);
|
| 338 | if(err) {
|
| 339 | printf("cmgf set error : %d\n", err);
|
| 340 | } else {
|
| 341 | printf("cmgf set success\n");
|
| 342 | }
|
| 343 |
|
| 344 |
|
| 345 | char cmgl[128] = {0};
|
| 346 | char resp[1024+1] ={0};
|
| 347 | sprintf(cmgl,"%d,%s", index, data);
|
| 348 | /*
|
| 349 | char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
|
| 350 | if(ptr != NULL)
|
| 351 | {
|
| 352 | ptr = strstr(cmd, ",");
|
| 353 | ptr++;
|
| 354 | memset(cmgl, 0, sizeof(cmgl));
|
| 355 | memcpy(cmgl, ptr, strlen(ptr));
|
| 356 | printf("0cmgl:%s\n", cmgl);
|
| 357 | }
|
| 358 | */
|
| 359 | memset(resp, 0, sizeof(resp));
|
| 360 | err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
|
| 361 | if(err) {
|
| 362 | printf("lynq_list_sms Error : %d\n", err);
|
| 363 | return -1;
|
| 364 | } else {
|
| 365 | printf("cmgl set success, reg:%s\n",resp);
|
| 366 | }
|
| 367 |
|
| 368 | return 0;
|
| 369 |
|
| 370 | }
|
| 371 |
|
| 372 |
|
| 373 | /*
|
| 374 | function: lynq_list_sms
|
| 375 | stat:0:pud, 1:text
|
| 376 | index: 0, list index;
|
| 377 | > 0,
|
| 378 |
|
| 379 | */
|
| 380 | QL_SMS_ERROR_CODE ql_sms_list_sms(int stat, int index, char *data)
|
| 381 | {
|
| 382 | if(info_handle == NULL)
|
| 383 | {
|
| 384 | return -1;
|
| 385 | }
|
| 386 |
|
| 387 | char cmgs[MSM_NUMBER_MAX] = {0};
|
| 388 | int mode = 0;
|
| 389 | int err = 0;
|
| 390 |
|
| 391 | if(stat) // text
|
| 392 | {
|
| 393 | mode = 1;
|
| 394 | }
|
| 395 |
|
| 396 | err = mbtk_sms_cmgf_set(info_handle, mode);
|
| 397 | if(err) {
|
| 398 | printf("cmgf set error : %d\n", err);
|
| 399 | } else {
|
| 400 | printf("cmgf set success\n");
|
| 401 | }
|
| 402 |
|
| 403 |
|
| 404 | char cmgl[128] = {0};
|
| 405 | char resp[1024+1] ={0};
|
| 406 | sprintf(cmgl,"%d,%s", index, data);
|
| 407 | /*
|
| 408 | char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
|
| 409 | if(ptr != NULL)
|
| 410 | {
|
| 411 | ptr = strstr(cmd, ",");
|
| 412 | ptr++;
|
| 413 | memset(cmgl, 0, sizeof(cmgl));
|
| 414 | memcpy(cmgl, ptr, strlen(ptr));
|
| 415 | printf("0cmgl:%s\n", cmgl);
|
| 416 | }
|
| 417 | */
|
| 418 | memset(resp, 0, sizeof(resp));
|
| 419 | err = mbtk_sms_cmgl_set(info_handle, cmgl, resp);
|
| 420 | if(err) {
|
| 421 | printf("lynq_list_sms Error : %d\n", err);
|
| 422 | return -1;
|
| 423 | } else {
|
| 424 | printf("cmgl set success, reg:%s\n",resp);
|
| 425 | }
|
| 426 |
|
| 427 | return 0;
|
| 428 | }
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 | int ql_sms_query_sms_storage_status(void)
|
| 433 | {
|
| 434 | char mem[128] = {0};
|
| 435 | int err = mbtk_sms_cpms_get(info_handle, mem);
|
| 436 | if(err) {
|
| 437 | printf("cpms query is fail Error : %d\n", err);
|
| 438 | return -1;
|
| 439 | } else {
|
| 440 | printf("cpms query is success : %s\n", mem);
|
| 441 | }
|
| 442 |
|
| 443 | return 0;
|
| 444 | }
|
| 445 |
|
| 446 | QL_SMS_ERROR_CODE ql_sms_get_sms_center_address(uint8_t *sms_center_addree)
|
| 447 | {
|
| 448 | char csca[128] = {0};
|
| 449 | if(info_handle == NULL || sms_center_addree == NULL)
|
| 450 | {
|
| 451 | return QL_SMS_GENERIC_FAILURE;
|
| 452 | }
|
| 453 |
|
| 454 | int err = mbtk_sms_csca_get(info_handle, sms_center_addree);
|
| 455 | if(err) {
|
| 456 | printf("lynq_get_smsc_address Error : %d\n", err);
|
| 457 | return QL_GET_RESPONSE_ERROR;
|
| 458 | } else {
|
| 459 | printf("lynq_get_smsc_address success\n");
|
| 460 | }
|
| 461 |
|
| 462 | return 0;
|
| 463 | }
|
| 464 |
|
| 465 |
|
| 466 | QL_SMS_ERROR_CODE ql_sms_set_sms_center_address(unsigned char *destNum)
|
| 467 | {
|
| 468 | printf("1destNum:%s\n", destNum);
|
| 469 | memset(center_address, 0, sizeof(center_address));
|
| 470 | memcpy(center_address, destNum, strlen(destNum));
|
| 471 | if(info_handle == NULL || destNum == NULL)
|
| 472 | {
|
| 473 | return -1;
|
| 474 | }
|
| 475 |
|
| 476 | int err = mbtk_sms_csca_set(info_handle, destNum);
|
| 477 | if(err) {
|
| 478 | printf("Error : %d\n", err);
|
| 479 | return err;
|
| 480 | } else {
|
| 481 | // memset(center_address, 0, sizeof(center_address));
|
| 482 | // memcpy(center_address, destNum, strlen(destNum));
|
| 483 | printf("destNum:%s\n", destNum);
|
| 484 | printf("lynq_set_smsc_address success\n");
|
| 485 | }
|
| 486 | return 0;
|
| 487 |
|
| 488 | }
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|