Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CellularSMS.h
00001 /* 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef CELLULAR_SMS_H_ 00019 #define CELLULAR_SMS_H_ 00020 00021 #include "Callback.h" 00022 #include "nsapi_types.h" 00023 00024 namespace mbed { 00025 00026 // including trailing '\0' 00027 const uint16_t SMS_MAX_SIZE_WITH_CONCATENATION = 4096 + 1; 00028 const uint16_t SMS_MAX_PHONE_NUMBER_SIZE = 20 + 1; 00029 const uint16_t SMS_MAX_TIME_STAMP_SIZE = 20 + 1; 00030 00031 const uint16_t SMS_MAX_SIZE_8BIT_SINGLE_SMS_SIZE = 140; 00032 const uint16_t SMS_MAX_SIZE_GSM7_SINGLE_SMS_SIZE = 160; 00033 00034 const uint16_t SMS_SIM_WAIT_TIME_MILLISECONDS = 200; 00035 00036 const int SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ = -5001; 00037 00038 /** 00039 * Class CellularSMS 00040 * 00041 * An abstract interface for SMS sending, reading and deleting. 00042 */ 00043 class CellularSMS { 00044 protected: 00045 // friend of CellularDevice so that it's the only way to close/delete this class. 00046 friend class CellularDevice; 00047 00048 /** 00049 * virtual Destructor 00050 */ 00051 virtual ~CellularSMS() {}; 00052 public: 00053 00054 /* Enumeration for possible SMS modes, PDU and Text */ 00055 enum CellularSMSMmode { 00056 CellularSMSMmodePDU = 0, 00057 CellularSMSMmodeText 00058 }; 00059 00060 /** Does all the necessary initializations needed for receiving and sending SMS. 00061 * 00062 * @param mode enumeration for choosing the correct mode: text/pdu 00063 * @return NSAPI_ERROR_OK on success 00064 * NSAPI_ERROR_NO_MEMORY on memory failure 00065 * NSAPI_ERROR_DEVICE_ERROR on other failures 00066 */ 00067 virtual nsapi_error_t initialize(CellularSMSMmode mode) = 0; 00068 00069 /** Send the SMS with the given parameters 00070 * 00071 * @param phone_number Phone number where to send SMS 00072 * @param message SMS message content 00073 * @param msg_len Length of the message 00074 * @return On success, length of the sent SMS (positive value) 00075 * NSAPI_ERROR_PARAMETER if invalid parameters 00076 * NSAPI_ERROR_NO_MEMORY on memory failure 00077 * NSAPI_ERROR_DEVICE_ERROR on other failures 00078 */ 00079 virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len) = 0; 00080 00081 /** Gets the oldest received sms. 00082 * 00083 * @param buf preallocated buffer for SMS message content 00084 * @param buf_len length of allocated buf 00085 * @param phone_num preallocated buffer for phone number where SMS was sent 00086 * @param phone_len length of allocated phone_num buffer 00087 * @param time_stamp preallocated buffer for TP-Service Centre Time Stamp (format: yy/MM/dd,hh:mm:ss-+zz). +-zz is timezone. 00088 * The unit of time zone is a quarter of an hour relative to GMT. For example +32 would be GMT+8. 00089 * @param time_len length of allocated time_stamp buffer 00090 * @param buf_size if method return error NSAPI_ERROR_NO_MEMORY because the given buf was not big enough, this 00091 * holds the size which is enough. Otherwise zero. 00092 * @return On success, length of the received SMS, (length of the buf, positive value) 00093 * NSAPI_ERROR_PARAMETER if invalid parameters 00094 * NSAPI_ERROR_NO_MEMORY on memory failure 00095 * SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ if SMS was multipart but not all parts are present/failed to read. 00096 * -1 if no SMS was found 00097 * NSAPI_ERROR_DEVICE_ERROR on other failures 00098 */ 00099 virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len, 00100 char *time_stamp, uint16_t time_len, int *buf_size) = 0; 00101 00102 /** Callback that is called when new SMS is received. SMS can be fetched using method get_sms(). 00103 * 00104 * @remark In PDU mode, there can be multipart SMS, and callback is called for every received part. 00105 * 00106 * @param func Callback function that is called when new SMS is received. 00107 */ 00108 virtual void set_sms_callback(Callback<void()> func) = 0; 00109 00110 /** CPMS preferred message storage 00111 * 00112 * @param memr memory from which messages are read and deleted 00113 * "SM" - SIM SMS memory storage (default) 00114 * "ME" - NVM SMS storage 00115 * @param memw memory to which writing and sending operations are made 00116 * "SM" - SIM SMS memory storage (default) 00117 * "ME" - NVM SMS storage 00118 * @param mems memory to which received SMs are preferred to be stored 00119 * "SM" - SIM SMS memory storage (default) 00120 * "ME" - NVM SMS storage 00121 * 00122 * @return NSAPI_ERROR_OK on success 00123 * NSAPI_ERROR_DEVICE_ERROR on failure 00124 */ 00125 virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems) = 0; 00126 00127 /** CSCA - set Service Center Address 00128 * 00129 * @param sca Service Center Address to be used for mobile originated SMS transmissions. 00130 * @param type 129 - national numbering scheme, 145 - international numbering scheme (contains the character "+") 00131 * 00132 * @return NSAPI_ERROR_OK on success 00133 * NSAPI_ERROR_DEVICE_ERROR on failure 00134 */ 00135 virtual nsapi_error_t set_csca(const char *sca, int type) = 0; 00136 00137 /** Set command sets the current character set used by the device. "GSM", "IRA",.... 00138 * 00139 * @remark Current implementation support only ASCII so choose the correct character set. 00140 * 00141 * @param chr_set preferred character set list (comma separated). Modem might not support the wanted character set, 00142 * so chr_set list is looped from start until supported set is found. Used character set index is returned. 00143 * See more from 3GPP TS 27.005. 00144 * @return Used character set index from the given list in case of success. 00145 * NSAPI_ERROR_DEVICE_ERROR on failure 00146 */ 00147 virtual nsapi_size_or_error_t set_cscs(const char *chr_set) = 0; 00148 00149 /** Deletes all messages from the currently set memory/SIM 00150 * 00151 * @return NSAPI_ERROR_OK on success 00152 * NSAPI_ERROR_DEVICE_ERROR on failure 00153 */ 00154 virtual nsapi_error_t delete_all_messages() = 0; 00155 00156 /** Some modems need extra time between AT commands and responses, or there will be error -314, SIM busy. 00157 * If SIM busy errors are an issue, this time should be increased. It can also be set to zero to make 00158 * operations faster and more energy efficient if no errors will follow. By default, wait time is zero. 00159 * 00160 * @param sim_wait_time 00161 */ 00162 virtual void set_extra_sim_wait_time(int sim_wait_time) = 0; 00163 }; 00164 00165 } // namespace mbed 00166 00167 #endif // CELLULAR_SMS_H_
Generated on Tue Jul 12 2022 13:53:03 by
