Skip to content

Commit 007caa0

Browse files
author
Ari Parkkila
committed
Cellular: Update modem drivers with get_default and other new APIs
1 parent af0d2cf commit 007caa0

16 files changed

+134
-319
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ class my_AT_CTXIPV6 : public AT_CellularContext {
142142
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
143143
AT_CellularContext(at, device, apn), _st(at) {}
144144
virtual ~my_AT_CTXIPV6() {}
145-
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type)
146-
{
147-
return true;
148-
}
149145
virtual NetworkStack *get_stack()
150146
{
151147
return &_st;

features/cellular/TESTS/socket/udp/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#include "CellularUtil.h" // for CELLULAR_ helper macros
2323
#include "CellularTargets.h"
2424

25-
#ifndef CELLULAR_DEVICE
26-
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
27-
#endif
28-
2925
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
3026
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
3127
#endif
Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
#include <M26/QUECTEL_M26_CellularInformation.h>
23
* Copyright (c) 2018, Arm Limited and affiliates.
34
* SPDX-License-Identifier: Apache-2.0
45
*
@@ -15,53 +16,89 @@
1516
* limitations under the License.
1617
*/
1718

18-
#include "QUECTEL_M26_CellularNetwork.h"
19-
#include "QUECTEL_M26_CellularPower.h"
20-
#include "QUECTEL_M26_CellularSIM.h"
19+
#include "AT_CellularNetwork.h"
2120
#include "QUECTEL_M26_CellularContext.h"
2221
#include "QUECTEL_M26.h"
2322

24-
using namespace events;
25-
using namespace mbed;
26-
27-
#define CONNECT_DELIM "\r\n"
28-
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
29-
#define CONNECT_TIMEOUT 8000
23+
#include "CellularLog.h"
3024

31-
#define MAX_STARTUP_TRIALS 5
32-
#define MAX_RESET_TRIALS 5
25+
using namespace mbed;
3326

34-
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
35-
AT_CellularBase::AT_CGSN_WITH_TYPE,
36-
AT_CellularBase::AT_CGAUTH,
37-
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
27+
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
28+
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
29+
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
30+
AT_CellularNetwork::RegistrationModeDisable,// C_REG
31+
0, // AT_CGSN_WITH_TYPE
32+
1, // AT_CGDATA
33+
0, // AT_CGAUTH
34+
1, // PROPERTY_IPV4_STACK
35+
0, // PROPERTY_IPV6_STACK
36+
0, // PROPERTY_IPV4V6_STACK
3837
};
3938

4039
QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
4140
{
42-
AT_CellularBase::set_unsupported_features(unsupported_features);
41+
AT_CellularBase::set_cellular_properties(cellular_properties);
4342
}
4443

45-
QUECTEL_M26::~QUECTEL_M26()
44+
nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state)
4645
{
47-
}
46+
char buf[13];
4847

49-
AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at)
50-
{
51-
return new QUECTEL_M26_CellularNetwork(at);
48+
_at->lock();
49+
_at->cmd_start("AT+CPIN?");
50+
_at->cmd_stop();
51+
_at->resp_start("+CPIN:");
52+
if (_at->info_resp()) {
53+
_at->read_string(buf, 13);
54+
tr_debug("CPIN: %s", buf);
55+
56+
if (memcmp(buf, "READY", 5) == 0) {
57+
state = SimStateReady;
58+
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
59+
state = SimStatePinNeeded;
60+
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
61+
state = SimStatePukNeeded;
62+
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
63+
state = SimStatePinNeeded;
64+
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
65+
state = SimStatePukNeeded;
66+
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
67+
state = SimStatePinNeeded;
68+
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
69+
state = SimStatePukNeeded;
70+
} else {
71+
state = SimStateUnknown; // SIM may not be ready yet
72+
}
73+
74+
}
75+
_at->resp_stop();
76+
return _at->unlock_return_error();
5277
}
5378

54-
AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at)
79+
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
5580
{
56-
return new QUECTEL_M26_CellularPower(at);
81+
return new QUECTEL_M26_CellularContext(at, this, apn, cp_req, nonip_req);
5782
}
5883

59-
AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at)
84+
nsapi_error_t QUECTEL_M26::init()
6085
{
61-
return new QUECTEL_M26_CellularSIM(at);
86+
_at->lock();
87+
_at->cmd_start("AT");
88+
_at->cmd_stop_read_resp();
89+
_at->cmd_start("AT+CMEE="); // verbose responses
90+
_at->write_int(1);
91+
_at->cmd_stop_read_resp();
92+
return _at->unlock_return_error();
6293
}
6394

64-
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn)
95+
nsapi_error_t QUECTEL_M26::shutdown()
6596
{
66-
return new QUECTEL_M26_CellularContext(at, this, apn);
97+
_at->lock();
98+
_at->cmd_start("AT+QPOWD=0");
99+
_at->cmd_stop();
100+
_at->resp_start();
101+
_at->resp_stop();
102+
103+
return _at->unlock_return_error();;
67104
}

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@
1818
#ifndef QUECTEL_M26_H_
1919
#define QUECTEL_M26_H_
2020

21+
#ifdef TARGET_FF_ARDUINO
22+
#ifndef MBED_CONF_QUECTEL_M26_TX
23+
#define MBED_CONF_QUECTEL_M26_TX D1
24+
#endif
25+
#ifndef MBED_CONF_QUECTEL_M26_RX
26+
#define MBED_CONF_QUECTEL_M26_RX D0
27+
#endif
28+
#endif /* TARGET_FF_ARDUINO */
29+
2130
#include "AT_CellularDevice.h"
2231

2332
namespace mbed {
2433

2534
class QUECTEL_M26 : public AT_CellularDevice {
2635
public:
2736
QUECTEL_M26(FileHandle *fh);
28-
virtual ~QUECTEL_M26();
2937

3038
protected: // AT_CellularDevice
31-
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
32-
virtual AT_CellularPower *open_power_impl(ATHandler &at);
33-
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
34-
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
39+
virtual nsapi_error_t get_sim_state(SimState &state);
40+
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
41+
virtual nsapi_error_t init();
42+
virtual nsapi_error_t shutdown();
3543

3644
public: // NetworkInterface
3745
void handle_urc(FileHandle *fh);

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,16 @@
1919

2020
namespace mbed {
2121

22-
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
23-
AT_CellularContext(at, device, apn)
22+
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
23+
AT_CellularContext(at, device, apn, cp_req, nonip_req)
2424
{
2525
}
2626

27-
QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext()
28-
{
29-
}
30-
31-
bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
32-
{
33-
return stack_type == IPV4_STACK ? true : false;
34-
}
35-
3627
#if !NSAPI_PPP_AVAILABLE
3728
NetworkStack *QUECTEL_M26_CellularContext::get_stack()
3829
{
3930
if (!_stack) {
40-
_stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type);
31+
_stack = new QUECTEL_M26_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type);
4132
}
4233
return _stack;
4334
}

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularContext.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ namespace mbed {
2323

2424
class QUECTEL_M26_CellularContext: public AT_CellularContext {
2525
public:
26-
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
27-
virtual ~QUECTEL_M26_CellularContext();
26+
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
2827

2928
protected:
30-
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
3129
#if !NSAPI_PPP_AVAILABLE
3230
virtual NetworkStack *get_stack();
3331
#endif // #if !NSAPI_PPP_AVAILABLE

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.h renamed to features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.cpp

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

18-
#ifndef QUECTEL_M26_CELLULAR_NETWORK_H_
19-
#define QUECTEL_M26_CELLULAR_NETWORK_H_
18+
#include "QUECTEL_M26_CellularInformation.h"
2019

21-
#include "AT_CellularNetwork.h"
20+
using namespace mbed;
2221

23-
namespace mbed {
22+
QUECTEL_M26_CellularInformation::QUECTEL_M26_CellularInformation(ATHandler &atHandler) : AT_CellularInformation(atHandler)
23+
{
2424

25-
class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork {
26-
public:
27-
QUECTEL_M26_CellularNetwork(ATHandler &atHandler);
28-
virtual ~QUECTEL_M26_CellularNetwork();
25+
}
2926

30-
protected:
31-
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
32-
virtual RegistrationMode has_registration(RegistrationType reg_type);
33-
};
34-
} // namespace mbed
35-
#endif // QUECTEL_M26_CELLULAR_NETWORK_H_
27+
// According to M26_AT_Commands_Manual_V1.9
28+
nsapi_error_t QUECTEL_M26_CellularInformation::get_iccid(char *buf, size_t buf_size)
29+
{
30+
_at.lock();
31+
_at.cmd_start("AT+CCID");
32+
_at.cmd_stop();
33+
_at.resp_start("+CCID:");
34+
_at.read_string(buf, buf_size);
35+
_at.resp_stop();
36+
return _at.unlock_return_error();
37+
}

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularPower.h renamed to features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularInformation.h

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

18-
#ifndef QUECTEL_M26_CELLULAR_POWER_H_
19-
#define QUECTEL_M26_CELLULAR_POWER_H_
18+
#ifndef QUECTEL_M26_CELLULAR_INFORMATION_H_
19+
#define QUECTEL_M26_CELLULAR_INFORMATION_H_
2020

21-
#include "AT_CellularPower.h"
21+
#include "AT_CellularInformation.h"
2222

2323
namespace mbed {
2424

25-
class QUECTEL_M26_CellularPower : public AT_CellularPower {
25+
class QUECTEL_M26_CellularInformation : public AT_CellularInformation {
2626
public:
27-
QUECTEL_M26_CellularPower(ATHandler &atHandler);
28-
virtual ~QUECTEL_M26_CellularPower();
27+
QUECTEL_M26_CellularInformation(ATHandler &atHandler);
2928

30-
public: //from CellularPower
31-
virtual nsapi_error_t set_at_mode();
32-
33-
virtual nsapi_error_t on();
34-
35-
virtual nsapi_error_t off();
29+
public: //from CellularInformation
30+
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
3631
};
3732

3833
} // namespace mbed
3934

40-
#endif // QUECTEL_M26_CELLULAR_POWER_H_
35+
#endif // QUECTEL_M26_CELLULAR_INFORMATION_H_

features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26_CellularNetwork.cpp

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)