Cellular: Update modem drivers with get_default and other new APIs

pull/9472/head
Ari Parkkila 2019-01-22 02:22:21 -08:00
parent af0d2cf61d
commit 007caa0235
16 changed files with 134 additions and 319 deletions

View File

@ -142,10 +142,6 @@ public:
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn), _st(at) {}
virtual ~my_AT_CTXIPV6() {}
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type)
{
return true;
}
virtual NetworkStack *get_stack()
{
return &_st;

View File

@ -22,10 +22,6 @@
#include "CellularUtil.h" // for CELLULAR_ helper macros
#include "CellularTargets.h"
#ifndef CELLULAR_DEVICE
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
#endif
#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
#endif

View File

@ -1,4 +1,5 @@
/*
#include <M26/QUECTEL_M26_CellularInformation.h>
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
@ -15,53 +16,89 @@
* limitations under the License.
*/
#include "QUECTEL_M26_CellularNetwork.h"
#include "QUECTEL_M26_CellularPower.h"
#include "QUECTEL_M26_CellularSIM.h"
#include "AT_CellularNetwork.h"
#include "QUECTEL_M26_CellularContext.h"
#include "QUECTEL_M26.h"
using namespace events;
#include "CellularLog.h"
using namespace mbed;
#define CONNECT_DELIM "\r\n"
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
#define CONNECT_TIMEOUT 8000
#define MAX_STARTUP_TRIALS 5
#define MAX_RESET_TRIALS 5
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::AT_CGAUTH,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
AT_CellularNetwork::RegistrationModeDisable,// C_EREG
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
AT_CellularNetwork::RegistrationModeDisable,// C_REG
0, // AT_CGSN_WITH_TYPE
1, // AT_CGDATA
0, // AT_CGAUTH
1, // PROPERTY_IPV4_STACK
0, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
};
QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
AT_CellularBase::set_cellular_properties(cellular_properties);
}
QUECTEL_M26::~QUECTEL_M26()
nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state)
{
char buf[13];
_at->lock();
_at->cmd_start("AT+CPIN?");
_at->cmd_stop();
_at->resp_start("+CPIN:");
if (_at->info_resp()) {
_at->read_string(buf, 13);
tr_debug("CPIN: %s", buf);
if (memcmp(buf, "READY", 5) == 0) {
state = SimStateReady;
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
state = SimStatePukNeeded;
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
state = SimStatePukNeeded;
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
state = SimStatePukNeeded;
} else {
state = SimStateUnknown; // SIM may not be ready yet
}
}
_at->resp_stop();
return _at->unlock_return_error();
}
AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at)
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
{
return new QUECTEL_M26_CellularNetwork(at);
return new QUECTEL_M26_CellularContext(at, this, apn, cp_req, nonip_req);
}
AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at)
nsapi_error_t QUECTEL_M26::init()
{
return new QUECTEL_M26_CellularPower(at);
_at->lock();
_at->cmd_start("AT");
_at->cmd_stop_read_resp();
_at->cmd_start("AT+CMEE="); // verbose responses
_at->write_int(1);
_at->cmd_stop_read_resp();
return _at->unlock_return_error();
}
AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at)
nsapi_error_t QUECTEL_M26::shutdown()
{
return new QUECTEL_M26_CellularSIM(at);
}
_at->lock();
_at->cmd_start("AT+QPOWD=0");
_at->cmd_stop();
_at->resp_start();
_at->resp_stop();
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn)
{
return new QUECTEL_M26_CellularContext(at, this, apn);
return _at->unlock_return_error();;
}

View File

@ -18,6 +18,15 @@
#ifndef QUECTEL_M26_H_
#define QUECTEL_M26_H_
#ifdef TARGET_FF_ARDUINO
#ifndef MBED_CONF_QUECTEL_M26_TX
#define MBED_CONF_QUECTEL_M26_TX D1
#endif
#ifndef MBED_CONF_QUECTEL_M26_RX
#define MBED_CONF_QUECTEL_M26_RX D0
#endif
#endif /* TARGET_FF_ARDUINO */
#include "AT_CellularDevice.h"
namespace mbed {
@ -25,13 +34,12 @@ namespace mbed {
class QUECTEL_M26 : public AT_CellularDevice {
public:
QUECTEL_M26(FileHandle *fh);
virtual ~QUECTEL_M26();
protected: // AT_CellularDevice
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
virtual nsapi_error_t get_sim_state(SimState &state);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
virtual nsapi_error_t init();
virtual nsapi_error_t shutdown();
public: // NetworkInterface
void handle_urc(FileHandle *fh);

View File

@ -19,25 +19,16 @@
namespace mbed {
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
AT_CellularContext(at, device, apn)
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
AT_CellularContext(at, device, apn, cp_req, nonip_req)
{
}
QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext()
{
}
bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
{
return stack_type == IPV4_STACK ? true : false;
}
#if !NSAPI_PPP_AVAILABLE
NetworkStack *QUECTEL_M26_CellularContext::get_stack()
{
if (!_stack) {
_stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type);
_stack = new QUECTEL_M26_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type);
}
return _stack;
}

View File

@ -23,11 +23,9 @@ namespace mbed {
class QUECTEL_M26_CellularContext: public AT_CellularContext {
public:
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
virtual ~QUECTEL_M26_CellularContext();
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false);
protected:
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
#if !NSAPI_PPP_AVAILABLE
virtual NetworkStack *get_stack();
#endif // #if !NSAPI_PPP_AVAILABLE

View File

@ -15,21 +15,23 @@
* limitations under the License.
*/
#ifndef QUECTEL_M26_CELLULAR_NETWORK_H_
#define QUECTEL_M26_CELLULAR_NETWORK_H_
#include "QUECTEL_M26_CellularInformation.h"
#include "AT_CellularNetwork.h"
using namespace mbed;
namespace mbed {
QUECTEL_M26_CellularInformation::QUECTEL_M26_CellularInformation(ATHandler &atHandler) : AT_CellularInformation(atHandler)
{
class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork {
public:
QUECTEL_M26_CellularNetwork(ATHandler &atHandler);
virtual ~QUECTEL_M26_CellularNetwork();
}
protected:
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
virtual RegistrationMode has_registration(RegistrationType reg_type);
};
} // namespace mbed
#endif // QUECTEL_M26_CELLULAR_NETWORK_H_
// According to M26_AT_Commands_Manual_V1.9
nsapi_error_t QUECTEL_M26_CellularInformation::get_iccid(char *buf, size_t buf_size)
{
_at.lock();
_at.cmd_start("AT+CCID");
_at.cmd_stop();
_at.resp_start("+CCID:");
_at.read_string(buf, buf_size);
_at.resp_stop();
return _at.unlock_return_error();
}

View File

@ -15,26 +15,21 @@
* limitations under the License.
*/
#ifndef QUECTEL_M26_CELLULAR_POWER_H_
#define QUECTEL_M26_CELLULAR_POWER_H_
#ifndef QUECTEL_M26_CELLULAR_INFORMATION_H_
#define QUECTEL_M26_CELLULAR_INFORMATION_H_
#include "AT_CellularPower.h"
#include "AT_CellularInformation.h"
namespace mbed {
class QUECTEL_M26_CellularPower : public AT_CellularPower {
class QUECTEL_M26_CellularInformation : public AT_CellularInformation {
public:
QUECTEL_M26_CellularPower(ATHandler &atHandler);
virtual ~QUECTEL_M26_CellularPower();
QUECTEL_M26_CellularInformation(ATHandler &atHandler);
public: //from CellularPower
virtual nsapi_error_t set_at_mode();
virtual nsapi_error_t on();
virtual nsapi_error_t off();
public: //from CellularInformation
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
};
} // namespace mbed
#endif // QUECTEL_M26_CELLULAR_POWER_H_
#endif // QUECTEL_M26_CELLULAR_INFORMATION_H_

View File

@ -1,45 +0,0 @@
/*
* Copyright (c) 2018, 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_M26_CellularNetwork.h"
using namespace mbed;
QUECTEL_M26_CellularNetwork::QUECTEL_M26_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
{
_op_act = RAT_EGPRS;
}
QUECTEL_M26_CellularNetwork::~QUECTEL_M26_CellularNetwork()
{
}
AT_CellularNetwork::RegistrationMode QUECTEL_M26_CellularNetwork::has_registration(RegistrationType reg_type)
{
return (reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable;
}
nsapi_error_t QUECTEL_M26_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
{
if (opRat != RAT_EGPRS) {
// only GPRS support in the driver.
_op_act = RAT_EGPRS;
return NSAPI_ERROR_UNSUPPORTED;
}
return NSAPI_ERROR_OK;
}

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2018, 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_M26_CellularPower.h"
using namespace mbed;
QUECTEL_M26_CellularPower::QUECTEL_M26_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{
}
QUECTEL_M26_CellularPower::~QUECTEL_M26_CellularPower()
{
}
nsapi_error_t QUECTEL_M26_CellularPower::set_at_mode()
{
_at.lock();
_at.cmd_start("AT");
_at.cmd_stop_read_resp();
_at.cmd_start("AT+CMEE="); // verbose responses
_at.write_int(1);
_at.cmd_stop_read_resp();
return _at.unlock_return_error();
}
nsapi_error_t QUECTEL_M26_CellularPower::on()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t QUECTEL_M26_CellularPower::off()
{
_at.lock();
_at.cmd_start("AT+QPOWD=0");
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
return _at.unlock_return_error();;
}

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2018, 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_M26_CellularSIM.h"
#include "CellularLog.h"
using namespace mbed;
QUECTEL_M26_CellularSIM::QUECTEL_M26_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
{
}
QUECTEL_M26_CellularSIM::~QUECTEL_M26_CellularSIM()
{
}
nsapi_error_t QUECTEL_M26_CellularSIM::get_sim_state(SimState &state)
{
char buf[13];
_at.lock();
_at.cmd_start("AT+CPIN?");
_at.cmd_stop();
_at.resp_start("+CPIN:");
if (_at.info_resp()) {
_at.read_string(buf, 13);
tr_debug("CPIN: %s", buf);
if (memcmp(buf, "READY", 5) == 0) {
state = SimStateReady;
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
state = SimStatePukNeeded;
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
state = SimStatePukNeeded;
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
state = SimStatePinNeeded;
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
state = SimStatePukNeeded;
} else {
state = SimStateUnknown; // SIM may not be ready yet
}
}
_at.resp_stop();
return _at.unlock_return_error();
}
// According to M26_AT_Commands_Manual_V1.9
nsapi_error_t QUECTEL_M26_CellularSIM::get_iccid(char *buf, size_t buf_size)
{
_at.lock();
_at.cmd_start("AT+CCID");
_at.cmd_stop();
_at.resp_start("+CCID:");
_at.read_string(buf, buf_size);
_at.resp_stop();
return _at.unlock_return_error();
}
nsapi_error_t QUECTEL_M26_CellularSIM::change_pin(const char *sim_pin, const char *new_pin)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t QUECTEL_M26_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin)
{
return NSAPI_ERROR_UNSUPPORTED;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2018, 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_M26_CELLULAR_SIM_H_
#define QUECTEL_M26_CELLULAR_SIM_H_
#include "AT_CellularSIM.h"
namespace mbed {
class QUECTEL_M26_CellularSIM : public AT_CellularSIM {
public:
QUECTEL_M26_CellularSIM(ATHandler &atHandler);
virtual ~QUECTEL_M26_CellularSIM();
public: //from CellularSIM
virtual nsapi_error_t get_sim_state(SimState &state);
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin);
virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin);
};
} // namespace mbed
#endif // QUECTEL_M26_CELLULAR_SIM_H_

View File

@ -0,0 +1,29 @@
{
"name": "QUECTEL_M26",
"config": {
"tx": {
"help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
"value": null
},
"rx": {
"help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.",
"value": null
},
"rts": {
"help": "RTS pin for serial connection",
"value": null
},
"cts": {
"help": "CTS pin for serial connection",
"value": null
},
"baudrate" : {
"help": "Serial connection baud rate",
"value": 115200
},
"provide-default": {
"help": "Provide as default CellularDevice [true/false]",
"value": false
}
}
}

View File

@ -44,8 +44,6 @@ public:
QUECTEL_UG96(FileHandle *fh);
protected: // AT_CellularDevice
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
public: // NetworkInterface

View File

@ -50,7 +50,6 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh)
{
#ifdef TARGET_UBLOX_C030_R41XM
AT_CellularBase::set_cellular_properties(cellular_properties);
}

View File

@ -36,8 +36,6 @@ public:
UBLOX_AT(FileHandle *fh);
protected: // AT_CellularDevice
virtual nsapi_error_t power_on();
virtual nsapi_error_t power_off();
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
public: // NetworkInterface