Cellular: Fix BG96 power up

pull/11066/head
Ari Parkkila 2019-07-18 03:57:20 -07:00
parent 2f136b977f
commit 7a5e4ca5da
1 changed files with 42 additions and 41 deletions

View File

@ -111,7 +111,10 @@ nsapi_error_t QUECTEL_BG96::hard_power_on()
nsapi_error_t QUECTEL_BG96::soft_power_on()
{
if (_rst.is_connected()) {
if (!_rst.is_connected()) {
return NSAPI_ERROR_OK;
}
tr_info("Reset modem");
_rst = !_active_high;
ThisThread::sleep_for(100);
@ -128,14 +131,16 @@ nsapi_error_t QUECTEL_BG96::soft_power_on()
bool rdy = _at->consume_to_stop_tag();
_at->set_stop_tag(OK);
_at->restore_at_timeout();
_at->unlock();
if (!rdy) {
return NSAPI_ERROR_DEVICE_ERROR;
// check if modem was silently powered on
_at->clear_error();
_at->set_at_timeout(100);
_at->cmd_start("AT");
_at->cmd_stop_read_resp();
_at->restore_at_timeout();
}
}
return NSAPI_ERROR_OK;
return _at->unlock_return_error();
}
nsapi_error_t QUECTEL_BG96::hard_power_off()
@ -162,25 +167,21 @@ nsapi_error_t QUECTEL_BG96::init()
_at->cmd_start("AT+CMEE=1"); // verbose responses
_at->cmd_stop_read_resp();
if (_at->get_last_error() == NSAPI_ERROR_OK) {
if (_at->get_last_error() != NSAPI_ERROR_OK) {
return _at->unlock_return_error();
}
do {
_at->clear_error();
_at->cmd_start("AT+CFUN=1"); // set full functionality
_at->cmd_stop_read_resp();
// CFUN executed ok
if (_at->get_last_error() != NSAPI_ERROR_OK) {
// wait some time that modem gets ready for CFUN command, and try again
retry++;
_at->flush();
ThisThread::sleep_for(64); // experimental value
} else {
// yes continue
if (_at->get_last_error() == NSAPI_ERROR_OK) {
break;
}
/* code */
} while ((retry < 3));
}
// wait some time that modem gets ready for CFUN command, and try again
retry++;
ThisThread::sleep_for(64); // experimental value
} while (retry < 3);
return _at->unlock_return_error();
}