mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: add Callback functionality to CellularDevice.
parent
a3f1ad7b8b
commit
76672db5cc
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "CellularTargets.h"
|
#include "CellularTargets.h"
|
||||||
#include "CellularStateMachine.h"
|
#include "CellularStateMachine.h"
|
||||||
|
#include "Callback.h"
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
|
@ -145,6 +146,19 @@ public:
|
||||||
*/
|
*/
|
||||||
nsapi_error_t attach_to_network();
|
nsapi_error_t attach_to_network();
|
||||||
|
|
||||||
|
/** Register callback for status reporting.
|
||||||
|
*
|
||||||
|
* The specified status callback function will be called on the network and cellular device status changes.
|
||||||
|
* The parameters on the callback are the event type and event-type dependent reason parameter.
|
||||||
|
*
|
||||||
|
* @remark deleting CellularDevice/CellularContext in callback not allowed.
|
||||||
|
* @remark application should not attach to this function if using CellularContext::attach as it will contain the
|
||||||
|
* same information.
|
||||||
|
*
|
||||||
|
* @param status_cb The callback for status changes.
|
||||||
|
*/
|
||||||
|
void attach(Callback<void(nsapi_event_t, intptr_t)> status_cb);
|
||||||
|
|
||||||
/** Create new CellularNetwork interface.
|
/** Create new CellularNetwork interface.
|
||||||
*
|
*
|
||||||
* @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
|
* @param fh file handle used in communication to modem. Can be for example UART handle. If null then the default
|
||||||
|
@ -258,6 +272,7 @@ private:
|
||||||
char _sim_pin[MAX_PIN_SIZE + 1];
|
char _sim_pin[MAX_PIN_SIZE + 1];
|
||||||
char _plmn[MAX_PLMN_SIZE + 1];
|
char _plmn[MAX_PLMN_SIZE + 1];
|
||||||
PlatformMutex _mutex;
|
PlatformMutex _mutex;
|
||||||
|
Callback<void(nsapi_event_t, intptr_t)> _status_cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -51,7 +51,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
||||||
#endif // CELLULAR_DEVICE
|
#endif // CELLULAR_DEVICE
|
||||||
|
|
||||||
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
|
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0),
|
||||||
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
|
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
|
||||||
{
|
{
|
||||||
set_sim_pin(NULL);
|
set_sim_pin(NULL);
|
||||||
set_plmn(NULL);
|
set_plmn(NULL);
|
||||||
|
@ -158,6 +158,11 @@ nsapi_error_t CellularDevice::start_state_machine(CellularStateMachine::Cellular
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CellularDevice::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||||
|
{
|
||||||
|
_status_cb = status_cb;
|
||||||
|
}
|
||||||
|
|
||||||
void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
{
|
{
|
||||||
if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) {
|
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)
|
||||||
curr->cellular_callback(ev, ptr);
|
curr->cellular_callback(ev, ptr);
|
||||||
curr = curr->_next;
|
curr = curr->_next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forward to callback function if set by attach(...)
|
||||||
|
if (_status_cb) {
|
||||||
|
_status_cb(ev, ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
Loading…
Reference in New Issue