mirror of https://github.com/ARMmbed/mbed-os.git
Valgrind & unittest fixes
parent
e19249f276
commit
1ed338ef28
|
@ -16,7 +16,6 @@ set(unittest-includes ${unittest-includes}
|
||||||
# Source files
|
# Source files
|
||||||
set(unittest-sources
|
set(unittest-sources
|
||||||
../features/cellular/framework/AT/AT_CellularBase.cpp
|
../features/cellular/framework/AT/AT_CellularBase.cpp
|
||||||
../features/cellular/framework/AT/ATHandler_factory.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include "CellularDevice_stub.h"
|
#include "CellularDevice_stub.h"
|
||||||
#include "equeue_stub.h"
|
#include "equeue_stub.h"
|
||||||
#include "AT_CellularBase_stub.h"
|
#include "AT_CellularBase_stub.h"
|
||||||
|
#include "CellularUtil_stub.h"
|
||||||
|
#include "PinNames.h"
|
||||||
|
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
using namespace events;
|
using namespace events;
|
||||||
|
@ -62,6 +64,9 @@ protected:
|
||||||
ATHandler_stub::read_string_table[kRead_string_table_size];
|
ATHandler_stub::read_string_table[kRead_string_table_size];
|
||||||
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
|
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
|
||||||
CellularDevice_stub::connect_counter = 2;
|
CellularDevice_stub::connect_counter = 2;
|
||||||
|
|
||||||
|
CellularUtil_stub::char_table[0] = (char *)"\0";
|
||||||
|
CellularUtil_stub::table_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown()
|
void TearDown()
|
||||||
|
@ -131,6 +136,16 @@ public:
|
||||||
AT_CellularContext::cellular_callback(ev, ptr);
|
AT_CellularContext::cellular_callback(ev, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void activ_non_ip_context()
|
||||||
|
{
|
||||||
|
activate_non_ip_context();
|
||||||
|
}
|
||||||
|
|
||||||
|
void deactiv_non_ip_context()
|
||||||
|
{
|
||||||
|
deactivate_non_ip_context();
|
||||||
|
}
|
||||||
|
|
||||||
my_stack _st;
|
my_stack _st;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,6 +165,19 @@ public:
|
||||||
my_stack _st;
|
my_stack _st;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class def_AT_CTX : public AT_CellularContext {
|
||||||
|
public:
|
||||||
|
def_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
|
||||||
|
AT_CellularContext(at, device, apn) {}
|
||||||
|
virtual ~def_AT_CTX() {}
|
||||||
|
|
||||||
|
uint32_t do_op()
|
||||||
|
{
|
||||||
|
return AT_CellularContext::get_timeout_for_operation(mbed::CellularContext::ContextOperation(_op));
|
||||||
|
}
|
||||||
|
int _op;
|
||||||
|
};
|
||||||
|
|
||||||
static int network_cb_count;
|
static int network_cb_count;
|
||||||
static void network_cb(nsapi_event_t ev, intptr_t intptr)
|
static void network_cb(nsapi_event_t ev, intptr_t intptr)
|
||||||
{
|
{
|
||||||
|
@ -169,6 +197,9 @@ TEST_F(TestAT_CellularContext, Create)
|
||||||
|
|
||||||
ctx = new AT_CellularContext(at, &dev);
|
ctx = new AT_CellularContext(at, &dev);
|
||||||
EXPECT_TRUE(ctx != NULL);
|
EXPECT_TRUE(ctx != NULL);
|
||||||
|
|
||||||
|
ctx->get_device();
|
||||||
|
EXPECT_EQ(NSAPI_STATUS_DISCONNECTED, ctx->get_connection_status());
|
||||||
delete ctx;
|
delete ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +356,20 @@ TEST_F(TestAT_CellularContext, get_pdpcontext_params)
|
||||||
ATHandler_stub::read_string_table[1] = (char *)"25.66.77.88";
|
ATHandler_stub::read_string_table[1] = (char *)"25.66.77.88";
|
||||||
ATHandler_stub::read_string_table[0] = (char *)"004.003.002.001";
|
ATHandler_stub::read_string_table[0] = (char *)"004.003.002.001";
|
||||||
|
|
||||||
|
CellularUtil_stub::table_idx = 12;
|
||||||
|
CellularUtil_stub::char_table[11] = (char *)"102:304:506:708:90A:B70:D0E:F10\0";
|
||||||
|
CellularUtil_stub::char_table[10] = (char *)"102:32C:3706:708:90A:B0C:D0E:F10\0";
|
||||||
|
CellularUtil_stub::char_table[9] = (char *)"1721:2C01:203:377B:E122:B01:000:7BEA\0";
|
||||||
|
CellularUtil_stub::char_table[8] = (char *)"1.2.3.4\0";
|
||||||
|
CellularUtil_stub::char_table[7] = (char *)"1.2.3.4\0";
|
||||||
|
CellularUtil_stub::char_table[6] = (char *)"1.2.3.4\0";
|
||||||
|
CellularUtil_stub::char_table[5] = (char *)"0.255.0.255\0";
|
||||||
|
CellularUtil_stub::char_table[4] = (char *)"1.2.3.4\0";
|
||||||
|
CellularUtil_stub::char_table[3] = (char *)"25.66.77.88\0";
|
||||||
|
CellularUtil_stub::char_table[2] = (char *)"1.2.3.4\0";
|
||||||
|
CellularUtil_stub::char_table[1] = (char *)"004.003.002.001\0";
|
||||||
|
CellularUtil_stub::char_table[0] = (char *)"1.2.3.4\0";
|
||||||
|
|
||||||
EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list));
|
EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list));
|
||||||
CellularContext::pdpcontext_params_t *params = list.get_head();
|
CellularContext::pdpcontext_params_t *params = list.get_head();
|
||||||
EXPECT_TRUE(params != NULL);
|
EXPECT_TRUE(params != NULL);
|
||||||
|
@ -457,6 +502,11 @@ TEST_F(TestAT_CellularContext, set_file_handle)
|
||||||
AT_CellularDevice dev(&fh1);
|
AT_CellularDevice dev(&fh1);
|
||||||
AT_CellularContext ctx(at, &dev);
|
AT_CellularContext ctx(at, &dev);
|
||||||
ctx.set_file_handle(&fh1);
|
ctx.set_file_handle(&fh1);
|
||||||
|
|
||||||
|
UARTSerial 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)
|
||||||
|
@ -481,10 +531,44 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
|
||||||
data.error = NSAPI_ERROR_OK;
|
data.error = NSAPI_ERROR_OK;
|
||||||
ctx1.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
ctx1.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
||||||
|
|
||||||
|
ATHandler_stub::resp_info_true_counter = 1;
|
||||||
|
ATHandler_stub::read_string_table[0] = (char *)"APN";
|
||||||
|
ATHandler_stub::read_string_table[1] = (char *)"IP";
|
||||||
|
ATHandler_stub::read_string_index = 2;
|
||||||
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
||||||
|
|
||||||
ASSERT_EQ(network_cb_count, 5);
|
ASSERT_EQ(network_cb_count, 5);
|
||||||
|
|
||||||
|
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
|
||||||
|
ATHandler_stub::resp_info_true_counter = 1;
|
||||||
|
ATHandler_stub::read_string_table[1] = (char *)"Non-IP";
|
||||||
|
ATHandler_stub::read_string_index = 2;
|
||||||
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
|
||||||
|
ATHandler_stub::resp_info_true_counter = 1;
|
||||||
|
ATHandler_stub::read_string_table[1] = (char *)"IPV6";
|
||||||
|
ATHandler_stub::read_string_index = 2;
|
||||||
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
||||||
|
|
||||||
|
AT_CellularBase_stub::supported_bool = true;
|
||||||
|
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
|
||||||
|
ATHandler_stub::resp_info_true_counter = 1;
|
||||||
|
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
|
||||||
|
ATHandler_stub::read_string_index = 2;
|
||||||
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
||||||
|
AT_CellularBase_stub::supported_bool = false;
|
||||||
|
|
||||||
|
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
|
||||||
|
ATHandler_stub::resp_info_true_counter = 1;
|
||||||
|
ATHandler_stub::read_string_table[0] = (char *)"APN2";
|
||||||
|
ATHandler_stub::read_string_table[1] = (char *)"IPV4V6";
|
||||||
|
ATHandler_stub::read_string_index = 2;
|
||||||
|
ATHandler_stub::int_value = 10;
|
||||||
|
ctx1.set_credentials("APN");
|
||||||
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_OK);
|
||||||
|
ATHandler_stub::int_value = -1;
|
||||||
|
|
||||||
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_IS_CONNECTED);
|
ASSERT_EQ(ctx1.connect(), NSAPI_ERROR_IS_CONNECTED);
|
||||||
|
|
||||||
EXPECT_TRUE(ctx1.is_connected() == true);
|
EXPECT_TRUE(ctx1.is_connected() == true);
|
||||||
|
@ -519,6 +603,26 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
|
||||||
// More connect test after we are re-writted getting of PDP context...
|
// More connect test after we are re-writted getting of PDP context...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestAT_CellularContext, de_and_activate_non_ip_context)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
AT_CellularDevice dev(&fh1);
|
||||||
|
my_AT_CTX ctx(at, &dev);
|
||||||
|
ctx.attach(&network_cb);
|
||||||
|
Semaphore_stub::acquire_return_value = true;
|
||||||
|
|
||||||
|
// call callback so that network is opened which is needed in disconnect
|
||||||
|
cell_callback_data_t data;
|
||||||
|
data.error = NSAPI_ERROR_OK;
|
||||||
|
ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
||||||
|
|
||||||
|
ctx.activ_non_ip_context();
|
||||||
|
|
||||||
|
ctx.deactiv_non_ip_context();
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularContext, set_device_ready_sync)
|
TEST_F(TestAT_CellularContext, set_device_ready_sync)
|
||||||
{
|
{
|
||||||
EventQueue que;
|
EventQueue que;
|
||||||
|
@ -618,3 +722,22 @@ TEST_F(TestAT_CellularContext, connect_disconnect_async)
|
||||||
|
|
||||||
// More connect test after we are re-writted getting of PDP context...
|
// More connect test after we are re-writted getting of PDP context...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestAT_CellularContext, get_timeout_for_operation)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
|
||||||
|
AT_CellularDevice dev(&fh1);
|
||||||
|
def_AT_CTX ctx1(at, &dev);
|
||||||
|
ctx1._op = 1;
|
||||||
|
EXPECT_EQ(300 * 1000, ctx1.do_op());
|
||||||
|
|
||||||
|
ctx1._op = 0;
|
||||||
|
EXPECT_EQ(300 * 1000, ctx1.do_op());
|
||||||
|
|
||||||
|
ctx1._op = -1;
|
||||||
|
EXPECT_EQ(1800 * 1000, ctx1.do_op());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ set(unittest-includes ${unittest-includes}
|
||||||
# Source files
|
# Source files
|
||||||
set(unittest-sources
|
set(unittest-sources
|
||||||
../features/cellular/framework/AT/AT_CellularContext.cpp
|
../features/cellular/framework/AT/AT_CellularContext.cpp
|
||||||
../features/cellular/framework/AT/ATHandler_factory.cpp
|
|
||||||
../features/cellular/framework/common/CellularUtil.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
|
@ -42,4 +40,5 @@ set(unittest-test-sources
|
||||||
stubs/UARTSerial_stub.cpp
|
stubs/UARTSerial_stub.cpp
|
||||||
stubs/SerialBase_stub.cpp
|
stubs/SerialBase_stub.cpp
|
||||||
stubs/CellularContext_stub.cpp
|
stubs/CellularContext_stub.cpp
|
||||||
|
stubs/CellularUtil_stub.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,22 +28,36 @@ protected:
|
||||||
|
|
||||||
void SetUp()
|
void SetUp()
|
||||||
{
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
filehandle_stub_table = NULL;
|
||||||
|
filehandle_stub_table_pos = 0;
|
||||||
|
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
ATHandler_stub::handler = &at;
|
||||||
|
|
||||||
|
ATHandler_stub::read_string_index = kRead_string_table_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown()
|
void TearDown()
|
||||||
{
|
{
|
||||||
|
ATHandler_stub::handler = NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(TestAT_CellularDevice, Create)
|
TEST_F(TestAT_CellularDevice, Create)
|
||||||
{
|
{
|
||||||
FileHandle_stub fh1;
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
AT_CellularDevice dev(&fh1);
|
AT_CellularDevice dev(&fh1);
|
||||||
|
|
||||||
CellularDevice *dev2 = new AT_CellularDevice(&fh1);
|
CellularDevice *dev2 = new AT_CellularDevice(&fh1);
|
||||||
|
|
||||||
EXPECT_TRUE(dev2 != NULL);
|
EXPECT_TRUE(dev2 != NULL);
|
||||||
delete dev2;
|
delete dev2;
|
||||||
|
ATHandler *at = dev.get_at_handler(&fh1);
|
||||||
|
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)
|
||||||
|
@ -54,6 +68,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
||||||
AT_CellularDevice dev(&fh1); // AT fh1 ref count 1
|
AT_CellularDevice dev(&fh1); // AT fh1 ref count 1
|
||||||
|
|
||||||
EXPECT_TRUE(dev.open_network(&fh1)); // AT fh1 ref count 2
|
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_sms(&fh2));
|
||||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||||
EXPECT_TRUE(dev.open_information(&fh3));
|
EXPECT_TRUE(dev.open_information(&fh3));
|
||||||
|
@ -64,12 +79,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
||||||
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
|
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
|
||||||
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
|
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
|
||||||
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
|
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
|
||||||
EXPECT_TRUE(at->get_ref_count() == 5);
|
EXPECT_EQ(at->get_ref_count(), 6);
|
||||||
delete dev2; // AT fh1 2 refs deleted -> ref count 3
|
delete dev2; // AT fh1 2 refs deleted -> ref count 3
|
||||||
EXPECT_TRUE(at->get_ref_count() == 3);
|
EXPECT_EQ(at->get_ref_count(), 4);
|
||||||
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
|
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
|
||||||
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
|
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
|
||||||
EXPECT_TRUE(ATHandler_stub::ref_count == 3);
|
EXPECT_EQ(ATHandler_stub::ref_count, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
|
||||||
|
@ -118,10 +133,9 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
|
||||||
|
|
||||||
EXPECT_TRUE(dev.open_network(&fh1));
|
EXPECT_TRUE(dev.open_network(&fh1));
|
||||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||||
EXPECT_TRUE(ATHandler_stub::ref_count == 2);
|
EXPECT_EQ(ATHandler_stub::ref_count, 1);
|
||||||
|
|
||||||
dev.close_network();
|
dev.close_network();
|
||||||
EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
||||||
|
@ -131,10 +145,9 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
||||||
|
|
||||||
EXPECT_TRUE(dev.open_sms(&fh1));
|
EXPECT_TRUE(dev.open_sms(&fh1));
|
||||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||||
EXPECT_TRUE(ATHandler_stub::ref_count == 2);
|
EXPECT_EQ(ATHandler_stub::ref_count, 1);
|
||||||
|
|
||||||
dev.close_sms();
|
dev.close_sms();
|
||||||
EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
||||||
|
@ -158,7 +171,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
||||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||||
|
|
||||||
dev.close_information();
|
dev.close_information();
|
||||||
EXPECT_TRUE(ATHANDLER_REF_COUNT_AT_DESTRUCTOR == kATHandler_destructor_ref_ount);
|
|
||||||
|
|
||||||
ATHandler_stub::fh_value = NULL;
|
ATHandler_stub::fh_value = NULL;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +187,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
||||||
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(&fh1));
|
||||||
EXPECT_TRUE(ATHandler_stub::ref_count == 2);
|
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);
|
||||||
|
@ -194,7 +206,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
||||||
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(&fh1));
|
||||||
EXPECT_TRUE(ATHandler_stub::ref_count == 2);
|
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);
|
||||||
|
@ -268,7 +280,7 @@ 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(at->get_ref_count() == 2);
|
EXPECT_EQ(at->get_ref_count(), 1);
|
||||||
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
|
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
CellularContext *ctx = dev->create_context(NULL);
|
CellularContext *ctx = dev->create_context(NULL);
|
||||||
|
@ -276,12 +288,12 @@ 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();
|
||||||
EXPECT_TRUE(at->get_ref_count() == 2);
|
EXPECT_EQ(at->get_ref_count(), 1);
|
||||||
ctx = dev->create_context(NULL);
|
ctx = dev->create_context(NULL);
|
||||||
CellularContext *ctx1 = dev->create_context(&fh1);
|
CellularContext *ctx1 = dev->create_context(&fh1);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 4);
|
EXPECT_EQ(at->get_ref_count(), 3);
|
||||||
CellularContext *ctx2 = dev->create_context(&fh1);
|
CellularContext *ctx2 = dev->create_context(&fh1);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 5);
|
EXPECT_EQ(at->get_ref_count(), 4);
|
||||||
|
|
||||||
EXPECT_TRUE(ctx);
|
EXPECT_TRUE(ctx);
|
||||||
EXPECT_TRUE(ctx1);
|
EXPECT_TRUE(ctx1);
|
||||||
|
@ -292,20 +304,20 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
|
||||||
EXPECT_TRUE(xx);
|
EXPECT_TRUE(xx);
|
||||||
|
|
||||||
dev->delete_context(ctx);
|
dev->delete_context(ctx);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 4);
|
EXPECT_EQ(at->get_ref_count(), 3);
|
||||||
dev->delete_context(ctx1);
|
dev->delete_context(ctx1);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 3);
|
EXPECT_EQ(at->get_ref_count(), 2);
|
||||||
dev->delete_context(NULL);
|
dev->delete_context(NULL);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 3);
|
EXPECT_EQ(at->get_ref_count(), 2);
|
||||||
dev->delete_context(ctx2);
|
dev->delete_context(ctx2);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 2);
|
EXPECT_EQ(at->get_ref_count(), 1);
|
||||||
|
|
||||||
ctx = dev->create_context(NULL);
|
ctx = dev->create_context(NULL);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 3);
|
EXPECT_EQ(at->get_ref_count(), 2);
|
||||||
ctx1 = dev->create_context(&fh1);
|
ctx1 = dev->create_context(&fh1);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 4);
|
EXPECT_EQ(at->get_ref_count(), 3);
|
||||||
ctx2 = dev->create_context(&fh1);
|
ctx2 = dev->create_context(&fh1);
|
||||||
EXPECT_TRUE(at->get_ref_count() == 5);
|
EXPECT_EQ(at->get_ref_count(), 4);
|
||||||
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
|
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
|
||||||
EXPECT_TRUE(ctx);
|
EXPECT_TRUE(ctx);
|
||||||
EXPECT_TRUE(ctx1);
|
EXPECT_TRUE(ctx1);
|
||||||
|
@ -322,6 +334,9 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_set_pin_verify_debug)
|
||||||
ATHandler at(&fh1, que, 0, ",");
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
|
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
|
||||||
|
|
||||||
|
ATHandler_stub::ssize_value = 8;
|
||||||
|
ATHandler_stub::read_string_value = (char *)"internet";
|
||||||
|
|
||||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||||
ATHandler_stub::get_debug_clear();
|
ATHandler_stub::get_debug_clear();
|
||||||
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
|
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
|
||||||
|
@ -375,6 +390,9 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state)
|
||||||
FileHandle_stub fh1;
|
FileHandle_stub fh1;
|
||||||
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
|
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
|
||||||
|
|
||||||
|
ATHandler_stub::ssize_value = 8;
|
||||||
|
ATHandler_stub::read_string_value = (char *)"internet";
|
||||||
|
|
||||||
CellularDevice::SimState state;
|
CellularDevice::SimState state;
|
||||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||||
ATHandler_stub::ssize_value = -1;
|
ATHandler_stub::ssize_value = -1;
|
||||||
|
|
|
@ -19,7 +19,6 @@ set(unittest-includes ${unittest-includes}
|
||||||
set(unittest-sources
|
set(unittest-sources
|
||||||
stubs/randLIB_stub.c
|
stubs/randLIB_stub.c
|
||||||
../features/cellular/framework/AT/AT_CellularDevice.cpp
|
../features/cellular/framework/AT/AT_CellularDevice.cpp
|
||||||
../features/cellular/framework/AT/ATHandler_factory.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "FileHandle_stub.h"
|
#include "FileHandle_stub.h"
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
#include "mbed_poll_stub.h"
|
#include "mbed_poll_stub.h"
|
||||||
|
#include "CellularUtil_stub.h"
|
||||||
|
|
||||||
#include "Timer_stub.h"
|
#include "Timer_stub.h"
|
||||||
|
|
||||||
|
@ -48,6 +49,8 @@ protected:
|
||||||
void SetUp()
|
void SetUp()
|
||||||
{
|
{
|
||||||
urc_callback_count = 0;
|
urc_callback_count = 0;
|
||||||
|
CellularUtil_stub::char_ptr = NULL;
|
||||||
|
CellularUtil_stub::char_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown()
|
void TearDown()
|
||||||
|
@ -62,6 +65,8 @@ TEST_F(TestATHandler, Create)
|
||||||
FileHandle_stub fh1;
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
ATHandler *at = new ATHandler(&fh1, que, 0, ",");
|
ATHandler *at = new ATHandler(&fh1, que, 0, ",");
|
||||||
|
at->set_default_delimiter();
|
||||||
|
at->use_delimiter(true);
|
||||||
|
|
||||||
delete at;
|
delete at;
|
||||||
|
|
||||||
|
@ -774,12 +779,20 @@ TEST_F(TestATHandler, test_ATHandler_read_string)
|
||||||
EXPECT_TRUE(!strncmp(buf4, "1016", 4));
|
EXPECT_TRUE(!strncmp(buf4, "1016", 4));
|
||||||
EXPECT_TRUE(4 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
EXPECT_TRUE(4 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||||
EXPECT_TRUE(!strncmp(buf4, "39AB", 4));
|
EXPECT_TRUE(!strncmp(buf4, "39AB", 4));
|
||||||
|
at.set_is_filehandle_usable(false);
|
||||||
|
EXPECT_TRUE(-1 == at.read_int());
|
||||||
|
at.set_is_filehandle_usable(true);
|
||||||
|
at.clear_error();
|
||||||
EXPECT_TRUE(9 == at.read_int());
|
EXPECT_TRUE(9 == at.read_int());
|
||||||
|
|
||||||
// *** CRLF part of the string ***
|
// *** CRLF part of the string ***
|
||||||
at.clear_error();
|
at.clear_error();
|
||||||
char table11[] = "\"s\"\r\nOK\r\n\0";
|
char table11[] = "\"s\"\r\nOK\r\n\0";
|
||||||
mbed_poll_stub::int_value = 0;
|
mbed_poll_stub::int_value = 0;
|
||||||
|
at.set_is_filehandle_usable(false);
|
||||||
|
at.flush();
|
||||||
|
at.set_is_filehandle_usable(true);
|
||||||
|
at.clear_error();
|
||||||
at.flush();
|
at.flush();
|
||||||
filehandle_stub_table = table11;
|
filehandle_stub_table = table11;
|
||||||
filehandle_stub_table_pos = 0;
|
filehandle_stub_table_pos = 0;
|
||||||
|
@ -840,6 +853,10 @@ TEST_F(TestATHandler, test_ATHandler_read_hex_string)
|
||||||
char buf1[10];
|
char buf1[10];
|
||||||
// Set _stop_tag to resp_stop(OKCRLF)
|
// Set _stop_tag to resp_stop(OKCRLF)
|
||||||
at.resp_start();
|
at.resp_start();
|
||||||
|
char resp[] = "hello\0";
|
||||||
|
CellularUtil_stub::char_ptr = resp;
|
||||||
|
CellularUtil_stub::char_pos = 0;
|
||||||
|
|
||||||
EXPECT_TRUE(5 == at.read_hex_string(buf1, 5));
|
EXPECT_TRUE(5 == at.read_hex_string(buf1, 5));
|
||||||
EXPECT_TRUE(!strncmp(buf1, "hello", 5));
|
EXPECT_TRUE(!strncmp(buf1, "hello", 5));
|
||||||
|
|
||||||
|
@ -854,6 +871,7 @@ TEST_F(TestATHandler, test_ATHandler_read_hex_string)
|
||||||
char buf2[10];
|
char buf2[10];
|
||||||
// Set _stop_tag to resp_stop(OKCRLF)
|
// Set _stop_tag to resp_stop(OKCRLF)
|
||||||
at.resp_start();
|
at.resp_start();
|
||||||
|
CellularUtil_stub::char_pos = 0;
|
||||||
EXPECT_TRUE(5 == at.read_hex_string(buf2, 6));
|
EXPECT_TRUE(5 == at.read_hex_string(buf2, 6));
|
||||||
EXPECT_TRUE(!strncmp(buf2, "hello", 5));
|
EXPECT_TRUE(!strncmp(buf2, "hello", 5));
|
||||||
|
|
||||||
|
@ -868,6 +886,8 @@ TEST_F(TestATHandler, test_ATHandler_read_hex_string)
|
||||||
char buf3[6];
|
char buf3[6];
|
||||||
// Set _stop_tag to resp_stop(OKCRLF)
|
// Set _stop_tag to resp_stop(OKCRLF)
|
||||||
at.resp_start();
|
at.resp_start();
|
||||||
|
CellularUtil_stub::char_pos = 0;
|
||||||
|
|
||||||
EXPECT_TRUE(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/));
|
EXPECT_TRUE(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/));
|
||||||
EXPECT_TRUE(!strncmp(buf3, "he", 2));
|
EXPECT_TRUE(!strncmp(buf3, "he", 2));
|
||||||
at.resp_stop();
|
at.resp_stop();
|
||||||
|
@ -883,6 +903,8 @@ TEST_F(TestATHandler, test_ATHandler_read_hex_string)
|
||||||
char buf4[6];
|
char buf4[6];
|
||||||
// Set _stop_tag to resp_stop(OKCRLF)
|
// Set _stop_tag to resp_stop(OKCRLF)
|
||||||
at.resp_start();
|
at.resp_start();
|
||||||
|
CellularUtil_stub::char_pos = 0;
|
||||||
|
|
||||||
EXPECT_TRUE(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/));
|
EXPECT_TRUE(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/));
|
||||||
EXPECT_TRUE(!strncmp(buf4, "h", 1));
|
EXPECT_TRUE(!strncmp(buf4, "h", 1));
|
||||||
}
|
}
|
||||||
|
@ -1278,3 +1300,84 @@ TEST_F(TestATHandler, test_ATHandler_get_3gpp_error)
|
||||||
at.get_3gpp_error();
|
at.get_3gpp_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestATHandler, test_ATHandler_cmd_start_stop)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
uint8_t byte[] = {1, 2, 3, 4};
|
||||||
|
at.cmd_start_stop("+CREG", "=1,", "%d%s%b", 3, "test", byte, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestATHandler, test_ATHandler_at_cmd_str)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
uint8_t byte[] = {1, 2, 3, 4};
|
||||||
|
char ret[10];
|
||||||
|
|
||||||
|
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
|
||||||
|
filehandle_stub_table = table;
|
||||||
|
|
||||||
|
at.flush();
|
||||||
|
at.clear_error();
|
||||||
|
filehandle_stub_table_pos = 0;
|
||||||
|
mbed_poll_stub::int_value = 1;
|
||||||
|
fh1.short_value = POLLIN;
|
||||||
|
|
||||||
|
EXPECT_EQ(NSAPI_ERROR_DEVICE_ERROR, at.at_cmd_str("+CREG", "=1,", ret, 10, "%d%s%b", 3, "test", byte, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestATHandler, test_ATHandler_at_cmd_int)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
uint8_t byte[] = {1, 2, 3, 4};
|
||||||
|
int ret;
|
||||||
|
EXPECT_EQ(NSAPI_ERROR_DEVICE_ERROR, at.at_cmd_int("+CREG", "=1,", ret, "%d%s%b", 3, "test", byte, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestATHandler, test_ATHandler_at_cmd_discard)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
uint8_t byte[] = {1, 2, 3, 4};
|
||||||
|
|
||||||
|
EXPECT_EQ(NSAPI_ERROR_DEVICE_ERROR, at.at_cmd_discard("+CREG", "=1,", "%d%s%b", 3, "test", byte, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestATHandler, test_ATHandler_sync)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
|
||||||
|
mbed_poll_stub::revents_value = 0;
|
||||||
|
ATHandler at(&fh1, que, 0, ",");
|
||||||
|
at.set_is_filehandle_usable(false);
|
||||||
|
EXPECT_EQ(false, at.sync(100));
|
||||||
|
at.set_is_filehandle_usable(true);
|
||||||
|
EXPECT_EQ(false, at.sync(100));
|
||||||
|
|
||||||
|
fh1.size_value = 8;
|
||||||
|
char table[] = "OK\r\n\0";
|
||||||
|
filehandle_stub_table = table;
|
||||||
|
|
||||||
|
at.flush();
|
||||||
|
at.clear_error();
|
||||||
|
filehandle_stub_table_pos = 0;
|
||||||
|
mbed_poll_stub::revents_value = POLLIN + POLLOUT;
|
||||||
|
fh1.size_value = 10;
|
||||||
|
mbed_poll_stub::int_value = 1;
|
||||||
|
filehandle_stub_short_value_counter = 1;
|
||||||
|
fh1.short_value = POLLIN;
|
||||||
|
|
||||||
|
EXPECT_EQ(true, at.sync(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ set(unittest-includes ${unittest-includes}
|
||||||
# Source files
|
# Source files
|
||||||
set(unittest-sources
|
set(unittest-sources
|
||||||
../features/cellular/framework/AT/ATHandler.cpp
|
../features/cellular/framework/AT/ATHandler.cpp
|
||||||
../features/cellular/framework/AT/ATHandler_factory.cpp
|
|
||||||
../features/cellular/framework/common/CellularUtil.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
|
@ -33,6 +31,7 @@ set(unittest-test-sources
|
||||||
stubs/Kernel_stub.cpp
|
stubs/Kernel_stub.cpp
|
||||||
stubs/ThisThread_stub.cpp
|
stubs/ThisThread_stub.cpp
|
||||||
stubs/randLIB_stub.cpp
|
stubs/randLIB_stub.cpp
|
||||||
|
stubs/CellularUtil_stub.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
|
||||||
|
|
|
@ -14,7 +14,6 @@ set(unittest-includes ${unittest-includes}
|
||||||
# Source files
|
# Source files
|
||||||
set(unittest-sources
|
set(unittest-sources
|
||||||
../features/cellular/framework/device/CellularStateMachine.cpp
|
../features/cellular/framework/device/CellularStateMachine.cpp
|
||||||
../features/cellular/framework/AT/ATHandler_factory.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test files
|
# Test files
|
||||||
|
|
|
@ -25,9 +25,11 @@ using namespace events;
|
||||||
|
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
|
|
||||||
const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds
|
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;
|
||||||
|
@ -88,8 +90,6 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
|
||||||
_oobs(NULL),
|
_oobs(NULL),
|
||||||
_max_resp_length(MAX_RESP_LENGTH)
|
_max_resp_length(MAX_RESP_LENGTH)
|
||||||
{
|
{
|
||||||
ATHandler_stub::ref_count = 1;
|
|
||||||
|
|
||||||
ATHandler_stub::process_oob_urc = false;
|
ATHandler_stub::process_oob_urc = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,29 +108,21 @@ bool ATHandler::get_debug() const
|
||||||
|
|
||||||
ATHandler::~ATHandler()
|
ATHandler::~ATHandler()
|
||||||
{
|
{
|
||||||
ATHandler_stub::ref_count = kATHandler_destructor_ref_ount;
|
|
||||||
while (_oobs) {
|
|
||||||
struct oob_t *oob = _oobs;
|
|
||||||
_oobs = oob->next;
|
|
||||||
delete oob;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::inc_ref_count()
|
void ATHandler::inc_ref_count()
|
||||||
{
|
{
|
||||||
_ref_count++;
|
ATHandler_stub::ref_count++;
|
||||||
ATHandler_stub::ref_count = _ref_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::dec_ref_count()
|
void ATHandler::dec_ref_count()
|
||||||
{
|
{
|
||||||
_ref_count--;
|
ATHandler_stub::ref_count--;
|
||||||
ATHandler_stub::ref_count = _ref_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ATHandler::get_ref_count()
|
int ATHandler::get_ref_count()
|
||||||
{
|
{
|
||||||
return _ref_count;
|
return ATHandler_stub::ref_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileHandle *ATHandler::get_file_handle()
|
FileHandle *ATHandler::get_file_handle()
|
||||||
|
@ -145,43 +137,15 @@ void ATHandler::set_file_handle(FileHandle *fh)
|
||||||
|
|
||||||
bool ATHandler::find_urc_handler(const char *prefix)
|
bool ATHandler::find_urc_handler(const char *prefix)
|
||||||
{
|
{
|
||||||
struct oob_t *oob = _oobs;
|
return ATHandler_stub::bool_value;
|
||||||
while (oob) {
|
|
||||||
if (strcmp(prefix, oob->prefix) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
oob = oob->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
|
void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
|
||||||
{
|
{
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
remove_urc_handler(urc);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (find_urc_handler(urc)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct oob_t *oob = new struct oob_t;
|
|
||||||
size_t prefix_len = strlen(urc);
|
|
||||||
if (prefix_len > _oob_string_max_length) {
|
|
||||||
_oob_string_max_length = prefix_len;
|
|
||||||
if (_oob_string_max_length > _max_resp_length) {
|
|
||||||
_max_resp_length = _oob_string_max_length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
oob->prefix = urc;
|
|
||||||
oob->prefix_len = prefix_len;
|
|
||||||
oob->cb = cb;
|
|
||||||
oob->next = _oobs;
|
|
||||||
_oobs = oob;
|
|
||||||
|
|
||||||
if (ATHandler_stub::call_immediately) {
|
if (ATHandler_stub::call_immediately) {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
@ -189,21 +153,6 @@ void ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
|
||||||
|
|
||||||
void ATHandler::remove_urc_handler(const char *prefix)
|
void ATHandler::remove_urc_handler(const char *prefix)
|
||||||
{
|
{
|
||||||
struct oob_t *current = _oobs;
|
|
||||||
struct oob_t *prev = NULL;
|
|
||||||
while (current) {
|
|
||||||
if (strcmp(prefix, current->prefix) == 0) {
|
|
||||||
if (prev) {
|
|
||||||
prev->next = current->next;
|
|
||||||
} else {
|
|
||||||
_oobs = current->next;
|
|
||||||
}
|
|
||||||
delete current;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
prev = current;
|
|
||||||
current = prev->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t ATHandler::get_last_error() const
|
nsapi_error_t ATHandler::get_last_error() const
|
||||||
|
@ -240,16 +189,6 @@ void ATHandler::restore_at_timeout()
|
||||||
|
|
||||||
void ATHandler::process_oob()
|
void ATHandler::process_oob()
|
||||||
{
|
{
|
||||||
if (ATHandler_stub::process_oob_urc) {
|
|
||||||
size_t prefix_len = 0;
|
|
||||||
for (struct oob_t *oob = _oobs; oob; oob = oob->next) {
|
|
||||||
prefix_len = oob->prefix_len;
|
|
||||||
if (!memcmp(oob->prefix, ATHandler_stub::read_string_table[ATHandler_stub::read_string_index], prefix_len)) {
|
|
||||||
oob->cb();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::clear_error()
|
void ATHandler::clear_error()
|
||||||
|
@ -273,7 +212,7 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
|
||||||
|
|
||||||
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
||||||
{
|
{
|
||||||
|
buf[0] = '\0';
|
||||||
if (ATHandler_stub::read_string_index == kRead_string_table_size) {
|
if (ATHandler_stub::read_string_index == kRead_string_table_size) {
|
||||||
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
|
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
|
||||||
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1);
|
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1);
|
||||||
|
@ -305,7 +244,6 @@ int32_t ATHandler::read_int()
|
||||||
return ATHandler_stub::int_value;
|
return ATHandler_stub::int_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count);
|
|
||||||
ATHandler_stub::int_count--;
|
ATHandler_stub::int_count--;
|
||||||
if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) {
|
if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) {
|
||||||
return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count];
|
return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count];
|
||||||
|
@ -338,20 +276,6 @@ void ATHandler::resp_start(const char *prefix, bool stop)
|
||||||
|
|
||||||
bool ATHandler::info_resp()
|
bool ATHandler::info_resp()
|
||||||
{
|
{
|
||||||
//3 counter variables available here now so that in a test
|
|
||||||
//case it is possible to have at least two while loops checking
|
|
||||||
//specified amount of info_resps.
|
|
||||||
//
|
|
||||||
//For example:
|
|
||||||
//while(athandler.info_resp())
|
|
||||||
//{
|
|
||||||
// resp_info_true_counter responses handled in this loop
|
|
||||||
//}
|
|
||||||
// resp_info_false_counter set to 1 to break out from the 1st loop
|
|
||||||
//while(athandler.info_resp())
|
|
||||||
//{
|
|
||||||
// resp_info_true_counter2 responses handled in this loop
|
|
||||||
//}
|
|
||||||
if (ATHandler_stub::resp_info_true_counter) {
|
if (ATHandler_stub::resp_info_true_counter) {
|
||||||
ATHandler_stub::resp_info_true_counter--;
|
ATHandler_stub::resp_info_true_counter--;
|
||||||
return true;
|
return true;
|
||||||
|
@ -455,3 +379,29 @@ 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_debug_list(bool debug_on)
|
||||||
|
{
|
||||||
|
ATHandler_stub::debug_on = debug_on;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,17 +26,14 @@
|
||||||
#ifndef __AT_HANDLER_STUB_H__
|
#ifndef __AT_HANDLER_STUB_H__
|
||||||
#define __AT_HANDLER_STUB_H__
|
#define __AT_HANDLER_STUB_H__
|
||||||
|
|
||||||
#define ATHANDLER_REF_COUNT_AT_DESTRUCTOR -909
|
|
||||||
|
|
||||||
static const int kRead_string_table_size = 100;
|
static const int kRead_string_table_size = 100;
|
||||||
static const int kRead_int_table_size = 100;
|
static const int kRead_int_table_size = 100;
|
||||||
static const int kResp_stop_count_default = 100;
|
static const int kResp_stop_count_default = 100;
|
||||||
// set reference count to -909 to separate it from zero so we can test that ATHandler is really deleted.
|
|
||||||
static const int kATHandler_destructor_ref_ount = ATHANDLER_REF_COUNT_AT_DESTRUCTOR;
|
|
||||||
static const int kATHandler_urc_table_max_size = 10;
|
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;
|
||||||
|
|
|
@ -19,6 +19,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "CellularUtil_stub.h"
|
||||||
|
|
||||||
|
int CellularUtil_stub::int_value = 0;
|
||||||
|
uint16_t CellularUtil_stub::uint16_value = 0;
|
||||||
|
char *CellularUtil_stub::char_ptr = NULL;
|
||||||
|
int CellularUtil_stub::char_pos = 0;
|
||||||
|
char *CellularUtil_stub::char_table[50] = {};
|
||||||
|
int CellularUtil_stub::table_idx = 0;
|
||||||
|
|
||||||
namespace mbed_cellular_util {
|
namespace mbed_cellular_util {
|
||||||
|
|
||||||
|
@ -39,7 +47,7 @@ void uint_to_binary_str(uint32_t num, char *str, uint8_t str_size, uint8_t bit_c
|
||||||
// converts the given str to hex string to buf
|
// converts the given str to hex string to buf
|
||||||
uint16_t char_str_to_hex(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
|
uint16_t char_str_to_hex(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
|
||||||
{
|
{
|
||||||
return 0;
|
return CellularUtil_stub::uint16_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void convert_ipv6(char *ip)
|
void convert_ipv6(char *ip)
|
||||||
|
@ -49,15 +57,35 @@ void convert_ipv6(char *ip)
|
||||||
|
|
||||||
char *find_dot_number(char *str, int dot_number)
|
char *find_dot_number(char *str, int dot_number)
|
||||||
{
|
{
|
||||||
return NULL;
|
return CellularUtil_stub::char_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void separate_ip4like_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
void separate_ip4like_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
||||||
{
|
{
|
||||||
|
if (CellularUtil_stub::table_idx > 1) {
|
||||||
|
CellularUtil_stub::table_idx--;
|
||||||
|
memcpy(ip, CellularUtil_stub::char_table[CellularUtil_stub::table_idx],
|
||||||
|
strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx]));
|
||||||
|
ip[strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx])] = '\0';
|
||||||
|
CellularUtil_stub::table_idx--;
|
||||||
|
memcpy(ip2, CellularUtil_stub::char_table[CellularUtil_stub::table_idx],
|
||||||
|
strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx]));
|
||||||
|
ip2[strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx])] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void separate_ip_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
void separate_ip_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
||||||
{
|
{
|
||||||
|
if (CellularUtil_stub::table_idx > 1) {
|
||||||
|
CellularUtil_stub::table_idx--;
|
||||||
|
memcpy(ip, CellularUtil_stub::char_table[CellularUtil_stub::table_idx],
|
||||||
|
strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx]));
|
||||||
|
ip[strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx])] = '\0';
|
||||||
|
CellularUtil_stub::table_idx--;
|
||||||
|
memcpy(ip2, CellularUtil_stub::char_table[CellularUtil_stub::table_idx],
|
||||||
|
strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx]));
|
||||||
|
ip2[strlen(CellularUtil_stub::char_table[CellularUtil_stub::table_idx])] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size)
|
||||||
|
@ -72,12 +100,13 @@ void int_to_hex_str(uint8_t num, char *buf)
|
||||||
|
|
||||||
int hex_str_to_int(const char *hex_string, int hex_string_length)
|
int hex_str_to_int(const char *hex_string, int hex_string_length)
|
||||||
{
|
{
|
||||||
return 0;
|
return CellularUtil_stub::int_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hex_str_to_char_str(const char *str, uint16_t len, char *buf)
|
int hex_str_to_char_str(const char *str, uint16_t len, char *buf)
|
||||||
{
|
{
|
||||||
return 0;
|
buf[0] = CellularUtil_stub::char_ptr[CellularUtil_stub::char_pos++];
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
|
void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
|
||||||
|
@ -87,28 +116,12 @@ void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
|
||||||
|
|
||||||
int char_str_to_hex_str(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
|
int char_str_to_hex_str(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
|
||||||
{
|
{
|
||||||
//The code is dependent on this, so this is easiest just to put here
|
return CellularUtil_stub::int_value;
|
||||||
if (!str || !buf) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ptr = buf;
|
|
||||||
int i = 0;
|
|
||||||
while (i < len) {
|
|
||||||
if (omit_leading_zero == true && i == 0 && !(str[i] >> 4 & 0x0F)) {
|
|
||||||
*ptr++ = hex_values[(str[i]) & 0x0F];
|
|
||||||
} else {
|
|
||||||
*ptr++ = hex_values[((str[i]) >> 4) & 0x0F];
|
|
||||||
*ptr++ = hex_values[(str[i]) & 0x0F];
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return ptr - buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t get_dynamic_ip_port()
|
uint16_t get_dynamic_ip_port()
|
||||||
{
|
{
|
||||||
return 0;
|
return CellularUtil_stub::uint16_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mbed_cellular_util
|
} // namespace mbed_cellular_util
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) , Arm Limited and affiliates.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CellularUtil.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace CellularUtil_stub {
|
||||||
|
extern int int_value;
|
||||||
|
extern uint16_t uint16_value;
|
||||||
|
extern char *char_ptr;
|
||||||
|
extern int char_pos;
|
||||||
|
extern char *char_table[50];
|
||||||
|
extern int table_idx;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mbed_cellular_util
|
|
@ -22,3 +22,4 @@ void mbed_assert_internal(const char *expr, const char *file, int line)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "mbed assertation failed: %s, file: %s, line %d \n", expr, file, line);
|
fprintf(stderr, "mbed assertation failed: %s, file: %s, line %d \n", expr, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Kernel.h"
|
#include "Kernel.h"
|
||||||
#include "CellularUtil.h"
|
#include "CellularUtil.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "SingletonPtr.h"
|
||||||
|
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
using namespace events;
|
using namespace events;
|
||||||
|
@ -62,6 +63,91 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
bool ATHandler::ok_to_proceed()
|
bool ATHandler::ok_to_proceed()
|
||||||
{
|
{
|
||||||
if (_last_err != NSAPI_ERROR_OK) {
|
if (_last_err != NSAPI_ERROR_OK) {
|
||||||
|
@ -660,7 +746,8 @@ void ATHandler::set_tag(tag_t *tag_dst, const char *tag_seq)
|
||||||
{
|
{
|
||||||
if (tag_seq) {
|
if (tag_seq) {
|
||||||
size_t tag_len = strlen(tag_seq);
|
size_t tag_len = strlen(tag_seq);
|
||||||
set_string(tag_dst->tag, tag_seq, tag_len);
|
memcpy(tag_dst->tag, tag_seq, tag_len);
|
||||||
|
tag_dst->tag[tag_len] = '\0';
|
||||||
tag_dst->len = tag_len;
|
tag_dst->len = tag_len;
|
||||||
tag_dst->found = false;
|
tag_dst->found = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1109,12 +1196,6 @@ ATHandler::ScopeType ATHandler::get_scope()
|
||||||
return _current_scope;
|
return _current_scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATHandler::set_string(char *dest, const char *src, size_t src_len)
|
|
||||||
{
|
|
||||||
memcpy(dest, src, src_len);
|
|
||||||
dest[src_len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *ATHandler::mem_str(const char *dest, size_t dest_len, const char *src, size_t src_len)
|
const char *ATHandler::mem_str(const char *dest, size_t dest_len, const char *src, size_t src_len)
|
||||||
{
|
{
|
||||||
if (dest_len >= src_len) {
|
if (dest_len >= src_len) {
|
||||||
|
@ -1218,6 +1299,7 @@ nsapi_error_t ATHandler::at_cmd_str(const char *cmd, const char *cmd_chr, char *
|
||||||
_cmd_buffer[strlen(cmd) + 1] = '\0';
|
_cmd_buffer[strlen(cmd) + 1] = '\0';
|
||||||
resp_start(_cmd_buffer);
|
resp_start(_cmd_buffer);
|
||||||
|
|
||||||
|
resp_buf[0] = '\0';
|
||||||
read_string(resp_buf, buf_size);
|
read_string(resp_buf, buf_size);
|
||||||
resp_stop();
|
resp_stop();
|
||||||
return unlock_return_error();
|
return unlock_return_error();
|
||||||
|
|
|
@ -612,15 +612,6 @@ private:
|
||||||
bool check_cmd_send();
|
bool check_cmd_send();
|
||||||
size_t write(const void *data, size_t len);
|
size_t write(const void *data, size_t len);
|
||||||
|
|
||||||
/** Copy content of one char buffer to another buffer and sets NULL terminator
|
|
||||||
*
|
|
||||||
* @param dest destination char buffer
|
|
||||||
* @param src source char buffer
|
|
||||||
* @param src_len number of bytes to copy
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void set_string(char *dest, const char *src, size_t src_len);
|
|
||||||
|
|
||||||
/** Finds occurrence of one char buffer inside another char buffer.
|
/** Finds occurrence of one char buffer inside another char buffer.
|
||||||
*
|
*
|
||||||
* @param dest destination char buffer
|
* @param dest destination char buffer
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ATHandler.h"
|
|
||||||
#include "SingletonPtr.h"
|
|
||||||
|
|
||||||
using namespace mbed;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
|
@ -227,7 +227,7 @@ nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
|
||||||
{
|
{
|
||||||
// if SIM is already in ready state then settings the PIN
|
// if SIM is already in ready state then settings the PIN
|
||||||
// will return error so let's check the state before settings the pin.
|
// will return error so let's check the state before settings the pin.
|
||||||
SimState state;
|
SimState state = SimStateUnknown;
|
||||||
if (get_sim_state(state) == NSAPI_ERROR_OK && state == SimStateReady) {
|
if (get_sim_state(state) == NSAPI_ERROR_OK && state == SimStateReady) {
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue