Skip to content

Commit 99bdefc

Browse files
author
Ari Parkkila
authored
Merge pull request #83 from AriParkkila/mbed-os-5.9.0-oob
Changed OnboardCellularInterface to CellularBase::get_default_instance
2 parents 2402e13 + 3a4f552 commit 99bdefc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

main.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "mbed.h"
1818
#include "common_functions.h"
1919
#include "UDPSocket.h"
20-
#include "OnboardCellularInterface.h"
2120
#include "CellularLog.h"
2221

2322
#define UDP 0
@@ -41,10 +40,7 @@
4140
// Number of retries /
4241
#define RETRY_COUNT 3
4342

44-
45-
46-
// CellularInterface object
47-
OnboardCellularInterface iface;
43+
CellularBase *iface;
4844

4945
// Echo server hostname
5046
const char *host_name = MBED_CONF_APP_ECHO_SERVER_HOSTNAME;
@@ -110,7 +106,7 @@ void dot_event()
110106
{
111107
while (true) {
112108
Thread::wait(4000);
113-
if (!iface.is_connected()) {
109+
if (!iface->is_connected()) {
114110
trace_mutex.lock();
115111
printf(".");
116112
fflush(stdout);
@@ -129,8 +125,8 @@ nsapi_error_t do_connect()
129125
nsapi_error_t retcode = NSAPI_ERROR_OK;
130126
uint8_t retry_counter = 0;
131127

132-
while (!iface.is_connected()) {
133-
retcode = iface.connect();
128+
while (!iface->is_connected()) {
129+
retcode = iface->connect();
134130
if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
135131
print_function("\n\nAuthentication Failure. Exiting application\n");
136132
} else if (retcode == NSAPI_ERROR_OK) {
@@ -160,14 +156,14 @@ nsapi_error_t test_send_recv()
160156
UDPSocket sock;
161157
#endif
162158

163-
retcode = sock.open(&iface);
159+
retcode = sock.open(iface);
164160
if (retcode != NSAPI_ERROR_OK) {
165161
print_function("UDPSocket.open() fails, code: %d\n", retcode);
166162
return -1;
167163
}
168164

169165
SocketAddress sock_addr;
170-
retcode = iface.gethostbyname(host_name, &sock_addr);
166+
retcode = iface->gethostbyname(host_name, &sock_addr);
171167
if (retcode != NSAPI_ERROR_OK) {
172168
print_function("Couldn't resolve remote host: %s, code: %d\n", host_name, retcode);
173169
return -1;
@@ -228,11 +224,14 @@ int main()
228224
#else
229225
dot_thread.start(dot_event);
230226
#endif // #if MBED_CONF_MBED_TRACE_ENABLE
227+
iface = CellularBase::get_default_instance();
228+
MBED_ASSERT(iface);
229+
231230
/* Set Pin code for SIM card */
232-
iface.set_sim_pin(MBED_CONF_APP_SIM_PIN_CODE);
231+
iface->set_sim_pin(MBED_CONF_APP_SIM_PIN_CODE);
233232

234233
/* Set network credentials here, e.g., APN */
235-
iface.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
234+
iface->set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
236235

237236
nsapi_error_t retcode = NSAPI_ERROR_NO_CONNECTION;
238237

0 commit comments

Comments
 (0)