Skip to content

Commit 75caa75

Browse files
author
Ari Parkkila
committed
Cellular: Add get_target_default_instance in CellularDevice
1 parent 59972b6 commit 75caa75

File tree

46 files changed

+1165
-143
lines changed

Some content is hidden

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

46 files changed

+1165
-143
lines changed

UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ TEST_F(TestCellularDevice, test_create_delete)
5353
dev = NULL;
5454

5555
CellularDevice *dev1 = CellularDevice::get_default_instance();
56-
EXPECT_TRUE(dev1);
56+
EXPECT_FALSE(dev1);
5757
}
5858

5959
TEST_F(TestCellularDevice, test_set_sim_pin)

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ AT_CellularDevice::~AT_CellularDevice()
4343
delete _network;
4444
}
4545

46-
nsapi_error_t AT_CellularDevice::power_on()
47-
{
48-
return NSAPI_ERROR_UNSUPPORTED;
49-
}
50-
51-
nsapi_error_t AT_CellularDevice::power_off()
52-
{
53-
return NSAPI_ERROR_UNSUPPORTED;
54-
}
55-
5646
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
5747
{
5848
return ATHandler::get_instance(fileHandle, _queue, _default_timeout, "\r", get_send_delay(), _modem_debug_on);
@@ -232,3 +222,13 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
232222

233223
return AT_CellularDevice_stub::nsapi_error_value;
234224
}
225+
226+
nsapi_error_t AT_CellularDevice::power_on()
227+
{
228+
return NSAPI_ERROR_UNSUPPORTED;
229+
}
230+
231+
nsapi_error_t AT_CellularDevice::power_off()
232+
{
233+
return NSAPI_ERROR_UNSUPPORTED;
234+
}

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ class myCellularDevice : public CellularDevice {
7979
return _network;
8080
}
8181

82-
nsapi_error_t power_on()
83-
{
84-
return NSAPI_ERROR_UNSUPPORTED;
85-
}
86-
87-
nsapi_error_t power_off()
88-
{
89-
return NSAPI_ERROR_UNSUPPORTED;
90-
}
91-
9282
virtual CellularSMS *open_sms(FileHandle *fh = NULL)
9383
{
9484
return NULL;
@@ -137,6 +127,16 @@ class myCellularDevice : public CellularDevice {
137127
return NSAPI_ERROR_OK;
138128
}
139129

130+
virtual nsapi_error_t power_on()
131+
{
132+
return NSAPI_ERROR_UNSUPPORTED;
133+
}
134+
135+
virtual nsapi_error_t power_off()
136+
{
137+
return NSAPI_ERROR_UNSUPPORTED;
138+
}
139+
140140
virtual void set_ready_cb(Callback<void()> callback)
141141
{
142142
}

features/cellular/framework/API/CellularDevice.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,22 @@ class CellularDevice {
5858
};
5959

6060
/** Returns singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not
61-
* defined, then it returns NULL. Implementation is marked as weak.
61+
* defined, then it returns NULL. See NetworkInterface::get_default_instance for details.
6262
*
63-
* @return CellularDevice* instance if any
63+
* @remark Application may override this (non-weak) default implementation.
64+
*
65+
* @return default CellularDevice, NULL if not defined
6466
*/
6567
static CellularDevice *get_default_instance();
6668

69+
/** Return target onboard instance of CellularDevice
70+
*
71+
* @remark Mbed OS target shall override (non-weak) this function for an onboard modem.
72+
*
73+
* @return CellularDevice* instance, NULL if not defined
74+
*/
75+
static CellularDevice *get_target_default_instance();
76+
6777
/** Default constructor
6878
*
6979
* @param fh File handle used in communication with the modem.

features/cellular/framework/device/CellularContext.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
2222
}
2323

2424
namespace mbed {
25-
#ifdef CELLULAR_DEVICE
25+
2626
MBED_WEAK CellularContext *CellularContext::get_default_instance()
2727
{
28-
// Uses default APN, uname, password from mbed_app.json
2928
CellularDevice *dev = CellularDevice::get_default_instance();
3029
if (!dev) {
3130
return NULL;
@@ -52,12 +51,6 @@ MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
5251
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
5352
return context;
5453
}
55-
#else
56-
MBED_WEAK CellularContext *CellularContext::get_default_instance()
57-
{
58-
return NULL;
59-
}
60-
#endif // CELLULAR_DEVICE
6154

6255
void CellularContext::cp_data_received()
6356
{

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,17 @@
2222
#include "CellularTargets.h"
2323
#include "EventQueue.h"
2424

25-
#ifdef CELLULAR_DEVICE
26-
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
27-
#endif // CELLULAR_DEVICE
28-
2925
namespace mbed {
3026

31-
#ifdef CELLULAR_DEVICE
3227
MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
3328
{
34-
static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
35-
#if DEVICE_SERIAL_FC
36-
if (MDMRTS != NC && MDMCTS != NC) {
37-
tr_info("_USING flow control, MDMRTS: %d MDMCTS: %d", MDMRTS, MDMCTS);
38-
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
39-
}
40-
#endif
41-
static CELLULAR_DEVICE device(&serial);
42-
return &device;
29+
return get_target_default_instance();
4330
}
44-
#else
45-
MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
31+
32+
MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
4633
{
4734
return NULL;
4835
}
49-
#endif // CELLULAR_DEVICE
5036

5137
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
5238
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh)
3232
{
3333
}
3434

35-
GEMALTO_CINTERION::~GEMALTO_CINTERION()
36-
{
37-
}
38-
3935
AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
4036
{
4137
return new GEMALTO_CINTERION_CellularContext(at, this, apn, cp_req, nonip_req);
@@ -138,3 +134,17 @@ void GEMALTO_CINTERION::init_module_ems31()
138134
AT_CellularBase::set_cellular_properties(cellular_properties);
139135
_module = ModuleEMS31;
140136
}
137+
138+
#if MBED_CONF_GEMALTO_CINTERION_DEFAULT_CELLULAR_DEVICE
139+
#include "UARTSerial.h"
140+
CellularDevice *CellularDevice::get_default_instance()
141+
{
142+
static UARTSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, MBED_CONF_GEMALTO_CINTERION_BAUDRATE);
143+
#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS)
144+
tr_info("GEMALTO_CINTERION flow control: RTS %d CTS %d", MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS);
145+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS);
146+
#endif
147+
static GEMALTO_CINTERION device(&serial);
148+
return &device;
149+
}
150+
#endif

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
2626
public:
2727

2828
GEMALTO_CINTERION(FileHandle *fh);
29-
virtual ~GEMALTO_CINTERION();
3029

3130
/** Actual model of cellular module is needed to make AT command adaptation at runtime
3231
* to support many different models in one cellular driver.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "GEMALTO_CINTERION",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection",
6+
"value": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection",
10+
"value": null
11+
},
12+
"rts": {
13+
"help": "RTS pin for serial connection",
14+
"value": null
15+
},
16+
"cts": {
17+
"help": "CTS pin for serial connection",
18+
"value": null
19+
},
20+
"baudrate" : {
21+
"help": "Serial connection baud rate",
22+
"value": 115200
23+
},
24+
"default-cellular-device": {
25+
"help": "Provide as default CellularDevice [true/false]",
26+
"value": false
27+
}
28+
},
29+
"target_overrides": {
30+
"K64F": {
31+
"rx": "D0",
32+
"tx": "D1"
33+
}
34+
}
35+
}

features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ namespace mbed {
2828
*
2929
* GENERIC_AT3GPP can be used as a shield for example on top K64F.
3030
* Cellular example can be used for testing: https://github.com/ARMmbed/mbed-os-example-cellular
31-
* Add line to mbed_app.json where you define this class as CELLULAR_DEVICE and the correct pins. In cellular example
32-
* line would be for example just above "target_overrides": {...
33-
* For example:
34-
* "macros": ["CELLULAR_DEVICE=GENERIC_AT3GPP", "MDMRXD=PTC16", "MDMTXD=PTC17","MDMRTS=NC", "MDMCTS=NC"],
35-
* You can define CELLULAR_DEVICE and pins also in ../../../common/CellularTargets.h
31+
* Define in mbed_app.json "target_overrides" correct pins and other setup for your modem.
3632
*
3733
* If new target don't work with GENERIC_AT3GPP then it needs some customizations.
3834
* First thing to try can be checking/modifying cellular_properties array in GENERIC_AT3GPP.cpp, does the module support

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp

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

18-
#include "onboard_modem_api.h"
19-
2018
#include "SARA4_PPP.h"
2119
#include "SARA4_PPP_CellularNetwork.h"
2220

@@ -49,19 +47,16 @@ AT_CellularNetwork *SARA4_PPP::open_network_impl(ATHandler &at)
4947
return new SARA4_PPP_CellularNetwork(at);
5048
}
5149

52-
nsapi_error_t SARA4_PPP::power_on()
50+
#if MBED_CONF_SARA4_PPP_DEFAULT_CELLULAR_DEVICE
51+
#include "UARTSerial.h"
52+
CellularDevice *CellularDevice::get_default_instance()
5353
{
54-
#if MODEM_ON_BOARD
55-
::onboard_modem_init();
56-
::onboard_modem_power_up();
54+
static UARTSerial serial(MBED_CONF_SARA4_PPP_TX, MBED_CONF_SARA4_PPP_RX, MBED_CONF_SARA4_PPP_BAUDRATE);
55+
#if defined (MBED_CONF_SARA4_PPP_RTS) && defined (MBED_CONF_SARA4_PPP_CTS)
56+
tr_info("SARA4_PPP flow control: RTS %d CTS %d", MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS);
57+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_SARA4_PPP_RTS, MBED_CONF_SARA4_PPP_CTS);
5758
#endif
58-
return NSAPI_ERROR_OK;
59+
static SARA4_PPP device(&serial);
60+
return &device;
5961
}
60-
61-
nsapi_error_t SARA4_PPP::power_off()
62-
{
63-
#if MODEM_ON_BOARD
64-
::onboard_modem_power_down();
6562
#endif
66-
return NSAPI_ERROR_OK;
67-
}

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class SARA4_PPP : public AT_CellularDevice {
3030

3131
public: // CellularDevice
3232
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
33-
virtual nsapi_error_t power_on();
34-
virtual nsapi_error_t power_off();
3533
};
3634

3735
} // namespace mbed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "SARA4_PPP",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection",
6+
"value": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection",
10+
"value": null
11+
},
12+
"rts": {
13+
"help": "RTS pin for serial connection",
14+
"value": null
15+
},
16+
"cts": {
17+
"help": "CTS pin for serial connection",
18+
"value": null
19+
},
20+
"baudrate" : {
21+
"help": "Serial connection baud rate",
22+
"value": 115200
23+
},
24+
"default-cellular-device": {
25+
"help": "Provide as default CellularDevice [true/false]",
26+
"value": false
27+
}
28+
}
29+
}

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,17 @@ nsapi_error_t QUECTEL_BC95::reset()
104104
_at->resp_start("REBOOTING", true);
105105
return _at->unlock_return_error();
106106
}
107+
108+
#if MBED_CONF_QUECTEL_BC95_DEFAULT_CELLULAR_DEVICE
109+
#include "UARTSerial.h"
110+
CellularDevice *CellularDevice::get_default_instance()
111+
{
112+
static UARTSerial serial(MBED_CONF_QUECTEL_BC95_TX, MBED_CONF_QUECTEL_BC95_RX, MBED_CONF_QUECTEL_BC95_BAUDRATE);
113+
#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS)
114+
tr_info("QUECTEL_BC95 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS);
115+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS);
116+
#endif
117+
static QUECTEL_BC95 device(&serial);
118+
return &device;
119+
}
120+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "QUECTEL_BC95",
3+
"config": {
4+
"tx": {
5+
"help": "TX pin for serial connection",
6+
"value": null
7+
},
8+
"rx": {
9+
"help": "RX pin for serial connection",
10+
"value": null
11+
},
12+
"rts": {
13+
"help": "RTS pin for serial connection",
14+
"value": null
15+
},
16+
"cts": {
17+
"help": "CTS pin for serial connection",
18+
"value": null
19+
},
20+
"baudrate" : {
21+
"help": "Serial connection baud rate",
22+
"value": 9600
23+
},
24+
"default-cellular-device": {
25+
"help": "Provide as default CellularDevice [true/false]",
26+
"value": false
27+
}
28+
}
29+
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ void QUECTEL_BG96::set_ready_cb(Callback<void()> callback)
7171
{
7272
_at->set_urc_handler(DEVICE_READY_URC, callback);
7373
}
74+
75+
#if MBED_CONF_QUECTEL_BG96_DEFAULT_CELLULAR_DEVICE
76+
#include "UARTSerial.h"
77+
CellularDevice *CellularDevice::get_default_instance()
78+
{
79+
static UARTSerial serial(MBED_CONF_QUECTEL_BG96_TX, MBED_CONF_QUECTEL_BG96_RX, MBED_CONF_QUECTEL_BG96_BAUDRATE);
80+
#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS)
81+
tr_info("QUECTEL_BG96 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS);
82+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BG96_RTS, MBED_CONF_QUECTEL_BG96_CTS);
83+
#endif
84+
static QUECTEL_BG96 device(&serial);
85+
return &device;
86+
}
87+
#endif

0 commit comments

Comments
 (0)