Skip to content

Commit c0151b1

Browse files
author
Teppo Järvelin
committed
Cellular: CellularContext must provide access to CellularDevice
When using NetworkInterface::get_default_instance() application gets handle to CellularInterface which is actually CellularContext derived from CellularInterface. Application needs also handle to CellularDevice to open other interfaces.
1 parent b29b55a commit c0151b1

File tree

13 files changed

+55
-8
lines changed

13 files changed

+55
-8
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ set(unittest-test-sources
4141
stubs/us_ticker_stub.cpp
4242
stubs/UARTSerial_stub.cpp
4343
stubs/SerialBase_stub.cpp
44+
stubs/CellularContext_stub.cpp
4445
)

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set(unittest-test-sources
4343
stubs/UARTSerial_stub.cpp
4444
stubs/SerialBase_stub.cpp
4545
stubs/CellularStateMachine_stub.cpp
46+
stubs/CellularContext_stub.cpp
4647
)
4748

4849
# defines

UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(unittest-test-sources
3232
stubs/Semaphore_stub.cpp
3333
stubs/NetworkInterface_stub.cpp
3434
stubs/NetworkInterfaceDefaults_stub.cpp
35+
stubs/CellularContext_stub.cpp
3536
)
3637

3738
# defines

UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(unittest-test-sources
3838
stubs/Mutex_stub.cpp
3939
stubs/EventQueue_stub.cpp
4040
stubs/equeue_stub.c
41+
stubs/CellularContext_stub.cpp
4142
)
4243

4344
# defines

UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "gtest/gtest.h"
1919
#include "features/netsocket/cellular/CellularNonIPSocket.h"
20-
#include "CellularContext_stub.h"
20+
#include "myCellularContext.h"
2121

2222
using namespace mbed;
2323

@@ -34,7 +34,7 @@ class TestCellularNonIPSocket : public testing::Test {
3434
protected:
3535
CellularNonIPSocket *socket;
3636
ControlPlane_netif_stub *cp_netif;
37-
CellularContext_stub cellular_context;
37+
myCellularContext cellular_context;
3838
nsapi_size_t dataSize;
3939
char dataBuf[10];
4040

UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ set(unittest-test-sources
1919
stubs/NetworkStack_stub.cpp
2020
stubs/EventFlags_stub.cpp
2121
stubs/Mutex_stub.cpp
22+
stubs/CellularContext_stub.cpp
2223
)

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using namespace mbed;
2121

2222
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
2323
AT_CellularBase(at), _is_blocking(true), _is_connected(false),
24-
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
24+
_current_op(OP_INVALID), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
2525
{
2626
_stack = NULL;
2727
_pdp_type = DEFAULT_PDP_TYPE;
@@ -37,6 +37,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
3737
_new_context_set = false;
3838
_next = NULL;
3939
_cp_netif = NULL;
40+
_device = device;
4041
}
4142

4243
AT_CellularContext::~AT_CellularContext()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) , 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 "CellularContext.h"
19+
20+
using namespace mbed;
21+
22+
void CellularContext::cp_data_received()
23+
{
24+
_cp_netif->data_received();
25+
}
26+
27+
CellularDevice *CellularContext::get_device() const
28+
{
29+
return _device;
30+
}

UNITTESTS/stubs/CellularContext_stub.h renamed to UNITTESTS/target_h/myCellularContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020

2121
namespace mbed {
2222

23-
class CellularContext_stub : public CellularContext {
23+
class myCellularContext : public CellularContext {
2424
public:
2525
std::list<nsapi_error_t> return_values;
2626
nsapi_error_t return_value;
2727
ControlPlane_netif_stub *my_cp_netif;
2828

29-
CellularContext_stub()
29+
myCellularContext()
3030
{
3131
return_value = 0;
3232
my_cp_netif = NULL;
3333
}
34-
~CellularContext_stub()
34+
~myCellularContext()
3535
{
3636
if (my_cp_netif) {
3737
delete my_cp_netif;

features/cellular/framework/API/CellularContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ class CellularContext : public CellularInterface {
172172
*/
173173
static CellularContext *get_default_nonip_instance();
174174

175+
/** Get pointer to CellularDevice instance. May be null if not AT-layer.
176+
*
177+
* @return pointer to CellularDevice instance
178+
*/
179+
CellularDevice *get_device() const;
175180

176181
// Operations, can be sync/async. Also Connect() is this kind of operation, inherited from NetworkInterface above.
177182

@@ -327,6 +332,7 @@ class CellularContext : public CellularInterface {
327332
bool _active_high;
328333

329334
ControlPlane_netif *_cp_netif;
335+
CellularDevice *_device;
330336
};
331337

332338
/**

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ using namespace mbed;
4848

4949
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
5050
AT_CellularBase(at), _is_connected(false), _is_blocking(true),
51-
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
51+
_current_op(OP_INVALID), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
5252
{
5353
tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
5454
_stack = NULL;
@@ -67,6 +67,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
6767
_dcd_pin = NC;
6868
_active_high = false;
6969
_cp_netif = NULL;
70+
_device = device;
7071
}
7172

7273
AT_CellularContext::~AT_CellularContext()

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
126126
bool _is_blocking;
127127
ContextOperation _current_op;
128128
char _found_apn[MAX_APN_LENGTH];
129-
CellularDevice *_device;
130129
CellularNetwork *_nw;
131130
FileHandle *_fh;
132131
rtos::Semaphore _semaphore;

features/cellular/framework/device/CellularContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ void CellularContext::cp_data_received()
6161
_cp_netif->data_received();
6262
}
6363

64+
CellularDevice *CellularContext::get_device() const
65+
{
66+
return _device;
67+
}
68+
6469
} // namespace mbed

0 commit comments

Comments
 (0)