diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake index c2407a6adf7e..59be1e254e7d 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake @@ -31,3 +31,8 @@ set(unittest-test-sources stubs/ConditionVariable_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") + + diff --git a/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp b/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp index 1275e1169eca..da2ff3f4ce98 100644 --- a/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp +++ b/UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp @@ -16,7 +16,7 @@ */ #include "netsocket/NetworkInterface.h" #include "WiFiInterface.h" -#include "CellularBase.h" +#include "CellularInterface.h" #include "MeshInterface.h" MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance() @@ -29,7 +29,7 @@ MBED_WEAK MeshInterface *MeshInterface::get_default_instance() return NULL; } -MBED_WEAK CellularBase *CellularBase::get_default_instance() +MBED_WEAK CellularInterface *CellularInterface::get_default_instance() { return NULL; } @@ -52,7 +52,7 @@ void WiFiInterface::set_default_parameters() { } -void CellularBase::set_default_parameters() +void CellularInterface::set_default_parameters() { } diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 2b9452302469..abc31b731df6 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -314,6 +314,7 @@ class CellularDevice { */ virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0; +#if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY) /** 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 @@ -322,6 +323,12 @@ class CellularDevice { */ 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. * * @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 { */ 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. */ virtual void close_information() = 0; @@ -472,7 +475,9 @@ class CellularDevice { virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL); void stm_callback(nsapi_event_t ev, intptr_t ptr); int _network_ref_count; +#if MBED_CONF_CELLULAR_USE_SMS int _sms_ref_count; +#endif // MBED_CONF_CELLULAR_USE_SMS int _info_ref_count; FileHandle *_fh; events::EventQueue _queue; diff --git a/features/cellular/framework/API/CellularSMS.h b/features/cellular/framework/API/CellularSMS.h index 22da301b1f1e..0f015232b3ca 100644 --- a/features/cellular/framework/API/CellularSMS.h +++ b/features/cellular/framework/API/CellularSMS.h @@ -18,6 +18,8 @@ #ifndef CELLULAR_SMS_H_ #define CELLULAR_SMS_H_ +#if MBED_CONF_CELLULAR_USE_SMS + #include "Callback.h" #include "nsapi_types.h" @@ -179,4 +181,6 @@ class CellularSMS { } // namespace mbed +#endif // MBED_CONF_CELLULAR_USE_SMS + #endif // CELLULAR_SMS_H_ diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index acfbeaac7d7b..32003a947f88 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -38,8 +38,11 @@ using namespace mbed; #define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds const int MAX_SIM_RESPONSE_LENGTH = 16; -AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), +AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), +#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) { 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. _network_ref_count = 1; +#if MBED_CONF_CELLULAR_USE_SMS _sms_ref_count = 1; +#endif // MBED_CONF_CELLULAR_USE_SMS _info_ref_count = 1; close_network(); + +#if MBED_CONF_CELLULAR_USE_SMS close_sms(); +#endif //MBED_CONF_CELLULAR_USE_SMS + close_information(); AT_CellularContext *curr = _context_list; @@ -350,15 +359,6 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) 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) { if (!_information) { @@ -373,10 +373,35 @@ AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &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) { return new AT_CellularSMS(at); } +#endif // MBED_CONF_CELLULAR_USE_SMS 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() { if (_information) { diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 25f78a87ada3..2de495c8db9b 100755 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -63,14 +63,10 @@ class AT_CellularDevice : public CellularDevice { virtual CellularNetwork *open_network(FileHandle *fh = NULL); - virtual CellularSMS *open_sms(FileHandle *fh = NULL); - virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual void close_network(); - virtual void close_sms(); - virtual void close_information(); virtual void set_timeout(int timeout); @@ -119,13 +115,6 @@ class AT_CellularDevice : public CellularDevice { */ 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. * * @param at ATHandler reference for communication with the modem. @@ -137,8 +126,24 @@ class AT_CellularDevice : public CellularDevice { 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; + +#endif // MBED_CONF_CELLULAR_USE_SMS + + AT_CellularNetwork *_network; + AT_CellularInformation *_information; AT_CellularContext *_context_list; int _default_timeout; diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index c41d7932d504..a0ab72afcb69 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#if MBED_CONF_CELLULAR_USE_SMS + #include #include #include @@ -1248,3 +1250,4 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char return decodedCount; } +#endif //MBED_CONF_CELLULAR_USE_SMS diff --git a/features/cellular/framework/AT/AT_CellularSMS.h b/features/cellular/framework/AT/AT_CellularSMS.h index c0e19ac7b5ff..0e8d100ffd2a 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.h +++ b/features/cellular/framework/AT/AT_CellularSMS.h @@ -18,6 +18,8 @@ #ifndef AT_CELLULAR_SMS_H_ #define AT_CELLULAR_SMS_H_ +#if MBED_CONF_CELLULAR_USE_SMS + #include "CellularSMS.h" #include "AT_CellularBase.h" #include "Callback.h" @@ -167,4 +169,6 @@ class AT_CellularSMS: public CellularSMS, public AT_CellularBase { } // namespace mbed +#endif //MBED_CONF_CELLULAR_USE_SMS + #endif // AT_CELLULAR_SMS_H_ diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index c3501368f2f3..b61f95e37d4a 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -33,7 +33,10 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance() 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) { MBED_ASSERT(fh); diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp index f7a0f6eef2bb..5ec96a8f0c0e 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp @@ -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); } +#if MBED_CONF_CELLULAR_USE_SMS AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at) { return new UBLOX_N2XX_CellularSMS(at); } +#endif // MBED_CONF_CELLULAR_USE_SMS nsapi_error_t UBLOX_N2XX::init() { diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h index 920bc1349f62..7bff286136a7 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h @@ -51,7 +51,9 @@ class UBLOX_N2XX : public AT_CellularDevice { protected: // AT_CellularDevice 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); +#endif // MBED_CONF_CELLULAR_USE_SMS virtual void set_at_urcs_impl(); public: // NetworkInterface diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp index 62ed888fe30c..82e16baaf019 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#if MBED_CONF_CELLULAR_USE_SMS + #include "UBLOX_N2XX_CellularSMS.h" using namespace mbed; @@ -47,3 +49,5 @@ nsapi_error_t UBLOX_N2XX_CellularSMS::delete_all_messages() { return NSAPI_ERROR_UNSUPPORTED; } + +#endif // MBED_CONF_CELLULAR_USE_SMS diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h index eee36417080f..a0b893ab3091 100644 --- a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h @@ -20,6 +20,8 @@ #include "AT_CellularSMS.h" +#if MBED_CONF_CELLULAR_USE_SMS + namespace mbed { class UBLOX_N2XX_CellularSMS : public AT_CellularSMS { @@ -42,4 +44,6 @@ class UBLOX_N2XX_CellularSMS : public AT_CellularSMS { } // namespace mbed +#endif // MBED_CONF_CELLULAR_USE_SMS + #endif // UBLOX_N2XX_CELLULAR_SMS_H_ diff --git a/features/cellular/mbed_lib.json b/features/cellular/mbed_lib.json index 355b0f9ded43..5ef8909e5a04 100644 --- a/features/cellular/mbed_lib.json +++ b/features/cellular/mbed_lib.json @@ -5,6 +5,10 @@ "help": "Use APN database lookup", "value": true }, + "use-sms": { + "help": "Enable or disable SMS functionality in Cellular stack.", + "value": false + }, "random_max_start_delay": { "help": "Maximum random delay value used in start-up sequence in milliseconds", "value": 0