ublox-cellular-base_mno_pr
Diff: UbloxCellularBase.cpp
- Revision:
- 34:73f2c02f14f3
- Parent:
- 33:32fc7c6e2f06
- Child:
- 35:5acdbb0ba583
--- a/UbloxCellularBase.cpp Mon Sep 23 17:07:23 2019 +0500 +++ b/UbloxCellularBase.cpp Mon Oct 07 15:26:06 2019 +0500 @@ -603,10 +603,6 @@ bool UbloxCellularBase::power_up() { bool success = false; - int at_timeout; - LOCK(); - - at_timeout = _at_timeout; // Has to be inside LOCK()s MBED_ASSERT(_at != NULL); @@ -621,28 +617,25 @@ if ( (retry_count % 5) == 0) { modem_power_up(); } - wait_ms(500); - // Modem tends to spit out noise during power up - don't confuse the parser - _at->flush(); - at_set_timeout(1000); - if (_at->send("AT")) { - // C027 needs a delay here - wait_ms(100); - if (_at->recv("OK")) { - success = true; - } - } - at_set_timeout(at_timeout); + success = is_modem_ready(); } - if (success) { - // Set the final baud rate - if (_at->send("AT+IPR=%d", _baud) && _at->recv("OK")) { - // Need to wait for things to be sorted out on the modem side - wait_ms(100); - ((UARTSerial *)_fh)->set_baud(_baud); - } - + return success; +} + +bool UbloxCellularBase::setup_modem() +{ + bool success = false; + LOCK(); + + MBED_ASSERT(_at != NULL); + + // Set the final baud rate + if (_at->send("AT+IPR=%d", _baud) && _at->recv("OK")) { + // Need to wait for things to be sorted out on the modem side + wait_ms(100); + ((UARTSerial *)_fh)->set_baud(_baud); + // Turn off modem echoing and turn on verbose responses success = _at->send("ATE0;+CMEE=2") && _at->recv("OK") && // The following commands are best sent separately @@ -659,6 +652,43 @@ return success; } +bool UbloxCellularBase::is_modem_ready() +{ + bool success = false; + int at_timeout; + LOCK(); + + at_timeout = _at_timeout; // Has to be inside LOCK()s + + MBED_ASSERT(_at != NULL); + + _at->flush(); + at_set_timeout(1000); + if (_at->send("AT")) { + // C027 needs a delay here + wait_ms(100); + if (_at->recv("OK")) { + success = true; + } + } + at_set_timeout(at_timeout); + + UNLOCK(); + return success; +} + +bool UbloxCellularBase::initialize_modem() +{ + bool success = false; + + if (power_up()) { + success = setup_modem(); + } else { + tr_error("Preliminary modem setup failed."); + } + return success; +} + // Power down modem via AT interface. void UbloxCellularBase::power_down() { @@ -803,7 +833,7 @@ MBED_ASSERT(_at != NULL); if (!_modem_initialised) { - if (power_up()) { + if (initialize_modem()) { tr_info("Modem Ready."); if (pin != NULL) { _pin = pin; @@ -817,6 +847,15 @@ #ifdef TARGET_UBLOX_C030_R41XM int mno_profile; if (get_mno_profile(&mno_profile)) { +#ifdef MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE + if (set_mno_profile((mno_profile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE) { + reboot_modem(); + while(is_modem_ready() == false) { + wait_ms(1000); + } + setup_modem(); + } +#endif if (mno_profile == SW_DEFAULT) { tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!"); _default_profile_is_set = true;