ublox-cellular-driver-gen Fork

Fork of ublox-cellular-driver-gen by u-blox

Committer:
rob.meades@u-blox.com
Date:
Thu Jun 15 01:14:18 2017 +0100
Revision:
5:b935404dcf7c
Parent:
3:027c9eaec52c
Tests now pass on C027: cope with filenames being returned without quotation marks, reduce file size to write since some modules can't keep up when there's no HW flow control, increase USSD timeout, simplify JSON template and run test without debug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:bb5fabac67ab 1 /* Copyright (c) 2017 ARM Limited
RobMeades 0:bb5fabac67ab 2 *
RobMeades 0:bb5fabac67ab 3 * Licensed under the Apache License, Version 2.0 (the "License");
RobMeades 0:bb5fabac67ab 4 * you may not use this file except in compliance with the License.
RobMeades 0:bb5fabac67ab 5 * You may obtain a copy of the License at
RobMeades 0:bb5fabac67ab 6 *
RobMeades 0:bb5fabac67ab 7 * http://www.apache.org/licenses/LICENSE-2.0
RobMeades 0:bb5fabac67ab 8 *
RobMeades 0:bb5fabac67ab 9 * Unless required by applicable law or agreed to in writing, software
RobMeades 0:bb5fabac67ab 10 * distributed under the License is distributed on an "AS IS" BASIS,
RobMeades 0:bb5fabac67ab 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
RobMeades 0:bb5fabac67ab 12 * See the License for the specific language governing permissions and
RobMeades 0:bb5fabac67ab 13 * limitations under the License.
RobMeades 0:bb5fabac67ab 14 */
RobMeades 0:bb5fabac67ab 15
RobMeades 0:bb5fabac67ab 16 #ifndef _UBLOX_CELLULAR_DRIVER_GEN_
RobMeades 0:bb5fabac67ab 17 #define _UBLOX_CELLULAR_DRIVER_GEN_
RobMeades 0:bb5fabac67ab 18
rob.meades@u-blox.com 3:027c9eaec52c 19 #include "UbloxCellularBase.h"
RobMeades 0:bb5fabac67ab 20
RobMeades 0:bb5fabac67ab 21 /** UbloxCellularDriverGen class
RobMeades 0:bb5fabac67ab 22 * This interface provide SMS, USSD and
RobMeades 0:bb5fabac67ab 23 * module File System functionality.
RobMeades 0:bb5fabac67ab 24 */
RobMeades 0:bb5fabac67ab 25 class UbloxCellularDriverGen: virtual public UbloxCellularBase {
RobMeades 0:bb5fabac67ab 26
RobMeades 0:bb5fabac67ab 27 public:
RobMeades 0:bb5fabac67ab 28 /** Constructor.
RobMeades 0:bb5fabac67ab 29 *
RobMeades 0:bb5fabac67ab 30 * @param tx the UART TX data pin to which the modem is attached.
RobMeades 0:bb5fabac67ab 31 * @param rx the UART RX data pin to which the modem is attached.
RobMeades 0:bb5fabac67ab 32 * @param baud the UART baud rate.
RobMeades 0:bb5fabac67ab 33 * @param debugOn true to switch AT interface debug on, otherwise false.
RobMeades 0:bb5fabac67ab 34 */
RobMeades 0:bb5fabac67ab 35 UbloxCellularDriverGen(PinName tx = MDMTXD, PinName rx = MDMRXD,
RobMeades 0:bb5fabac67ab 36 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
RobMeades 0:bb5fabac67ab 37 bool debugOn = false);
RobMeades 0:bb5fabac67ab 38
RobMeades 0:bb5fabac67ab 39 /* Destructor.
RobMeades 0:bb5fabac67ab 40 */
RobMeades 0:bb5fabac67ab 41 ~UbloxCellularDriverGen();
RobMeades 0:bb5fabac67ab 42
RobMeades 0:bb5fabac67ab 43 /**********************************************************************
RobMeades 0:bb5fabac67ab 44 * PUBLIC: Short Message Service
RobMeades 0:bb5fabac67ab 45 **********************************************************************/
RobMeades 0:bb5fabac67ab 46
RobMeades 0:bb5fabac67ab 47 /** The size of an SMS storage buffer, including null terminator.
RobMeades 0:bb5fabac67ab 48 */
RobMeades 0:bb5fabac67ab 49 #define SMS_BUFFER_SIZE 145
RobMeades 0:bb5fabac67ab 50
RobMeades 0:bb5fabac67ab 51 /** Count the number of messages in the device and optionally return a
RobMeades 0:bb5fabac67ab 52 * list with indexes from the storage locations in the device.
RobMeades 0:bb5fabac67ab 53 *
RobMeades 0:bb5fabac67ab 54 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 55 *
RobMeades 0:bb5fabac67ab 56 * @param stat what type of messages you can use:
RobMeades 0:bb5fabac67ab 57 * "REC UNREAD", "REC READ", "STO UNSENT", "STO SENT", "ALL".
RobMeades 0:bb5fabac67ab 58 * @param index list where to save the storage positions (pointer
RobMeades 0:bb5fabac67ab 59 * to an array of ints).
RobMeades 0:bb5fabac67ab 60 * @param num number of elements that can be stored in the list.
RobMeades 0:bb5fabac67ab 61 * @return the number of messages, this can be bigger than num,
RobMeades 0:bb5fabac67ab 62 * -1 on failure.
RobMeades 0:bb5fabac67ab 63 */
RobMeades 0:bb5fabac67ab 64 int smsList(const char* stat = "ALL", int* index = NULL, int num = 0);
RobMeades 0:bb5fabac67ab 65
RobMeades 0:bb5fabac67ab 66 /** Read a message from a storage position.
RobMeades 0:bb5fabac67ab 67 *
RobMeades 0:bb5fabac67ab 68 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 69 *
RobMeades 0:bb5fabac67ab 70 * @param index the storage position to read.
RobMeades 0:bb5fabac67ab 71 * @param num the originator address (16 chars including terminator).
RobMeades 0:bb5fabac67ab 72 * @param buf a buffer where to save the short message.
RobMeades 0:bb5fabac67ab 73 * @param len the length of buf.
RobMeades 0:bb5fabac67ab 74 * @return true if successful, false otherwise.
RobMeades 0:bb5fabac67ab 75 */
RobMeades 0:bb5fabac67ab 76 bool smsRead(int index, char* num, char* buf, int len);
RobMeades 0:bb5fabac67ab 77
RobMeades 0:bb5fabac67ab 78 /** Delete a message.
RobMeades 0:bb5fabac67ab 79 *
RobMeades 0:bb5fabac67ab 80 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 81 *
RobMeades 0:bb5fabac67ab 82 * @param index the storage position to delete.
RobMeades 0:bb5fabac67ab 83 * @return true if successful, false otherwise.
RobMeades 0:bb5fabac67ab 84 */
RobMeades 0:bb5fabac67ab 85 bool smsDelete(int index);
RobMeades 0:bb5fabac67ab 86
RobMeades 0:bb5fabac67ab 87 /** Send a message to a recipient.
RobMeades 0:bb5fabac67ab 88 *
RobMeades 0:bb5fabac67ab 89 * Note: init() and nwk_registration() should be called before
RobMeades 0:bb5fabac67ab 90 * this method can be used.
RobMeades 0:bb5fabac67ab 91 *
RobMeades 0:bb5fabac67ab 92 * @param num the phone number of the recipient as a null terminated
RobMeades 0:bb5fabac67ab 93 * string. Note: no spaces are allowed in this string.
RobMeades 0:bb5fabac67ab 94 * @param buf the content of the message to sent, null terminated.
RobMeades 0:bb5fabac67ab 95 * @return true if successful, false otherwise.
RobMeades 0:bb5fabac67ab 96 */
RobMeades 0:bb5fabac67ab 97 bool smsSend(const char* num, const char* buf);
RobMeades 0:bb5fabac67ab 98
RobMeades 0:bb5fabac67ab 99 /**********************************************************************
RobMeades 0:bb5fabac67ab 100 * PUBLIC: Unstructured Supplementary Service Data
RobMeades 0:bb5fabac67ab 101 **********************************************************************/
RobMeades 0:bb5fabac67ab 102
RobMeades 0:bb5fabac67ab 103 /** The maximum size of a USSD string (not including terminator).
RobMeades 0:bb5fabac67ab 104 */
RobMeades 0:bb5fabac67ab 105 #define USSD_STRING_LENGTH 128
RobMeades 0:bb5fabac67ab 106
RobMeades 0:bb5fabac67ab 107 /** Make a USSD query.
RobMeades 0:bb5fabac67ab 108 *
RobMeades 0:bb5fabac67ab 109 * Note: init() should be called before using this method can be
RobMeades 0:bb5fabac67ab 110 * used and, in many cases, nwk_registration() is also required as
RobMeades 0:bb5fabac67ab 111 * the USSD may need network access.
RobMeades 0:bb5fabac67ab 112 *
RobMeades 0:bb5fabac67ab 113 * Note: some USSD commands relate to call waiting, call forwarding,
RobMeades 0:bb5fabac67ab 114 * etc., which can result in multiple responses. This function returns
RobMeades 0:bb5fabac67ab 115 * only the first response. Instantiate this class with debugOn set to
RobMeades 0:bb5fabac67ab 116 * true to get a better view of what is really going on. If such
RobMeades 0:bb5fabac67ab 117 * responses are important to you, you should subclass this class and
RobMeades 0:bb5fabac67ab 118 * parse for them specifically and, probably, use specific AT commands
RobMeades 0:bb5fabac67ab 119 * rather than USSD.
RobMeades 0:bb5fabac67ab 120 *
RobMeades 0:bb5fabac67ab 121 * @param cmd the USSD string to send e.g "*#100#".
RobMeades 0:bb5fabac67ab 122 * @param buf a buffer where to save the reply, which
RobMeades 0:bb5fabac67ab 123 * will always be returned zero terminated.
RobMeades 0:bb5fabac67ab 124 * @param len the length of buf, set to USSD_STRING_LENGTH + 1 to
RobMeades 0:bb5fabac67ab 125 * obtain the maximum length response plus terminator.
RobMeades 0:bb5fabac67ab 126 * @return true if successful, false otherwise.
RobMeades 0:bb5fabac67ab 127 */
RobMeades 0:bb5fabac67ab 128 bool ussdCommand(const char* cmd, char* buf, int len);
RobMeades 0:bb5fabac67ab 129
RobMeades 0:bb5fabac67ab 130 /**********************************************************************
RobMeades 0:bb5fabac67ab 131 * PUBLIC: Module File System
RobMeades 0:bb5fabac67ab 132 **********************************************************************/
RobMeades 0:bb5fabac67ab 133
RobMeades 0:bb5fabac67ab 134 /** Delete a file from the module's local file system. An attempt
RobMeades 0:bb5fabac67ab 135 * to delete a non-existent file will fail.
RobMeades 0:bb5fabac67ab 136 *
RobMeades 0:bb5fabac67ab 137 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 138 *
RobMeades 0:bb5fabac67ab 139 * @param filename the name of the file.
RobMeades 0:bb5fabac67ab 140 * @return true if successful, false otherwise.
RobMeades 0:bb5fabac67ab 141 */
RobMeades 0:bb5fabac67ab 142 bool delFile(const char* filename);
RobMeades 0:bb5fabac67ab 143
RobMeades 0:bb5fabac67ab 144 /** Write some data to a file in the module's local file system.
RobMeades 0:bb5fabac67ab 145 *
RobMeades 0:bb5fabac67ab 146 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 147 *
RobMeades 0:bb5fabac67ab 148 * @param filename the name of the file.
RobMeades 0:bb5fabac67ab 149 * @param buf the data to write.
RobMeades 0:bb5fabac67ab 150 * @param len the size of the data to write.
RobMeades 0:bb5fabac67ab 151 * @return the number of bytes written.
RobMeades 0:bb5fabac67ab 152 */
RobMeades 0:bb5fabac67ab 153 int writeFile(const char* filename, const char* buf, int len);
RobMeades 0:bb5fabac67ab 154
RobMeades 0:bb5fabac67ab 155 /** Read a file from the module's local file system.
RobMeades 0:bb5fabac67ab 156 *
RobMeades 0:bb5fabac67ab 157 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 158 *
RobMeades 0:bb5fabac67ab 159 * @param filename the name of the file
RobMeades 0:bb5fabac67ab 160 * @param buf a buffer to hold the data
RobMeades 0:bb5fabac67ab 161 * @param len the size to read
RobMeades 0:bb5fabac67ab 162 * @return the number of bytes read
RobMeades 0:bb5fabac67ab 163 */
RobMeades 0:bb5fabac67ab 164 int readFile(const char* filename, char* buf, int len);
RobMeades 0:bb5fabac67ab 165
RobMeades 0:bb5fabac67ab 166 /** Retrieve the file size from the module's local file system.
RobMeades 0:bb5fabac67ab 167 *
RobMeades 0:bb5fabac67ab 168 * Note: init() should be called before this method can be used.
RobMeades 0:bb5fabac67ab 169 *
RobMeades 0:bb5fabac67ab 170 * @param filename the name of the file.
RobMeades 0:bb5fabac67ab 171 * @return the file size in bytes.
RobMeades 0:bb5fabac67ab 172 */
RobMeades 0:bb5fabac67ab 173 int fileSize(const char* filename);
RobMeades 0:bb5fabac67ab 174
RobMeades 0:bb5fabac67ab 175 protected:
RobMeades 0:bb5fabac67ab 176
RobMeades 0:bb5fabac67ab 177 /**********************************************************************
RobMeades 0:bb5fabac67ab 178 * PROTECTED: Short Message Service
RobMeades 0:bb5fabac67ab 179 **********************************************************************/
RobMeades 0:bb5fabac67ab 180
RobMeades 0:bb5fabac67ab 181 /** The number type for telephone numbers without a + on the front
RobMeades 0:bb5fabac67ab 182 */
RobMeades 0:bb5fabac67ab 183 #define TYPE_OF_ADDRESS_NATIONAL 129
RobMeades 0:bb5fabac67ab 184
RobMeades 0:bb5fabac67ab 185 /** The number type for telephone numbers with a + on the front
RobMeades 0:bb5fabac67ab 186 */
RobMeades 0:bb5fabac67ab 187 #define TYPE_OF_ADDRESS_INTERNATIONAL 145
RobMeades 0:bb5fabac67ab 188
RobMeades 0:bb5fabac67ab 189 /** Convert a #define to a string
RobMeades 0:bb5fabac67ab 190 */
RobMeades 0:bb5fabac67ab 191 #define stringify(a) str(a)
RobMeades 0:bb5fabac67ab 192 #define str(a) #a
RobMeades 0:bb5fabac67ab 193
RobMeades 0:bb5fabac67ab 194 /** Place to store the index of an SMS message.
RobMeades 0:bb5fabac67ab 195 */
RobMeades 0:bb5fabac67ab 196 int *_userSmsIndex;
RobMeades 0:bb5fabac67ab 197
RobMeades 0:bb5fabac67ab 198 /** The number of SMS message being returned to the user.
RobMeades 0:bb5fabac67ab 199 */
RobMeades 0:bb5fabac67ab 200 int _userSmsNum;
RobMeades 0:bb5fabac67ab 201
RobMeades 0:bb5fabac67ab 202 /** The number of SMS messages stored in the module.
RobMeades 0:bb5fabac67ab 203 */
RobMeades 0:bb5fabac67ab 204 int _smsCount;
RobMeades 0:bb5fabac67ab 205
RobMeades 0:bb5fabac67ab 206 /** Temporary storage for an SMS message.
RobMeades 0:bb5fabac67ab 207 */
RobMeades 0:bb5fabac67ab 208 char _smsBuf[SMS_BUFFER_SIZE];
RobMeades 0:bb5fabac67ab 209
RobMeades 0:bb5fabac67ab 210 /** URC for Short Message listing.
RobMeades 0:bb5fabac67ab 211 */
RobMeades 0:bb5fabac67ab 212 void CMGL_URC();
RobMeades 0:bb5fabac67ab 213
RobMeades 0:bb5fabac67ab 214 /** URC for new SMS messages.
RobMeades 0:bb5fabac67ab 215 */
RobMeades 0:bb5fabac67ab 216 void CMTI_URC();
RobMeades 0:bb5fabac67ab 217
RobMeades 0:bb5fabac67ab 218 /**********************************************************************
RobMeades 0:bb5fabac67ab 219 * PROTECTED: Unstructured Supplementary Service Data
RobMeades 0:bb5fabac67ab 220 **********************************************************************/
RobMeades 0:bb5fabac67ab 221
RobMeades 0:bb5fabac67ab 222 /** A buffer for the string assembled from the URC.
RobMeades 0:bb5fabac67ab 223 */
RobMeades 0:bb5fabac67ab 224 char * _ssUrcBuf;
RobMeades 0:bb5fabac67ab 225
rob.meades@u-blox.com 5:b935404dcf7c 226 /** URC for USSD.
rob.meades@u-blox.com 5:b935404dcf7c 227 */
rob.meades@u-blox.com 5:b935404dcf7c 228 void CUSD_URC();
rob.meades@u-blox.com 5:b935404dcf7c 229
RobMeades 0:bb5fabac67ab 230 /** URC for call waiting.
RobMeades 0:bb5fabac67ab 231 */
RobMeades 0:bb5fabac67ab 232 void CCWA_URC();
RobMeades 0:bb5fabac67ab 233
RobMeades 0:bb5fabac67ab 234 /** URC for call forwarding.
RobMeades 0:bb5fabac67ab 235 */
RobMeades 0:bb5fabac67ab 236 void CCFC_URC();
RobMeades 0:bb5fabac67ab 237
RobMeades 0:bb5fabac67ab 238 /** URC for calling lined ID restriction.
RobMeades 0:bb5fabac67ab 239 */
RobMeades 0:bb5fabac67ab 240 void CLIR_URC();
RobMeades 0:bb5fabac67ab 241
RobMeades 0:bb5fabac67ab 242 /** URC for calling lined ID presentation.
RobMeades 0:bb5fabac67ab 243 */
RobMeades 0:bb5fabac67ab 244 void CLIP_URC();
RobMeades 0:bb5fabac67ab 245
RobMeades 0:bb5fabac67ab 246 /** URC for connected lined ID restriction.
RobMeades 0:bb5fabac67ab 247 */
RobMeades 0:bb5fabac67ab 248 void COLR_URC();
RobMeades 0:bb5fabac67ab 249
RobMeades 0:bb5fabac67ab 250 /** URC for connected lined ID presentation.
RobMeades 0:bb5fabac67ab 251 */
RobMeades 0:bb5fabac67ab 252 void COLP_URC();
RobMeades 0:bb5fabac67ab 253
RobMeades 0:bb5fabac67ab 254 /**********************************************************************
RobMeades 0:bb5fabac67ab 255 * PROTECTED: File System
RobMeades 0:bb5fabac67ab 256 **********************************************************************/
RobMeades 0:bb5fabac67ab 257
RobMeades 0:bb5fabac67ab 258 /** The maximum size of a single read of file data.
RobMeades 0:bb5fabac67ab 259 * Note: this should be no larger than BUFFERED_SERIAL_RXBUF_SIZE
RobMeades 0:bb5fabac67ab 260 * (which defaults to 256) minus some margin for the AT command
RobMeades 0:bb5fabac67ab 261 * stuff that precedes it (which includes the filename). A good
RobMeades 0:bb5fabac67ab 262 * number is 192. If you want to use something bigger then add an
RobMeades 0:bb5fabac67ab 263 * entry to the target_overrides section of your mbed_app.json of the
RobMeades 0:bb5fabac67ab 264 * following form:
RobMeades 0:bb5fabac67ab 265 *
RobMeades 0:bb5fabac67ab 266 * "platform.buffered-serial-rxbuf-size": 1024
RobMeades 0:bb5fabac67ab 267 */
RobMeades 0:bb5fabac67ab 268
RobMeades 0:bb5fabac67ab 269 #define FILE_BUFFER_SIZE 192
RobMeades 0:bb5fabac67ab 270 };
RobMeades 0:bb5fabac67ab 271
RobMeades 0:bb5fabac67ab 272 #endif // _UBLOX_CELLULAR_DRIVER_GEN_
RobMeades 0:bb5fabac67ab 273