mirror of https://github.com/ARMmbed/mbed-os.git
Updated tests
- Vodafone tests are gone for now - Added u-blox TCP test (UB_1) and SMS test (UB_2). - tests can now have more than a single source directorypull/88/head
parent
a34945661d
commit
bdf5d03ba1
|
@ -1,21 +1,20 @@
|
|||
#include "mbed.h"
|
||||
#include "VodafoneUSBModem.h"
|
||||
#include "CellularModem.h"
|
||||
#include "HTTPClient.h"
|
||||
#include "test_env.h"
|
||||
#include "httptest.h"
|
||||
|
||||
int main()
|
||||
int httptest(CellularModem& modem, const char* apn, const char* username, const char* password)
|
||||
{
|
||||
printf("Connecting...\n");
|
||||
|
||||
VodafoneUSBModem modem;
|
||||
HTTPClient http;
|
||||
char str[512];
|
||||
|
||||
int ret = modem.connect("internet", "web", "web");
|
||||
int ret = modem.connect(apn, username, password);
|
||||
if(ret)
|
||||
{
|
||||
printf("Could not connect\n");
|
||||
notify_completion(false); //Blocks indefinitely
|
||||
return false;
|
||||
}
|
||||
|
||||
//GET data
|
||||
|
@ -30,7 +29,7 @@ int main()
|
|||
{
|
||||
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
|
||||
modem.disconnect();
|
||||
notify_completion(false); //Blocks indefinitely
|
||||
return false;
|
||||
}
|
||||
|
||||
//POST data
|
||||
|
@ -49,10 +48,9 @@ int main()
|
|||
{
|
||||
printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
|
||||
modem.disconnect();
|
||||
notify_completion(false); //Blocks indefinitely
|
||||
return false;
|
||||
}
|
||||
|
||||
modem.disconnect();
|
||||
|
||||
notify_completion(true); //Blocks indefinitely
|
||||
modem.disconnect();
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef HTTPTEST_H_
|
||||
#define HTTPTEST_H_
|
||||
|
||||
#include "CellularModem.h"
|
||||
|
||||
int httptest(CellularModem& modem, const char* apn = NULL, const char* username = NULL, const char* password= NULL);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#include "UBloxUSBGSMModem.h"
|
||||
#include "test_env.h"
|
||||
#include "httptest.h"
|
||||
|
||||
#ifndef MODEM_APN
|
||||
#warning APN not specified, using "internet"
|
||||
#define APN "internet"
|
||||
#endif
|
||||
|
||||
#ifndef MODEM_USERNAME
|
||||
#warning username not specified
|
||||
#define USERNAME NULL
|
||||
#endif
|
||||
|
||||
#ifndef MODEM_PASSWORD
|
||||
#warning password not specified
|
||||
#define PASSWORD NULL
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
UbloxUSBGSMModem modem;
|
||||
|
||||
notify_completion(httptest(modem, APN, USERNAME, PASSWORD));
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#include "CellularModem.h"
|
||||
#include "smstest.h"
|
||||
|
||||
void smstest(CellularModem& modem)
|
||||
{
|
||||
#ifdef DESTINATION_NUMBER
|
||||
modem.sendSM(DESINATION_NUMBER, "Hello from mbed:)");
|
||||
#endif
|
||||
|
||||
while(true)
|
||||
{
|
||||
char num[17];
|
||||
char msg[64];
|
||||
size_t count;
|
||||
int ret = modem.getSMCount(&count);
|
||||
if(ret)
|
||||
{
|
||||
printf("getSMCount returned %d\n", ret);
|
||||
Thread::wait(3000);
|
||||
continue;
|
||||
}
|
||||
if( count > 0)
|
||||
{
|
||||
printf("%d SMS to read\n", count);
|
||||
ret = modem.getSM(num, msg, 64);
|
||||
if(ret)
|
||||
{
|
||||
printf("getSM returned %d\n", ret);
|
||||
Thread::wait(3000);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s : %s\n", num, msg);
|
||||
}
|
||||
Thread::wait(3000);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef SMSTEST_H_
|
||||
#define SMSTEST_H_
|
||||
|
||||
#include "CellularModem.h"
|
||||
|
||||
void smstest(CellularModem&);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#include "UBloxUSBGSMModem.h"
|
||||
#include "smstest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
UbloxUSBGSMModem modem;
|
||||
|
||||
smstest(modem);
|
||||
}
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
#include "mbed.h"
|
||||
#include "VodafoneUSBModem.h"
|
||||
#include "test_env.h"
|
||||
|
||||
bool compare_msisdn(char* remote_msisdn, char* local_msisdn)
|
||||
{
|
||||
if( !memcmp(remote_msisdn, "+44", 3) ) //Conver to local number
|
||||
{
|
||||
remote_msisdn += 2;
|
||||
remote_msisdn[0] = '0';
|
||||
}
|
||||
if( !memcmp(local_msisdn, "+44", 3) ) //Conver to local number
|
||||
{
|
||||
local_msisdn += 2;
|
||||
local_msisdn[0] = '0';
|
||||
}
|
||||
return !strcmp(remote_msisdn, local_msisdn);
|
||||
}
|
||||
|
||||
bool run(VodafoneUSBModem& modem)
|
||||
{
|
||||
char local_msisdn[32];
|
||||
char remote_msisdn[32];
|
||||
char local_msg[192];
|
||||
char remote_msg[192];
|
||||
|
||||
int ret;
|
||||
//Clear SMS inbox
|
||||
size_t count;
|
||||
do
|
||||
{
|
||||
ret = modem.getSMCount(&count);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(count)
|
||||
{
|
||||
//Fetch SMS
|
||||
ret = modem.getSM(remote_msisdn, remote_msg, 192);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} while(count);
|
||||
|
||||
//Now get MSISDN using USSD
|
||||
ret = modem.sendUSSD("*#100#", local_msisdn, 32);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Local MSISDN is %s\n", local_msisdn);
|
||||
|
||||
//Makeup a random text message (32 uppper case letters)
|
||||
for(int i = 0; i < 32; i++)
|
||||
{
|
||||
local_msg[i] = 'A' + (rand() % 26); //This is pseudo-random only, but we don't really care anyway
|
||||
}
|
||||
local_msg[32] = '\0'; //Terminate string
|
||||
|
||||
printf("Sending '%s'\n", local_msg);
|
||||
|
||||
//Send SM
|
||||
ret = modem.sendSM(local_msisdn, local_msg);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//Now wait for corresponding message for 15s max
|
||||
Timer t;
|
||||
t.start();
|
||||
do
|
||||
{
|
||||
ret = modem.getSMCount(&count);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(count)
|
||||
{
|
||||
//Fetch SM
|
||||
ret = modem.getSM(remote_msisdn, remote_msg, 192);
|
||||
if(ret)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("Received '%s' from %s\n", remote_msg, remote_msisdn);
|
||||
|
||||
if( compare_msisdn(remote_msisdn, local_msisdn) && !strcmp(remote_msg, local_msg) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(t.read_ms() > 15000)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Thread::wait(500);
|
||||
} while(true);
|
||||
|
||||
//Success :)
|
||||
return true;
|
||||
}
|
||||
|
||||
void test(void const*)
|
||||
{
|
||||
VodafoneUSBModem modem;
|
||||
bool test = run(modem);
|
||||
if(test)
|
||||
{
|
||||
printf("Test successful\n");
|
||||
notify_completion(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test failed\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
//notify_completion() blocks indefinitely
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Thread testTask(test, NULL, osPriorityNormal, 1024 * 5);
|
||||
DigitalOut led(LED1);
|
||||
while(1)
|
||||
{
|
||||
led=!led;
|
||||
Thread::wait(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -31,14 +31,17 @@ def build_project(src_path, build_path, target, toolchain_name,
|
|||
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify)
|
||||
toolchain.VERBOSE = verbose
|
||||
toolchain.build_all = clean
|
||||
|
||||
|
||||
src_paths = [src_path] if type(src_path) != ListType else src_path
|
||||
if name is None:
|
||||
name = basename(src_path)
|
||||
name = basename(src_paths[0])
|
||||
toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
|
||||
|
||||
# Scan src_path and libraries_paths for resources
|
||||
resources = toolchain.scan_resources(src_path)
|
||||
src_paths = [src_path]
|
||||
resources = toolchain.scan_resources(src_paths[0])
|
||||
for path in src_paths[1:]:
|
||||
print "PATH:", path
|
||||
resources.add(toolchain.scan_resources(path))
|
||||
if libraries_paths is not None:
|
||||
src_paths.extend(libraries_paths)
|
||||
for path in libraries_paths:
|
||||
|
|
|
@ -565,20 +565,21 @@ TESTS = [
|
|||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
|
||||
},
|
||||
|
||||
# Vodafone tests
|
||||
# u-blox tests
|
||||
{
|
||||
"id": "VF_1", "description": "HTTP client",
|
||||
"source_dir": join(TEST_DIR, "net", "vodafone", "HTTPClient_HelloWorld"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, VODAFONE_LIBRARY, TEST_MBED_LIB],
|
||||
"id": "UB_1", "description": "u-blox USB GSM modem: HTTP client",
|
||||
"source_dir": [join(TEST_DIR, "net", "cellular", "http", "ubloxusbgsm"), join(TEST_DIR, "net", "cellular", "http", "common")],
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, RTOS_LIBRARIES, USB_HOST_LIBRARIES, UBLOX_LIBRARY],
|
||||
"supported": CORTEX_ARM_SUPPORT,
|
||||
"automated": True,
|
||||
},
|
||||
{
|
||||
"id": "VF_2", "description": "USSD & SMS Test",
|
||||
"source_dir": join(TEST_DIR, "net", "vodafone", "USSD_SMS_HelloWorld"),
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, VODAFONE_LIBRARY, TEST_MBED_LIB],
|
||||
"id": "UB_2", "description": "u-blox USB GSM modem: SMS test",
|
||||
"source_dir": [join(TEST_DIR, "net", "cellular", "sms", "ubloxusbgsm"), join(TEST_DIR, "net", "cellular", "sms", "common")],
|
||||
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES, UBLOX_LIBRARY],
|
||||
"supported": CORTEX_ARM_SUPPORT,
|
||||
},
|
||||
|
||||
|
||||
# USB Tests
|
||||
{
|
||||
"id": "USB_1", "description": "Mouse",
|
||||
|
|
Loading…
Reference in New Issue