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:
mudassar0121
Date:
Fri Jan 03 15:46:29 2020 +0500
Revision:
34:4f08b9dd8d03
Parent:
30:da746bc48735
Child:
35:6a6ee1adff84
updated tests as disable_psm name changed to disable_power_saving_mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:0b75e22c9231 1 #include "mbed.h"
RobMeades 0:0b75e22c9231 2 #include "greentea-client/test_env.h"
RobMeades 0:0b75e22c9231 3 #include "unity.h"
RobMeades 0:0b75e22c9231 4 #include "utest.h"
RobMeades 0:0b75e22c9231 5 #include "UbloxATCellularInterfaceExt.h"
RobMeades 0:0b75e22c9231 6 #include "UDPSocket.h"
rob.meades@u-blox.com 5:9fd89567f769 7 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 8 #include "mbed_trace.h"
RobMeades 0:0b75e22c9231 9 #define TRACE_GROUP "TEST"
rob.meades@u-blox.com 5:9fd89567f769 10 #else
rob.meades@u-blox.com 5:9fd89567f769 11 #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 12 #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 13 #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 14 #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 15 #endif
RobMeades 0:0b75e22c9231 16
RobMeades 0:0b75e22c9231 17 using namespace utest::v1;
RobMeades 0:0b75e22c9231 18
RobMeades 0:0b75e22c9231 19 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 20 // COMPILE-TIME MACROS
RobMeades 0:0b75e22c9231 21 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 22
RobMeades 0:0b75e22c9231 23 // These macros can be overridden with an mbed_app.json file and
RobMeades 0:0b75e22c9231 24 // contents of the following form:
RobMeades 0:0b75e22c9231 25 //
RobMeades 0:0b75e22c9231 26 //{
RobMeades 0:0b75e22c9231 27 // "config": {
RobMeades 0:0b75e22c9231 28 // "apn": {
RobMeades 0:0b75e22c9231 29 // "value": "\"my_apn\""
RobMeades 0:0b75e22c9231 30 // },
RobMeades 0:0b75e22c9231 31 // "ftp-server": {
RobMeades 0:0b75e22c9231 32 // "value": "\"test.rebex.net\""
RobMeades 0:0b75e22c9231 33 // },
RobMeades 0:0b75e22c9231 34 // "ftp-username": {
RobMeades 0:0b75e22c9231 35 // "value": "\"demo\""
RobMeades 0:0b75e22c9231 36 // },
RobMeades 0:0b75e22c9231 37 // "ftp-password": {
RobMeades 0:0b75e22c9231 38 // "value": "\"password\""
RobMeades 0:0b75e22c9231 39 // },
RobMeades 0:0b75e22c9231 40 // "ftp-use-passive": {
RobMeades 0:0b75e22c9231 41 // "value": true
RobMeades 0:0b75e22c9231 42 // },
RobMeades 0:0b75e22c9231 43 // "ftp-server-supports-write": {
RobMeades 0:0b75e22c9231 44 // "value": false
RobMeades 0:0b75e22c9231 45 // },
RobMeades 0:0b75e22c9231 46 // "ftp-filename": {
RobMeades 0:0b75e22c9231 47 // "value": "\"readme.txt\""
RobMeades 0:0b75e22c9231 48 // },
RobMeades 0:0b75e22c9231 49 // "ftp-dirname": {
RobMeades 0:0b75e22c9231 50 // "value": "\"pub\""
RobMeades 0:0b75e22c9231 51 // }
RobMeades 0:0b75e22c9231 52 //}
RobMeades 0:0b75e22c9231 53
rob.meades@u-blox.com 11:3631f62bb359 54 // Whether debug trace is on
rob.meades@u-blox.com 11:3631f62bb359 55 #ifndef MBED_CONF_APP_DEBUG_ON
rob.meades@u-blox.com 11:3631f62bb359 56 # define MBED_CONF_APP_DEBUG_ON false
rob.meades@u-blox.com 11:3631f62bb359 57 #endif
rob.meades@u-blox.com 11:3631f62bb359 58
RobMeades 0:0b75e22c9231 59 // The credentials of the SIM in the board.
RobMeades 0:0b75e22c9231 60 #ifndef MBED_CONF_APP_DEFAULT_PIN
rob.meades@u-blox.com 11:3631f62bb359 61 // Note: if PIN is enabled on your SIM, you must define the PIN
rob.meades@u-blox.com 11:3631f62bb359 62 // for your SIM jere (e.g. using mbed_app.json to do so).
rob.meades@u-blox.com 11:3631f62bb359 63 # define MBED_CONF_APP_DEFAULT_PIN "0000"
RobMeades 0:0b75e22c9231 64 #endif
RobMeades 0:0b75e22c9231 65
RobMeades 0:0b75e22c9231 66 // Network credentials.
RobMeades 0:0b75e22c9231 67 #ifndef MBED_CONF_APP_APN
RobMeades 0:0b75e22c9231 68 # define MBED_CONF_APP_APN NULL
RobMeades 0:0b75e22c9231 69 #endif
RobMeades 0:0b75e22c9231 70 #ifndef MBED_CONF_APP_USERNAME
RobMeades 0:0b75e22c9231 71 # define MBED_CONF_APP_USERNAME NULL
RobMeades 0:0b75e22c9231 72 #endif
RobMeades 0:0b75e22c9231 73 #ifndef MBED_CONF_APP_PASSWORD
RobMeades 0:0b75e22c9231 74 # define MBED_CONF_APP_PASSWORD NULL
RobMeades 0:0b75e22c9231 75 #endif
RobMeades 0:0b75e22c9231 76
RobMeades 0:0b75e22c9231 77 // FTP server name
RobMeades 0:0b75e22c9231 78 #ifndef MBED_CONF_APP_FTP_SERVER
RobMeades 0:0b75e22c9231 79 # error "Must define an FTP server name to run these tests"
RobMeades 0:0b75e22c9231 80 #endif
RobMeades 0:0b75e22c9231 81
RobMeades 0:0b75e22c9231 82 // User name on the FTP server
RobMeades 0:0b75e22c9231 83 #ifndef MBED_CONF_APP_FTP_USERNAME
RobMeades 0:0b75e22c9231 84 # define MBED_CONF_APP_FTP_SERVER_USERNAME ""
RobMeades 0:0b75e22c9231 85 #endif
RobMeades 0:0b75e22c9231 86
RobMeades 0:0b75e22c9231 87 // Password on the FTP server
RobMeades 0:0b75e22c9231 88 #ifndef MBED_CONF_APP_FTP_PASSWORD
RobMeades 0:0b75e22c9231 89 # define MBED_CONF_APP_FTP_SERVER_PASSWORD ""
RobMeades 0:0b75e22c9231 90 #endif
RobMeades 0:0b75e22c9231 91
RobMeades 0:0b75e22c9231 92 // Whether to use SFTP or not
RobMeades 0:0b75e22c9231 93 #ifndef MBED_CONF_APP_FTP_SECURE
RobMeades 0:0b75e22c9231 94 # define MBED_CONF_APP_FTP_SECURE false
RobMeades 0:0b75e22c9231 95 #endif
RobMeades 0:0b75e22c9231 96
RobMeades 0:0b75e22c9231 97 // Port to use on the remote server
RobMeades 0:0b75e22c9231 98 #ifndef MBED_CONF_APP_FTP_SERVER_PORT
RobMeades 0:0b75e22c9231 99 # if MBED_CONF_APP_FTP_SECURE
RobMeades 0:0b75e22c9231 100 # define MBED_CONF_APP_FTP_SERVER_PORT 22
RobMeades 0:0b75e22c9231 101 # else
RobMeades 0:0b75e22c9231 102 # define MBED_CONF_APP_FTP_SERVER_PORT 21
RobMeades 0:0b75e22c9231 103 # endif
RobMeades 0:0b75e22c9231 104 #endif
RobMeades 0:0b75e22c9231 105
RobMeades 0:0b75e22c9231 106 // Whether to use passive or active mode
RobMeades 0:0b75e22c9231 107 // default to true as many servers/networks
RobMeades 0:0b75e22c9231 108 // require this
RobMeades 0:0b75e22c9231 109 #ifndef MBED_CONF_APP_FTP_USE_PASSIVE
RobMeades 0:0b75e22c9231 110 # define MBED_CONF_APP_FTP_USE_PASSIVE true
RobMeades 0:0b75e22c9231 111 #endif
RobMeades 0:0b75e22c9231 112
RobMeades 0:0b75e22c9231 113 // Whether the server supports FTP write operations
RobMeades 0:0b75e22c9231 114 #ifndef MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE
RobMeades 0:0b75e22c9231 115 # define MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE false
RobMeades 0:0b75e22c9231 116 #endif
RobMeades 0:0b75e22c9231 117
RobMeades 0:0b75e22c9231 118 #if MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE
RobMeades 0:0b75e22c9231 119 // The name of the file to PUT, GET and then delete
RobMeades 0:0b75e22c9231 120 # ifndef MBED_CONF_APP_FTP_FILENAME
RobMeades 0:0b75e22c9231 121 # define MBED_CONF_APP_FTP_FILENAME "test_file_delete_me"
RobMeades 0:0b75e22c9231 122 # endif
RobMeades 0:0b75e22c9231 123 // The name of the directory to create, CD to and then remove
rob.meades@u-blox.com 11:3631f62bb359 124 // Must not be a substring of MBED_CONF_APP_FTP_FILENAME.
RobMeades 0:0b75e22c9231 125 # ifndef MBED_CONF_APP_FTP_DIRNAME
RobMeades 0:0b75e22c9231 126 # define MBED_CONF_APP_FTP_DIRNAME "test_dir_delete_me"
RobMeades 0:0b75e22c9231 127 # endif
RobMeades 0:0b75e22c9231 128 #else
RobMeades 0:0b75e22c9231 129 // The name of the file to GET
RobMeades 0:0b75e22c9231 130 # ifndef MBED_CONF_APP_FTP_FILENAME
RobMeades 0:0b75e22c9231 131 # error "Must define the name of a file you know exists on the FTP server"
RobMeades 0:0b75e22c9231 132 # endif
RobMeades 0:0b75e22c9231 133 // The name of the directory to CD to
RobMeades 0:0b75e22c9231 134 # ifndef MBED_CONF_APP_FTP_DIRNAME
RobMeades 0:0b75e22c9231 135 # error "Must define the name of a directory you know exists on the FTP server"
RobMeades 0:0b75e22c9231 136 # endif
RobMeades 0:0b75e22c9231 137 #endif
RobMeades 0:0b75e22c9231 138
RobMeades 0:0b75e22c9231 139 // The size of file when testing PUT/GET
RobMeades 0:0b75e22c9231 140 #ifndef MBED_CONF_APP_FTP_FILE_SIZE
rob.meades@u-blox.com 11:3631f62bb359 141 # define MBED_CONF_APP_FTP_FILE_SIZE 1200
RobMeades 0:0b75e22c9231 142 #endif
RobMeades 0:0b75e22c9231 143
RobMeades 0:0b75e22c9231 144 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 145 // PRIVATE VARIABLES
RobMeades 0:0b75e22c9231 146 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 147
rob.meades@u-blox.com 5:9fd89567f769 148 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 149 // Lock for debug prints
RobMeades 0:0b75e22c9231 150 static Mutex mtx;
rob.meades@u-blox.com 5:9fd89567f769 151 #endif
RobMeades 0:0b75e22c9231 152
RobMeades 0:0b75e22c9231 153 // An instance of the cellular interface
RobMeades 0:0b75e22c9231 154 static UbloxATCellularInterfaceExt *pDriver =
RobMeades 0:0b75e22c9231 155 new UbloxATCellularInterfaceExt(MDMTXD, MDMRXD,
RobMeades 0:0b75e22c9231 156 MBED_CONF_UBLOX_CELL_BAUD_RATE,
rob.meades@u-blox.com 11:3631f62bb359 157 MBED_CONF_APP_DEBUG_ON);
RobMeades 0:0b75e22c9231 158 // A buffer for general use
RobMeades 0:0b75e22c9231 159 static char buf[MBED_CONF_APP_FTP_FILE_SIZE];
RobMeades 0:0b75e22c9231 160
RobMeades 0:0b75e22c9231 161 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 162 // PRIVATE FUNCTIONS
RobMeades 0:0b75e22c9231 163 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 164
rob.meades@u-blox.com 5:9fd89567f769 165 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 166 // Locks for debug prints
RobMeades 0:0b75e22c9231 167 static void lock()
RobMeades 0:0b75e22c9231 168 {
RobMeades 0:0b75e22c9231 169 mtx.lock();
RobMeades 0:0b75e22c9231 170 }
RobMeades 0:0b75e22c9231 171
RobMeades 0:0b75e22c9231 172 static void unlock()
RobMeades 0:0b75e22c9231 173 {
RobMeades 0:0b75e22c9231 174 mtx.unlock();
RobMeades 0:0b75e22c9231 175 }
rob.meades@u-blox.com 5:9fd89567f769 176 #endif
RobMeades 0:0b75e22c9231 177
RobMeades 0:0b75e22c9231 178 // Write a file to the module's file system with known contents
RobMeades 0:0b75e22c9231 179 void createFile(const char * filename) {
RobMeades 0:0b75e22c9231 180
RobMeades 0:0b75e22c9231 181 for (unsigned int x = 0; x < sizeof (buf); x++) {
RobMeades 0:0b75e22c9231 182 buf[x] = (char) x;
RobMeades 0:0b75e22c9231 183 }
RobMeades 0:0b75e22c9231 184
RobMeades 0:0b75e22c9231 185 TEST_ASSERT(pDriver->writeFile(filename, buf, sizeof (buf)) == sizeof (buf));
RobMeades 0:0b75e22c9231 186 tr_debug("%d bytes written to file \"%s\"", sizeof (buf), filename);
RobMeades 0:0b75e22c9231 187 }
RobMeades 0:0b75e22c9231 188
RobMeades 0:0b75e22c9231 189 // Read a file back from the module's file system and check the contents
RobMeades 0:0b75e22c9231 190 void checkFile(const char * filename) {
RobMeades 0:0b75e22c9231 191 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 192
RobMeades 0:0b75e22c9231 193 int x = pDriver->readFile(filename, buf, sizeof (buf));
RobMeades 0:0b75e22c9231 194 tr_debug ("File is %d bytes big", x);
RobMeades 0:0b75e22c9231 195 TEST_ASSERT(x == sizeof (buf));
RobMeades 0:0b75e22c9231 196
RobMeades 0:0b75e22c9231 197 tr_debug("%d bytes read from file \"%s\"", sizeof (buf), filename);
RobMeades 0:0b75e22c9231 198
RobMeades 0:0b75e22c9231 199 for (unsigned int x = 0; x < sizeof (buf); x++) {
RobMeades 0:0b75e22c9231 200 TEST_ASSERT(buf[x] == (char) x);
RobMeades 0:0b75e22c9231 201 }
RobMeades 0:0b75e22c9231 202 }
RobMeades 0:0b75e22c9231 203
RobMeades 0:0b75e22c9231 204 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 205 // TESTS
RobMeades 0:0b75e22c9231 206 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 207
RobMeades 0:0b75e22c9231 208 // Test the setting up of parameters, connection and login to an FTP session
RobMeades 0:0b75e22c9231 209 void test_ftp_login() {
RobMeades 0:0b75e22c9231 210 SocketAddress address;
RobMeades 0:0b75e22c9231 211 char portString[10];
RobMeades 0:0b75e22c9231 212
RobMeades 0:0b75e22c9231 213 sprintf(portString, "%d", MBED_CONF_APP_FTP_SERVER_PORT);
wajahat.abbas@u-blox.com 30:da746bc48735 214 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 30:da746bc48735 215 int mno_profile;
wajahat.abbas@u-blox.com 30:da746bc48735 216 if (pDriver->init(MBED_CONF_APP_DEFAULT_PIN) == false) //init can return false if profile set is SW_DEFAULT
wajahat.abbas@u-blox.com 30:da746bc48735 217 {
wajahat.abbas@u-blox.com 30:da746bc48735 218 TEST_ASSERT(pDriver->get_mno_profile(&mno_profile));
wajahat.abbas@u-blox.com 30:da746bc48735 219 if (mno_profile == UbloxATCellularInterface::SW_DEFAULT) {
wajahat.abbas@u-blox.com 30:da746bc48735 220 TEST_ASSERT(pDriver->set_mno_profile(UbloxATCellularInterface::STANDARD_EU));
wajahat.abbas@u-blox.com 30:da746bc48735 221 TEST_ASSERT(pDriver->reboot_modem());
wajahat.abbas@u-blox.com 30:da746bc48735 222 tr_debug("Reboot successful\n");
wajahat.abbas@u-blox.com 30:da746bc48735 223 wait_ms(5000);
wajahat.abbas@u-blox.com 30:da746bc48735 224 }
wajahat.abbas@u-blox.com 30:da746bc48735 225 }
RobMeades 0:0b75e22c9231 226 TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN));
mudassar0121 34:4f08b9dd8d03 227 TEST_ASSERT(pDriver->disable_power_saving_mode());
wajahat.abbas@u-blox.com 30:da746bc48735 228 #else
wajahat.abbas@u-blox.com 30:da746bc48735 229 TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN));
wajahat.abbas@u-blox.com 30:da746bc48735 230 #endif
RobMeades 0:0b75e22c9231 231
RobMeades 0:0b75e22c9231 232 // Reset parameters to default to begin with
rob.meades@u-blox.com 11:3631f62bb359 233 pDriver->ftpResetPar();
RobMeades 0:0b75e22c9231 234
RobMeades 0:0b75e22c9231 235 // Set a timeout for FTP commands
RobMeades 0:0b75e22c9231 236 TEST_ASSERT(pDriver->ftpSetTimeout(60000));
RobMeades 0:0b75e22c9231 237
RobMeades 0:0b75e22c9231 238 // Set up the FTP server parameters
RobMeades 0:0b75e22c9231 239 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_SERVER_NAME,
RobMeades 0:0b75e22c9231 240 MBED_CONF_APP_FTP_SERVER));
RobMeades 0:0b75e22c9231 241 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_SERVER_PORT,
RobMeades 0:0b75e22c9231 242 portString));
RobMeades 0:0b75e22c9231 243 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_USER_NAME,
RobMeades 0:0b75e22c9231 244 MBED_CONF_APP_FTP_USERNAME));
RobMeades 0:0b75e22c9231 245 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_PASSWORD,
RobMeades 0:0b75e22c9231 246 MBED_CONF_APP_FTP_PASSWORD));
RobMeades 0:0b75e22c9231 247 #ifdef MBED_CONF_APP_FTP_ACCOUNT
RobMeades 0:0b75e22c9231 248 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_ACCOUNT,
RobMeades 0:0b75e22c9231 249 MBED_CONF_APP_FTP_ACCOUNT));
RobMeades 0:0b75e22c9231 250 #endif
RobMeades 0:0b75e22c9231 251 #if MBED_CONF_APP_FTP_SECURE
RobMeades 0:0b75e22c9231 252 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_SECURE, "1"));
RobMeades 0:0b75e22c9231 253 #endif
RobMeades 0:0b75e22c9231 254 #if MBED_CONF_APP_FTP_USE_PASSIVE
RobMeades 0:0b75e22c9231 255 TEST_ASSERT(pDriver->ftpSetPar(UbloxATCellularInterfaceExt::FTP_MODE, "1"));
RobMeades 0:0b75e22c9231 256 #endif
RobMeades 0:0b75e22c9231 257
RobMeades 0:0b75e22c9231 258 // Now connect to the network
RobMeades 0:0b75e22c9231 259 TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
RobMeades 0:0b75e22c9231 260 MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
RobMeades 0:0b75e22c9231 261
RobMeades 0:0b75e22c9231 262 // Get the server IP address, purely to make sure it's there
RobMeades 0:0b75e22c9231 263 TEST_ASSERT(pDriver->gethostbyname(MBED_CONF_APP_FTP_SERVER, &address) == 0);
RobMeades 0:0b75e22c9231 264 tr_debug ("Using FTP \"%s\", which is at %s", MBED_CONF_APP_FTP_SERVER,
RobMeades 0:0b75e22c9231 265 address.get_ip_address());
RobMeades 0:0b75e22c9231 266
RobMeades 0:0b75e22c9231 267 // Log into the FTP server
RobMeades 0:0b75e22c9231 268 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LOGIN) == NULL);
RobMeades 0:0b75e22c9231 269 }
RobMeades 0:0b75e22c9231 270
RobMeades 0:0b75e22c9231 271 // Test FTP directory listing
RobMeades 0:0b75e22c9231 272 void test_ftp_dir() {
RobMeades 0:0b75e22c9231 273 // Get a directory listing
RobMeades 0:0b75e22c9231 274 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 275 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 276 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 277
RobMeades 0:0b75e22c9231 278 // The file we will GET should appear in the directory listing
mudassar0121 27:12b47e78f601 279 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME));
RobMeades 0:0b75e22c9231 280 // As should the directory name we will change to
mudassar0121 27:12b47e78f601 281 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME));
RobMeades 0:0b75e22c9231 282 }
RobMeades 0:0b75e22c9231 283
RobMeades 0:0b75e22c9231 284 // Test FTP file information
RobMeades 0:0b75e22c9231 285 void test_ftp_fileinfo() {
RobMeades 0:0b75e22c9231 286 // Get the info
RobMeades 0:0b75e22c9231 287 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_FILE_INFO,
rob.meades@u-blox.com 11:3631f62bb359 288 MBED_CONF_APP_FTP_FILENAME, NULL,
RobMeades 0:0b75e22c9231 289 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 290 tr_debug("File info:\n%s", buf);
RobMeades 0:0b75e22c9231 291
RobMeades 0:0b75e22c9231 292 // The file info string should at least include the file name
mudassar0121 27:12b47e78f601 293 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME));
RobMeades 0:0b75e22c9231 294 }
RobMeades 0:0b75e22c9231 295
RobMeades 0:0b75e22c9231 296 #if MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE
RobMeades 0:0b75e22c9231 297
RobMeades 0:0b75e22c9231 298 // In case a previous test failed half way, do some cleaning up first
RobMeades 0:0b75e22c9231 299 // Note: don't check return values as these operations will fail
RobMeades 0:0b75e22c9231 300 // if there's nothing to clean up
RobMeades 0:0b75e22c9231 301 void test_ftp_write_cleanup() {
RobMeades 0:0b75e22c9231 302 pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_DELETE_FILE,
RobMeades 0:0b75e22c9231 303 MBED_CONF_APP_FTP_FILENAME);
RobMeades 0:0b75e22c9231 304 pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_DELETE_FILE,
RobMeades 0:0b75e22c9231 305 MBED_CONF_APP_FTP_FILENAME "_2");
RobMeades 0:0b75e22c9231 306 pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_RMDIR,
RobMeades 0:0b75e22c9231 307 MBED_CONF_APP_FTP_DIRNAME);
RobMeades 0:0b75e22c9231 308 pDriver->delFile(MBED_CONF_APP_FTP_FILENAME);
RobMeades 0:0b75e22c9231 309 pDriver->delFile(MBED_CONF_APP_FTP_FILENAME "_1");
RobMeades 0:0b75e22c9231 310 }
RobMeades 0:0b75e22c9231 311
RobMeades 0:0b75e22c9231 312 // Test FTP put and then get
RobMeades 0:0b75e22c9231 313 void test_ftp_put_get() {
RobMeades 0:0b75e22c9231 314 // Create the file
RobMeades 0:0b75e22c9231 315 createFile(MBED_CONF_APP_FTP_FILENAME);
RobMeades 0:0b75e22c9231 316
RobMeades 0:0b75e22c9231 317 // Put the file
RobMeades 0:0b75e22c9231 318 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_PUT_FILE,
RobMeades 0:0b75e22c9231 319 MBED_CONF_APP_FTP_FILENAME) == NULL);
RobMeades 0:0b75e22c9231 320
RobMeades 0:0b75e22c9231 321 // Get the file
RobMeades 0:0b75e22c9231 322 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_GET_FILE,
RobMeades 0:0b75e22c9231 323 MBED_CONF_APP_FTP_FILENAME,
RobMeades 0:0b75e22c9231 324 MBED_CONF_APP_FTP_FILENAME "_1") == NULL);
RobMeades 0:0b75e22c9231 325
RobMeades 0:0b75e22c9231 326 // Check that it is the same as we sent
RobMeades 0:0b75e22c9231 327 checkFile(MBED_CONF_APP_FTP_FILENAME "_1");
RobMeades 0:0b75e22c9231 328 }
RobMeades 0:0b75e22c9231 329
RobMeades 0:0b75e22c9231 330 // Test FTP rename file
RobMeades 0:0b75e22c9231 331 void test_ftp_rename() {
RobMeades 0:0b75e22c9231 332 // Get a directory listing
RobMeades 0:0b75e22c9231 333 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 334 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 335 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 336
RobMeades 0:0b75e22c9231 337 // The file we are renaming to should not appear
RobMeades 0:0b75e22c9231 338 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME "_2") == NULL);
RobMeades 0:0b75e22c9231 339
RobMeades 0:0b75e22c9231 340 // Rename the file
RobMeades 0:0b75e22c9231 341 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_RENAME_FILE,
RobMeades 0:0b75e22c9231 342 MBED_CONF_APP_FTP_FILENAME,
RobMeades 0:0b75e22c9231 343 MBED_CONF_APP_FTP_FILENAME "_2") == NULL);
RobMeades 0:0b75e22c9231 344
RobMeades 0:0b75e22c9231 345 // Get a directory listing
RobMeades 0:0b75e22c9231 346 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 347 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 348 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 349
RobMeades 0:0b75e22c9231 350 // The new file should now exist
RobMeades 0:0b75e22c9231 351 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME "_2") > NULL);
RobMeades 0:0b75e22c9231 352
RobMeades 0:0b75e22c9231 353 }
RobMeades 0:0b75e22c9231 354
RobMeades 0:0b75e22c9231 355 // Test FTP delete file
RobMeades 0:0b75e22c9231 356 void test_ftp_delete() {
RobMeades 0:0b75e22c9231 357 // Get a directory listing
RobMeades 0:0b75e22c9231 358 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 359 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 360 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 361
RobMeades 0:0b75e22c9231 362 // The file we are to delete should appear in the list
RobMeades 0:0b75e22c9231 363 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME "_2") > NULL);
RobMeades 0:0b75e22c9231 364
RobMeades 0:0b75e22c9231 365 // Delete the file
RobMeades 0:0b75e22c9231 366 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_DELETE_FILE,
RobMeades 0:0b75e22c9231 367 MBED_CONF_APP_FTP_FILENAME "_2") == NULL);
RobMeades 0:0b75e22c9231 368
RobMeades 0:0b75e22c9231 369 // Get a directory listing
RobMeades 0:0b75e22c9231 370 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 371 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 372 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 373
RobMeades 0:0b75e22c9231 374 // The file we deleted should no longer appear in the list
RobMeades 0:0b75e22c9231 375 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_FILENAME "_2") == NULL);
RobMeades 0:0b75e22c9231 376 }
RobMeades 0:0b75e22c9231 377
RobMeades 0:0b75e22c9231 378 // Test FTP MKDIR
RobMeades 0:0b75e22c9231 379 void test_ftp_mkdir() {
RobMeades 0:0b75e22c9231 380 // Get a directory listing
RobMeades 0:0b75e22c9231 381 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 382 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 383 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 384
RobMeades 0:0b75e22c9231 385 // The directory we are to create should not appear in the list
RobMeades 0:0b75e22c9231 386 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 387
RobMeades 0:0b75e22c9231 388 // Create the directory
RobMeades 0:0b75e22c9231 389 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_MKDIR,
RobMeades 0:0b75e22c9231 390 MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 391
RobMeades 0:0b75e22c9231 392 // Get a directory listing
RobMeades 0:0b75e22c9231 393 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 394 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 395 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 396
RobMeades 0:0b75e22c9231 397 // The directory we created should now appear in the list
RobMeades 0:0b75e22c9231 398 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME) > NULL);
RobMeades 0:0b75e22c9231 399 }
RobMeades 0:0b75e22c9231 400
RobMeades 0:0b75e22c9231 401 // Test FTP RMDIR
RobMeades 0:0b75e22c9231 402 void test_ftp_rmdir() {
RobMeades 0:0b75e22c9231 403 // Get a directory listing
RobMeades 0:0b75e22c9231 404 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 405 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 406 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 407
RobMeades 0:0b75e22c9231 408 // The directory we are to remove should appear in the list
RobMeades 0:0b75e22c9231 409 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME) > NULL);
RobMeades 0:0b75e22c9231 410
RobMeades 0:0b75e22c9231 411 // Remove the directory
RobMeades 0:0b75e22c9231 412 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_RMDIR,
RobMeades 0:0b75e22c9231 413 MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 414
RobMeades 0:0b75e22c9231 415 // Get a directory listing
RobMeades 0:0b75e22c9231 416 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 417 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 418 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 419
RobMeades 0:0b75e22c9231 420 // The directory we removed should no longer appear in the list
RobMeades 0:0b75e22c9231 421 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 422 }
RobMeades 0:0b75e22c9231 423
RobMeades 0:0b75e22c9231 424 #endif // MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE
RobMeades 0:0b75e22c9231 425
RobMeades 0:0b75e22c9231 426 // Test FTP get
RobMeades 0:0b75e22c9231 427 void test_ftp_get() {
RobMeades 0:0b75e22c9231 428 // Make sure that the 'get' filename we're going to use
RobMeades 0:0b75e22c9231 429 // isn't already here (but don't assert on this one
RobMeades 0:0b75e22c9231 430 // as, if the file isn't there, we will get an error)
RobMeades 0:0b75e22c9231 431 pDriver->delFile(MBED_CONF_APP_FTP_FILENAME);
RobMeades 0:0b75e22c9231 432
RobMeades 0:0b75e22c9231 433 // Get the file
RobMeades 0:0b75e22c9231 434 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_GET_FILE,
RobMeades 0:0b75e22c9231 435 MBED_CONF_APP_FTP_FILENAME) == NULL);
RobMeades 0:0b75e22c9231 436
RobMeades 0:0b75e22c9231 437 // Check that it has arrived
RobMeades 0:0b75e22c9231 438 TEST_ASSERT(pDriver->fileSize(MBED_CONF_APP_FTP_FILENAME) > 0);
RobMeades 0:0b75e22c9231 439 }
RobMeades 0:0b75e22c9231 440
RobMeades 0:0b75e22c9231 441 // Test FTP change directory
RobMeades 0:0b75e22c9231 442 void test_ftp_cd() {
RobMeades 0:0b75e22c9231 443 // Get a directory listing
RobMeades 0:0b75e22c9231 444 *buf = 0;
RobMeades 0:0b75e22c9231 445 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 446 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 447
RobMeades 0:0b75e22c9231 448 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 449
RobMeades 0:0b75e22c9231 450 // The listing should include the directory name we are going to move to
mudassar0121 27:12b47e78f601 451 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME));
RobMeades 0:0b75e22c9231 452
RobMeades 0:0b75e22c9231 453 // Change directories
RobMeades 0:0b75e22c9231 454 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_CD,
RobMeades 0:0b75e22c9231 455 MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 456 // Get a directory listing
RobMeades 0:0b75e22c9231 457 *buf = 0;
RobMeades 0:0b75e22c9231 458 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 459 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 460 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 461
RobMeades 0:0b75e22c9231 462 // The listing should no longer include the directory name we have moved
RobMeades 0:0b75e22c9231 463 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME) == NULL);
RobMeades 0:0b75e22c9231 464
RobMeades 0:0b75e22c9231 465 // Go back to where we were
RobMeades 0:0b75e22c9231 466 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_CD, "..")
RobMeades 0:0b75e22c9231 467 == NULL);
RobMeades 0:0b75e22c9231 468
RobMeades 0:0b75e22c9231 469 // Get a directory listing
RobMeades 0:0b75e22c9231 470 *buf = 0;
RobMeades 0:0b75e22c9231 471 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 11:3631f62bb359 472 NULL, NULL, buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 473 tr_debug("Listing:\n%s", buf);
RobMeades 0:0b75e22c9231 474
RobMeades 0:0b75e22c9231 475 // The listing should include the directory name we went to once more
mudassar0121 27:12b47e78f601 476 TEST_ASSERT(strstr(buf, MBED_CONF_APP_FTP_DIRNAME));
RobMeades 0:0b75e22c9231 477 }
RobMeades 0:0b75e22c9231 478
RobMeades 0:0b75e22c9231 479 #ifdef MBED_CONF_APP_FTP_FOTA_FILENAME
RobMeades 0:0b75e22c9231 480 // Test FTP FOTA
RobMeades 0:0b75e22c9231 481 // TODO: test not tested as I don't have a module that supports the FTP FOTA operation
RobMeades 0:0b75e22c9231 482 void test_ftp_fota() {
RobMeades 0:0b75e22c9231 483 *buf = 0;
RobMeades 0:0b75e22c9231 484 // Do FOTA on a file
RobMeades 0:0b75e22c9231 485 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_FOTA_FILE,
RobMeades 0:0b75e22c9231 486 MBED_CONF_APP_FTP_FOTA_FILENAME, NULL,
rob.meades@u-blox.com 11:3631f62bb359 487 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 488 tr_debug("MD5 sum: %s\n", buf);
RobMeades 0:0b75e22c9231 489
RobMeades 0:0b75e22c9231 490 // Check that the 128 bit MD5 sum is now there
RobMeades 0:0b75e22c9231 491 TEST_ASSERT(strlen (buf) == 32);
RobMeades 0:0b75e22c9231 492 }
RobMeades 0:0b75e22c9231 493 #endif
RobMeades 0:0b75e22c9231 494
RobMeades 0:0b75e22c9231 495 // Test logout and disconnect from an FTP session
RobMeades 0:0b75e22c9231 496 void test_ftp_logout() {
RobMeades 0:0b75e22c9231 497 // Log out from the FTP server
RobMeades 0:0b75e22c9231 498 TEST_ASSERT(pDriver->ftpCommand(UbloxATCellularInterfaceExt::FTP_LOGOUT) == NULL);
RobMeades 0:0b75e22c9231 499
RobMeades 0:0b75e22c9231 500 TEST_ASSERT(pDriver->disconnect() == 0);
RobMeades 0:0b75e22c9231 501
RobMeades 0:0b75e22c9231 502 // Wait for printfs to leave the building or the test result string gets messed up
RobMeades 0:0b75e22c9231 503 wait_ms(500);
RobMeades 0:0b75e22c9231 504 }
RobMeades 0:0b75e22c9231 505
RobMeades 0:0b75e22c9231 506 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 507 // TEST ENVIRONMENT
RobMeades 0:0b75e22c9231 508 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 509
RobMeades 0:0b75e22c9231 510 // Setup the test environment
RobMeades 0:0b75e22c9231 511 utest::v1::status_t test_setup(const size_t number_of_cases) {
RobMeades 0:0b75e22c9231 512 // Setup Greentea with a timeout
RobMeades 0:0b75e22c9231 513 GREENTEA_SETUP(540, "default_auto");
RobMeades 0:0b75e22c9231 514 return verbose_test_setup_handler(number_of_cases);
RobMeades 0:0b75e22c9231 515 }
RobMeades 0:0b75e22c9231 516
RobMeades 0:0b75e22c9231 517 // Test cases
RobMeades 0:0b75e22c9231 518 Case cases[] = {
RobMeades 0:0b75e22c9231 519 Case("FTP log in", test_ftp_login),
RobMeades 0:0b75e22c9231 520 #if MBED_CONF_APP_FTP_SERVER_SUPPORTS_WRITE
RobMeades 0:0b75e22c9231 521 Case("Clean-up", test_ftp_write_cleanup),
RobMeades 0:0b75e22c9231 522 Case("FTP put and get", test_ftp_put_get),
RobMeades 0:0b75e22c9231 523 Case("FTP file info", test_ftp_fileinfo),
RobMeades 0:0b75e22c9231 524 Case("FTP rename", test_ftp_rename),
RobMeades 0:0b75e22c9231 525 Case("FTP make directory", test_ftp_mkdir),
rob.meades@u-blox.com 11:3631f62bb359 526 Case("FTP directory list", test_ftp_dir), Case("FTP delete", test_ftp_delete),
RobMeades 0:0b75e22c9231 527 Case("FTP change directory", test_ftp_cd),
RobMeades 0:0b75e22c9231 528 Case("FTP delete directory", test_ftp_rmdir),
RobMeades 0:0b75e22c9231 529 #else
RobMeades 0:0b75e22c9231 530 Case("FTP directory list", test_ftp_dir),
RobMeades 0:0b75e22c9231 531 Case("FTP file info", test_ftp_fileinfo),
RobMeades 0:0b75e22c9231 532 Case("FTP get", test_ftp_get),
RobMeades 0:0b75e22c9231 533 Case("FTP change directory", test_ftp_cd),
RobMeades 0:0b75e22c9231 534 #endif
RobMeades 0:0b75e22c9231 535 #ifdef MBED_CONF_APP_FTP_FOTA_FILENAME
RobMeades 0:0b75e22c9231 536 Case("FTP FOTA", test_ftp_fota),
RobMeades 0:0b75e22c9231 537 #endif
RobMeades 0:0b75e22c9231 538 Case("FTP log out", test_ftp_logout)
RobMeades 0:0b75e22c9231 539 };
RobMeades 0:0b75e22c9231 540
RobMeades 0:0b75e22c9231 541 Specification specification(test_setup, cases);
RobMeades 0:0b75e22c9231 542
RobMeades 0:0b75e22c9231 543 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 544 // MAIN
RobMeades 0:0b75e22c9231 545 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 546
RobMeades 0:0b75e22c9231 547 int main() {
rob.meades@u-blox.com 5:9fd89567f769 548
rob.meades@u-blox.com 5:9fd89567f769 549 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 550 mbed_trace_init();
RobMeades 0:0b75e22c9231 551
RobMeades 0:0b75e22c9231 552 mbed_trace_mutex_wait_function_set(lock);
RobMeades 0:0b75e22c9231 553 mbed_trace_mutex_release_function_set(unlock);
rob.meades@u-blox.com 5:9fd89567f769 554 #endif
RobMeades 0:0b75e22c9231 555
RobMeades 0:0b75e22c9231 556 // Run tests
RobMeades 0:0b75e22c9231 557 return !Harness::run(specification);
RobMeades 0:0b75e22c9231 558 }
RobMeades 0:0b75e22c9231 559
RobMeades 0:0b75e22c9231 560 // End Of File
RobMeades 0:0b75e22c9231 561