luat_sms.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef LUAT_SMS_H
  22. #define LUAT_SMS_H
  23. #include "luat_base.h"
  24. #define LUAT_MSG_MAX_ADDR_LEN 80
  25. #define LUAT_SMS_MAX_TXT_SIZE 640
  26. #define LUAT_SMS_MAX_PDU_SIZE 180
  27. #define LUAT_SMS_MAX_LENGTH_OF_ADDRESS_VALUE 40
  28. #define LUAT_SMS_MAX_ADDR_STR_MAX_LEN ((LUAT_SMS_MAX_LENGTH_OF_ADDRESS_VALUE + 1) * 4)
  29. typedef void (*LUAT_SMS_HANDLE_CB)(uint8_t event, void* param);
  30. typedef void (*LUAT_SMS_HANDLE_SEND_CB)(int ret);
  31. typedef enum
  32. {
  33. SMS_SEND_OK = 0,
  34. SMS_ME_FAILURE = 300,
  35. SMS_SERVICE_OF_ME_RESV,
  36. SMS_OPERATION_NOT_ALLOWED,
  37. SMS_OPERATION_NOT_SUPPORTED,
  38. SMS_INVALID_PDU_MODE_PARAMETER,
  39. SMS_INVALID_TEXT_MODE_PARAMETER,
  40. SMS_USIM_NOT_INSERTED = 310,
  41. SMS_USIM_PIN_REQUIRED,
  42. SMS_PHSIM_PIN_REQUIRED,
  43. SMS_USIM_FAILURE,
  44. SMS_USIM_BUSY,
  45. SMS_USIM_WRONG,
  46. SMS_USIM_PUK_REQUIRED,
  47. SMS_USIM_PIN2_REQUIRED,
  48. SMS_USIM_PUK2_REQUIRED,
  49. SMS_MEMORY_FAILURE = 320,
  50. SMS_INVALID_MEM_INDEX,
  51. SMS_MEM_FULL,
  52. SMS_SMSC_ADDR_UNKNOWN = 330,
  53. SMS_NO_NETWORK_SERVICE,
  54. SMS_NETWORK_TIMEOUT,
  55. SMS_NO_CNMA_ACK_EXPECTED = 340,
  56. SMS_UNKNOWN_ERROR = 500,
  57. SMS_INVALID_DATA = 550,
  58. SMS_UNSUPPORT_TEXT_WITH_CHINESE = 555,
  59. SMS_MAX_ERROR = 0xFFFF
  60. }LUAT_SMS_SEND_RET_CODE_E;
  61. typedef struct
  62. {
  63. LUAT_SMS_HANDLE_CB cb;
  64. LUAT_SMS_HANDLE_SEND_CB send_cb;
  65. }LUAT_SMS_MAIN_CFG_T;
  66. typedef struct
  67. {
  68. uint8_t year;
  69. uint8_t month;
  70. uint8_t day;
  71. uint8_t hour;
  72. uint8_t minute;
  73. uint8_t second;
  74. uint8_t tz; /* time zone */
  75. uint8_t tz_sign; /* '+'/'-' */
  76. }LUAT_SMS_RECV_MSG_TIME_T;
  77. typedef struct
  78. {
  79. uint8_t type;
  80. uint8_t msg_class;
  81. uint8_t alpha_bet;
  82. uint8_t indication;
  83. uint8_t dcs;
  84. }LUAT_SMS_RECV_MSG_DCS_T;
  85. //接受的短信信息结构体
  86. typedef struct
  87. {
  88. uint16_t pdu_length;//PDU 长度
  89. uint16_t sms_length;//TEXT 的长度
  90. LUAT_SMS_RECV_MSG_TIME_T time;//时间
  91. LUAT_SMS_RECV_MSG_DCS_T dcs_info;//Data Coding Scheme
  92. char pdu_data[LUAT_SMS_MAX_TXT_SIZE + 1];//PDU 数据
  93. uint8_t sms_buffer[LUAT_SMS_MAX_TXT_SIZE + 1];//TEXT 数据
  94. uint8_t sc_address[LUAT_MSG_MAX_ADDR_LEN + 1];//中心地址
  95. uint8_t phone_address[LUAT_MSG_MAX_ADDR_LEN + 1];//来电号码
  96. uint8_t refNum;
  97. uint8_t maxNum;
  98. uint8_t seqNum;
  99. }LUAT_SMS_RECV_MSG_T;
  100. /**
  101. * @defgroup luatos_sms 短信功能
  102. * @{
  103. */
  104. /**
  105. * @brief 初始化短信
  106. */
  107. void luat_sms_init(void);
  108. /**
  109. * @brief 发送短信
  110. * @param p_input 短信的内容(当 is_pdu = false 时, 只支持英文,数字以及常用符号)
  111. * @param p_des 接收短信的手机号
  112. * @param is_pdu 是否是PDU格式的短信(当 false 时, 有效参数为 p_input & pdes, 当 true 时, 有效参数为 p_input & pudLen)
  113. * @param input_pdu_len PDU格式短信的长度,注意和p_input长度没有关系
  114. * @return 0成功,-1失败
  115. */
  116. int luat_sms_send_msg(uint8_t *p_input, char *p_des, bool is_pdu, int input_pdu_len);
  117. /**
  118. * @brief 接受短信回调
  119. * @param callback_fun 回调函数
  120. */
  121. void luat_sms_recv_msg_register_handler(LUAT_SMS_HANDLE_CB callback_fun);
  122. /**
  123. * @brief 发送短信回调
  124. * @param callback_fun 回调函数
  125. */
  126. void luat_sms_send_msg_register_handler(LUAT_SMS_HANDLE_SEND_CB callback_fun);
  127. #endif