Skip to content

Commit 353782b

Browse files
author
Antti Kauppila
committed
Disable SMS by default from Cellular stack
Put SMS behind configuration flag to save some memory (4,5kB) for Cellular users not needing SMS features. UBlox N2XX target is also updated
1 parent 6993724 commit 353782b

File tree

14 files changed

+101
-44
lines changed

14 files changed

+101
-44
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ set(unittest-test-sources
3131
stubs/ConditionVariable_stub.cpp
3232
stubs/Mutex_stub.cpp
3333
)
34+
35+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
36+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
37+
38+

UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "netsocket/NetworkInterface.h"
1818
#include "WiFiInterface.h"
19-
#include "CellularBase.h"
19+
#include "CellularInterface.h"
2020
#include "MeshInterface.h"
2121

2222
MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance()
@@ -29,7 +29,7 @@ MBED_WEAK MeshInterface *MeshInterface::get_default_instance()
2929
return NULL;
3030
}
3131

32-
MBED_WEAK CellularBase *CellularBase::get_default_instance()
32+
MBED_WEAK CellularInterface *CellularInterface::get_default_instance()
3333
{
3434
return NULL;
3535
}
@@ -52,7 +52,7 @@ void WiFiInterface::set_default_parameters()
5252
{
5353
}
5454

55-
void CellularBase::set_default_parameters()
55+
void CellularInterface::set_default_parameters()
5656
{
5757
}
5858

features/cellular/framework/API/CellularDevice.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ class CellularDevice {
314314
*/
315315
virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0;
316316

317+
#if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY)
317318
/** Create new CellularSMS interface.
318319
*
319320
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
@@ -322,6 +323,12 @@ class CellularDevice {
322323
*/
323324
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0;
324325

326+
/** Closes the opened CellularSMS by deleting the CellularSMS instance.
327+
*/
328+
virtual void close_sms() = 0;
329+
330+
#endif // MBED_CONF_CELLULAR_USE_SMS
331+
325332
/** Create new CellularInformation interface.
326333
*
327334
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
@@ -334,10 +341,6 @@ class CellularDevice {
334341
*/
335342
virtual void close_network() = 0;
336343

337-
/** Closes the opened CellularSMS by deleting the CellularSMS instance.
338-
*/
339-
virtual void close_sms() = 0;
340-
341344
/** Closes the opened CellularInformation by deleting the CellularInformation instance.
342345
*/
343346
virtual void close_information() = 0;
@@ -472,7 +475,9 @@ class CellularDevice {
472475
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
473476
void stm_callback(nsapi_event_t ev, intptr_t ptr);
474477
int _network_ref_count;
478+
#if MBED_CONF_CELLULAR_USE_SMS
475479
int _sms_ref_count;
480+
#endif // MBED_CONF_CELLULAR_USE_SMS
476481
int _info_ref_count;
477482
FileHandle *_fh;
478483
events::EventQueue _queue;

features/cellular/framework/API/CellularSMS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef CELLULAR_SMS_H_
1919
#define CELLULAR_SMS_H_
2020

21+
#if MBED_CONF_CELLULAR_USE_SMS
22+
2123
#include "Callback.h"
2224
#include "nsapi_types.h"
2325

@@ -179,4 +181,6 @@ class CellularSMS {
179181

180182
} // namespace mbed
181183

184+
#endif // MBED_CONF_CELLULAR_USE_SMS
185+
182186
#endif // CELLULAR_SMS_H_

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ using namespace mbed;
3838
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
3939
const int MAX_SIM_RESPONSE_LENGTH = 16;
4040

41-
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
42-
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
41+
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
42+
#if MBED_CONF_CELLULAR_USE_SMS
43+
_sms(0),
44+
#endif // MBED_CONF_CELLULAR_USE_SMS
45+
_network(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
4346
_modem_debug_on(false)
4447
{
4548
MBED_ASSERT(fh);
@@ -58,11 +61,17 @@ AT_CellularDevice::~AT_CellularDevice()
5861

5962
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
6063
_network_ref_count = 1;
64+
#if MBED_CONF_CELLULAR_USE_SMS
6165
_sms_ref_count = 1;
66+
#endif // MBED_CONF_CELLULAR_USE_SMS
6267
_info_ref_count = 1;
6368

6469
close_network();
70+
71+
#if MBED_CONF_CELLULAR_USE_SMS
6572
close_sms();
73+
#endif //MBED_CONF_CELLULAR_USE_SMS
74+
6675
close_information();
6776

6877
AT_CellularContext *curr = _context_list;
@@ -350,15 +359,6 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
350359
return _network;
351360
}
352361

353-
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
354-
{
355-
if (!_sms) {
356-
_sms = open_sms_impl(*get_at_handler(fh));
357-
}
358-
_sms_ref_count++;
359-
return _sms;
360-
}
361-
362362
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
363363
{
364364
if (!_information) {
@@ -373,10 +373,35 @@ AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
373373
return new AT_CellularNetwork(at);
374374
}
375375

376+
#if MBED_CONF_CELLULAR_USE_SMS
377+
378+
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
379+
{
380+
if (!_sms) {
381+
_sms = open_sms_impl(*get_at_handler(fh));
382+
}
383+
_sms_ref_count++;
384+
return _sms;
385+
}
386+
387+
void AT_CellularDevice::close_sms()
388+
{
389+
if (_sms) {
390+
_sms_ref_count--;
391+
if (_sms_ref_count == 0) {
392+
ATHandler *atHandler = &_sms->get_at_handler();
393+
delete _sms;
394+
_sms = NULL;
395+
release_at_handler(atHandler);
396+
}
397+
}
398+
}
399+
376400
AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
377401
{
378402
return new AT_CellularSMS(at);
379403
}
404+
#endif // MBED_CONF_CELLULAR_USE_SMS
380405

381406
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
382407
{
@@ -396,19 +421,6 @@ void AT_CellularDevice::close_network()
396421
}
397422
}
398423

399-
void AT_CellularDevice::close_sms()
400-
{
401-
if (_sms) {
402-
_sms_ref_count--;
403-
if (_sms_ref_count == 0) {
404-
ATHandler *atHandler = &_sms->get_at_handler();
405-
delete _sms;
406-
_sms = NULL;
407-
release_at_handler(atHandler);
408-
}
409-
}
410-
}
411-
412424
void AT_CellularDevice::close_information()
413425
{
414426
if (_information) {

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,10 @@ class AT_CellularDevice : public CellularDevice {
6363

6464
virtual CellularNetwork *open_network(FileHandle *fh = NULL);
6565

66-
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
67-
6866
virtual CellularInformation *open_information(FileHandle *fh = NULL);
6967

7068
virtual void close_network();
7169

72-
virtual void close_sms();
73-
7470
virtual void close_information();
7571

7672
virtual void set_timeout(int timeout);
@@ -119,13 +115,6 @@ class AT_CellularDevice : public CellularDevice {
119115
*/
120116
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
121117

122-
/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
123-
*
124-
* @param at ATHandler reference for communication with the modem.
125-
* @return new instance of class AT_CellularSMS
126-
*/
127-
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
128-
129118
/** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
130119
*
131120
* @param at ATHandler reference for communication with the modem.
@@ -137,8 +126,24 @@ class AT_CellularDevice : public CellularDevice {
137126

138127
virtual nsapi_error_t set_baud_rate(int baud_rate);
139128

140-
AT_CellularNetwork *_network;
129+
#if MBED_CONF_CELLULAR_USE_SMS
130+
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
131+
132+
virtual void close_sms();
133+
134+
/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
135+
*
136+
* @param at ATHandler reference for communication with the modem.
137+
* @return new instance of class AT_CellularSMS
138+
*/
139+
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
140+
141141
AT_CellularSMS *_sms;
142+
143+
#endif // MBED_CONF_CELLULAR_USE_SMS
144+
145+
AT_CellularNetwork *_network;
146+
142147
AT_CellularInformation *_information;
143148
AT_CellularContext *_context_list;
144149
int _default_timeout;

features/cellular/framework/AT/AT_CellularSMS.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#if MBED_CONF_CELLULAR_USE_SMS
19+
1820
#include <time.h>
1921
#include <stdlib.h>
2022
#include <stdio.h>
@@ -1248,3 +1250,4 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char
12481250

12491251
return decodedCount;
12501252
}
1253+
#endif //MBED_CONF_CELLULAR_USE_SMS

features/cellular/framework/AT/AT_CellularSMS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#ifndef AT_CELLULAR_SMS_H_
1919
#define AT_CELLULAR_SMS_H_
2020

21+
#if MBED_CONF_CELLULAR_USE_SMS
22+
2123
#include "CellularSMS.h"
2224
#include "AT_CellularBase.h"
2325
#include "Callback.h"
@@ -167,4 +169,6 @@ class AT_CellularSMS: public CellularSMS, public AT_CellularBase {
167169

168170
} // namespace mbed
169171

172+
#endif //MBED_CONF_CELLULAR_USE_SMS
173+
170174
#endif // AT_CELLULAR_SMS_H_

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
3333
return NULL;
3434
}
3535

36-
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
36+
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
37+
#if MBED_CONF_CELLULAR_USE_SMS
38+
_sms_ref_count(0),
39+
#endif //MBED_CONF_CELLULAR_USE_SMS
3740
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
3841
{
3942
MBED_ASSERT(fh);

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ AT_CellularContext *UBLOX_N2XX::create_context_impl(ATHandler &at, const char *a
6363
return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req);
6464
}
6565

66+
#if MBED_CONF_CELLULAR_USE_SMS
6667
AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)
6768
{
6869
return new UBLOX_N2XX_CellularSMS(at);
6970
}
71+
#endif // MBED_CONF_CELLULAR_USE_SMS
7072

7173
nsapi_error_t UBLOX_N2XX::init()
7274
{

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class UBLOX_N2XX : public AT_CellularDevice {
5151
protected: // AT_CellularDevice
5252

5353
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
54+
#if MBED_CONF_CELLULAR_USE_SMS
5455
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
56+
#endif // MBED_CONF_CELLULAR_USE_SMS
5557
virtual void set_at_urcs_impl();
5658

5759
public: // NetworkInterface

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
#if MBED_CONF_CELLULAR_USE_SMS
19+
1820
#include "UBLOX_N2XX_CellularSMS.h"
1921

2022
using namespace mbed;
@@ -47,3 +49,5 @@ nsapi_error_t UBLOX_N2XX_CellularSMS::delete_all_messages()
4749
{
4850
return NSAPI_ERROR_UNSUPPORTED;
4951
}
52+
53+
#endif // MBED_CONF_CELLULAR_USE_SMS

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "AT_CellularSMS.h"
2222

23+
#if MBED_CONF_CELLULAR_USE_SMS
24+
2325
namespace mbed {
2426

2527
class UBLOX_N2XX_CellularSMS : public AT_CellularSMS {
@@ -42,4 +44,6 @@ class UBLOX_N2XX_CellularSMS : public AT_CellularSMS {
4244

4345
} // namespace mbed
4446

47+
#endif // MBED_CONF_CELLULAR_USE_SMS
48+
4549
#endif // UBLOX_N2XX_CELLULAR_SMS_H_

features/cellular/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"help": "Use APN database lookup",
66
"value": true
77
},
8+
"use-sms": {
9+
"help": "Enable or disable SMS functionality in Cellular stack.",
10+
"value": false
11+
},
812
"random_max_start_delay": {
913
"help": "Maximum random delay value used in start-up sequence in milliseconds",
1014
"value": 0

0 commit comments

Comments
 (0)