Mistake on this page?
Report an issue in GitHub or email us
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 CELLULAR_SMS_H_
19 #define CELLULAR_SMS_H_
20 
21 #include "Callback.h"
22 #include "nsapi_types.h"
23 
24 namespace mbed {
25 
26 // including trailing '\0'
27 const uint16_t SMS_MAX_SIZE_WITH_CONCATENATION = 4096 + 1;
28 const uint16_t SMS_MAX_PHONE_NUMBER_SIZE = 20 + 1;
29 const uint16_t SMS_MAX_TIME_STAMP_SIZE = 20 + 1;
30 
31 const uint16_t SMS_MAX_SIZE_8BIT_SINGLE_SMS_SIZE = 140;
32 const uint16_t SMS_MAX_SIZE_GSM7_SINGLE_SMS_SIZE = 160;
33 
34 const uint16_t SMS_SIM_WAIT_TIME_MILLISECONDS = 200;
35 
36 const int SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ = -5001;
37 
38 /**
39  * @addtogroup cellular
40  * @{
41  */
42 
43 /**
44  * Class CellularSMS
45  *
46  * An abstract interface for SMS sending, reading and deleting.
47  */
48 class CellularSMS {
49 protected:
50  // friend of CellularDevice so that it's the only way to close/delete this class.
51  friend class CellularDevice;
52 
53  /**
54  * virtual Destructor
55  */
56  virtual ~CellularSMS() {};
57 public:
58 
59  /* Enumeration for possible SMS modes, PDU and Text */
60  enum CellularSMSMmode {
61  CellularSMSMmodePDU = 0,
62  CellularSMSMmodeText
63  };
64 
65  enum CellularSMSEncoding {
66  CellularSMSEncoding7Bit,
67  CellularSMSEncoding8Bit,
68  };
69 
70  /** Does all the necessary initializations needed for receiving and sending SMS.
71  *
72  * @param mode enumeration for choosing the correct mode: text/pdu
73  * @return NSAPI_ERROR_OK on success
74  * NSAPI_ERROR_NO_MEMORY on memory failure
75  * NSAPI_ERROR_DEVICE_ERROR on other failures
76  */
77  virtual nsapi_error_t initialize(CellularSMSMmode mode,
78  CellularSMSEncoding encoding = CellularSMSEncoding::CellularSMSEncoding7Bit) = 0;
79 
80  /** Send the SMS with the given parameters
81  *
82  * @param phone_number Phone number where to send SMS
83  * @param message SMS message content
84  * @param msg_len Length of the message
85  * @return On success, length of the sent SMS (positive value)
86  * NSAPI_ERROR_PARAMETER if invalid parameters
87  * NSAPI_ERROR_NO_MEMORY on memory failure
88  * NSAPI_ERROR_DEVICE_ERROR on other failures
89  */
90  virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len) = 0;
91 
92  /** Gets the oldest received sms.
93  *
94  * @param buf preallocated buffer for SMS message content
95  * @param buf_len length of allocated buf
96  * @param phone_num preallocated buffer for phone number where SMS was sent
97  * @param phone_len length of allocated phone_num buffer
98  * @param time_stamp preallocated buffer for TP-Service Centre Time Stamp (format: yy/MM/dd,hh:mm:ss-+zz). +-zz is timezone.
99  * The unit of time zone is a quarter of an hour relative to GMT. For example +32 would be GMT+8.
100  * @param time_len length of allocated time_stamp buffer
101  * @param buf_size if method return error NSAPI_ERROR_NO_MEMORY because the given buf was not big enough, this
102  * holds the size which is enough. Otherwise zero.
103  * @return On success, length of the received SMS, (length of the buf, positive value)
104  * NSAPI_ERROR_PARAMETER if invalid parameters
105  * NSAPI_ERROR_NO_MEMORY on memory failure
106  * SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ if SMS was multipart but not all parts are present/failed to read.
107  * -1 if no SMS was found
108  * NSAPI_ERROR_DEVICE_ERROR on other failures
109  */
110  virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len,
111  char *time_stamp, uint16_t time_len, int *buf_size) = 0;
112 
113  /** Callback that is called when new SMS is received. SMS can be fetched using method get_sms().
114  *
115  * @remark In PDU mode, there can be multipart SMS, and callback is called for every received part.
116  *
117  * @param func Callback function that is called when new SMS is received.
118  */
119  virtual void set_sms_callback(Callback<void()> func) = 0;
120 
121  /** CPMS preferred message storage
122  *
123  * @param memr memory from which messages are read and deleted
124  * "SM" - SIM SMS memory storage (default)
125  * "ME" - NVM SMS storage
126  * @param memw memory to which writing and sending operations are made
127  * "SM" - SIM SMS memory storage (default)
128  * "ME" - NVM SMS storage
129  * @param mems memory to which received SMs are preferred to be stored
130  * "SM" - SIM SMS memory storage (default)
131  * "ME" - NVM SMS storage
132  *
133  * @return NSAPI_ERROR_OK on success
134  * NSAPI_ERROR_DEVICE_ERROR on failure
135  */
136  virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems) = 0;
137 
138  /** CSCA - set Service Center Address
139  *
140  * @param sca Service Center Address to be used for mobile originated SMS transmissions.
141  * @param type 129 - national numbering scheme, 145 - international numbering scheme (contains the character "+")
142  *
143  * @return NSAPI_ERROR_OK on success
144  * NSAPI_ERROR_DEVICE_ERROR on failure
145  */
146  virtual nsapi_error_t set_csca(const char *sca, int type) = 0;
147 
148  /** Set command sets the current character set used by the device. "GSM", "IRA",....
149  *
150  * @remark Current implementation support only ASCII so choose the correct character set.
151  *
152  * @param chr_set preferred character set list (comma separated). Modem might not support the wanted character set,
153  * so chr_set list is looped from start until supported set is found. Used character set index is returned.
154  * See more from 3GPP TS 27.005.
155  * @return Used character set index from the given list in case of success.
156  * NSAPI_ERROR_DEVICE_ERROR on failure
157  */
158  virtual nsapi_size_or_error_t set_cscs(const char *chr_set) = 0;
159 
160  /** Deletes all messages from the currently set memory/SIM
161  *
162  * @return NSAPI_ERROR_OK on success
163  * NSAPI_ERROR_DEVICE_ERROR on failure
164  */
165  virtual nsapi_error_t delete_all_messages() = 0;
166 
167  /** Some modems need extra time between AT commands and responses, or there will be error -314, SIM busy.
168  * If SIM busy errors are an issue, this time should be increased. It can also be set to zero to make
169  * operations faster and more energy efficient if no errors will follow. By default, wait time is zero.
170  *
171  * @param sim_wait_time
172  */
173  virtual void set_extra_sim_wait_time(int sim_wait_time) = 0;
174 };
175 
176 /**
177  * @}
178  */
179 
180 } // namespace mbed
181 
182 #endif // CELLULAR_SMS_H_
virtual void set_extra_sim_wait_time(int sim_wait_time)=0
Some modems need extra time between AT commands and responses, or there will be error -314...
virtual nsapi_error_t set_csca(const char *sca, int type)=0
CSCA - set Service Center Address.
virtual nsapi_size_or_error_t set_cscs(const char *chr_set)=0
Set command sets the current character set used by the device.
virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems)=0
CPMS preferred message storage.
virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len)=0
Send the SMS with the given parameters.
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)=0
Gets the oldest received sms.
Class CellularDevice.
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_error_t initialize(CellularSMSMmode mode, CellularSMSEncoding encoding=CellularSMSEncoding::CellularSMSEncoding7Bit)=0
Does all the necessary initializations needed for receiving and sending SMS.
virtual ~CellularSMS()
virtual Destructor
Definition: CellularSMS.h:56
virtual nsapi_error_t delete_all_messages()=0
Deletes all messages from the currently set memory/SIM.
Class CellularSMS.
Definition: CellularSMS.h:48
virtual void set_sms_callback(Callback< void()> func)=0
Callback that is called when new SMS is received.
Callback class based on template specialization.
Definition: Callback.h:39
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.