Assert updated with the returned status code instead of URL

Dependencies:   ublox-at-cellular-interface

Committer:
rob.meades@u-blox.com
Date:
Tue Jun 13 00:12:01 2017 +0100
Revision:
5:9fd89567f769
Parent:
2:3c825852fdbe
Child:
11:3631f62bb359
Updated to use u-blox cellular libraries outside mbed but NOT yet fully working on C027.  Please hold off from using this library on C027 for now until a commit comes along stating that it is tested and working on C027.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:0b75e22c9231 1 /* Copyright (c) 2017 ARM Limited
RobMeades 0:0b75e22c9231 2 *
RobMeades 0:0b75e22c9231 3 * Licensed under the Apache License, Version 2.0 (the "License");
RobMeades 0:0b75e22c9231 4 * you may not use this file except in compliance with the License.
RobMeades 0:0b75e22c9231 5 * You may obtain a copy of the License at
RobMeades 0:0b75e22c9231 6 *
RobMeades 0:0b75e22c9231 7 * http://www.apache.org/licenses/LICENSE-2.0
RobMeades 0:0b75e22c9231 8 *
RobMeades 0:0b75e22c9231 9 * Unless required by applicable law or agreed to in writing, software
RobMeades 0:0b75e22c9231 10 * distributed under the License is distributed on an "AS IS" BASIS,
RobMeades 0:0b75e22c9231 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
RobMeades 0:0b75e22c9231 12 * See the License for the specific language governing permissions and
RobMeades 0:0b75e22c9231 13 * limitations under the License.
RobMeades 0:0b75e22c9231 14 */
RobMeades 0:0b75e22c9231 15
RobMeades 0:0b75e22c9231 16 #ifndef _UBLOX_AT_CELLULAR_INTERFACE_EXT_
RobMeades 0:0b75e22c9231 17 #define _UBLOX_AT_CELLULAR_INTERFACE_EXT_
RobMeades 0:0b75e22c9231 18
rob.meades@u-blox.com 5:9fd89567f769 19 #include "UbloxATCellularInterface.h"
RobMeades 0:0b75e22c9231 20 #include "UbloxCellularDriverGen.h"
RobMeades 0:0b75e22c9231 21
RobMeades 0:0b75e22c9231 22 /**UbloxATCellularInterfaceExt class.
RobMeades 0:0b75e22c9231 23 *
RobMeades 0:0b75e22c9231 24 * This interface extends the UbloxATCellularInterface to
RobMeades 0:0b75e22c9231 25 * include other features that use the IP stack on board the
RobMeades 0:0b75e22c9231 26 * cellular modem: HTTP, FTP and Cell Locate.
RobMeades 0:0b75e22c9231 27 *
RobMeades 0:0b75e22c9231 28 * Note: the UbloxCellularGeneric class is required because
RobMeades 0:0b75e22c9231 29 * reading a large HTTP response is performed via a modem
RobMeades 0:0b75e22c9231 30 * file system call and the UbloxCellularGeneric class is
RobMeades 0:0b75e22c9231 31 * where modem file system support is provided.
RobMeades 0:0b75e22c9231 32 */
RobMeades 0:0b75e22c9231 33 class UbloxATCellularInterfaceExt : public UbloxATCellularInterface, public UbloxCellularDriverGen {
RobMeades 0:0b75e22c9231 34
RobMeades 0:0b75e22c9231 35 public:
RobMeades 0:0b75e22c9231 36 /** Constructor.
RobMeades 0:0b75e22c9231 37 *
RobMeades 0:0b75e22c9231 38 * @param tx the UART TX data pin to which the modem is attached.
RobMeades 0:0b75e22c9231 39 * @param rx the UART RX data pin to which the modem is attached.
RobMeades 0:0b75e22c9231 40 * @param baud the UART baud rate.
RobMeades 0:0b75e22c9231 41 * @param debugOn true to switch AT interface debug on, otherwise false.
RobMeades 0:0b75e22c9231 42 */
RobMeades 0:0b75e22c9231 43 UbloxATCellularInterfaceExt(PinName tx = MDMTXD,
RobMeades 0:0b75e22c9231 44 PinName rx = MDMRXD,
RobMeades 0:0b75e22c9231 45 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
RobMeades 0:0b75e22c9231 46 bool debugOn = false);
RobMeades 0:0b75e22c9231 47
RobMeades 0:0b75e22c9231 48 /* Destructor.
RobMeades 0:0b75e22c9231 49 */
RobMeades 0:0b75e22c9231 50 virtual ~UbloxATCellularInterfaceExt();
RobMeades 0:0b75e22c9231 51
RobMeades 0:0b75e22c9231 52 /**********************************************************************
RobMeades 0:0b75e22c9231 53 * PUBLIC: General
RobMeades 0:0b75e22c9231 54 **********************************************************************/
RobMeades 0:0b75e22c9231 55
RobMeades 0:0b75e22c9231 56 /** Infinite timeout.
RobMeades 0:0b75e22c9231 57 */
RobMeades 0:0b75e22c9231 58 #define TIMEOUT_BLOCKING -1
RobMeades 0:0b75e22c9231 59
RobMeades 0:0b75e22c9231 60 /** A struct containing an HTTP or FTP error class and code
RobMeades 0:0b75e22c9231 61 */
RobMeades 0:0b75e22c9231 62 typedef struct {
RobMeades 0:0b75e22c9231 63 int eClass;
RobMeades 0:0b75e22c9231 64 int eCode;
RobMeades 0:0b75e22c9231 65 } Error;
RobMeades 0:0b75e22c9231 66
RobMeades 0:0b75e22c9231 67 /**********************************************************************
RobMeades 0:0b75e22c9231 68 * PUBLIC: HTTP
RobMeades 0:0b75e22c9231 69 **********************************************************************/
RobMeades 0:0b75e22c9231 70
RobMeades 0:0b75e22c9231 71 /** HTTP profile unused marker.
RobMeades 0:0b75e22c9231 72 */
RobMeades 0:0b75e22c9231 73 #define HTTP_PROF_UNUSED -1
RobMeades 0:0b75e22c9231 74
RobMeades 0:0b75e22c9231 75 /** HTTP configuration parameters (reference to HTTP control +UHTTP).
RobMeades 0:0b75e22c9231 76 */
RobMeades 0:0b75e22c9231 77 typedef enum {
RobMeades 0:0b75e22c9231 78 HTTP_IP_ADDRESS = 0,
RobMeades 0:0b75e22c9231 79 HTTP_SERVER_NAME = 1,
RobMeades 0:0b75e22c9231 80 HTTP_USER_NAME = 2,
RobMeades 0:0b75e22c9231 81 HTTP_PASSWORD = 3,
RobMeades 0:0b75e22c9231 82 HTTP_AUTH_TYPE = 4,
RobMeades 0:0b75e22c9231 83 HTTP_SERVER_PORT = 5,
RobMeades 0:0b75e22c9231 84 HTTP_SECURE = 6
RobMeades 0:0b75e22c9231 85 } HttpOpCode;
RobMeades 0:0b75e22c9231 86
RobMeades 0:0b75e22c9231 87 /** Type of HTTP Command.
RobMeades 0:0b75e22c9231 88 */
RobMeades 0:0b75e22c9231 89 typedef enum {
RobMeades 0:0b75e22c9231 90 HTTP_HEAD = 0,
RobMeades 0:0b75e22c9231 91 HTTP_GET = 1,
RobMeades 0:0b75e22c9231 92 HTTP_DELETE = 2,
RobMeades 0:0b75e22c9231 93 HTTP_PUT = 3,
RobMeades 0:0b75e22c9231 94 HTTP_POST_FILE = 4,
RobMeades 0:0b75e22c9231 95 HTTP_POST_DATA = 5
RobMeades 0:0b75e22c9231 96 } HttpCmd;
RobMeades 0:0b75e22c9231 97
RobMeades 0:0b75e22c9231 98 /** HTTP content types.
RobMeades 0:0b75e22c9231 99 */
RobMeades 0:0b75e22c9231 100 typedef enum {
RobMeades 0:0b75e22c9231 101 HTTP_CONTENT_URLENCODED = 0,
RobMeades 0:0b75e22c9231 102 HTTP_CONTENT_TEXT = 1,
RobMeades 0:0b75e22c9231 103 HTTP_CONTENT_OCTET_STREAM = 2,
RobMeades 0:0b75e22c9231 104 HTTP_CONTENT_FORM_DATA = 3,
RobMeades 0:0b75e22c9231 105 HTTP_CONTENT_JSON = 4,
RobMeades 0:0b75e22c9231 106 HTTP_CONTENT_XML = 5,
RobMeades 0:0b75e22c9231 107 HTTP_CONTENT_USER_DEFINED = 6
RobMeades 0:0b75e22c9231 108 } HttpContentType;
RobMeades 0:0b75e22c9231 109
RobMeades 0:0b75e22c9231 110 /** Find a free HTTP profile.
RobMeades 0:0b75e22c9231 111 *
RobMeades 0:0b75e22c9231 112 * A profile will be blocking when first allocated.
RobMeades 0:0b75e22c9231 113 *
RobMeades 0:0b75e22c9231 114 * @return the profile or negative if none are available.
RobMeades 0:0b75e22c9231 115 */
RobMeades 0:0b75e22c9231 116 int httpAllocProfile();
RobMeades 0:0b75e22c9231 117
RobMeades 0:0b75e22c9231 118 /** Free the HTTP profile.
RobMeades 0:0b75e22c9231 119 *
RobMeades 0:0b75e22c9231 120 * @param profile the HTTP profile handle.
RobMeades 0:0b75e22c9231 121 * @return true if successful, otherwise false.
RobMeades 0:0b75e22c9231 122 */
RobMeades 0:0b75e22c9231 123 bool httpFreeProfile(int profile);
RobMeades 0:0b75e22c9231 124
RobMeades 0:0b75e22c9231 125 /** Set the timeout for this profile.
RobMeades 0:0b75e22c9231 126 *
RobMeades 0:0b75e22c9231 127 * @param profile the HTTP profile handle.
RobMeades 0:0b75e22c9231 128 * @param timeout -1 blocking, else non-blocking timeout in milliseconds.
RobMeades 0:0b75e22c9231 129 * @return true if successful, otherwise false.
RobMeades 0:0b75e22c9231 130 */
RobMeades 0:0b75e22c9231 131 bool httpSetTimeout(int profile, int timeout);
RobMeades 0:0b75e22c9231 132
RobMeades 0:0b75e22c9231 133 /** Reset a HTTP profile back to defaults.
RobMeades 0:0b75e22c9231 134 *
RobMeades 0:0b75e22c9231 135 * This may be called if the state of a HTTP profile
RobMeades 0:0b75e22c9231 136 * during parameter setting or exchange of HTTP commands
RobMeades 0:0b75e22c9231 137 * has become confusing/unknown.
RobMeades 0:0b75e22c9231 138 *
RobMeades 0:0b75e22c9231 139 * @param httpProfile the HTTP profile to be reset.
RobMeades 0:0b75e22c9231 140 * @return true if successful, false otherwise.
RobMeades 0:0b75e22c9231 141 */
RobMeades 0:0b75e22c9231 142 bool httpResetProfile(int httpProfile);
RobMeades 0:0b75e22c9231 143
RobMeades 0:0b75e22c9231 144 /** Set HTTP parameters.
RobMeades 0:0b75e22c9231 145 *
RobMeades 0:0b75e22c9231 146 * This should be called as many times as is necessary
RobMeades 0:0b75e22c9231 147 * to set all the possible parameters (HttpOpCode).
RobMeades 0:0b75e22c9231 148 *
RobMeades 0:0b75e22c9231 149 * See section 28.1 of u-blox-ATCommands_Manual(UBX-13002752).pdf
RobMeades 0:0b75e22c9231 150 * for full details. By example:
RobMeades 0:0b75e22c9231 151 *
RobMeades 0:0b75e22c9231 152 * httpOpCode httpInPar
RobMeades 0:0b75e22c9231 153 * HTTP_IP_ADDRESS "145.33.18.10" (the target HTTP server IP address)
RobMeades 0:0b75e22c9231 154 * HTTP_SERVER_NAME "www.myhttpserver.com" (the target HTTP server name)
RobMeades 0:0b75e22c9231 155 * HTTP_USER_NAME "my_username"
RobMeades 0:0b75e22c9231 156 * HTTP_PASSWORD "my_password"
RobMeades 0:0b75e22c9231 157 * HTTP_AUTH_TYPE "0" for no authentication, "1" for username/password
RobMeades 0:0b75e22c9231 158 * authentication (the default is 0)
RobMeades 0:0b75e22c9231 159 * HTTP_SERVER_PORT "81" (default is port 80)
RobMeades 0:0b75e22c9231 160 * HTTP_SECURE "0" for no security, "1" for TLS (the default is 0)
RobMeades 0:0b75e22c9231 161 *
RobMeades 0:0b75e22c9231 162 * @param httpProfile the HTTP profile identifier.
RobMeades 0:0b75e22c9231 163 * @param httpOpCode the HTTP operation code.
RobMeades 0:0b75e22c9231 164 * @param httpInPar the HTTP input parameter.
RobMeades 0:0b75e22c9231 165 * @return true if successful, false otherwise.
RobMeades 0:0b75e22c9231 166 */
RobMeades 0:0b75e22c9231 167 bool httpSetPar(int httpProfile, HttpOpCode httpOpCode, const char * httpInPar);
RobMeades 0:0b75e22c9231 168
RobMeades 0:0b75e22c9231 169 /** Perform a HTTP command.
RobMeades 0:0b75e22c9231 170 *
RobMeades 0:0b75e22c9231 171 * See section 28.3 of u-blox-ATCommands_Manual(UBX-13002752).pdf
RobMeades 0:0b75e22c9231 172 * for full details. By example, it works like this:
RobMeades 0:0b75e22c9231 173 *
RobMeades 0:0b75e22c9231 174 * httpCmd httpPath rspFile sendStr httpContentType httpCustomPar
RobMeades 0:0b75e22c9231 175 * HEAD "path/file.html" NULL NULL 0 NULL
RobMeades 0:0b75e22c9231 176 * GET "path/file.html" NULL NULL 0 NULL
RobMeades 0:0b75e22c9231 177 * DELETE "path/file.html" NULL NULL 0 NULL
RobMeades 0:0b75e22c9231 178 * PUT "path/file.html" NULL "myfile.txt" 0 to 6 Note 1
RobMeades 0:0b75e22c9231 179 * POST_FILE "path/file.html" NULL "myfile.txt" 0 to 6 Note 1
RobMeades 0:0b75e22c9231 180 * POST "path/file.html" NULL "hello there!" 0 to 6 Note 1
RobMeades 0:0b75e22c9231 181 *
RobMeades 0:0b75e22c9231 182 * Note 1: httpCustomPar is only applicable when httpContentType = HTTP_CONTENT_USER_DEFINED.
RobMeades 0:0b75e22c9231 183 *
RobMeades 0:0b75e22c9231 184 * The server to which this command is directed must have previously been
RobMeades 0:0b75e22c9231 185 * set with a call to httpSetPar(). If the server requires TLS (i.e. "HTTPS"),
RobMeades 0:0b75e22c9231 186 * then set that up with httpSetPar() also (HTTP_SECURE).
RobMeades 0:0b75e22c9231 187 *
RobMeades 0:0b75e22c9231 188 * rspFile may be left as NULL as the server response will be returned in buf.
RobMeades 0:0b75e22c9231 189 * Alternatively, a rspFile may be given (e.g. "myresponse.txt") and this can
RobMeades 0:0b75e22c9231 190 * later be read from the modem file system using readFile().
RobMeades 0:0b75e22c9231 191 *
RobMeades 0:0b75e22c9231 192 * @param httpProfile the HTTP profile identifier.
RobMeades 0:0b75e22c9231 193 * @param httpCmd the HTTP command.
RobMeades 0:0b75e22c9231 194 * @param httpPath the path of resource on the HTTP server.
RobMeades 0:0b75e22c9231 195 * @param rspFile the local modem file where the server
RobMeades 0:0b75e22c9231 196 * response will be stored, use NULL for
RobMeades 0:0b75e22c9231 197 * don't care.
RobMeades 0:0b75e22c9231 198 * @param sendStr the filename or string to be sent
RobMeades 0:0b75e22c9231 199 * to the HTTP server with the command request.
RobMeades 0:0b75e22c9231 200 * @param httpContentType the HTTP Content-Type identifier.
RobMeades 0:0b75e22c9231 201 * @param httpCustomPar the parameter for a user defined HTTP Content-Type.
RobMeades 0:0b75e22c9231 202 * @param buf the buffer to read into.
RobMeades 0:0b75e22c9231 203 * @param len the size of the buffer to read into.
RobMeades 0:0b75e22c9231 204 * @return NULL if successful, otherwise a pointer to
RobMeades 0:0b75e22c9231 205 * a Error struct containing the error class and error
RobMeades 0:0b75e22c9231 206 * code, see section Appendix A.B of
RobMeades 0:0b75e22c9231 207 * u-blox-ATCommands_Manual(UBX-13002752).pdf for details.
RobMeades 0:0b75e22c9231 208 */
RobMeades 0:0b75e22c9231 209 Error * httpCommand(int httpProfile, HttpCmd httpCmd, const char* httpPath,
RobMeades 0:0b75e22c9231 210 const char* rspFile, const char* sendStr,
RobMeades 0:0b75e22c9231 211 int httpContentType, const char* httpCustomPar,
RobMeades 0:0b75e22c9231 212 char* buf, int len);
RobMeades 0:0b75e22c9231 213
RobMeades 0:0b75e22c9231 214 /**********************************************************************
RobMeades 0:0b75e22c9231 215 * PUBLIC: FTP
RobMeades 0:0b75e22c9231 216 **********************************************************************/
RobMeades 0:0b75e22c9231 217
RobMeades 0:0b75e22c9231 218 /** FTP configuration parameters (reference to FTP control +UFTP).
RobMeades 0:0b75e22c9231 219 */
RobMeades 0:0b75e22c9231 220 typedef enum {
RobMeades 0:0b75e22c9231 221 FTP_IP_ADDRESS = 0,
RobMeades 0:0b75e22c9231 222 FTP_SERVER_NAME = 1,
RobMeades 0:0b75e22c9231 223 FTP_USER_NAME = 2,
RobMeades 0:0b75e22c9231 224 FTP_PASSWORD = 3,
RobMeades 0:0b75e22c9231 225 FTP_ACCOUNT = 4,
RobMeades 0:0b75e22c9231 226 FTP_INACTIVITY_TIMEOUT = 5,
RobMeades 0:0b75e22c9231 227 FTP_MODE = 6,
RobMeades 0:0b75e22c9231 228 FTP_SERVER_PORT = 7,
RobMeades 0:0b75e22c9231 229 FTP_SECURE = 8,
RobMeades 0:0b75e22c9231 230 NUM_FTP_OP_CODES
RobMeades 0:0b75e22c9231 231 } FtpOpCode;
RobMeades 0:0b75e22c9231 232
RobMeades 0:0b75e22c9231 233 /** Type of FTP Command.
RobMeades 0:0b75e22c9231 234 */
RobMeades 0:0b75e22c9231 235 typedef enum {
RobMeades 0:0b75e22c9231 236 FTP_LOGOUT = 0,
RobMeades 0:0b75e22c9231 237 FTP_LOGIN = 1,
RobMeades 0:0b75e22c9231 238 FTP_DELETE_FILE = 2,
RobMeades 0:0b75e22c9231 239 FTP_RENAME_FILE = 3,
RobMeades 0:0b75e22c9231 240 FTP_GET_FILE = 4,
RobMeades 0:0b75e22c9231 241 FTP_PUT_FILE = 5,
RobMeades 0:0b75e22c9231 242 FTP_GET_DIRECT = 6,
RobMeades 0:0b75e22c9231 243 FTP_PUT_DIRECT = 7,
RobMeades 0:0b75e22c9231 244 FTP_CD = 8,
RobMeades 0:0b75e22c9231 245 FTP_MKDIR = 10,
RobMeades 0:0b75e22c9231 246 FTP_RMDIR = 11,
RobMeades 0:0b75e22c9231 247 FTP_FILE_INFO = 13,
RobMeades 0:0b75e22c9231 248 FTP_LS = 14,
RobMeades 0:0b75e22c9231 249 FTP_FOTA_FILE = 100
RobMeades 0:0b75e22c9231 250 } FtpCmd;
RobMeades 0:0b75e22c9231 251
RobMeades 0:0b75e22c9231 252 /** Set the timeout for FTP operations.
RobMeades 0:0b75e22c9231 253 *
RobMeades 0:0b75e22c9231 254 * @param timeout -1 blocking, else non-blocking timeout in milliseconds.
RobMeades 0:0b75e22c9231 255 * @return true if successful, otherwise false.
RobMeades 0:0b75e22c9231 256 */
RobMeades 0:0b75e22c9231 257 bool ftpSetTimeout(int timeout);
RobMeades 0:0b75e22c9231 258
RobMeades 0:0b75e22c9231 259 /** Reset the FTP configuration back to defaults.
RobMeades 0:0b75e22c9231 260 *
RobMeades 0:0b75e22c9231 261 * @return true if successful, false otherwise.
RobMeades 0:0b75e22c9231 262 */
RobMeades 0:0b75e22c9231 263 bool ftpResetPar();
RobMeades 0:0b75e22c9231 264
RobMeades 0:0b75e22c9231 265 /** Set FTP parameters.
RobMeades 0:0b75e22c9231 266 *
RobMeades 0:0b75e22c9231 267 * This should be called as many times as is necessary
RobMeades 0:0b75e22c9231 268 * to set all the possible parameters (FtpOpCode).
RobMeades 0:0b75e22c9231 269 *
RobMeades 0:0b75e22c9231 270 * See section 27.1 of u-blox-ATCommands_Manual(UBX-13002752).pdf
RobMeades 0:0b75e22c9231 271 * for full details. By example:
RobMeades 0:0b75e22c9231 272 *
RobMeades 0:0b75e22c9231 273 * ftpOpCode ftpInPar
RobMeades 0:0b75e22c9231 274 * FTP_IP_ADDRESS "145.33.18.10" (the target FTP server IP address)
RobMeades 0:0b75e22c9231 275 * FTP_SERVER_NAME "www.ftpserver.com" (the target FTP server name)
RobMeades 0:0b75e22c9231 276 * FTP_USER_NAME "my_username"
RobMeades 0:0b75e22c9231 277 * FTP_PASSWORD "my_password"
RobMeades 0:0b75e22c9231 278 * FTP_ACCOUNT "my_account" (not required by most FTP servers)
RobMeades 0:0b75e22c9231 279 * FTP_INACTIVITY_TIMEOUT "60" (the default is 0, which means no timeout)
RobMeades 0:0b75e22c9231 280 * FTP_MODE "0" for active, "1" for passive (the default is 0)
RobMeades 0:0b75e22c9231 281 * FTP_SERVER_PORT "25" (default is port 21)
RobMeades 0:0b75e22c9231 282 * FTP_SECURE "0" for no security, "1" for SFTP (the default is 0)
RobMeades 0:0b75e22c9231 283 *
RobMeades 0:0b75e22c9231 284 * @param ftpOpCode the FTP operation code.
RobMeades 0:0b75e22c9231 285 * @param ftpInPar the FTP input parameter.
RobMeades 0:0b75e22c9231 286 * @return true if successful, false otherwise.
RobMeades 0:0b75e22c9231 287 */
RobMeades 0:0b75e22c9231 288 bool ftpSetPar(FtpOpCode ftpOpCode, const char * ftpInPar);
RobMeades 0:0b75e22c9231 289
RobMeades 0:0b75e22c9231 290 /** Perform an FTP command.
RobMeades 0:0b75e22c9231 291 *
RobMeades 0:0b75e22c9231 292 * Connect() must have been called previously to establish a data
RobMeades 0:0b75e22c9231 293 * connection.
RobMeades 0:0b75e22c9231 294 *
RobMeades 0:0b75e22c9231 295 * See section 27.2 of u-blox-ATCommands_Manual(UBX-13002752).pdf
RobMeades 0:0b75e22c9231 296 * for full details. By example, it works like this:
RobMeades 0:0b75e22c9231 297 *
RobMeades 0:0b75e22c9231 298 * ftpCmd file1 file2 offset buf len
RobMeades 0:0b75e22c9231 299 * FTP_LOGOUT N/A N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 300 * FTP_LOGIN N/A N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 301 * FTP_DELETE_FILE "the_file" N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 302 * FTP_RENAME_FILE "old_name" "new_name" N/A N/A N/A
RobMeades 0:0b75e22c9231 303 * FTP_GET_FILE "the_file" Note 1 0 - 65535 N/A N/A (Notes 2)
RobMeades 0:0b75e22c9231 304 * FTP_PUT_FILE "the_file" Note 1 0 - 65535 N/A N/A (Note 2)
RobMeades 0:0b75e22c9231 305 * FTP_CD "dir1\dir2" N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 306 * FTP_MKDIR "newdir" N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 307 * FTP_RMDIR "dir" N/A N/A N/A N/A
RobMeades 0:0b75e22c9231 308 * FTP_FILE_INFO "the_path" N/A N/A Note 3
RobMeades 0:0b75e22c9231 309 * FTP_LS "the_path" N/A N/A Note 3
RobMeades 0:0b75e22c9231 310 * FTP_FOTA_FILE "the_file" N/A N/A Note 4
RobMeades 0:0b75e22c9231 311 *
RobMeades 0:0b75e22c9231 312 * Note 1: for this case, file2 is the name that the file should be
RobMeades 0:0b75e22c9231 313 * given when it arrives (in the modem file system for a GET, at the FTP
RobMeades 0:0b75e22c9231 314 * server for a PUT); if set to NULL then file1 is used.
RobMeades 0:0b75e22c9231 315 * Note 2: the file will placed into the modem file system for the
RobMeades 0:0b75e22c9231 316 * GET case (and can be read with readFile()), or must already be in the
RobMeades 0:0b75e22c9231 317 * modem file system, (can be written using writeFile()) for the PUT case.
RobMeades 0:0b75e22c9231 318 * Note 3: buf should point to the location where the file info
RobMeades 0:0b75e22c9231 319 * or directory listing is to be stored and len should be the maximum
RobMeades 0:0b75e22c9231 320 * length that can be stored.
RobMeades 0:0b75e22c9231 321 * Note 4: a hex string representing the MD5 sum of the FOTA file will be
RobMeades 0:0b75e22c9231 322 * stored at buf; len must be at least 32 as an MD5 sum is 16 bytes.
RobMeades 0:0b75e22c9231 323 * FTP_FOTA_FILE is not supported on SARA-U2.
RobMeades 0:0b75e22c9231 324 * Note 5: FTP_GET_DIRECT and FTP_PUT_DIRECT are not supported by
RobMeades 0:0b75e22c9231 325 * this driver.
RobMeades 0:0b75e22c9231 326 *
RobMeades 0:0b75e22c9231 327 * @param ftpCmd the FTP command.
RobMeades 0:0b75e22c9231 328 * @param file1 the first file name if required (NULL otherwise).
RobMeades 0:0b75e22c9231 329 * @param file2 the second file name if required (NULL otherwise).
RobMeades 0:0b75e22c9231 330 * @param offset the offset (in bytes) at which to begin the get
RobMeades 0:0b75e22c9231 331 * or put operation within the file.
RobMeades 0:0b75e22c9231 332 * @param buf pointer to a buffer, required for FTP_DIRECT mode
RobMeades 0:0b75e22c9231 333 * and FTP_LS only.
RobMeades 0:0b75e22c9231 334 * @param len the size of buf.
RobMeades 0:0b75e22c9231 335 * @return NULL if successful, otherwise a pointer to
RobMeades 0:0b75e22c9231 336 * a Error struct containing the error class and error
RobMeades 0:0b75e22c9231 337 * code, see section Appendix A.B of
RobMeades 0:0b75e22c9231 338 * u-blox-ATCommands_Manual(UBX-13002752).pdf for details.
RobMeades 0:0b75e22c9231 339 */
RobMeades 0:0b75e22c9231 340 Error *ftpCommand(FtpCmd ftpCmd, const char* file1 = NULL, const char* file2 = NULL,
RobMeades 0:0b75e22c9231 341 int offset = 0, char* buf = NULL, int len = 0);
RobMeades 0:0b75e22c9231 342
RobMeades 0:0b75e22c9231 343 /**********************************************************************
RobMeades 0:0b75e22c9231 344 * PUBLIC: Cell Locate
RobMeades 0:0b75e22c9231 345 **********************************************************************/
RobMeades 0:0b75e22c9231 346
RobMeades 0:0b75e22c9231 347 /** Which form of Cell Locate sensing to use.
RobMeades 0:0b75e22c9231 348 */
RobMeades 0:0b75e22c9231 349 typedef enum {
RobMeades 0:0b75e22c9231 350 CELL_LAST,
RobMeades 0:0b75e22c9231 351 CELL_GNSS,
RobMeades 0:0b75e22c9231 352 CELL_LOCATE,
RobMeades 0:0b75e22c9231 353 CELL_HYBRID
RobMeades 0:0b75e22c9231 354 } CellSensType;
RobMeades 0:0b75e22c9231 355
RobMeades 0:0b75e22c9231 356 /** Types of Cell Locate response.
RobMeades 0:0b75e22c9231 357 */
RobMeades 0:0b75e22c9231 358 typedef enum {
RobMeades 0:0b75e22c9231 359 CELL_DETAILED = 1,
RobMeades 0:0b75e22c9231 360 CELL_MULTIHYP = 2
RobMeades 0:0b75e22c9231 361 } CellRespType;
RobMeades 0:0b75e22c9231 362
RobMeades 0:0b75e22c9231 363 /** Cell Locate data.
RobMeades 0:0b75e22c9231 364 */
RobMeades 0:0b75e22c9231 365 typedef struct {
RobMeades 0:0b75e22c9231 366 volatile bool validData; //!< Flag for indicating if data is valid.
RobMeades 0:0b75e22c9231 367 volatile struct tm time; //!< GPS Timestamp.
RobMeades 0:0b75e22c9231 368 volatile float longitude; //!< Estimated longitude, in degrees.
RobMeades 0:0b75e22c9231 369 volatile float latitude; //!< Estimated latitude, in degrees.
RobMeades 0:0b75e22c9231 370 volatile int altitude; //!< Estimated altitude, in meters^2.
RobMeades 0:0b75e22c9231 371 volatile int uncertainty; //!< Maximum possible error, in meters.
RobMeades 0:0b75e22c9231 372 volatile int speed; //!< Speed over ground m/s^2.
RobMeades 0:0b75e22c9231 373 volatile int direction; //!< Course over ground in degrees.
RobMeades 0:0b75e22c9231 374 volatile int verticalAcc; //!< Vertical accuracy, in meters^2.
RobMeades 0:0b75e22c9231 375 volatile CellSensType sensor; //!< Sensor used for last calculation.
RobMeades 0:0b75e22c9231 376 volatile int svUsed; //!< number of satellite used.
RobMeades 0:0b75e22c9231 377 } CellLocData;
RobMeades 0:0b75e22c9231 378
RobMeades 0:0b75e22c9231 379 /** Configure the Cell Locate TCP aiding server.
RobMeades 0:0b75e22c9231 380 *
RobMeades 0:0b75e22c9231 381 * Connect() must have been called previously to establish
RobMeades 0:0b75e22c9231 382 * a data connection.
RobMeades 0:0b75e22c9231 383 *
RobMeades 0:0b75e22c9231 384 * @param server_1 host name of the primary MGA server.
RobMeades 0:0b75e22c9231 385 * @param server_2 host name of the secondary MGA server.
RobMeades 0:0b75e22c9231 386 * @param token authentication token for MGA server access.
RobMeades 0:0b75e22c9231 387 * @param days the number of days into the future the off-line
RobMeades 0:0b75e22c9231 388 * data for the u-blox 7.
RobMeades 0:0b75e22c9231 389 * @param period the number of weeks into the future the off-line
RobMeades 0:0b75e22c9231 390 * data for u-blox M8.
RobMeades 0:0b75e22c9231 391 * @param resolution resolution of off-line data for u-blox M8: 1 every
RobMeades 0:0b75e22c9231 392 * day, 0 every other day.
RobMeades 0:0b75e22c9231 393 * @return true if the request is successful, otherwise false.
RobMeades 0:0b75e22c9231 394 */
RobMeades 0:0b75e22c9231 395 bool cellLocSrvTcp(const char* token, const char* server_1 = "cell-live1.services.u-blox.com",
RobMeades 0:0b75e22c9231 396 const char* server_2 = "cell-live2.services.u-blox.com",
RobMeades 0:0b75e22c9231 397 int days = 14, int period = 4, int resolution = 1);
RobMeades 0:0b75e22c9231 398
RobMeades 0:0b75e22c9231 399 /** Configure Cell Locate UDP aiding server.
RobMeades 0:0b75e22c9231 400 *
RobMeades 0:0b75e22c9231 401 * Connect() must have been called previously to establish
RobMeades 0:0b75e22c9231 402 * a data connection.
RobMeades 0:0b75e22c9231 403 *
RobMeades 0:0b75e22c9231 404 * @param server_1 host name of the primary MGA server.
RobMeades 0:0b75e22c9231 405 * @param port server port.
RobMeades 0:0b75e22c9231 406 * @param latency expected network latency in seconds from 0 to 10000 milliseconds.
RobMeades 0:0b75e22c9231 407 * @param mode Assist Now management, mode of operation:
RobMeades 0:0b75e22c9231 408 * 0 data downloaded at GNSS power up,
RobMeades 0:0b75e22c9231 409 * 1 automatically kept alive, manual download.
RobMeades 0:0b75e22c9231 410 * @return true if the request is successful, otherwise false.
RobMeades 0:0b75e22c9231 411 */
RobMeades 0:0b75e22c9231 412 bool cellLocSrvUdp(const char* server_1 = "cell-live1.services.u-blox.com",
RobMeades 0:0b75e22c9231 413 int port = 46434, int latency = 1000, int mode = 0);
RobMeades 0:0b75e22c9231 414
RobMeades 0:0b75e22c9231 415 /** Configure Cell Locate location sensor.
RobMeades 0:0b75e22c9231 416 *
RobMeades 0:0b75e22c9231 417 * @param scanMode network scan mode: 0 normal, 1 deep scan.
RobMeades 0:0b75e22c9231 418 * @return true if the request is successful, otherwise false.
RobMeades 0:0b75e22c9231 419 */
RobMeades 0:0b75e22c9231 420 bool cellLocConfig(int scanMode);
RobMeades 0:0b75e22c9231 421
RobMeades 0:0b75e22c9231 422 /** Request a one-shot Cell Locate.
RobMeades 0:0b75e22c9231 423 *
RobMeades 0:0b75e22c9231 424 * This function is non-blocking, the result is retrieved using cellLocGetxxx.
RobMeades 0:0b75e22c9231 425 *
rob.meades@u-blox.com 1:26a67ab07275 426 * Note: none of the CellLocate methods switch on the GNSS receiver chip.
rob.meades@u-blox.com 1:26a67ab07275 427 * That should be done by instantiating the GnssSerial or GnssI2C classes and
rob.meades@u-blox.com 1:26a67ab07275 428 * calling the init() method.
rob.meades@u-blox.com 1:26a67ab07275 429 *
RobMeades 0:0b75e22c9231 430 * Note: during the location process, unsolicited result codes will be returned
RobMeades 0:0b75e22c9231 431 * by the modem indicating progress and potentially flagging interesting errors.
RobMeades 0:0b75e22c9231 432 * In order to see these errors, instantiate this class with debugOn set to true.
RobMeades 0:0b75e22c9231 433 *
RobMeades 0:0b75e22c9231 434 * @param sensor sensor selection.
RobMeades 0:0b75e22c9231 435 * @param timeout timeout period in seconds (1 - 999).
RobMeades 0:0b75e22c9231 436 * @param accuracy target accuracy in meters (1 - 999999).
RobMeades 0:0b75e22c9231 437 * @param type detailed or multi-hypothesis.
RobMeades 0:0b75e22c9231 438 * @param hypothesis maximum desired number of responses from CellLocate (up to 16),
RobMeades 0:0b75e22c9231 439 * must be 1 if type is CELL_DETAILED.
RobMeades 0:0b75e22c9231 440 * @return true if the request is successful, otherwise false.
RobMeades 0:0b75e22c9231 441 */
RobMeades 0:0b75e22c9231 442 bool cellLocRequest(CellSensType sensor, int timeout, int accuracy,
RobMeades 0:0b75e22c9231 443 CellRespType type = CELL_DETAILED, int hypothesis = 1);
RobMeades 0:0b75e22c9231 444
RobMeades 0:0b75e22c9231 445 /** Get a position record.
RobMeades 0:0b75e22c9231 446 *
RobMeades 0:0b75e22c9231 447 * @param data pointer to a CellLocData structure where the location will be put.
RobMeades 0:0b75e22c9231 448 * @param index of the position to retrieve.
RobMeades 0:0b75e22c9231 449 * @return true if data has been retrieved and copied, false otherwise.
RobMeades 0:0b75e22c9231 450 */
RobMeades 0:0b75e22c9231 451 bool cellLocGetData(CellLocData *data, int index = 0);
RobMeades 0:0b75e22c9231 452
RobMeades 0:0b75e22c9231 453 /** Get the number of position records received.
RobMeades 0:0b75e22c9231 454 *
RobMeades 0:0b75e22c9231 455 * @return number of position records received.
RobMeades 0:0b75e22c9231 456 */
RobMeades 0:0b75e22c9231 457 int cellLocGetRes();
RobMeades 0:0b75e22c9231 458
RobMeades 0:0b75e22c9231 459 /** Get the number of position records expected to be received.
RobMeades 0:0b75e22c9231 460 *
RobMeades 0:0b75e22c9231 461 * @return number of position records expected to be received.
RobMeades 0:0b75e22c9231 462 */
RobMeades 0:0b75e22c9231 463 int cellLocGetExpRes();
RobMeades 0:0b75e22c9231 464
RobMeades 0:0b75e22c9231 465 protected:
RobMeades 0:0b75e22c9231 466
RobMeades 0:0b75e22c9231 467 /**********************************************************************
RobMeades 0:0b75e22c9231 468 * PROTECTED: HTTP
RobMeades 0:0b75e22c9231 469 **********************************************************************/
RobMeades 0:0b75e22c9231 470
RobMeades 0:0b75e22c9231 471 /** Check for timeout.
RobMeades 0:0b75e22c9231 472 */
RobMeades 0:0b75e22c9231 473 #define TIMEOUT(t, ms) ((ms != TIMEOUT_BLOCKING) && (ms < t.read_ms()))
RobMeades 0:0b75e22c9231 474
RobMeades 0:0b75e22c9231 475 /** Check for a valid profile.
RobMeades 0:0b75e22c9231 476 */
RobMeades 0:0b75e22c9231 477 #define IS_PROFILE(p) (((p) >= 0) && (((unsigned int) p) < (sizeof(_httpProfiles)/sizeof(_httpProfiles[0]))) \
RobMeades 0:0b75e22c9231 478 && (_httpProfiles[p].modemHandle != HTTP_PROF_UNUSED))
RobMeades 0:0b75e22c9231 479
RobMeades 0:0b75e22c9231 480 /** Management structure for HTTP profiles.
RobMeades 0:0b75e22c9231 481 *
RobMeades 0:0b75e22c9231 482 * It is possible to have up to 4 different HTTP profiles (LISA-C200, LISA-U200 and SARA-G350) having:
RobMeades 0:0b75e22c9231 483 *
RobMeades 0:0b75e22c9231 484 * @param handle the current HTTP profile is in handling state or not (default value is HTTP_ERROR).
RobMeades 0:0b75e22c9231 485 * @param timeout the timeout for the current HTTP command.
RobMeades 0:0b75e22c9231 486 * @param pending the status for the current HTTP command (in processing state or not).
RobMeades 0:0b75e22c9231 487 * @param cmd the code for the current HTTP command.
RobMeades 0:0b75e22c9231 488 * @param result the result for the current HTTP command once processed.
RobMeades 0:0b75e22c9231 489 */
RobMeades 0:0b75e22c9231 490 typedef struct {
RobMeades 0:0b75e22c9231 491 int modemHandle;
RobMeades 0:0b75e22c9231 492 int timeout;
RobMeades 0:0b75e22c9231 493 volatile bool pending;
RobMeades 0:0b75e22c9231 494 volatile int cmd;
RobMeades 0:0b75e22c9231 495 volatile int result;
RobMeades 0:0b75e22c9231 496 Error httpError;
RobMeades 0:0b75e22c9231 497 } HttpProfCtrl;
RobMeades 0:0b75e22c9231 498
RobMeades 0:0b75e22c9231 499 /** The HTTP profile storage.
RobMeades 0:0b75e22c9231 500 */
RobMeades 0:0b75e22c9231 501 HttpProfCtrl _httpProfiles[4];
RobMeades 0:0b75e22c9231 502
RobMeades 0:0b75e22c9231 503 /** Callback to capture the response to an HTTP command.
RobMeades 0:0b75e22c9231 504 */
RobMeades 0:0b75e22c9231 505 void UUHTTPCR_URC();
RobMeades 0:0b75e22c9231 506
RobMeades 0:0b75e22c9231 507 /** Find a profile with a given handle. If no handle is given, find the next
RobMeades 0:0b75e22c9231 508 * free profile.
RobMeades 0:0b75e22c9231 509 *
RobMeades 0:0b75e22c9231 510 * @param modemHandle the handle of the profile to find.
RobMeades 0:0b75e22c9231 511 * @return the profile handle or negative if not found/created.
RobMeades 0:0b75e22c9231 512 */
RobMeades 0:0b75e22c9231 513 int findProfile(int modemHandle = HTTP_PROF_UNUSED);
RobMeades 0:0b75e22c9231 514
RobMeades 0:0b75e22c9231 515 /** Helper function to get a HTTP command as a text string, useful
RobMeades 0:0b75e22c9231 516 * for debug purposes.
RobMeades 0:0b75e22c9231 517 *
RobMeades 0:0b75e22c9231 518 * @param httpCmdCode the HTTP command.
RobMeades 0:0b75e22c9231 519 * @return HTTP command in string format.
RobMeades 0:0b75e22c9231 520 */
RobMeades 0:0b75e22c9231 521 const char* getHttpCmd(HttpCmd httpCmd);
RobMeades 0:0b75e22c9231 522
RobMeades 0:0b75e22c9231 523 /**********************************************************************
RobMeades 0:0b75e22c9231 524 * PROTECTED: FTP
RobMeades 0:0b75e22c9231 525 **********************************************************************/
RobMeades 0:0b75e22c9231 526
RobMeades 0:0b75e22c9231 527 /** Unused FTP op code marker.
RobMeades 0:0b75e22c9231 528 */
RobMeades 0:0b75e22c9231 529 #define FTP_OP_CODE_UNUSED -1
RobMeades 0:0b75e22c9231 530
RobMeades 0:0b75e22c9231 531 /** The FTP timeout in milliseconds.
RobMeades 0:0b75e22c9231 532 */
RobMeades 0:0b75e22c9231 533 int _ftpTimeout;
RobMeades 0:0b75e22c9231 534
RobMeades 0:0b75e22c9231 535 /** A place to store the FTP op code for the last result.
RobMeades 0:0b75e22c9231 536 */
RobMeades 0:0b75e22c9231 537 volatile int _lastFtpOpCodeResult;
RobMeades 0:0b75e22c9231 538
RobMeades 0:0b75e22c9231 539 /** A place to store the last FTP result.
RobMeades 0:0b75e22c9231 540 */
RobMeades 0:0b75e22c9231 541 volatile int _lastFtpResult;
RobMeades 0:0b75e22c9231 542
RobMeades 0:0b75e22c9231 543 /** A place to store the last FTP op code for data response.
RobMeades 0:0b75e22c9231 544 */
RobMeades 0:0b75e22c9231 545 volatile int _lastFtpOpCodeData;
RobMeades 0:0b75e22c9231 546
RobMeades 0:0b75e22c9231 547 /** A place to store data returns from an FTP operation.
RobMeades 0:0b75e22c9231 548 */
RobMeades 0:0b75e22c9231 549 char * _ftpBuf;
RobMeades 0:0b75e22c9231 550
RobMeades 0:0b75e22c9231 551 /** The length of FTP data that can be stored (at _ftpBuf).
RobMeades 0:0b75e22c9231 552 */
RobMeades 0:0b75e22c9231 553 int _ftpBufLen;
RobMeades 0:0b75e22c9231 554
RobMeades 0:0b75e22c9231 555 /** storage for the last FTP error
RobMeades 0:0b75e22c9231 556 */
RobMeades 0:0b75e22c9231 557 Error _ftpError;
RobMeades 0:0b75e22c9231 558
RobMeades 0:0b75e22c9231 559 /** Callback to capture the result of an FTP command.
RobMeades 0:0b75e22c9231 560 */
RobMeades 0:0b75e22c9231 561 void UUFTPCR_URC();
RobMeades 0:0b75e22c9231 562
RobMeades 0:0b75e22c9231 563 /** Callback to capture data returned from an FTP command.
RobMeades 0:0b75e22c9231 564 */
RobMeades 0:0b75e22c9231 565 void UUFTPCD_URC();
RobMeades 0:0b75e22c9231 566
RobMeades 0:0b75e22c9231 567 /** Helper function to get an FTP command as a text string, useful
RobMeades 0:0b75e22c9231 568 * for debug purposes.
RobMeades 0:0b75e22c9231 569 *
RobMeades 0:0b75e22c9231 570 * @param ftpCmdCode the FTP command.
RobMeades 0:0b75e22c9231 571 * @return FTP command in string format.
RobMeades 0:0b75e22c9231 572 */
RobMeades 0:0b75e22c9231 573 const char * getFtpCmd(FtpCmd ftpCmd);
RobMeades 0:0b75e22c9231 574
RobMeades 0:0b75e22c9231 575 /**********************************************************************
RobMeades 0:0b75e22c9231 576 * PROTECTED: Cell Locate
RobMeades 0:0b75e22c9231 577 **********************************************************************/
RobMeades 0:0b75e22c9231 578
RobMeades 0:0b75e22c9231 579 /** The maximum number of hypotheses
RobMeades 0:0b75e22c9231 580 */
RobMeades 0:0b75e22c9231 581 #define CELL_MAX_HYP (16 + 1)
RobMeades 0:0b75e22c9231 582
RobMeades 0:0b75e22c9231 583 /** Received positions.
RobMeades 0:0b75e22c9231 584 */
RobMeades 0:0b75e22c9231 585 volatile int _locRcvPos;
RobMeades 0:0b75e22c9231 586
RobMeades 0:0b75e22c9231 587 /** Expected positions.
RobMeades 0:0b75e22c9231 588 */
RobMeades 0:0b75e22c9231 589 volatile int _locExpPos;
RobMeades 0:0b75e22c9231 590
RobMeades 0:0b75e22c9231 591 /** The Cell Locate data.
RobMeades 0:0b75e22c9231 592 */
RobMeades 0:0b75e22c9231 593 CellLocData _loc[CELL_MAX_HYP];
RobMeades 0:0b75e22c9231 594
RobMeades 0:0b75e22c9231 595 /** Buffer for the URC to work with
RobMeades 0:0b75e22c9231 596 */
RobMeades 0:0b75e22c9231 597 char urcBuf[128];
RobMeades 0:0b75e22c9231 598
RobMeades 0:0b75e22c9231 599 /** Callback to capture +UULOCIND.
RobMeades 0:0b75e22c9231 600 */
RobMeades 0:0b75e22c9231 601 void UULOCIND_URC();
RobMeades 0:0b75e22c9231 602
RobMeades 0:0b75e22c9231 603 /** Callback to capture +UULOC.
RobMeades 0:0b75e22c9231 604 */
RobMeades 0:0b75e22c9231 605 void UULOC_URC();
RobMeades 0:0b75e22c9231 606 };
RobMeades 0:0b75e22c9231 607
RobMeades 0:0b75e22c9231 608 #endif // _UBLOX_AT_CELLULAR_INTERFACE_EXT_
RobMeades 0:0b75e22c9231 609