Skip to content

Cellular: CellularContext must provide access to CellularDevice #10210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ set(unittest-test-sources
stubs/us_ticker_stub.cpp
stubs/UARTSerial_stub.cpp
stubs/SerialBase_stub.cpp
stubs/CellularContext_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(unittest-test-sources
stubs/UARTSerial_stub.cpp
stubs/SerialBase_stub.cpp
stubs/CellularStateMachine_stub.cpp
stubs/CellularContext_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(unittest-test-sources
stubs/Semaphore_stub.cpp
stubs/NetworkInterface_stub.cpp
stubs/NetworkInterfaceDefaults_stub.cpp
stubs/CellularContext_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(unittest-test-sources
stubs/Mutex_stub.cpp
stubs/EventQueue_stub.cpp
stubs/equeue_stub.c
stubs/CellularContext_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "gtest/gtest.h"
#include "features/netsocket/cellular/CellularNonIPSocket.h"
#include "CellularContext_stub.h"
#include "myCellularContext.h"

using namespace mbed;

Expand All @@ -34,7 +34,7 @@ class TestCellularNonIPSocket : public testing::Test {
protected:
CellularNonIPSocket *socket;
ControlPlane_netif_stub *cp_netif;
CellularContext_stub cellular_context;
myCellularContext cellular_context;
nsapi_size_t dataSize;
char dataBuf[10];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ set(unittest-test-sources
stubs/NetworkStack_stub.cpp
stubs/EventFlags_stub.cpp
stubs/Mutex_stub.cpp
stubs/CellularContext_stub.cpp
)
3 changes: 2 additions & 1 deletion UNITTESTS/stubs/AT_CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace mbed;

AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
AT_CellularBase(at), _is_blocking(true), _is_connected(false),
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
_current_op(OP_INVALID), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
{
_stack = NULL;
_pdp_type = DEFAULT_PDP_TYPE;
Expand All @@ -37,6 +37,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
_new_context_set = false;
_next = NULL;
_cp_netif = NULL;
_device = device;
}

AT_CellularContext::~AT_CellularContext()
Expand Down
30 changes: 30 additions & 0 deletions UNITTESTS/stubs/CellularContext_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "CellularContext.h"

using namespace mbed;

void CellularContext::cp_data_received()
{
_cp_netif->data_received();
}

CellularDevice *CellularContext::get_device() const
{
return _device;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

namespace mbed {

class CellularContext_stub : public CellularContext {
class myCellularContext : public CellularContext {
public:
std::list<nsapi_error_t> return_values;
nsapi_error_t return_value;
ControlPlane_netif_stub *my_cp_netif;

CellularContext_stub()
myCellularContext()
{
return_value = 0;
my_cp_netif = NULL;
}
~CellularContext_stub()
~myCellularContext()
{
if (my_cp_netif) {
delete my_cp_netif;
Expand Down
6 changes: 6 additions & 0 deletions features/cellular/framework/API/CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class CellularContext : public CellularInterface {
*/
static CellularContext *get_default_nonip_instance();

/** Get pointer to CellularDevice instance. May be null if not AT-layer.
*
* @return pointer to CellularDevice instance
*/
CellularDevice *get_device() const;

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

Expand Down Expand Up @@ -327,6 +332,7 @@ class CellularContext : public CellularInterface {
bool _active_high;

ControlPlane_netif *_cp_netif;
CellularDevice *_device;
};

/**
Expand Down
9 changes: 8 additions & 1 deletion features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "AT_CellularContext.h"
#include "AT_CellularNetwork.h"
#include "AT_CellularStack.h"
#include "AT_CellularDevice.h"
#include "CellularLog.h"
#include "CellularUtil.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
Expand Down Expand Up @@ -48,7 +49,7 @@ using namespace mbed;

AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
AT_CellularBase(at), _is_connected(false), _is_blocking(true),
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
_current_op(OP_INVALID), _nw(0), _fh(0), _cp_req(cp_req), _nonip_req(nonip_req), _cp_in_use(false)
{
tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
_stack = NULL;
Expand All @@ -67,6 +68,7 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
_dcd_pin = NC;
_active_high = false;
_cp_netif = NULL;
_device = device;
}

AT_CellularContext::~AT_CellularContext()
Expand Down Expand Up @@ -112,6 +114,11 @@ void AT_CellularContext::enable_hup(bool enable)
}
}

AT_CellularDevice *AT_CellularContext::get_device() const
{
return static_cast<AT_CellularDevice *>(CellularContext::get_device());
}

nsapi_error_t AT_CellularContext::connect()
{
tr_info("CellularContext connect");
Expand Down
4 changes: 3 additions & 1 deletion features/cellular/framework/AT/AT_CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const int MAX_APN_LENGTH = 63 + 1;

namespace mbed {

class AT_CellularDevice;

class AT_CellularContext : public CellularContext, public AT_CellularBase {
public:
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0, bool cp_req = false, bool nonip_req = false);
Expand Down Expand Up @@ -65,6 +67,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {

virtual ControlPlane_netif *get_cp_netif();

AT_CellularDevice *get_device() const;
protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr);

Expand Down Expand Up @@ -126,7 +129,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
bool _is_blocking;
ContextOperation _current_op;
char _found_apn[MAX_APN_LENGTH];
CellularDevice *_device;
CellularNetwork *_nw;
FileHandle *_fh;
rtos::Semaphore _semaphore;
Expand Down
5 changes: 5 additions & 0 deletions features/cellular/framework/device/CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ void CellularContext::cp_data_received()
_cp_netif->data_received();
}

CellularDevice *CellularContext::get_device() const
{
return _device;
}

} // namespace mbed