mirror of https://github.com/ARMmbed/mbed-os.git
Changed CellularContext to inherit from CellularBase instead of NetworkInterface. \n Changed Device constructor to take Filehandle instead of eventqueue.
parent
dbbe2ddc59
commit
9fb83024ea
|
@ -84,15 +84,15 @@ public:
|
|||
|
||||
class my_AT_CTX : public AT_CellularContext {
|
||||
public:
|
||||
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN,
|
||||
nsapi_ip_stack_t stack = DEFAULT_STACK) : AT_CellularContext(at, device, apn, stack) {}
|
||||
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
|
||||
AT_CellularContext(at, device, apn) {}
|
||||
virtual ~my_AT_CTX() {}
|
||||
};
|
||||
|
||||
class my_AT_CTXIPV6 : public AT_CellularContext {
|
||||
public:
|
||||
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN,
|
||||
nsapi_ip_stack_t stack = DEFAULT_STACK) : AT_CellularContext(at, device, apn, stack) {}
|
||||
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
|
||||
AT_CellularContext(at, device, apn) {}
|
||||
virtual ~my_AT_CTXIPV6() {}
|
||||
};
|
||||
|
||||
|
|
|
@ -37,10 +37,10 @@ protected:
|
|||
|
||||
TEST_F(TestAT_CellularDevice, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularDevice *dev2 = new AT_CellularDevice(que);
|
||||
CellularDevice *dev2 = new AT_CellularDevice(&fh1);
|
||||
|
||||
EXPECT_TRUE(dev2 != NULL);
|
||||
delete dev2;
|
||||
|
@ -48,11 +48,10 @@ TEST_F(TestAT_CellularDevice, Create)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
FileHandle_stub fh2;
|
||||
FileHandle_stub fh3;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
EXPECT_TRUE(dev.open_sms(&fh2));
|
||||
|
@ -66,9 +65,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularNetwork *nw = dev.open_network(NULL);
|
||||
CellularNetwork *nw1 = dev.open_network(&fh1);
|
||||
|
@ -80,9 +78,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularSMS *sms = dev.open_sms(NULL);
|
||||
CellularSMS *sms1 = dev.open_sms(&fh1);
|
||||
|
@ -94,9 +91,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularPower *pwr = dev.open_power(NULL);
|
||||
CellularPower *pwr1 = dev.open_power(&fh1);
|
||||
|
@ -108,9 +104,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularSIM *sim = dev.open_sim(NULL);
|
||||
CellularSIM *sim1 = dev.open_sim(&fh1);
|
||||
|
@ -122,9 +117,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
|
||||
CellularInformation *info = dev.open_information(NULL);
|
||||
CellularInformation *info1 = dev.open_information(&fh1);
|
||||
|
@ -136,9 +130,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
|
@ -151,9 +144,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_sms(&fh1));
|
||||
|
@ -166,9 +158,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_power(&fh1));
|
||||
|
@ -181,9 +172,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::ref_count = 0;
|
||||
int ana = 0;
|
||||
|
||||
|
@ -202,9 +192,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::int_value = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_information(&fh1));
|
||||
|
@ -213,6 +202,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
|||
AT_CellularBase_stub::handler_value = NULL;
|
||||
dev.close_information();
|
||||
|
||||
EventQueue que;
|
||||
ATHandler_stub::fh_value = &fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
AT_CellularBase_stub::handler_value = &at;
|
||||
|
@ -228,9 +218,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::timeout = 0;
|
||||
ATHandler_stub::default_timeout = false;
|
||||
|
||||
|
@ -251,9 +240,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
ATHandler_stub::debug_on = false;
|
||||
|
||||
// no interfaces open so debug toggling should not affect
|
||||
|
@ -271,14 +259,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
|||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
EXPECT_TRUE(0 == dev.get_send_delay());
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
|
||||
FileHandle_stub fh1;
|
||||
AT_CellularDevice dev(&fh1);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
using namespace mbed;
|
||||
|
||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack) :
|
||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
||||
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
||||
{
|
||||
|
@ -105,14 +105,29 @@ nsapi_error_t AT_CellularContext::set_blocking(bool blocking)
|
|||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_apn_credentials(const char *uname, const char *pwd,
|
||||
CellularContext::AuthenticationType type) {
|
||||
void AT_CellularContext::set_sim_pin(const char *sim_pin)
|
||||
{
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_apn_credentials(const char* apn, const char *uname, const char *pwd,
|
||||
CellularContext::AuthenticationType type)
|
||||
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
||||
const char *pwd)
|
||||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_credentials(const char *apn, const char *uname, const char *pwd)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const char *AT_CellularContext::get_netmask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *AT_CellularContext::get_gateway()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
|
||||
|
|
|
@ -26,8 +26,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CellularDevice::CellularDevice() : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
|
||||
_info_ref_count(0), _fh(0), _error(0), _state_machine(0), _nw(0)
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -36,11 +36,15 @@ CellularDevice::~CellularDevice()
|
|||
|
||||
}
|
||||
|
||||
events::EventQueue *CellularDevice::get_queue() const
|
||||
events::EventQueue *CellularDevice::get_queue()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CellularDevice::set_sim_pin(char const*)
|
||||
{
|
||||
}
|
||||
|
||||
CellularContext *CellularDevice::get_context_list() const
|
||||
{
|
||||
return NULL;
|
||||
|
|
|
@ -78,7 +78,7 @@ static void test_information_interface()
|
|||
{
|
||||
CellularInformation *info = cellular.get_device()->open_information(&cellular_serial);
|
||||
const int kbuf_size = 100;
|
||||
char *buf = (char *)malloc(sizeof(char) * kbuf_size);
|
||||
char *buf = new char[kbuf_size];
|
||||
|
||||
TEST_ASSERT(info->get_manufacturer(buf, kbuf_size) == NSAPI_ERROR_OK);
|
||||
TEST_ASSERT(info->get_model(buf, kbuf_size) == NSAPI_ERROR_OK);
|
||||
|
@ -98,7 +98,7 @@ static void test_information_interface()
|
|||
|
||||
cellular.get_device()->close_information();
|
||||
|
||||
free(buf);
|
||||
delete [] buf;
|
||||
}
|
||||
|
||||
using namespace utest::v1;
|
||||
|
|
|
@ -1,239 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 "CellularTargets.h"
|
||||
#ifdef CELLULAR_DEVICE
|
||||
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
#include "nsapi_ppp.h"
|
||||
#endif
|
||||
|
||||
#include "EasyCellularConnection.h"
|
||||
#include "CellularContext.h"
|
||||
#include "CellularSIM.h"
|
||||
#include "CellularLog.h"
|
||||
#include "mbed_wait_api.h"
|
||||
|
||||
#if USE_APN_LOOKUP
|
||||
#include "APN_db.h"
|
||||
#endif //USE_APN_LOOKUP
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void EasyCellularConnection::network_callback(nsapi_event_t ev, intptr_t ptr)
|
||||
{
|
||||
// forward to application
|
||||
if (_status_cb) {
|
||||
_status_cb(ev, ptr);
|
||||
}
|
||||
}
|
||||
|
||||
EasyCellularConnection::EasyCellularConnection(CellularContext *ctx) : _is_initialized(false), _context(ctx),
|
||||
_credentials_err(NSAPI_ERROR_OK), _status_cb(0)
|
||||
{
|
||||
_device = CellularDevice::get_default_instance();
|
||||
#if USE_APN_LOOKUP
|
||||
_credentials_set = false;
|
||||
#endif // #if USE_APN_LOOKUP
|
||||
}
|
||||
|
||||
EasyCellularConnection::~EasyCellularConnection()
|
||||
{
|
||||
}
|
||||
|
||||
nsapi_error_t EasyCellularConnection::init()
|
||||
{
|
||||
nsapi_error_t err = NSAPI_ERROR_OK;
|
||||
if (!_is_initialized) {
|
||||
_context->attach(callback(this, &EasyCellularConnection::network_callback));
|
||||
err = _device->start_dispatch();
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
_is_initialized = true;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void EasyCellularConnection::set_credentials(const char *apn, const char *uname, const char *pwd)
|
||||
{
|
||||
if (apn && strlen(apn) > 0) {
|
||||
_credentials_err = init();
|
||||
if (_credentials_err) {
|
||||
return;
|
||||
}
|
||||
|
||||
_context->set_apn_credentials(apn, uname, pwd);
|
||||
#if USE_APN_LOOKUP
|
||||
_credentials_set = true;
|
||||
#endif // #if USE_APN_LOOKUP
|
||||
}
|
||||
}
|
||||
|
||||
void EasyCellularConnection::set_sim_pin(const char *sim_pin)
|
||||
{
|
||||
if (sim_pin && strlen(sim_pin) > 0) {
|
||||
_device->set_sim_pin(sim_pin);
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_error_t EasyCellularConnection::connect(const char *sim_pin, const char *apn, const char *uname, const char *pwd)
|
||||
{
|
||||
if (_context->is_connected()) {
|
||||
return NSAPI_ERROR_IS_CONNECTED;
|
||||
}
|
||||
|
||||
set_credentials(apn, uname, pwd);
|
||||
if (_credentials_err) {
|
||||
return _credentials_err;
|
||||
}
|
||||
|
||||
if (sim_pin) {
|
||||
set_sim_pin(sim_pin);
|
||||
}
|
||||
|
||||
return connect();
|
||||
}
|
||||
|
||||
nsapi_error_t EasyCellularConnection::check_connect()
|
||||
{
|
||||
if (_context->is_connected()) {
|
||||
return NSAPI_ERROR_IS_CONNECTED;
|
||||
}
|
||||
|
||||
// there was an error while setting credentials but it's a void function so check error here...
|
||||
if (_credentials_err) {
|
||||
return _credentials_err;
|
||||
}
|
||||
|
||||
nsapi_error_t err = init();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t EasyCellularConnection::connect()
|
||||
{
|
||||
nsapi_error_t err = check_connect();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#if USE_APN_LOOKUP
|
||||
if (!_credentials_set) {
|
||||
err = _context->set_sim_ready();
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
char imsi[MAX_IMSI_LENGTH + 1];
|
||||
wait(1); // need to wait to access SIM in some modems
|
||||
CellularSIM* sim = _device->open_sim(&_device->get_filehandle());
|
||||
err = sim->get_imsi(imsi);
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
const char *apn_config = apnconfig(imsi);
|
||||
if (apn_config) {
|
||||
const char *apn = _APN_GET(apn_config);
|
||||
const char *uname = _APN_GET(apn_config);
|
||||
const char *pwd = _APN_GET(apn_config);
|
||||
tr_info("Looked up APN %s", apn);
|
||||
_context->set_apn_credentials(apn, uname, pwd);
|
||||
}
|
||||
}
|
||||
_device->close_sim();
|
||||
} else {
|
||||
tr_error("APN lookup failed");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif // USE_APN_LOOKUP
|
||||
|
||||
|
||||
err = _context->connect();
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
tr_info("No cellular connection");
|
||||
err = NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
nsapi_error_t EasyCellularConnection::disconnect()
|
||||
{
|
||||
_credentials_err = NSAPI_ERROR_OK;
|
||||
_is_initialized = false;
|
||||
#if USE_APN_LOOKUP
|
||||
_credentials_set = false;
|
||||
#endif // #if USE_APN_LOOKUP
|
||||
|
||||
return _context->disconnect();
|
||||
}
|
||||
|
||||
bool EasyCellularConnection::is_connected()
|
||||
{
|
||||
return _context->is_connected();
|
||||
}
|
||||
|
||||
const char *EasyCellularConnection::get_ip_address()
|
||||
{
|
||||
return _context->get_ip_address();
|
||||
}
|
||||
|
||||
const char *EasyCellularConnection::get_netmask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *EasyCellularConnection::get_gateway()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void EasyCellularConnection::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||
{
|
||||
_status_cb = status_cb;
|
||||
}
|
||||
|
||||
void EasyCellularConnection::modem_debug_on(bool on)
|
||||
{
|
||||
_device->modem_debug_on(on);
|
||||
}
|
||||
|
||||
void EasyCellularConnection::set_plmn(const char *plmn)
|
||||
{
|
||||
if (plmn && strlen(plmn) > 0) {
|
||||
_device->set_plmn(plmn);
|
||||
}
|
||||
}
|
||||
|
||||
NetworkStack *EasyCellularConnection::get_stack()
|
||||
{
|
||||
return _context->get_stack();
|
||||
}
|
||||
|
||||
CellularDevice *EasyCellularConnection::get_device() const
|
||||
{
|
||||
return _device;
|
||||
}
|
||||
|
||||
UARTSerial *EasyCellularConnection::get_serial()
|
||||
{
|
||||
return (UARTSerial*)&_device->get_filehandle();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // CELLULAR_DEVICE
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 EASY_CELLULAR_CONNECTION_H
|
||||
#define EASY_CELLULAR_CONNECTION_H
|
||||
|
||||
#include "CellularStateMachine.h"
|
||||
|
||||
#if defined(CELLULAR_DEVICE) || defined(DOXYGEN_ONLY)
|
||||
|
||||
#include "CellularContext.h"
|
||||
#include "UARTSerial.h"
|
||||
#include "CellularBase.h"
|
||||
|
||||
#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class CellularDevice;
|
||||
/** EasyCellularConnection class
|
||||
*
|
||||
* Simplified adapter for cellular connection
|
||||
*/
|
||||
class EasyCellularConnection: public CellularBase {
|
||||
|
||||
public:
|
||||
EasyCellularConnection(CellularContext *ctx = (CellularContext *)CellularContext::get_default_instance());
|
||||
virtual ~EasyCellularConnection();
|
||||
|
||||
public:
|
||||
/** Set the Cellular network credentials
|
||||
*
|
||||
* Please check documentation of connect() for default behaviour of APN settings.
|
||||
*
|
||||
* @param apn Access point name
|
||||
* @param uname optionally, Username
|
||||
* @param pwd optionally, password
|
||||
*/
|
||||
virtual void set_credentials(const char *apn, const char *uname = 0,
|
||||
const char *pwd = 0);
|
||||
|
||||
/** Set the pin code for SIM card
|
||||
*
|
||||
* @param sim_pin PIN for the SIM card
|
||||
*/
|
||||
virtual void set_sim_pin(const char *sim_pin);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to connect to a Cellular network.
|
||||
*
|
||||
* @param sim_pin PIN for the SIM card
|
||||
* @param apn optionally, access point name
|
||||
* @param uname optionally, Username
|
||||
* @param pwd optionally, password
|
||||
* @return NSAPI_ERROR_OK on success, or negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0,
|
||||
const char *uname = 0,
|
||||
const char *pwd = 0);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to connect to a Cellular network.
|
||||
* If the SIM requires a PIN, and it is not set/invalid, NSAPI_ERROR_AUTH_ERROR is returned.
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success, or negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t connect();
|
||||
|
||||
/** Stop the interface
|
||||
*
|
||||
* @return 0 on success, or error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t disconnect();
|
||||
|
||||
/** Check if the connection is currently established or not
|
||||
*
|
||||
* @return true/false If the cellular module have successfully acquired a carrier and is
|
||||
* connected to an external packet data network using PPP, isConnected()
|
||||
* API returns true and false otherwise.
|
||||
*/
|
||||
virtual bool is_connected();
|
||||
|
||||
/** Get the local IP address
|
||||
*
|
||||
* @return Null-terminated representation of the local IP address
|
||||
* or null if no IP address has been received
|
||||
*/
|
||||
virtual const char *get_ip_address();
|
||||
|
||||
/** Get the local network mask
|
||||
*
|
||||
* @return Null-terminated representation of the local network mask
|
||||
* or null if no network mask has been received
|
||||
*/
|
||||
virtual const char *get_netmask();
|
||||
|
||||
/** Get the local gateways
|
||||
*
|
||||
* @return Null-terminated representation of the local gateway
|
||||
* or null if no network mask has been received
|
||||
*/
|
||||
virtual const char *get_gateway();
|
||||
|
||||
/** Register callback for status reporting
|
||||
*
|
||||
* The specified status callback function will be called on status changes
|
||||
* on the network. The parameters on the callback are the event type and
|
||||
* event-type dependent reason parameter.
|
||||
*
|
||||
* @param status_cb The callback for status changes
|
||||
*/
|
||||
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||
|
||||
/** Turn modem debug traces on
|
||||
*
|
||||
* @param on set true to enable debug traces
|
||||
*/
|
||||
void modem_debug_on(bool on);
|
||||
|
||||
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
|
||||
* registering is used when registering to a cellular network.
|
||||
*
|
||||
* @param plmn operator in numeric format. See more from 3GPP TS 27.007 chapter 7.3.
|
||||
*/
|
||||
void set_plmn(const char *plmn);
|
||||
|
||||
/** Get the cellular device from the cellular state machine
|
||||
*
|
||||
* @return cellular device
|
||||
*/
|
||||
CellularDevice *get_device() const;
|
||||
|
||||
/** Get the UART serial file handle used by cellular subsystem
|
||||
*
|
||||
* @return address of cellular UART serial
|
||||
*/
|
||||
UARTSerial *get_serial();
|
||||
|
||||
protected:
|
||||
|
||||
/** Provide access to the NetworkStack object
|
||||
*
|
||||
* @return The underlying NetworkStack object
|
||||
*/
|
||||
virtual NetworkStack *get_stack();
|
||||
|
||||
private:
|
||||
void network_callback(nsapi_event_t ev, intptr_t ptr);
|
||||
nsapi_error_t init();
|
||||
nsapi_error_t check_connect();
|
||||
|
||||
bool _is_initialized;
|
||||
#if USE_APN_LOOKUP
|
||||
bool _credentials_set;
|
||||
#endif // #if USE_APN_LOOKUP
|
||||
|
||||
CellularDevice *_device;
|
||||
CellularContext* _context;
|
||||
nsapi_error_t _credentials_err;
|
||||
Callback<void(nsapi_event_t, intptr_t)> _status_cb;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // CELLULAR_DEVICE || DOXYGEN
|
||||
|
||||
#endif // EASY_CELLULAR_CONNECTION_H
|
||||
|
||||
/** @}*/
|
|
@ -17,18 +17,26 @@
|
|||
#ifndef _CELLULARCONTEXT_H_
|
||||
#define _CELLULARCONTEXT_H_
|
||||
|
||||
#include "NetworkInterface.h"
|
||||
#include "CellularBase.h"
|
||||
#include "CellularDevice.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class CellularContext : public NetworkInterface {
|
||||
class CellularContext : public CellularBase {
|
||||
|
||||
public:
|
||||
// max simultaneous PDP contexts active
|
||||
static const int PDP_CONTEXT_COUNT = 4;
|
||||
|
||||
static NetworkInterface *get_default_instance();
|
||||
/** Get the default cellular interface.
|
||||
*
|
||||
* This is provided as a weak method so applications can override.
|
||||
* Default behaviour is to get the target's default interface, if
|
||||
* any.
|
||||
*
|
||||
* @return pointer to interface, if any.
|
||||
*/
|
||||
static CellularBase *get_default_instance();
|
||||
|
||||
/* authentication type when activating or modifying the pdp context */
|
||||
enum AuthenticationType {
|
||||
|
@ -113,9 +121,17 @@ public: // from NetworkInterface
|
|||
virtual nsapi_error_t disconnect() = 0;
|
||||
virtual bool is_connected() = 0;
|
||||
|
||||
public:
|
||||
// from CellularBase
|
||||
virtual void set_sim_pin(const char *sim_pin) = 0;
|
||||
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
|
||||
const char *pwd = 0) = 0;
|
||||
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0;
|
||||
virtual const char *get_netmask() = 0;
|
||||
virtual const char *get_gateway() = 0;
|
||||
|
||||
/** Start the interface
|
||||
// Operations, can be sync/async. Also Connect() is this kind of operations, inherited from NetworkInterface above.
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Power on the device and does the initializations for communication with the modem..
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
|
@ -163,7 +179,7 @@ public:
|
|||
*/
|
||||
virtual nsapi_error_t attach_to_network() = 0;
|
||||
|
||||
public:
|
||||
// PDP Context specific functions
|
||||
|
||||
/** Get APN rate control.
|
||||
*
|
||||
|
@ -196,32 +212,13 @@ public:
|
|||
*/
|
||||
virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer) = 0;
|
||||
|
||||
/** Set the cellular network APN and credentials
|
||||
*
|
||||
* @param apn Optional name of the network to connect to
|
||||
* @param uname Optional username for the APN
|
||||
* @param pwd Optional password for the APN
|
||||
*/
|
||||
virtual void set_apn_credentials(const char *uname = 0, const char *pwd = 0,
|
||||
CellularContext::AuthenticationType type = CellularContext::CHAP) = 0;
|
||||
|
||||
/** Set the cellular network APN and credentials
|
||||
*
|
||||
* @param apn Name of the network to connect to
|
||||
* @param uname Optional username for the APN
|
||||
* @param pwd Optional password for the APN
|
||||
* @param type Optional authentication type to use
|
||||
*/
|
||||
virtual void set_apn_credentials(const char* apn, const char *uname = 0, const char *pwd = 0,
|
||||
CellularContext::AuthenticationType type = CellularContext::CHAP) = 0;
|
||||
|
||||
/** Set the file handle used to communicate with the modem. Can be used to change default file handle.
|
||||
*
|
||||
* @param fh file handle for communicating with the modem
|
||||
*/
|
||||
virtual void set_file_handle(FileHandle *fh) = 0;
|
||||
|
||||
protected:
|
||||
protected: // Device specific implementations might need these so protected
|
||||
enum ContextOperation {
|
||||
OP_INVALID = -1,
|
||||
OP_DEVICE_READY = 0,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#ifndef CELLULAR_DEVICE_H_
|
||||
#define CELLULAR_DEVICE_H_
|
||||
|
||||
#include "CellularTargets.h"
|
||||
#include "CellularStateMachine.h"
|
||||
|
||||
namespace mbed {
|
||||
|
@ -53,47 +54,105 @@ public:
|
|||
*/
|
||||
static CellularDevice *get_default_instance();
|
||||
|
||||
/** Get event queue that can be chained to main event queue. EventQueue is created in get_default_instance() or
|
||||
* given to CELLULAR_DEVICE (for example TELIT_HE910 class) if get_default_instance() is not used to create CellularDevice.
|
||||
* @return event queue
|
||||
*/
|
||||
virtual events::EventQueue *get_queue() const;
|
||||
|
||||
/** Get file handle
|
||||
*
|
||||
* @return File handle used in CellularDevice. For example with AT it's UARTSerial.
|
||||
*/
|
||||
FileHandle &get_filehandle() const;
|
||||
|
||||
/** Default constructor
|
||||
*
|
||||
* @param fh File handle used in communication with the modem.
|
||||
*/
|
||||
CellularDevice();
|
||||
CellularDevice(FileHandle *fh);
|
||||
|
||||
/** virtual Destructor
|
||||
*/
|
||||
virtual ~CellularDevice();
|
||||
|
||||
public:
|
||||
|
||||
/** Creates a new CellularContext interface. There can be multiple CellularContext interfaces unlike interface opened with
|
||||
* open_xxx(...) methods.
|
||||
/** Creates a new CellularContext interface.
|
||||
*
|
||||
* @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
|
||||
* file handle is used.
|
||||
* @param apn access point to use with context, can be null.
|
||||
* @param stack stack type to be used when finding suitable PDP context
|
||||
*
|
||||
* @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, nsapi_ip_stack_t stack = DEFAULT_STACK) = 0;
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) = 0;
|
||||
|
||||
/** Deletes the given CellularContext instance
|
||||
*
|
||||
* @param context to delete
|
||||
* @param context CellularContext to delete
|
||||
*/
|
||||
virtual void delete_context(CellularContext *context) = 0;
|
||||
|
||||
/** Stop the current operation. Operations: set_device_ready, set_sim_ready, register_to_network, attach_to_network
|
||||
*
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/** Get event queue that can be chained to main event queue.
|
||||
* @return event queue
|
||||
*/
|
||||
virtual events::EventQueue *get_queue();
|
||||
|
||||
/** Set the pin code for SIM card
|
||||
*
|
||||
* @param sim_pin PIN for the SIM card
|
||||
*/
|
||||
void set_sim_pin(const char *sim_pin);
|
||||
|
||||
/** Plmn to use when registering to cellular network.
|
||||
* If plmn is set then registering is forced to this plmn. If plmn is not set then automatic
|
||||
* registering is used when registering to a cellular network. Does not start any operations.
|
||||
*
|
||||
* @param plmn plmn used when registering to cellular network
|
||||
*/
|
||||
void set_plmn(const char* plmn);
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Power on the device and does the initializations for communication with the modem..
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t set_device_ready();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to open the sim.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t set_sim_ready();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to register the device to cellular network.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t register_to_network();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to attach the device to cellular network.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t attach_to_network();
|
||||
|
||||
/** Create new CellularNetwork interface.
|
||||
*
|
||||
* @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
|
||||
|
@ -170,97 +229,9 @@ public:
|
|||
* For example, when multiple modules are supported in a single AT driver this function detects
|
||||
* and adapts to an actual module at runtime.
|
||||
*
|
||||
* @param fh file handle used in communication to modem.
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual nsapi_error_t init_module(FileHandle *fh) = 0;
|
||||
|
||||
public:
|
||||
|
||||
/** Start event queue dispatching in internal state machine by creating a new thread.
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on memory failure
|
||||
*/
|
||||
nsapi_error_t start_dispatch();
|
||||
|
||||
/** Stop the current operation. Operations: set_device_ready, set_sim_ready, register_to_network, attach_to_network
|
||||
*
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/** Set the pin code for SIM card
|
||||
*
|
||||
* @param sim_pin PIN for the SIM card
|
||||
*/
|
||||
void set_sim_pin(const char *sim_pin);
|
||||
|
||||
/** Plmn to use when registering to cellular network.
|
||||
* If plmn is set then registering is forced to this plmn. If plmn is not set then automatic
|
||||
* registering is used when registering to a cellular network. Does not start any operations.
|
||||
*
|
||||
* @param plmn plmn used when registering to cellular network
|
||||
*/
|
||||
void set_plmn(const char* plmn);
|
||||
|
||||
public: // Operations that can be sync/async, CellularContext will use these
|
||||
friend class CellularContext;
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Power on the device and does the initializations for communication with the modem..
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t set_device_ready();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to open the sim.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t set_sim_ready();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to register the device to cellular network.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t register_to_network();
|
||||
|
||||
/** Start the interface
|
||||
*
|
||||
* Attempts to attach the device to cellular network.
|
||||
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
|
||||
* In synchronous and asynchronous mode application can get result in from callback which is set with
|
||||
* attach(...)
|
||||
*
|
||||
* @return NSAPI_ERROR_OK on success
|
||||
* NSAPI_ERROR_NO_MEMORY on case of memory failure
|
||||
*/
|
||||
nsapi_error_t attach_to_network();
|
||||
|
||||
/** Cellular callback which is called by Network class after this class attaches to it, CellularStateMachine
|
||||
* and CellularContext when in PPP mode. This method will broadcast to every interested classes:
|
||||
* CellularContext (might be many) and CellularStateMachine if available.
|
||||
*
|
||||
*/
|
||||
void cellular_callback(nsapi_event_t ev, intptr_t ptr);
|
||||
virtual nsapi_error_t init_module() = 0;
|
||||
|
||||
/** Get the linked list of CellularContext instances
|
||||
*
|
||||
|
@ -268,17 +239,27 @@ public: // Operations that can be sync/async, CellularContext will use these
|
|||
*/
|
||||
virtual CellularContext *get_context_list() const;
|
||||
|
||||
protected:
|
||||
friend class AT_CellularNetwork;
|
||||
friend class AT_CellularContext;
|
||||
/** Cellular callback which is called by Network class after this class attaches to it, CellularStateMachine
|
||||
* and CellularContext when in PPP mode. This method will broadcast to every interested classes:
|
||||
* CellularContext (might be many) and CellularStateMachine if available.
|
||||
*
|
||||
*/
|
||||
void cellular_callback(nsapi_event_t ev, intptr_t ptr);
|
||||
|
||||
int _network_ref_count;
|
||||
int _sms_ref_count;
|
||||
int _power_ref_count;
|
||||
int _sim_ref_count;
|
||||
int _info_ref_count;
|
||||
FileHandle *_fh;
|
||||
events::EventQueue _queue;
|
||||
private:
|
||||
nsapi_error_t start_state_machine(CellularStateMachine::CellularState target_state);
|
||||
void create_state_machine();
|
||||
nsapi_error_t create_state_machine();
|
||||
|
||||
nsapi_error_t _error;
|
||||
CellularStateMachine *_state_machine;
|
||||
CellularNetwork *_nw;
|
||||
char _sim_pin[MAX_PIN_SIZE + 1];
|
||||
|
|
|
@ -78,7 +78,8 @@ public:
|
|||
RegisteredSMSOnlyRoaming,
|
||||
AttachedEmergencyOnly,
|
||||
RegisteredCSFBNotPreferredHome,
|
||||
RegisteredCSFBNotPreferredRoaming = 10
|
||||
RegisteredCSFBNotPreferredRoaming,
|
||||
AlreadyRegistered = 11 // our our definition when modem says that we are not registered but we have active PDP Context
|
||||
};
|
||||
|
||||
/* Network registration type */
|
||||
|
|
|
@ -22,17 +22,26 @@
|
|||
#include "CellularUtil.h"
|
||||
#include "CellularSIM.h"
|
||||
#include "UARTSerial.h"
|
||||
#include "mbed_wait_api.h"
|
||||
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
#include "nsapi_ppp.h"
|
||||
#include "nsapi_dns.h"
|
||||
#endif
|
||||
|
||||
#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))
|
||||
|
||||
#if USE_APN_LOOKUP
|
||||
#include "APN_db.h"
|
||||
#endif //USE_APN_LOOKUP
|
||||
|
||||
using namespace mbed_cellular_util;
|
||||
using namespace mbed;
|
||||
|
||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack) :
|
||||
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularBase(at), _ip_stack_type_requested(DEFAULT_STACK), _is_connected(false), _is_blocking(true),
|
||||
_current_op(OP_INVALID), _device(device), _nw(0), _fh(0)
|
||||
{
|
||||
tr_debug("AT_CellularContext::AT_CellularContext(): apn: %s, stack: %d", apn, stack);
|
||||
tr_debug("AT_CellularContext::AT_CellularContext(): apn: %s", apn);
|
||||
_stack = NULL;
|
||||
_ip_stack_type = DEFAULT_STACK;
|
||||
_authentication_type = CellularContext::CHAP;
|
||||
|
@ -155,6 +164,16 @@ NetworkStack *AT_CellularContext::get_stack()
|
|||
return _stack;
|
||||
}
|
||||
|
||||
const char *AT_CellularContext::get_netmask()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *AT_CellularContext::get_gateway()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *AT_CellularContext::get_ip_address()
|
||||
{
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
|
@ -185,21 +204,24 @@ nsapi_error_t AT_CellularContext::set_blocking(bool blocking)
|
|||
return err;
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_apn_credentials(const char *uname, const char *pwd,
|
||||
CellularContext::AuthenticationType type) {
|
||||
|
||||
_uname = uname;
|
||||
_pwd = pwd;
|
||||
_authentication_type = type;
|
||||
void AT_CellularContext::set_sim_pin(const char *sim_pin)
|
||||
{
|
||||
_device->set_sim_pin(sim_pin);
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_apn_credentials(const char* apn, const char *uname, const char *pwd,
|
||||
CellularContext::AuthenticationType type)
|
||||
nsapi_error_t AT_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname,
|
||||
const char *pwd)
|
||||
{
|
||||
set_sim_pin(sim_pin);
|
||||
set_credentials(apn, uname, pwd);
|
||||
return connect();
|
||||
}
|
||||
|
||||
void AT_CellularContext::set_credentials(const char *apn, const char *uname, const char *pwd)
|
||||
{
|
||||
_apn = apn;
|
||||
_uname = uname;
|
||||
_pwd = pwd;
|
||||
_authentication_type = type;
|
||||
}
|
||||
|
||||
bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
|
||||
|
@ -711,16 +733,8 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t ¶ms
|
|||
{
|
||||
const int ipv6_subnet_size = 128;
|
||||
const int max_ipv6_size = 64;
|
||||
char *ipv6_and_subnetmask = (char *)malloc(ipv6_subnet_size);
|
||||
if (!ipv6_and_subnetmask) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
char *temp = (char *)malloc(max_ipv6_size);
|
||||
if (!temp) {
|
||||
free(ipv6_and_subnetmask);
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
char *ipv6_and_subnetmask = new char[ipv6_subnet_size];
|
||||
char *temp = new char[max_ipv6_size];
|
||||
|
||||
_at.lock();
|
||||
|
||||
|
@ -732,16 +746,6 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t ¶ms
|
|||
pdpcontext_params_t *params = NULL;
|
||||
while (_at.info_resp()) { // response can be zero or many +CGDCONT lines
|
||||
params = params_list.add_new();
|
||||
if (!params) {
|
||||
tr_warn("Could not allocate new pdpcontext_params_t");
|
||||
_at.resp_stop();
|
||||
_at.unlock();
|
||||
params_list.delete_all();
|
||||
free(temp);
|
||||
free(ipv6_and_subnetmask);
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
params->cid = _at.read_int();
|
||||
params->bearer_id = _at.read_int();
|
||||
_at.read_string(params->apn, sizeof(params->apn));
|
||||
|
@ -791,8 +795,8 @@ nsapi_error_t AT_CellularContext::get_pdpcontext_params(pdpContextList_t ¶ms
|
|||
}
|
||||
_at.resp_stop();
|
||||
|
||||
free(temp);
|
||||
free(ipv6_and_subnetmask);
|
||||
delete [] temp;
|
||||
delete [] ipv6_and_subnetmask;
|
||||
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
@ -803,9 +807,36 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
|||
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
|
||||
cell_callback_data_t* data = (cell_callback_data_t*)ptr;
|
||||
cellular_connection_status_t st = (cellular_connection_status_t)ev;
|
||||
tr_debug("AT_CellularContext: network_callback called with event: %d, err: %d, data: %d", ev, data->error, data->status_data);
|
||||
_cb_data.error = data->error;
|
||||
|
||||
tr_debug("AT_CellularContext::cellular_callback, network_callback called with event: %d, err: %d, data: %d", ev, data->error, data->status_data);
|
||||
#if USE_APN_LOOKUP
|
||||
if (st == CellularSIMStatusChanged && data->status_data == CellularSIM::SimStateReady &&
|
||||
_cb_data.error == NSAPI_ERROR_OK) {
|
||||
if (!_apn) {
|
||||
char imsi[MAX_IMSI_LENGTH + 1];
|
||||
wait(1); // need to wait to access SIM in some modems
|
||||
_cb_data.error = _device->open_sim()->get_imsi(imsi);
|
||||
if (_cb_data.error == NSAPI_ERROR_OK) {
|
||||
const char *apn_config = apnconfig(imsi);
|
||||
if (apn_config) {
|
||||
const char *apn = _APN_GET(apn_config);
|
||||
const char *uname = _APN_GET(apn_config);
|
||||
const char *pwd = _APN_GET(apn_config);
|
||||
tr_info("Looked up APN %s", apn);
|
||||
set_credentials(apn, uname, pwd);
|
||||
}
|
||||
} else {
|
||||
tr_error("APN lookup failed");
|
||||
_device->stop();
|
||||
if (_is_blocking) {
|
||||
// operation failed, release semaphore
|
||||
_semaphore.release();
|
||||
}
|
||||
}
|
||||
_device->close_sim();
|
||||
}
|
||||
}
|
||||
#endif // USE_APN_LOOKUP
|
||||
if (_is_blocking) {
|
||||
if (data->error != NSAPI_ERROR_OK) {
|
||||
// operation failed, release semaphore
|
||||
|
@ -817,7 +848,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
|||
// target reached, release semaphore
|
||||
_semaphore.release();
|
||||
} else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork ||
|
||||
data->status_data == CellularNetwork::RegisteredRoaming) && _current_op == OP_REGISTER) {
|
||||
data->status_data == CellularNetwork::RegisteredRoaming || data->status_data == CellularNetwork::AlreadyRegistered) && _current_op == OP_REGISTER) {
|
||||
// target reached, release semaphore
|
||||
_semaphore.release();
|
||||
} else if (st == CellularAttachNetwork && (_current_op == OP_ATTACH || _current_op == OP_CONNECT) &&
|
||||
|
@ -840,7 +871,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
tr_debug("AT_CellularContext: network_callback called with event: %d, ptr: %d", ev, ptr);
|
||||
#if NSAPI_PPP_AVAILABLE
|
||||
if (_is_blocking) {
|
||||
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {
|
||||
|
|
|
@ -27,11 +27,10 @@ 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,
|
||||
nsapi_ip_stack_t stack = DEFAULT_STACK);
|
||||
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
|
||||
virtual ~AT_CellularContext();
|
||||
|
||||
public: // from NetworkInterface
|
||||
// from CellularBase/NetworkInterface
|
||||
virtual nsapi_error_t set_blocking(bool blocking);
|
||||
virtual NetworkStack *get_stack();
|
||||
virtual const char *get_ip_address();
|
||||
|
@ -39,8 +38,15 @@ public: // from NetworkInterface
|
|||
virtual nsapi_error_t connect();
|
||||
virtual nsapi_error_t disconnect();
|
||||
virtual bool is_connected();
|
||||
// from CellularBase
|
||||
virtual void set_sim_pin(const char *sim_pin);
|
||||
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
|
||||
const char *pwd = 0);
|
||||
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0);
|
||||
virtual const char *get_netmask();
|
||||
virtual const char *get_gateway();
|
||||
|
||||
public: // from CellularContext
|
||||
private: // 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);
|
||||
|
@ -49,10 +55,6 @@ public: // from CellularContext
|
|||
virtual nsapi_error_t set_sim_ready();
|
||||
virtual nsapi_error_t register_to_network();
|
||||
virtual nsapi_error_t attach_to_network();
|
||||
virtual void set_apn_credentials(const char *uname = 0, const char *pwd = 0,
|
||||
CellularContext::AuthenticationType type = CellularContext::CHAP);
|
||||
virtual void set_apn_credentials(const char* apn, const char *uname = 0, const char *pwd = 0,
|
||||
CellularContext::AuthenticationType type = CellularContext::CHAP);
|
||||
virtual void set_file_handle(FileHandle *fh);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -33,23 +33,10 @@ using namespace mbed;
|
|||
|
||||
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
|
||||
|
||||
#ifndef MDMTXD
|
||||
#define MDMTXD NC
|
||||
#endif
|
||||
|
||||
#ifndef MDMRXD
|
||||
#define MDMRXD NC
|
||||
#endif
|
||||
|
||||
#ifndef MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE
|
||||
#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE 115200
|
||||
#endif
|
||||
|
||||
AT_CellularDevice::AT_CellularDevice(EventQueue &queue) :
|
||||
_atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _information(0), _context_list(0), _at_queue(queue),
|
||||
_default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false)
|
||||
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _atHandlers(0), _network(0), _sms(0),
|
||||
_sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
|
||||
_modem_debug_on(false)
|
||||
{
|
||||
_fh = new UARTSerial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
}
|
||||
|
||||
AT_CellularDevice::~AT_CellularDevice()
|
||||
|
@ -81,13 +68,6 @@ AT_CellularDevice::~AT_CellularDevice()
|
|||
atHandler = atHandler->_nextATHandler;
|
||||
delete old;
|
||||
}
|
||||
|
||||
delete _fh;
|
||||
}
|
||||
|
||||
events::EventQueue *AT_CellularDevice::get_queue() const
|
||||
{
|
||||
return &_at_queue;
|
||||
}
|
||||
|
||||
// each parser is associated with one filehandle (that is UART)
|
||||
|
@ -105,7 +85,7 @@ ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
|
|||
atHandler = atHandler->_nextATHandler;
|
||||
}
|
||||
|
||||
atHandler = new ATHandler(fileHandle, _at_queue, _default_timeout, "\r", get_send_delay());
|
||||
atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r", get_send_delay());
|
||||
if (_modem_debug_on) {
|
||||
atHandler->set_debug(_modem_debug_on);
|
||||
}
|
||||
|
@ -147,11 +127,11 @@ CellularContext *AT_CellularDevice::get_context_list() const
|
|||
return _context_list;
|
||||
}
|
||||
|
||||
CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, nsapi_ip_stack_t stack)
|
||||
CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn)
|
||||
{
|
||||
ATHandler *atHandler = get_at_handler(_fh);
|
||||
ATHandler *atHandler = get_at_handler(fh);
|
||||
if (atHandler) {
|
||||
AT_CellularContext *ctx = create_context_impl(*atHandler, apn, stack);
|
||||
AT_CellularContext *ctx = create_context_impl(*atHandler, apn);
|
||||
AT_CellularContext* curr = _context_list;
|
||||
|
||||
if (_context_list == NULL) {
|
||||
|
@ -171,9 +151,9 @@ CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *a
|
|||
return NULL;
|
||||
}
|
||||
|
||||
AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new AT_CellularContext(at, this, apn, stack);
|
||||
return new AT_CellularContext(at, this, apn);
|
||||
}
|
||||
|
||||
void AT_CellularDevice::delete_context(CellularContext *context)
|
||||
|
@ -381,7 +361,7 @@ void AT_CellularDevice::modem_debug_on(bool on)
|
|||
}
|
||||
}
|
||||
|
||||
nsapi_error_t AT_CellularDevice::init_module(FileHandle *fh)
|
||||
nsapi_error_t AT_CellularDevice::init_module()
|
||||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
|
|
@ -38,25 +38,10 @@ class AT_CellularContext;
|
|||
*/
|
||||
class AT_CellularDevice : public CellularDevice {
|
||||
public:
|
||||
AT_CellularDevice(events::EventQueue &queue);
|
||||
AT_CellularDevice(FileHandle *fh);
|
||||
virtual ~AT_CellularDevice();
|
||||
|
||||
ATHandler *_atHandlers;
|
||||
|
||||
ATHandler *get_at_handler(FileHandle *fh);
|
||||
|
||||
/** Releases the given at_handler. If last reference to at_hander then it's deleted.
|
||||
*
|
||||
* @param at_handler
|
||||
*/
|
||||
void release_at_handler(ATHandler *at_handler);
|
||||
|
||||
public: // CellularDevice
|
||||
|
||||
virtual events::EventQueue *get_queue() const;
|
||||
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, nsapi_ip_stack_t stack = DEFAULT_STACK);
|
||||
|
||||
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
|
||||
virtual void delete_context(CellularContext *context);
|
||||
|
||||
virtual CellularNetwork *open_network(FileHandle *fh = NULL);
|
||||
|
@ -85,19 +70,26 @@ public: // CellularDevice
|
|||
|
||||
virtual void modem_debug_on(bool on);
|
||||
|
||||
virtual nsapi_error_t init_module(FileHandle *fh);
|
||||
virtual nsapi_error_t init_module();
|
||||
|
||||
protected:
|
||||
ATHandler *_atHandlers;
|
||||
|
||||
ATHandler *get_at_handler(FileHandle *fh);
|
||||
|
||||
/** Releases the given at_handler. If last reference to at_hander then it's deleted.
|
||||
*
|
||||
* @param at_handler
|
||||
*/
|
||||
void release_at_handler(ATHandler *at_handler);
|
||||
|
||||
/** Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
|
||||
*
|
||||
* @param at ATHandler reference for communication with the modem.
|
||||
* @param apn access point to use with context
|
||||
* @param stack stack type to be used when finding suitable PDP context
|
||||
* @return new instance of class AT_CellularContext
|
||||
*
|
||||
*/
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
|
||||
/** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
|
||||
*
|
||||
|
@ -142,8 +134,6 @@ protected:
|
|||
AT_CellularPower *_power;
|
||||
AT_CellularInformation *_information;
|
||||
AT_CellularContext *_context_list;
|
||||
protected:
|
||||
events::EventQueue &_at_queue;
|
||||
int _default_timeout;
|
||||
bool _modem_debug_on;
|
||||
};
|
||||
|
|
|
@ -392,15 +392,6 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
|
|||
while (_at.info_elem('(')) {
|
||||
|
||||
op = operators.add_new();
|
||||
if (!op) {
|
||||
tr_warn("Could not allocate new operator");
|
||||
_at.resp_stop();
|
||||
_at.unlock();
|
||||
operators.delete_all();
|
||||
opsCount = 0;
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
||||
op->op_status = (operator_t::Status)_at.read_int();
|
||||
_at.read_string(op->op_long, sizeof(op->op_long));
|
||||
_at.read_string(op->op_short, sizeof(op->op_short));
|
||||
|
@ -551,13 +542,6 @@ nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_nam
|
|||
operator_names_t *names = NULL;
|
||||
while (_at.info_resp()) {
|
||||
names = op_names.add_new();
|
||||
if (!names) {
|
||||
tr_warn("Could not allocate new operator_names_t");
|
||||
_at.resp_stop();
|
||||
_at.unlock();
|
||||
op_names.delete_all();
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
_at.read_string(names->numeric, sizeof(names->numeric));
|
||||
_at.read_string(names->alpha, sizeof(names->alpha));
|
||||
}
|
||||
|
|
|
@ -294,11 +294,8 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
|
|||
// message 7-bit padded and it will be converted to hex so it will take twice as much space
|
||||
totalPDULength += (message_length - (message_length / 8)) * 2;
|
||||
|
||||
char *pdu = (char *)calloc(totalPDULength, sizeof(char));
|
||||
if (!pdu) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *pdu = new char[totalPDULength];
|
||||
memset(pdu, 0, totalPDULength);
|
||||
int x = 0;
|
||||
// See more how to create PDU from 3GPP specification 23040
|
||||
// first two define that we use service center number which is set with +CSCA
|
||||
|
@ -386,7 +383,7 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
|
|||
// we might need to send zero length sms
|
||||
if (message_length) {
|
||||
if (pack_7_bit_gsm_and_hex(message, message_length, pdu + x, paddingBits) == 0) {
|
||||
free(pdu);
|
||||
delete [] pdu;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -501,7 +498,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
|
|||
_at.cmd_start(ESC);
|
||||
_at.cmd_stop();
|
||||
_at.unlock();
|
||||
free(pdu_str);
|
||||
delete [] pdu_str;
|
||||
return msg_write_len;
|
||||
}
|
||||
|
||||
|
@ -511,7 +508,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
|
|||
_at.resp_start("+CMGS:");
|
||||
_at.resp_stop();
|
||||
}
|
||||
free(pdu_str);
|
||||
delete [] pdu_str;
|
||||
remaining_len -= concatenated_sms_length;
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
return _at.unlock_return_error();
|
||||
|
@ -667,7 +664,8 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char
|
|||
msg_len = _at.read_int();
|
||||
if (msg_len > 0) {
|
||||
pduSize = msg_len * 2 + 20; // *2 as it's hex encoded and +20 as service center number is not included in size given by CMGR
|
||||
pdu = (char *)calloc(pduSize, sizeof(char));
|
||||
pdu = new char[pduSize];
|
||||
memset(pdu, 0, pduSize);
|
||||
if (!pdu) {
|
||||
_at.resp_stop();
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
|
@ -678,12 +676,12 @@ nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char
|
|||
if (msg_len >= 0) { // we need to allow zero length messages
|
||||
index += msg_len;
|
||||
} else {
|
||||
free(pdu);
|
||||
delete [] pdu;
|
||||
_at.resp_stop();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
free(pdu);
|
||||
delete [] pdu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1062,7 +1060,8 @@ nsapi_error_t AT_CellularSMS::list_messages()
|
|||
_at.skip_param(2); // <stat>,[<alpha>]
|
||||
length = _at.read_int();
|
||||
length = length * 2 + 20; // *2 as it's hex encoded and +20 as service center number is not included in size given by CMGL
|
||||
pdu = (char *)calloc(length, sizeof(char));
|
||||
pdu = new char[length];
|
||||
memset(pdu, 0, length);
|
||||
if (!pdu) {
|
||||
delete info;
|
||||
_at.resp_stop();
|
||||
|
@ -1086,7 +1085,7 @@ nsapi_error_t AT_CellularSMS::list_messages()
|
|||
delete info;
|
||||
info = NULL;
|
||||
}
|
||||
free(pdu);
|
||||
delete [] pdu;
|
||||
pdu = NULL;
|
||||
}
|
||||
|
||||
|
@ -1194,7 +1193,7 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char *str, uint16_t len, c
|
|||
return 0;
|
||||
}
|
||||
// convert to 7bit gsm first
|
||||
char *gsm_str = (char *)malloc(len);
|
||||
char *gsm_str = new char[len];
|
||||
if (!gsm_str) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1236,7 +1235,7 @@ uint16_t AT_CellularSMS::pack_7_bit_gsm_and_hex(const char *str, uint16_t len, c
|
|||
i++;
|
||||
}
|
||||
|
||||
free(gsm_str);
|
||||
delete [] gsm_str;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
|
||||
namespace mbed {
|
||||
#ifdef CELLULAR_DEVICE
|
||||
MBED_WEAK NetworkInterface *CellularContext::get_default_instance()
|
||||
MBED_WEAK CellularBase *CellularContext::get_default_instance()
|
||||
{
|
||||
// Uses default APN, uname, password from mbed_app.json
|
||||
static CellularDevice *dev = CellularDevice::get_default_instance();
|
||||
return dev->create_context();
|
||||
}
|
||||
#else
|
||||
MBED_WEAK NetworkInterface *CellularContext::get_default_instance()
|
||||
MBED_WEAK CellularBase *CellularContext::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace mbed {
|
|||
#ifdef CELLULAR_DEVICE
|
||||
MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
||||
{
|
||||
static events::EventQueue event_queue(5 * EVENTS_EVENT_SIZE);
|
||||
static CELLULAR_DEVICE device(event_queue);
|
||||
static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||
static CELLULAR_DEVICE device(&serial);
|
||||
return &device;
|
||||
}
|
||||
#else
|
||||
|
@ -44,8 +44,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
|||
}
|
||||
#endif // CELLULAR_DEVICE
|
||||
|
||||
CellularDevice::CellularDevice() : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
|
||||
_info_ref_count(0), _fh(0), _error(0), _state_machine(0), _nw(0)
|
||||
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);
|
||||
|
@ -62,18 +62,14 @@ void CellularDevice::stop()
|
|||
_state_machine->stop();
|
||||
}
|
||||
|
||||
events::EventQueue *CellularDevice::get_queue() const
|
||||
events::EventQueue *CellularDevice::get_queue()
|
||||
{
|
||||
return NULL;
|
||||
return &_queue;
|
||||
}
|
||||
|
||||
CellularContext *CellularDevice::get_context_list() const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FileHandle &CellularDevice::get_filehandle() const
|
||||
CellularContext *CellularDevice::get_context_list() const
|
||||
{
|
||||
return *_fh;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CellularDevice::set_sim_pin(const char *sim_pin)
|
||||
|
@ -96,15 +92,6 @@ void CellularDevice::set_plmn(const char* plmn)
|
|||
}
|
||||
}
|
||||
|
||||
nsapi_error_t CellularDevice::start_dispatch() {
|
||||
_mutex.lock();
|
||||
create_state_machine();
|
||||
nsapi_error_t err = _state_machine->start_dispatch();
|
||||
_mutex.unlock();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
nsapi_error_t CellularDevice::set_device_ready()
|
||||
{
|
||||
return start_state_machine(CellularStateMachine::STATE_DEVICE_READY);
|
||||
|
@ -125,18 +112,23 @@ nsapi_error_t CellularDevice::attach_to_network()
|
|||
return start_state_machine(CellularStateMachine::STATE_ATTACHING_NETWORK);
|
||||
}
|
||||
|
||||
void CellularDevice::create_state_machine()
|
||||
nsapi_error_t CellularDevice::create_state_machine()
|
||||
{
|
||||
if (!_state_machine) {
|
||||
_state_machine = new CellularStateMachine(*this, *get_queue());
|
||||
_state_machine->set_cellular_callback(callback(this, &CellularDevice::cellular_callback));
|
||||
return _state_machine->start_dispatch();
|
||||
}
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t CellularDevice::start_state_machine(CellularStateMachine::CellularState target_state)
|
||||
{
|
||||
_mutex.lock();
|
||||
create_state_machine();
|
||||
nsapi_error_t err = create_state_machine();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
CellularStateMachine::CellularState current_state, targeted_state;
|
||||
|
||||
|
@ -150,7 +142,7 @@ nsapi_error_t CellularDevice::start_state_machine(CellularStateMachine::Cellular
|
|||
return NSAPI_ERROR_IN_PROGRESS;
|
||||
}
|
||||
|
||||
nsapi_error_t err = _state_machine->run_to_state(target_state);
|
||||
err = _state_machine->run_to_state(target_state);
|
||||
_mutex.unlock();
|
||||
|
||||
return err;
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
|
||||
#define RETRY_COUNT_DEFAULT 3
|
||||
|
||||
const int STM_STOPPED = -99;
|
||||
|
||||
namespace mbed {
|
||||
|
||||
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
|
||||
|
@ -72,6 +74,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event
|
|||
CellularStateMachine::~CellularStateMachine()
|
||||
{
|
||||
stop();
|
||||
_queue.break_dispatch();
|
||||
}
|
||||
|
||||
void CellularStateMachine::reset()
|
||||
|
@ -88,7 +91,6 @@ void CellularStateMachine::reset()
|
|||
void CellularStateMachine::stop()
|
||||
{
|
||||
_queue.cancel(_event_id);
|
||||
_queue.break_dispatch();
|
||||
|
||||
if (_queue_thread) {
|
||||
_queue_thread->terminate();
|
||||
|
@ -97,6 +99,7 @@ void CellularStateMachine::stop()
|
|||
}
|
||||
|
||||
reset();
|
||||
_event_id = STM_STOPPED;
|
||||
if (_power) {
|
||||
_cellularDevice.close_power();
|
||||
_power = NULL;
|
||||
|
@ -113,11 +116,6 @@ void CellularStateMachine::stop()
|
|||
}
|
||||
}
|
||||
|
||||
events::EventQueue *CellularStateMachine::get_queue() const
|
||||
{
|
||||
return &_queue;
|
||||
}
|
||||
|
||||
bool CellularStateMachine::power_on()
|
||||
{
|
||||
_cb_data.error = _power->on();
|
||||
|
@ -196,6 +194,7 @@ bool CellularStateMachine::is_registered()
|
|||
}
|
||||
}
|
||||
|
||||
_cb_data.status_data = status;
|
||||
return is_registered || _active_context;
|
||||
}
|
||||
|
||||
|
@ -439,6 +438,10 @@ void CellularStateMachine::state_registering()
|
|||
{
|
||||
_cellularDevice.set_timeout(TIMEOUT_NETWORK);
|
||||
if (is_registered()) {
|
||||
tr_info("Sending Registration changed from plmn");
|
||||
_cb_data.status_data = CellularNetwork::AlreadyRegistered;
|
||||
_cb_data.error = NSAPI_ERROR_OK;
|
||||
_event_status_cb(_current_event, (intptr_t)&_cb_data);
|
||||
// we are already registered, go to attach
|
||||
enter_to_state(STATE_ATTACHING_NETWORK);
|
||||
} else {
|
||||
|
@ -458,6 +461,11 @@ void CellularStateMachine::state_manual_registering_network()
|
|||
tr_info("state_manual_registering_network");
|
||||
if (!_plmn_network_found) {
|
||||
if (is_registered() && is_registered_to_plmn()) {
|
||||
// we have to send registration changed event as network thinks that we are not registered even we have active PDP context
|
||||
tr_info("Sending REgistration changed from plmn");
|
||||
_cb_data.status_data = CellularNetwork::AlreadyRegistered;
|
||||
_cb_data.error = NSAPI_ERROR_OK;
|
||||
_event_status_cb(_current_event, (intptr_t)&_cb_data);
|
||||
_plmn_network_found = true;
|
||||
enter_to_state(STATE_ATTACHING_NETWORK);
|
||||
} else {
|
||||
|
@ -596,7 +604,7 @@ void CellularStateMachine::event()
|
|||
break;
|
||||
}
|
||||
|
||||
if (_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) {
|
||||
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
|
||||
tr_info("Target state reached: %s", get_state_string(_target_state));
|
||||
_event_id = -1;
|
||||
return;
|
||||
|
@ -626,7 +634,7 @@ nsapi_error_t CellularStateMachine::start_dispatch()
|
|||
{
|
||||
MBED_ASSERT(!_queue_thread);
|
||||
|
||||
_queue_thread = new rtos::Thread(osPriorityNormal, 2048);
|
||||
_queue_thread = new rtos::Thread(osPriorityNormal, 2048, NULL, "stm_queue");
|
||||
if (_queue_thread->start(callback(&_queue, &events::EventQueue::dispatch_forever)) != osOK) {
|
||||
stop();
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
|
|
|
@ -114,11 +114,6 @@ private:
|
|||
*/
|
||||
const char *get_state_string(CellularState state) const;
|
||||
|
||||
/** Get event queue that can be chained to main event queue (or use start_dispatch)
|
||||
* @return event queue
|
||||
*/
|
||||
events::EventQueue *get_queue() const;
|
||||
|
||||
/** Get the current status of the state machine. Thread safe.
|
||||
*
|
||||
* @param current_state
|
||||
|
|
|
@ -28,7 +28,7 @@ using namespace events;
|
|||
|
||||
const uint16_t RESPONSE_TO_SEND_DELAY = 100; // response-to-send delay in milliseconds at bit-rate over 9600
|
||||
|
||||
GEMALTO_CINTERION::GEMALTO_CINTERION(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -41,14 +41,14 @@ AT_CellularNetwork *GEMALTO_CINTERION::open_network_impl(ATHandler &at)
|
|||
return new GEMALTO_CINTERION_CellularNetwork(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new GEMALTO_CINTERION_CellularContext(at, this, apn, stack);
|
||||
return new GEMALTO_CINTERION_CellularContext(at, this, apn);
|
||||
}
|
||||
|
||||
nsapi_error_t GEMALTO_CINTERION::init_module(FileHandle *fh)
|
||||
nsapi_error_t GEMALTO_CINTERION::init_module()
|
||||
{
|
||||
CellularInformation *information = open_information(fh);
|
||||
CellularInformation *information = open_information();
|
||||
if (!information) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
}
|
||||
|
|
|
@ -25,14 +25,14 @@ namespace mbed {
|
|||
class GEMALTO_CINTERION : public AT_CellularDevice {
|
||||
public:
|
||||
|
||||
GEMALTO_CINTERION(events::EventQueue &queue);
|
||||
GEMALTO_CINTERION(FileHandle *fh);
|
||||
virtual ~GEMALTO_CINTERION();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
public:
|
||||
virtual nsapi_error_t init_module(FileHandle *fh);
|
||||
virtual nsapi_error_t init_module();
|
||||
virtual uint16_t get_send_delay();
|
||||
};
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
namespace mbed {
|
||||
|
||||
GEMALTO_CINTERION_CellularContext::GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device,
|
||||
const char *apn, nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
const char *apn) : AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class GEMALTO_CINTERION_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
GEMALTO_CINTERION_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~GEMALTO_CINTERION_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -28,7 +28,7 @@ static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
|||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
|
||||
SARA4_PPP::SARA4_PPP(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace mbed {
|
|||
class SARA4_PPP : public AT_CellularDevice {
|
||||
|
||||
public:
|
||||
SARA4_PPP(events::EventQueue &queue);
|
||||
SARA4_PPP(FileHandle *fh);
|
||||
virtual ~SARA4_PPP();
|
||||
|
||||
public: // CellularDevice
|
||||
|
|
|
@ -36,7 +36,7 @@ static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
|||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
|
||||
QUECTEL_BC95::QUECTEL_BC95(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ AT_CellularSIM *QUECTEL_BC95::open_sim_impl(ATHandler &at)
|
|||
return new QUECTEL_BC95_CellularSIM(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new QUECTEL_BC95_CellularContext(at, this, apn, stack);
|
||||
return new QUECTEL_BC95_CellularContext(at, this, apn);
|
||||
}
|
||||
|
|
|
@ -24,14 +24,14 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_BC95 : public AT_CellularDevice {
|
||||
public:
|
||||
QUECTEL_BC95(events::EventQueue &queue);
|
||||
QUECTEL_BC95(FileHandle *fh);
|
||||
virtual ~QUECTEL_BC95();
|
||||
|
||||
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, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
|
||||
public: // NetworkInterface
|
||||
void handle_urc(FileHandle *fh);
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
QUECTEL_BC95_CellularContext::QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_BC95_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
QUECTEL_BC95_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~QUECTEL_BC95_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -37,7 +37,7 @@ static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
|||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
|
||||
QUECTEL_BG96::QUECTEL_BG96(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ AT_CellularPower *QUECTEL_BG96::open_power_impl(ATHandler &at)
|
|||
return new QUECTEL_BG96_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new QUECTEL_BG96_CellularContext(at, this, apn, stack);
|
||||
return new QUECTEL_BG96_CellularContext(at, this, apn);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_BG96 : public AT_CellularDevice {
|
||||
public:
|
||||
QUECTEL_BG96(events::EventQueue &queue);
|
||||
QUECTEL_BG96(FileHandle *fh);
|
||||
virtual ~QUECTEL_BG96();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
public:
|
||||
void handle_urc(FileHandle *fh);
|
||||
};
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
QUECTEL_BG96_CellularContext::QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_BG96_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
QUECTEL_BG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~QUECTEL_BG96_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -30,7 +30,7 @@ using namespace events;
|
|||
#define MAX_STARTUP_TRIALS 5
|
||||
#define MAX_RESET_TRIALS 5
|
||||
|
||||
QUECTEL_UG96::QUECTEL_UG96(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
QUECTEL_UG96::QUECTEL_UG96(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at)
|
|||
return new QUECTEL_UG96_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *QUECTEL_UG96::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new QUECTEL_UG96_CellularContext(at, this, apn, stack);
|
||||
return new QUECTEL_UG96_CellularContext(at, this, apn);
|
||||
}
|
||||
|
|
|
@ -32,13 +32,13 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_UG96 : public AT_CellularDevice {
|
||||
public:
|
||||
QUECTEL_UG96(events::EventQueue &queue);
|
||||
QUECTEL_UG96(FileHandle *fh);
|
||||
virtual ~QUECTEL_UG96();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
|
||||
public: // NetworkInterface
|
||||
void handle_urc(FileHandle *fh);
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
QUECTEL_UG96_CellularContext::QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class QUECTEL_UG96_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
QUECTEL_UG96_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~QUECTEL_UG96_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -29,7 +29,7 @@ static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
|||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
|
||||
TELIT_HE910::TELIT_HE910(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
TELIT_HE910::TELIT_HE910(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at)
|
|||
return new TELIT_HE910_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *TELIT_HE910::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *TELIT_HE910::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new TELIT_HE910_CellularContext(at, this, apn, stack);
|
||||
return new TELIT_HE910_CellularContext(at, this, apn);
|
||||
}
|
||||
|
||||
uint16_t TELIT_HE910::get_send_delay() const
|
||||
|
|
|
@ -27,13 +27,13 @@ namespace mbed {
|
|||
|
||||
class TELIT_HE910 : public AT_CellularDevice {
|
||||
public:
|
||||
TELIT_HE910(events::EventQueue &queue);
|
||||
TELIT_HE910(FileHandle *fh);
|
||||
virtual ~TELIT_HE910();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
|
||||
public: // from CellularDevice
|
||||
virtual uint16_t get_send_delay() const;
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
TELIT_HE910_CellularContext::TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
TELIT_HE910_CellularContext::TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class TELIT_HE910_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
TELIT_HE910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~TELIT_HE910_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -23,14 +23,7 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
#ifdef TARGET_UBLOX_C030_R410M
|
||||
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
||||
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
||||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
#endif
|
||||
|
||||
UBLOX_AT::UBLOX_AT(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
#ifdef TARGET_UBLOX_C030_R410M
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
|
@ -51,7 +44,7 @@ AT_CellularPower *UBLOX_AT::open_power_impl(ATHandler &at)
|
|||
return new UBLOX_AT_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *UBLOX_AT::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new UBLOX_AT_CellularContext(at, this, apn, stack);
|
||||
return new UBLOX_AT_CellularContext(at, this, apn);
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ namespace mbed {
|
|||
|
||||
class UBLOX_AT : public AT_CellularDevice {
|
||||
public:
|
||||
UBLOX_AT(events::EventQueue &queue);
|
||||
UBLOX_AT(FileHandle *fh);
|
||||
virtual ~UBLOX_AT();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
public: // NetworkInterface
|
||||
void handle_urc(FileHandle *fh);
|
||||
};
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
UBLOX_AT_CellularContext::UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
// The authentication to use
|
||||
_auth = NSAPI_SECURITY_UNKNOWN;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class UBLOX_AT_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
UBLOX_AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~UBLOX_AT_CellularContext();
|
||||
|
||||
virtual void do_connect();
|
||||
|
|
|
@ -23,14 +23,7 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
#ifdef TARGET_UBLOX_C027
|
||||
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
||||
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
||||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
#endif
|
||||
|
||||
UBLOX_PPP::UBLOX_PPP(EventQueue &queue) : AT_CellularDevice(queue)
|
||||
UBLOX_PPP::UBLOX_PPP(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
#ifdef TARGET_UBLOX_C027
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
|
@ -51,7 +44,7 @@ AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at)
|
|||
return new UBLOX_PPP_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *UBLOX_PPP::create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack)
|
||||
AT_CellularContext *UBLOX_PPP::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new UBLOX_PPP_CellularContext(at, this, apn, stack);
|
||||
return new UBLOX_PPP_CellularContext(at, this, apn);
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ namespace mbed {
|
|||
|
||||
class UBLOX_PPP : public AT_CellularDevice {
|
||||
public:
|
||||
UBLOX_PPP(events::EventQueue &queue);
|
||||
UBLOX_PPP(FileHandle *fh);
|
||||
virtual ~UBLOX_PPP();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, nsapi_ip_stack_t stack);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
UBLOX_PPP_CellularContext::UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn,
|
||||
nsapi_ip_stack_t stack) : AT_CellularContext(at, device, apn, stack)
|
||||
UBLOX_PPP_CellularContext::UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace mbed {
|
|||
|
||||
class UBLOX_PPP_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, nsapi_ip_stack_t stack);
|
||||
UBLOX_PPP_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~UBLOX_PPP_CellularContext();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -66,9 +66,7 @@ void OnboardCellularInterface::modem_power_down()
|
|||
#ifdef ONBOARD_CELLULAR_INTERFACE_AVAILABLE
|
||||
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
|
||||
{
|
||||
static OnboardCellularInterface cellular;
|
||||
|
||||
return &cellular;
|
||||
return mbed::CellularContext::get_default_instance();
|
||||
}
|
||||
#else
|
||||
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#ifndef ONBOARD_CELLULAR_INTERFACE_
|
||||
#define ONBOARD_CELLULAR_INTERFACE_
|
||||
|
||||
#include "EasyCellularConnection.h"
|
||||
#include "CellularContext.h"
|
||||
#ifdef CELLULAR_DEVICE
|
||||
typedef mbed::EasyCellularConnection OnboardCellularInterface;
|
||||
typedef mbed::CellularContext OnboardCellularInterface;
|
||||
#define ONBOARD_CELLULAR_INTERFACE_AVAILABLE
|
||||
#elif MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE
|
||||
|
||||
|
|
Loading…
Reference in New Issue