This class provides SMS, USSD and modem file system support for u-blox modules on the C027 and C030 boards (excepting the C030 N2xx flavour) from mbed 5.5 onwards.
Dependents: example-ublox-at-cellular-interface-ext example-ublox-cellular-driver-gen HelloMQTT ublox_new_driver_test ... more
main.cpp
00001 #include "mbed.h" 00002 #include "greentea-client/test_env.h" 00003 #include "unity.h" 00004 #include "utest.h" 00005 #include "UbloxCellularDriverGen.h" 00006 #include "UDPSocket.h" 00007 #ifdef FEATURE_COMMON_PAL 00008 #include "mbed_trace.h" 00009 #define TRACE_GROUP "TEST" 00010 #else 00011 #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__) 00012 #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__) 00013 #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__) 00014 #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__) 00015 #endif 00016 00017 using namespace utest::v1; 00018 00019 // ---------------------------------------------------------------- 00020 // COMPILE-TIME MACROS 00021 // ---------------------------------------------------------------- 00022 00023 // These macros can be overridden with an mbed_app.json file and 00024 // contents of the following form: 00025 // 00026 //{ 00027 // "config": { 00028 // "default-pin": { 00029 // "value": "\"my_pin\"" 00030 // } 00031 //} 00032 00033 // Whether debug trace is on 00034 #ifndef MBED_CONF_APP_DEBUG_ON 00035 # define MBED_CONF_APP_DEBUG_ON false 00036 #endif 00037 00038 // The credentials of the SIM in the board. 00039 #ifndef MBED_CONF_APP_DEFAULT_PIN 00040 // Note: this is the PIN for the SIM with ICCID 00041 // 8944501104169548380. 00042 # define MBED_CONF_APP_DEFAULT_PIN "5134" 00043 #endif 00044 00045 // The size of file to use. 00046 #ifndef MBED_CONF_APP_FILE_SIZE 00047 # ifdef TARGET_UBLOX_C027 00048 // C027 doesn't have so much RAM. 00049 // TODO: it should be possible to use, say 12000 00050 // here but it seems that the Sara-G350 module 00051 // needs flow control so that it can slow 00052 // things down while flash writees complete 00053 // and UARTSerial doesn't yet support HW 00054 // flow control. Come back to this once 00055 // UARTSerial has HW flow control. 00056 # define MBED_CONF_APP_FILE_SIZE 1500 00057 # else 00058 # define MBED_CONF_APP_FILE_SIZE 42000 00059 # endif 00060 #endif 00061 00062 // The name of the file to use. 00063 #ifndef MBED_CONF_APP_FILE_NAME 00064 # define MBED_CONF_APP_FILE_NAME "test_file" 00065 #endif 00066 00067 // ---------------------------------------------------------------- 00068 // PRIVATE VARIABLES 00069 // ---------------------------------------------------------------- 00070 00071 #ifdef FEATURE_COMMON_PAL 00072 // Lock for debug prints 00073 static Mutex mtx; 00074 #endif 00075 00076 // An instance of the generic cellular class 00077 static UbloxCellularDriverGen *pDriver = 00078 new UbloxCellularDriverGen(MDMTXD, MDMRXD, 00079 MBED_CONF_UBLOX_CELL_BAUD_RATE, 00080 MBED_CONF_APP_DEBUG_ON); 00081 00082 // A general purpose buffer 00083 char buf[MBED_CONF_APP_FILE_SIZE]; 00084 00085 // ---------------------------------------------------------------- 00086 // PRIVATE FUNCTIONS 00087 // ---------------------------------------------------------------- 00088 00089 #ifdef FEATURE_COMMON_PAL 00090 // Locks for debug prints 00091 static void lock() 00092 { 00093 mtx.lock(); 00094 } 00095 00096 static void unlock() 00097 { 00098 mtx.unlock(); 00099 } 00100 #endif 00101 00102 // ---------------------------------------------------------------- 00103 // TESTS 00104 // ---------------------------------------------------------------- 00105 00106 // Initialise the module 00107 void test_start() { 00108 TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN)); 00109 } 00110 00111 // Write a file to the module's file system with known contents 00112 void test_write() { 00113 00114 for (unsigned int x = 0; x < sizeof (buf); x++) { 00115 buf[x] = (char) x; 00116 } 00117 00118 TEST_ASSERT(pDriver->writeFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf)); 00119 TEST_ASSERT(pDriver->fileSize(MBED_CONF_APP_FILE_NAME) >= (int) sizeof (buf)); 00120 tr_debug("%d bytes written to file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME); 00121 } 00122 00123 // Read a file back from the module's file system and check the contents 00124 void test_read() { 00125 memset(buf, 0, sizeof (buf)); 00126 00127 TEST_ASSERT(pDriver->readFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf)); 00128 00129 tr_debug("%d bytes read from file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME); 00130 00131 for (unsigned int x = 0; x < sizeof (buf); x++) { 00132 TEST_ASSERT(buf[x] == (char) x); 00133 } 00134 } 00135 00136 // Delete a file from the module's file system 00137 void test_delete() { 00138 TEST_ASSERT(pDriver->delFile(MBED_CONF_APP_FILE_NAME)); 00139 tr_debug("File \"%s\" deleted", MBED_CONF_APP_FILE_NAME); 00140 } 00141 00142 // ---------------------------------------------------------------- 00143 // TEST ENVIRONMENT 00144 // ---------------------------------------------------------------- 00145 00146 // Setup the test environment 00147 utest::v1::status_t test_setup(const size_t number_of_cases) { 00148 // Setup Greentea with a timeout 00149 GREENTEA_SETUP(180, "default_auto"); 00150 return verbose_test_setup_handler(number_of_cases); 00151 } 00152 00153 // Test cases 00154 Case cases[] = { 00155 Case("Start", test_start), 00156 Case("Write file", test_write), 00157 Case("Read file", test_read), 00158 Case("Delete file", test_delete) 00159 }; 00160 00161 Specification specification(test_setup, cases); 00162 00163 // ---------------------------------------------------------------- 00164 // MAIN 00165 // ---------------------------------------------------------------- 00166 00167 int main() { 00168 00169 #ifdef FEATURE_COMMON_PAL 00170 mbed_trace_init(); 00171 00172 mbed_trace_mutex_wait_function_set(lock); 00173 mbed_trace_mutex_release_function_set(unlock); 00174 #endif 00175 00176 // Run tests 00177 return !Harness::run(specification); 00178 } 00179 00180 // End Of File 00181
Generated on Tue Jul 12 2022 17:22:58 by 1.7.2