Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CellularSMS.h Source File

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 #if MBED_CONF_CELLULAR_USE_SMS
00022 
00023 #include "Callback.h"
00024 #include "nsapi_types.h"
00025 
00026 namespace mbed {
00027 
00028 // including trailing '\0'
00029 const uint16_t SMS_MAX_SIZE_WITH_CONCATENATION = 4096 + 1;
00030 const uint16_t SMS_MAX_PHONE_NUMBER_SIZE = 20 + 1;
00031 const uint16_t SMS_MAX_TIME_STAMP_SIZE = 20 + 1;
00032 
00033 const uint16_t SMS_MAX_SIZE_8BIT_SINGLE_SMS_SIZE = 140;
00034 const uint16_t SMS_MAX_SIZE_GSM7_SINGLE_SMS_SIZE = 160;
00035 
00036 const uint16_t SMS_SIM_WAIT_TIME_MILLISECONDS = 200;
00037 
00038 const int SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ = -5001;
00039 
00040 /**
00041  * @addtogroup cellular
00042  * @{
00043  */
00044 
00045 /**
00046  *  Class CellularSMS
00047  *
00048  *  An abstract interface for SMS sending, reading and deleting.
00049  */
00050 class CellularSMS {
00051 protected:
00052     // friend of CellularDevice so that it's the only way to close/delete this class.
00053     friend class CellularDevice;
00054 
00055     /**
00056      * virtual Destructor
00057      */
00058     virtual ~CellularSMS() {};
00059 public:
00060 
00061     /* Enumeration for possible SMS modes, PDU and Text */
00062     enum CellularSMSMmode {
00063         CellularSMSMmodePDU = 0,
00064         CellularSMSMmodeText
00065     };
00066 
00067     enum CellularSMSEncoding {
00068         CellularSMSEncoding7Bit,
00069         CellularSMSEncoding8Bit,
00070     };
00071 
00072     /** Does all the necessary initializations needed for receiving and sending SMS.
00073      *
00074      *  @param mode          enumeration for choosing the correct mode: text/pdu
00075      *  @return              NSAPI_ERROR_OK on success
00076      *                       NSAPI_ERROR_NO_MEMORY on memory failure
00077      *                       NSAPI_ERROR_DEVICE_ERROR on other failures
00078      */
00079     virtual nsapi_error_t initialize(CellularSMSMmode mode,
00080                                      CellularSMSEncoding encoding = CellularSMSEncoding::CellularSMSEncoding7Bit) = 0;
00081 
00082     /** Send the SMS with the given parameters
00083      *
00084      *  @param phone_number  Phone number where to send SMS
00085      *  @param message       SMS message content
00086      *  @param msg_len       Length of the message
00087      *  @return              On success, length of the sent SMS (positive value)
00088      *                       NSAPI_ERROR_PARAMETER if invalid parameters
00089      *                       NSAPI_ERROR_NO_MEMORY on memory failure
00090      *                       NSAPI_ERROR_DEVICE_ERROR on other failures
00091      */
00092     virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len) = 0;
00093 
00094     /** Gets the oldest received sms.
00095      *
00096      *  @param buf           preallocated buffer for SMS message content
00097      *  @param buf_len       length of allocated buf
00098      *  @param phone_num     preallocated buffer for phone number where SMS was sent
00099      *  @param phone_len     length of allocated phone_num  buffer
00100      *  @param time_stamp    preallocated buffer for TP-Service Centre Time Stamp (format: yy/MM/dd,hh:mm:ss-+zz). +-zz is timezone.
00101      *                       The unit of time zone is a quarter of an hour relative to GMT. For example +32 would be GMT+8.
00102      *  @param time_len      length of allocated time_stamp buffer
00103      *  @param buf_size      if method return error NSAPI_ERROR_NO_MEMORY because the given buf was not big enough, this
00104      *                       holds the size which is enough. Otherwise zero.
00105      *  @return              On success, length of the received SMS, (length of the buf, positive value)
00106      *                       NSAPI_ERROR_PARAMETER if invalid parameters
00107      *                       NSAPI_ERROR_NO_MEMORY on memory failure
00108      *                       SMS_ERROR_MULTIPART_ALL_PARTS_NOT_READ if SMS was multipart but not all parts are present/failed to read.
00109      *                       -1 if no SMS was found
00110      *                       NSAPI_ERROR_DEVICE_ERROR on other failures
00111      */
00112     virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len,
00113                                           char *time_stamp, uint16_t time_len, int *buf_size) = 0;
00114 
00115     /** Callback that is called when new SMS is received. SMS can be fetched using method get_sms().
00116      *
00117      * @remark      In PDU mode, there can be multipart SMS, and callback is called for every received part.
00118      *
00119      * @param func  Callback function that is called when new SMS is received.
00120      */
00121     virtual void set_sms_callback(Callback<void()> func) = 0;
00122 
00123     /** CPMS preferred message storage
00124      *
00125      *  @param memr        memory from which messages are read and deleted
00126      *                     "SM" - SIM SMS memory storage (default)
00127      *                     "ME" - NVM SMS storage
00128      *  @param memw        memory to which writing and sending operations are made
00129      *                     "SM" - SIM SMS memory storage (default)
00130      *                     "ME" - NVM SMS storage
00131      *  @param mems        memory to which received SMs are preferred to be stored
00132      *                     "SM" - SIM SMS memory storage (default)
00133      *                     "ME" - NVM SMS storage
00134      *
00135      *  @return            NSAPI_ERROR_OK on success
00136      *                     NSAPI_ERROR_DEVICE_ERROR on failure
00137      */
00138     virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems) = 0;
00139 
00140     /** CSCA - set Service Center Address
00141      *
00142      *  @param sca        Service Center Address to be used for mobile originated SMS transmissions.
00143      *  @param type       129 - national numbering scheme, 145 - international numbering scheme (contains the character "+")
00144      *
00145      *  @return           NSAPI_ERROR_OK on success
00146      *                    NSAPI_ERROR_DEVICE_ERROR on failure
00147      */
00148     virtual nsapi_error_t set_csca(const char *sca, int type) = 0;
00149 
00150     /** Set command sets the current character set used by the device. "GSM", "IRA",....
00151      *
00152      *  @remark Current implementation support only ASCII so choose the correct character set.
00153      *
00154      *  @param chr_set   preferred character set list (comma separated). Modem might not support the wanted character set,
00155      *                   so chr_set list is looped from start until supported set is found. Used character set index is returned.
00156      *                   See more from 3GPP TS 27.005.
00157      * @return           Used character set index from the given list in case of success.
00158      *                   NSAPI_ERROR_DEVICE_ERROR on failure
00159      */
00160     virtual nsapi_size_or_error_t set_cscs(const char *chr_set) = 0;
00161 
00162     /** Deletes all messages from the currently set memory/SIM
00163      *
00164      *  @return            NSAPI_ERROR_OK on success
00165      *                     NSAPI_ERROR_DEVICE_ERROR on failure
00166      */
00167     virtual nsapi_error_t delete_all_messages() = 0;
00168 
00169     /** Some modems need extra time between AT commands and responses, or there will be error -314, SIM busy.
00170      *  If SIM busy errors are an issue, this time should be increased. It can also be set to zero to make
00171      *  operations faster and more energy efficient if no errors will follow. By default, wait time is zero.
00172      *
00173      *  @param sim_wait_time
00174      */
00175     virtual void set_extra_sim_wait_time(int sim_wait_time) = 0;
00176 };
00177 
00178 /**
00179  * @}
00180  */
00181 
00182 } // namespace mbed
00183 
00184 #endif // MBED_CONF_CELLULAR_USE_SMS
00185 
00186 #endif // CELLULAR_SMS_H_