Skip to content

Commit a6e27b1

Browse files
authored
Merge pull request #6082 from AriParkkila/master
Mbed OS cellular connectivity
2 parents f0bda6c + f91cc33 commit a6e27b1

File tree

178 files changed

+19123
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+19123
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ matrix:
111111
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
112112
# Check that example compiles without rtos
113113
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
114-
- rm -r rtos features/netsocket features/frameworks BUILD
114+
- rm -r rtos features/cellular features/netsocket features/frameworks BUILD
115115
- python tools/make.py -t GCC_ARM -m DISCO_F401VC --source=. --build=BUILD/DISCO_F401VC/GCC_ARM -j0
116116
# Run local equeue tests
117117
- make -C $EVENTS/equeue test

features/cellular/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lcov/
2+
results/
3+
coverages/
4+
gcov/
5+
*.exe
6+
*.o
7+
*.d
8+
*.a
9+
*.gcda
10+
*.gcno
11+
cpputest_*.xml
12+
*_unit_tests*

features/cellular/.mbedignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UNITTESTS/*

features/cellular/Makefile.test

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# Makefile.test for CIot library unit tests
3+
#
4+
5+
6+
# List of subdirectories to build
7+
TEST_FOLDER_NAME := UNITTESTS
8+
TEST_FOLDER := ./UNITTESTS/
9+
# List of unit test directories for libraries
10+
UNITTESTS := $(sort $(dir $(wildcard $(TEST_FOLDER)*)))
11+
TESTDIRS := $(UNITTESTS:%=build-%)
12+
CLEANTESTDIRS := $(UNITTESTS:%=clean-%)
13+
COVERAGEFILE := ./lcov/coverage.info
14+
15+
.PHONY: test
16+
test: $(TESTDIRS)
17+
@rm -rf ./lcov
18+
@rm -rf ./coverage
19+
@mkdir -p lcov
20+
@mkdir -p lcov/results
21+
@mkdir coverage
22+
@find $(TEST_FOLDER) -name '*.xml' | xargs cp -t ./lcov/results/
23+
@rm -f lcov/index.xml
24+
@./xsl_script.sh
25+
@cp junit_xsl.xslt lcov/.
26+
@xsltproc -o lcov/testresults.html lcov/junit_xsl.xslt lcov/index.xml
27+
@rm -f lcov/junit_xsl.xslt
28+
@rm -f lcov/index.xml
29+
@find ./ -name '*.gcno' | xargs cp --backup=numbered -t ./coverage/
30+
@find ./ -name '*.gcda' | xargs cp --backup=numbered -t ./coverage/
31+
@gcovr --object-directory ./coverage --exclude-unreachable-branches -e '.*/builds/.*' -e '.*/$(TEST_FOLDER_NAME)/.*' -e '.*/yotta_modules/.*' -e '.*/stubs/.*' -e '.*/mbed-coap/.*' -x -o ./lcov/gcovr.xml
32+
@lcov -d $(TEST_FOLDER_NAME)/. -c -o $(COVERAGEFILE)
33+
@lcov -q -r $(COVERAGEFILE) "/usr*" -o $(COVERAGEFILE)
34+
@lcov -q -r $(COVERAGEFILE) "/$(TEST_FOLDER_NAME)*" -o $(COVERAGEFILE)
35+
@lcov -q -r $(COVERAGEFILE) "/mbed-client-libservice*" -o $(COVERAGEFILE)
36+
@lcov -q -r $(COVERAGEFILE) "/mbed-client*" -o $(COVERAGEFILE)
37+
@lcov -q -r $(COVERAGEFILE) "/mbed-os/events*" -o $(COVERAGEFILE)
38+
@lcov -q -r $(COVERAGEFILE) "/mbed-os/features/netsocket*" -o $(COVERAGEFILE)
39+
@lcov -q -r $(COVERAGEFILE) "/mbed-os/platform*" -o $(COVERAGEFILE)
40+
@genhtml -q $(COVERAGEFILE) --output-directory lcov/html
41+
@echo mbed-ciot module unit tests built
42+
43+
$(TESTDIRS):
44+
@make -C $(@:build-%=%)
45+
46+
$(CLEANDIRS):
47+
@make -C $(@:clean-%=%) clean
48+
49+
$(CLEANTESTDIRS):
50+
@make -C $(@:clean-%=%) clean
51+
52+
# Extend default clean rule
53+
clean: clean-extra
54+
55+
clean-extra: $(CLEANDIRS) \
56+
$(CLEANTESTDIRS)

features/cellular/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Mbed cellular connectivity
2+
3+
This is the Github repo for Mbed cellular connectivity:
4+
5+
easy_cellular/
6+
EasyCellularConnection Simplified cellular usage based on `CellularBase.h`
7+
CellularConnectionUtil A utility class for cellular connection
8+
9+
framework/
10+
API Application Programming Interface for cellular connectivity
11+
AT AT implementation based on 3GPP TS 27.007 specification
12+
common Common and utility sources
13+
targets Vendor specific cellular module adaptations
14+
15+
## Known limitations
16+
17+
**Please note that this is a first release of Cellular framework and is subject to further development in future.**
18+
19+
Only UDP is supported when using AT commands to control sockets in an IP stack built into the cellular modem. If TCP is required, use the PPP/LWIP stack.
20+
21+
## Supported modules
22+
23+
You can find currently supported cellular modules in the `framework/targets/` folder, where we also add support for new cellular modules.
24+
25+
## Cellular configuration
26+
27+
You can change cellular defaults in the `mbed_app.json` configuration file:
28+
29+
"config": {
30+
"cellular_plmn": {
31+
"help": "PLMN selection, 0=auto",
32+
"value": 0
33+
},
34+
"apn": {
35+
"help": "Access point name, e.g. internet",
36+
"value": "\"internet\""
37+
},
38+
"cellular_sim_pin": {
39+
"help": "PIN code",
40+
"value": "\"1234\""
41+
}
42+
}
43+
44+
## Debug traces
45+
46+
You can define the debug tracing level in the `mbed_app.json` configuration file:
47+
48+
"target_overrides": {
49+
"*": {
50+
"target.features_add": ["COMMON_PAL"],
51+
"mbed-trace.enable": true,
52+
"platform.stdio-convert-newlines": true,
53+
"platform.stdio-baud-rate": 115200,
54+
"platform.default-serial-baud-rate": 115200
55+
}
56+
},
57+
"config": {
58+
"trace-level": {
59+
"help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG",
60+
"macro_name": "MBED_TRACE_MAX_LEVEL",
61+
"value": "TRACE_LEVEL_INFO"
62+
}
63+
}
64+
65+
## Unit tests
66+
67+
The `UNITTESTS` folder contains unit tests for cellular specific classes. Unit tests are based on the stubbing method.
68+
69+
You can run those tests locally by running `./run_tests` script under the `UNITTESTS/` folder.
70+
71+
You need the following applications: `cpputest`, `gcov` and `lcov` (genhtml) for running the tests.
72+
73+
After you have run the `run_tests` script, you can find test results under `UNITTESTS/results` folder and line and function coverages under the `UNITTESTS/coverages` folder.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef CELLULAR_TESTS_H
18+
#define CELLULAR_TESTS_H
19+
20+
#include "CellularUtil.h" // for CELLULAR_ helper macros
21+
#include "CellularTargets.h"
22+
23+
#ifdef CELLULAR_DEVICE
24+
25+
#include "mbed_events.h"
26+
27+
#include "greentea-client/test_env.h"
28+
#include "unity.h"
29+
#include "utest.h"
30+
31+
#include "CellularLog.h"
32+
33+
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
34+
extern EventQueue queue;
35+
extern CELLULAR_DEVICE cellularDevice;
36+
37+
extern UARTSerial serial;
38+
extern CellularNetwork *network;
39+
40+
extern CellularSMS *sms;
41+
extern CellularPower *pwr;
42+
extern CellularSIM *sim;
43+
44+
45+
/**
46+
* TEST CASES DEFINED HERE AND in main.cpp
47+
*/
48+
49+
// power
50+
void test_create_power(void);
51+
52+
// SIM
53+
void test_get_sim_state(void);
54+
void test_set_pin(void);
55+
void test_change_pin(void);
56+
57+
// sms
58+
void test_sms_init(void);
59+
60+
// network
61+
void test_attach(void);
62+
void test_connect(void);
63+
void test_get_ip_address(void);
64+
void test_disconnect(void);
65+
66+
// stack
67+
void test_socket_open(void);
68+
void test_socket_bind(void);
69+
/*
70+
void test_socket_set_blocking();
71+
void test_socket_send_receive_blocking();
72+
*/
73+
void test_socket_set_non_blocking();
74+
void test_socket_send_receive_non_blocking();
75+
void test_socket_close(void);
76+
77+
// Test closing all interface via device
78+
void test_close_interfaces(void);
79+
80+
#endif // CELLULAR_DEVICE
81+
82+
#endif // CELLULAR_TESTS_H
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "CellularTests.h"
19+
20+
#if !defined(MBED_CONF_NSAPI_PRESENT)
21+
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
22+
#endif
23+
24+
#ifndef CELLULAR_DEVICE
25+
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined for this test
26+
#endif
27+
28+
EventQueue queue(32 * EVENTS_EVENT_SIZE);
29+
Thread t;
30+
CELLULAR_DEVICE cellularDevice(queue);
31+
32+
UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
33+
CellularNetwork *network = NULL;
34+
CellularPower *pwr = NULL;
35+
CellularSIM *sim = NULL;
36+
CellularSMS *sms = NULL;
37+
38+
using namespace utest::v1;
39+
40+
// using namespace mbed;
41+
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
42+
{
43+
greentea_case_failure_abort_handler(source, reason);
44+
return STATUS_CONTINUE;
45+
}
46+
47+
Case cases[] = {
48+
// power test
49+
Case("Create power", test_create_power, greentea_failure_handler),
50+
#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN
51+
// sim test
52+
Case("test get SIM state", test_get_sim_state, greentea_failure_handler),
53+
Case("SIM set pin", test_set_pin, greentea_failure_handler),
54+
Case("SIM change pin", test_change_pin, greentea_failure_handler),
55+
#endif
56+
// network tests
57+
Case("attach", test_attach, greentea_failure_handler),
58+
// SMS tests
59+
Case("SMS init", test_sms_init, greentea_failure_handler),
60+
// network tests
61+
Case("connect", test_connect, greentea_failure_handler),
62+
Case("get_ip_address", test_get_ip_address, greentea_failure_handler),
63+
// stack tests
64+
Case("open", test_socket_open, greentea_failure_handler),
65+
Case("bind", test_socket_bind, greentea_failure_handler),
66+
// Case("set socket blocking", test_socket_set_blocking, greentea_failure_handler),
67+
// Case("socket send receive in blocking mode", test_socket_send_receive_blocking, greentea_failure_handler),
68+
Case("set socket non blocking", test_socket_set_non_blocking, greentea_failure_handler),
69+
Case("socket send receive in non blocking mode", test_socket_send_receive_non_blocking, greentea_failure_handler),
70+
Case("close", test_socket_close, greentea_failure_handler),
71+
// network tests
72+
Case("disconnect", test_disconnect, greentea_failure_handler),
73+
74+
// test closing of all interface, must be the last test case
75+
Case("Close all Interfaces", test_close_interfaces, greentea_failure_handler)
76+
};
77+
78+
utest::v1::status_t test_setup(const size_t number_of_cases)
79+
{
80+
GREENTEA_SETUP(300, "default_auto");
81+
82+
return verbose_test_setup_handler(number_of_cases);
83+
}
84+
85+
Specification specification(test_setup, cases);
86+
87+
void test_close_interfaces()
88+
{
89+
// SMS is already closed in it's test
90+
cellularDevice.close_network();
91+
cellularDevice.close_sim();
92+
cellularDevice.close_power();
93+
}
94+
95+
int main()
96+
{
97+
#if defined (MDMRTS) && defined (MDMCTS)
98+
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
99+
#endif
100+
pwr = cellularDevice.open_power(&serial);
101+
sim = cellularDevice.open_sim(&serial);
102+
sms = cellularDevice.open_sms(&serial);
103+
network = cellularDevice.open_network(&serial);
104+
105+
t.start(callback(&queue, &EventQueue::dispatch_forever));
106+
return Harness::run(specification);
107+
}

0 commit comments

Comments
 (0)