ublox-cellular-driver-gen Fork

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

Committer:
rob.meades@u-blox.com
Date:
Tue Jun 13 00:29:44 2017 +0100
Revision:
3:027c9eaec52c
Parent:
1:458e1b3d460c
Child:
5:b935404dcf7c
Update to work with external libraries, not yet fully working on C027 though, watch this space.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:bb5fabac67ab 1 #include "mbed.h"
RobMeades 0:bb5fabac67ab 2 #include "greentea-client/test_env.h"
RobMeades 0:bb5fabac67ab 3 #include "unity.h"
RobMeades 0:bb5fabac67ab 4 #include "utest.h"
RobMeades 0:bb5fabac67ab 5 #include "UbloxCellularDriverGen.h"
RobMeades 0:bb5fabac67ab 6 #include "UDPSocket.h"
rob.meades@u-blox.com 3:027c9eaec52c 7 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 8 #include "mbed_trace.h"
RobMeades 0:bb5fabac67ab 9 #define TRACE_GROUP "TEST"
rob.meades@u-blox.com 3:027c9eaec52c 10 #else
rob.meades@u-blox.com 3:027c9eaec52c 11 #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 12 #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 13 #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 14 #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 15 #endif
RobMeades 0:bb5fabac67ab 16
RobMeades 0:bb5fabac67ab 17 using namespace utest::v1;
RobMeades 0:bb5fabac67ab 18
RobMeades 0:bb5fabac67ab 19 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 20 // COMPILE-TIME MACROS
RobMeades 0:bb5fabac67ab 21 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 22
RobMeades 0:bb5fabac67ab 23 // These macros can be overridden with an mbed_app.json file and
RobMeades 0:bb5fabac67ab 24 // contents of the following form:
RobMeades 0:bb5fabac67ab 25 //
RobMeades 0:bb5fabac67ab 26 //{
RobMeades 0:bb5fabac67ab 27 // "config": {
RobMeades 0:bb5fabac67ab 28 // "default-pin": {
RobMeades 0:bb5fabac67ab 29 // "value": "\"my_pin\""
RobMeades 0:bb5fabac67ab 30 // }
RobMeades 0:bb5fabac67ab 31 //}
RobMeades 0:bb5fabac67ab 32
RobMeades 0:bb5fabac67ab 33 // The credentials of the SIM in the board.
RobMeades 0:bb5fabac67ab 34 #ifndef MBED_CONF_APP_DEFAULT_PIN
RobMeades 0:bb5fabac67ab 35 // Note: this is the PIN for the SIM with ICCID
RobMeades 0:bb5fabac67ab 36 // 8944501104169548380.
RobMeades 0:bb5fabac67ab 37 # define MBED_CONF_APP_DEFAULT_PIN "5134"
RobMeades 0:bb5fabac67ab 38 #endif
RobMeades 0:bb5fabac67ab 39
RobMeades 0:bb5fabac67ab 40 // The size of file to use.
RobMeades 0:bb5fabac67ab 41 #ifndef MBED_CONF_APP_FILE_SIZE
rob.meades@u-blox.com 3:027c9eaec52c 42 # define MBED_CONF_APP_FILE_SIZE 12000
RobMeades 0:bb5fabac67ab 43 #endif
RobMeades 0:bb5fabac67ab 44
RobMeades 0:bb5fabac67ab 45 // The name of the file to use.
RobMeades 0:bb5fabac67ab 46 #ifndef MBED_CONF_APP_FILE_NAME
RobMeades 0:bb5fabac67ab 47 # define MBED_CONF_APP_FILE_NAME "test_file"
RobMeades 0:bb5fabac67ab 48 #endif
RobMeades 0:bb5fabac67ab 49
RobMeades 0:bb5fabac67ab 50 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 51 // PRIVATE VARIABLES
RobMeades 0:bb5fabac67ab 52 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 53
RobMeades 0:bb5fabac67ab 54 // Lock for debug prints
RobMeades 0:bb5fabac67ab 55 static Mutex mtx;
RobMeades 0:bb5fabac67ab 56
RobMeades 0:bb5fabac67ab 57 // An instance of the generic cellular class
RobMeades 0:bb5fabac67ab 58 static UbloxCellularDriverGen *pDriver =
RobMeades 0:bb5fabac67ab 59 new UbloxCellularDriverGen(MDMTXD, MDMRXD,
RobMeades 0:bb5fabac67ab 60 MBED_CONF_UBLOX_CELL_BAUD_RATE,
RobMeades 0:bb5fabac67ab 61 true);
RobMeades 0:bb5fabac67ab 62
RobMeades 0:bb5fabac67ab 63 // A general purpose buffer
RobMeades 0:bb5fabac67ab 64 char buf[MBED_CONF_APP_FILE_SIZE];
RobMeades 0:bb5fabac67ab 65
RobMeades 0:bb5fabac67ab 66 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 67 // PRIVATE FUNCTIONS
RobMeades 0:bb5fabac67ab 68 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 69
rob.meades@u-blox.com 3:027c9eaec52c 70 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 71 // Locks for debug prints
RobMeades 0:bb5fabac67ab 72 static void lock()
RobMeades 0:bb5fabac67ab 73 {
RobMeades 0:bb5fabac67ab 74 mtx.lock();
RobMeades 0:bb5fabac67ab 75 }
RobMeades 0:bb5fabac67ab 76
RobMeades 0:bb5fabac67ab 77 static void unlock()
RobMeades 0:bb5fabac67ab 78 {
RobMeades 0:bb5fabac67ab 79 mtx.unlock();
RobMeades 0:bb5fabac67ab 80 }
rob.meades@u-blox.com 3:027c9eaec52c 81 #endif
RobMeades 0:bb5fabac67ab 82
RobMeades 0:bb5fabac67ab 83 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 84 // TESTS
RobMeades 0:bb5fabac67ab 85 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 86
RobMeades 0:bb5fabac67ab 87 // Initialise the module
RobMeades 0:bb5fabac67ab 88 void test_start() {
RobMeades 0:bb5fabac67ab 89 TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN));
RobMeades 0:bb5fabac67ab 90 }
RobMeades 0:bb5fabac67ab 91
RobMeades 0:bb5fabac67ab 92 // Write a file to the module's file system with known contents
RobMeades 0:bb5fabac67ab 93 void test_write() {
RobMeades 0:bb5fabac67ab 94
RobMeades 0:bb5fabac67ab 95 for (int x = 0; x < sizeof (buf); x++) {
RobMeades 0:bb5fabac67ab 96 buf[x] = (char) x;
RobMeades 0:bb5fabac67ab 97 }
RobMeades 0:bb5fabac67ab 98
RobMeades 0:bb5fabac67ab 99 TEST_ASSERT(pDriver->writeFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf));
RobMeades 0:bb5fabac67ab 100 TEST_ASSERT(pDriver->fileSize(MBED_CONF_APP_FILE_NAME) >= sizeof (buf));
RobMeades 0:bb5fabac67ab 101 tr_debug("%d bytes written to file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 102 }
RobMeades 0:bb5fabac67ab 103
RobMeades 0:bb5fabac67ab 104 // Read a file back from the module's file system and check the contents
RobMeades 0:bb5fabac67ab 105 void test_read() {
RobMeades 0:bb5fabac67ab 106 memset(buf, 0, sizeof (buf));
RobMeades 0:bb5fabac67ab 107
RobMeades 0:bb5fabac67ab 108 TEST_ASSERT(pDriver->readFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf));
RobMeades 0:bb5fabac67ab 109
RobMeades 0:bb5fabac67ab 110 tr_debug("%d bytes read from file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 111
RobMeades 0:bb5fabac67ab 112 for (int x = 0; x < sizeof (buf); x++) {
RobMeades 0:bb5fabac67ab 113 TEST_ASSERT(buf[x] == (char) x);
RobMeades 0:bb5fabac67ab 114 }
RobMeades 0:bb5fabac67ab 115 }
RobMeades 0:bb5fabac67ab 116
RobMeades 0:bb5fabac67ab 117 // Delete a file from the module's file system
RobMeades 0:bb5fabac67ab 118 void test_delete() {
RobMeades 0:bb5fabac67ab 119 TEST_ASSERT(pDriver->delFile(MBED_CONF_APP_FILE_NAME));
RobMeades 0:bb5fabac67ab 120 tr_debug("File \"%s\" deleted", MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 121 }
RobMeades 0:bb5fabac67ab 122
RobMeades 0:bb5fabac67ab 123 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 124 // TEST ENVIRONMENT
RobMeades 0:bb5fabac67ab 125 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 126
RobMeades 0:bb5fabac67ab 127 // Setup the test environment
RobMeades 0:bb5fabac67ab 128 utest::v1::status_t test_setup(const size_t number_of_cases) {
RobMeades 0:bb5fabac67ab 129 // Setup Greentea with a timeout
RobMeades 0:bb5fabac67ab 130 GREENTEA_SETUP(180, "default_auto");
RobMeades 0:bb5fabac67ab 131 return verbose_test_setup_handler(number_of_cases);
RobMeades 0:bb5fabac67ab 132 }
RobMeades 0:bb5fabac67ab 133
RobMeades 0:bb5fabac67ab 134 // Test cases
RobMeades 0:bb5fabac67ab 135 Case cases[] = {
RobMeades 0:bb5fabac67ab 136 Case("Start", test_start),
RobMeades 0:bb5fabac67ab 137 Case("Write file", test_write),
RobMeades 0:bb5fabac67ab 138 Case("Read file", test_read),
RobMeades 0:bb5fabac67ab 139 Case("Delete file", test_delete)
RobMeades 0:bb5fabac67ab 140 };
RobMeades 0:bb5fabac67ab 141
RobMeades 0:bb5fabac67ab 142 Specification specification(test_setup, cases);
RobMeades 0:bb5fabac67ab 143
RobMeades 0:bb5fabac67ab 144 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 145 // MAIN
RobMeades 0:bb5fabac67ab 146 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 147
RobMeades 0:bb5fabac67ab 148 int main() {
rob.meades@u-blox.com 3:027c9eaec52c 149
rob.meades@u-blox.com 3:027c9eaec52c 150 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 151 mbed_trace_init();
RobMeades 0:bb5fabac67ab 152
RobMeades 0:bb5fabac67ab 153 mbed_trace_mutex_wait_function_set(lock);
RobMeades 0:bb5fabac67ab 154 mbed_trace_mutex_release_function_set(unlock);
rob.meades@u-blox.com 3:027c9eaec52c 155 #endif
RobMeades 0:bb5fabac67ab 156
RobMeades 0:bb5fabac67ab 157 // Run tests
RobMeades 0:bb5fabac67ab 158 return !Harness::run(specification);
RobMeades 0:bb5fabac67ab 159 }
RobMeades 0:bb5fabac67ab 160
RobMeades 0:bb5fabac67ab 161 // End Of File
RobMeades 0:bb5fabac67ab 162