Skip to content

Commit bd0f939

Browse files
author
Kimmo Vaisanen
committed
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.
1 parent ee1d998 commit bd0f939

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+314
-845
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class TestAT_CellularContext : public testing::Test {
4444
ATHandler_stub::nsapi_error_value = 0;
4545
ATHandler_stub::nsapi_error_ok_counter = 0;
4646
ATHandler_stub::int_value = -1;
47-
ATHandler_stub::ref_count = 0;
4847
ATHandler_stub::timeout = 0;
4948
ATHandler_stub::default_timeout = 0;
5049
ATHandler_stub::debug_on = 0;
@@ -514,21 +513,6 @@ TEST_F(TestAT_CellularContext, get_apn_backoff_timer)
514513
ASSERT_EQ(time, 55);
515514
}
516515

517-
TEST_F(TestAT_CellularContext, set_file_handle)
518-
{
519-
EventQueue que;
520-
FileHandle_stub fh1;
521-
ATHandler at(&fh1, que, 0, ",");
522-
AT_CellularDevice dev(&fh1);
523-
AT_CellularContext ctx(at, &dev);
524-
ctx.set_file_handle(&fh1);
525-
526-
BufferedSerial ss(NC, NC);
527-
528-
ctx.set_file_handle(&ss, PTC0, true);
529-
ctx.enable_hup(true);
530-
}
531-
532516
TEST_F(TestAT_CellularContext, connect_disconnect_sync)
533517
{
534518
EventQueue que;

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,14 @@ class TestAT_CellularDevice : public testing::Test {
2828

2929
void SetUp()
3030
{
31-
EventQueue que;
32-
FileHandle_stub fh1;
3331
filehandle_stub_table = NULL;
3432
filehandle_stub_table_pos = 0;
3533

36-
ATHandler at(&fh1, que, 0, ",");
37-
ATHandler_stub::handler = &at;
38-
3934
ATHandler_stub::read_string_index = kRead_string_table_size;
4035
}
4136

4237
void TearDown()
4338
{
44-
ATHandler_stub::handler = NULL;
4539
}
4640
};
4741

@@ -55,82 +49,50 @@ TEST_F(TestAT_CellularDevice, Create)
5549

5650
EXPECT_TRUE(dev2 != NULL);
5751
delete dev2;
58-
ATHandler *at = dev.get_at_handler(&fh1);
59-
dev.release_at_handler(at);
60-
dev.release_at_handler(at);
52+
ATHandler *at = dev.get_at_handler();
6153
}
6254

6355
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
6456
{
6557
FileHandle_stub fh1;
66-
FileHandle_stub fh2;
67-
FileHandle_stub fh3;
68-
AT_CellularDevice dev(&fh1); // AT fh1 ref count 1
69-
70-
EXPECT_TRUE(dev.open_network(&fh1)); // AT fh1 ref count 2
71-
dev.modem_debug_on(true);
72-
EXPECT_TRUE(dev.open_sms(&fh2));
73-
EXPECT_TRUE(dev.open_information(&fh3));
74-
ATHandler_stub::fh_value = &fh1;
75-
76-
ATHandler_stub::fh_value = NULL;
77-
78-
AT_CellularDevice *dev2 = new AT_CellularDevice(&fh1); // AT fh1 ref count 3
79-
EXPECT_TRUE(dev2->open_information(&fh1)); // AT fh1 ref count 4
80-
ATHandler *at = dev2->get_at_handler(); // AT fh1 ref count 5
81-
delete dev2; // AT fh1 2 refs deleted -> ref count 3
82-
83-
AT_CellularDevice dev3(&fh1); // AT fh1 ref count 4
84-
EXPECT_TRUE(dev3.release_at_handler(at) == NSAPI_ERROR_OK); // AT fh1 ref count 3
58+
AT_CellularDevice dev(&fh1);
59+
ATHandler *at = dev.get_at_handler();
60+
EXPECT_TRUE(at->get_file_handle() == &fh1);
8561
}
8662

8763
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
8864
{
8965
FileHandle_stub fh1;
9066
AT_CellularDevice dev(&fh1);
9167

92-
CellularNetwork *nw = dev.open_network(NULL);
93-
CellularNetwork *nw1 = dev.open_network(&fh1);
94-
68+
CellularNetwork *nw = dev.open_network();
9569
EXPECT_TRUE(nw);
96-
EXPECT_TRUE(nw1);
97-
EXPECT_TRUE(nw1 == nw);
9870
}
9971

10072
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
10173
{
10274
FileHandle_stub fh1;
10375
AT_CellularDevice dev(&fh1);
10476

105-
CellularSMS *sms = dev.open_sms(NULL);
106-
CellularSMS *sms1 = dev.open_sms(&fh1);
107-
77+
CellularSMS *sms = dev.open_sms();
10878
EXPECT_TRUE(sms);
109-
EXPECT_TRUE(sms1);
110-
EXPECT_TRUE(sms1 == sms);
11179
}
11280

11381
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
11482
{
11583
FileHandle_stub fh1;
11684
AT_CellularDevice dev(&fh1);
11785

118-
CellularInformation *info = dev.open_information(NULL);
119-
CellularInformation *info1 = dev.open_information(&fh1);
120-
86+
CellularInformation *info = dev.open_information();
12187
EXPECT_TRUE(info);
122-
EXPECT_TRUE(info1);
123-
EXPECT_TRUE(info1 == info);
12488
}
12589

12690
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
12791
{
12892
FileHandle_stub fh1;
12993
AT_CellularDevice dev(&fh1);
13094

131-
EXPECT_TRUE(dev.open_network(&fh1));
132-
EXPECT_EQ(ATHandler_stub::ref_count, 1);
133-
95+
EXPECT_TRUE(dev.open_network());
13496
dev.close_network();
13597
}
13698

@@ -139,9 +101,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
139101
FileHandle_stub fh1;
140102
AT_CellularDevice dev(&fh1);
141103

142-
EXPECT_TRUE(dev.open_sms(&fh1));
143-
EXPECT_EQ(ATHandler_stub::ref_count, 1);
144-
104+
EXPECT_TRUE(dev.open_sms());
145105
dev.close_sms();
146106
}
147107

@@ -151,14 +111,14 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
151111
AT_CellularDevice dev(&fh1);
152112
ATHandler_stub::int_value = 0;
153113

154-
EXPECT_TRUE(dev.open_information(&fh1));
114+
EXPECT_TRUE(dev.open_information());
155115

156116
ATHandler_stub::fh_value = NULL;
157117
dev.close_information();
158118

159119
ATHandler_stub::fh_value = &fh1;
160120

161-
EXPECT_TRUE(dev.open_information(&fh1));
121+
EXPECT_TRUE(dev.open_information());
162122

163123
dev.close_information();
164124

@@ -176,8 +136,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
176136
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
177137
EXPECT_TRUE(ATHandler_stub::default_timeout == true);
178138

179-
EXPECT_TRUE(dev.open_sms(&fh1));
180-
EXPECT_EQ(ATHandler_stub::ref_count, 1);
139+
EXPECT_TRUE(dev.open_sms());
181140

182141
dev.set_timeout(5000);
183142
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
@@ -195,8 +154,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
195154
dev.modem_debug_on(true);
196155
EXPECT_TRUE(ATHandler_stub::debug_on == true);
197156

198-
EXPECT_TRUE(dev.open_sms(&fh1));
199-
EXPECT_EQ(ATHandler_stub::ref_count, 1);
157+
EXPECT_TRUE(dev.open_sms());
200158

201159
dev.modem_debug_on(true);
202160
EXPECT_TRUE(ATHandler_stub::debug_on == true);
@@ -263,16 +221,15 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
263221
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
264222

265223
ATHandler *at = dev->get_at_handler();
266-
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
267224

268225
CellularContext *ctx = dev->create_context(NULL);
269226
delete dev;
270227

271228
dev = new AT_CellularDevice(&fh1);
272229
at = dev->get_at_handler();
273230
ctx = dev->create_context(NULL);
274-
CellularContext *ctx1 = dev->create_context(&fh1);
275-
CellularContext *ctx2 = dev->create_context(&fh1);
231+
CellularContext *ctx1 = dev->create_context();
232+
CellularContext *ctx2 = dev->create_context();
276233

277234
EXPECT_TRUE(ctx);
278235
EXPECT_TRUE(ctx1);
@@ -288,9 +245,9 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
288245
dev->delete_context(ctx2);
289246

290247
ctx = dev->create_context(NULL);
291-
ctx1 = dev->create_context(&fh1);
292-
ctx2 = dev->create_context(&fh1);
293-
EXPECT_TRUE(dev->release_at_handler(at) == NSAPI_ERROR_OK);
248+
ctx1 = dev->create_context();
249+
ctx2 = dev->create_context();
250+
294251
EXPECT_TRUE(ctx);
295252
EXPECT_TRUE(ctx1);
296253
EXPECT_TRUE(ctx1 != ctx);

UNITTESTS/features/cellular/framework/device/athandler/athandlertest.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -86,43 +86,6 @@ TEST_F(TestATHandler, test_ATHandler_get_file_handle)
8686
EXPECT_EQ(&fh1, at.get_file_handle());
8787
}
8888

89-
TEST_F(TestATHandler, test_ATHandler_set_file_handle)
90-
{
91-
EventQueue que;
92-
FileHandle_stub fh1, fh2;
93-
94-
ATHandler at(&fh1, que, 0, ",");
95-
96-
at.set_file_handle(&fh2);
97-
}
98-
99-
TEST_F(TestATHandler, test_ATHandler_list)
100-
{
101-
EventQueue que;
102-
FileHandle_stub fh1;
103-
104-
ATHandler::set_at_timeout_list(1000, false);
105-
ATHandler::set_debug_list(false);
106-
107-
ATHandler *at1 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
108-
109-
ATHandler::set_at_timeout_list(1000, false);
110-
ATHandler::set_debug_list(true);
111-
112-
EXPECT_TRUE(ATHandler::get_instance(NULL, que, 0, ",", 0, 0) == NULL);
113-
114-
ATHandler *at2 = ATHandler::get_instance(&fh1, que, 0, ",", 0, 0);
115-
116-
ATHandler::set_at_timeout_list(2000, true);
117-
ATHandler::set_debug_list(false);
118-
119-
EXPECT_TRUE(at1->close() == NSAPI_ERROR_OK);
120-
EXPECT_TRUE(at2->close() == NSAPI_ERROR_OK);
121-
122-
ATHandler::set_at_timeout_list(1000, false);
123-
ATHandler::set_debug_list(false);
124-
}
125-
12689
TEST_F(TestATHandler, test_ATHandler_lock)
12790
{
12891
EventQueue que;

UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ class testContext : public CellularContext
165165

166166
}
167167
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
168-
virtual void set_file_handle(BufferedSerial *serial, PinName dcd_pin = NC, bool active_high = false)
168+
virtual nsapi_error_t configure_hup(PinName dcd_pin = NC, bool active_high = false)
169169
{
170-
170+
return NSAPI_ERROR_OK;
171171
}
172172
#endif
173173
ControlPlane_netif *get_cp_netif()

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ using namespace events;
2828
const int DEFAULT_AT_TIMEOUT = 1000;
2929
const uint8_t MAX_RESP_LENGTH = 7;
3030

31-
mbed::ATHandler *ATHandler_stub::handler = NULL;
32-
3331
nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
3432
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
3533
int ATHandler_stub::int_value = -1;
36-
int ATHandler_stub::ref_count = 0;
3734
int ATHandler_stub::timeout = 0;
3835
bool ATHandler_stub::default_timeout = 0;
3936
bool ATHandler_stub::debug_on = 0;
@@ -84,7 +81,6 @@ void ATHandler_stub::debug_call_count_clear()
8481
}
8582

8683
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
87-
_nextATHandler(0),
8884
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
8985
_oobCv(_fileHandleMutex),
9086
#endif
@@ -111,41 +107,17 @@ bool ATHandler::get_debug() const
111107
return ATHandler_stub::debug_on;
112108
}
113109

114-
void ATHandler::set_debug_list(bool debug_on)
115-
{
116-
ATHandler_stub::debug_on = debug_on;
117-
}
118-
119110
ATHandler::~ATHandler()
120111
{
121112
ATHandler_stub::urc_handlers.clear();
122113
}
123114

124-
void ATHandler::inc_ref_count()
125-
{
126-
ATHandler_stub::ref_count++;
127-
}
128-
129-
void ATHandler::dec_ref_count()
130-
{
131-
ATHandler_stub::ref_count--;
132-
}
133-
134-
int ATHandler::get_ref_count()
135-
{
136-
return ATHandler_stub::ref_count;
137-
}
138-
139115
FileHandle *ATHandler::get_file_handle()
140116
{
141117
ATHandler_stub::fh_value = (FileHandle_stub *)_fileHandle;
142118
return _fileHandle;
143119
}
144120

145-
void ATHandler::set_file_handle(FileHandle *fh)
146-
{
147-
}
148-
149121
bool ATHandler::find_urc_handler(const char *prefix)
150122
{
151123
return ATHandler_stub::bool_value;
@@ -393,27 +365,6 @@ nsapi_error_t ATHandler::at_cmd_discard(const char *cmd, const char *cmd_chr,
393365
return ATHandler_stub::nsapi_error_value;
394366
}
395367

396-
ATHandler *ATHandler::get_instance(FileHandle *fileHandle, events::EventQueue &queue, uint32_t timeout,
397-
const char *delimiter, uint16_t send_delay, bool debug_on)
398-
{
399-
ATHandler_stub::ref_count++;
400-
int a = ATHandler_stub::ref_count;
401-
a = 0;
402-
return ATHandler_stub::handler;
403-
}
404-
405-
nsapi_error_t ATHandler::close()
406-
{
407-
ATHandler_stub::ref_count--;
408-
return NSAPI_ERROR_OK;
409-
}
410-
411-
void ATHandler::set_at_timeout_list(uint32_t timeout_milliseconds, bool default_timeout)
412-
{
413-
ATHandler_stub::timeout = timeout_milliseconds;
414-
ATHandler_stub::default_timeout = default_timeout;
415-
}
416-
417368
void ATHandler::set_send_delay(uint16_t send_delay)
418369
{
419370
}

UNITTESTS/stubs/ATHandler_stub.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ static const int kATHandler_urc_table_max_size = 10;
3434
static const int kATHandler_urc_string_max_size = 16;
3535

3636
namespace ATHandler_stub {
37-
extern mbed::ATHandler *handler;
3837
extern nsapi_error_t nsapi_error_value;
3938
extern uint8_t nsapi_error_ok_counter;
4039
extern int int_value;
41-
extern int ref_count;
4240
extern int timeout;
4341
extern bool default_timeout;
4442
extern bool debug_on;

0 commit comments

Comments
 (0)