Skip to content

Cellular: BC95 echo test fixes #6291

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 5 commits into from
Mar 20, 2018
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
20 changes: 10 additions & 10 deletions features/cellular/easy_cellular/EasyCellularConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include "CellularLog.h"
#include "mbed_wait_api.h"

#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
#include "APN_db.h"
#endif //MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif //USE_APN_LOOKUP

namespace mbed {

Expand Down Expand Up @@ -59,9 +59,9 @@ EasyCellularConnection::EasyCellularConnection(bool debug) :
NSAPI_ERROR_OK)
{
tr_info("EasyCellularConnection()");
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
_credentials_set = false;
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif // #if USE_APN_LOOKUP
modem_debug_on(debug);
}

Expand Down Expand Up @@ -102,11 +102,11 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
CellularNetwork * network = _cellularConnectionFSM.get_network();
if (network) {
_credentials_err = network->set_credentials(apn, uname, pwd);
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
if (_credentials_err == NSAPI_ERROR_OK) {
_credentials_set = true;
}
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif // #if USE_APN_LOOKUP
} else {
tr_error("NO Network...");
}
Expand Down Expand Up @@ -163,7 +163,7 @@ nsapi_error_t EasyCellularConnection::connect()
if (err) {
return err;
}
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
if (!_credentials_set) {
_target_state = CellularConnectionFSM::STATE_SIM_PIN;
err = _cellularConnectionFSM.continue_to_state(_target_state);
Expand Down Expand Up @@ -193,7 +193,7 @@ nsapi_error_t EasyCellularConnection::connect()
return err;
}
}
#endif // MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif // USE_APN_LOOKUP

_target_state = CellularConnectionFSM::STATE_CONNECTED;
err = _cellularConnectionFSM.continue_to_state(_target_state);
Expand All @@ -212,9 +212,9 @@ nsapi_error_t EasyCellularConnection::disconnect()
{
_credentials_err = NSAPI_ERROR_OK;
_is_connected = false;
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
_credentials_set = false;
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif // #if USE_APN_LOOKUP
if (!_cellularConnectionFSM.get_network()) {
return NSAPI_ERROR_NO_CONNECTION;
}
Expand Down
6 changes: 4 additions & 2 deletions features/cellular/easy_cellular/EasyCellularConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "netsocket/CellularBase.h"

#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))

namespace mbed
{

Expand Down Expand Up @@ -145,9 +147,9 @@ class EasyCellularConnection: public CellularBase

bool _is_connected;
bool _is_initialized;
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#if USE_APN_LOOKUP
bool _credentials_set;
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
#endif // #if USE_APN_LOOKUP
CellularConnectionFSM::CellularState _target_state;

UARTSerial _cellularSerial;
Expand Down
14 changes: 12 additions & 2 deletions features/cellular/framework/AT/AT_CellularNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ nsapi_error_t AT_CellularNetwork::connect(const char *apn,

nsapi_error_t AT_CellularNetwork::delete_current_context()
{
tr_info("Delete context %d", _cid);
_at.clear_error();
_at.cmd_start("AT+CGDCONT=");
_at.write_int(_cid);
Expand Down Expand Up @@ -236,12 +237,14 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
int context_activation_state = _at.read_int();
if (context_id == _cid && context_activation_state == 1) {
is_context_active = true;
tr_debug("PDP context %d is active.", _cid);
break;
}
}
_at.resp_stop();

if (!is_context_active) {
tr_info("Activate PDP context");
tr_info("Activate PDP context %d", _cid);
_at.cmd_start("AT+CGACT=1,");
_at.write_int(_cid);
_at.cmd_stop();
Expand Down Expand Up @@ -401,13 +404,20 @@ bool AT_CellularNetwork::set_new_context(int cid)
_ip_stack_type = tmp_stack;
_cid = cid;
_new_context_set = true;
tr_info("New PDP context id %d was created", _cid);
}

return success;
}

bool AT_CellularNetwork::get_context()
{
if (_apn) {
tr_debug("APN in use: %s", _apn);
} else {
tr_debug("NO APN");
}

_at.cmd_start("AT+CGDCONT?");
_at.cmd_stop();
_at.resp_start("+CGDCONT:");
Expand All @@ -429,7 +439,7 @@ bool AT_CellularNetwork::get_context()
if (pdp_type_len > 0) {
apn_len = _at.read_string(apn, sizeof(apn) - 1);
if (apn_len >= 0) {
if (_apn && strcmp(apn, _apn) != 0 ) {
if (_apn && (strcmp(apn, _apn) != 0) ) {
continue;
}
nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context);
Expand Down
31 changes: 29 additions & 2 deletions features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "QUECTEL_BC95_CellularNetwork.h"
#include "QUECTEL_BC95_CellularPower.h"
#include "QUECTEL_BC95_CellularSIM.h"

#include "QUECTEL_BC95.h"

Expand All @@ -41,15 +42,41 @@ QUECTEL_BC95::~QUECTEL_BC95()
CellularNetwork *QUECTEL_BC95::open_network(FileHandle *fh)
{
if (!_network) {
_network = new QUECTEL_BC95_CellularNetwork(*get_at_handler(fh));
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_network = new QUECTEL_BC95_CellularNetwork(*atHandler);
if (!_network) {
release_at_handler(atHandler);
}
}
}
return _network;
}

CellularPower *QUECTEL_BC95::open_power(FileHandle *fh)
{
if (!_power) {
_power = new QUECTEL_BC95_CellularPower(*get_at_handler(fh));
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_power = new QUECTEL_BC95_CellularPower(*atHandler);
if (!_power) {
release_at_handler(atHandler);
}
}
}
return _power;
}

CellularSIM *QUECTEL_BC95::open_sim(FileHandle *fh)
{
if (!_sim) {
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_sim = new QUECTEL_BC95_CellularSIM(*atHandler);
if (!_sim) {
release_at_handler(atHandler);
}
}
}
return _sim;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class QUECTEL_BC95 : public AT_CellularDevice
public: // CellularDevice
virtual CellularNetwork *open_network(FileHandle *fh);
virtual CellularPower *open_power(FileHandle *fh);
virtual CellularSIM *open_sim(FileHandle *fh);

public: // NetworkInterface
void handle_urc(FileHandle *fh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* limitations under the License.
*/

#ifndef TELIT_HE910_CELLULAR_POWER_H_
#define TELIT_HE910_CELLULAR_POWER_H_
#ifndef QUECTEL_BC95_CELLULAR_POWER_H_
#define QUECTEL_BC95_CELLULAR_POWER_H_

#include "AT_CellularPower.h"

Expand All @@ -36,4 +36,4 @@ class QUECTEL_BC95_CellularPower : public AT_CellularPower

} // namespace mbed

#endif // TELIT_HE910_CELLULAR_POWER_H_
#endif // QUECTEL_BC95_CELLULAR_POWER_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, 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 "QUECTEL_BC95_CellularSIM.h"
#include "CellularLog.h"

using namespace mbed;

QUECTEL_BC95_CellularSIM::QUECTEL_BC95_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason the constructor and destructor are empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "empty" constructor is needed for passing atHandler to base AT_CellularSIM.
But empty destructor is not needed.


}

QUECTEL_BC95_CellularSIM::~QUECTEL_BC95_CellularSIM()
{

}

nsapi_error_t QUECTEL_BC95_CellularSIM::get_sim_state(SimState &state)
{
_at.lock();
_at.flush();
_at.cmd_start("AT+NCCID?");
_at.cmd_stop();
_at.resp_start("+NCCID:");
if (_at.info_resp()) {
state = SimStateReady;
} else {
tr_warn("SIM not readable.");
state = SimStateUnknown; // SIM may not be ready yet
}
_at.resp_stop();
return _at.unlock_return_error();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2017, 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.
*/

#ifndef QUECTEL_BC95_CELLULAR_SIM_H_
#define QUECTEL_BC95_CELLULAR_SIM_H_

#include "AT_CellularSIM.h"

namespace mbed {

class QUECTEL_BC95_CellularSIM : public AT_CellularSIM
{
public:
QUECTEL_BC95_CellularSIM(ATHandler &atHandler);
virtual ~QUECTEL_BC95_CellularSIM();

public: //from CellularSIM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funky. Is there a specific reason why public: is declared twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. It is copied from other modules where it is used for specifying in comments the different interfaces the class is implementing, but of course comment alone would be enough.

virtual nsapi_error_t get_sim_state(SimState &state);
};

} // namespace mbed

#endif // QUECTEL_BC95_CELLULAR_SIM_H_
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
_at.write_string(hexstr, false);
_at.cmd_stop();
_at.resp_start();
socket->id = _at.read_int();
// skip socket id
_at.skip_param();
sent_len = _at.read_int();
_at.resp_stop();

Expand Down Expand Up @@ -182,6 +183,7 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_recvfrom_impl(CellularS
_at.read_string(hexstr, sizeof(hexstr));
// remaining length
_at.skip_param();
_at.resp_stop();

if (!recv_len || (recv_len == -1) || (_at.get_last_error() != NSAPI_ERROR_OK)) {
return NSAPI_ERROR_WOULD_BLOCK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ QUECTEL_BG96::~QUECTEL_BG96()
CellularNetwork *QUECTEL_BG96::open_network(FileHandle *fh)
{
if (!_network) {
_network = new QUECTEL_BG96_CellularNetwork(*get_at_handler(fh));
ATHandler *atHandler = get_at_handler(fh);
if (atHandler) {
_network = new QUECTEL_BG96_CellularNetwork(*atHandler);
if (!_network) {
release_at_handler(atHandler);
}
}
}
return _network;
}