Skip to content

Commit 248f193

Browse files
author
Ari Parkkila
committed
Cellular: Add get_target_default_instance in CellularDevice
1 parent d852c88 commit 248f193

File tree

49 files changed

+1166
-127
lines changed

Some content is hidden

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

49 files changed

+1166
-127
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,13 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
216216

217217
return AT_CellularDevice_stub::nsapi_error_value;
218218
}
219+
220+
nsapi_error_t AT_CellularDevice::power_on()
221+
{
222+
return NSAPI_ERROR_UNSUPPORTED;
223+
}
224+
225+
nsapi_error_t AT_CellularDevice::power_off()
226+
{
227+
return NSAPI_ERROR_UNSUPPORTED;
228+
}

UNITTESTS/stubs/CellularDevice_stub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
3030
return NULL;
3131
}
3232

33-
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0)
33+
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
3434
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
3535
{
3636
}

UNITTESTS/target_h/myCellularDevice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ class myCellularDevice : public CellularDevice {
127127
return NSAPI_ERROR_OK;
128128
}
129129

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+
130140
virtual void set_ready_cb(Callback<void()> callback)
131141
{
132142
}

features/cellular/framework/API/CellularDevice.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,22 @@ class CellularDevice {
5050
SimStateUnknown
5151
};
5252

53-
/** Return singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not
54-
* defined then returns NULL. Implementation is marked as weak.
53+
/** See NetworkInterface::get_default_instance for details
5554
*
56-
* @return CellularDevice* instance if any
55+
* @remark Application may define default to override (non-weak) this function.
56+
*
57+
* @return default CellularDevice, NULL if not defined
5758
*/
5859
static CellularDevice *get_default_instance();
5960

61+
/** Return target onboard instance of CellularDevice
62+
*
63+
* @remark Mbed OS target shall override (non-weak) this function for an onboard modem.
64+
*
65+
* @return CellularDevice* instance, NULL if not defined
66+
*/
67+
static CellularDevice *get_target_default_instance();
68+
6069
/** Default constructor
6170
*
6271
* @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
static CellularDevice *dev = CellularDevice::get_default_instance();
3029
if (!dev) {
3130
return NULL;
@@ -36,11 +35,5 @@ MBED_WEAK CellularContext *CellularContext::get_default_instance()
3635
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
3736
return context;
3837
}
39-
#else
40-
MBED_WEAK CellularContext *CellularContext::get_default_instance()
41-
{
42-
return NULL;
43-
}
44-
#endif // CELLULAR_DEVICE
4538

4639
} // namespace mbed

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
@@ -30,10 +30,6 @@ GEMALTO_CINTERION::GEMALTO_CINTERION(FileHandle *fh) : AT_CellularDevice(fh)
3030
{
3131
}
3232

33-
GEMALTO_CINTERION::~GEMALTO_CINTERION()
34-
{
35-
}
36-
3733
AT_CellularContext *GEMALTO_CINTERION::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
3834
{
3935
return new GEMALTO_CINTERION_CellularContext(at, this, apn, cp_req, nonip_req);
@@ -64,3 +60,17 @@ uint16_t GEMALTO_CINTERION::get_send_delay() const
6460
{
6561
return RESPONSE_TO_SEND_DELAY;
6662
}
63+
64+
#if MBED_CONF_GEMALTO_CINTERION_DEFAULT_CELLULAR_DEVICE
65+
#include "UARTSerial.h"
66+
CellularDevice *CellularDevice::get_default_instance()
67+
{
68+
static UARTSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, MBED_CONF_GEMALTO_CINTERION_BAUDRATE);
69+
#if defined (MBED_CONF_UBLOX_AT_RTS) && defined(MBED_CONF_UBLOX_AT_CTS)
70+
tr_info("GEMALTO_CINTERION flow control: RTS %d CTS %d", MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS);
71+
serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_GEMALTO_CINTERION_RTS, MBED_CONF_GEMALTO_CINTERION_CTS);
72+
#endif
73+
static GEMALTO_CINTERION device(&serial);
74+
return &device;
75+
}
76+
#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
protected: // AT_CellularDevice
3231
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "QUECTEL_BB96",
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": "PTC16",
32+
"tx": "PTC17"
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)