Cellular: Remove support for multiple ATHandlers

Major changes:
- Dependency to FileHandle removed from base classes
- AT_CellularDevice owns the default FileHandle and shares it with AT -classes
- Hang-up -detection moved as CellularContext::configure_hup(). Cannot be configured via CellularDevice any more.

Result on NRF52840_DK + BG96:
GCC:
Total Static RAM memory (data + bss): 29360(+296) bytes
Total Flash memory (text + data): 130660(-832) bytes

ARM:
Total Static RAM memory (data + bss): 261554(+8) bytes
Total Flash memory (text + data): 127573(-1193) bytes

IAR:
Total Static RAM memory (data + bss): 25479(+296) bytes
Total Flash memory (text + data): 102418(-527) bytes

RAM increase is because now ATHandler is no longer created with new -operator but is now member of AT_CellularDevice,
so image tool is able to count it. Actually total RAM consumption has decreased due to removed variables.
pull/12305/head
Kimmo Vaisanen 2020-01-15 11:11:44 +02:00
parent ee1d998d43
commit bd0f939277
43 changed files with 314 additions and 845 deletions

View File

@ -44,7 +44,6 @@ protected:
ATHandler_stub::nsapi_error_value = 0; ATHandler_stub::nsapi_error_value = 0;
ATHandler_stub::nsapi_error_ok_counter = 0; ATHandler_stub::nsapi_error_ok_counter = 0;
ATHandler_stub::int_value = -1; ATHandler_stub::int_value = -1;
ATHandler_stub::ref_count = 0;
ATHandler_stub::timeout = 0; ATHandler_stub::timeout = 0;
ATHandler_stub::default_timeout = 0; ATHandler_stub::default_timeout = 0;
ATHandler_stub::debug_on = 0; ATHandler_stub::debug_on = 0;
@ -514,21 +513,6 @@ TEST_F(TestAT_CellularContext, get_apn_backoff_timer)
ASSERT_EQ(time, 55); ASSERT_EQ(time, 55);
} }
TEST_F(TestAT_CellularContext, set_file_handle)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularDevice dev(&fh1);
AT_CellularContext ctx(at, &dev);
ctx.set_file_handle(&fh1);
BufferedSerial ss(NC, NC);
ctx.set_file_handle(&ss, PTC0, true);
ctx.enable_hup(true);
}
TEST_F(TestAT_CellularContext, connect_disconnect_sync) TEST_F(TestAT_CellularContext, connect_disconnect_sync)
{ {
EventQueue que; EventQueue que;

View File

@ -28,20 +28,14 @@ protected:
void SetUp() void SetUp()
{ {
EventQueue que;
FileHandle_stub fh1;
filehandle_stub_table = NULL; filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
ATHandler at(&fh1, que, 0, ",");
ATHandler_stub::handler = &at;
ATHandler_stub::read_string_index = kRead_string_table_size; ATHandler_stub::read_string_index = kRead_string_table_size;
} }
void TearDown() void TearDown()
{ {
ATHandler_stub::handler = NULL;
} }
}; };
@ -55,33 +49,15 @@ TEST_F(TestAT_CellularDevice, Create)
EXPECT_TRUE(dev2 != NULL); EXPECT_TRUE(dev2 != NULL);
delete dev2; delete dev2;
ATHandler *at = dev.get_at_handler(&fh1); ATHandler *at = dev.get_at_handler();
dev.release_at_handler(at);
dev.release_at_handler(at);
} }
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
{ {
FileHandle_stub fh1; FileHandle_stub fh1;
FileHandle_stub fh2; AT_CellularDevice dev(&fh1);
FileHandle_stub fh3; ATHandler *at = dev.get_at_handler();
AT_CellularDevice dev(&fh1); // AT fh1 ref count 1 EXPECT_TRUE(at->get_file_handle() == &fh1);
EXPECT_TRUE(dev.open_network(&fh1)); // AT fh1 ref count 2
dev.modem_debug_on(true);
EXPECT_TRUE(dev.open_sms(&fh2));
EXPECT_TRUE(dev.open_information(&fh3));
ATHandler_stub::fh_value = &fh1;
ATHandler_stub::fh_value = NULL;
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
delete dev2; // AT fh1 2 refs deleted -> ref count 3
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
} }
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
@ -89,12 +65,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
FileHandle_stub fh1; FileHandle_stub fh1;
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
CellularNetwork *nw = dev.open_network(NULL); CellularNetwork *nw = dev.open_network();
CellularNetwork *nw1 = dev.open_network(&fh1);
EXPECT_TRUE(nw); EXPECT_TRUE(nw);
EXPECT_TRUE(nw1);
EXPECT_TRUE(nw1 == nw);
} }
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
@ -102,12 +74,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
FileHandle_stub fh1; FileHandle_stub fh1;
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
CellularSMS *sms = dev.open_sms(NULL); CellularSMS *sms = dev.open_sms();
CellularSMS *sms1 = dev.open_sms(&fh1);
EXPECT_TRUE(sms); EXPECT_TRUE(sms);
EXPECT_TRUE(sms1);
EXPECT_TRUE(sms1 == sms);
} }
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
@ -115,12 +83,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
FileHandle_stub fh1; FileHandle_stub fh1;
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
CellularInformation *info = dev.open_information(NULL); CellularInformation *info = dev.open_information();
CellularInformation *info1 = dev.open_information(&fh1);
EXPECT_TRUE(info); EXPECT_TRUE(info);
EXPECT_TRUE(info1);
EXPECT_TRUE(info1 == info);
} }
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
@ -128,9 +92,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
FileHandle_stub fh1; FileHandle_stub fh1;
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
EXPECT_TRUE(dev.open_network(&fh1)); EXPECT_TRUE(dev.open_network());
EXPECT_EQ(ATHandler_stub::ref_count, 1);
dev.close_network(); dev.close_network();
} }
@ -139,9 +101,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
FileHandle_stub fh1; FileHandle_stub fh1;
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(dev.open_sms());
EXPECT_EQ(ATHandler_stub::ref_count, 1);
dev.close_sms(); dev.close_sms();
} }
@ -151,14 +111,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
AT_CellularDevice dev(&fh1); AT_CellularDevice dev(&fh1);
ATHandler_stub::int_value = 0; ATHandler_stub::int_value = 0;
EXPECT_TRUE(dev.open_information(&fh1)); EXPECT_TRUE(dev.open_information());
ATHandler_stub::fh_value = NULL; ATHandler_stub::fh_value = NULL;
dev.close_information(); dev.close_information();
ATHandler_stub::fh_value = &fh1; ATHandler_stub::fh_value = &fh1;
EXPECT_TRUE(dev.open_information(&fh1)); EXPECT_TRUE(dev.open_information());
dev.close_information(); dev.close_information();
@ -176,8 +136,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
EXPECT_TRUE(ATHandler_stub::timeout == 5000); EXPECT_TRUE(ATHandler_stub::timeout == 5000);
EXPECT_TRUE(ATHandler_stub::default_timeout == true); EXPECT_TRUE(ATHandler_stub::default_timeout == true);
EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(dev.open_sms());
EXPECT_EQ(ATHandler_stub::ref_count, 1);
dev.set_timeout(5000); dev.set_timeout(5000);
EXPECT_TRUE(ATHandler_stub::timeout == 5000); EXPECT_TRUE(ATHandler_stub::timeout == 5000);
@ -195,8 +154,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
dev.modem_debug_on(true); dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == true); EXPECT_TRUE(ATHandler_stub::debug_on == true);
EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(dev.open_sms());
EXPECT_EQ(ATHandler_stub::ref_count, 1);
dev.modem_debug_on(true); dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == true); EXPECT_TRUE(ATHandler_stub::debug_on == true);
@ -263,7 +221,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
AT_CellularDevice *dev = new AT_CellularDevice(&fh1); AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
ATHandler *at = dev->get_at_handler(); ATHandler *at = dev->get_at_handler();
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
CellularContext *ctx = dev->create_context(NULL); CellularContext *ctx = dev->create_context(NULL);
delete dev; delete dev;
@ -271,8 +228,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
dev = new AT_CellularDevice(&fh1); dev = new AT_CellularDevice(&fh1);
at = dev->get_at_handler(); at = dev->get_at_handler();
ctx = dev->create_context(NULL); ctx = dev->create_context(NULL);
CellularContext *ctx1 = dev->create_context(&fh1); CellularContext *ctx1 = dev->create_context();
CellularContext *ctx2 = dev->create_context(&fh1); CellularContext *ctx2 = dev->create_context();
EXPECT_TRUE(ctx); EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1); EXPECT_TRUE(ctx1);
@ -288,9 +245,9 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
dev->delete_context(ctx2); dev->delete_context(ctx2);
ctx = dev->create_context(NULL); ctx = dev->create_context(NULL);
ctx1 = dev->create_context(&fh1); ctx1 = dev->create_context();
ctx2 = dev->create_context(&fh1); ctx2 = dev->create_context();
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
EXPECT_TRUE(ctx); EXPECT_TRUE(ctx);
EXPECT_TRUE(ctx1); EXPECT_TRUE(ctx1);
EXPECT_TRUE(ctx1 != ctx); EXPECT_TRUE(ctx1 != ctx);

View File

@ -86,43 +86,6 @@ TEST_F(TestATHandler, test_ATHandler_get_file_handle)
EXPECT_EQ(&fh1, at.get_file_handle()); EXPECT_EQ(&fh1, at.get_file_handle());
} }
TEST_F(TestATHandler, test_ATHandler_set_file_handle)
{
EventQueue que;
FileHandle_stub fh1, fh2;
ATHandler at(&fh1, que, 0, ",");
at.set_file_handle(&fh2);
}
TEST_F(TestATHandler, test_ATHandler_list)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(false);
ATHandler *at1 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(true);
EXPECT_TRUE(ATHandler::get_instance(NULL, que, 0, ",", 0, 0) == NULL);
ATHandler *at2 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
ATHandler::set_at_timeout_list(2000, true);
ATHandler::set_debug_list(false);
EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);
ATHandler::set_at_timeout_list(1000, false);
ATHandler::set_debug_list(false);
}
TEST_F(TestATHandler, test_ATHandler_lock) TEST_F(TestATHandler, test_ATHandler_lock)
{ {
EventQueue que; EventQueue que;

View File

@ -165,9 +165,9 @@ public:
} }
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual void set_file_handle(BufferedSerial *serial, PinName dcd_pin = NC, bool active_high = false) virtual nsapi_error_t configure_hup(PinName dcd_pin = NC, bool active_high = false)
{ {
return NSAPI_ERROR_OK;
} }
#endif #endif
ControlPlane_netif *get_cp_netif() ControlPlane_netif *get_cp_netif()

View File

@ -28,12 +28,9 @@ using namespace events;
const int DEFAULT_AT_TIMEOUT = 1000; const int DEFAULT_AT_TIMEOUT = 1000;
const uint8_t MAX_RESP_LENGTH = 7; const uint8_t MAX_RESP_LENGTH = 7;
mbed::ATHandler *ATHandler_stub::handler = NULL;
nsapi_error_t ATHandler_stub::nsapi_error_value = 0; nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0; uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
int ATHandler_stub::int_value = -1; int ATHandler_stub::int_value = -1;
int ATHandler_stub::ref_count = 0;
int ATHandler_stub::timeout = 0; int ATHandler_stub::timeout = 0;
bool ATHandler_stub::default_timeout = 0; bool ATHandler_stub::default_timeout = 0;
bool ATHandler_stub::debug_on = 0; bool ATHandler_stub::debug_on = 0;
@ -84,7 +81,6 @@ void ATHandler_stub::debug_call_count_clear()
} }
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) : ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT #if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
_oobCv(_fileHandleMutex), _oobCv(_fileHandleMutex),
#endif #endif
@ -111,41 +107,17 @@ bool ATHandler::get_debug() const
return ATHandler_stub::debug_on; return ATHandler_stub::debug_on;
} }
void ATHandler::set_debug_list(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}
ATHandler::~ATHandler() ATHandler::~ATHandler()
{ {
ATHandler_stub::urc_handlers.clear(); ATHandler_stub::urc_handlers.clear();
} }
void ATHandler::inc_ref_count()
{
ATHandler_stub::ref_count++;
}
void ATHandler::dec_ref_count()
{
ATHandler_stub::ref_count--;
}
int ATHandler::get_ref_count()
{
return ATHandler_stub::ref_count;
}
FileHandle *ATHandler::get_file_handle() FileHandle *ATHandler::get_file_handle()
{ {
ATHandler_stub::fh_value = (FileHandle_stub *)_fileHandle; ATHandler_stub::fh_value = (FileHandle_stub *)_fileHandle;
return _fileHandle; return _fileHandle;
} }
void ATHandler::set_file_handle(FileHandle *fh)
{
}
bool ATHandler::find_urc_handler(const char *prefix) bool ATHandler::find_urc_handler(const char *prefix)
{ {
return ATHandler_stub::bool_value; return ATHandler_stub::bool_value;
@ -393,27 +365,6 @@ nsapi_error_t ATHandler::at_cmd_discard(const char *cmd, const char *cmd_chr,
return ATHandler_stub::nsapi_error_value; return ATHandler_stub::nsapi_error_value;
} }
ATHandler *ATHandler::get_instance(FileHandle *fileHandle, events::EventQueue &queue, uint32_t timeout,
const char *delimiter, uint16_t send_delay, bool debug_on)
{
ATHandler_stub::ref_count++;
int a = ATHandler_stub::ref_count;
a = 0;
return ATHandler_stub::handler;
}
nsapi_error_t ATHandler::close()
{
ATHandler_stub::ref_count--;
return NSAPI_ERROR_OK;
}
void ATHandler::set_at_timeout_list(uint32_t timeout_milliseconds, bool default_timeout)
{
ATHandler_stub::timeout = timeout_milliseconds;
ATHandler_stub::default_timeout = default_timeout;
}
void ATHandler::set_send_delay(uint16_t send_delay) void ATHandler::set_send_delay(uint16_t send_delay)
{ {
} }

View File

@ -34,11 +34,9 @@ static const int kATHandler_urc_table_max_size = 10;
static const int kATHandler_urc_string_max_size = 16; static const int kATHandler_urc_string_max_size = 16;
namespace ATHandler_stub { namespace ATHandler_stub {
extern mbed::ATHandler *handler;
extern nsapi_error_t nsapi_error_value; extern nsapi_error_t nsapi_error_value;
extern uint8_t nsapi_error_ok_counter; extern uint8_t nsapi_error_ok_counter;
extern int int_value; extern int int_value;
extern int ref_count;
extern int timeout; extern int timeout;
extern bool default_timeout; extern bool default_timeout;
extern bool debug_on; extern bool debug_on;

View File

@ -21,7 +21,7 @@ using namespace mbed;
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
_at(at), _is_connected(false), _at(at), _is_connected(false),
_current_op(OP_INVALID), _fh(0), _cp_req(cp_req) _current_op(OP_INVALID), _dcd_pin(NC), _active_high(false), _cp_req(cp_req)
{ {
_stack = NULL; _stack = NULL;
_pdp_type = DEFAULT_PDP_TYPE; _pdp_type = DEFAULT_PDP_TYPE;
@ -51,17 +51,15 @@ AT_CellularContext::~AT_CellularContext()
{ {
} }
void AT_CellularContext::set_file_handle(BufferedSerial *serial, PinName dcd_pin, bool active_high) nsapi_error_t AT_CellularContext::configure_hup(PinName dcd_pin, bool active_high)
{ {
return NSAPI_ERROR_OK;
} }
void AT_CellularContext::enable_hup(bool enable) void AT_CellularContext::enable_hup(bool enable)
{ {
} }
void AT_CellularContext::set_file_handle(FileHandle *fh)
{
}
nsapi_error_t AT_CellularContext::connect() nsapi_error_t AT_CellularContext::connect()
{ {
@ -311,8 +309,3 @@ char *AT_CellularContext::get_interface_name(char *interface_name)
{ {
return NULL; return NULL;
} }
ATHandler &AT_CellularContext::get_at_handler()
{
return _at;
}

View File

@ -33,7 +33,9 @@ bool AT_CellularDevice_stub::pin_needed = false;
bool AT_CellularDevice_stub::supported_bool = false; bool AT_CellularDevice_stub::supported_bool = false;
int AT_CellularDevice_stub::max_sock_value = 1; int AT_CellularDevice_stub::max_sock_value = 1;
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), AT_CellularDevice::AT_CellularDevice(FileHandle *fh) :
CellularDevice(),
_at(fh, _queue, get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), "\r"),
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
_sms(0), _sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS #endif // MBED_CONF_CELLULAR_USE_SMS
@ -47,31 +49,12 @@ AT_CellularDevice::~AT_CellularDevice()
close_network(); close_network();
} }
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
{
return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), _modem_debug_on);
}
ATHandler *AT_CellularDevice::get_at_handler() ATHandler *AT_CellularDevice::get_at_handler()
{ {
return get_at_handler(NULL); return &_at;
} }
nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) CellularContext *create_context(const char *apn)
{
if (at_handler) {
return at_handler->close();
} else {
return NSAPI_ERROR_PARAMETER;
}
}
CellularContext *AT_CellularDevice::create_context(BufferedSerial *serial, const char *const apn, PinName dcd_pin,
bool active_high, bool cp_req, bool nonip_req)
{
}
CellularContext *create_context(FileHandle *fh, const char *apn)
{ {
} }
@ -79,21 +62,16 @@ void delete_context(CellularContext *context)
{ {
} }
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) CellularNetwork *AT_CellularDevice::open_network()
{ {
if (_network) { if (_network) {
return _network; return _network;
} }
_network = new AT_CellularNetwork(*ATHandler::get_instance(fh, _network = new AT_CellularNetwork(_at, *this);
_queue,
_default_timeout,
"\r",
get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY),
_modem_debug_on), *this);
return _network; return _network;
} }
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) CellularSMS *AT_CellularDevice::open_sms()
{ {
return NULL; return NULL;
} }
@ -109,7 +87,7 @@ AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
#endif // MBED_CONF_CELLULAR_USE_SMS #endif // MBED_CONF_CELLULAR_USE_SMS
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) CellularInformation *AT_CellularDevice::open_information()
{ {
return NULL; return NULL;
} }
@ -117,10 +95,8 @@ CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
void AT_CellularDevice::close_network() void AT_CellularDevice::close_network()
{ {
if (_network) { if (_network) {
ATHandler *atHandler = &_network->get_at_handler();
delete _network; delete _network;
_network = NULL; _network = NULL;
release_at_handler(atHandler);
} }
} }
@ -133,7 +109,7 @@ CellularContext *AT_CellularDevice::get_context_list() const
return NULL; return NULL;
} }
CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req) CellularContext *AT_CellularDevice::create_context(const char *apn, bool cp_req, bool nonip_req)
{ {
return NULL; return NULL;
} }

View File

@ -57,8 +57,3 @@ nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size)
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
ATHandler &AT_CellularInformation::get_at_handler()
{
return _at;
}

View File

@ -171,8 +171,3 @@ nsapi_error_t AT_CellularNetwork::clear()
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
ATHandler &AT_CellularNetwork::get_at_handler()
{
return _at;
}

View File

@ -188,9 +188,3 @@ bool AT_CellularSMS::create_time(const char *time_string, time_t *time)
{ {
return 0; return 0;
} }
ATHandler &AT_CellularSMS::get_at_handler()
{
return _at;
}

View File

@ -22,7 +22,7 @@ namespace mbed {
CellularContext::CellularContext() : _next(0), _stack(0), _pdp_type(DEFAULT_PDP_TYPE), CellularContext::CellularContext() : _next(0), _stack(0), _pdp_type(DEFAULT_PDP_TYPE),
_authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(0), _authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(0),
_cid(-1), _new_context_set(false), _is_context_active(false), _is_context_activated(false), _cid(-1), _new_context_set(false), _is_context_active(false), _is_context_activated(false),
_apn(0), _uname(0), _pwd(0), _dcd_pin(NC), _active_high(false), _cp_netif(0), _retry_array_length(0), _apn(0), _uname(0), _pwd(0), _cp_netif(0), _retry_array_length(0),
_retry_count(0), _device(0), _nw(0), _is_blocking(true) _retry_count(0), _device(0), _nw(0), _is_blocking(true)
{ {
memset(_retry_timeout_array, 0, CELLULAR_RETRY_ARRAY_SIZE); memset(_retry_timeout_array, 0, CELLULAR_RETRY_ARRAY_SIZE);

View File

@ -37,11 +37,12 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
} }
} }
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), CellularDevice::CellularDevice() :
_network_ref_count(0),
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count(0), _sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS #endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _info_ref_count(0), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
_nw(0), _status_cb(0) _nw(0), _status_cb(0)
{ {
} }

View File

@ -39,18 +39,15 @@ public:
} }
} }
void set_file_handle(BufferedSerial *serial, PinName dcd_pin, bool active_high) nsapi_error_t configure_hup(PinName dcd_pin, bool active_high)
{ {
return NSAPI_ERROR_OK;
}; };
void enable_hup(bool enable) void enable_hup(bool enable)
{ {
}; };
void set_file_handle(FileHandle *fh)
{
};
nsapi_error_t connect() nsapi_error_t connect()
{ {
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;

View File

@ -53,19 +53,8 @@ public:
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
virtual CellularContext *create_context(BufferedSerial *serial, const char *const apn, PinName dcd_pin,
bool active_high, bool cp_req = false, bool nonip_req = false)
{
if (_context_list) {
return _context_list;
}
EventQueue que;
ATHandler at(serial, que, 0, ",");
_context_list = new AT_CellularContext(at, this);
return _context_list;
}
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false) virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false)
{ {
if (_context_list) { if (_context_list) {
return _context_list; return _context_list;
@ -82,7 +71,7 @@ public:
delete _context_list; delete _context_list;
} }
virtual CellularNetwork *open_network(FileHandle *fh = NULL) virtual CellularNetwork *open_network()
{ {
if (_network) { if (_network) {
return _network; return _network;
@ -94,12 +83,12 @@ public:
return _network; return _network;
} }
virtual CellularSMS *open_sms(FileHandle *fh = NULL) virtual CellularSMS *open_sms()
{ {
return NULL; return NULL;
} }
virtual CellularInformation *open_information(FileHandle *fh = NULL) virtual CellularInformation *open_information()
{ {
return NULL; return NULL;
} }

View File

@ -88,23 +88,23 @@ nsapi_error_t STModCellular::soft_power_on()
} }
// wait for RDY // wait for RDY
_at->lock(); _at.lock();
_at->set_at_timeout(5000); _at.set_at_timeout(5000);
_at->set_stop_tag("RDY"); _at.set_stop_tag("RDY");
bool rdy = _at->consume_to_stop_tag(); bool rdy = _at.consume_to_stop_tag();
(void)rdy; (void)rdy;
/* Modem may send more bytes are RDY flag */ /* Modem may send more bytes are RDY flag */
_at->flush(); _at.flush();
/* Turn OFF ECHO before anything else */ /* Turn OFF ECHO before anything else */
_at->set_stop_tag(mbed::OK); _at.set_stop_tag(mbed::OK);
_at->cmd_start("ATE0"); _at.cmd_start("ATE0");
_at->cmd_stop(); _at.cmd_stop();
_at->consume_to_stop_tag(); _at.consume_to_stop_tag();
_at->restore_at_timeout(); _at.restore_at_timeout();
_at->unlock(); _at.unlock();
tr_info("Modem %sready to receive AT commands", rdy ? "" : "NOT "); tr_info("Modem %sready to receive AT commands", rdy ? "" : "NOT ");
@ -113,17 +113,17 @@ nsapi_error_t STModCellular::soft_power_on()
pin_mode(MBED_CONF_STMOD_CELLULAR_CTS, PullDown); pin_mode(MBED_CONF_STMOD_CELLULAR_CTS, PullDown);
_at->lock(); _at.lock();
// enable CTS/RTS flowcontrol // enable CTS/RTS flowcontrol
_at->set_stop_tag(mbed::OK); _at.set_stop_tag(mbed::OK);
_at->set_at_timeout(400); _at.set_at_timeout(400);
_at->cmd_start("AT+IFC="); _at.cmd_start("AT+IFC=");
_at->write_int(2); _at.write_int(2);
_at->write_int(2); _at.write_int(2);
_at->cmd_stop_read_resp(); _at.cmd_stop_read_resp();
err = _at->get_last_error(); err = _at.get_last_error();
_at->restore_at_timeout(); _at.restore_at_timeout();
_at->unlock(); _at.unlock();
if (err == NSAPI_ERROR_OK) { if (err == NSAPI_ERROR_OK) {
tr_debug("Flow control turned ON"); tr_debug("Flow control turned ON");
@ -135,11 +135,11 @@ nsapi_error_t STModCellular::soft_power_on()
rtos::ThisThread::sleep_for(500); rtos::ThisThread::sleep_for(500);
#if MBED_CONF_CELLULAR_DEBUG_AT #if MBED_CONF_CELLULAR_DEBUG_AT
_at->lock(); _at.lock();
/* Verify Flow Control settings */ /* Verify Flow Control settings */
_at->cmd_start("AT+IFC?"); _at.cmd_start("AT+IFC?");
_at->cmd_stop_read_resp(); _at.cmd_stop_read_resp();
_at->unlock(); _at.unlock();
#endif // MBED_CONF_CELLULAR_DEBUG_AT #endif // MBED_CONF_CELLULAR_DEBUG_AT
return err; return err;
@ -147,8 +147,8 @@ nsapi_error_t STModCellular::soft_power_on()
nsapi_error_t STModCellular::soft_power_off() nsapi_error_t STModCellular::soft_power_off()
{ {
_at->cmd_start("AT+QPOWD"); _at.cmd_start("AT+QPOWD");
_at->cmd_stop(); _at.cmd_stop();
rtos::ThisThread::sleep_for(1000); rtos::ThisThread::sleep_for(1000);
// should wait for POWERED DOWN with a time out up to 65 second according to the manual. // should wait for POWERED DOWN with a time out up to 65 second according to the manual.
// we cannot afford such a long wait though. // we cannot afford such a long wait though.

View File

@ -86,32 +86,6 @@ public:
*/ */
FileHandle *get_file_handle(); FileHandle *get_file_handle();
/** Get a new ATHandler instance, and update the linked list. Once the use of the ATHandler
* has finished, call to close() has to be made
*
* @param fileHandle filehandle used for reading AT responses and writing AT commands.
* If there is already an ATHandler with the same fileHandle pointer,
* then a pointer to that ATHandler instance will be returned with
* that ATHandler's queue, timeout, delimiter, send_delay and debug_on
* values
* @param queue Event queue used to transfer sigio events to this thread
* @param timeout Timeout when reading for AT response
* @param delimiter delimiter used when parsing at responses, "\r" should be used as output_delimiter
* @param send_delay the minimum delay in ms between the end of last response and the beginning of a new command
* @param debug_on Set true to enable debug traces
* @return NULL, if fileHandle is not set, or a pointer to an existing ATHandler, if the fileHandle is
* already in use. Otherwise a pointer to a new ATHandler instance is returned
*/
static ATHandler *get_instance(FileHandle *fileHandle, events::EventQueue &queue, uint32_t timeout,
const char *delimiter, uint16_t send_delay, bool debug_on);
/** Close and delete the current ATHandler instance, if the reference count to it is 0.
* Close() can be only called, if the ATHandler was opened with get_instance()
*
* @return NSAPI_ERROR_OK on success, NSAPI_ERROR_PARAMETER on failure
*/
nsapi_error_t close();
/** Locks the mutex for file handle if AT_HANDLER_MUTEX is defined. /** Locks the mutex for file handle if AT_HANDLER_MUTEX is defined.
*/ */
void lock(); void lock();
@ -133,8 +107,6 @@ public:
*/ */
void set_urc_handler(const char *prefix, Callback<void()> callback); void set_urc_handler(const char *prefix, Callback<void()> callback);
ATHandler *_nextATHandler; // linked list
/** returns the last error while parsing AT responses. /** returns the last error while parsing AT responses.
* *
* @return last error * @return last error
@ -154,13 +126,6 @@ public:
*/ */
void set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout = false); void set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout = false);
/** Set timeout in milliseconds for all ATHandlers in the _atHandlers list
*
* @param timeout_milliseconds Timeout in milliseconds
* @param default_timeout Store as default timeout
*/
static void set_at_timeout_list(uint32_t timeout_milliseconds, bool default_timeout = false);
/** Restore timeout to previous timeout. Handy if there is a need to change timeout temporarily. /** Restore timeout to previous timeout. Handy if there is a need to change timeout temporarily.
*/ */
void restore_at_timeout(); void restore_at_timeout();
@ -178,12 +143,6 @@ public:
*/ */
void process_oob(); void process_oob();
/** Set file handle, which is used for reading AT responses and writing AT commands
*
* @param fh file handle used for reading AT responses and writing AT commands
*/
void set_file_handle(FileHandle *fh);
/** Set is file handle usable. Some situations like after going to data mode, file handle is not usable anymore. /** Set is file handle usable. Some situations like after going to data mode, file handle is not usable anymore.
* Any items in queue are not to be processed. * Any items in queue are not to be processed.
* *
@ -448,12 +407,6 @@ public: // just for debugging
*/ */
bool get_debug() const; bool get_debug() const;
/** Set debug_on for all ATHandlers in the _atHandlers list
*
* @param debug_on Set true to enable debug traces
*/
static void set_debug_list(bool debug_on);
private: //Private structs & enums private: //Private structs & enums
struct tag_t { struct tag_t {
char tag[7]; char tag[7];
@ -621,8 +574,6 @@ private: //Member variables
int32_t _ref_count; int32_t _ref_count;
bool _is_fh_usable; bool _is_fh_usable;
static ATHandler *_atHandlers;
// should fit any prefix and int // should fit any prefix and int
char _recv_buff[BUFF_SIZE]; char _recv_buff[BUFF_SIZE];
// reading position // reading position

View File

@ -261,21 +261,23 @@ public: // from NetworkInterface
*/ */
virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer) = 0; virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer) = 0;
/** Set the file handle used to communicate with the modem. You can use this to change the default file handle.
*
* @param fh file handle for communicating with the modem
*/
virtual void set_file_handle(FileHandle *fh) = 0;
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
/** Set the UART serial used to communicate with the modem. Can be used to change default file handle.
* File handle set with this method will use data carrier detect to be able to detect disconnection much faster in PPP mode. /** Enable or disable hang-up detection.
* *
* @param serial BufferedSerial used in communication to modem. If null then the default file handle is used. * This method will use data carrier detect to be able to detect disconnection much faster in PPP mode.
* @param dcd_pin Pin used to set data carrier detect on/off for the given UART *
* When in PPP data pump mode, it is helpful if the FileHandle will signal hang-up via
* POLLHUP, e.g., if the DCD line is deasserted on a UART. During command mode, this
* signaling is not desired.
*
* @param dcd_pin Pin used to set data carrier detect on/off for the given UART. NC if feature is disabled.
* @param active_high a boolean set to true if DCD polarity is active low * @param active_high a boolean set to true if DCD polarity is active low
*
* @return NSAPI_ERROR_OK if success,
* NSAPI_ERROR_UNSUPPORTED if modem does not support this feature
*/ */
virtual void set_file_handle(BufferedSerial *serial, PinName dcd_pin = NC, bool active_high = false) = 0; virtual nsapi_error_t configure_hup(PinName dcd_pin = NC, bool active_high = false) = 0;
#endif // #if DEVICE_SERIAL #endif // #if DEVICE_SERIAL
/** Returns the control plane AT command interface /** Returns the control plane AT command interface
@ -320,15 +322,6 @@ protected: // Device specific implementations might need these so protected
*/ */
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr) = 0; virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr) = 0;
/** Enable or disable hang-up detection
*
* When in PPP data pump mode, it is helpful if the FileHandle will signal hang-up via
* POLLHUP, e.g., if the DCD line is deasserted on a UART. During command mode, this
* signaling is not desired. enable_hup() controls whether this function should be
* active.
*/
virtual void enable_hup(bool enable) = 0;
/** Return PDP type string for Non-IP if modem uses other than standard "Non-IP" /** Return PDP type string for Non-IP if modem uses other than standard "Non-IP"
* *
* Some modems uses a non-standard PDP type string for non-ip (e.g. "NONIP"). * Some modems uses a non-standard PDP type string for non-ip (e.g. "NONIP").
@ -387,8 +380,6 @@ protected:
const char *_apn; const char *_apn;
const char *_uname; const char *_uname;
const char *_pwd; const char *_pwd;
PinName _dcd_pin;
bool _active_high;
ControlPlane_netif *_cp_netif; ControlPlane_netif *_cp_netif;
uint16_t _retry_timeout_array[CELLULAR_RETRY_ARRAY_SIZE]; uint16_t _retry_timeout_array[CELLULAR_RETRY_ARRAY_SIZE];

View File

@ -21,10 +21,7 @@
#include "CellularStateMachine.h" #include "CellularStateMachine.h"
#include "Callback.h" #include "Callback.h"
#include "ATHandler.h" #include "ATHandler.h"
#include "PinNames.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#include "drivers/BufferedSerial.h"
#endif // #if DEVICE_SERIAL
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT
#include "Thread.h" #include "Thread.h"
@ -40,7 +37,6 @@ class CellularSMS;
class CellularInformation; class CellularInformation;
class CellularNetwork; class CellularNetwork;
class CellularContext; class CellularContext;
class FileHandle;
const int MAX_PIN_SIZE = 8; const int MAX_PIN_SIZE = 8;
const int MAX_PLMN_SIZE = 16; const int MAX_PLMN_SIZE = 16;
@ -86,10 +82,8 @@ public:
static CellularDevice *get_target_default_instance(); static CellularDevice *get_target_default_instance();
/** Default constructor /** Default constructor
*
* @param fh File handle used in communication with the modem.
*/ */
CellularDevice(FileHandle *fh); CellularDevice();
/** virtual Destructor /** virtual Destructor
*/ */
@ -232,26 +226,7 @@ public: //Pure virtual functions
* @return new instance of class CellularContext or NULL in case of failure * @return new instance of class CellularContext or NULL in case of failure
* *
*/ */
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false) = 0; virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false) = 0;
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
/** Creates a new CellularContext interface. This API should be used if serial is UART and PPP mode used.
* CellularContext created will use data carrier detect to be able to detect disconnection much faster in PPP mode.
* BufferedSerial usually is the same which was given for the CellularDevice.
*
* @param serial BufferedSerial used in communication to modem. If null then the default file handle is used.
* @param apn access point to use with context, can be null.
* @param dcd_pin Pin used to set data carrier detect on/off for the given UART
* @param active_high a boolean set to true if DCD polarity is active low
* @param cp_req Flag indicating if EPS control plane optimization is required
* @param nonip_req Flag indicating if this context is required to be Non-IP
*
* @return new instance of class CellularContext or NULL in case of failure
*
*/
virtual CellularContext *create_context(BufferedSerial *serial, const char *apn, PinName dcd_pin = NC,
bool active_high = false, bool cp_req = false, bool nonip_req = false) = 0;
#endif // #if DEVICE_SERIAL
/** Deletes the given CellularContext instance /** Deletes the given CellularContext instance
* *
@ -307,19 +282,11 @@ public: //Pure virtual functions
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0) = 0; virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0) = 0;
/** Get the current ATHandler instance in use for debug purposes etc. /** Get the current ATHandler instance in use for debug purposes etc.
* Once use has been finished call to release_at_handler() has to be made
* *
* @return Pointer to the ATHandler in use * @return Pointer to the ATHandler in use, NULL if device is non-AT -device.
*/ */
virtual ATHandler *get_at_handler() = 0; virtual ATHandler *get_at_handler() = 0;
/** Release the ATHandler taken into use with get_at_handler()
*
* @param at_handler
* @return NSAPI_ERROR_OK on success, NSAPI_ERROR_PARAMETER on failure
*/
virtual nsapi_error_t release_at_handler(ATHandler *at_handler) = 0;
/** Sets cellular modem to given baud rate /** Sets cellular modem to given baud rate
* *
* @param baud_rate * @param baud_rate
@ -333,7 +300,7 @@ public: //Pure virtual functions
* file handle is used. * file handle is used.
* @return New instance of interface CellularNetwork. * @return New instance of interface CellularNetwork.
*/ */
virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0; virtual CellularNetwork *open_network() = 0;
#if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY) #if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY)
/** Create new CellularSMS interface. /** Create new CellularSMS interface.
@ -342,7 +309,7 @@ public: //Pure virtual functions
* file handle is used. * file handle is used.
* @return New instance of interface CellularSMS. * @return New instance of interface CellularSMS.
*/ */
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0; virtual CellularSMS *open_sms() = 0;
/** Closes the opened CellularSMS by deleting the CellularSMS instance. /** Closes the opened CellularSMS by deleting the CellularSMS instance.
*/ */
@ -356,7 +323,7 @@ public: //Pure virtual functions
* file handle is used. * file handle is used.
* @return New instance of interface CellularInformation. * @return New instance of interface CellularInformation.
*/ */
virtual CellularInformation *open_information(FileHandle *fh = NULL) = 0; virtual CellularInformation *open_information() = 0;
/** Closes the opened CellularNetwork by deleting the CellularNetwork instance. /** Closes the opened CellularNetwork by deleting the CellularNetwork instance.
*/ */
@ -377,11 +344,6 @@ public: //Pure virtual functions
public: //Common functions public: //Common functions
/** Get the current FileHandle item used when communicating with the modem.
*
* @return reference to FileHandle
*/
FileHandle &get_file_handle() const;
/** Set the pin code for SIM card /** Set the pin code for SIM card
* *
@ -493,7 +455,6 @@ protected: //Member variables
int _sms_ref_count; int _sms_ref_count;
#endif // MBED_CONF_CELLULAR_USE_SMS #endif // MBED_CONF_CELLULAR_USE_SMS
int _info_ref_count; int _info_ref_count;
FileHandle *_fh;
events::EventQueue _queue; events::EventQueue _queue;
CellularStateMachine *_state_machine; CellularStateMachine *_state_machine;
Callback<void(nsapi_event_t, intptr_t)> _status_cb; Callback<void(nsapi_event_t, intptr_t)> _status_cb;

View File

@ -47,7 +47,7 @@ using namespace mbed;
using namespace rtos; using namespace rtos;
AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) : AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :
_current_op(OP_INVALID), _fh(0), _cp_req(cp_req), _is_connected(false), _at(at) _current_op(OP_INVALID), _dcd_pin(NC), _active_high(false), _cp_req(cp_req), _is_connected(false), _at(at)
{ {
tr_info("New CellularContext %s (%p)", apn ? apn : "", this); tr_info("New CellularContext %s (%p)", apn ? apn : "", this);
_nonip_req = nonip_req; _nonip_req = nonip_req;
@ -71,22 +71,13 @@ AT_CellularContext::~AT_CellularContext()
} }
} }
void AT_CellularContext::set_file_handle(FileHandle *fh)
{
tr_info("CellularContext filehandle %p", fh);
_fh = fh;
_at.set_file_handle(_fh);
}
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
void AT_CellularContext::set_file_handle(BufferedSerial *serial, PinName dcd_pin, bool active_high) nsapi_error_t AT_CellularContext::configure_hup(PinName dcd_pin, bool active_high)
{ {
tr_info("CellularContext serial %p", serial);
_dcd_pin = dcd_pin; _dcd_pin = dcd_pin;
_active_high = active_high; _active_high = active_high;
_fh = serial;
_at.set_file_handle(static_cast<FileHandle *>(serial));
enable_hup(false); enable_hup(false);
return NSAPI_ERROR_OK;
} }
#endif // #if DEVICE_SERIAL #endif // #if DEVICE_SERIAL
@ -94,7 +85,7 @@ void AT_CellularContext::enable_hup(bool enable)
{ {
if (_dcd_pin != NC) { if (_dcd_pin != NC) {
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
static_cast<BufferedSerial *>(_fh)->set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high); static_cast<BufferedSerial *>(_at.get_file_handle())->set_data_carrier_detect(enable ? _dcd_pin : NC, _active_high);
#endif // #if DEVICE_SERIAL #endif // #if DEVICE_SERIAL
} }
} }
@ -967,7 +958,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
#endif // MBED_CONF_CELLULAR_USE_APN_LOOKUP #endif // MBED_CONF_CELLULAR_USE_APN_LOOKUP
if (!_nw && st == CellularDeviceReady && _cb_data.error == NSAPI_ERROR_OK) { if (!_nw && st == CellularDeviceReady && _cb_data.error == NSAPI_ERROR_OK) {
_nw = _device->open_network(_fh); _nw = _device->open_network();
} }
#if MBED_CONF_CELLULAR_CONTROL_PLANE_OPT #if MBED_CONF_CELLULAR_CONTROL_PLANE_OPT
@ -1113,8 +1104,3 @@ void AT_CellularContext::set_cid(int cid)
static_cast<AT_CellularStack *>(_stack)->set_cid(_cid); static_cast<AT_CellularStack *>(_stack)->set_cid(_cid);
} }
} }
ATHandler &AT_CellularContext::get_at_handler()
{
return _at;
}

View File

@ -62,19 +62,17 @@ public:
virtual nsapi_error_t set_sim_ready(); virtual nsapi_error_t set_sim_ready();
virtual nsapi_error_t register_to_network(); virtual nsapi_error_t register_to_network();
virtual nsapi_error_t attach_to_network(); virtual nsapi_error_t attach_to_network();
virtual void set_file_handle(FileHandle *fh);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual void set_file_handle(BufferedSerial *serial, PinName dcd_pin = NC, bool active_high = false); virtual nsapi_error_t configure_hup(PinName dcd_pin = NC, bool active_high = false);
#endif // #if DEVICE_SERIAL #endif // #if DEVICE_SERIAL
virtual void enable_hup(bool enable);
virtual ControlPlane_netif *get_cp_netif(); virtual ControlPlane_netif *get_cp_netif();
AT_CellularDevice *get_device() const; AT_CellularDevice *get_device() const;
ATHandler &get_at_handler();
protected: protected:
virtual void enable_hup(bool enable);
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr); virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr);
/** Does the authentication for the PDP Context if user name and password are provided. /** Does the authentication for the PDP Context if user name and password are provided.
@ -132,11 +130,13 @@ private:
void set_cid(int cid); void set_cid(int cid);
private: private:
ContextOperation _current_op; ContextOperation _current_op;
FileHandle *_fh;
rtos::Semaphore _semaphore; rtos::Semaphore _semaphore;
rtos::Semaphore _cp_opt_semaphore; rtos::Semaphore _cp_opt_semaphore;
PinName _dcd_pin;
bool _active_high;
protected: protected:
char _found_apn[MAX_APN_LENGTH]; char _found_apn[MAX_APN_LENGTH];
// flag indicating if CP was requested to be setup // flag indicating if CP was requested to be setup

View File

@ -38,25 +38,29 @@ using namespace mbed;
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds #define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
const int MAX_SIM_RESPONSE_LENGTH = 16; const int MAX_SIM_RESPONSE_LENGTH = 16;
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), AT_CellularDevice::AT_CellularDevice(FileHandle *fh) :
CellularDevice(),
_at(fh, _queue, DEFAULT_AT_TIMEOUT, "\r"),
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
_sms(0), _sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS #endif // MBED_CONF_CELLULAR_USE_SMS
_network(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _network(0),
_modem_debug_on(false), _property_array(NULL) _information(0),
_context_list(0),
_default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false),
_property_array(NULL)
{ {
MBED_ASSERT(fh); MBED_ASSERT(fh);
_at = get_at_handler(fh);
MBED_ASSERT(_at);
} }
AT_CellularDevice::~AT_CellularDevice() AT_CellularDevice::~AT_CellularDevice()
{ {
if (get_property(PROPERTY_AT_CGEREP)) { if (get_property(PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", nullptr); _at.set_urc_handler("+CGEV: NW DEACT", nullptr);
_at->set_urc_handler("+CGEV: ME DEACT", nullptr); _at.set_urc_handler("+CGEV: ME DEACT", nullptr);
_at->set_urc_handler("+CGEV: NW PDN D", nullptr); _at.set_urc_handler("+CGEV: NW PDN D", nullptr);
_at->set_urc_handler("+CGEV: ME PDN D", nullptr); _at.set_urc_handler("+CGEV: ME PDN D", nullptr);
} }
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up. // make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
@ -78,13 +82,9 @@ AT_CellularDevice::~AT_CellularDevice()
AT_CellularContext *next; AT_CellularContext *next;
while (curr) { while (curr) {
next = (AT_CellularContext *)curr->_next; next = (AT_CellularContext *)curr->_next;
ATHandler *at = &curr->get_at_handler();
delete curr; delete curr;
curr = next; curr = next;
release_at_handler(at);
} }
release_at_handler(_at);
} }
void AT_CellularDevice::set_at_urcs_impl() void AT_CellularDevice::set_at_urcs_impl()
@ -94,10 +94,10 @@ void AT_CellularDevice::set_at_urcs_impl()
void AT_CellularDevice::set_at_urcs() void AT_CellularDevice::set_at_urcs()
{ {
if (get_property(PROPERTY_AT_CGEREP)) { if (get_property(PROPERTY_AT_CGEREP)) {
_at->set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact)); _at.set_urc_handler("+CGEV: NW DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact)); _at.set_urc_handler("+CGEV: ME DEACT", callback(this, &AT_CellularDevice::urc_nw_deact));
_at->set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact)); _at.set_urc_handler("+CGEV: NW PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
_at->set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact)); _at.set_urc_handler("+CGEV: ME PDN D", callback(this, &AT_CellularDevice::urc_pdn_deact));
} }
set_at_urcs_impl(); set_at_urcs_impl();
@ -107,24 +107,24 @@ void AT_CellularDevice::setup_at_handler()
{ {
set_at_urcs(); set_at_urcs();
_at->set_send_delay(get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY)); _at.set_send_delay(get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY));
} }
void AT_CellularDevice::urc_nw_deact() void AT_CellularDevice::urc_nw_deact()
{ {
// The network has forced a context deactivation // The network has forced a context deactivation
char buf[10]; char buf[10];
_at->read_string(buf, 10); _at.read_string(buf, 10);
int cid; int cid;
if (isalpha(buf[0])) { if (isalpha(buf[0])) {
// this is +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>] // this is +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
// or +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>] // or +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
_at->skip_param(); // skip <PDP_addr> _at.skip_param(); // skip <PDP_addr>
cid = _at->read_int(); cid = _at.read_int();
} else { } else {
// this is +CGEV: NW DEACT <p_cid>, <cid>, <event_type>[,<WLAN_Offload>] // this is +CGEV: NW DEACT <p_cid>, <cid>, <event_type>[,<WLAN_Offload>]
// or +CGEV: ME DEACT <p_cid>, <cid>, <event_type // or +CGEV: ME DEACT <p_cid>, <cid>, <event_type
cid = _at->read_int(); cid = _at.read_int();
} }
send_disconnect_to_context(cid); send_disconnect_to_context(cid);
} }
@ -135,11 +135,11 @@ void AT_CellularDevice::urc_pdn_deact()
// The mobile termination has deactivated a context. // The mobile termination has deactivated a context.
// +CGEV: NW PDN DEACT <cid>[,<WLAN_Offload>] // +CGEV: NW PDN DEACT <cid>[,<WLAN_Offload>]
// +CGEV: ME PDN DEACT <cid> // +CGEV: ME PDN DEACT <cid>
_at->set_delimiter(' '); _at.set_delimiter(' ');
_at->skip_param(); _at.skip_param();
_at->set_delimiter(','); _at.set_delimiter(',');
int cid = _at->read_int(); int cid = _at.read_int();
send_disconnect_to_context(cid); send_disconnect_to_context(cid);
} }
@ -180,42 +180,22 @@ nsapi_error_t AT_CellularDevice::soft_power_off()
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
// each parser is associated with one filehandle (that is UART)
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
{
if (!fileHandle) {
fileHandle = _fh;
}
return ATHandler::get_instance(fileHandle, _queue, _default_timeout,
"\r", get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), _modem_debug_on);
}
ATHandler *AT_CellularDevice::get_at_handler() ATHandler *AT_CellularDevice::get_at_handler()
{ {
return get_at_handler(NULL); return &_at;
}
nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler)
{
if (at_handler) {
return at_handler->close();
} else {
return NSAPI_ERROR_PARAMETER;
}
} }
nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
{ {
char simstr[MAX_SIM_RESPONSE_LENGTH]; char simstr[MAX_SIM_RESPONSE_LENGTH];
_at->lock(); _at.lock();
_at->flush(); _at.flush();
nsapi_error_t error = _at->at_cmd_str("+CPIN", "?", simstr, sizeof(simstr)); nsapi_error_t error = _at.at_cmd_str("+CPIN", "?", simstr, sizeof(simstr));
ssize_t len = strlen(simstr); ssize_t len = strlen(simstr);
#if MBED_CONF_MBED_TRACE_ENABLE #if MBED_CONF_MBED_TRACE_ENABLE
device_err_t err = _at->get_last_device_error(); device_err_t err = _at.get_last_device_error();
#endif #endif
_at->unlock(); _at.unlock();
if (len != -1) { if (len != -1) {
if (len >= 5 && memcmp(simstr, "READY", 5) == 0) { if (len >= 5 && memcmp(simstr, "READY", 5) == 0) {
@ -268,16 +248,16 @@ nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
_at->lock(); _at.lock();
const bool stored_debug_state = _at->get_debug(); const bool stored_debug_state = _at.get_debug();
_at->set_debug(false); _at.set_debug(false);
_at->at_cmd_discard("+CPIN", "=", "%s", sim_pin); _at.at_cmd_discard("+CPIN", "=", "%s", sim_pin);
_at->set_debug(stored_debug_state); _at.set_debug(stored_debug_state);
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
CellularContext *AT_CellularDevice::get_context_list() const CellularContext *AT_CellularDevice::get_context_list() const
@ -285,22 +265,9 @@ CellularContext *AT_CellularDevice::get_context_list() const
return _context_list; return _context_list;
} }
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) CellularContext *AT_CellularDevice::create_context(const char *apn, bool cp_req, bool nonip_req)
CellularContext *AT_CellularDevice::create_context(BufferedSerial *serial, const char *const apn, PinName dcd_pin,
bool active_high, bool cp_req, bool nonip_req)
{ {
// Call FileHandle base version - explict upcast to avoid recursing into ourselves AT_CellularContext *ctx = create_context_impl(_at, apn, cp_req, nonip_req);
CellularContext *ctx = create_context(static_cast<FileHandle *>(serial), apn, cp_req, nonip_req);
if (serial) {
ctx->set_file_handle(serial, dcd_pin, active_high);
}
return ctx;
}
#endif // #if DEVICE_SERIAL
CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *apn, bool cp_req, bool nonip_req)
{
AT_CellularContext *ctx = create_context_impl(*get_at_handler(fh), apn, cp_req, nonip_req);
AT_CellularContext *curr = _context_list; AT_CellularContext *curr = _context_list;
if (_context_list == NULL) { if (_context_list == NULL) {
@ -320,9 +287,6 @@ CellularContext *AT_CellularDevice::create_context(FileHandle *fh, const char *a
AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
{ {
if (cp_req) {
}
return new AT_CellularContext(at, this, apn, cp_req, nonip_req); return new AT_CellularContext(at, this, apn, cp_req, nonip_req);
} }
@ -341,28 +305,22 @@ void AT_CellularDevice::delete_context(CellularContext *context)
prev = curr; prev = curr;
curr = (AT_CellularContext *)curr->_next; curr = (AT_CellularContext *)curr->_next;
} }
curr = (AT_CellularContext *)context;
ATHandler *at = NULL;
if (curr) {
at = &curr->get_at_handler();
}
delete (AT_CellularContext *)context; delete (AT_CellularContext *)context;
release_at_handler(at);
} }
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) CellularNetwork *AT_CellularDevice::open_network()
{ {
if (!_network) { if (!_network) {
_network = open_network_impl(*get_at_handler(fh)); _network = open_network_impl(*get_at_handler());
} }
_network_ref_count++; _network_ref_count++;
return _network; return _network;
} }
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) CellularInformation *AT_CellularDevice::open_information()
{ {
if (!_information) { if (!_information) {
_information = open_information_impl(*get_at_handler(fh)); _information = open_information_impl(*get_at_handler());
} }
_info_ref_count++; _info_ref_count++;
return _information; return _information;
@ -375,10 +333,10 @@ AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) CellularSMS *AT_CellularDevice::open_sms()
{ {
if (!_sms) { if (!_sms) {
_sms = open_sms_impl(*get_at_handler(fh)); _sms = open_sms_impl(*get_at_handler());
} }
_sms_ref_count++; _sms_ref_count++;
return _sms; return _sms;
@ -389,10 +347,8 @@ void AT_CellularDevice::close_sms()
if (_sms) { if (_sms) {
_sms_ref_count--; _sms_ref_count--;
if (_sms_ref_count == 0) { if (_sms_ref_count == 0) {
ATHandler *atHandler = &_sms->get_at_handler();
delete _sms; delete _sms;
_sms = NULL; _sms = NULL;
release_at_handler(atHandler);
} }
} }
} }
@ -413,10 +369,8 @@ void AT_CellularDevice::close_network()
if (_network) { if (_network) {
_network_ref_count--; _network_ref_count--;
if (_network_ref_count == 0) { if (_network_ref_count == 0) {
ATHandler *atHandler = &_network->get_at_handler();
delete _network; delete _network;
_network = NULL; _network = NULL;
release_at_handler(atHandler);
} }
} }
} }
@ -426,10 +380,8 @@ void AT_CellularDevice::close_information()
if (_information) { if (_information) {
_info_ref_count--; _info_ref_count--;
if (_info_ref_count == 0) { if (_info_ref_count == 0) {
ATHandler *atHandler = &_information->get_at_handler();
delete _information; delete _information;
_information = NULL; _information = NULL;
release_at_handler(atHandler);
} }
} }
} }
@ -438,7 +390,7 @@ void AT_CellularDevice::set_timeout(int timeout)
{ {
_default_timeout = timeout; _default_timeout = timeout;
ATHandler::set_at_timeout_list(_default_timeout, true); _at.set_at_timeout(_default_timeout, true);
if (_state_machine) { if (_state_machine) {
_state_machine->set_timeout(_default_timeout); _state_machine->set_timeout(_default_timeout);
@ -448,23 +400,22 @@ void AT_CellularDevice::set_timeout(int timeout)
void AT_CellularDevice::modem_debug_on(bool on) void AT_CellularDevice::modem_debug_on(bool on)
{ {
_modem_debug_on = on; _modem_debug_on = on;
_at.set_debug(_modem_debug_on);
ATHandler::set_debug_list(_modem_debug_on);
} }
nsapi_error_t AT_CellularDevice::init() nsapi_error_t AT_CellularDevice::init()
{ {
setup_at_handler(); setup_at_handler();
_at->lock(); _at.lock();
for (int retry = 1; retry <= 3; retry++) { for (int retry = 1; retry <= 3; retry++) {
_at->clear_error(); _at.clear_error();
_at->flush(); _at.flush();
_at->at_cmd_discard("E0", ""); _at.at_cmd_discard("E0", "");
if (_at->get_last_error() == NSAPI_ERROR_OK) { if (_at.get_last_error() == NSAPI_ERROR_OK) {
_at->at_cmd_discard("+CMEE", "=1"); _at.at_cmd_discard("+CMEE", "=1");
_at->at_cmd_discard("+CFUN", "=1"); _at.at_cmd_discard("+CFUN", "=1");
if (_at->get_last_error() == NSAPI_ERROR_OK) { if (_at.get_last_error() == NSAPI_ERROR_OK) {
break; break;
} }
} }
@ -472,27 +423,27 @@ nsapi_error_t AT_CellularDevice::init()
rtos::ThisThread::sleep_for(100); // let modem have time to get ready rtos::ThisThread::sleep_for(100); // let modem have time to get ready
} }
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
nsapi_error_t AT_CellularDevice::shutdown() nsapi_error_t AT_CellularDevice::shutdown()
{ {
CellularDevice::shutdown(); CellularDevice::shutdown();
return _at->at_cmd_discard("+CFUN", "=0"); return _at.at_cmd_discard("+CFUN", "=0");
} }
nsapi_error_t AT_CellularDevice::is_ready() nsapi_error_t AT_CellularDevice::is_ready()
{ {
_at->lock(); _at.lock();
_at->at_cmd_discard("", ""); _at.at_cmd_discard("", "");
// we need to do this twice because for example after data mode the first 'AT' command will give modem a // we need to do this twice because for example after data mode the first 'AT' command will give modem a
// stimulus that we are back to command mode. // stimulus that we are back to command mode.
_at->clear_error(); _at.clear_error();
_at->at_cmd_discard("", ""); _at.at_cmd_discard("", "");
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
void AT_CellularDevice::set_ready_cb(Callback<void()> callback) void AT_CellularDevice::set_ready_cb(Callback<void()> callback)
@ -501,11 +452,11 @@ void AT_CellularDevice::set_ready_cb(Callback<void()> callback)
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time) nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
{ {
_at->lock(); _at.lock();
if (periodic_time == 0 && active_time == 0) { if (periodic_time == 0 && active_time == 0) {
// disable PSM // disable PSM
_at->at_cmd_discard("+CPSMS", "=0"); _at.at_cmd_discard("+CPSMS", "=0");
} else { } else {
const int PSMTimerBits = 5; const int PSMTimerBits = 5;
@ -607,9 +558,9 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
// request for both GPRS and LTE // request for both GPRS and LTE
_at->at_cmd_discard("+CPSMS", "=1,", "%s%s%s%s", pt, at, pt, at); _at.at_cmd_discard("+CPSMS", "=1,", "%s%s%s%s", pt, at, pt, at);
if (_at->get_last_error() != NSAPI_ERROR_OK) { if (_at.get_last_error() != NSAPI_ERROR_OK) {
tr_warn("Power save mode not enabled!"); tr_warn("Power save mode not enabled!");
} else { } else {
// network may not agree with power save options but // network may not agree with power save options but
@ -617,7 +568,7 @@ nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int acti
} }
} }
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx) void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx)
@ -629,7 +580,7 @@ void AT_CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr, Cellul
int timeout = *(int *)data->data; int timeout = *(int *)data->data;
if (_default_timeout != timeout) { if (_default_timeout != timeout) {
_default_timeout = timeout; _default_timeout = timeout;
ATHandler::set_at_timeout_list(_default_timeout, true); _at.set_at_timeout(_default_timeout, true);
} }
} }
} }
@ -654,7 +605,7 @@ nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
return error; return error;
} }
_at->set_baud(baud_rate); _at.set_baud(baud_rate);
// Give some time before starting using the UART with the new baud rate // Give some time before starting using the UART with the new baud rate
rtos::ThisThread::sleep_for(3000); rtos::ThisThread::sleep_for(3000);
@ -664,7 +615,7 @@ nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate)
nsapi_error_t AT_CellularDevice::set_baud_rate_impl(int baud_rate) nsapi_error_t AT_CellularDevice::set_baud_rate_impl(int baud_rate)
{ {
return _at->at_cmd_discard("+IPR", "=", "%d", baud_rate); return _at.at_cmd_discard("+IPR", "=", "%d", baud_rate);
} }
void AT_CellularDevice::set_cellular_properties(const intptr_t *property_array) void AT_CellularDevice::set_cellular_properties(const intptr_t *property_array)

View File

@ -19,14 +19,15 @@
#define AT_CELLULAR_DEVICE_H_ #define AT_CELLULAR_DEVICE_H_
#include "CellularDevice.h" #include "CellularDevice.h"
#include "ATHandler.h"
namespace mbed { namespace mbed {
class ATHandler;
class AT_CellularInformation; class AT_CellularInformation;
class AT_CellularNetwork; class AT_CellularNetwork;
class AT_CellularSMS; class AT_CellularSMS;
class AT_CellularContext; class AT_CellularContext;
class FileHandle;
/** /**
* Class AT_CellularDevice * Class AT_CellularDevice
@ -83,17 +84,13 @@ public:
virtual nsapi_error_t get_sim_state(SimState &state); virtual nsapi_error_t get_sim_state(SimState &state);
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false); virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
virtual CellularContext *create_context(BufferedSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false, bool cp_req = false, bool nonip_req = false);
#endif // #if DEVICE_SERIAL
virtual void delete_context(CellularContext *context); virtual void delete_context(CellularContext *context);
virtual CellularNetwork *open_network(FileHandle *fh = NULL); virtual CellularNetwork *open_network();
virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual CellularInformation *open_information();
virtual void close_network(); virtual void close_network();
@ -113,24 +110,14 @@ public:
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0); virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
virtual ATHandler *get_at_handler(FileHandle *fh);
virtual ATHandler *get_at_handler(); virtual ATHandler *get_at_handler();
/** Releases the given at_handler. If last reference to at_hander then it's deleted.
*
* @param at_handler
* @return NSAPI_ERROR_OK on success, NSAPI_ERROR_PARAMETER on failure
*/
virtual nsapi_error_t release_at_handler(ATHandler *at_handler);
virtual CellularContext *get_context_list() const; virtual CellularContext *get_context_list() const;
virtual nsapi_error_t set_baud_rate(int baud_rate); virtual nsapi_error_t set_baud_rate(int baud_rate);
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms(FileHandle *fh = NULL); virtual CellularSMS *open_sms();
virtual void close_sms(); virtual void close_sms();
#endif #endif
@ -199,7 +186,7 @@ private:
void urc_pdn_deact(); void urc_pdn_deact();
protected: protected:
ATHandler *_at; ATHandler _at;
private: private:
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS

View File

@ -98,8 +98,3 @@ nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size)
} }
return _at.at_cmd_str("+CCID", "?", buf, buf_size); return _at.at_cmd_str("+CCID", "?", buf, buf_size);
} }
ATHandler &AT_CellularInformation::get_at_handler()
{
return _at;
}

View File

@ -48,8 +48,6 @@ public:
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
ATHandler &get_at_handler();
protected: protected:
/** Request information text from cellular device /** Request information text from cellular device
* *

View File

@ -710,8 +710,3 @@ nsapi_error_t AT_CellularNetwork::clear()
return _at.unlock_return_error(); return _at.unlock_return_error();
} }
ATHandler &AT_CellularNetwork::get_at_handler()
{
return _at;
}

View File

@ -96,9 +96,6 @@ public: // CellularNetwork
virtual nsapi_error_t set_packet_domain_event_reporting(bool on); virtual nsapi_error_t set_packet_domain_event_reporting(bool on);
public:
ATHandler &get_at_handler();
protected: protected:
/** Sets access technology to be scanned. Modem specific implementation. /** Sets access technology to be scanned. Modem specific implementation.
* *

View File

@ -1252,9 +1252,4 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char
return decodedCount; return decodedCount;
} }
ATHandler &AT_CellularSMS::get_at_handler()
{
return _at;
}
#endif //MBED_CONF_CELLULAR_USE_SMS #endif //MBED_CONF_CELLULAR_USE_SMS

View File

@ -62,9 +62,6 @@ public:
virtual void set_extra_sim_wait_time(int sim_wait_time); virtual void set_extra_sim_wait_time(int sim_wait_time);
public:
ATHandler &get_at_handler();
private: private:
struct sms_info_t { struct sms_info_t {
char date[SMS_MAX_TIME_STAMP_SIZE]; char date[SMS_MAX_TIME_STAMP_SIZE];

View File

@ -63,99 +63,11 @@ static const uint8_t map_3gpp_errors[][2] = {
{ 146, 46 }, { 178, 65 }, { 179, 66 }, { 180, 48 }, { 181, 83 }, { 171, 49 }, { 146, 46 }, { 178, 65 }, { 179, 66 }, { 180, 48 }, { 181, 83 }, { 171, 49 },
}; };
ATHandler *ATHandler::_atHandlers = NULL;
// each parser is associated with one filehandle (that is UART)
ATHandler *ATHandler::get_instance(FileHandle *fileHandle, events::EventQueue &queue, uint32_t timeout,
const char *delimiter, uint16_t send_delay, bool debug_on)
{
if (!fileHandle) {
return NULL;
}
singleton_lock();
ATHandler *atHandler = _atHandlers;
while (atHandler) {
if (atHandler->get_file_handle() == fileHandle) {
atHandler->inc_ref_count();
singleton_unlock();
return atHandler;
}
atHandler = atHandler->_nextATHandler;
}
atHandler = new ATHandler(fileHandle, queue, timeout, delimiter, send_delay);
if (debug_on) {
atHandler->set_debug(debug_on);
}
atHandler->_nextATHandler = _atHandlers;
_atHandlers = atHandler;
singleton_unlock();
return atHandler;
}
nsapi_error_t ATHandler::close()
{
if (get_ref_count() == 0) {
return NSAPI_ERROR_PARAMETER;
}
singleton_lock();
dec_ref_count();
if (get_ref_count() == 0) {
// we can delete this at_handler
ATHandler *atHandler = _atHandlers;
ATHandler *prev = NULL;
while (atHandler) {
if (atHandler == this) {
if (prev == NULL) {
_atHandlers = _atHandlers->_nextATHandler;
} else {
prev->_nextATHandler = atHandler->_nextATHandler;
}
delete this;
break;
} else {
prev = atHandler;
atHandler = atHandler->_nextATHandler;
}
}
}
singleton_unlock();
return NSAPI_ERROR_OK;
}
void ATHandler::set_at_timeout_list(uint32_t timeout_milliseconds, bool default_timeout)
{
ATHandler *atHandler = _atHandlers;
singleton_lock();
while (atHandler) {
atHandler->set_at_timeout(timeout_milliseconds, default_timeout);
atHandler = atHandler->_nextATHandler;
}
singleton_unlock();
}
bool ATHandler::ok_to_proceed()
{
if (_last_err != NSAPI_ERROR_OK) {
return false;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return false;
}
return true;
}
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) : ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT #if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
_oobCv(_fileHandleMutex), _oobCv(_fileHandleMutex),
#endif #endif
_fileHandle(NULL), // filehandle is set by set_file_handle() _fileHandle(fh),
_queue(queue), _queue(queue),
_last_err(NSAPI_ERROR_OK), _last_err(NSAPI_ERROR_OK),
_last_3gpp_error(0), _last_3gpp_error(0),
@ -197,35 +109,15 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
set_tag(&_info_stop, CRLF); set_tag(&_info_stop, CRLF);
set_tag(&_elem_stop, ")"); set_tag(&_elem_stop, ")");
set_file_handle(fh); set_is_filehandle_usable(true);
}
void ATHandler::set_debug(bool debug_on)
{
_debug_on = debug_on;
}
bool ATHandler::get_debug() const
{
return _debug_on;
}
void ATHandler::set_debug_list(bool debug_on)
{
ATHandler *atHandler = _atHandlers;
singleton_lock();
while (atHandler) {
atHandler->set_debug(debug_on);
atHandler = atHandler->_nextATHandler;
}
singleton_unlock();
} }
ATHandler::~ATHandler() ATHandler::~ATHandler()
{ {
ScopedLock <ATHandler> lock(*this); ScopedLock <ATHandler> lock(*this);
set_file_handle(NULL);
set_is_filehandle_usable(false);
_fileHandle = NULL;
if (_event_id != 0 && _queue.cancel(_event_id)) { if (_event_id != 0 && _queue.cancel(_event_id)) {
_event_id = 0; _event_id = 0;
@ -250,19 +142,27 @@ ATHandler::~ATHandler()
} }
} }
void ATHandler::inc_ref_count() bool ATHandler::ok_to_proceed()
{ {
_ref_count++; if (_last_err != NSAPI_ERROR_OK) {
return false;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return false;
}
return true;
} }
void ATHandler::dec_ref_count() void ATHandler::set_debug(bool debug_on)
{ {
_ref_count--; _debug_on = debug_on;
} }
int ATHandler::get_ref_count() bool ATHandler::get_debug() const
{ {
return _ref_count; return _debug_on;
} }
FileHandle *ATHandler::get_file_handle() FileHandle *ATHandler::get_file_handle()
@ -270,18 +170,6 @@ FileHandle *ATHandler::get_file_handle()
return _fileHandle; return _fileHandle;
} }
void ATHandler::set_file_handle(FileHandle *fh)
{
ScopedLock<ATHandler> lock(*this);
if (_fileHandle) {
set_is_filehandle_usable(false);
}
_fileHandle = fh;
if (_fileHandle) {
set_is_filehandle_usable(true);
}
}
void ATHandler::set_is_filehandle_usable(bool usable) void ATHandler::set_is_filehandle_usable(bool usable)
{ {
ScopedLock<ATHandler> lock(*this); ScopedLock<ATHandler> lock(*this);

View File

@ -32,12 +32,7 @@ MBED_WEAK CellularContext *CellularContext::get_default_instance()
return NULL; return NULL;
} }
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT); static CellularContext *context = dev->create_context(NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
context->set_file_handle(static_cast<BufferedSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
#endif // #if DEVICE_SERIAL
return context; return context;
} }
@ -49,19 +44,14 @@ MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
return NULL; return NULL;
} }
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true); static CellularContext *context = dev->create_context(NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true);
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
context->set_file_handle(static_cast<BufferedSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
#endif // #if DEVICE_SERIAL
return context; return context;
} }
CellularContext::CellularContext() : _next(0), _stack(0), _pdp_type(DEFAULT_PDP_TYPE), CellularContext::CellularContext() : _next(0), _stack(0), _pdp_type(DEFAULT_PDP_TYPE),
_authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(), _authentication_type(CellularContext::CHAP), _connect_status(NSAPI_STATUS_DISCONNECTED), _status_cb(),
_cid(-1), _new_context_set(false), _is_context_active(false), _is_context_activated(false), _cid(-1), _new_context_set(false), _is_context_active(false), _is_context_activated(false),
_apn(0), _uname(0), _pwd(0), _dcd_pin(NC), _active_high(false), _cp_netif(0), _retry_timeout_array(), _apn(0), _uname(0), _pwd(0), _cp_netif(0), _retry_timeout_array(),
_retry_array_length(0), _retry_count(0), _device(0), _nw(0), _is_blocking(true), _nonip_req(false), _cp_in_use(false) _retry_array_length(0), _retry_count(0), _device(0), _nw(0), _is_blocking(true), _nonip_req(false), _cp_in_use(false)
{ {
} }

View File

@ -34,18 +34,17 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
return NULL; return NULL;
} }
CellularDevice::CellularDevice(FileHandle *fh) : CellularDevice::CellularDevice() :
_network_ref_count(0), _network_ref_count(0),
#if MBED_CONF_CELLULAR_USE_SMS #if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count(0), _sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS #endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _info_ref_count(0), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0),
_status_cb(), _nw(0) _status_cb(), _nw(0)
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT
, _queue_thread(osPriorityNormal, 2048, NULL, "cellular_queue") , _queue_thread(osPriorityNormal, 2048, NULL, "cellular_queue")
#endif // MBED_CONF_RTOS_PRESENT #endif // MBED_CONF_RTOS_PRESENT
{ {
MBED_ASSERT(fh);
set_sim_pin(NULL); set_sim_pin(NULL);
set_plmn(NULL); set_plmn(NULL);
@ -64,11 +63,6 @@ CellularDevice::~CellularDevice()
delete _state_machine; delete _state_machine;
} }
FileHandle &CellularDevice::get_file_handle() const
{
return *_fh;
}
events::EventQueue *CellularDevice::get_queue() events::EventQueue *CellularDevice::get_queue()
{ {
return &_queue; return &_queue;
@ -130,7 +124,7 @@ nsapi_error_t CellularDevice::create_state_machine()
{ {
nsapi_error_t err = NSAPI_ERROR_OK; nsapi_error_t err = NSAPI_ERROR_OK;
if (!_state_machine) { if (!_state_machine) {
_nw = open_network(_fh); _nw = open_network();
// Attach to network so we can get update status from the network // Attach to network so we can get update status from the network
_nw->attach(callback(this, &CellularDevice::stm_callback)); _nw->attach(callback(this, &CellularDevice::stm_callback));
_state_machine = new CellularStateMachine(*this, *get_queue(), *_nw); _state_machine = new CellularStateMachine(*this, *get_queue(), *_nw);

View File

@ -39,7 +39,7 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack()
} }
if (!_stack) { if (!_stack) {
_stack = new GEMALTO_CINTERION_CellularStack(get_at_handler(), _apn, _uname, _pwd, _cid, (nsapi_ip_stack_t)_pdp_type, *get_device()); _stack = new GEMALTO_CINTERION_CellularStack(_at, _apn, _uname, _pwd, _cid, (nsapi_ip_stack_t)_pdp_type, *get_device());
if (static_cast<GEMALTO_CINTERION_CellularStack *>(_stack)->socket_stack_init() != NSAPI_ERROR_OK) { if (static_cast<GEMALTO_CINTERION_CellularStack *>(_stack)->socket_stack_init() != NSAPI_ERROR_OK) {
delete _stack; delete _stack;
_stack = NULL; _stack = NULL;

View File

@ -58,10 +58,10 @@ QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state) nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state)
{ {
_at->lock(); _at.lock();
_at->flush(); _at.flush();
nsapi_error_t err = _at->at_cmd_discard("+NCCID", "?"); nsapi_error_t err = _at.at_cmd_discard("+NCCID", "?");
_at->unlock(); _at.unlock();
state = SimStateReady; state = SimStateReady;
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
@ -91,25 +91,25 @@ nsapi_error_t QUECTEL_BC95::init()
{ {
setup_at_handler(); setup_at_handler();
_at->lock(); _at.lock();
_at->flush(); _at.flush();
nsapi_error_t err = _at->at_cmd_discard("", ""); //Send AT nsapi_error_t err = _at.at_cmd_discard("", ""); //Send AT
if (!err) { if (!err) {
err = _at->at_cmd_discard("+CMEE", "=1"); // verbose responses err = _at.at_cmd_discard("+CMEE", "=1"); // verbose responses
} }
if (!err) { if (!err) {
err = _at->at_cmd_discard("+CFUN", "=", "%d", 1); err = _at.at_cmd_discard("+CFUN", "=", "%d", 1);
} }
if (!err) { if (!err) {
err = _at->get_last_error(); err = _at.get_last_error();
} }
_at->unlock(); _at.unlock();
return err; return err;
} }
nsapi_error_t QUECTEL_BC95::set_baud_rate_impl(int baud_rate) nsapi_error_t QUECTEL_BC95::set_baud_rate_impl(int baud_rate)
{ {
return _at->at_cmd_discard("+NATSPEED", "=", "%d%d%d%d%d%d%d", baud_rate, 30, 0, 2, 1, 0, 0); return _at.at_cmd_discard("+NATSPEED", "=", "%d%d%d%d%d%d%d", baud_rate, 30, 0, 2, 1, 0, 0);
} }
#if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT #if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT

View File

@ -79,7 +79,7 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinNam
void QUECTEL_BG96::set_at_urcs_impl() void QUECTEL_BG96::set_at_urcs_impl()
{ {
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact)); _at.set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
} }
AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at)
@ -99,7 +99,7 @@ AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
void QUECTEL_BG96::set_ready_cb(Callback<void()> callback) void QUECTEL_BG96::set_ready_cb(Callback<void()> callback)
{ {
_at->set_urc_handler(DEVICE_READY_URC, callback); _at.set_urc_handler(DEVICE_READY_URC, callback);
} }
nsapi_error_t QUECTEL_BG96::soft_power_on() nsapi_error_t QUECTEL_BG96::soft_power_on()
@ -117,7 +117,7 @@ nsapi_error_t QUECTEL_BG96::soft_power_on()
} }
#if defined (MBED_CONF_QUECTEL_BG96_RTS) && defined(MBED_CONF_QUECTEL_BG96_CTS) #if defined (MBED_CONF_QUECTEL_BG96_RTS) && defined(MBED_CONF_QUECTEL_BG96_CTS)
if (_at->at_cmd_discard("+IFC", "=", "%d%d", 2, 2) != NSAPI_ERROR_OK) { if (_at.at_cmd_discard("+IFC", "=", "%d%d", 2, 2) != NSAPI_ERROR_OK) {
tr_warn("Set flow control failed"); tr_warn("Set flow control failed");
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;
} }
@ -128,16 +128,16 @@ nsapi_error_t QUECTEL_BG96::soft_power_on()
nsapi_error_t QUECTEL_BG96::soft_power_off() nsapi_error_t QUECTEL_BG96::soft_power_off()
{ {
_at->lock(); _at.lock();
_at->cmd_start("AT+QPOWD"); _at.cmd_start("AT+QPOWD");
_at->cmd_stop_read_resp(); _at.cmd_stop_read_resp();
if (_at->get_last_error() != NSAPI_ERROR_OK) { if (_at.get_last_error() != NSAPI_ERROR_OK) {
tr_warn("Force modem off"); tr_warn("Force modem off");
if (_pwr.is_connected()) { if (_pwr.is_connected()) {
press_button(_pwr, 650); // BG96_Hardware_Design_V1.1: Power off signal at least 650 ms press_button(_pwr, 650); // BG96_Hardware_Design_V1.1: Power off signal at least 650 ms
} }
} }
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
#if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT #if MBED_CONF_QUECTEL_BG96_PROVIDE_DEFAULT
@ -159,10 +159,10 @@ CellularDevice *CellularDevice::get_default_instance()
void QUECTEL_BG96::urc_pdpdeact() void QUECTEL_BG96::urc_pdpdeact()
{ {
_at->lock(); _at.lock();
_at->skip_param(); _at.skip_param();
int cid = _at->read_int(); int cid = _at.read_int();
const nsapi_error_t err = _at->unlock_return_error(); const nsapi_error_t err = _at.unlock_return_error();
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
return; return;
@ -183,14 +183,14 @@ void QUECTEL_BG96::press_button(DigitalOut &button, uint32_t timeout)
bool QUECTEL_BG96::wake_up(bool reset) bool QUECTEL_BG96::wake_up(bool reset)
{ {
// check if modem is already ready // check if modem is already ready
_at->lock(); _at.lock();
_at->flush(); _at.flush();
_at->set_at_timeout(30); _at.set_at_timeout(30);
_at->cmd_start("AT"); _at.cmd_start("AT");
_at->cmd_stop_read_resp(); _at.cmd_stop_read_resp();
nsapi_error_t err = _at->get_last_error(); nsapi_error_t err = _at.get_last_error();
_at->restore_at_timeout(); _at.restore_at_timeout();
_at->unlock(); _at.unlock();
// modem is not responding, power it on // modem is not responding, power it on
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
if (!reset) { if (!reset) {
@ -201,20 +201,20 @@ bool QUECTEL_BG96::wake_up(bool reset)
tr_warn("Reset modem"); tr_warn("Reset modem");
press_button(_rst, 150); // BG96_Hardware_Design_V1.1 requires RESET_N timeout at least 150 ms press_button(_rst, 150); // BG96_Hardware_Design_V1.1 requires RESET_N timeout at least 150 ms
} }
_at->lock(); _at.lock();
// According to BG96_Hardware_Design_V1.1 USB is active after 4.2s, but it seems to take over 5s // According to BG96_Hardware_Design_V1.1 USB is active after 4.2s, but it seems to take over 5s
_at->set_at_timeout(6000); _at.set_at_timeout(6000);
_at->resp_start(); _at.resp_start();
_at->set_stop_tag("RDY"); _at.set_stop_tag("RDY");
bool rdy = _at->consume_to_stop_tag(); bool rdy = _at.consume_to_stop_tag();
_at->set_stop_tag(OK); _at.set_stop_tag(OK);
_at->restore_at_timeout(); _at.restore_at_timeout();
_at->unlock(); _at.unlock();
if (!rdy) { if (!rdy) {
return false; return false;
} }
} }
// sync to check that AT is really responsive and to clear garbage // sync to check that AT is really responsive and to clear garbage
return _at->sync(500); return _at.sync(500);
} }

View File

@ -124,15 +124,15 @@ nsapi_error_t QUECTEL_EC2X::soft_power_on()
_rst = !_active_high; _rst = !_active_high;
ThisThread::sleep_for(100); ThisThread::sleep_for(100);
_at->lock(); _at.lock();
_at->set_at_timeout(5000); _at.set_at_timeout(5000);
_at->resp_start(); _at.resp_start();
_at->set_stop_tag("RDY"); _at.set_stop_tag("RDY");
bool rdy = _at->consume_to_stop_tag(); bool rdy = _at.consume_to_stop_tag();
_at->set_stop_tag(OK); _at.set_stop_tag(OK);
_at->unlock(); _at.unlock();
if (!rdy) { if (!rdy) {
return NSAPI_ERROR_DEVICE_ERROR; return NSAPI_ERROR_DEVICE_ERROR;

View File

@ -56,10 +56,10 @@ nsapi_error_t QUECTEL_M26::get_sim_state(SimState &state)
{ {
char buf[13]; char buf[13];
_at->lock(); _at.lock();
nsapi_error_t err = _at->at_cmd_str("+CPIN", "?", buf, 13); nsapi_error_t err = _at.at_cmd_str("+CPIN", "?", buf, 13);
tr_debug("CPIN: %s", buf); tr_debug("CPIN: %s", buf);
_at->unlock(); _at.unlock();
if (memcmp(buf, "READY", 5) == 0) { if (memcmp(buf, "READY", 5) == 0) {
state = SimStateReady; state = SimStateReady;
@ -89,7 +89,7 @@ AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *
nsapi_error_t QUECTEL_M26::shutdown() nsapi_error_t QUECTEL_M26::shutdown()
{ {
return _at->at_cmd_discard("+QPOWD", "=0"); return _at.at_cmd_discard("+QPOWD", "=0");
} }

View File

@ -74,18 +74,18 @@ nsapi_error_t RM1000_AT::init()
{ {
tr_debug("RM1000_AT::init"); tr_debug("RM1000_AT::init");
_at->lock(); _at.lock();
_at->flush(); _at.flush();
_at->at_cmd_discard("E0", ""); // echo off _at.at_cmd_discard("E0", ""); // echo off
_at->at_cmd_discard("+SIM", "=physical"); _at.at_cmd_discard("+SIM", "=physical");
_at->set_at_timeout(5000); _at.set_at_timeout(5000);
_at->at_cmd_discard("+CFUN", "=1"); // set full functionality _at.at_cmd_discard("+CFUN", "=1"); // set full functionality
_at->at_cmd_discard("+VERBOSE", "=0"); // verbose responses _at.at_cmd_discard("+VERBOSE", "=0"); // verbose responses
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
#if MBED_CONF_RM1000_AT_PROVIDE_DEFAULT #if MBED_CONF_RM1000_AT_PROVIDE_DEFAULT

View File

@ -55,7 +55,7 @@ nsapi_error_t TELIT_HE910::init()
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
return err; return err;
} }
return _at->at_cmd_discard("&K0;&C1;&D0", ""); return _at.at_cmd_discard("&K0;&C1;&D0", "");
} }
#if MBED_CONF_TELIT_HE910_PROVIDE_DEFAULT #if MBED_CONF_TELIT_HE910_PROVIDE_DEFAULT

View File

@ -84,11 +84,11 @@ nsapi_error_t TELIT_ME910::init()
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
return err; return err;
} }
_at->lock(); _at.lock();
#if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS) #if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS)
_at->at_cmd_discard("&K3;&C1;&D0", ""); _at.at_cmd_discard("&K3;&C1;&D0", "");
#else #else
_at->at_cmd_discard("&K0;&C1;&D0", ""); _at.at_cmd_discard("&K0;&C1;&D0", "");
#endif #endif
// AT#QSS=1 // AT#QSS=1
@ -100,7 +100,7 @@ nsapi_error_t TELIT_ME910::init()
// <status> values: // <status> values:
// - 0: SIM not inserted // - 0: SIM not inserted
// - 1: SIM inserted // - 1: SIM inserted
_at->at_cmd_discard("#QSS", "=1"); _at.at_cmd_discard("#QSS", "=1");
// AT#PSNT=1 // AT#PSNT=1
// Set command enables unsolicited result code for packet service network type (PSNT) // Set command enables unsolicited result code for packet service network type (PSNT)
@ -110,7 +110,7 @@ nsapi_error_t TELIT_ME910::init()
// - 0: GPRS network // - 0: GPRS network
// - 4: LTE network // - 4: LTE network
// - 5: unknown or not registered // - 5: unknown or not registered
_at->at_cmd_discard("#PSNT", "=1"); _at.at_cmd_discard("#PSNT", "=1");
// AT+CMER=2 // AT+CMER=2
// Set command enables sending of unsolicited result codes from TA to TE in the case of // Set command enables sending of unsolicited result codes from TA to TE in the case of
@ -118,7 +118,7 @@ nsapi_error_t TELIT_ME910::init()
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is // Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
// reserved (e.g. on-line data mode) and flush them to the TE after // reserved (e.g. on-line data mode) and flush them to the TE after
// reservation; otherwise forward them directly to the TE // reservation; otherwise forward them directly to the TE
_at->at_cmd_discard("+CMER", "=2"); _at.at_cmd_discard("+CMER", "=2");
// AT+CMEE=2 // AT+CMEE=2
// Set command disables the use of result code +CME ERROR: <err> as an indication of an // Set command disables the use of result code +CME ERROR: <err> as an indication of an
@ -126,16 +126,16 @@ nsapi_error_t TELIT_ME910::init()
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned // ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
// normally when the error message is related to syntax, invalid parameters or DTE functionality. // normally when the error message is related to syntax, invalid parameters or DTE functionality.
// Current setting: enable and use verbose <err> values // Current setting: enable and use verbose <err> values
_at->at_cmd_discard("+CMEE", "=2"); _at.at_cmd_discard("+CMEE", "=2");
// AT&W&P // AT&W&P
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If // - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
// parameter is omitted, the command has the same behavior of AT&W0. // parameter is omitted, the command has the same behavior of AT&W0.
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter // - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
// is omitted, the command has the same behavior as AT&P0 // is omitted, the command has the same behavior as AT&P0
_at->at_cmd_discard("&W&P", ""); _at.at_cmd_discard("&W&P", "");
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
#if MBED_CONF_TELIT_ME910_PROVIDE_DEFAULT #if MBED_CONF_TELIT_ME910_PROVIDE_DEFAULT

View File

@ -129,9 +129,9 @@ nsapi_error_t UBLOX_AT::init()
{ {
setup_at_handler(); setup_at_handler();
_at->lock(); _at.lock();
_at->flush(); _at.flush();
_at->at_cmd_discard("", ""); _at.at_cmd_discard("", "");
int value = -1; int value = -1;
#ifdef UBX_MDM_SARA_G3XX #ifdef UBX_MDM_SARA_G3XX
@ -139,19 +139,19 @@ nsapi_error_t UBLOX_AT::init()
#elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_R41XM) #elif defined(UBX_MDM_SARA_U2XX) || defined(UBX_MDM_SARA_R41XM)
value = 4; value = 4;
#else #else
_at->unlock(); _at.unlock();
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
#endif #endif
nsapi_error_t err = _at->at_cmd_discard("+CFUN", "=", "%d", value); nsapi_error_t err = _at.at_cmd_discard("+CFUN", "=", "%d", value);
if (err == NSAPI_ERROR_OK) { if (err == NSAPI_ERROR_OK) {
_at->at_cmd_discard("E0", ""); // echo off _at.at_cmd_discard("E0", ""); // echo off
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses _at.at_cmd_discard("+CMEE", "=1"); // verbose responses
config_authentication_parameters(); config_authentication_parameters();
err = _at->at_cmd_discard("+CFUN", "=1"); // set full functionality err = _at.at_cmd_discard("+CFUN", "=1"); // set full functionality
} }
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
nsapi_error_t UBLOX_AT::config_authentication_parameters() nsapi_error_t UBLOX_AT::config_authentication_parameters()
@ -191,19 +191,19 @@ nsapi_error_t UBLOX_AT::set_authentication_parameters(const char *apn,
{ {
int modem_security = ubx_context->nsapi_security_to_modem_security(auth); int modem_security = ubx_context->nsapi_security_to_modem_security(auth);
nsapi_error_t err = _at->at_cmd_discard("+CGDCONT", "=", "%d%s%s", 1, "IP", apn); nsapi_error_t err = _at.at_cmd_discard("+CGDCONT", "=", "%d%s%s", 1, "IP", apn);
if (err == NSAPI_ERROR_OK) { if (err == NSAPI_ERROR_OK) {
#ifdef UBX_MDM_SARA_R41XM #ifdef UBX_MDM_SARA_R41XM
if (modem_security == CellularContext::CHAP) { if (modem_security == CellularContext::CHAP) {
err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, password, username); err = _at.at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, password, username);
} else if (modem_security == CellularContext::NOAUTH) { } else if (modem_security == CellularContext::NOAUTH) {
err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d", 1, modem_security); err = _at.at_cmd_discard("+UAUTHREQ", "=", "%d%d", 1, modem_security);
} else { } else {
err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password); err = _at.at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password);
} }
#else #else
err = _at->at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password); err = _at.at_cmd_discard("+UAUTHREQ", "=", "%d%d%s%s", 1, modem_security, username, password);
#endif #endif
} }
@ -213,5 +213,5 @@ nsapi_error_t UBLOX_AT::set_authentication_parameters(const char *apn,
nsapi_error_t UBLOX_AT::get_imsi(char *imsi) nsapi_error_t UBLOX_AT::get_imsi(char *imsi)
{ {
//Special case: Command put in cmd_chr to make a 1 liner //Special case: Command put in cmd_chr to make a 1 liner
return _at->at_cmd_str("", "+CIMI", imsi, MAX_IMSI_LENGTH + 1); return _at.at_cmd_str("", "+CIMI", imsi, MAX_IMSI_LENGTH + 1);
} }

View File

@ -51,18 +51,18 @@ UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh)
void UBLOX_N2XX::set_at_urcs_impl() void UBLOX_N2XX::set_at_urcs_impl()
{ {
_at->set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC)); _at.set_urc_handler("+NPIN:", mbed::Callback<void()>(this, &UBLOX_N2XX::NPIN_URC));
} }
UBLOX_N2XX::~UBLOX_N2XX() UBLOX_N2XX::~UBLOX_N2XX()
{ {
_at->set_urc_handler("+NPIN:", nullptr); _at.set_urc_handler("+NPIN:", nullptr);
} }
// Callback for Sim Pin. // Callback for Sim Pin.
void UBLOX_N2XX::NPIN_URC() void UBLOX_N2XX::NPIN_URC()
{ {
_at->read_string(simstr, sizeof(simstr)); _at.read_string(simstr, sizeof(simstr));
} }
AT_CellularNetwork *UBLOX_N2XX::open_network_impl(ATHandler &at) AT_CellularNetwork *UBLOX_N2XX::open_network_impl(ATHandler &at)
@ -86,27 +86,27 @@ nsapi_error_t UBLOX_N2XX::init()
{ {
setup_at_handler(); setup_at_handler();
_at->lock(); _at.lock();
_at->flush(); _at.flush();
_at->at_cmd_discard("", ""); _at.at_cmd_discard("", "");
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses _at.at_cmd_discard("+CMEE", "=1"); // verbose responses
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN #ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
set_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN); set_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
#endif #endif
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
nsapi_error_t UBLOX_N2XX::get_sim_state(SimState &state) nsapi_error_t UBLOX_N2XX::get_sim_state(SimState &state)
{ {
nsapi_error_t error = NSAPI_ERROR_DEVICE_ERROR; nsapi_error_t error = NSAPI_ERROR_DEVICE_ERROR;
_at->lock(); _at.lock();
_at->flush(); _at.flush();
//Special case: Command put in cmd_chr to make a 1 liner //Special case: Command put in cmd_chr to make a 1 liner
error = _at->at_cmd_str("", "+CFUN=1", simstr, sizeof(simstr)); error = _at.at_cmd_str("", "+CFUN=1", simstr, sizeof(simstr));
_at->unlock(); _at.unlock();
int len = strlen(simstr); int len = strlen(simstr);
if (len > 0 || error == NSAPI_ERROR_OK) { if (len > 0 || error == NSAPI_ERROR_OK) {
@ -157,7 +157,7 @@ nsapi_error_t UBLOX_N2XX::set_pin(const char *sim_pin)
return NSAPI_ERROR_PARAMETER; return NSAPI_ERROR_PARAMETER;
} }
return _at->at_cmd_discard("+NPIN", "=", "%d%s", 0, sim_pin); return _at.at_cmd_discard("+NPIN", "=", "%d%s", 0, sim_pin);
} }
#if MBED_CONF_UBLOX_N2XX_PROVIDE_DEFAULT #if MBED_CONF_UBLOX_N2XX_PROVIDE_DEFAULT

View File

@ -67,11 +67,11 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
return err; return err;
} }
_at->lock(); _at.lock();
#if DEVICE_SERIAL_FC #if DEVICE_SERIAL_FC
_at->at_cmd_discard("&K3;&C1;&D0", ""); _at.at_cmd_discard("&K3;&C1;&D0", "");
#else #else
_at->at_cmd_discard("&K0;&C1;&D0", ""); _at.at_cmd_discard("&K0;&C1;&D0", "");
#endif #endif
// AT#QSS=1 // AT#QSS=1
@ -83,7 +83,7 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
// <status> values: // <status> values:
// - 0: SIM not inserted // - 0: SIM not inserted
// - 1: SIM inserted // - 1: SIM inserted
_at->at_cmd_discard("#QSS", "=1"); _at.at_cmd_discard("#QSS", "=1");
// AT#PSNT=1 // AT#PSNT=1
// Set command enables unsolicited result code for packet service network type (PSNT) // Set command enables unsolicited result code for packet service network type (PSNT)
@ -93,7 +93,7 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
// - 0: GPRS network // - 0: GPRS network
// - 4: LTE network // - 4: LTE network
// - 5: unknown or not registered // - 5: unknown or not registered
_at->at_cmd_discard("#PSNT", "=1"); _at.at_cmd_discard("#PSNT", "=1");
// AT+CMER=2 // AT+CMER=2
// Set command enables sending of unsolicited result codes from TA to TE in the case of // Set command enables sending of unsolicited result codes from TA to TE in the case of
@ -101,7 +101,7 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
// Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is // Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
// reserved (e.g. on-line data mode) and flush them to the TE after // reserved (e.g. on-line data mode) and flush them to the TE after
// reservation; otherwise forward them directly to the TE // reservation; otherwise forward them directly to the TE
_at->at_cmd_discard("+CMER", "=2"); _at.at_cmd_discard("+CMER", "=2");
// AT+CMEE=2 // AT+CMEE=2
// Set command disables the use of result code +CME ERROR: <err> as an indication of an // Set command disables the use of result code +CME ERROR: <err> as an indication of an
@ -109,21 +109,21 @@ nsapi_error_t ONBOARD_TELIT_ME910::init()
// ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned // ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
// normally when the error message is related to syntax, invalid parameters or DTE functionality. // normally when the error message is related to syntax, invalid parameters or DTE functionality.
// Current setting: enable and use verbose <err> values // Current setting: enable and use verbose <err> values
_at->at_cmd_discard("+CMEE", "=2"); _at.at_cmd_discard("+CMEE", "=2");
// AT#PORTCFG=0 // AT#PORTCFG=0
// Set command allows to connect Service Access Points to the external physical ports giving a great // Set command allows to connect Service Access Points to the external physical ports giving a great
// flexibility. Examples of Service Access Points: AT Parser Instance #1, #2, #3, etc.. // flexibility. Examples of Service Access Points: AT Parser Instance #1, #2, #3, etc..
_at->at_cmd_discard("#PORTCFG", "=", "%d", EP_AGORA_PORT_CONFIGURATION_VARIANT); _at.at_cmd_discard("#PORTCFG", "=", "%d", EP_AGORA_PORT_CONFIGURATION_VARIANT);
// AT&W&P // AT&W&P
// - AT&W: Execution command stores on profile <n> the complete configuration of the device. If // - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
// parameter is omitted, the command has the same behavior of AT&W0. // parameter is omitted, the command has the same behavior of AT&W0.
// - AT&P: Execution command defines which full profile will be loaded at startup. If parameter // - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
// is omitted, the command has the same behavior as AT&P0 // is omitted, the command has the same behavior as AT&P0
_at->at_cmd_discard("&W&P", ""); _at.at_cmd_discard("&W&P", "");
return _at->unlock_return_error(); return _at.unlock_return_error();
} }
void ONBOARD_TELIT_ME910::press_power_button(int time_ms) void ONBOARD_TELIT_ME910::press_power_button(int time_ms)