2
2
#include < inttypes.h>
3
3
#include " mbed.h"
4
4
#include " BufferedSerial.h"
5
-
6
- #define UBLOX 0
7
- #define MTS_DRAGONFLY 1
8
-
9
- #if MBED_CONF_APP_PLATFORM == UBLOX
10
- #include " ublox_modem_driver/UbloxCellularInterface.h"
11
- UbloxCellularInterface *iface;
12
- #elif MBED_CONF_APP_PLATFORM == MTS_DRAGONFLY
13
- #include " dragonfly_modem_driver/DragonFlyCellularInterface.h"
14
- DragonFlyCellularInterface *iface;
15
- #endif
5
+ #include " ReferenceCellularInterface.h"
16
6
#include " UDPSocket.h"
17
7
#include " common_functions.h"
18
8
#if defined(FEATURE_COMMON_PAL)
@@ -24,6 +14,7 @@ DragonFlyCellularInterface *iface;
24
14
#define tr_error (...) (void (0 )) // dummies if feature common pal is not added
25
15
#endif // defined(FEATURE_COMMON_PAL)
26
16
17
+ ReferenceCellularInterface iface;
27
18
UDPSocket *socket;
28
19
static const char *host_name = " 2.pool.ntp.org" ;
29
20
static const int port = 123 ;
@@ -58,24 +49,21 @@ static void unlock()
58
49
mtx.unlock ();
59
50
}
60
51
61
- // main() runs in its own thread in the OS
62
-
63
-
64
52
int do_ntp ()
65
53
{
66
54
int ntp_values[12 ] = { 0 };
67
55
time_t TIME1970 = 2208988800U ;
68
56
69
57
UDPSocket sock;
70
58
71
- int ret = sock.open (iface);
59
+ int ret = sock.open (& iface);
72
60
if (ret) {
73
61
tr_error (" UDPSocket.open() fails, code: %d" , ret);
74
62
return -1 ;
75
63
}
76
64
77
65
SocketAddress nist;
78
- ret = iface-> gethostbyname (host_name, &nist);
66
+ ret = iface. gethostbyname (host_name, &nist);
79
67
if (ret) {
80
68
tr_error (" Couldn't resolve remote host: %s, code: %d" , host_name, ret);
81
69
return -1 ;
@@ -126,24 +114,14 @@ int do_ntp()
126
114
return -1 ;
127
115
}
128
116
129
- #ifndef MODEM_DEBUG_TRACE
130
- #define MODEM_DEBUG_TRACE false
131
- #endif
132
-
133
- #if MBED_CONF_APP_PLATFORM == UBLOX
134
- UbloxCellularInterface my_iface (false , MODEM_DEBUG_TRACE);
135
- #elif MBED_CONF_APP_PLATFORM == MTS_DRAGONFLY
136
- DragonFlyCellularInterface my_iface (false , MODEM_DEBUG_TRACE);
137
- #endif
138
-
139
117
nsapi_error_t connection ()
140
118
{
141
119
nsapi_error_t retcode;
142
120
bool disconnected = false ;
143
121
144
- while (!iface-> isConnected ()) {
122
+ while (!iface. isConnected ()) {
145
123
146
- retcode = iface-> connect ();
124
+ retcode = iface. connect ();
147
125
if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
148
126
printf (" \n\n Authentication Failure. Exiting application\n " );
149
127
return retcode;
@@ -163,7 +141,7 @@ nsapi_error_t connection()
163
141
int getTime ()
164
142
{
165
143
int retcode = -1 ;
166
- if (iface-> isConnected ()) {
144
+ if (iface. isConnected ()) {
167
145
retcode = do_ntp ();
168
146
} else {
169
147
/* Determine why the network is down */
@@ -193,12 +171,11 @@ int main()
193
171
194
172
nsapi_error_t retcode = NSAPI_ERROR_OK;
195
173
196
- iface = &my_iface;
197
- iface->set_SIM_pin (" 1234" );
174
+ iface.set_SIM_pin (" 1234" );
198
175
199
- iface-> set_credentials (" internet" );
176
+ iface. set_credentials (" internet" );
200
177
201
- iface-> connection_lost_notification_cb (ppp_connection_down_cb);
178
+ iface. connection_status_cb (ppp_connection_down_cb);
202
179
203
180
tr_debug (" Connecting..." );
204
181
retcode = connection ();
0 commit comments