This class adds HTTP, FTP and CellLocate client support for u-blox modules for the C027 and C030 boards (excepting the C030 N2xx flavour) from mbed 5.5 onwards. The HTTP, FTP and CellLocate operations are all hosted on the module, minimizing RAM consumption in the mbed MCU. It also sub-classes ublox-cellular-driver-gen to bring in SMS, USSD and modem file system support if you need to use these functions at the same time as the cellular interface.

Dependencies:   ublox-at-cellular-interface

Dependents:   example-ublox-at-cellular-interface-ext HelloMQTT ublox_new_driver_test example-ublox-at-cellular-interface-ext ... more

Committer:
Bilal Qamar
Date:
Mon Aug 26 16:55:43 2019 +0500
Revision:
28:4427f2e6bbab
Parent:
17:ac64a6b90925
Child:
35:6a6ee1adff84
HTTP Test TLS issue resolved

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:0b75e22c9231 1 /* Copyright (c) 2017 ublox 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 #include "UbloxATCellularInterfaceExt.h"
RobMeades 0:0b75e22c9231 17 #include "APN_db.h"
rob.meades@u-blox.com 5:9fd89567f769 18 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 19 #include "mbed_trace.h"
RobMeades 0:0b75e22c9231 20 #define TRACE_GROUP "UCAD"
RobMeades 0:0b75e22c9231 21 #else
rob.meades@u-blox.com 10:3b24bc50cc06 22 #define tr_debug(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 10:3b24bc50cc06 23 #define tr_info(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 10:3b24bc50cc06 24 #define tr_warn(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 10:3b24bc50cc06 25 #define tr_error(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__)
RobMeades 0:0b75e22c9231 26 #endif
RobMeades 0:0b75e22c9231 27
RobMeades 0:0b75e22c9231 28 /**********************************************************************
RobMeades 0:0b75e22c9231 29 * PROTECTED METHODS: HTTP
RobMeades 0:0b75e22c9231 30 **********************************************************************/
RobMeades 0:0b75e22c9231 31
RobMeades 0:0b75e22c9231 32 // Callback for HTTP result code handling.
RobMeades 0:0b75e22c9231 33 void UbloxATCellularInterfaceExt::UUHTTPCR_URC()
RobMeades 0:0b75e22c9231 34 {
RobMeades 0:0b75e22c9231 35 char buf[32];
RobMeades 0:0b75e22c9231 36 int a, b, c;
RobMeades 0:0b75e22c9231 37
RobMeades 0:0b75e22c9231 38 // Note: not calling _at->recv() from here as we're
RobMeades 0:0b75e22c9231 39 // already in an _at->recv()
RobMeades 0:0b75e22c9231 40 // +UUHTTPCR: <profile_id>,<op_code>,<param_val>
RobMeades 0:0b75e22c9231 41 if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
RobMeades 0:0b75e22c9231 42 if (sscanf(buf, ": %d,%d,%d", &a, &b, &c) == 3) {
RobMeades 0:0b75e22c9231 43 _httpProfiles[a].cmd = b; // Command
RobMeades 0:0b75e22c9231 44 _httpProfiles[a].result = c; // Result
RobMeades 0:0b75e22c9231 45 debug_if(_debug_trace_on, "%s on profile %d, result code is %d\n", getHttpCmd((HttpCmd) b), a, c);
RobMeades 0:0b75e22c9231 46 }
RobMeades 0:0b75e22c9231 47 }
RobMeades 0:0b75e22c9231 48 }
RobMeades 0:0b75e22c9231 49
RobMeades 0:0b75e22c9231 50 // Find a given profile. NOTE: LOCK() before calling.
RobMeades 0:0b75e22c9231 51 int UbloxATCellularInterfaceExt::findProfile(int modemHandle)
RobMeades 0:0b75e22c9231 52 {
RobMeades 0:0b75e22c9231 53 for (unsigned int profile = 0; profile < (sizeof(_httpProfiles)/sizeof(_httpProfiles[0]));
RobMeades 0:0b75e22c9231 54 profile++) {
RobMeades 0:0b75e22c9231 55 if (_httpProfiles[profile].modemHandle == modemHandle) {
RobMeades 0:0b75e22c9231 56 return profile;
RobMeades 0:0b75e22c9231 57 }
RobMeades 0:0b75e22c9231 58 }
RobMeades 0:0b75e22c9231 59
RobMeades 0:0b75e22c9231 60 return HTTP_PROF_UNUSED;
RobMeades 0:0b75e22c9231 61 }
RobMeades 0:0b75e22c9231 62
RobMeades 0:0b75e22c9231 63 // Return a string representing an HTTP AT command.
RobMeades 0:0b75e22c9231 64 const char *UbloxATCellularInterfaceExt::getHttpCmd(HttpCmd httpCmd)
RobMeades 0:0b75e22c9231 65 {
RobMeades 0:0b75e22c9231 66 const char * str = "HTTP command not recognised";
RobMeades 0:0b75e22c9231 67
RobMeades 0:0b75e22c9231 68 switch (httpCmd) {
RobMeades 0:0b75e22c9231 69 case HTTP_HEAD:
RobMeades 0:0b75e22c9231 70 str = "HTTP HEAD command";
RobMeades 0:0b75e22c9231 71 break;
RobMeades 0:0b75e22c9231 72 case HTTP_GET:
RobMeades 0:0b75e22c9231 73 str = "HTTP GET command";
RobMeades 0:0b75e22c9231 74 break;
RobMeades 0:0b75e22c9231 75 case HTTP_DELETE:
RobMeades 0:0b75e22c9231 76 str = "HTTP DELETE command";
RobMeades 0:0b75e22c9231 77 break;
RobMeades 0:0b75e22c9231 78 case HTTP_PUT:
RobMeades 0:0b75e22c9231 79 str = "HTTP PUT command";
RobMeades 0:0b75e22c9231 80 break;
RobMeades 0:0b75e22c9231 81 case HTTP_POST_FILE:
RobMeades 0:0b75e22c9231 82 str = "HTTP POST file command";
RobMeades 0:0b75e22c9231 83 break;
RobMeades 0:0b75e22c9231 84 case HTTP_POST_DATA:
RobMeades 0:0b75e22c9231 85 str = "HTTP POST data command";
RobMeades 0:0b75e22c9231 86 break;
RobMeades 0:0b75e22c9231 87 default:
RobMeades 0:0b75e22c9231 88 break;
RobMeades 0:0b75e22c9231 89 }
RobMeades 0:0b75e22c9231 90
RobMeades 0:0b75e22c9231 91 return str;
RobMeades 0:0b75e22c9231 92 }
RobMeades 0:0b75e22c9231 93
RobMeades 0:0b75e22c9231 94 /**********************************************************************
RobMeades 0:0b75e22c9231 95 * PROTECTED METHODS: FTP
RobMeades 0:0b75e22c9231 96 **********************************************************************/
RobMeades 0:0b75e22c9231 97
RobMeades 0:0b75e22c9231 98 // Callback for FTP result code handling.
RobMeades 0:0b75e22c9231 99 void UbloxATCellularInterfaceExt::UUFTPCR_URC()
RobMeades 0:0b75e22c9231 100 {
RobMeades 0:0b75e22c9231 101 char buf[64];
RobMeades 0:0b75e22c9231 102 char md5[32];
RobMeades 0:0b75e22c9231 103
RobMeades 0:0b75e22c9231 104 // Note: not calling _at->recv() from here as we're
RobMeades 0:0b75e22c9231 105 // already in an _at->recv()
RobMeades 0:0b75e22c9231 106 // +UUFTPCR: <op_code>,<ftp_result>[,<md5_sum>]
RobMeades 0:0b75e22c9231 107 if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
RobMeades 0:0b75e22c9231 108 if (sscanf(buf, ": %d,%d,%32[^\n]\n", &_lastFtpOpCodeResult, &_lastFtpResult, md5) == 3) {
RobMeades 0:0b75e22c9231 109 // Store the MD5 sum if we can
RobMeades 0:0b75e22c9231 110 if ((_ftpBuf != NULL) && (_ftpBufLen >= 32)) {
RobMeades 0:0b75e22c9231 111 memcpy (_ftpBuf, md5, 32);
RobMeades 0:0b75e22c9231 112 if (_ftpBufLen == 33) {
RobMeades 0:0b75e22c9231 113 *(buf + 32) = 0; // Add a terminator if there's room
RobMeades 0:0b75e22c9231 114 }
RobMeades 0:0b75e22c9231 115 }
RobMeades 0:0b75e22c9231 116 }
RobMeades 0:0b75e22c9231 117 debug_if(_debug_trace_on, "%s result code is %d\n",
RobMeades 0:0b75e22c9231 118 getFtpCmd((FtpCmd) _lastFtpOpCodeResult), _lastFtpResult);
RobMeades 0:0b75e22c9231 119 }
RobMeades 0:0b75e22c9231 120 }
RobMeades 0:0b75e22c9231 121
RobMeades 0:0b75e22c9231 122 // Callback for FTP data handling.
RobMeades 0:0b75e22c9231 123 void UbloxATCellularInterfaceExt::UUFTPCD_URC()
RobMeades 0:0b75e22c9231 124 {
RobMeades 0:0b75e22c9231 125 char buf[32];
RobMeades 0:0b75e22c9231 126 char *ftpBufPtr = _ftpBuf;
RobMeades 0:0b75e22c9231 127 int ftpDataLen;
RobMeades 0:0b75e22c9231 128
RobMeades 0:0b75e22c9231 129 // Note: not calling _at->recv() from here as we're
RobMeades 0:0b75e22c9231 130 // already in an _at->recv()
RobMeades 0:0b75e22c9231 131 // +UUFTPCD: <op_code>,<ftp_data_len>,<ftp_data_in_quotes>
RobMeades 0:0b75e22c9231 132 if (read_at_to_char(buf, sizeof(buf), '\"') > 0) {
RobMeades 0:0b75e22c9231 133 if (sscanf(buf, ": %d,%d,\"", &_lastFtpOpCodeData, &ftpDataLen) == 2) {
RobMeades 0:0b75e22c9231 134 if ((ftpBufPtr != NULL) && (_ftpBufLen > 0)) {
RobMeades 0:0b75e22c9231 135 if (ftpDataLen + 1 > _ftpBufLen) { // +1 for terminator
RobMeades 0:0b75e22c9231 136 ftpDataLen = _ftpBufLen - 1;
RobMeades 0:0b75e22c9231 137 }
RobMeades 0:0b75e22c9231 138 ftpBufPtr += _at->read(ftpBufPtr, ftpDataLen);
RobMeades 0:0b75e22c9231 139 *ftpBufPtr = 0; // Add terminator
RobMeades 0:0b75e22c9231 140 }
RobMeades 0:0b75e22c9231 141 }
RobMeades 0:0b75e22c9231 142 }
RobMeades 0:0b75e22c9231 143 }
RobMeades 0:0b75e22c9231 144
RobMeades 0:0b75e22c9231 145 // Return a string representing an FTP AT command.
RobMeades 0:0b75e22c9231 146 const char *UbloxATCellularInterfaceExt::getFtpCmd(FtpCmd ftpCmd)
RobMeades 0:0b75e22c9231 147 {
RobMeades 0:0b75e22c9231 148 const char * str = "FTP command not recognised";
RobMeades 0:0b75e22c9231 149
RobMeades 0:0b75e22c9231 150 switch (ftpCmd) {
RobMeades 0:0b75e22c9231 151 case FTP_LOGOUT:
RobMeades 0:0b75e22c9231 152 str = "FTP log out command";
RobMeades 0:0b75e22c9231 153 break;
RobMeades 0:0b75e22c9231 154 case FTP_LOGIN:
RobMeades 0:0b75e22c9231 155 str = "FTP log in command";
RobMeades 0:0b75e22c9231 156 break;
RobMeades 0:0b75e22c9231 157 case FTP_DELETE_FILE:
RobMeades 0:0b75e22c9231 158 str = "FTP delete file command";
RobMeades 0:0b75e22c9231 159 break;
RobMeades 0:0b75e22c9231 160 case FTP_RENAME_FILE:
RobMeades 0:0b75e22c9231 161 str = "FTP rename file command";
RobMeades 0:0b75e22c9231 162 break;
RobMeades 0:0b75e22c9231 163 case FTP_GET_FILE:
RobMeades 0:0b75e22c9231 164 str = "FTP get file command";
RobMeades 0:0b75e22c9231 165 break;
RobMeades 0:0b75e22c9231 166 case FTP_PUT_FILE:
RobMeades 0:0b75e22c9231 167 str = "FTP put file command";
RobMeades 0:0b75e22c9231 168 break;
RobMeades 0:0b75e22c9231 169 case FTP_CD:
RobMeades 0:0b75e22c9231 170 str = "FTP change directory command";
RobMeades 0:0b75e22c9231 171 break;
RobMeades 0:0b75e22c9231 172 case FTP_MKDIR:
RobMeades 0:0b75e22c9231 173 str = "FTP make directory command";
RobMeades 0:0b75e22c9231 174 break;
RobMeades 0:0b75e22c9231 175 case FTP_RMDIR:
RobMeades 0:0b75e22c9231 176 str = "FTP remove directory command";
RobMeades 0:0b75e22c9231 177 break;
RobMeades 0:0b75e22c9231 178 case FTP_FILE_INFO:
RobMeades 0:0b75e22c9231 179 str = "FTP file info command";
RobMeades 0:0b75e22c9231 180 break;
RobMeades 0:0b75e22c9231 181 case FTP_LS:
RobMeades 0:0b75e22c9231 182 str = "FTP directory list command";
RobMeades 0:0b75e22c9231 183 break;
RobMeades 0:0b75e22c9231 184 case FTP_FOTA_FILE:
RobMeades 0:0b75e22c9231 185 str = "FTP FOTA file command";
RobMeades 0:0b75e22c9231 186 break;
RobMeades 0:0b75e22c9231 187 default:
RobMeades 0:0b75e22c9231 188 break;
RobMeades 0:0b75e22c9231 189 }
RobMeades 0:0b75e22c9231 190
RobMeades 0:0b75e22c9231 191 return str;
RobMeades 0:0b75e22c9231 192 }
RobMeades 0:0b75e22c9231 193
RobMeades 0:0b75e22c9231 194 /**********************************************************************
RobMeades 0:0b75e22c9231 195 * PROTECTED METHODS: Cell Locate
RobMeades 0:0b75e22c9231 196 **********************************************************************/
RobMeades 0:0b75e22c9231 197
RobMeades 0:0b75e22c9231 198 // Callback for UULOCIND handling.
RobMeades 0:0b75e22c9231 199 void UbloxATCellularInterfaceExt::UULOCIND_URC()
RobMeades 0:0b75e22c9231 200 {
RobMeades 0:0b75e22c9231 201 char buf[32];
RobMeades 0:0b75e22c9231 202 int a, b;
RobMeades 0:0b75e22c9231 203
RobMeades 0:0b75e22c9231 204 // Note: not calling _at->recv() from here as we're
RobMeades 0:0b75e22c9231 205 // already in an _at->recv()
RobMeades 0:0b75e22c9231 206 // +UULOCIND: <step>,<result>
RobMeades 0:0b75e22c9231 207 if (read_at_to_char(buf, sizeof (buf), '\n') > 0) {
RobMeades 0:0b75e22c9231 208 if (sscanf(buf, " %d,%d", &a, &b) == 2) {
RobMeades 0:0b75e22c9231 209 switch (a) {
RobMeades 0:0b75e22c9231 210 case 0:
RobMeades 0:0b75e22c9231 211 debug_if(_debug_trace_on, "Network scan start\n");
RobMeades 0:0b75e22c9231 212 break;
RobMeades 0:0b75e22c9231 213 case 1:
RobMeades 0:0b75e22c9231 214 debug_if(_debug_trace_on, "Network scan end\n");
RobMeades 0:0b75e22c9231 215 break;
RobMeades 0:0b75e22c9231 216 case 2:
RobMeades 0:0b75e22c9231 217 debug_if(_debug_trace_on, "Requesting data from server\n");
RobMeades 0:0b75e22c9231 218 break;
RobMeades 0:0b75e22c9231 219 case 3:
RobMeades 0:0b75e22c9231 220 debug_if(_debug_trace_on, "Received data from server\n");
RobMeades 0:0b75e22c9231 221 break;
RobMeades 0:0b75e22c9231 222 case 4:
RobMeades 0:0b75e22c9231 223 debug_if(_debug_trace_on, "Sending feedback to server\n");
RobMeades 0:0b75e22c9231 224 break;
RobMeades 0:0b75e22c9231 225 default:
RobMeades 0:0b75e22c9231 226 debug_if(_debug_trace_on, "Unknown step\n");
RobMeades 0:0b75e22c9231 227 break;
RobMeades 0:0b75e22c9231 228 }
RobMeades 0:0b75e22c9231 229 switch (b) {
RobMeades 0:0b75e22c9231 230 case 0:
RobMeades 0:0b75e22c9231 231 // No error
RobMeades 0:0b75e22c9231 232 break;
RobMeades 0:0b75e22c9231 233 case 1:
RobMeades 0:0b75e22c9231 234 debug_if(_debug_trace_on, "Wrong URL!\n");
RobMeades 0:0b75e22c9231 235 break;
RobMeades 0:0b75e22c9231 236 case 2:
RobMeades 0:0b75e22c9231 237 debug_if(_debug_trace_on, "HTTP error!\n");
RobMeades 0:0b75e22c9231 238 break;
RobMeades 0:0b75e22c9231 239 case 3:
RobMeades 0:0b75e22c9231 240 debug_if(_debug_trace_on, "Create socket error!\n");
RobMeades 0:0b75e22c9231 241 break;
RobMeades 0:0b75e22c9231 242 case 4:
RobMeades 0:0b75e22c9231 243 debug_if(_debug_trace_on, "Close socket error!\n");
RobMeades 0:0b75e22c9231 244 break;
RobMeades 0:0b75e22c9231 245 case 5:
RobMeades 0:0b75e22c9231 246 debug_if(_debug_trace_on, "Write to socket error!\n");
RobMeades 0:0b75e22c9231 247 break;
RobMeades 0:0b75e22c9231 248 case 6:
RobMeades 0:0b75e22c9231 249 debug_if(_debug_trace_on, "Read from socket error!\n");
RobMeades 0:0b75e22c9231 250 break;
RobMeades 0:0b75e22c9231 251 case 7:
RobMeades 0:0b75e22c9231 252 debug_if(_debug_trace_on, "Connection/DNS error!\n");
RobMeades 0:0b75e22c9231 253 break;
RobMeades 0:0b75e22c9231 254 case 8:
RobMeades 0:0b75e22c9231 255 debug_if(_debug_trace_on, "Authentication token problem!\n");
RobMeades 0:0b75e22c9231 256 break;
RobMeades 0:0b75e22c9231 257 case 9:
RobMeades 0:0b75e22c9231 258 debug_if(_debug_trace_on, "Generic error!\n");
RobMeades 0:0b75e22c9231 259 break;
RobMeades 0:0b75e22c9231 260 case 10:
RobMeades 0:0b75e22c9231 261 debug_if(_debug_trace_on, "User terminated!\n");
RobMeades 0:0b75e22c9231 262 break;
RobMeades 0:0b75e22c9231 263 case 11:
RobMeades 0:0b75e22c9231 264 debug_if(_debug_trace_on, "No data from server!\n");
RobMeades 0:0b75e22c9231 265 break;
RobMeades 0:0b75e22c9231 266 default:
RobMeades 0:0b75e22c9231 267 debug_if(_debug_trace_on, "Unknown result!\n");
RobMeades 0:0b75e22c9231 268 break;
RobMeades 0:0b75e22c9231 269 }
RobMeades 0:0b75e22c9231 270 }
RobMeades 0:0b75e22c9231 271 }
RobMeades 0:0b75e22c9231 272 }
RobMeades 0:0b75e22c9231 273
RobMeades 0:0b75e22c9231 274 // Callback for UULOC URC handling.
RobMeades 0:0b75e22c9231 275 void UbloxATCellularInterfaceExt::UULOC_URC()
RobMeades 0:0b75e22c9231 276 {
RobMeades 0:0b75e22c9231 277 int a, b;
RobMeades 0:0b75e22c9231 278
RobMeades 0:0b75e22c9231 279 // Note: not calling _at->recv() from here as we're
RobMeades 0:0b75e22c9231 280 // already in an _at->recv()
RobMeades 0:0b75e22c9231 281
RobMeades 0:0b75e22c9231 282 // +UHTTPCR: <profile_id>,<op_code>,<param_val>
RobMeades 0:0b75e22c9231 283 if (read_at_to_char(urcBuf, sizeof (urcBuf), '\n') > 0) {
rob.meades@u-blox.com 1:26a67ab07275 284 // Response type 1
RobMeades 0:0b75e22c9231 285 // +UULOC: <date>,<time>,<lat>,<long>,<alt>,<uncertainty>,<speed>, <direction>,<vertical_acc>,<sensor_used>,<SV_used>,<antenna_status>, <jamming_status>
RobMeades 4:39acbc0111eb 286 if (sscanf(urcBuf, " %d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%d,%d,%d,%d,%d,%d,%*d,%*d",
RobMeades 0:0b75e22c9231 287 &_loc[0].time.tm_mday, &_loc[0].time.tm_mon,
RobMeades 0:0b75e22c9231 288 &_loc[0].time.tm_year, &_loc[0].time.tm_hour,
RobMeades 0:0b75e22c9231 289 &_loc[0].time.tm_min, &_loc[0].time.tm_sec,
RobMeades 0:0b75e22c9231 290 &_loc[0].latitude, &_loc[0].longitude, &_loc[0].altitude,
RobMeades 0:0b75e22c9231 291 &_loc[0].uncertainty, &_loc[0].speed, &_loc[0].direction,
RobMeades 0:0b75e22c9231 292 &_loc[0].verticalAcc,
RobMeades 0:0b75e22c9231 293 &b, &_loc[0].svUsed) == 15) {
RobMeades 0:0b75e22c9231 294 debug_if(_debug_trace_on, "Position found at index 0\n");
RobMeades 0:0b75e22c9231 295 _loc[0].sensor = (b == 0) ? CELL_LAST : (b == 1) ? CELL_GNSS :
RobMeades 0:0b75e22c9231 296 (b == 2) ? CELL_LOCATE : (b == 3) ? CELL_HYBRID : CELL_LAST;
rob.meades@u-blox.com 1:26a67ab07275 297 _loc[0].time.tm_year -= 1900;
RobMeades 0:0b75e22c9231 298 _loc[0].time.tm_mon -= 1;
RobMeades 0:0b75e22c9231 299 _loc[0].time.tm_wday = 0;
RobMeades 0:0b75e22c9231 300 _loc[0].time.tm_yday = 0;
RobMeades 0:0b75e22c9231 301 _loc[0].validData = true;
RobMeades 4:39acbc0111eb 302 // Uncertainty can appear as 4294967, which is
RobMeades 4:39acbc0111eb 303 // (2^32 - 1) / 1000, or -1. Since it is confusing
RobMeades 4:39acbc0111eb 304 // for the user to get a large positive number instead
RobMeades 4:39acbc0111eb 305 // of 0 -1, set it to -1 in th1s case.
RobMeades 4:39acbc0111eb 306 if (_loc[0].uncertainty == 4294967) {
RobMeades 4:39acbc0111eb 307 _loc[0].uncertainty = -1;
RobMeades 4:39acbc0111eb 308 }
RobMeades 4:39acbc0111eb 309 _locExpPos = 1;
RobMeades 0:0b75e22c9231 310 _locRcvPos++;
rob.meades@u-blox.com 1:26a67ab07275 311 // Response type 2, sensor used 1
RobMeades 0:0b75e22c9231 312 // +UULOC: <sol>,<num>,<sensor_used>,<date>,<time>,<lat>,<long>,<alt>,<uncertainty>,<speed>, <direction>,<vertical_acc>,,<SV_used>,<antenna_status>, <jamming_status>
RobMeades 4:39acbc0111eb 313 } else if (sscanf(urcBuf, " %d,%d,%d,%d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%d,%d,%d,%d,%d,%*d,%*d",
RobMeades 0:0b75e22c9231 314 &a, &_locExpPos, &b,
RobMeades 0:0b75e22c9231 315 &_loc[CELL_MAX_HYP - 1].time.tm_mday,
RobMeades 0:0b75e22c9231 316 &_loc[CELL_MAX_HYP - 1].time.tm_mon,
RobMeades 0:0b75e22c9231 317 &_loc[CELL_MAX_HYP - 1].time.tm_year,
RobMeades 0:0b75e22c9231 318 &_loc[CELL_MAX_HYP - 1].time.tm_hour,
RobMeades 0:0b75e22c9231 319 &_loc[CELL_MAX_HYP - 1].time.tm_min,
RobMeades 0:0b75e22c9231 320 &_loc[CELL_MAX_HYP - 1].time.tm_sec,
RobMeades 0:0b75e22c9231 321 &_loc[CELL_MAX_HYP - 1].latitude,
RobMeades 0:0b75e22c9231 322 &_loc[CELL_MAX_HYP - 1].longitude,
RobMeades 0:0b75e22c9231 323 &_loc[CELL_MAX_HYP - 1].altitude,
RobMeades 0:0b75e22c9231 324 &_loc[CELL_MAX_HYP - 1].uncertainty,
RobMeades 0:0b75e22c9231 325 &_loc[CELL_MAX_HYP - 1].speed,
RobMeades 0:0b75e22c9231 326 &_loc[CELL_MAX_HYP - 1].direction,
RobMeades 0:0b75e22c9231 327 &_loc[CELL_MAX_HYP - 1].verticalAcc,
RobMeades 0:0b75e22c9231 328 &_loc[CELL_MAX_HYP - 1].svUsed) == 17) {
RobMeades 0:0b75e22c9231 329 if (--a >= 0) {
RobMeades 0:0b75e22c9231 330 debug_if(_debug_trace_on, "Position found at index %d\n", a);
RobMeades 0:0b75e22c9231 331
RobMeades 0:0b75e22c9231 332 memcpy(&_loc[a], &_loc[CELL_MAX_HYP - 1], sizeof(*_loc));
RobMeades 0:0b75e22c9231 333
RobMeades 0:0b75e22c9231 334 _loc[a].sensor = (b == 0) ? CELL_LAST : (b == 1) ? CELL_GNSS :
RobMeades 0:0b75e22c9231 335 (b == 2) ? CELL_LOCATE : (b == 3) ? CELL_HYBRID : CELL_LAST;
rob.meades@u-blox.com 1:26a67ab07275 336 _loc[a].time.tm_year -= 1900;
RobMeades 0:0b75e22c9231 337 _loc[a].time.tm_mon -= 1;
RobMeades 0:0b75e22c9231 338 _loc[a].time.tm_wday = 0;
RobMeades 0:0b75e22c9231 339 _loc[a].time.tm_yday = 0;
RobMeades 4:39acbc0111eb 340 // Uncertainty can appear as 4294967, which is
RobMeades 4:39acbc0111eb 341 // (2^32 - 1) / 1000, or -1. Since it is confusing
RobMeades 4:39acbc0111eb 342 // for the user to get a large positive number instead
RobMeades 4:39acbc0111eb 343 // of 0 -1, set it to -1 in th1s case.
RobMeades 4:39acbc0111eb 344 if (_loc[a].uncertainty == 4294967) {
RobMeades 4:39acbc0111eb 345 _loc[a].uncertainty = -1;
RobMeades 4:39acbc0111eb 346 }
RobMeades 0:0b75e22c9231 347 _loc[a].validData = true;
RobMeades 0:0b75e22c9231 348 _locRcvPos++;
RobMeades 0:0b75e22c9231 349 }
rob.meades@u-blox.com 1:26a67ab07275 350 // Response type 2, sensor used 2
RobMeades 0:0b75e22c9231 351 //+UULOC: <sol>,<num>,<sensor_used>,<date>,<time>,<lat>,<long>,<alt>,<lat50>,<long50>,<major50>,<minor50>,<orientation50>,<confidence50>[,<lat95>,<long95>,<major95>,<minor95>,<orientation95>,<confidence95>]
RobMeades 4:39acbc0111eb 352 } else if (sscanf(urcBuf, " %d,%d,%d,%d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%*f,%*f,%d,%*d,%*d,%*d",
RobMeades 0:0b75e22c9231 353 &a, &_locExpPos, &b,
RobMeades 0:0b75e22c9231 354 &_loc[CELL_MAX_HYP - 1].time.tm_mday,
RobMeades 0:0b75e22c9231 355 &_loc[CELL_MAX_HYP - 1].time.tm_mon,
RobMeades 0:0b75e22c9231 356 &_loc[CELL_MAX_HYP - 1].time.tm_year,
RobMeades 0:0b75e22c9231 357 &_loc[CELL_MAX_HYP - 1].time.tm_hour,
RobMeades 0:0b75e22c9231 358 &_loc[CELL_MAX_HYP - 1].time.tm_min,
RobMeades 0:0b75e22c9231 359 &_loc[CELL_MAX_HYP - 1].time.tm_sec,
RobMeades 0:0b75e22c9231 360 &_loc[CELL_MAX_HYP - 1].latitude,
RobMeades 0:0b75e22c9231 361 &_loc[CELL_MAX_HYP - 1].longitude,
RobMeades 0:0b75e22c9231 362 &_loc[CELL_MAX_HYP - 1].altitude,
RobMeades 0:0b75e22c9231 363 &_loc[CELL_MAX_HYP - 1].uncertainty) == 13) {
RobMeades 0:0b75e22c9231 364 if (--a >= 0) {
RobMeades 0:0b75e22c9231 365
RobMeades 0:0b75e22c9231 366 debug_if(_debug_trace_on, "Position found at index %d\n", a);
RobMeades 0:0b75e22c9231 367
RobMeades 0:0b75e22c9231 368 memcpy(&_loc[a], &_loc[CELL_MAX_HYP - 1], sizeof(*_loc));
RobMeades 0:0b75e22c9231 369
RobMeades 0:0b75e22c9231 370 _loc[a].sensor = (b == 0) ? CELL_LAST : (b == 1) ? CELL_GNSS :
RobMeades 0:0b75e22c9231 371 (b == 2) ? CELL_LOCATE : (b == 3) ? CELL_HYBRID : CELL_LAST;
rob.meades@u-blox.com 1:26a67ab07275 372 _loc[a].time.tm_year -= 1900;
RobMeades 0:0b75e22c9231 373 _loc[a].time.tm_mon -= 1;
RobMeades 0:0b75e22c9231 374 _loc[a].time.tm_wday = 0;
RobMeades 0:0b75e22c9231 375 _loc[a].time.tm_yday = 0;
rob.meades@u-blox.com 1:26a67ab07275 376 _loc[a].speed = 0;
rob.meades@u-blox.com 1:26a67ab07275 377 _loc[a].direction = 0;
rob.meades@u-blox.com 1:26a67ab07275 378 _loc[a].verticalAcc = 0;
rob.meades@u-blox.com 1:26a67ab07275 379 _loc[a].svUsed = 0;
RobMeades 4:39acbc0111eb 380 // Uncertainty can appear as 4294967, which is
RobMeades 4:39acbc0111eb 381 // (2^32 - 1) / 1000, or -1. Since it is confusing
RobMeades 4:39acbc0111eb 382 // for the user to get a large positive number instead
RobMeades 4:39acbc0111eb 383 // of 0 -1, set it to -1 in th1s case.
RobMeades 4:39acbc0111eb 384 if (_loc[a].uncertainty == 4294967) {
RobMeades 4:39acbc0111eb 385 _loc[a].uncertainty = -1;
RobMeades 4:39acbc0111eb 386 }
rob.meades@u-blox.com 1:26a67ab07275 387 _loc[a].validData = true;
rob.meades@u-blox.com 1:26a67ab07275 388 _locRcvPos++;
rob.meades@u-blox.com 1:26a67ab07275 389 }
rob.meades@u-blox.com 1:26a67ab07275 390 // Response type 2, sensor used 0
rob.meades@u-blox.com 1:26a67ab07275 391 //+UULOC: <sol>,<num>,<sensor_used>,<date>,<time>,<lat>,<long>,<alt>,<uncertainty>
RobMeades 4:39acbc0111eb 392 } else if (sscanf(urcBuf, " %d,%d,%d,%d/%d/%d,%d:%d:%d.%*d,%f,%f,%d,%d",
rob.meades@u-blox.com 1:26a67ab07275 393 &a, &_locExpPos, &b,
rob.meades@u-blox.com 1:26a67ab07275 394 &_loc[CELL_MAX_HYP - 1].time.tm_mday,
rob.meades@u-blox.com 1:26a67ab07275 395 &_loc[CELL_MAX_HYP - 1].time.tm_mon,
rob.meades@u-blox.com 1:26a67ab07275 396 &_loc[CELL_MAX_HYP - 1].time.tm_year,
rob.meades@u-blox.com 1:26a67ab07275 397 &_loc[CELL_MAX_HYP - 1].time.tm_hour,
rob.meades@u-blox.com 1:26a67ab07275 398 &_loc[CELL_MAX_HYP - 1].time.tm_min,
rob.meades@u-blox.com 1:26a67ab07275 399 &_loc[CELL_MAX_HYP - 1].time.tm_sec,
rob.meades@u-blox.com 1:26a67ab07275 400 &_loc[CELL_MAX_HYP - 1].latitude,
rob.meades@u-blox.com 1:26a67ab07275 401 &_loc[CELL_MAX_HYP - 1].longitude,
rob.meades@u-blox.com 1:26a67ab07275 402 &_loc[CELL_MAX_HYP - 1].altitude,
rob.meades@u-blox.com 1:26a67ab07275 403 &_loc[CELL_MAX_HYP - 1].uncertainty) == 13) {
rob.meades@u-blox.com 1:26a67ab07275 404 if (--a >= 0) {
rob.meades@u-blox.com 1:26a67ab07275 405
rob.meades@u-blox.com 1:26a67ab07275 406 debug_if(_debug_trace_on, "Position found at index %d\n", a);
rob.meades@u-blox.com 1:26a67ab07275 407
rob.meades@u-blox.com 1:26a67ab07275 408 memcpy(&_loc[a], &_loc[CELL_MAX_HYP - 1], sizeof(*_loc));
rob.meades@u-blox.com 1:26a67ab07275 409
rob.meades@u-blox.com 1:26a67ab07275 410 _loc[a].sensor = (b == 0) ? CELL_LAST : (b == 1) ? CELL_GNSS :
rob.meades@u-blox.com 1:26a67ab07275 411 (b == 2) ? CELL_LOCATE : (b == 3) ? CELL_HYBRID : CELL_LAST;
rob.meades@u-blox.com 1:26a67ab07275 412 _loc[a].time.tm_year -= 1900;
rob.meades@u-blox.com 1:26a67ab07275 413 _loc[a].time.tm_mon -= 1;
rob.meades@u-blox.com 1:26a67ab07275 414 _loc[a].time.tm_wday = 0;
rob.meades@u-blox.com 1:26a67ab07275 415 _loc[a].time.tm_yday = 0;
rob.meades@u-blox.com 1:26a67ab07275 416 _loc[a].speed = 0;
rob.meades@u-blox.com 1:26a67ab07275 417 _loc[a].direction = 0;
rob.meades@u-blox.com 1:26a67ab07275 418 _loc[a].verticalAcc = 0;
rob.meades@u-blox.com 1:26a67ab07275 419 _loc[a].svUsed = 0;
RobMeades 4:39acbc0111eb 420 // Uncertainty can appear as 4294967, which is
RobMeades 4:39acbc0111eb 421 // (2^32 - 1) / 1000, or -1. Since it is confusing
RobMeades 4:39acbc0111eb 422 // for the user to get a large positive number instead
RobMeades 4:39acbc0111eb 423 // of 0 -1, set it to -1 in th1s case.
RobMeades 4:39acbc0111eb 424 if (_loc[a].uncertainty == 4294967) {
RobMeades 4:39acbc0111eb 425 _loc[a].uncertainty = -1;
RobMeades 4:39acbc0111eb 426 }
RobMeades 0:0b75e22c9231 427 _loc[a].validData = true;
RobMeades 0:0b75e22c9231 428 _locRcvPos++;
RobMeades 0:0b75e22c9231 429 }
RobMeades 0:0b75e22c9231 430 }
RobMeades 0:0b75e22c9231 431 }
RobMeades 0:0b75e22c9231 432 }
RobMeades 0:0b75e22c9231 433
RobMeades 0:0b75e22c9231 434 /**********************************************************************
RobMeades 0:0b75e22c9231 435 * PUBLIC METHODS: GENERAL
RobMeades 0:0b75e22c9231 436 **********************************************************************/
RobMeades 0:0b75e22c9231 437
RobMeades 0:0b75e22c9231 438 // Constructor.
RobMeades 0:0b75e22c9231 439 UbloxATCellularInterfaceExt::UbloxATCellularInterfaceExt(PinName tx,
RobMeades 0:0b75e22c9231 440 PinName rx,
RobMeades 0:0b75e22c9231 441 int baud,
amq 15:6f0a1ecc8cec 442 bool debugOn,
amq 15:6f0a1ecc8cec 443 osPriority priority):
amq 15:6f0a1ecc8cec 444 UbloxATCellularInterface(tx, rx, baud, debugOn, priority)
RobMeades 0:0b75e22c9231 445 {
RobMeades 0:0b75e22c9231 446 // Zero HTTP stuff
RobMeades 0:0b75e22c9231 447 memset(_httpProfiles, 0, sizeof(_httpProfiles));
RobMeades 0:0b75e22c9231 448 for (unsigned int profile = 0; profile < sizeof(_httpProfiles) / sizeof(_httpProfiles[0]);
RobMeades 0:0b75e22c9231 449 profile++) {
RobMeades 0:0b75e22c9231 450 _httpProfiles[profile].modemHandle = HTTP_PROF_UNUSED;
RobMeades 0:0b75e22c9231 451 }
RobMeades 0:0b75e22c9231 452
RobMeades 0:0b75e22c9231 453 // Zero FTP stuff
RobMeades 0:0b75e22c9231 454 _ftpTimeout = TIMEOUT_BLOCKING;
RobMeades 0:0b75e22c9231 455 _lastFtpOpCodeResult = FTP_OP_CODE_UNUSED;
RobMeades 0:0b75e22c9231 456 _lastFtpResult = 0;
RobMeades 0:0b75e22c9231 457 _lastFtpOpCodeData = FTP_OP_CODE_UNUSED;
RobMeades 0:0b75e22c9231 458 _ftpBuf = NULL;
RobMeades 0:0b75e22c9231 459 _ftpBufLen = 0;
RobMeades 0:0b75e22c9231 460 _ftpError.eClass = 0;
RobMeades 0:0b75e22c9231 461 _ftpError.eCode = 0;
RobMeades 0:0b75e22c9231 462
RobMeades 0:0b75e22c9231 463 // Zero Cell Locate stuff
RobMeades 0:0b75e22c9231 464 _locRcvPos = 0;
RobMeades 0:0b75e22c9231 465 _locExpPos = 0;
RobMeades 0:0b75e22c9231 466
RobMeades 0:0b75e22c9231 467 // URC handler for HTTP
RobMeades 0:0b75e22c9231 468 _at->oob("+UUHTTPCR", callback(this, &UbloxATCellularInterfaceExt::UUHTTPCR_URC));
RobMeades 0:0b75e22c9231 469
RobMeades 0:0b75e22c9231 470 // URC handlers for FTP
RobMeades 0:0b75e22c9231 471 _at->oob("+UUFTPCR", callback(this, &UbloxATCellularInterfaceExt::UUFTPCR_URC));
RobMeades 0:0b75e22c9231 472 _at->oob("+UUFTPCD", callback(this, &UbloxATCellularInterfaceExt::UUFTPCD_URC));
RobMeades 0:0b75e22c9231 473
RobMeades 0:0b75e22c9231 474 // URC handlers for Cell Locate
RobMeades 4:39acbc0111eb 475 _at->oob("+UULOCIND:", callback(this, &UbloxATCellularInterfaceExt::UULOCIND_URC));
RobMeades 4:39acbc0111eb 476 _at->oob("+UULOC:", callback(this, &UbloxATCellularInterfaceExt::UULOC_URC));
RobMeades 0:0b75e22c9231 477 }
RobMeades 0:0b75e22c9231 478
RobMeades 0:0b75e22c9231 479 // Destructor.
RobMeades 0:0b75e22c9231 480 UbloxATCellularInterfaceExt::~UbloxATCellularInterfaceExt()
RobMeades 0:0b75e22c9231 481 {
RobMeades 0:0b75e22c9231 482 }
RobMeades 0:0b75e22c9231 483
RobMeades 0:0b75e22c9231 484 /**********************************************************************
RobMeades 0:0b75e22c9231 485 * PUBLIC METHODS: HTTP
RobMeades 0:0b75e22c9231 486 **********************************************************************/
RobMeades 0:0b75e22c9231 487
RobMeades 0:0b75e22c9231 488 // Find a free profile.
RobMeades 0:0b75e22c9231 489 int UbloxATCellularInterfaceExt::httpAllocProfile()
RobMeades 0:0b75e22c9231 490 {
RobMeades 0:0b75e22c9231 491 int profile = HTTP_PROF_UNUSED;
RobMeades 0:0b75e22c9231 492 LOCK();
RobMeades 0:0b75e22c9231 493
RobMeades 0:0b75e22c9231 494 // Find a free HTTP profile
RobMeades 0:0b75e22c9231 495 profile = findProfile();
RobMeades 0:0b75e22c9231 496 debug_if(_debug_trace_on, "httpFindProfile: profile is %d\n", profile);
RobMeades 0:0b75e22c9231 497
RobMeades 0:0b75e22c9231 498 if (profile != HTTP_PROF_UNUSED) {
RobMeades 0:0b75e22c9231 499 _httpProfiles[profile].modemHandle = 1;
RobMeades 0:0b75e22c9231 500 _httpProfiles[profile].timeout = TIMEOUT_BLOCKING;
RobMeades 0:0b75e22c9231 501 _httpProfiles[profile].pending = false;
RobMeades 0:0b75e22c9231 502 _httpProfiles[profile].cmd = -1;
RobMeades 0:0b75e22c9231 503 _httpProfiles[profile].result = -1;
RobMeades 0:0b75e22c9231 504 }
RobMeades 0:0b75e22c9231 505
RobMeades 0:0b75e22c9231 506 UNLOCK();
RobMeades 0:0b75e22c9231 507 return profile;
RobMeades 0:0b75e22c9231 508 }
RobMeades 0:0b75e22c9231 509
RobMeades 0:0b75e22c9231 510 // Free a profile.
RobMeades 0:0b75e22c9231 511 bool UbloxATCellularInterfaceExt::httpFreeProfile(int profile)
RobMeades 0:0b75e22c9231 512 {
RobMeades 0:0b75e22c9231 513 bool success = false;
RobMeades 0:0b75e22c9231 514 LOCK();
RobMeades 0:0b75e22c9231 515
RobMeades 0:0b75e22c9231 516 if (IS_PROFILE(profile)) {
RobMeades 0:0b75e22c9231 517 debug_if(_debug_trace_on, "httpFreeProfile(%d)\n", profile);
RobMeades 0:0b75e22c9231 518 _httpProfiles[profile].modemHandle = HTTP_PROF_UNUSED;
RobMeades 0:0b75e22c9231 519 _httpProfiles[profile].timeout = TIMEOUT_BLOCKING;
RobMeades 0:0b75e22c9231 520 _httpProfiles[profile].pending = false;
RobMeades 0:0b75e22c9231 521 _httpProfiles[profile].cmd = -1;
RobMeades 0:0b75e22c9231 522 _httpProfiles[profile].result = -1;
RobMeades 0:0b75e22c9231 523 success = _at->send("AT+UHTTP=%d", profile) && _at->recv("OK");
RobMeades 0:0b75e22c9231 524 }
RobMeades 0:0b75e22c9231 525
RobMeades 0:0b75e22c9231 526 UNLOCK();
RobMeades 0:0b75e22c9231 527 return success;
RobMeades 0:0b75e22c9231 528 }
RobMeades 0:0b75e22c9231 529
RobMeades 0:0b75e22c9231 530 // Set the blocking/timeout state of a profile.
RobMeades 0:0b75e22c9231 531 bool UbloxATCellularInterfaceExt::httpSetTimeout(int profile, int timeout)
RobMeades 0:0b75e22c9231 532 {
RobMeades 0:0b75e22c9231 533 bool success = false;
RobMeades 0:0b75e22c9231 534 LOCK();
RobMeades 0:0b75e22c9231 535
RobMeades 0:0b75e22c9231 536 debug_if(_debug_trace_on, "httpSetTimeout(%d, %d)\n", profile, timeout);
RobMeades 0:0b75e22c9231 537
RobMeades 0:0b75e22c9231 538 if (IS_PROFILE(profile)) {
RobMeades 0:0b75e22c9231 539 _httpProfiles[profile].timeout = timeout;
RobMeades 0:0b75e22c9231 540 success = true;
RobMeades 0:0b75e22c9231 541 }
RobMeades 0:0b75e22c9231 542
RobMeades 0:0b75e22c9231 543 UNLOCK();
RobMeades 0:0b75e22c9231 544 return success;
RobMeades 0:0b75e22c9231 545 }
RobMeades 0:0b75e22c9231 546
RobMeades 0:0b75e22c9231 547 // Set a profile back to defaults.
RobMeades 0:0b75e22c9231 548 bool UbloxATCellularInterfaceExt::httpResetProfile(int httpProfile)
RobMeades 0:0b75e22c9231 549 {
RobMeades 0:0b75e22c9231 550 bool success = false;
RobMeades 0:0b75e22c9231 551 LOCK();
RobMeades 0:0b75e22c9231 552
RobMeades 0:0b75e22c9231 553 debug_if(_debug_trace_on, "httpResetProfile(%d)\n", httpProfile);
RobMeades 0:0b75e22c9231 554 success = _at->send("AT+UHTTP=%d", httpProfile) && _at->recv("OK");
RobMeades 0:0b75e22c9231 555
RobMeades 0:0b75e22c9231 556 UNLOCK();
RobMeades 0:0b75e22c9231 557 return success;
RobMeades 0:0b75e22c9231 558 }
RobMeades 0:0b75e22c9231 559
RobMeades 0:0b75e22c9231 560 // Set HTTP parameters.
RobMeades 0:0b75e22c9231 561 bool UbloxATCellularInterfaceExt::httpSetPar(int httpProfile,
RobMeades 0:0b75e22c9231 562 HttpOpCode httpOpCode,
RobMeades 0:0b75e22c9231 563 const char * httpInPar)
RobMeades 0:0b75e22c9231 564 {
RobMeades 0:0b75e22c9231 565 bool success = false;
RobMeades 0:0b75e22c9231 566 int httpInParNum = 0;
RobMeades 0:0b75e22c9231 567 SocketAddress address;
RobMeades 0:0b75e22c9231 568
RobMeades 0:0b75e22c9231 569 debug_if(_debug_trace_on, "httpSetPar(%d, %d, \"%s\")\n", httpProfile, httpOpCode, httpInPar);
RobMeades 0:0b75e22c9231 570 if (IS_PROFILE(httpProfile)) {
RobMeades 0:0b75e22c9231 571 LOCK();
RobMeades 0:0b75e22c9231 572
RobMeades 0:0b75e22c9231 573 switch(httpOpCode) {
RobMeades 0:0b75e22c9231 574 case HTTP_IP_ADDRESS: // 0
RobMeades 0:0b75e22c9231 575 if (gethostbyname(httpInPar, &address) == NSAPI_ERROR_OK) {
RobMeades 0:0b75e22c9231 576 success = _at->send("AT+UHTTP=%d,%d,\"%s\"",
RobMeades 0:0b75e22c9231 577 httpProfile, httpOpCode, address.get_ip_address()) &&
RobMeades 0:0b75e22c9231 578 _at->recv("OK");
RobMeades 0:0b75e22c9231 579 }
RobMeades 0:0b75e22c9231 580 break;
RobMeades 0:0b75e22c9231 581 case HTTP_SERVER_NAME: // 1
RobMeades 0:0b75e22c9231 582 case HTTP_USER_NAME: // 2
RobMeades 0:0b75e22c9231 583 case HTTP_PASSWORD: // 3
RobMeades 0:0b75e22c9231 584 success = _at->send("AT+UHTTP=%d,%d,\"%s\"", httpProfile, httpOpCode, httpInPar) &&
RobMeades 0:0b75e22c9231 585 _at->recv("OK");
RobMeades 0:0b75e22c9231 586 break;
RobMeades 0:0b75e22c9231 587
RobMeades 0:0b75e22c9231 588 case HTTP_AUTH_TYPE: // 4
RobMeades 0:0b75e22c9231 589 case HTTP_SERVER_PORT: // 5
RobMeades 0:0b75e22c9231 590 httpInParNum = atoi(httpInPar);
RobMeades 0:0b75e22c9231 591 success = _at->send("AT+UHTTP=%d,%d,%d", httpProfile, httpOpCode, httpInParNum) &&
RobMeades 0:0b75e22c9231 592 _at->recv("OK");
RobMeades 0:0b75e22c9231 593 break;
RobMeades 0:0b75e22c9231 594
RobMeades 0:0b75e22c9231 595 case HTTP_SECURE: // 6
RobMeades 0:0b75e22c9231 596 httpInParNum = atoi(httpInPar);
RobMeades 0:0b75e22c9231 597 success = _at->send("AT+UHTTP=%d,%d,%d", httpProfile, httpOpCode, httpInParNum) &&
RobMeades 0:0b75e22c9231 598 _at->recv("OK");
RobMeades 0:0b75e22c9231 599 break;
RobMeades 0:0b75e22c9231 600
Bilal Qamar 28:4427f2e6bbab 601 case HTTP_REQ_HEADER: //9
Bilal Qamar 28:4427f2e6bbab 602 success = _at->send("AT+UHTTP=%d,%d,\"%s\"", httpProfile, httpOpCode, httpInPar) &&
Bilal Qamar 28:4427f2e6bbab 603 _at->recv("OK");
Bilal Qamar 28:4427f2e6bbab 604 break;
Bilal Qamar 28:4427f2e6bbab 605
RobMeades 0:0b75e22c9231 606 default:
RobMeades 0:0b75e22c9231 607 debug_if(_debug_trace_on, "httpSetPar: unknown httpOpCode %d\n", httpOpCode);
RobMeades 0:0b75e22c9231 608 break;
RobMeades 0:0b75e22c9231 609 }
RobMeades 0:0b75e22c9231 610
RobMeades 0:0b75e22c9231 611 UNLOCK();
RobMeades 0:0b75e22c9231 612 }
RobMeades 0:0b75e22c9231 613
RobMeades 0:0b75e22c9231 614 return success;
RobMeades 0:0b75e22c9231 615 }
RobMeades 0:0b75e22c9231 616
RobMeades 0:0b75e22c9231 617 // Perform an HTTP command.
RobMeades 0:0b75e22c9231 618 UbloxATCellularInterfaceExt::Error * UbloxATCellularInterfaceExt::httpCommand(int httpProfile,
RobMeades 0:0b75e22c9231 619 HttpCmd httpCmd,
RobMeades 0:0b75e22c9231 620 const char *httpPath,
RobMeades 0:0b75e22c9231 621 const char *rspFile,
RobMeades 0:0b75e22c9231 622 const char *sendStr,
RobMeades 0:0b75e22c9231 623 int httpContentType,
RobMeades 0:0b75e22c9231 624 const char *httpCustomPar,
fahim.alavi@u-blox.com 17:ac64a6b90925 625 char *buf, int len, int *read_size)
RobMeades 0:0b75e22c9231 626 {
RobMeades 0:0b75e22c9231 627 bool atSuccess = false;
RobMeades 0:0b75e22c9231 628 bool success = false;
RobMeades 0:0b75e22c9231 629 int at_timeout;
RobMeades 0:0b75e22c9231 630 char defaultFilename[] = "http_last_response_x";
RobMeades 0:0b75e22c9231 631
RobMeades 0:0b75e22c9231 632 debug_if(_debug_trace_on, "%s\n", getHttpCmd(httpCmd));
RobMeades 0:0b75e22c9231 633
RobMeades 0:0b75e22c9231 634 if (IS_PROFILE(httpProfile)) {
RobMeades 0:0b75e22c9231 635 LOCK();
RobMeades 0:0b75e22c9231 636 at_timeout = _at_timeout; // Has to be inside LOCK()s
RobMeades 0:0b75e22c9231 637
RobMeades 0:0b75e22c9231 638 if (rspFile == NULL) {
RobMeades 0:0b75e22c9231 639 sprintf(defaultFilename + sizeof (defaultFilename) - 2, "%1d", httpProfile);
RobMeades 0:0b75e22c9231 640 rspFile = defaultFilename;
RobMeades 0:0b75e22c9231 641 }
RobMeades 0:0b75e22c9231 642
RobMeades 0:0b75e22c9231 643 switch (httpCmd) {
RobMeades 0:0b75e22c9231 644 case HTTP_HEAD:
RobMeades 0:0b75e22c9231 645 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\"", httpProfile, httpCmd,
RobMeades 0:0b75e22c9231 646 httpPath, rspFile) &&
RobMeades 0:0b75e22c9231 647 _at->recv("OK");
RobMeades 0:0b75e22c9231 648 break;
RobMeades 0:0b75e22c9231 649 case HTTP_GET:
RobMeades 0:0b75e22c9231 650 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\"", httpProfile, httpCmd,
RobMeades 0:0b75e22c9231 651 httpPath, rspFile) &&
RobMeades 0:0b75e22c9231 652 _at->recv("OK");
RobMeades 0:0b75e22c9231 653 break;
RobMeades 0:0b75e22c9231 654 case HTTP_DELETE:
RobMeades 0:0b75e22c9231 655 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\"", httpProfile, httpCmd,
RobMeades 0:0b75e22c9231 656 httpPath, rspFile) &&
RobMeades 0:0b75e22c9231 657 _at->recv("OK");
RobMeades 0:0b75e22c9231 658 break;
RobMeades 0:0b75e22c9231 659 case HTTP_PUT:
RobMeades 0:0b75e22c9231 660 // In this case the parameter sendStr is a filename
RobMeades 0:0b75e22c9231 661 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\",\"%s\"", httpProfile, httpCmd,
RobMeades 0:0b75e22c9231 662 httpPath, rspFile, sendStr) &&
RobMeades 0:0b75e22c9231 663 _at->recv("OK");
RobMeades 0:0b75e22c9231 664 break;
RobMeades 0:0b75e22c9231 665 case HTTP_POST_FILE:
RobMeades 0:0b75e22c9231 666 // In this case the parameter sendStr is a filename
RobMeades 0:0b75e22c9231 667 if (httpContentType != 6) {
RobMeades 0:0b75e22c9231 668 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\",\"%s\",%d",
RobMeades 0:0b75e22c9231 669 httpProfile, httpCmd, httpPath, rspFile, sendStr,
RobMeades 0:0b75e22c9231 670 httpContentType) &&
RobMeades 0:0b75e22c9231 671 _at->recv("OK");
RobMeades 0:0b75e22c9231 672 } else {
RobMeades 0:0b75e22c9231 673 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\",\"%s\",%d,%s",
RobMeades 0:0b75e22c9231 674 httpProfile, httpCmd, httpPath, rspFile, sendStr,
RobMeades 0:0b75e22c9231 675 httpContentType,
RobMeades 0:0b75e22c9231 676 httpCustomPar) &&
RobMeades 0:0b75e22c9231 677 _at->recv("OK");
RobMeades 0:0b75e22c9231 678 }
RobMeades 0:0b75e22c9231 679 break;
RobMeades 0:0b75e22c9231 680 case HTTP_POST_DATA:
RobMeades 0:0b75e22c9231 681 // In this case the parameter sendStr is a string containing data
RobMeades 0:0b75e22c9231 682 if (httpContentType != 6) {
RobMeades 0:0b75e22c9231 683 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\",\"%s\",%d",
RobMeades 0:0b75e22c9231 684 httpProfile, httpCmd, httpPath, rspFile, sendStr,
RobMeades 0:0b75e22c9231 685 httpContentType) &&
RobMeades 0:0b75e22c9231 686 _at->recv("OK");
RobMeades 0:0b75e22c9231 687 } else {
RobMeades 0:0b75e22c9231 688 atSuccess = _at->send("AT+UHTTPC=%d,%d,\"%s\",\"%s\",\"%s\",%d,%s",
RobMeades 0:0b75e22c9231 689 httpProfile, httpCmd, httpPath, rspFile, sendStr,
RobMeades 0:0b75e22c9231 690 httpContentType,
RobMeades 0:0b75e22c9231 691 httpCustomPar) &&
RobMeades 0:0b75e22c9231 692 _at->recv("OK");
RobMeades 0:0b75e22c9231 693 }
RobMeades 0:0b75e22c9231 694 break;
RobMeades 0:0b75e22c9231 695 default:
RobMeades 0:0b75e22c9231 696 debug_if(_debug_trace_on, "HTTP command not recognised\n");
RobMeades 0:0b75e22c9231 697 break;
RobMeades 0:0b75e22c9231 698 }
RobMeades 0:0b75e22c9231 699
RobMeades 0:0b75e22c9231 700 if (atSuccess) {
RobMeades 0:0b75e22c9231 701 Timer timer;
fahim.alavi@u-blox.com 17:ac64a6b90925 702 int read_length = 0;
RobMeades 0:0b75e22c9231 703
RobMeades 0:0b75e22c9231 704 at_set_timeout(1000);
RobMeades 0:0b75e22c9231 705 _httpProfiles[httpProfile].pending = true;
RobMeades 0:0b75e22c9231 706 _httpProfiles[httpProfile].result = -1;
RobMeades 0:0b75e22c9231 707
RobMeades 0:0b75e22c9231 708 // Waiting for unsolicited result code
RobMeades 0:0b75e22c9231 709 timer.start();
RobMeades 0:0b75e22c9231 710 while (_httpProfiles[httpProfile].pending) {
RobMeades 0:0b75e22c9231 711 if (_httpProfiles[httpProfile].result != -1) {
RobMeades 0:0b75e22c9231 712 // Received unsolicited: starting its analysis
RobMeades 0:0b75e22c9231 713 _httpProfiles[httpProfile].pending = false;
RobMeades 0:0b75e22c9231 714 if (_httpProfiles[httpProfile].result == 1) {
rob.meades@u-blox.com 11:3631f62bb359 715 // Leave a short delay to make sure the file has been written
rob.meades@u-blox.com 11:3631f62bb359 716 wait_ms(100);
RobMeades 0:0b75e22c9231 717 // HTTP command successfully executed
fahim.alavi@u-blox.com 17:ac64a6b90925 718 read_length = readFile(rspFile, buf, len);
fahim.alavi@u-blox.com 17:ac64a6b90925 719
fahim.alavi@u-blox.com 17:ac64a6b90925 720 if (read_length >= 0) {
RobMeades 0:0b75e22c9231 721 success = true;
fahim.alavi@u-blox.com 17:ac64a6b90925 722
fahim.alavi@u-blox.com 17:ac64a6b90925 723 if(read_size != NULL) {
fahim.alavi@u-blox.com 17:ac64a6b90925 724 *read_size = *read_size + read_length;
fahim.alavi@u-blox.com 17:ac64a6b90925 725 }
RobMeades 0:0b75e22c9231 726 }
RobMeades 0:0b75e22c9231 727 } else {
RobMeades 0:0b75e22c9231 728 // Retrieve the error class and code
RobMeades 0:0b75e22c9231 729 if (_at->send("AT+UHTTPER=%d", httpProfile) &&
RobMeades 0:0b75e22c9231 730 _at->recv("AT+UHTTPER=%*d,%d,%d",
RobMeades 0:0b75e22c9231 731 &(_httpProfiles[httpProfile].httpError.eClass),
RobMeades 0:0b75e22c9231 732 &(_httpProfiles[httpProfile].httpError.eCode)) &&
RobMeades 0:0b75e22c9231 733 _at->recv("OK")) {
RobMeades 0:0b75e22c9231 734 debug_if(_debug_trace_on, "HTTP error class %d, code %d\n",
RobMeades 0:0b75e22c9231 735 _httpProfiles[httpProfile].httpError.eClass,
RobMeades 0:0b75e22c9231 736 _httpProfiles[httpProfile].httpError.eCode);
RobMeades 0:0b75e22c9231 737 }
RobMeades 0:0b75e22c9231 738 }
RobMeades 0:0b75e22c9231 739 } else if (!TIMEOUT(timer, _httpProfiles[httpProfile].timeout)) {
RobMeades 0:0b75e22c9231 740 // Wait for URCs
RobMeades 0:0b75e22c9231 741 _at->recv(UNNATURAL_STRING);
RobMeades 0:0b75e22c9231 742 } else {
RobMeades 0:0b75e22c9231 743 _httpProfiles[httpProfile].pending = false;
RobMeades 0:0b75e22c9231 744 }
RobMeades 0:0b75e22c9231 745 }
RobMeades 0:0b75e22c9231 746 timer.stop();
RobMeades 0:0b75e22c9231 747
RobMeades 0:0b75e22c9231 748 at_set_timeout(at_timeout);
RobMeades 0:0b75e22c9231 749
RobMeades 0:0b75e22c9231 750 if (!success) {
RobMeades 0:0b75e22c9231 751 debug_if(_debug_trace_on, "%s: ERROR\n", getHttpCmd(httpCmd));
RobMeades 0:0b75e22c9231 752 }
RobMeades 0:0b75e22c9231 753
RobMeades 0:0b75e22c9231 754 }
RobMeades 0:0b75e22c9231 755
RobMeades 0:0b75e22c9231 756 UNLOCK();
RobMeades 0:0b75e22c9231 757 }
RobMeades 0:0b75e22c9231 758
RobMeades 0:0b75e22c9231 759 return success ? NULL : &(_httpProfiles[httpProfile].httpError);
RobMeades 0:0b75e22c9231 760 }
RobMeades 0:0b75e22c9231 761
RobMeades 0:0b75e22c9231 762 /**********************************************************************
RobMeades 0:0b75e22c9231 763 * PUBLIC METHODS: FTP
RobMeades 0:0b75e22c9231 764 **********************************************************************/
RobMeades 0:0b75e22c9231 765
RobMeades 0:0b75e22c9231 766 // Set the blocking/timeout for FTP.
RobMeades 0:0b75e22c9231 767 bool UbloxATCellularInterfaceExt::ftpSetTimeout(int timeout)
RobMeades 0:0b75e22c9231 768 {
RobMeades 0:0b75e22c9231 769 LOCK();
RobMeades 0:0b75e22c9231 770 debug_if(_debug_trace_on, "ftpSetTimeout(%d)\n", timeout);
RobMeades 0:0b75e22c9231 771 _ftpTimeout = timeout;
RobMeades 0:0b75e22c9231 772 UNLOCK();
RobMeades 0:0b75e22c9231 773
RobMeades 0:0b75e22c9231 774 return true;
RobMeades 0:0b75e22c9231 775 }
RobMeades 0:0b75e22c9231 776
RobMeades 0:0b75e22c9231 777 // Reset the FTP configuration back to defaults.
rob.meades@u-blox.com 11:3631f62bb359 778 // Note: not all modrmd support all parameters,
rob.meades@u-blox.com 11:3631f62bb359 779 // hence the void return code.
rob.meades@u-blox.com 11:3631f62bb359 780 void UbloxATCellularInterfaceExt::ftpResetPar()
RobMeades 0:0b75e22c9231 781 {
RobMeades 0:0b75e22c9231 782 LOCK();
RobMeades 0:0b75e22c9231 783 debug_if(_debug_trace_on, "ftpResetPar()\n");
rob.meades@u-blox.com 11:3631f62bb359 784 for (int x = 0; x < NUM_FTP_OP_CODES; x++) {
rob.meades@u-blox.com 11:3631f62bb359 785 if (_at->send("AT+UFTP=%d", x)) {
rob.meades@u-blox.com 11:3631f62bb359 786 _at->recv("OK");
rob.meades@u-blox.com 11:3631f62bb359 787 }
RobMeades 0:0b75e22c9231 788 }
RobMeades 0:0b75e22c9231 789 UNLOCK();
RobMeades 0:0b75e22c9231 790 }
RobMeades 0:0b75e22c9231 791
RobMeades 0:0b75e22c9231 792 // Set FTP parameters.
RobMeades 0:0b75e22c9231 793 bool UbloxATCellularInterfaceExt::ftpSetPar(FtpOpCode ftpOpCode,
RobMeades 0:0b75e22c9231 794 const char * ftpInPar)
RobMeades 0:0b75e22c9231 795 {
RobMeades 0:0b75e22c9231 796 bool success = false;
RobMeades 0:0b75e22c9231 797 int ftpInParNum = 0;
RobMeades 0:0b75e22c9231 798 LOCK();
RobMeades 0:0b75e22c9231 799
RobMeades 0:0b75e22c9231 800 debug_if(_debug_trace_on, "ftpSetPar(%d, %s)\n", ftpOpCode, ftpInPar);
RobMeades 0:0b75e22c9231 801 switch (ftpOpCode) {
RobMeades 0:0b75e22c9231 802 case FTP_IP_ADDRESS: // 0
RobMeades 0:0b75e22c9231 803 case FTP_SERVER_NAME: // 1
RobMeades 0:0b75e22c9231 804 case FTP_USER_NAME: // 2
RobMeades 0:0b75e22c9231 805 case FTP_PASSWORD: // 3
RobMeades 0:0b75e22c9231 806 case FTP_ACCOUNT: // 4
RobMeades 0:0b75e22c9231 807 success = _at->send("AT+UFTP=%d,\"%s\"", ftpOpCode, ftpInPar) &&
RobMeades 0:0b75e22c9231 808 _at->recv("OK");
RobMeades 0:0b75e22c9231 809 break;
RobMeades 0:0b75e22c9231 810 case FTP_INACTIVITY_TIMEOUT: // 5
RobMeades 0:0b75e22c9231 811 case FTP_MODE: // 6
RobMeades 0:0b75e22c9231 812 case FTP_SERVER_PORT: // 7
RobMeades 0:0b75e22c9231 813 case FTP_SECURE: // 8
RobMeades 0:0b75e22c9231 814 ftpInParNum = atoi(ftpInPar);
RobMeades 0:0b75e22c9231 815 success = _at->send("AT+UFTP=%d,%d", ftpOpCode, ftpInParNum) &&
RobMeades 0:0b75e22c9231 816 _at->recv("OK");
RobMeades 0:0b75e22c9231 817 break;
RobMeades 0:0b75e22c9231 818 default:
RobMeades 0:0b75e22c9231 819 debug_if(_debug_trace_on, "ftpSetPar: unknown ftpOpCode %d\n", ftpOpCode);
RobMeades 0:0b75e22c9231 820 break;
RobMeades 0:0b75e22c9231 821 }
RobMeades 0:0b75e22c9231 822
RobMeades 0:0b75e22c9231 823 UNLOCK();
RobMeades 0:0b75e22c9231 824 return success;
RobMeades 0:0b75e22c9231 825 }
RobMeades 0:0b75e22c9231 826
RobMeades 0:0b75e22c9231 827 // Perform an FTP command.
RobMeades 0:0b75e22c9231 828 UbloxATCellularInterfaceExt::Error * UbloxATCellularInterfaceExt::ftpCommand(FtpCmd ftpCmd,
RobMeades 0:0b75e22c9231 829 const char* file1,
RobMeades 0:0b75e22c9231 830 const char* file2,
rob.meades@u-blox.com 11:3631f62bb359 831 char* buf, int len,
rob.meades@u-blox.com 11:3631f62bb359 832 int offset)
RobMeades 0:0b75e22c9231 833 {
RobMeades 0:0b75e22c9231 834 bool atSuccess = false;
RobMeades 0:0b75e22c9231 835 bool success = false;
RobMeades 0:0b75e22c9231 836 int at_timeout;
RobMeades 0:0b75e22c9231 837 LOCK();
RobMeades 0:0b75e22c9231 838 at_timeout = _at_timeout; // Has to be inside LOCK()s
RobMeades 0:0b75e22c9231 839
RobMeades 0:0b75e22c9231 840 debug_if(_debug_trace_on, "%s\n", getFtpCmd(ftpCmd));
RobMeades 0:0b75e22c9231 841 switch (ftpCmd) {
RobMeades 0:0b75e22c9231 842 case FTP_LOGOUT:
RobMeades 0:0b75e22c9231 843 case FTP_LOGIN:
RobMeades 0:0b75e22c9231 844 atSuccess = _at->send("AT+UFTPC=%d", ftpCmd) && _at->recv("OK");
RobMeades 0:0b75e22c9231 845 break;
RobMeades 0:0b75e22c9231 846 case FTP_DELETE_FILE:
RobMeades 0:0b75e22c9231 847 case FTP_CD:
RobMeades 0:0b75e22c9231 848 case FTP_MKDIR:
RobMeades 0:0b75e22c9231 849 case FTP_RMDIR:
RobMeades 0:0b75e22c9231 850 case FTP_FOTA_FILE:
RobMeades 0:0b75e22c9231 851 atSuccess = _at->send("AT+UFTPC=%d,\"%s\"", ftpCmd, file1) &&
RobMeades 0:0b75e22c9231 852 _at->recv("OK");
RobMeades 0:0b75e22c9231 853 break;
RobMeades 0:0b75e22c9231 854 case FTP_RENAME_FILE:
RobMeades 0:0b75e22c9231 855 atSuccess = _at->send("AT+UFTPC=%d,\"%s\",\"%s\"",
RobMeades 0:0b75e22c9231 856 ftpCmd, file1, file2) &&
RobMeades 0:0b75e22c9231 857 _at->recv("OK");
RobMeades 0:0b75e22c9231 858 break;
RobMeades 0:0b75e22c9231 859 case FTP_GET_FILE:
RobMeades 0:0b75e22c9231 860 case FTP_PUT_FILE:
RobMeades 0:0b75e22c9231 861 if (file2 == NULL) {
RobMeades 0:0b75e22c9231 862 file2 = file1;
RobMeades 0:0b75e22c9231 863 }
RobMeades 0:0b75e22c9231 864 atSuccess = _at->send("AT+UFTPC=%d,\"%s\",\"%s\",%d",
RobMeades 0:0b75e22c9231 865 ftpCmd, file1, file2, offset) &&
RobMeades 0:0b75e22c9231 866 _at->recv("OK");
rob.meades@u-blox.com 11:3631f62bb359 867
rob.meades@u-blox.com 11:3631f62bb359 868 // Not all modules support continuing a GET/PUT (e.g.
rob.meades@u-blox.com 11:3631f62bb359 869 // Sara-G350 00S-00 doesn't), so if we receive an error,
rob.meades@u-blox.com 11:3631f62bb359 870 // try again without it
rob.meades@u-blox.com 11:3631f62bb359 871 if (!atSuccess) {
rob.meades@u-blox.com 11:3631f62bb359 872 atSuccess = _at->send("AT+UFTPC=%d,\"%s\",\"%s\"",
rob.meades@u-blox.com 11:3631f62bb359 873 ftpCmd, file1, file2) &&
rob.meades@u-blox.com 11:3631f62bb359 874 _at->recv("OK");
rob.meades@u-blox.com 11:3631f62bb359 875 }
RobMeades 0:0b75e22c9231 876 break;
RobMeades 0:0b75e22c9231 877 case FTP_FILE_INFO:
RobMeades 0:0b75e22c9231 878 case FTP_LS:
RobMeades 0:0b75e22c9231 879 _ftpBuf = buf;
RobMeades 0:0b75e22c9231 880 _ftpBufLen = len;
RobMeades 0:0b75e22c9231 881 // Add a terminator in case nothing comes back
RobMeades 0:0b75e22c9231 882 if (_ftpBufLen > 0) {
RobMeades 0:0b75e22c9231 883 *_ftpBuf = 0;
RobMeades 0:0b75e22c9231 884 }
RobMeades 0:0b75e22c9231 885 if (file1 == NULL) {
RobMeades 0:0b75e22c9231 886 atSuccess = _at->send("AT+UFTPC=%d", ftpCmd) &&
RobMeades 0:0b75e22c9231 887 _at->recv("OK");
RobMeades 0:0b75e22c9231 888 } else {
RobMeades 0:0b75e22c9231 889 atSuccess = _at->send("AT+UFTPC=%d,\"%s\"", ftpCmd, file1) &&
RobMeades 0:0b75e22c9231 890 _at->recv("OK");
RobMeades 0:0b75e22c9231 891 }
RobMeades 0:0b75e22c9231 892 break;
RobMeades 0:0b75e22c9231 893 default:
RobMeades 0:0b75e22c9231 894 debug_if(_debug_trace_on, "FTP command not recognised/supported\n");
RobMeades 0:0b75e22c9231 895 break;
RobMeades 0:0b75e22c9231 896 }
RobMeades 0:0b75e22c9231 897
RobMeades 0:0b75e22c9231 898 // Wait for the result to arrive back
RobMeades 0:0b75e22c9231 899 if (atSuccess) {
RobMeades 0:0b75e22c9231 900 Timer timer;
RobMeades 0:0b75e22c9231 901
RobMeades 0:0b75e22c9231 902 at_set_timeout(1000);
RobMeades 0:0b75e22c9231 903 _lastFtpOpCodeData = FTP_OP_CODE_UNUSED;
RobMeades 0:0b75e22c9231 904 _lastFtpOpCodeResult = FTP_OP_CODE_UNUSED;
RobMeades 0:0b75e22c9231 905 _lastFtpResult = -1; // just for safety
RobMeades 0:0b75e22c9231 906 // Waiting for result to arrive
RobMeades 0:0b75e22c9231 907 timer.start();
RobMeades 0:0b75e22c9231 908 while ((_lastFtpOpCodeResult == FTP_OP_CODE_UNUSED) &&
RobMeades 0:0b75e22c9231 909 !TIMEOUT(timer, _ftpTimeout)) {
RobMeades 0:0b75e22c9231 910 _at->recv(UNNATURAL_STRING);
RobMeades 0:0b75e22c9231 911 }
RobMeades 0:0b75e22c9231 912 timer.stop();
RobMeades 0:0b75e22c9231 913
RobMeades 0:0b75e22c9231 914 if ((_lastFtpOpCodeResult == ftpCmd) && (_lastFtpResult == 1)) {
RobMeades 0:0b75e22c9231 915 // Got a result for our FTP op code and it is good
RobMeades 0:0b75e22c9231 916 success = true;
RobMeades 0:0b75e22c9231 917 } else {
RobMeades 0:0b75e22c9231 918 // Retrieve the error class and code
RobMeades 0:0b75e22c9231 919 if (_at->send("AT+UFTPER") &&
RobMeades 0:0b75e22c9231 920 _at->recv("+UFTPER:%d,%d", &(_ftpError.eClass), &(_ftpError.eCode)) &&
RobMeades 0:0b75e22c9231 921 _at->recv("OK")) {
RobMeades 0:0b75e22c9231 922 debug_if(_debug_trace_on, "FTP Error class %d, code %d\n",
RobMeades 0:0b75e22c9231 923 _ftpError.eClass, _ftpError.eCode);
RobMeades 0:0b75e22c9231 924 }
RobMeades 0:0b75e22c9231 925 }
RobMeades 0:0b75e22c9231 926
RobMeades 0:0b75e22c9231 927 at_set_timeout(at_timeout);
RobMeades 0:0b75e22c9231 928
RobMeades 0:0b75e22c9231 929 if (!success) {
RobMeades 0:0b75e22c9231 930 debug_if(_debug_trace_on, "%s: ERROR\n", getFtpCmd(ftpCmd));
RobMeades 0:0b75e22c9231 931 }
RobMeades 0:0b75e22c9231 932 }
RobMeades 0:0b75e22c9231 933
RobMeades 0:0b75e22c9231 934 // Set these back to nothing to stop the URC splatting
RobMeades 0:0b75e22c9231 935 _ftpBuf = NULL;
RobMeades 0:0b75e22c9231 936 _ftpBufLen = 0;
RobMeades 0:0b75e22c9231 937
RobMeades 0:0b75e22c9231 938 UNLOCK();
RobMeades 0:0b75e22c9231 939 return success ? NULL : &_ftpError;
RobMeades 0:0b75e22c9231 940 }
RobMeades 0:0b75e22c9231 941
RobMeades 0:0b75e22c9231 942 /**********************************************************************
RobMeades 0:0b75e22c9231 943 * PUBLIC METHODS: Cell Locate
RobMeades 0:0b75e22c9231 944 **********************************************************************/
RobMeades 0:0b75e22c9231 945
RobMeades 0:0b75e22c9231 946 // Configure CellLocate TCP Aiding server.
RobMeades 0:0b75e22c9231 947 bool UbloxATCellularInterfaceExt::cellLocSrvTcp(const char* token,
RobMeades 0:0b75e22c9231 948 const char* server_1,
RobMeades 0:0b75e22c9231 949 const char* server_2,
RobMeades 0:0b75e22c9231 950 int days, int period,
RobMeades 0:0b75e22c9231 951 int resolution)
RobMeades 0:0b75e22c9231 952 {
RobMeades 0:0b75e22c9231 953 bool success = false;
RobMeades 0:0b75e22c9231 954 LOCK();
RobMeades 0:0b75e22c9231 955
RobMeades 0:0b75e22c9231 956 if ((_dev_info.dev == DEV_LISA_U2_03S) || (_dev_info.dev == DEV_SARA_U2)){
RobMeades 0:0b75e22c9231 957 success = _at->send("AT+UGSRV=\"%s\",\"%s\",\"%s\",%d,%d,%d",
RobMeades 0:0b75e22c9231 958 server_1, server_2, token, days, period, resolution) &&
RobMeades 0:0b75e22c9231 959 _at->recv("OK");
RobMeades 0:0b75e22c9231 960 }
RobMeades 0:0b75e22c9231 961
RobMeades 0:0b75e22c9231 962 UNLOCK();
RobMeades 0:0b75e22c9231 963 return success;
RobMeades 0:0b75e22c9231 964 }
RobMeades 0:0b75e22c9231 965
RobMeades 0:0b75e22c9231 966 // Configure CellLocate UDP Aiding server.
RobMeades 0:0b75e22c9231 967 bool UbloxATCellularInterfaceExt::cellLocSrvUdp(const char* server_1,
RobMeades 0:0b75e22c9231 968 int port, int latency,
RobMeades 0:0b75e22c9231 969 int mode)
RobMeades 0:0b75e22c9231 970 {
RobMeades 0:0b75e22c9231 971
RobMeades 0:0b75e22c9231 972 bool success = false;
RobMeades 0:0b75e22c9231 973 LOCK();
RobMeades 0:0b75e22c9231 974
RobMeades 0:0b75e22c9231 975 if (_dev_info.dev != DEV_TOBY_L2) {
RobMeades 0:0b75e22c9231 976 success = _at->send("AT+UGAOP=\"%s\",%d,%d,%d", server_1, port, latency, mode) &&
RobMeades 0:0b75e22c9231 977 _at->recv("OK");
RobMeades 0:0b75e22c9231 978 }
RobMeades 0:0b75e22c9231 979
RobMeades 0:0b75e22c9231 980 UNLOCK();
RobMeades 0:0b75e22c9231 981 return success;
RobMeades 0:0b75e22c9231 982 }
RobMeades 0:0b75e22c9231 983
RobMeades 0:0b75e22c9231 984 // Configure Cell Locate location sensor.
RobMeades 0:0b75e22c9231 985 bool UbloxATCellularInterfaceExt::cellLocConfig(int scanMode)
RobMeades 0:0b75e22c9231 986 {
RobMeades 0:0b75e22c9231 987 bool success;
RobMeades 0:0b75e22c9231 988 LOCK();
RobMeades 0:0b75e22c9231 989
RobMeades 0:0b75e22c9231 990 success = _at->send("AT+ULOCCELL=%d", scanMode) &&
RobMeades 0:0b75e22c9231 991 _at->recv("OK");
RobMeades 0:0b75e22c9231 992
RobMeades 0:0b75e22c9231 993 UNLOCK();
RobMeades 0:0b75e22c9231 994 return success;
RobMeades 0:0b75e22c9231 995 }
RobMeades 0:0b75e22c9231 996
RobMeades 0:0b75e22c9231 997 // Request CellLocate.
RobMeades 0:0b75e22c9231 998 bool UbloxATCellularInterfaceExt::cellLocRequest(CellSensType sensor,
RobMeades 0:0b75e22c9231 999 int timeout,
RobMeades 0:0b75e22c9231 1000 int accuracy,
RobMeades 0:0b75e22c9231 1001 CellRespType type,
RobMeades 0:0b75e22c9231 1002 int hypothesis)
RobMeades 0:0b75e22c9231 1003 {
RobMeades 0:0b75e22c9231 1004 bool success = false;
RobMeades 0:0b75e22c9231 1005
RobMeades 0:0b75e22c9231 1006 if ((hypothesis <= CELL_MAX_HYP) &&
RobMeades 0:0b75e22c9231 1007 !((hypothesis > 1) && (type != CELL_MULTIHYP))) {
RobMeades 0:0b75e22c9231 1008
RobMeades 0:0b75e22c9231 1009 LOCK();
RobMeades 0:0b75e22c9231 1010
RobMeades 0:0b75e22c9231 1011 _locRcvPos = 0;
RobMeades 0:0b75e22c9231 1012 _locExpPos = 0;
RobMeades 0:0b75e22c9231 1013
RobMeades 0:0b75e22c9231 1014 for (int i = 0; i < hypothesis; i++) {
RobMeades 0:0b75e22c9231 1015 _loc[i].validData = false;
RobMeades 0:0b75e22c9231 1016 }
RobMeades 0:0b75e22c9231 1017
rob.meades@u-blox.com 11:3631f62bb359 1018 // Switch on the URC but don't error on it as some
rob.meades@u-blox.com 11:3631f62bb359 1019 // modules (e.g. Sara-G350) don't support it
rob.meades@u-blox.com 11:3631f62bb359 1020 if (_at->send("AT+ULOCIND=1")) {
rob.meades@u-blox.com 11:3631f62bb359 1021 _at->recv("OK");
RobMeades 0:0b75e22c9231 1022 }
rob.meades@u-blox.com 11:3631f62bb359 1023 // Switch on Cell Locate
rob.meades@u-blox.com 11:3631f62bb359 1024 success = _at->send("AT+ULOC=2,%d,%d,%d,%d,%d", sensor, type, timeout, accuracy, hypothesis) &&
rob.meades@u-blox.com 11:3631f62bb359 1025 _at->recv("OK");
rob.meades@u-blox.com 11:3631f62bb359 1026 // Answers are picked up by reacting to +ULOC
RobMeades 0:0b75e22c9231 1027
RobMeades 0:0b75e22c9231 1028 UNLOCK();
RobMeades 0:0b75e22c9231 1029 }
RobMeades 0:0b75e22c9231 1030
RobMeades 0:0b75e22c9231 1031 return success;
RobMeades 0:0b75e22c9231 1032 }
RobMeades 0:0b75e22c9231 1033
RobMeades 0:0b75e22c9231 1034 // Get a position record.
RobMeades 0:0b75e22c9231 1035 bool UbloxATCellularInterfaceExt::cellLocGetData(CellLocData *data, int index)
RobMeades 0:0b75e22c9231 1036 {
RobMeades 0:0b75e22c9231 1037 bool success = false;
RobMeades 0:0b75e22c9231 1038
RobMeades 0:0b75e22c9231 1039 if (_loc[index].validData) {
RobMeades 0:0b75e22c9231 1040 LOCK();
RobMeades 0:0b75e22c9231 1041 memcpy(data, &_loc[index], sizeof(*_loc));
RobMeades 0:0b75e22c9231 1042 success = true;
RobMeades 0:0b75e22c9231 1043 UNLOCK();
RobMeades 0:0b75e22c9231 1044 }
RobMeades 0:0b75e22c9231 1045
RobMeades 0:0b75e22c9231 1046 return success;
RobMeades 0:0b75e22c9231 1047 }
RobMeades 0:0b75e22c9231 1048
RobMeades 0:0b75e22c9231 1049 // Get number of position records received.
RobMeades 0:0b75e22c9231 1050 int UbloxATCellularInterfaceExt::cellLocGetRes()
RobMeades 0:0b75e22c9231 1051 {
RobMeades 0:0b75e22c9231 1052 int at_timeout;
RobMeades 0:0b75e22c9231 1053 LOCK();
RobMeades 0:0b75e22c9231 1054
RobMeades 0:0b75e22c9231 1055 at_timeout = _at_timeout; // Has to be inside LOCK()s
RobMeades 0:0b75e22c9231 1056 at_set_timeout(1000);
RobMeades 0:0b75e22c9231 1057 // Wait for URCs
RobMeades 0:0b75e22c9231 1058 _at->recv(UNNATURAL_STRING);
RobMeades 0:0b75e22c9231 1059 at_set_timeout(at_timeout);
RobMeades 0:0b75e22c9231 1060
RobMeades 0:0b75e22c9231 1061 UNLOCK();
RobMeades 0:0b75e22c9231 1062 return _locRcvPos;
RobMeades 0:0b75e22c9231 1063 }
RobMeades 0:0b75e22c9231 1064
RobMeades 0:0b75e22c9231 1065 // Get number of positions records expected to be received.
RobMeades 0:0b75e22c9231 1066 int UbloxATCellularInterfaceExt::cellLocGetExpRes()
RobMeades 0:0b75e22c9231 1067 {
RobMeades 0:0b75e22c9231 1068 int numRecords = 0;
RobMeades 0:0b75e22c9231 1069 LOCK();
RobMeades 0:0b75e22c9231 1070
RobMeades 0:0b75e22c9231 1071 _at->recv("OK");
RobMeades 0:0b75e22c9231 1072
RobMeades 0:0b75e22c9231 1073 if (_locRcvPos > 0) {
RobMeades 0:0b75e22c9231 1074 numRecords = _locExpPos;
RobMeades 0:0b75e22c9231 1075 }
RobMeades 0:0b75e22c9231 1076
RobMeades 0:0b75e22c9231 1077 UNLOCK();
RobMeades 0:0b75e22c9231 1078 return numRecords;
RobMeades 0:0b75e22c9231 1079 }
RobMeades 0:0b75e22c9231 1080
RobMeades 0:0b75e22c9231 1081 // End of file
RobMeades 0:0b75e22c9231 1082