mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Fixed backward compatibility with OnBoardCellularInterface and set default values in NetworkInterfaceDefaults.cpp.
parent
1a047efade
commit
3f6e088782
|
@ -119,7 +119,7 @@ public: // from NetworkInterface
|
|||
virtual const char *get_netmask() = 0;
|
||||
virtual const char *get_gateway() = 0;
|
||||
virtual bool is_connected() = 0;
|
||||
static CellularBase *get_default_instance();
|
||||
static CellularContext *get_default_instance();
|
||||
|
||||
|
||||
// Operations, can be sync/async. Also Connect() is this kind of operations, inherited from NetworkInterface above.
|
||||
|
|
|
@ -34,10 +34,6 @@ class FileHandle;
|
|||
const int MAX_PIN_SIZE = 8;
|
||||
const int MAX_PLMN_SIZE = 16;
|
||||
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN NULL
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Class CellularDevice
|
||||
*
|
||||
|
@ -73,7 +69,7 @@ public:
|
|||
* @return new instance of class CellularContext or NULL in case of failure
|
||||
*
|
||||
*/
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) = 0;
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) = 0;
|
||||
|
||||
/** Deletes the given CellularContext instance
|
||||
*
|
||||
|
|
|
@ -52,8 +52,8 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
|
|||
_is_context_active = false;
|
||||
_is_context_activated = false;
|
||||
_apn = apn;
|
||||
_uname = MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME;
|
||||
_pwd = MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD;
|
||||
_uname = NULL;
|
||||
_pwd = NULL;
|
||||
_status_cb = NULL;
|
||||
_cid = -1;
|
||||
_new_context_set = false;
|
||||
|
@ -465,6 +465,7 @@ nsapi_error_t AT_CellularContext::do_activate_context()
|
|||
// try to find or create context with suitable stack
|
||||
if (get_context()) {
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
_at.unlock();
|
||||
// in PPP we don't activate any context but leave it to PPP stack
|
||||
return err;
|
||||
#endif // NSAPI_PPP_AVAILABLE
|
||||
|
@ -483,6 +484,7 @@ nsapi_error_t AT_CellularContext::do_activate_context()
|
|||
|
||||
// do check for stack to validate that we have support for stack
|
||||
if (!get_stack()) {
|
||||
_at.unlock();
|
||||
tr_error("No cellular stack!");
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mbed {
|
|||
|
||||
class AT_CellularContext : public CellularContext, public AT_CellularBase {
|
||||
public:
|
||||
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
|
||||
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0);
|
||||
virtual ~AT_CellularContext();
|
||||
|
||||
// from CellularBase/NetworkInterface
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
virtual const char *get_netmask();
|
||||
virtual const char *get_gateway();
|
||||
|
||||
private: // from CellularContext
|
||||
// from CellularContext
|
||||
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t ¶ms_list);
|
||||
virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports,
|
||||
CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate);
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
AT_CellularDevice(FileHandle *fh);
|
||||
virtual ~AT_CellularDevice();
|
||||
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL);
|
||||
virtual void delete_context(CellularContext *context);
|
||||
|
||||
virtual CellularNetwork *open_network(FileHandle *fh = NULL);
|
||||
|
|
|
@ -18,14 +18,18 @@
|
|||
|
||||
namespace mbed {
|
||||
#ifdef CELLULAR_DEVICE
|
||||
MBED_WEAK CellularBase *CellularContext::get_default_instance()
|
||||
MBED_WEAK CellularContext *CellularContext::get_default_instance()
|
||||
{
|
||||
// Uses default APN, uname, password from mbed_app.json
|
||||
static CellularDevice *dev = CellularDevice::get_default_instance();
|
||||
return dev->create_context();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
static CellularContext *context = dev->create_context();
|
||||
return context;
|
||||
}
|
||||
#else
|
||||
MBED_WEAK CellularBase *CellularContext::get_default_instance()
|
||||
MBED_WEAK CellularContext *CellularContext::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
|||
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
|
||||
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
|
||||
{
|
||||
set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
|
||||
set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
|
||||
set_sim_pin(NULL);
|
||||
set_plmn(NULL);
|
||||
}
|
||||
|
||||
CellularDevice::~CellularDevice()
|
||||
|
@ -171,14 +171,14 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
|||
_nw = open_network(_fh);
|
||||
// Attach to network so we can get update status from the network
|
||||
_nw->attach(callback(this, &CellularDevice::cellular_callback));
|
||||
if (strlen(_plmn)) {
|
||||
_state_machine->set_plmn(_plmn);
|
||||
}
|
||||
} else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK &&
|
||||
ptr_data->status_data == CellularSIM::SimStatePinNeeded) {
|
||||
if (strlen(_sim_pin)) {
|
||||
_state_machine->set_sim_pin(_sim_pin);
|
||||
}
|
||||
if (strlen(_plmn)) {
|
||||
_state_machine->set_plmn(_plmn);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tr_debug("Device: network_callback called with event: %d, ptr: %d", ev, ptr);
|
||||
|
|
|
@ -110,8 +110,29 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
|
|||
#elif MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == CELLULAR
|
||||
MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
|
||||
{
|
||||
return CellularBase::get_default_instance();
|
||||
|
||||
CellularBase *cellular = CellularBase::get_default_instance();
|
||||
if (!cellular) {
|
||||
return NULL;
|
||||
}
|
||||
/* CellularBase is expected to attempt to work without any parameters - we
|
||||
* will try, at least.
|
||||
*/
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL
|
||||
#endif
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL
|
||||
#endif
|
||||
cellular->set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
|
||||
cellular->set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
|
||||
cellular->set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
|
||||
#endif
|
||||
return cellular;
|
||||
}
|
||||
#elif defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)
|
||||
/* If anyone invents a new JSON value, they must have their own default weak
|
||||
|
|
|
@ -60,13 +60,19 @@ void OnboardCellularInterface::modem_power_down()
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CELLULAR_DEVICE
|
||||
|
||||
#ifdef ONBOARD_CELLULAR_INTERFACE_AVAILABLE
|
||||
#ifdef CELLULAR_DEVICE
|
||||
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
|
||||
{
|
||||
return mbed::CellularContext::get_default_instance();
|
||||
return CellularContext::get_default_instance();
|
||||
}
|
||||
#elif defined ONBOARD_CELLULAR_INTERFACE_AVAILABLE
|
||||
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
|
||||
{
|
||||
static OnboardCellularInterface cellular;
|
||||
|
||||
return &cellular;
|
||||
}
|
||||
#else
|
||||
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
|
||||
|
|
|
@ -18,7 +18,39 @@
|
|||
|
||||
#include "CellularContext.h"
|
||||
#ifdef CELLULAR_DEVICE
|
||||
typedef mbed::CellularContext OnboardCellularInterface;
|
||||
using namespace mbed;
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use CellularBase::get_default_instance() instead.")
|
||||
class OnboardCellularInterface : public CellularBase
|
||||
{
|
||||
public:
|
||||
OnboardCellularInterface() {
|
||||
context = CellularContext::get_default_instance();
|
||||
MBED_ASSERT(context != NULL);
|
||||
}
|
||||
public: // from NetworkInterface
|
||||
virtual nsapi_error_t set_blocking(bool blocking) {return context->set_blocking(blocking);}
|
||||
virtual NetworkStack *get_stack() {return context->get_stack();}
|
||||
virtual const char *get_ip_address() {return context->get_ip_address();}
|
||||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) {context->attach(status_cb);}
|
||||
virtual nsapi_error_t connect() {return context->connect();}
|
||||
virtual nsapi_error_t disconnect() {return context->disconnect();}
|
||||
|
||||
// from CellularBase
|
||||
virtual void set_plmn(const char *plmn) {context->set_plmn(plmn);}
|
||||
virtual void set_sim_pin(const char *sim_pin) {context->set_sim_pin(sim_pin);}
|
||||
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
|
||||
const char *pwd = 0)
|
||||
{return context->connect(sim_pin, apn, uname, pwd);}
|
||||
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0)
|
||||
{context->set_credentials(apn, uname, pwd);}
|
||||
virtual const char *get_netmask() {return context->get_netmask();}
|
||||
virtual const char *get_gateway() {return context->get_gateway();}
|
||||
virtual bool is_connected() {return context->is_connected();}
|
||||
|
||||
private:
|
||||
CellularContext *context;
|
||||
};
|
||||
|
||||
#define ONBOARD_CELLULAR_INTERFACE_AVAILABLE
|
||||
#elif MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
"default-wifi-ssid": null,
|
||||
"default-wifi-password": null,
|
||||
"default-wifi-security": "NONE",
|
||||
"default-cellular-plmn": 0,
|
||||
"default-cellular-sim-pin": 0,
|
||||
"default-cellular-apn": 0,
|
||||
"default-cellular-username": 0,
|
||||
"default-cellular-password": 0,
|
||||
"default-cellular-plmn": null,
|
||||
"default-cellular-sim-pin": null,
|
||||
"default-cellular-apn": null,
|
||||
"default-cellular-username": null,
|
||||
"default-cellular-password": null,
|
||||
"default-mesh-type": {
|
||||
"help": "Configuration type for MeshInterface::get_default_instance(). [LOWPAN/THREAD]",
|
||||
"value": "THREAD"
|
||||
|
|
Loading…
Reference in New Issue