Skip to content

Commit 7b2ee2d

Browse files
authored
Merge pull request #6291 from mirelachirica/bc95_echotest_fixes
Cellular: BC95 echo test fixes
2 parents 447e96e + be95f47 commit 7b2ee2d

File tree

10 files changed

+155
-21
lines changed

10 files changed

+155
-21
lines changed

features/cellular/easy_cellular/EasyCellularConnection.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "CellularLog.h"
3030
#include "mbed_wait_api.h"
3131

32-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
32+
#if USE_APN_LOOKUP
3333
#include "APN_db.h"
34-
#endif //MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
34+
#endif //USE_APN_LOOKUP
3535

3636
namespace mbed {
3737

@@ -59,9 +59,9 @@ EasyCellularConnection::EasyCellularConnection(bool debug) :
5959
NSAPI_ERROR_OK)
6060
{
6161
tr_info("EasyCellularConnection()");
62-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
62+
#if USE_APN_LOOKUP
6363
_credentials_set = false;
64-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
64+
#endif // #if USE_APN_LOOKUP
6565
modem_debug_on(debug);
6666
}
6767

@@ -102,11 +102,11 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
102102
CellularNetwork * network = _cellularConnectionFSM.get_network();
103103
if (network) {
104104
_credentials_err = network->set_credentials(apn, uname, pwd);
105-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
105+
#if USE_APN_LOOKUP
106106
if (_credentials_err == NSAPI_ERROR_OK) {
107107
_credentials_set = true;
108108
}
109-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
109+
#endif // #if USE_APN_LOOKUP
110110
} else {
111111
tr_error("NO Network...");
112112
}
@@ -163,7 +163,7 @@ nsapi_error_t EasyCellularConnection::connect()
163163
if (err) {
164164
return err;
165165
}
166-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
166+
#if USE_APN_LOOKUP
167167
if (!_credentials_set) {
168168
_target_state = CellularConnectionFSM::STATE_SIM_PIN;
169169
err = _cellularConnectionFSM.continue_to_state(_target_state);
@@ -193,7 +193,7 @@ nsapi_error_t EasyCellularConnection::connect()
193193
return err;
194194
}
195195
}
196-
#endif // MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
196+
#endif // USE_APN_LOOKUP
197197

198198
_target_state = CellularConnectionFSM::STATE_CONNECTED;
199199
err = _cellularConnectionFSM.continue_to_state(_target_state);
@@ -212,9 +212,9 @@ nsapi_error_t EasyCellularConnection::disconnect()
212212
{
213213
_credentials_err = NSAPI_ERROR_OK;
214214
_is_connected = false;
215-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
215+
#if USE_APN_LOOKUP
216216
_credentials_set = false;
217-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
217+
#endif // #if USE_APN_LOOKUP
218218
if (!_cellularConnectionFSM.get_network()) {
219219
return NSAPI_ERROR_NO_CONNECTION;
220220
}

features/cellular/easy_cellular/EasyCellularConnection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "netsocket/CellularBase.h"
2626

27+
#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))
28+
2729
namespace mbed
2830
{
2931

@@ -145,9 +147,9 @@ class EasyCellularConnection: public CellularBase
145147

146148
bool _is_connected;
147149
bool _is_initialized;
148-
#if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
150+
#if USE_APN_LOOKUP
149151
bool _credentials_set;
150-
#endif // #if MBED_CONF_CELLULAR_USE_APN_LOOKUP || MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP
152+
#endif // #if USE_APN_LOOKUP
151153
CellularConnectionFSM::CellularState _target_state;
152154

153155
UARTSerial _cellularSerial;

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ nsapi_error_t AT_CellularNetwork::connect(const char *apn,
133133

134134
nsapi_error_t AT_CellularNetwork::delete_current_context()
135135
{
136+
tr_info("Delete context %d", _cid);
136137
_at.clear_error();
137138
_at.cmd_start("AT+CGDCONT=");
138139
_at.write_int(_cid);
@@ -236,12 +237,14 @@ nsapi_error_t AT_CellularNetwork::open_data_channel()
236237
int context_activation_state = _at.read_int();
237238
if (context_id == _cid && context_activation_state == 1) {
238239
is_context_active = true;
240+
tr_debug("PDP context %d is active.", _cid);
241+
break;
239242
}
240243
}
241244
_at.resp_stop();
242245

243246
if (!is_context_active) {
244-
tr_info("Activate PDP context");
247+
tr_info("Activate PDP context %d", _cid);
245248
_at.cmd_start("AT+CGACT=1,");
246249
_at.write_int(_cid);
247250
_at.cmd_stop();
@@ -401,13 +404,20 @@ bool AT_CellularNetwork::set_new_context(int cid)
401404
_ip_stack_type = tmp_stack;
402405
_cid = cid;
403406
_new_context_set = true;
407+
tr_info("New PDP context id %d was created", _cid);
404408
}
405409

406410
return success;
407411
}
408412

409413
bool AT_CellularNetwork::get_context()
410414
{
415+
if (_apn) {
416+
tr_debug("APN in use: %s", _apn);
417+
} else {
418+
tr_debug("NO APN");
419+
}
420+
411421
_at.cmd_start("AT+CGDCONT?");
412422
_at.cmd_stop();
413423
_at.resp_start("+CGDCONT:");
@@ -429,7 +439,7 @@ bool AT_CellularNetwork::get_context()
429439
if (pdp_type_len > 0) {
430440
apn_len = _at.read_string(apn, sizeof(apn) - 1);
431441
if (apn_len >= 0) {
432-
if (_apn && strcmp(apn, _apn) != 0 ) {
442+
if (_apn && (strcmp(apn, _apn) != 0) ) {
433443
continue;
434444
}
435445
nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context);

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

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

1818
#include "QUECTEL_BC95_CellularNetwork.h"
1919
#include "QUECTEL_BC95_CellularPower.h"
20+
#include "QUECTEL_BC95_CellularSIM.h"
2021

2122
#include "QUECTEL_BC95.h"
2223

@@ -41,15 +42,41 @@ QUECTEL_BC95::~QUECTEL_BC95()
4142
CellularNetwork *QUECTEL_BC95::open_network(FileHandle *fh)
4243
{
4344
if (!_network) {
44-
_network = new QUECTEL_BC95_CellularNetwork(*get_at_handler(fh));
45+
ATHandler *atHandler = get_at_handler(fh);
46+
if (atHandler) {
47+
_network = new QUECTEL_BC95_CellularNetwork(*atHandler);
48+
if (!_network) {
49+
release_at_handler(atHandler);
50+
}
51+
}
4552
}
4653
return _network;
4754
}
4855

4956
CellularPower *QUECTEL_BC95::open_power(FileHandle *fh)
5057
{
5158
if (!_power) {
52-
_power = new QUECTEL_BC95_CellularPower(*get_at_handler(fh));
59+
ATHandler *atHandler = get_at_handler(fh);
60+
if (atHandler) {
61+
_power = new QUECTEL_BC95_CellularPower(*atHandler);
62+
if (!_power) {
63+
release_at_handler(atHandler);
64+
}
65+
}
5366
}
5467
return _power;
5568
}
69+
70+
CellularSIM *QUECTEL_BC95::open_sim(FileHandle *fh)
71+
{
72+
if (!_sim) {
73+
ATHandler *atHandler = get_at_handler(fh);
74+
if (atHandler) {
75+
_sim = new QUECTEL_BC95_CellularSIM(*atHandler);
76+
if (!_sim) {
77+
release_at_handler(atHandler);
78+
}
79+
}
80+
}
81+
return _sim;
82+
}

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QUECTEL_BC95 : public AT_CellularDevice
3232
public: // CellularDevice
3333
virtual CellularNetwork *open_network(FileHandle *fh);
3434
virtual CellularPower *open_power(FileHandle *fh);
35+
virtual CellularSIM *open_sim(FileHandle *fh);
3536

3637
public: // NetworkInterface
3738
void handle_urc(FileHandle *fh);

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularPower.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
#ifndef TELIT_HE910_CELLULAR_POWER_H_
19-
#define TELIT_HE910_CELLULAR_POWER_H_
18+
#ifndef QUECTEL_BC95_CELLULAR_POWER_H_
19+
#define QUECTEL_BC95_CELLULAR_POWER_H_
2020

2121
#include "AT_CellularPower.h"
2222

@@ -36,4 +36,4 @@ class QUECTEL_BC95_CellularPower : public AT_CellularPower
3636

3737
} // namespace mbed
3838

39-
#endif // TELIT_HE910_CELLULAR_POWER_H_
39+
#endif // QUECTEL_BC95_CELLULAR_POWER_H_
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 "QUECTEL_BC95_CellularSIM.h"
19+
#include "CellularLog.h"
20+
21+
using namespace mbed;
22+
23+
QUECTEL_BC95_CellularSIM::QUECTEL_BC95_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
24+
{
25+
26+
}
27+
28+
QUECTEL_BC95_CellularSIM::~QUECTEL_BC95_CellularSIM()
29+
{
30+
31+
}
32+
33+
nsapi_error_t QUECTEL_BC95_CellularSIM::get_sim_state(SimState &state)
34+
{
35+
_at.lock();
36+
_at.flush();
37+
_at.cmd_start("AT+NCCID?");
38+
_at.cmd_stop();
39+
_at.resp_start("+NCCID:");
40+
if (_at.info_resp()) {
41+
state = SimStateReady;
42+
} else {
43+
tr_warn("SIM not readable.");
44+
state = SimStateUnknown; // SIM may not be ready yet
45+
}
46+
_at.resp_stop();
47+
return _at.unlock_return_error();
48+
}
49+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
#ifndef QUECTEL_BC95_CELLULAR_SIM_H_
19+
#define QUECTEL_BC95_CELLULAR_SIM_H_
20+
21+
#include "AT_CellularSIM.h"
22+
23+
namespace mbed {
24+
25+
class QUECTEL_BC95_CellularSIM : public AT_CellularSIM
26+
{
27+
public:
28+
QUECTEL_BC95_CellularSIM(ATHandler &atHandler);
29+
virtual ~QUECTEL_BC95_CellularSIM();
30+
31+
public: //from CellularSIM
32+
virtual nsapi_error_t get_sim_state(SimState &state);
33+
};
34+
35+
} // namespace mbed
36+
37+
#endif // QUECTEL_BC95_CELLULAR_SIM_H_

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
150150
_at.write_string(hexstr, false);
151151
_at.cmd_stop();
152152
_at.resp_start();
153-
socket->id = _at.read_int();
153+
// skip socket id
154+
_at.skip_param();
154155
sent_len = _at.read_int();
155156
_at.resp_stop();
156157

@@ -182,6 +183,7 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_recvfrom_impl(CellularS
182183
_at.read_string(hexstr, sizeof(hexstr));
183184
// remaining length
184185
_at.skip_param();
186+
_at.resp_stop();
185187

186188
if (!recv_len || (recv_len == -1) || (_at.get_last_error() != NSAPI_ERROR_OK)) {
187189
return NSAPI_ERROR_WOULD_BLOCK;

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ QUECTEL_BG96::~QUECTEL_BG96()
4040
CellularNetwork *QUECTEL_BG96::open_network(FileHandle *fh)
4141
{
4242
if (!_network) {
43-
_network = new QUECTEL_BG96_CellularNetwork(*get_at_handler(fh));
43+
ATHandler *atHandler = get_at_handler(fh);
44+
if (atHandler) {
45+
_network = new QUECTEL_BG96_CellularNetwork(*atHandler);
46+
if (!_network) {
47+
release_at_handler(atHandler);
48+
}
49+
}
4450
}
4551
return _network;
4652
}

0 commit comments

Comments
 (0)