Base class for the ublox-xxx-cellular-xxx classes. Cannot be used standalone, only inherited by classes that do properly useful stuff. Or, to put it another way, if you are using any of the ublox-xxx-cellular-xxx classes, you will need this class also.
Dependents: example-ublox-cellular-interface example-ublox-cellular-driver-gen HelloMQTT example-ublox-cellular-interface_r410M ... more
Revision 24:e26a6ab0dd75, committed 2019-05-28
- Comitter:
- wajahat.abbas@u-blox.com
- Date:
- Tue May 28 15:39:51 2019 +0500
- Parent:
- 23:eaab8e812a5d
- Child:
- 25:e67d3d9d2e7e
- Commit message:
- +CFUN support
Changed in this revision
| UbloxCellularBase.cpp | Show annotated file Show diff for this revision Revisions of this file |
| UbloxCellularBase.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/UbloxCellularBase.cpp Fri May 03 13:43:49 2019 +0500
+++ b/UbloxCellularBase.cpp Tue May 28 15:39:51 2019 +0500
@@ -802,29 +802,35 @@
if (pin != NULL) {
_pin = pin;
}
- if (initialise_sim_card()) {
+#ifdef TARGET_UBLOX_C027
+ if (set_functionality_mode(FUNC_MIN)) {
+#else
+ if (set_functionality_mode(FUNC_AIRPLANE)) {
+#endif
+ if (initialise_sim_card()) {
#ifdef TARGET_UBLOX_C030_R412M
- if (_psm_status == false) { //psm is not enabled by application yet so disable it at start-up
- set_power_saving_mode(0, 0);
- }
+ if (_psm_status == false) { //psm is not enabled by application yet so disable it at start-up
+ set_power_saving_mode(0, 0);
+ }
#endif
- if (set_device_identity(&_dev_info.dev) && // Set up device identity
- device_init(_dev_info.dev)) {// Initialise this device
- // Get the integrated circuit ID of the SIM
- if (get_iccid()) {
- // Try a few times to get the IMSI (since on some modems this can
- // take a while to be retrieved, especially if a SIM PIN
- // was set)
- for (x = 0; (x < 3) && !get_imsi(); x++) {
- wait_ms(1000);
- }
-
- if (x < 3) { // If we got the IMSI, can get the others
- if (get_imei() && // Get international mobile equipment identifier
- get_meid() && // Probably the same as the IMEI
- set_sms()) { // And set up SMS
- // The modem is initialised.
- _modem_initialised = true;
+ if (set_device_identity(&_dev_info.dev) && // Set up device identity
+ device_init(_dev_info.dev)) {// Initialise this device
+ // Get the integrated circuit ID of the SIM
+ if (get_iccid()) {
+ // Try a few times to get the IMSI (since on some modems this can
+ // take a while to be retrieved, especially if a SIM PIN
+ // was set)
+ for (x = 0; (x < 3) && !get_imsi(); x++) {
+ wait_ms(1000);
+ }
+
+ if (x < 3) { // If we got the IMSI, can get the others
+ if (get_imei() && // Get international mobile equipment identifier
+ get_meid() && // Probably the same as the IMEI
+ set_sms()) { // And set up SMS
+ // The modem is initialised.
+ _modem_initialised = true;
+ }
}
}
}
@@ -850,58 +856,60 @@
MBED_ASSERT(_at != NULL);
if (!is_registered_psd() && !is_registered_csd() && !is_registered_eps()) {
- tr_info("Searching Network...");
- // Enable the packet switched and network registration unsolicited result codes
- if (_at->send("AT+CREG=1") && _at->recv("OK") &&
- _at->send("AT+CGREG=1") && _at->recv("OK")) {
- atSuccess = true;
- if (_at->send("AT+CEREG=1")) {
- _at->recv("OK");
- // Don't check return value as this works for LTE only
- }
-
- if (atSuccess) {
- // See if we are already in automatic mode
- if (_at->send("AT+COPS?") && _at->recv("+COPS: %d", &status) &&
- _at->recv("OK")) {
- // If not, set it
- if (status != 0) {
- // Don't check return code here as there's not much
- // we can do if this fails.
- _at->send("AT+COPS=0") && _at->recv("OK");
- }
- }
-
- // Query the registration status directly as well,
- // just in case
- if (_at->send("AT+CREG?") && _at->recv("OK")) {
- // Answer will be processed by URC
- }
- if (_at->send("AT+CGREG?") && _at->recv("OK")) {
- // Answer will be processed by URC
- }
- if (_at->send("AT+CEREG?")) {
+ if (set_functionality_mode(FUNC_FULL)) {
+ tr_info("Searching Network...");
+ // Enable the packet switched and network registration unsolicited result codes
+ if (_at->send("AT+CREG=1") && _at->recv("OK") &&
+ _at->send("AT+CGREG=1") && _at->recv("OK")) {
+ atSuccess = true;
+ if (_at->send("AT+CEREG=1")) {
_at->recv("OK");
// Don't check return value as this works for LTE only
}
+
+ if (atSuccess) {
+ // See if we are already in automatic mode
+ if (_at->send("AT+COPS?") && _at->recv("+COPS: %d", &status) &&
+ _at->recv("OK")) {
+ // If not, set it
+ if (status != 0) {
+ // Don't check return code here as there's not much
+ // we can do if this fails.
+ _at->send("AT+COPS=0") && _at->recv("OK");
+ }
+ }
+
+ // Query the registration status directly as well,
+ // just in case
+ if (_at->send("AT+CREG?") && _at->recv("OK")) {
+ // Answer will be processed by URC
+ }
+ if (_at->send("AT+CGREG?") && _at->recv("OK")) {
+ // Answer will be processed by URC
+ }
+ if (_at->send("AT+CEREG?")) {
+ _at->recv("OK");
+ // Don't check return value as this works for LTE only
+ }
+ }
}
- }
- // Wait for registration to succeed
- at_set_timeout(1000);
- for (int waitSeconds = 0; !registered && (waitSeconds < 180); waitSeconds++) {
- registered = is_registered_psd() || is_registered_csd() || is_registered_eps();
- _at->recv(UNNATURAL_STRING);
- }
- at_set_timeout(at_timeout);
-
- if (registered) {
- // This should return quickly but sometimes the status field is not returned
- // so make the timeout short
+ // Wait for registration to succeed
at_set_timeout(1000);
- if (_at->send("AT+COPS?") && _at->recv("+COPS: %*d,%*d,\"%*[^\"]\",%d\n", &status)) {
- set_rat(status);
+ for (int waitSeconds = 0; !registered && (waitSeconds < 180); waitSeconds++) {
+ registered = is_registered_psd() || is_registered_csd() || is_registered_eps();
+ _at->recv(UNNATURAL_STRING);
}
at_set_timeout(at_timeout);
+
+ if (registered) {
+ // This should return quickly but sometimes the status field is not returned
+ // so make the timeout short
+ at_set_timeout(1000);
+ if (_at->send("AT+COPS?") && _at->recv("+COPS: %*d,%*d,\"%*[^\"]\",%d\n", &status)) {
+ set_rat(status);
+ }
+ at_set_timeout(at_timeout);
+ }
}
} else {
registered = true;
@@ -1190,6 +1198,11 @@
//application should call init() or connect() in order to initialize the modem
bool UbloxCellularBase::reboot_modem()
{
+ return (set_functionality_mode(FUNC_RESET));
+}
+
+bool UbloxCellularBase::set_functionality_mode(FunctionalityMode mode)
+{
bool return_val = false;
int at_timeout;
LOCK();
@@ -1198,23 +1211,40 @@
at_timeout = _at_timeout; // Has to be inside LOCK()s
at_set_timeout(3*60*1000); //command has 3 minutes timeout
- tr_info("rebooting modem...");
- if (_at->send("AT+CFUN=15") && _at->recv("OK")) {
- tr_info("reboot successful");
+ if (_at->send("AT+CFUN=%d", mode) && _at->recv("OK")) {
return_val = true;
}
- _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING;
- _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING;
- _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING;
- _modem_initialised = false;
+ if (mode == FUNC_RESET || mode == FUNC_RESET_WITH_SIM) {
+ _modem_initialised = false;
+ }
+
at_set_timeout(at_timeout);
UNLOCK();
return return_val;
}
+bool UbloxCellularBase::get_functionality_mode(int *mode)
+{
+ bool return_val = false;
+
+ if (mode == NULL) {
+ return false;
+ }
+
+ LOCK();
+ MBED_ASSERT(_at != NULL);
+
+ if ( (_at->send("AT+CFUN?") && _at->recv("+CFUN: %d", mode) && _at->recv("OK")) ) {
+ return_val = true;
+ }
+
+ UNLOCK();
+ return return_val;
+}
+
#ifdef TARGET_UBLOX_C030_R41XM
bool UbloxCellularBase::set_mno_profile(MNOProfile profile)
{
--- a/UbloxCellularBase.h Fri May 03 13:43:49 2019 +0500
+++ b/UbloxCellularBase.h Tue May 28 15:39:51 2019 +0500
@@ -199,6 +199,21 @@
NOT_USED = -1
} RAT;
+ /** Module functionality modes. Ref to section 5.3.3 of UBX-13002752 for details.
+ */
+ typedef enum {
+ FUNC_MIN = 0,
+ FUNC_FULL = 1,
+ FUNC_AIRPLANE = 4,
+ FUNC_EN_SIM_TLKT_DEDICATED = 6,
+ FUNC_DS_SIM_TLKT = 7,
+ FUNC_EN_SIM_TLKT_RAW = 9,
+ FUNC_RESET = 15,
+ FUNC_RESET_WITH_SIM = 16,
+ FUNC_MIN_WITH_SIM = 19,
+ FUNC_HALT = 127
+ } FunctionalityMode;
+
#ifdef TARGET_UBLOX_C030_R41XM
/** Supported MNO profiles for SARA-R4.
*/
@@ -264,6 +279,18 @@
*/
bool get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat);
+ /** Sets the modem to specified functionality mode.
+ *
+ * @return true if successful, otherwise false.
+ */
+ bool set_functionality_mode(FunctionalityMode mode);
+
+ /** Get the modem functionality mode
+ *
+ * @return true if successful, otherwise false.
+ */
+ bool get_functionality_mode(int *mode);
+
/** reboot the modem using AT+CFUN=15. Application should call init() or connect() before making any other API calls.
*
* @return true if successful, otherwise false.
u-blox