mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Move ready_cb from power to device
parent
19b24946df
commit
2dde5a4376
|
@ -398,3 +398,17 @@ TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state)
|
||||||
|
|
||||||
delete dev;
|
delete dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void device_ready_cb()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_ready_cb)
|
||||||
|
{
|
||||||
|
EventQueue que;
|
||||||
|
FileHandle_stub fh1;
|
||||||
|
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
|
||||||
|
|
||||||
|
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(&device_ready_cb));
|
||||||
|
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == dev->set_ready_cb(0));
|
||||||
|
}
|
||||||
|
|
|
@ -41,10 +41,6 @@ protected:
|
||||||
// *INDENT-ON*
|
// *INDENT-ON*
|
||||||
|
|
||||||
|
|
||||||
static void device_ready_cb()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(TestAT_CellularPower, Create)
|
TEST_F(TestAT_CellularPower, Create)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -122,27 +118,3 @@ TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
|
||||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
|
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
|
|
||||||
{
|
|
||||||
EventQueue que;
|
|
||||||
FileHandle_stub fh1;
|
|
||||||
ATHandler at(&fh1, que, 0, ",");
|
|
||||||
|
|
||||||
AT_CellularPower pow(at);
|
|
||||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
|
||||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb)
|
|
||||||
{
|
|
||||||
EventQueue que;
|
|
||||||
FileHandle_stub fh1;
|
|
||||||
ATHandler at(&fh1, que, 0, ",");
|
|
||||||
|
|
||||||
AT_CellularPower pow(at);
|
|
||||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
|
||||||
|
|
||||||
pow.remove_device_ready_urc_cb(NULL);
|
|
||||||
pow.remove_device_ready_urc_cb(&device_ready_cb);
|
|
||||||
}
|
|
||||||
|
|
|
@ -156,9 +156,14 @@ nsapi_error_t AT_CellularDevice::is_ready()
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t AT_CellularDevice::set_ready_cb(mbed::Callback<void()> callback)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
|
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularDevice::init_module()
|
nsapi_error_t AT_CellularDevice::init_module()
|
||||||
|
|
|
@ -54,13 +54,3 @@ nsapi_error_t AT_CellularPower::reset()
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -114,6 +114,11 @@ public:
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual nsapi_error_t set_ready_cb(Callback<void()> callback)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
|
nsapi_error_t set_power_save_mode(int periodic_time, int active_time)
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
return NSAPI_ERROR_OK;
|
||||||
|
|
|
@ -52,7 +52,7 @@ static void urc_callback()
|
||||||
|
|
||||||
static void wait_for_power(CellularPower *pwr)
|
static void wait_for_power(CellularPower *pwr)
|
||||||
{
|
{
|
||||||
nsapi_error_t err = pwr->set_device_ready_urc_cb(&urc_callback);
|
nsapi_error_t err = cellular_device->set_ready_cb(&urc_callback);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
|
||||||
|
|
||||||
int sanity_count = 0;
|
int sanity_count = 0;
|
||||||
|
@ -66,7 +66,7 @@ static void wait_for_power(CellularPower *pwr)
|
||||||
|
|
||||||
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);
|
TEST_ASSERT(cellular_device->is_ready() == NSAPI_ERROR_OK);
|
||||||
|
|
||||||
pwr->remove_device_ready_urc_cb(&urc_callback);
|
TEST_ASSERT(cellular_device->set_ready_cb(0) == NSAPI_ERROR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_power_interface()
|
static void test_power_interface()
|
||||||
|
|
|
@ -257,6 +257,16 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t is_ready() = 0;
|
virtual nsapi_error_t is_ready() = 0;
|
||||||
|
|
||||||
|
/** Set callback function to listen when device is ready.
|
||||||
|
*
|
||||||
|
* @param callback function to call on device ready, or NULL to remove callback.
|
||||||
|
*
|
||||||
|
* @return NSAPI_ERROR_OK on success
|
||||||
|
* NSAPI_ERROR_NO_MEMORY on memory failure
|
||||||
|
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
|
||||||
|
*/
|
||||||
|
virtual nsapi_error_t set_ready_cb(Callback<void()> callback) = 0;
|
||||||
|
|
||||||
/** Set power save mode
|
/** Set power save mode
|
||||||
*
|
*
|
||||||
* @remark See 3GPP TS 27.007 PSM for details
|
* @remark See 3GPP TS 27.007 PSM for details
|
||||||
|
|
|
@ -92,24 +92,6 @@ public:
|
||||||
* NSAPI_ERROR_DEVICE_ERROR on failure
|
* NSAPI_ERROR_DEVICE_ERROR on failure
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t reset() = 0;
|
virtual nsapi_error_t reset() = 0;
|
||||||
|
|
||||||
/** Set URC callback function for device specific ready urc. URC is defined in device specific
|
|
||||||
* power API. Used in startup sequence to listen when device is ready
|
|
||||||
* for using at commands and possible sim.
|
|
||||||
*
|
|
||||||
* @param callback Callback function called when urc received
|
|
||||||
*
|
|
||||||
* @return NSAPI_ERROR_OK on success
|
|
||||||
* NSAPI_ERROR_NO_MEMORY on memory failure
|
|
||||||
* NSAPI_ERROR_UNSUPPORTED if not overridden by the target modem
|
|
||||||
*/
|
|
||||||
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
|
|
||||||
|
|
||||||
/** Removes the device ready urc from the list of urc's.
|
|
||||||
*
|
|
||||||
* @param callback callback to remove from the list of urc's
|
|
||||||
*/
|
|
||||||
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -381,6 +381,11 @@ nsapi_error_t AT_CellularDevice::is_ready()
|
||||||
return _at->unlock_return_error();
|
return _at->unlock_return_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t AT_CellularDevice::set_ready_cb(Callback<void()> callback)
|
||||||
|
{
|
||||||
|
return NSAPI_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
|
nsapi_error_t AT_CellularDevice::set_power_save_mode(int periodic_time, int active_time)
|
||||||
{
|
{
|
||||||
_at->lock();
|
_at->lock();
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
|
|
||||||
virtual nsapi_error_t is_ready();
|
virtual nsapi_error_t is_ready();
|
||||||
|
|
||||||
|
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
|
||||||
|
|
||||||
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
|
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
|
||||||
|
|
||||||
virtual nsapi_error_t init_module();
|
virtual nsapi_error_t init_module();
|
||||||
|
|
|
@ -73,12 +73,3 @@ nsapi_error_t AT_CellularPower::reset()
|
||||||
_at.cmd_stop_read_resp();
|
_at.cmd_stop_read_resp();
|
||||||
return _at.unlock_return_error();
|
return _at.unlock_return_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
return NSAPI_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,10 +43,6 @@ public:
|
||||||
virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0);
|
virtual nsapi_error_t set_power_level(int func_level, int do_reset = 0);
|
||||||
|
|
||||||
virtual nsapi_error_t reset();
|
virtual nsapi_error_t reset();
|
||||||
|
|
||||||
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
|
|
||||||
|
|
||||||
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -387,8 +387,7 @@ bool CellularStateMachine::device_ready()
|
||||||
if (_event_status_cb) {
|
if (_event_status_cb) {
|
||||||
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data);
|
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t)&_cb_data);
|
||||||
}
|
}
|
||||||
|
_cellularDevice.set_ready_cb(0);
|
||||||
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
|
|
||||||
_cellularDevice.close_power();
|
_cellularDevice.close_power();
|
||||||
_power = NULL;
|
_power = NULL;
|
||||||
return true;
|
return true;
|
||||||
|
@ -406,7 +405,7 @@ void CellularStateMachine::state_device_ready()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_retry_count == 0) {
|
if (_retry_count == 0) {
|
||||||
_power->set_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
|
_cellularDevice.set_ready_cb(callback(this, &CellularStateMachine::device_ready_cb));
|
||||||
}
|
}
|
||||||
retry_state_or_fail();
|
retry_state_or_fail();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ private:
|
||||||
bool is_registered_to_plmn();
|
bool is_registered_to_plmn();
|
||||||
void report_failure(const char *msg);
|
void report_failure(const char *msg);
|
||||||
void event();
|
void event();
|
||||||
void ready_urc_cb();
|
void device_ready_cb();
|
||||||
void pre_event(CellularState state);
|
void pre_event(CellularState state);
|
||||||
bool check_is_target_reached();
|
bool check_is_target_reached();
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ using namespace events;
|
||||||
#define MAX_STARTUP_TRIALS 5
|
#define MAX_STARTUP_TRIALS 5
|
||||||
#define MAX_RESET_TRIALS 5
|
#define MAX_RESET_TRIALS 5
|
||||||
|
|
||||||
|
#define DEVICE_READY_URC "CPIN:"
|
||||||
|
|
||||||
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
||||||
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
||||||
AT_CellularBase::AT_CGDATA,
|
AT_CellularBase::AT_CGDATA,
|
||||||
|
@ -62,7 +64,3 @@ AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char
|
||||||
return new QUECTEL_BG96_CellularContext(at, this, apn);
|
return new QUECTEL_BG96_CellularContext(at, this, apn);
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
|
|
||||||
{
|
|
||||||
return new QUECTEL_BG96_CellularInformation(at);
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ protected: // AT_CellularDevice
|
||||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||||
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
|
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
|
||||||
|
virtual nsapi_error_t set_ready_cb(Callback<void()> callback);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void handle_urc(FileHandle *fh);
|
void handle_urc(FileHandle *fh);
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,13 +24,3 @@ using namespace mbed;
|
||||||
QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
|
QUECTEL_BG96_CellularPower::QUECTEL_BG96_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
nsapi_error_t QUECTEL_BG96_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
return _at.set_urc_handler(DEVICE_READY_URC, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QUECTEL_BG96_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
|
|
||||||
{
|
|
||||||
_at.set_urc_handler(DEVICE_READY_URC, 0);
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,10 +25,6 @@ namespace mbed {
|
||||||
class QUECTEL_BG96_CellularPower : public AT_CellularPower {
|
class QUECTEL_BG96_CellularPower : public AT_CellularPower {
|
||||||
public:
|
public:
|
||||||
QUECTEL_BG96_CellularPower(ATHandler &atHandler);
|
QUECTEL_BG96_CellularPower(ATHandler &atHandler);
|
||||||
|
|
||||||
public: //from CellularPower
|
|
||||||
virtual nsapi_error_t set_device_ready_urc_cb(mbed::Callback<void()> callback);
|
|
||||||
virtual void remove_device_ready_urc_cb(mbed::Callback<void()> callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
Loading…
Reference in New Issue