Skip to content

Commit fce4dc6

Browse files
author
Cruz Monrreal
authored
Merge pull request #8852 from jarvte/cellular_doxygen_update
Cellular: update doxygen and add attach CellularDevice.
2 parents c4e913b + 446c428 commit fce4dc6

File tree

3 files changed

+71
-41
lines changed

3 files changed

+71
-41
lines changed

features/cellular/framework/API/CellularContext.h

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,24 @@ class CellularContext : public CellularBase {
9898
// pointer for next item when used as a linked list
9999
CellularContext *_next;
100100
protected:
101-
// friend of CellularDevice so that it's the only way to close/delete this class.
101+
// friend of CellularDevice, so it's the only way to close or delete this class.
102102
friend class CellularDevice;
103103
virtual ~CellularContext() {}
104104

105105
public: // from NetworkInterface
106106
virtual nsapi_error_t set_blocking(bool blocking) = 0;
107107
virtual NetworkStack *get_stack() = 0;
108108
virtual const char *get_ip_address() = 0;
109+
110+
/** Register callback for status reporting.
111+
*
112+
* The specified status callback function is called on the network, and the cellular device status changes.
113+
* The parameters on the callback are the event type and event type dependent reason parameter.
114+
*
115+
* @remark deleting CellularDevice/CellularContext in callback is not allowed.
116+
*
117+
* @param status_cb The callback for status changes.
118+
*/
109119
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) = 0;
110120
virtual nsapi_error_t connect() = 0;
111121
virtual nsapi_error_t disconnect() = 0;
@@ -122,13 +132,13 @@ class CellularContext : public CellularBase {
122132
static CellularContext *get_default_instance();
123133

124134

125-
// Operations, can be sync/async. Also Connect() is this kind of operations, inherited from NetworkInterface above.
135+
// Operations, can be sync/async. Also Connect() is this kind of operation, inherited from NetworkInterface above.
126136

127137
/** Start the interface
128138
*
129-
* Power on the device and does the initializations for communication with the modem..
130-
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
131-
* In synchronous and asynchronous mode application can get result in from callback which is set with
139+
* Powers on the device and does the initializations for communication with the modem.
140+
* By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...).
141+
* In synchronous and asynchronous mode, the application can get result in from callback, which is set with
132142
* attach(...)
133143
*
134144
* @return NSAPI_ERROR_OK on success
@@ -138,9 +148,9 @@ class CellularContext : public CellularBase {
138148

139149
/** Start the interface
140150
*
141-
* Attempts to open the sim.
142-
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
143-
* In synchronous and asynchronous mode application can get result in from callback which is set with
151+
* Attempts to open the SIM.
152+
* By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...).
153+
* In synchronous and asynchronous mode, the application can get result in from callback, which is set with
144154
* attach(...)
145155
*
146156
* @return NSAPI_ERROR_OK on success
@@ -151,8 +161,8 @@ class CellularContext : public CellularBase {
151161
/** Start the interface
152162
*
153163
* Attempts to register the device to cellular network.
154-
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
155-
* In synchronous and asynchronous mode application can get result in from callback which is set with
164+
* By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...).
165+
* In synchronous and asynchronous mode, the application can get result in from callback, which is set with
156166
* attach(...)
157167
*
158168
* @return NSAPI_ERROR_OK on success
@@ -163,8 +173,8 @@ class CellularContext : public CellularBase {
163173
/** Start the interface
164174
*
165175
* Attempts to attach the device to cellular network.
166-
* By default this API is synchronous. API can be set to asynchronous with method set_blocking(...).
167-
* In synchronous and asynchronous mode application can get result in from callback which is set with
176+
* By default, this API is synchronous. API can be set to asynchronous with method set_blocking(...).
177+
* In synchronous and asynchronous mode, the application can get result in from callback, which is set with
168178
* attach(...)
169179
*
170180
* @return NSAPI_ERROR_OK on success
@@ -186,7 +196,7 @@ class CellularContext : public CellularBase {
186196
virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports,
187197
CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate) = 0;
188198

189-
/** Get the relevant information for an active non secondary PDP context.
199+
/** Get the relevant information for an active nonsecondary PDP context.
190200
*
191201
* @remark optional params are not updated if not received from network.
192202
* @param params_list reference to linked list, which is filled on successful call
@@ -205,7 +215,7 @@ class CellularContext : public CellularBase {
205215
*/
206216
virtual nsapi_error_t get_apn_backoff_timer(int &backoff_timer) = 0;
207217

208-
/** Set the file handle used to communicate with the modem. Can be used to change default file handle.
218+
/** Set the file handle used to communicate with the modem. You can use this to change the default file handle.
209219
*
210220
* @param fh file handle for communicating with the modem
211221
*/
@@ -222,8 +232,7 @@ class CellularContext : public CellularBase {
222232
OP_MAX = 5
223233
};
224234

225-
/** Status callback function will be called on status changes on the network or CellularDevice
226-
* by the CellularDevice.
235+
/** The CellularDevice calls the status callback function on status changes on the network or CellularDevice.
227236
*
228237
* @param ev event type
229238
* @param ptr event-type dependent reason parameter

features/cellular/framework/API/CellularDevice.h

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "CellularTargets.h"
2222
#include "CellularStateMachine.h"
23+
#include "Callback.h"
2324

2425
namespace mbed {
2526

@@ -38,13 +39,13 @@ const int MAX_PLMN_SIZE = 16;
3839
* Class CellularDevice
3940
*
4041
* 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.
4243
*/
4344
class CellularDevice {
4445
public:
4546

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.
4849
*
4950
* @return CellularDevice* instance if any
5051
*/
@@ -62,7 +63,7 @@ class CellularDevice {
6263

6364
/** Creates a new CellularContext interface.
6465
*
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
6667
* file handle is used.
6768
* @param apn access point to use with context, can be null.
6869
*
@@ -94,19 +95,18 @@ class CellularDevice {
9495
void set_sim_pin(const char *sim_pin);
9596

9697
/** 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.
99100
*
100101
* @param plmn plmn used when registering to cellular network
101102
*/
102103
void set_plmn(const char *plmn);
103104

104105
/** Start the interface
105106
*
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.
110110
*
111111
* @return NSAPI_ERROR_OK on success
112112
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -116,9 +116,8 @@ class CellularDevice {
116116
/** Start the interface
117117
*
118118
* 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.
122121
*
123122
* @return NSAPI_ERROR_OK on success
124123
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -128,9 +127,8 @@ class CellularDevice {
128127
/** Start the interface
129128
*
130129
* 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.
134132
*
135133
* @return NSAPI_ERROR_OK on success
136134
* NSAPI_ERROR_NO_MEMORY on case of memory failure
@@ -140,50 +138,62 @@ class CellularDevice {
140138
/** Start the interface
141139
*
142140
* 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.
146143
*
147144
* @return NSAPI_ERROR_OK on success
148145
* NSAPI_ERROR_NO_MEMORY on case of memory failure
149146
*/
150147
nsapi_error_t attach_to_network();
151148

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+
152162
/** Create new CellularNetwork interface.
153163
*
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
155165
* file handle is used.
156166
* @return New instance of interface CellularNetwork.
157167
*/
158168
virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0;
159169

160170
/** Create new CellularSMS interface.
161171
*
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
163173
* file handle is used.
164174
* @return New instance of interface CellularSMS.
165175
*/
166176
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0;
167177

168178
/** Create new CellularPower interface.
169179
*
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
171181
* file handle is used.
172182
* @return New instance of interface CellularPower.
173183
*/
174184
virtual CellularPower *open_power(FileHandle *fh = NULL) = 0;
175185

176186
/** Create new CellularSIM interface.
177187
*
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
179189
* file handle is used.
180190
* @return New instance of interface CellularSIM.
181191
*/
182192
virtual CellularSIM *open_sim(FileHandle *fh = NULL) = 0;
183193

184194
/** Create new CellularInformation interface.
185195
*
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
187197
* file handle is used.
188198
* @return New instance of interface CellularInformation.
189199
*/
@@ -266,6 +276,7 @@ class CellularDevice {
266276
char _sim_pin[MAX_PIN_SIZE + 1];
267277
char _plmn[MAX_PLMN_SIZE + 1];
268278
PlatformMutex _mutex;
279+
Callback<void(nsapi_event_t, intptr_t)> _status_cb;
269280
};
270281

271282
} // namespace mbed

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
5151
#endif // CELLULAR_DEVICE
5252

5353
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
54-
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
54+
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
5555
{
5656
set_sim_pin(NULL);
5757
set_plmn(NULL);
@@ -158,6 +158,11 @@ nsapi_error_t CellularDevice::start_state_machine(CellularStateMachine::Cellular
158158
return err;
159159
}
160160

161+
void CellularDevice::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
162+
{
163+
_status_cb = status_cb;
164+
}
165+
161166
void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
162167
{
163168
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
@@ -200,6 +205,11 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
200205
curr->cellular_callback(ev, ptr);
201206
curr = curr->_next;
202207
}
208+
209+
// forward to callback function if set by attach(...)
210+
if (_status_cb) {
211+
_status_cb(ev, ptr);
212+
}
203213
}
204214

205215
} // namespace mbed

0 commit comments

Comments
 (0)