Mistake on this page?
Report an issue in GitHub or email us
AT_CellularSMS.h
1 /*
2  * Copyright (c) 2017, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef AT_CELLULAR_SMS_H_
19 #define AT_CELLULAR_SMS_H_
20 
21 #include "CellularSMS.h"
22 #include "AT_CellularBase.h"
23 #include "Callback.h"
24 #include <time.h>
25 
26 namespace mbed {
27 
28 /**
29  * Class AT_CellularSMS
30  *
31  * Class for SMS sending, reading and deleting.
32  */
34 
35 public:
36  AT_CellularSMS(ATHandler &atHandler);
37  virtual ~AT_CellularSMS();
38 
39 public:
40  // from CellularSMS
41 
42  virtual nsapi_error_t initialize(CellularSMSMmode mode,
43  CellularSMSEncoding encoding = CellularSMSEncoding7Bit);
44 
45  virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len);
46 
47  virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len,
48  char *time_stamp, uint16_t time_len, int *buf_size);
49 
50  virtual void set_sms_callback(Callback<void()> func);
51 
52  virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems);
53 
54  virtual nsapi_error_t set_csca(const char *sca, int type);
55 
56  virtual nsapi_size_or_error_t set_cscs(const char *chr_set);
57 
59 
60  virtual void set_extra_sim_wait_time(int sim_wait_time);
61 
62 private:
63 
64  struct sms_info_t {
65  char date[SMS_MAX_TIME_STAMP_SIZE];
66  uint16_t msg_index[50]; // can hold up to 50 concatenated msg parts, indexes are in correct order. So max sms size is 50*140 = 7kb
67  uint16_t msg_size;
68  uint8_t parts;
69  uint8_t parts_added;
70  uint16_t msg_ref_number;
71  struct sms_info_t *next_info;
72  sms_info_t() : msg_size(0), parts(1), parts_added(1), msg_ref_number(0), next_info(0) {};
73  };
74 
75  // application callback function for received sms
76  Callback<void()> _cb;
77  CellularSMSMmode _mode;
78  bool _use_8bit_encoding;
79  uint32_t _sim_wait_time;
80  uint16_t _sms_message_ref_number;
81  sms_info_t *_sms_info;
82 
83  // SMS urc's
84  void cmt_urc();
85  void cmti_urc();
86 
87  /** Set command selects the format of messages used with send, list, read and write commands.
88  *
89  * @param msg_format 0 PDU mode, 1 text mode
90  * @return zero for success
91  */
92  nsapi_error_t set_cmgf(int msg_format);
93 
94  /** Set how receiving of new messages from the network is indicated to the TE.
95  *
96  * @return zero for success
97  */
98  nsapi_error_t set_cnmi();
99 
100  /** Set Text Mode Parameters
101  *
102  * @param fo See more from 3GPP TS 27.005 for all params.
103  * @param vp
104  * @param pid
105  * @param dcs
106  * @return zero for success
107  */
108  nsapi_error_t set_csmp(int fo, int vp, int pid, int dcs);
109 
110  /** CSDH - Set command controls whether detailed header information is shown in text mode (AT+CMGF=1) result codes.
111  *
112  * @param show_header 1 to show detailed header in text mode, 0 for not showing.
113  * @return zero for success
114  */
115  nsapi_error_t set_csdh(int show_header);
116 
117  /** Delete SMS in the given message position(s) in the storage
118  *
119  * @param sms struct containing index array to delete
120  * @return zero for success
121  */
122  nsapi_error_t delete_sms(sms_info_t *sms);
123 
124  /**
125  * Internal helper methods
126  */
127  nsapi_error_t list_messages();
128  int read_sms_params(char *, char *);
129  void free_linked_list();
130  void add_info(sms_info_t *info, int index, int part_number);
131  int read_udh_from_pdu(const char *pdu, sms_info_t *info, int &part_number, int &padding_bits);
132  nsapi_size_or_error_t get_data_from_pdu(const char *pdu, sms_info_t *info, int *part_number,
133  char *phone_number = NULL, char *msg = NULL);
134  nsapi_size_or_error_t read_pdu_payload(const char *pdu, int msg_len, int scheme, char *msg, int padding_bits);
135  sms_info_t *get_oldest_sms_index();
136  bool create_time(const char *time_string, time_t *time);
137  int compare_time_strings(const char *time_string_1, const char *time_string_2);
138  char *create_pdu(const char *phone_number, const char *message, uint8_t message_length, uint8_t msg_parts,
139  uint8_t msg_part_number, uint8_t &header_size);
140  nsapi_size_or_error_t read_sms_from_index(int msg_index, char *buf, uint16_t len, char *phone_num,
141  char *time_stamp);
142  nsapi_size_or_error_t read_sms(sms_info_t *sms, char *buf, char *phone_num, char *time_stamp);
143 
144  /** Packs the given str from ascii to 7bit gsm format and converts it to hex to the given buf.
145  *
146  * @param str string that is to be converted
147  * @param len length of the str buffer
148  * @param buf preallocated buffer that holds the converted string in hex format after successful call
149  * @param number_of_padding_bit padding bits needed to keep the octet boundary
150  * @return length of buffer buf or zero on failure
151  */
152  uint16_t pack_7_bit_gsm_and_hex(const char *str, uint16_t len, char *buf, int number_of_padding_bit);
153 
154  /** Unpacks the given hex- and 7-bit gsm encoded str to ascii string
155  *
156  * @param str string to convert to ascii string and write to buf
157  * @param len length of the str divided by two as str is hexencoded
158  * @param buf preallocated destination buffer
159  * @param padding_bits number of padding bits needed to hold the octet boundary
160  * @param msg_len Length of the received message, which is coded in str
161  * @return length of the destination buffer buf
162  *
163  */
164  uint16_t unpack_7_bit_gsm_to_str(const char *str, int len, char *buf, int padding_bits,
165  int msg_len);
166 };
167 
168 } // namespace mbed
169 
170 #endif // AT_CELLULAR_SMS_H_
virtual void set_extra_sim_wait_time(int sim_wait_time)
Some modems need extra time between AT commands and responses, or there will be error -314...
Class AT_CellularSMS.
The key size.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:95
signed int nsapi_size_or_error_t
Type used to represent either a size or error passed through sockets.
Definition: nsapi_types.h:106
virtual nsapi_size_or_error_t set_cscs(const char *chr_set)
Set command sets the current character set used by the device.
virtual nsapi_error_t set_csca(const char *sca, int type)
CSCA - set Service Center Address.
Class AT_CellularBase.
Class CellularSMS.
Definition: CellularSMS.h:48
virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems)
CPMS preferred message storage.
virtual void set_sms_callback(Callback< void()> func)
Callback that is called when new SMS is received.
virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len, char *time_stamp, uint16_t time_len, int *buf_size)
Gets the oldest received sms.
Callback class based on template specialization.
Definition: Callback.h:39
Class for sending AT commands and parsing AT responses.
Definition: ATHandler.h:66
virtual nsapi_error_t delete_all_messages()
Deletes all messages from the currently set memory/SIM.
virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len)
Send the SMS with the given parameters.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.