20
20
21
21
#include " CellularTargets.h"
22
22
#include " CellularStateMachine.h"
23
+ #include " Callback.h"
23
24
24
25
namespace mbed {
25
26
@@ -38,13 +39,13 @@ const int MAX_PLMN_SIZE = 16;
38
39
* Class CellularDevice
39
40
*
40
41
* An abstract interface that defines opening and closing of cellular interfaces.
41
- * Deleting/Closing of opened interfaces can be done only via this class.
42
+ * You can delete or close opened interfaces only through this class.
42
43
*/
43
44
class CellularDevice {
44
45
public:
45
46
46
- /* * Return singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not
47
- * defined then returns NULL. Implementation is marked as weak.
47
+ /* * Returns singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not
48
+ * defined, then it returns NULL. Implementation is marked as weak.
48
49
*
49
50
* @return CellularDevice* instance if any
50
51
*/
@@ -62,7 +63,7 @@ class CellularDevice {
62
63
63
64
/* * Creates a new CellularContext interface.
64
65
*
65
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
66
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
66
67
* file handle is used.
67
68
* @param apn access point to use with context, can be null.
68
69
*
@@ -94,19 +95,18 @@ class CellularDevice {
94
95
void set_sim_pin (const char *sim_pin);
95
96
96
97
/* * Plmn to use when registering to cellular network.
97
- * If plmn is set then registering is forced to this plmn. If plmn is not set then automatic
98
- * registering is used when registering to a cellular network. Does not start any operations.
98
+ * If plmn is set, then registering is forced to this plmn. If plmn is not set, then automatic
99
+ * registering is used when registering to a cellular network. It doesn't start any operations.
99
100
*
100
101
* @param plmn plmn used when registering to cellular network
101
102
*/
102
103
void set_plmn (const char *plmn);
103
104
104
105
/* * Start the interface
105
106
*
106
- * Power on the device and does the initializations for communication with the modem..
107
- * By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
108
- * In synchronous and asynchronous mode application can get result in from callback which is set with
109
- * attach(...)
107
+ * Powers on the device and does the initializations for communication with the modem.
108
+ * API is asynchronous. Application can get results from CellularContext callback, which is set
109
+ * with attach(...), or callback, which is set by attach(...), in this class.
110
110
*
111
111
* @return NSAPI_ERROR_OK on success
112
112
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -116,9 +116,8 @@ class CellularDevice {
116
116
/* * Start the interface
117
117
*
118
118
* Attempts to open the sim.
119
- * By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
120
- * In synchronous and asynchronous mode application can get result in from callback which is set with
121
- * attach(...)
119
+ * API is asynchronous. Application can get results from CellularContext callback, which is set
120
+ * with attach(...), or callback, which is set by attach(...), in this class.
122
121
*
123
122
* @return NSAPI_ERROR_OK on success
124
123
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -128,9 +127,8 @@ class CellularDevice {
128
127
/* * Start the interface
129
128
*
130
129
* Attempts to register the device to cellular network.
131
- * By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
132
- * In synchronous and asynchronous mode application can get result in from callback which is set with
133
- * attach(...)
130
+ * API is asynchronous. Application can get results from CellularContext callback, which is set
131
+ * with attach(...), or callback, which is set by attach(...), in this class.
134
132
*
135
133
* @return NSAPI_ERROR_OK on success
136
134
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -140,50 +138,62 @@ class CellularDevice {
140
138
/* * Start the interface
141
139
*
142
140
* Attempts to attach the device to cellular network.
143
- * By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
144
- * In synchronous and asynchronous mode application can get result in from callback which is set with
145
- * attach(...)
141
+ * API is asynchronous. Application can get results from CellularContext callback, which is set
142
+ * with attach(...), or callback, which is set by attach(...), in this class.
146
143
*
147
144
* @return NSAPI_ERROR_OK on success
148
145
* NSAPI_ERROR_NO_MEMORY on case of memory failure
149
146
*/
150
147
nsapi_error_t attach_to_network ();
151
148
149
+ /* * Register callback for status reporting.
150
+ *
151
+ * The specified status callback function is called on the network, and the cellular device status changes.
152
+ * The parameters on the callback are the event type and event type dependent reason parameter.
153
+ *
154
+ * @remark deleting CellularDevice/CellularContext in callback is not allowed.
155
+ * @remark application should not attach to this function if it uses CellularContext::attach because it contains the
156
+ * same information.
157
+ *
158
+ * @param status_cb The callback for status changes.
159
+ */
160
+ void attach (Callback<void (nsapi_event_t , intptr_t )> status_cb);
161
+
152
162
/* * Create new CellularNetwork interface.
153
163
*
154
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
164
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
155
165
* file handle is used.
156
166
* @return New instance of interface CellularNetwork.
157
167
*/
158
168
virtual CellularNetwork *open_network (FileHandle *fh = NULL ) = 0;
159
169
160
170
/* * Create new CellularSMS interface.
161
171
*
162
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
172
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
163
173
* file handle is used.
164
174
* @return New instance of interface CellularSMS.
165
175
*/
166
176
virtual CellularSMS *open_sms (FileHandle *fh = NULL ) = 0;
167
177
168
178
/* * Create new CellularPower interface.
169
179
*
170
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
180
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
171
181
* file handle is used.
172
182
* @return New instance of interface CellularPower.
173
183
*/
174
184
virtual CellularPower *open_power (FileHandle *fh = NULL ) = 0;
175
185
176
186
/* * Create new CellularSIM interface.
177
187
*
178
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
188
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
179
189
* file handle is used.
180
190
* @return New instance of interface CellularSIM.
181
191
*/
182
192
virtual CellularSIM *open_sim (FileHandle *fh = NULL ) = 0;
183
193
184
194
/* * Create new CellularInformation interface.
185
195
*
186
- * @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
196
+ * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
187
197
* file handle is used.
188
198
* @return New instance of interface CellularInformation.
189
199
*/
@@ -266,6 +276,7 @@ class CellularDevice {
266
276
char _sim_pin[MAX_PIN_SIZE + 1 ];
267
277
char _plmn[MAX_PLMN_SIZE + 1 ];
268
278
PlatformMutex _mutex;
279
+ Callback<void (nsapi_event_t , intptr_t )> _status_cb;
269
280
};
270
281
271
282
} // namespace mbed
0 commit comments