This class provides SMS, USSD and modem file system support for u-blox modules on the C027 and C030 boards (excepting the C030 N2xx flavour) from mbed 5.5 onwards.
Dependents: example-ublox-at-cellular-interface-ext example-ublox-cellular-driver-gen HelloMQTT ublox_new_driver_test ... more
UbloxCellularDriverGen.h
00001 /* Copyright (c) 2017 ARM Limited 00002 * 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 */ 00015 00016 #ifndef _UBLOX_CELLULAR_DRIVER_GEN_ 00017 #define _UBLOX_CELLULAR_DRIVER_GEN_ 00018 00019 #include "UbloxCellularBase.h" 00020 00021 /** UbloxCellularDriverGen class 00022 * This interface provide SMS, USSD and 00023 * module File System functionality. 00024 */ 00025 class UbloxCellularDriverGen: virtual public UbloxCellularBase { 00026 00027 public: 00028 /** Constructor. 00029 * 00030 * @param tx the UART TX data pin to which the modem is attached. 00031 * @param rx the UART RX data pin to which the modem is attached. 00032 * @param baud the UART baud rate. 00033 * @param debugOn true to switch AT interface debug on, otherwise false. 00034 */ 00035 UbloxCellularDriverGen(PinName tx = MDMTXD, PinName rx = MDMRXD, 00036 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, 00037 bool debugOn = false); 00038 00039 /* Destructor. 00040 */ 00041 ~UbloxCellularDriverGen(); 00042 00043 /********************************************************************** 00044 * PUBLIC: Short Message Service 00045 **********************************************************************/ 00046 00047 /** The size of an SMS storage buffer, including null terminator. 00048 */ 00049 #define SMS_BUFFER_SIZE 145 00050 00051 /** Count the number of messages in the device and optionally return a 00052 * list with indexes from the storage locations in the device. 00053 * 00054 * Note: init() should be called before this method can be used. 00055 * 00056 * @param stat what type of messages you can use: 00057 * "REC UNREAD", "REC READ", "STO UNSENT", "STO SENT", "ALL". 00058 * @param index list where to save the storage positions (pointer 00059 * to an array of ints). 00060 * @param num number of elements that can be stored in the list. 00061 * @return the number of messages, this can be bigger than num, 00062 * -1 on failure. 00063 */ 00064 int smsList(const char* stat = "ALL", int* index = NULL, int num = 0); 00065 00066 /** Read a message from a storage position. 00067 * 00068 * Note: init() should be called before this method can be used. 00069 * 00070 * @param index the storage position to read. 00071 * @param num the originator address (16 chars including terminator). 00072 * @param buf a buffer where to save the short message. 00073 * @param len the length of buf. 00074 * @return true if successful, false otherwise. 00075 */ 00076 bool smsRead(int index, char* num, char* buf, int len); 00077 00078 /** Delete a message. 00079 * 00080 * Note: init() should be called before this method can be used. 00081 * 00082 * @param index the storage position to delete. 00083 * @return true if successful, false otherwise. 00084 */ 00085 bool smsDelete(int index); 00086 00087 /** Send a message to a recipient. 00088 * 00089 * Note: init() and nwk_registration() should be called before 00090 * this method can be used. 00091 * 00092 * @param num the phone number of the recipient as a null terminated 00093 * string. Note: no spaces are allowed in this string. 00094 * @param buf the content of the message to sent, null terminated. 00095 * @return true if successful, false otherwise. 00096 */ 00097 bool smsSend(const char* num, const char* buf); 00098 00099 /********************************************************************** 00100 * PUBLIC: Unstructured Supplementary Service Data 00101 **********************************************************************/ 00102 00103 /** The maximum size of a USSD string (not including terminator). 00104 */ 00105 #define USSD_STRING_LENGTH 128 00106 00107 /** Make a USSD query. 00108 * 00109 * Note: init() should be called before using this method can be 00110 * used and, in many cases, nwk_registration() is also required as 00111 * the USSD may need network access. 00112 * 00113 * Note: some USSD commands relate to call waiting, call forwarding, 00114 * etc., which can result in multiple responses. This function returns 00115 * only the first response. Instantiate this class with debugOn set to 00116 * true to get a better view of what is really going on. If such 00117 * responses are important to you, you should subclass this class and 00118 * parse for them specifically and, probably, use specific AT commands 00119 * rather than USSD. 00120 * 00121 * @param cmd the USSD string to send e.g "*#100#". 00122 * @param buf a buffer where to save the reply, which 00123 * will always be returned zero terminated. 00124 * @param len the length of buf, set to USSD_STRING_LENGTH + 1 to 00125 * obtain the maximum length response plus terminator. 00126 * @return true if successful, false otherwise. 00127 */ 00128 bool ussdCommand(const char* cmd, char* buf, int len); 00129 00130 /********************************************************************** 00131 * PUBLIC: Module File System 00132 **********************************************************************/ 00133 00134 /** Delete a file from the module's local file system. An attempt 00135 * to delete a non-existent file will fail. 00136 * 00137 * Note: init() should be called before this method can be used. 00138 * 00139 * @param filename the name of the file. 00140 * @return true if successful, false otherwise. 00141 */ 00142 bool delFile(const char* filename); 00143 00144 /** Write some data to a file in the module's local file system. 00145 * 00146 * Note: init() should be called before this method can be used. 00147 * 00148 * @param filename the name of the file. 00149 * @param buf the data to write. 00150 * @param len the size of the data to write. 00151 * @return the number of bytes written. 00152 */ 00153 int writeFile(const char* filename, const char* buf, int len); 00154 00155 /** Read a file from the module's local file system. 00156 * 00157 * Note: init() should be called before this method can be used. 00158 * 00159 * @param filename the name of the file 00160 * @param buf a buffer to hold the data 00161 * @param len the size to read 00162 * @return the number of bytes read 00163 */ 00164 int readFile(const char* filename, char* buf, int len); 00165 00166 /** Retrieve the file size from the module's local file system. 00167 * 00168 * Note: init() should be called before this method can be used. 00169 * 00170 * @param filename the name of the file. 00171 * @return the file size in bytes. 00172 */ 00173 int fileSize(const char* filename); 00174 00175 protected: 00176 00177 /********************************************************************** 00178 * PROTECTED: Short Message Service 00179 **********************************************************************/ 00180 00181 /** The number type for telephone numbers without a + on the front 00182 */ 00183 #define TYPE_OF_ADDRESS_NATIONAL 129 00184 00185 /** The number type for telephone numbers with a + on the front 00186 */ 00187 #define TYPE_OF_ADDRESS_INTERNATIONAL 145 00188 00189 /** Convert a #define to a string 00190 */ 00191 #define stringify(a) str(a) 00192 #define str(a) #a 00193 00194 /** Place to store the index of an SMS message. 00195 */ 00196 int *_userSmsIndex; 00197 00198 /** The number of SMS message being returned to the user. 00199 */ 00200 int _userSmsNum; 00201 00202 /** The number of SMS messages stored in the module. 00203 */ 00204 int _smsCount; 00205 00206 /** Temporary storage for an SMS message. 00207 */ 00208 char _smsBuf[SMS_BUFFER_SIZE]; 00209 00210 /** URC for Short Message listing. 00211 */ 00212 void CMGL_URC(); 00213 00214 /** URC for new SMS messages. 00215 */ 00216 void CMTI_URC(); 00217 00218 /********************************************************************** 00219 * PROTECTED: Unstructured Supplementary Service Data 00220 **********************************************************************/ 00221 00222 /** A buffer for the string assembled from the URC. 00223 */ 00224 char * _ssUrcBuf; 00225 00226 /** URC for USSD. 00227 */ 00228 void CUSD_URC(); 00229 00230 /** URC for call waiting. 00231 */ 00232 void CCWA_URC(); 00233 00234 /** URC for call forwarding. 00235 */ 00236 void CCFC_URC(); 00237 00238 /** URC for calling lined ID restriction. 00239 */ 00240 void CLIR_URC(); 00241 00242 /** URC for calling lined ID presentation. 00243 */ 00244 void CLIP_URC(); 00245 00246 /** URC for connected lined ID restriction. 00247 */ 00248 void COLR_URC(); 00249 00250 /** URC for connected lined ID presentation. 00251 */ 00252 void COLP_URC(); 00253 00254 /********************************************************************** 00255 * PROTECTED: File System 00256 **********************************************************************/ 00257 00258 /** The maximum size of a single read of file data. 00259 * Note: this should be no larger than BUFFERED_SERIAL_RXBUF_SIZE 00260 * (which defaults to 256) minus some margin for the AT command 00261 * stuff that precedes it (which includes the filename). A good 00262 * number is 192. If you want to use something bigger then add an 00263 * entry to the target_overrides section of your mbed_app.json of the 00264 * following form: 00265 * 00266 * "platform.buffered-serial-rxbuf-size": 1024 00267 */ 00268 00269 #define FILE_BUFFER_SIZE 192 00270 }; 00271 00272 #endif // _UBLOX_CELLULAR_DRIVER_GEN_ 00273
Generated on Tue Jul 12 2022 17:22:58 by 1.7.2