Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AT_CellularSMS.h Source File

AT_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 AT_CELLULAR_SMS_H_
00019 #define AT_CELLULAR_SMS_H_
00020 
00021 #include "CellularSMS.h"
00022 #include "AT_CellularBase.h"
00023 #include "Callback.h"
00024 #include <time.h>
00025 
00026 namespace mbed {
00027 
00028 /**
00029  *  Class AT_CellularSMS
00030  *
00031  *  Class for SMS sending, reading and deleting.
00032  */
00033 class AT_CellularSMS: public CellularSMS, public AT_CellularBase
00034 {
00035 
00036 public:
00037     AT_CellularSMS(ATHandler &atHandler);
00038     virtual ~AT_CellularSMS();
00039 
00040 public:
00041     // from CellularSMS
00042 
00043     virtual nsapi_error_t initialize(CellularSMSMmode mode);
00044 
00045     virtual nsapi_size_or_error_t send_sms(const char* phone_number, const char* message, int msg_len);
00046 
00047     virtual nsapi_size_or_error_t get_sms(char* buf, uint16_t buf_len, char* phone_num, uint16_t phone_len,
00048             char* time_stamp, uint16_t time_len, int *buf_size);
00049 
00050     virtual void set_sms_callback(Callback<void()> func);
00051 
00052     virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems);
00053 
00054     virtual nsapi_error_t set_csca(const char *sca, int type);
00055 
00056     virtual nsapi_size_or_error_t set_cscs(const char *chr_set);
00057 
00058     virtual nsapi_error_t delete_all_messages();
00059 
00060     virtual void set_extra_sim_wait_time(int sim_wait_time);
00061 
00062 private:
00063 
00064     struct sms_info_t {
00065         char date[SMS_MAX_TIME_STAMP_SIZE];
00066         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
00067         uint16_t msg_size;
00068         uint8_t parts;
00069         uint8_t parts_added;
00070         uint16_t msg_ref_number;
00071         struct sms_info_t *next_info;
00072         sms_info_t() : msg_size(0), parts(1), parts_added(1), msg_ref_number(0), next_info(0){};
00073     };
00074 
00075     // application callback function for received sms
00076     Callback<void()> _cb;
00077     CellularSMSMmode _mode;
00078     bool _use_8bit_encoding;
00079     uint32_t _sim_wait_time;
00080     uint16_t _sms_message_ref_number;
00081     sms_info_t *_sms_info;
00082 
00083     // SMS urc's
00084     void cmt_urc();
00085     void cmti_urc();
00086 
00087     /** Set command selects the format of messages used with send, list, read and write commands.
00088      *
00089      *  @param   msg_format 0 PDU mode, 1 text mode
00090      *  @return  zero for success
00091      */
00092     nsapi_error_t set_cmgf(int msg_format);
00093 
00094     /** Set how receiving of new messages from the network is indicated to the TE.
00095      *
00096      *  @return zero for success
00097      */
00098     nsapi_error_t set_cnmi();
00099 
00100     /** Set Text Mode Parameters
00101      *
00102      * @param fo    See more from 3GPP TS 27.005 for all params.
00103      * @param vp
00104      * @param pid
00105      * @param dcs
00106      * @return      zero for success
00107      */
00108     nsapi_error_t set_csmp(int fo, int vp, int pid, int dcs);
00109 
00110     /** CSDH - Set command controls whether detailed header information is shown in text mode (AT+CMGF=1) result codes.
00111      *
00112      *  @param show_header  1 to show detailed header in text mode, 0 for not showing.
00113      *  @return             zero for success
00114      */
00115     nsapi_error_t set_csdh(int show_header);
00116 
00117     /** Delete SMS in the given message position(s) in the storage
00118      *
00119      *  @param sms  struct containing index array to delete
00120      *  @return     zero for success
00121      */
00122     nsapi_error_t delete_sms(sms_info_t* sms);
00123 
00124     /**
00125      * Internal helper methods
00126      */
00127     nsapi_error_t list_messages();
00128     int read_sms_params(char *, char *);
00129     void free_linked_list();
00130     void add_info(sms_info_t* info, int index, int part_number);
00131     int read_udh_from_pdu(const char* pdu, sms_info_t *info, int &part_number, int &padding_bits);
00132     nsapi_size_or_error_t get_data_from_pdu(const char* pdu, sms_info_t *info, int *part_number,
00133                                             char *phone_number = NULL, char *msg = NULL);
00134     nsapi_size_or_error_t read_pdu_payload(const char* pdu, int msg_len, int scheme, char *msg, int padding_bits);
00135     sms_info_t* get_oldest_sms_index();
00136     bool create_time(const char* time_string, time_t* time);
00137     int compare_time_strings(const char* time_string_1, const char* time_string_2);
00138     char* create_pdu(const char* phone_number, const char* message, uint8_t message_length, uint8_t msg_parts,
00139                      uint8_t msg_part_number, uint8_t& header_size);
00140     nsapi_size_or_error_t read_sms_from_index(int msg_index, char* buf, uint16_t len, char* phone_num,
00141                                               char* time_stamp);
00142     nsapi_size_or_error_t read_sms(sms_info_t* sms, char* buf, char* phone_num, char* time_stamp);
00143 
00144     /** Packs the given str from ascii to 7bit gsm format and converts it to hex to the given buf.
00145      *
00146      *  @param str                   string that is to be converted
00147      *  @param len                   length of the str buffer
00148      *  @param buf                   preallocated buffer that holds the converted string in hex format after successful call
00149      *  @param number_of_padding_bit padding bits needed to keep the octet boundary
00150      *  @return                      length of buffer buf or zero on failure
00151      */
00152     uint16_t pack_7_bit_gsm_and_hex(const char* str, uint16_t len, char *buf, int number_of_padding_bit);
00153 
00154     /** Unpacks the given hex- and 7-bit gsm encoded str to ascii string
00155      *
00156      *  @param str          string to convert to ascii string and write to buf
00157      *  @param len          length of the str divided by two as str is hexencoded
00158      *  @param buf          preallocated destination buffer
00159      *  @param padding_bits number of padding bits needed to hold the octet boundary
00160      *  @param msg_len      Length of the received message, which is coded in str
00161      *  @return             length of the destination buffer buf
00162      *
00163      */
00164     uint16_t unpack_7_bit_gsm_to_str(const char* str, int len, char *buf, int padding_bits,
00165                                          int msg_len);
00166 };
00167 
00168 } // namespace mbed
00169 
00170 #endif // AT_CELLULAR_SMS_H_