Skip to content

Commit ecf4d62

Browse files
authored
Merge pull request #12265 from AriParkkila/cell-fea-refactor
Refactor unnecessary functions from cellular driver
2 parents 0266a95 + f9eef97 commit ecf4d62

Some content is hidden

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

41 files changed

+155
-248
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,10 @@ class TestAT_CellularContext : public testing::Test {
7777
class my_stack : public AT_CellularStack {
7878
public:
7979
my_stack(ATHandler &atHandler, AT_CellularDevice &device) : AT_CellularStack(atHandler, 1, IPV4_STACK, device) {}
80-
virtual int get_max_socket_count()
81-
{
82-
return 1;
83-
}
8480
virtual int get_max_packet_size()
8581
{
8682
return 200;
8783
}
88-
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
89-
{
90-
return true;
91-
}
9284
virtual nsapi_error_t socket_close_impl(int sock_id)
9385
{
9486
return NSAPI_ERROR_OK;

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_power_save_mode)
257257
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == dev.set_power_save_mode(0));
258258
}
259259

260-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
261-
{
262-
FileHandle_stub fh1;
263-
AT_CellularDevice dev(&fh1);
264-
EXPECT_TRUE(0 == dev.get_send_delay());
265-
}
266-
267260
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
268261
{
269262
FileHandle_stub fh1;

UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ATHandler_stub.h"
2727
#include "SocketAddress.h"
2828
#include "CellularDevice_stub.h"
29+
#include "AT_CellularDevice_stub.h"
2930
#include "myCellularDevice.h"
3031

3132
using namespace mbed;
@@ -34,27 +35,15 @@ using namespace events;
3435
class MyStack : public AT_CellularStack {
3536
public:
3637
bool bool_value;
37-
bool max_sock_value;
3838
nsapi_error_t create_error;
3939
CellularSocket socket;
4040

4141
MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ, AT_CellularDevice &device) : AT_CellularStack(atr, cid, typ, device)
4242
{
4343
bool_value = false;
44-
max_sock_value = 0;
4544
create_error = NSAPI_ERROR_OK;
4645
}
4746

48-
virtual int get_max_socket_count()
49-
{
50-
return max_sock_value;
51-
}
52-
53-
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
54-
{
55-
return bool_value;
56-
}
57-
5847
virtual nsapi_error_t socket_close_impl(int sock_id)
5948
{
6049
return NSAPI_ERROR_OK;
@@ -207,19 +196,22 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
207196
ATHandler at(&fh1, que, 0, ",");
208197

209198
MyStack st(at, 0, IPV6_STACK, *_dev);
210-
st.bool_value = false;
199+
AT_CellularDevice_stub::supported_bool = 0;
200+
AT_CellularDevice_stub::max_sock_value = 1;
211201
EXPECT_EQ(st.socket_open(NULL, NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
212202

213-
st.bool_value = true;
214-
st.max_sock_value = 0;
203+
AT_CellularDevice_stub::supported_bool = 1;
215204
nsapi_socket_t sock = &st.socket;
205+
AT_CellularDevice_stub::max_sock_value = 0;
216206
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);
217207

218208
MyStack st2(at, 0, IPV6_STACK, *_dev);
219209
st2.bool_value = true;
220-
st2.max_sock_value = 1;
210+
AT_CellularDevice_stub::max_sock_value = 1;
221211
sock = &st2.socket;
222212
EXPECT_EQ(st2.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
213+
214+
AT_CellularDevice_stub::max_sock_value = 1; // value must be the same as before the first open
223215
}
224216

225217
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
@@ -233,13 +225,13 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
233225

234226
nsapi_socket_t sock = &st.socket;
235227
st.bool_value = true;
236-
st.max_sock_value = 1;
228+
AT_CellularDevice_stub::max_sock_value = 1;
237229
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
238-
st.max_sock_value = 0;
230+
AT_CellularDevice_stub::max_sock_value = 0;
239231
EXPECT_EQ(st.socket_close(sock), NSAPI_ERROR_DEVICE_ERROR);
240232

241233
MyStack st2(at, 0, IPV6_STACK, *_dev);
242-
st2.max_sock_value = 1;
234+
AT_CellularDevice_stub::max_sock_value = 1;
243235
st2.bool_value = true;
244236
sock = &st2.socket;
245237
EXPECT_EQ(st2.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
@@ -306,7 +298,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
306298
EXPECT_EQ(st.socket_send(&st.socket, "addr", 4), NSAPI_ERROR_NO_CONNECTION);
307299

308300
SocketAddress addr("fc00::", 123);
309-
st.max_sock_value = 1;
301+
AT_CellularDevice_stub::max_sock_value = 1;
310302
st.bool_value = true;
311303
nsapi_socket_t sock = &st.socket;
312304
st.socket_open(&sock, NSAPI_TCP);
@@ -325,7 +317,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
325317
SocketAddress addr("fc00::", 123);
326318
EXPECT_EQ(st.socket_sendto(NULL, addr, "addr", 4), NSAPI_ERROR_NO_SOCKET);
327319

328-
st.max_sock_value = 1;
320+
AT_CellularDevice_stub::max_sock_value = 1;
329321
st.bool_value = true;
330322
nsapi_socket_t sock = &st.socket;
331323
st.socket_open(&sock, NSAPI_TCP);
@@ -359,7 +351,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
359351
EXPECT_EQ(st.socket_recvfrom(NULL, NULL, table, 4), NSAPI_ERROR_NO_SOCKET);
360352

361353
SocketAddress addr;
362-
st.max_sock_value = 1;
354+
AT_CellularDevice_stub::max_sock_value = 1;
363355
st.bool_value = true;
364356
nsapi_socket_t sock = &st.socket;
365357
st.socket_open(&sock, NSAPI_TCP);
@@ -380,7 +372,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
380372
MyStack st(at, 0, IPV6_STACK, *_dev);
381373

382374
st.socket_attach(NULL, NULL, NULL);
383-
st.max_sock_value = 1;
375+
AT_CellularDevice_stub::max_sock_value = 1;
384376
st.bool_value = true;
385377
nsapi_socket_t sock = &st.socket;
386378
st.socket_open(&sock, NSAPI_TCP);

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int AT_CellularDevice_stub::set_pin_failure_count = 0;
3131
int AT_CellularDevice_stub::get_sim_failure_count = 0;
3232
bool AT_CellularDevice_stub::pin_needed = false;
3333
bool AT_CellularDevice_stub::supported_bool = false;
34+
int AT_CellularDevice_stub::max_sock_value = 0;
3435

3536
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
3637
#if MBED_CONF_CELLULAR_USE_SMS
@@ -48,7 +49,7 @@ AT_CellularDevice::~AT_CellularDevice()
4849

4950
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
5051
{
51-
return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on);
52+
return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), _modem_debug_on);
5253
}
5354

5455
ATHandler *AT_CellularDevice::get_at_handler()
@@ -87,7 +88,7 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
8788
_queue,
8889
_default_timeout,
8990
"\r",
90-
get_send_delay(),
91+
get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY),
9192
_modem_debug_on), *this);
9293
return _network;
9394
}
@@ -163,11 +164,6 @@ void AT_CellularDevice::set_timeout(int timeout)
163164
_default_timeout = timeout;
164165
}
165166

166-
uint16_t AT_CellularDevice::get_send_delay() const
167-
{
168-
return 0;
169-
}
170-
171167
void AT_CellularDevice::modem_debug_on(bool on)
172168
{
173169
_modem_debug_on = on;
@@ -293,6 +289,8 @@ intptr_t AT_CellularDevice::get_property(CellularProperty key)
293289
return true;
294290
} else if (key == PROPERTY_IPV4_PDP_TYPE) {
295291
return true;
292+
} else if (key == PROPERTY_SOCKET_COUNT) {
293+
return AT_CellularDevice_stub::max_sock_value;
296294
}
297295

298296
return AT_CellularDevice_stub::supported_bool;

UNITTESTS/stubs/AT_CellularDevice_stub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern int set_pin_failure_count;
2828
extern int get_sim_failure_count;
2929
extern bool pin_needed;
3030
extern bool supported_bool;
31+
extern int max_sock_value;
3132
}
3233

3334

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ class myCellularDevice : public AT_CellularDevice {
115115

116116
virtual void set_timeout(int timeout) {}
117117

118-
virtual uint16_t get_send_delay() const
119-
{
120-
return 0;
121-
}
122-
123118
virtual void modem_debug_on(bool on) {}
124119

125120
virtual nsapi_error_t init()

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void AT_CellularDevice::setup_at_handler()
107107
{
108108
set_at_urcs();
109109

110-
_at->set_send_delay(get_send_delay());
110+
_at->set_send_delay(get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY));
111111
}
112112

113113
void AT_CellularDevice::urc_nw_deact()
@@ -188,7 +188,7 @@ ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
188188
}
189189

190190
return ATHandler::get_instance(fileHandle, _queue, _default_timeout,
191-
"\r", get_send_delay(), _modem_debug_on);
191+
"\r", get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), _modem_debug_on);
192192
}
193193

194194
ATHandler *AT_CellularDevice::get_at_handler()
@@ -445,11 +445,6 @@ void AT_CellularDevice::set_timeout(int timeout)
445445
}
446446
}
447447

448-
uint16_t AT_CellularDevice::get_send_delay() const
449-
{
450-
return 0;
451-
}
452-
453448
void AT_CellularDevice::modem_debug_on(bool on)
454449
{
455450
_modem_debug_on = on;

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class AT_CellularDevice : public CellularDevice {
5858
PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP?
5959
PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
6060
PROPERTY_AT_COPS_FALLBACK_AUTO, // 0 = not supported, 1 = supported. Does modem support mode 4 of AT+COPS= ?
61-
61+
PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
62+
PROPERTY_IP_TCP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
63+
PROPERTY_IP_UDP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
64+
PROPERTY_AT_SEND_DELAY, // Sending delay between AT commands in ms
6265
PROPERTY_MAX
6366
};
6467

@@ -98,8 +101,6 @@ class AT_CellularDevice : public CellularDevice {
98101

99102
virtual void set_timeout(int timeout);
100103

101-
virtual uint16_t get_send_delay() const;
102-
103104
virtual void modem_debug_on(bool on);
104105

105106
virtual nsapi_error_t init();

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,32 @@ using namespace mbed_cellular_util;
2525
using namespace mbed;
2626

2727
AT_CellularStack::AT_CellularStack(ATHandler &at, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device) :
28-
_socket(NULL), _socket_count(0), _cid(cid),
28+
_socket(NULL), _cid(cid),
2929
_stack_type(stack_type), _ip_ver_sendto(NSAPI_UNSPEC), _at(at), _device(device)
3030
{
3131
memset(_ip, 0, PDP_IPV6_SIZE);
3232
}
3333

3434
AT_CellularStack::~AT_CellularStack()
3535
{
36-
for (int i = 0; i < _socket_count; i++) {
37-
if (_socket[i]) {
38-
delete _socket[i];
39-
_socket[i] = NULL;
36+
if (_socket) {
37+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
38+
if (_socket[i]) {
39+
delete _socket[i];
40+
_socket[i] = NULL;
41+
}
4042
}
43+
delete [] _socket;
44+
_socket = NULL;
4145
}
42-
_socket_count = 0;
43-
44-
delete [] _socket;
45-
_socket = NULL;
4646
}
4747

4848
int AT_CellularStack::find_socket_index(nsapi_socket_t handle)
4949
{
50-
int max_socket_count = get_max_socket_count();
51-
for (int i = 0; i < max_socket_count; i++) {
50+
if (!_socket) {
51+
return -1;
52+
}
53+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
5254
if (_socket[i] == handle) {
5355
return i;
5456
}
@@ -158,23 +160,36 @@ nsapi_error_t AT_CellularStack::socket_stack_init()
158160

159161
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
160162
{
161-
if (!is_protocol_supported(proto) || !handle) {
163+
if (!handle) {
162164
return NSAPI_ERROR_UNSUPPORTED;
163165
}
164166

165-
int max_socket_count = get_max_socket_count();
167+
if (proto == NSAPI_UDP) {
168+
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_UDP)) {
169+
return NSAPI_ERROR_UNSUPPORTED;
170+
}
171+
} else if (proto == NSAPI_TCP) {
172+
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_TCP)) {
173+
return NSAPI_ERROR_UNSUPPORTED;
174+
}
175+
} else {
176+
return NSAPI_ERROR_UNSUPPORTED;
177+
}
166178

167179
_socket_mutex.lock();
168180

169181
if (!_socket) {
182+
if (_device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT) == 0) {
183+
_socket_mutex.unlock();
184+
return NSAPI_ERROR_NO_SOCKET;
185+
}
170186
if (socket_stack_init() != NSAPI_ERROR_OK) {
171187
_socket_mutex.unlock();
172188
return NSAPI_ERROR_NO_SOCKET;
173189
}
174190

175-
_socket = new CellularSocket*[max_socket_count];
176-
_socket_count = max_socket_count;
177-
for (int i = 0; i < max_socket_count; i++) {
191+
_socket = new CellularSocket*[_device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT)];
192+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
178193
_socket[i] = 0;
179194
}
180195
}
@@ -435,8 +450,7 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi
435450

436451
int AT_CellularStack::get_socket_index_by_port(uint16_t port)
437452
{
438-
int max_socket_count = get_max_socket_count();
439-
for (int i = 0; i < max_socket_count; i++) {
453+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
440454
if (_socket[i]->localAddress.get_port() == port) {
441455
return i;
442456
}
@@ -447,7 +461,7 @@ int AT_CellularStack::get_socket_index_by_port(uint16_t port)
447461
AT_CellularStack::CellularSocket *AT_CellularStack::find_socket(int sock_id)
448462
{
449463
CellularSocket *sock = NULL;
450-
for (int i = 0; i < _socket_count; i++) {
464+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
451465
if (_socket[i] && _socket[i]->id == sock_id) {
452466
sock = _socket[i];
453467
break;

0 commit comments

Comments
 (0)