Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UBLOX_AT_CellularNetwork.cpp Source File

UBLOX_AT_CellularNetwork.cpp

00001 /*
00002  * Copyright (c) 2018, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "UBLOX_AT_CellularNetwork.h"
00019 #include "rtos/ThisThread.h"
00020 
00021 using namespace mbed;
00022 
00023 UBLOX_AT_CellularNetwork::UBLOX_AT_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device) : AT_CellularNetwork(atHandler, device)
00024 {
00025     _op_act = RAT_UNKNOWN;
00026 }
00027 
00028 UBLOX_AT_CellularNetwork::~UBLOX_AT_CellularNetwork()
00029 {
00030     if (_connection_status_cb) {
00031         _connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE , NSAPI_ERROR_CONNECTION_LOST );
00032     }
00033 }
00034 
00035 nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
00036 {
00037     nsapi_error_t ret = NSAPI_ERROR_OK ;
00038     CellularNetwork::AttachStatus status;
00039 
00040     get_attach(status);
00041     if (status == Attached) {
00042         tr_debug("RAT should only be set in detached state");
00043         return NSAPI_ERROR_UNSUPPORTED ;
00044     }
00045 
00046     _at.lock();
00047     switch (opRat) {
00048         case RAT_EGPRS:
00049 #if defined (UBX_MDM_SARA_R412M)
00050             _at.at_cmd_discard("+URAT", "=", "%d%d", 9, 8);
00051             break;
00052 #endif
00053 #if defined(UBX_MDM_SARA_U201)
00054         case RAT_GSM:
00055             _at.at_cmd_discard("+URAT", "=", "%d%d", 0, 0);
00056             break;
00057         case RAT_UTRAN:
00058         case RAT_HSDPA:
00059         case RAT_HSUPA:
00060         case RAT_HSDPA_HSUPA:
00061             _at.at_cmd_discard("+URAT", "=", "%d%d", 2, 2);
00062             break;
00063 #elif defined(UBX_MDM_SARA_R41XM)
00064         case RAT_CATM1:
00065             _at.at_cmd_discard("+URAT", "=", "%d%d", 7, 8);
00066             break;
00067         case RAT_NB1:
00068             _at.at_cmd_discard("+URAT", "=", "%d%d", 8, 7);
00069             break;
00070 #endif
00071         default:
00072             _op_act = RAT_UNKNOWN;
00073             ret = NSAPI_ERROR_UNSUPPORTED ;
00074             break;
00075     }
00076     _at.unlock();
00077     ubx_reboot();
00078 
00079     return (ret);
00080 }
00081 
00082 nsapi_error_t UBLOX_AT_CellularNetwork::ubx_reboot()
00083 {
00084     _at.lock();
00085     _at.at_cmd_discard("+CFUN", "=15");
00086 
00087     nsapi_error_t err = NSAPI_ERROR_OK ;
00088     Timer t1;
00089     t1.start();
00090     while (!(t1.read() >= 30)) {
00091         err = _at.at_cmd_discard("E0", "");
00092         if (err == NSAPI_ERROR_OK ) {
00093             break;
00094         } else {
00095             //Don't clear err here so that we get some error in case of failure
00096             _at.clear_error();
00097             rtos::ThisThread::sleep_for(1000);
00098         }
00099     }
00100     t1.stop();
00101     _at.unlock();
00102     return err;
00103 }