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
pull/11873/head
Antti Kauppila 2019-11-15 15:51:17 +02:00
parent 699372421a
commit 353782bf63
14 changed files with 101 additions and 44 deletions

View File

@ -31,3 +31,8 @@ set(unittest-test-sources
stubs/ConditionVariable_stub.cpp stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp stubs/Mutex_stub.cpp
) )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")

View File

@ -16,7 +16,7 @@
*/ */
#include "netsocket/NetworkInterface.h" #include "netsocket/NetworkInterface.h"
#include "WiFiInterface.h" #include "WiFiInterface.h"
#include "CellularBase.h" #include "CellularInterface.h"
#include "MeshInterface.h" #include "MeshInterface.h"
MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance() MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance()
@ -29,7 +29,7 @@ MBED_WEAK MeshInterface *MeshInterface::get_default_instance()
return NULL; return NULL;
} }
MBED_WEAK CellularBase *CellularBase::get_default_instance() MBED_WEAK CellularInterface *CellularInterface::get_default_instance()
{ {
return NULL; return NULL;
} }
@ -52,7 +52,7 @@ void WiFiInterface::set_default_parameters()
{ {
} }
void CellularBase::set_default_parameters() void CellularInterface::set_default_parameters()
{ {
} }

View File

@ -314,6 +314,7 @@ public:
*/ */
virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0; virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0;
#if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY)
/** Create new CellularSMS interface. /** Create new CellularSMS interface.
* *
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default * @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 @@ public:
*/ */
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0; virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0;
/** Closes the opened CellularSMS by deleting the CellularSMS instance.
*/
virtual void close_sms() = 0;
#endif // MBED_CONF_CELLULAR_USE_SMS
/** Create new CellularInformation interface. /** Create new CellularInformation interface.
* *
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default * @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 @@ public:
*/ */
virtual void close_network() = 0; virtual void close_network() = 0;
/** Closes the opened CellularSMS by deleting the CellularSMS instance.
*/
virtual void close_sms() = 0;
/** Closes the opened CellularInformation by deleting the CellularInformation instance. /** Closes the opened CellularInformation by deleting the CellularInformation instance.
*/ */
virtual void close_information() = 0; virtual void close_information() = 0;
@ -472,7 +475,9 @@ protected:
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL); virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
void stm_callback(nsapi_event_t ev, intptr_t ptr); void stm_callback(nsapi_event_t ev, intptr_t ptr);
int _network_ref_count; int _network_ref_count;
#if MBED_CONF_CELLULAR_USE_SMS
int _sms_ref_count; int _sms_ref_count;
#endif // MBED_CONF_CELLULAR_USE_SMS
int _info_ref_count; int _info_ref_count;
FileHandle *_fh; FileHandle *_fh;
events::EventQueue _queue; events::EventQueue _queue;

View File

@ -18,6 +18,8 @@
#ifndef CELLULAR_SMS_H_ #ifndef CELLULAR_SMS_H_
#define CELLULAR_SMS_H_ #define CELLULAR_SMS_H_
#if MBED_CONF_CELLULAR_USE_SMS
#include "Callback.h" #include "Callback.h"
#include "nsapi_types.h" #include "nsapi_types.h"
@ -179,4 +181,6 @@ public:
} // namespace mbed } // namespace mbed
#endif // MBED_CONF_CELLULAR_USE_SMS
#endif // CELLULAR_SMS_H_ #endif // CELLULAR_SMS_H_

View File

@ -38,8 +38,11 @@ using namespace mbed;
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds #define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
const int MAX_SIM_RESPONSE_LENGTH = 16; const int MAX_SIM_RESPONSE_LENGTH = 16;
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), #if MBED_CONF_CELLULAR_USE_SMS
_sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS
_network(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false) _modem_debug_on(false)
{ {
MBED_ASSERT(fh); MBED_ASSERT(fh);
@ -58,11 +61,17 @@ AT_CellularDevice::~AT_CellularDevice()
// make sure that all is deleted even if somewhere close was not called and reference counting is messed up. // make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
_network_ref_count = 1; _network_ref_count = 1;
#if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count = 1; _sms_ref_count = 1;
#endif // MBED_CONF_CELLULAR_USE_SMS
_info_ref_count = 1; _info_ref_count = 1;
close_network(); close_network();
#if MBED_CONF_CELLULAR_USE_SMS
close_sms(); close_sms();
#endif //MBED_CONF_CELLULAR_USE_SMS
close_information(); close_information();
AT_CellularContext *curr = _context_list; AT_CellularContext *curr = _context_list;
@ -350,15 +359,6 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
return _network; return _network;
} }
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
if (!_sms) {
_sms = open_sms_impl(*get_at_handler(fh));
}
_sms_ref_count++;
return _sms;
}
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{ {
if (!_information) { if (!_information) {
@ -373,10 +373,35 @@ AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
return new AT_CellularNetwork(at); return new AT_CellularNetwork(at);
} }
#if MBED_CONF_CELLULAR_USE_SMS
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
if (!_sms) {
_sms = open_sms_impl(*get_at_handler(fh));
}
_sms_ref_count++;
return _sms;
}
void AT_CellularDevice::close_sms()
{
if (_sms) {
_sms_ref_count--;
if (_sms_ref_count == 0) {
ATHandler *atHandler = &_sms->get_at_handler();
delete _sms;
_sms = NULL;
release_at_handler(atHandler);
}
}
}
AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at) AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
{ {
return new AT_CellularSMS(at); return new AT_CellularSMS(at);
} }
#endif // MBED_CONF_CELLULAR_USE_SMS
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
{ {
@ -396,19 +421,6 @@ void AT_CellularDevice::close_network()
} }
} }
void AT_CellularDevice::close_sms()
{
if (_sms) {
_sms_ref_count--;
if (_sms_ref_count == 0) {
ATHandler *atHandler = &_sms->get_at_handler();
delete _sms;
_sms = NULL;
release_at_handler(atHandler);
}
}
}
void AT_CellularDevice::close_information() void AT_CellularDevice::close_information()
{ {
if (_information) { if (_information) {

View File

@ -63,14 +63,10 @@ public:
virtual CellularNetwork *open_network(FileHandle *fh = NULL); virtual CellularNetwork *open_network(FileHandle *fh = NULL);
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual CellularInformation *open_information(FileHandle *fh = NULL);
virtual void close_network(); virtual void close_network();
virtual void close_sms();
virtual void close_information(); virtual void close_information();
virtual void set_timeout(int timeout); virtual void set_timeout(int timeout);
@ -119,13 +115,6 @@ public:
*/ */
virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularSMS
*/
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
/** Create new instance of AT_CellularInformation or if overridden, modem specific implementation. /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
* *
* @param at ATHandler reference for communication with the modem. * @param at ATHandler reference for communication with the modem.
@ -137,8 +126,24 @@ public:
virtual nsapi_error_t set_baud_rate(int baud_rate); virtual nsapi_error_t set_baud_rate(int baud_rate);
AT_CellularNetwork *_network; #if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms(FileHandle *fh = NULL);
virtual void close_sms();
/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularSMS
*/
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
AT_CellularSMS *_sms; AT_CellularSMS *_sms;
#endif // MBED_CONF_CELLULAR_USE_SMS
AT_CellularNetwork *_network;
AT_CellularInformation *_information; AT_CellularInformation *_information;
AT_CellularContext *_context_list; AT_CellularContext *_context_list;
int _default_timeout; int _default_timeout;

View File

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
#if MBED_CONF_CELLULAR_USE_SMS
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -1248,3 +1250,4 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char
return decodedCount; return decodedCount;
} }
#endif //MBED_CONF_CELLULAR_USE_SMS

View File

@ -18,6 +18,8 @@
#ifndef AT_CELLULAR_SMS_H_ #ifndef AT_CELLULAR_SMS_H_
#define AT_CELLULAR_SMS_H_ #define AT_CELLULAR_SMS_H_
#if MBED_CONF_CELLULAR_USE_SMS
#include "CellularSMS.h" #include "CellularSMS.h"
#include "AT_CellularBase.h" #include "AT_CellularBase.h"
#include "Callback.h" #include "Callback.h"
@ -167,4 +169,6 @@ private:
} // namespace mbed } // namespace mbed
#endif //MBED_CONF_CELLULAR_USE_SMS
#endif // AT_CELLULAR_SMS_H_ #endif // AT_CELLULAR_SMS_H_

View File

@ -33,7 +33,10 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
return NULL; return NULL;
} }
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
#if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) _info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
{ {
MBED_ASSERT(fh); MBED_ASSERT(fh);

View File

@ -63,10 +63,12 @@ AT_CellularContext *UBLOX_N2XX::create_context_impl(ATHandler &at, const char *a
return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req); return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req);
} }
#if MBED_CONF_CELLULAR_USE_SMS
AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at) AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)
{ {
return new UBLOX_N2XX_CellularSMS(at); return new UBLOX_N2XX_CellularSMS(at);
} }
#endif // MBED_CONF_CELLULAR_USE_SMS
nsapi_error_t UBLOX_N2XX::init() nsapi_error_t UBLOX_N2XX::init()
{ {

View File

@ -51,7 +51,9 @@ public:
protected: // AT_CellularDevice protected: // AT_CellularDevice
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
#if MBED_CONF_CELLULAR_USE_SMS
virtual AT_CellularSMS *open_sms_impl(ATHandler &at); virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
#endif // MBED_CONF_CELLULAR_USE_SMS
virtual void set_at_urcs_impl(); virtual void set_at_urcs_impl();
public: // NetworkInterface public: // NetworkInterface

View File

@ -15,6 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
#if MBED_CONF_CELLULAR_USE_SMS
#include "UBLOX_N2XX_CellularSMS.h" #include "UBLOX_N2XX_CellularSMS.h"
using namespace mbed; using namespace mbed;
@ -47,3 +49,5 @@ nsapi_error_t UBLOX_N2XX_CellularSMS::delete_all_messages()
{ {
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
#endif // MBED_CONF_CELLULAR_USE_SMS

View File

@ -20,6 +20,8 @@
#include "AT_CellularSMS.h" #include "AT_CellularSMS.h"
#if MBED_CONF_CELLULAR_USE_SMS
namespace mbed { namespace mbed {
class UBLOX_N2XX_CellularSMS : public AT_CellularSMS { class UBLOX_N2XX_CellularSMS : public AT_CellularSMS {
@ -42,4 +44,6 @@ public:
} // namespace mbed } // namespace mbed
#endif // MBED_CONF_CELLULAR_USE_SMS
#endif // UBLOX_N2XX_CELLULAR_SMS_H_ #endif // UBLOX_N2XX_CELLULAR_SMS_H_

View File

@ -5,6 +5,10 @@
"help": "Use APN database lookup", "help": "Use APN database lookup",
"value": true "value": true
}, },
"use-sms": {
"help": "Enable or disable SMS functionality in Cellular stack.",
"value": false
},
"random_max_start_delay": { "random_max_start_delay": {
"help": "Maximum random delay value used in start-up sequence in milliseconds", "help": "Maximum random delay value used in start-up sequence in milliseconds",
"value": 0 "value": 0