Skip to content

Commit aaf4edc

Browse files
author
Mirela Chirica
committed
Own SIM state retrieval for Quectel BC95
1 parent 79bd263 commit aaf4edc

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

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);
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_

0 commit comments

Comments
 (0)