Skip to content

Commit 4af3c38

Browse files
author
Cruz Monrreal
authored
Merge pull request #10210 from jarvte/cellulardevice_from_context
Cellular: CellularContext must provide access to CellularDevice
2 parents 8614382 + b0ee22c commit 4af3c38

File tree

13 files changed

+64
-8
lines changed

13 files changed

+64
-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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "AT_CellularContext.h"
1919
#include "AT_CellularNetwork.h"
2020
#include "AT_CellularStack.h"
21+
#include "AT_CellularDevice.h"
2122
#include "CellularLog.h"
2223
#include "CellularUtil.h"
2324
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
@@ -48,7 +49,7 @@ using namespace mbed;
4849

4950
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
5051
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)
52+
_current_op(OP_INVALID), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
5253
{
5354
tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
5455
_stack = NULL;
@@ -67,6 +68,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
6768
_dcd_pin = NC;
6869
_active_high = false;
6970
_cp_netif = NULL;
71+
_device = device;
7072
}
7173

7274
AT_CellularContext::~AT_CellularContext()
@@ -112,6 +114,11 @@ void AT_CellularContext::enable_hup(bool enable)
112114
}
113115
}
114116

117+
AT_CellularDevice *AT_CellularContext::get_device() const
118+
{
119+
return static_cast<AT_CellularDevice *>(CellularContext::get_device());
120+
}
121+
115122
nsapi_error_t AT_CellularContext::connect()
116123
{
117124
tr_info("CellularContext connect");

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const int MAX_APN_LENGTH = 63 + 1;
2525

2626
namespace mbed {
2727

28+
class AT_CellularDevice;
29+
2830
class AT_CellularContext : public CellularContext, public AT_CellularBase {
2931
public:
3032
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0, bool cp_req = false, bool nonip_req = false);
@@ -65,6 +67,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
6567

6668
virtual ControlPlane_netif *get_cp_netif();
6769

70+
AT_CellularDevice *get_device() const;
6871
protected:
6972
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr);
7073

@@ -126,7 +129,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
126129
bool _is_blocking;
127130
ContextOperation _current_op;
128131
char _found_apn[MAX_APN_LENGTH];
129-
CellularDevice *_device;
130132
CellularNetwork *_nw;
131133
FileHandle *_fh;
132134
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)