Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QUECTEL_BC95.cpp Source File

QUECTEL_BC95.cpp

00001 /*
00002  * Copyright (c) 2017, 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 "QUECTEL_BC95_CellularNetwork.h"
00019 #include "QUECTEL_BC95_CellularContext.h"
00020 #include "QUECTEL_BC95_CellularInformation.h"
00021 #include "QUECTEL_BC95.h"
00022 #include "CellularLog.h"
00023 
00024 #define CONNECT_DELIM         "\r\n"
00025 #define CONNECT_BUFFER_SIZE   (1280 + 80 + 80) // AT response + sscanf format
00026 #define CONNECT_TIMEOUT       8000
00027 
00028 using namespace events;
00029 using namespace mbed;
00030 
00031 static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
00032     AT_CellularNetwork::RegistrationModeLAC,        // C_EREG
00033     AT_CellularNetwork::RegistrationModeDisable,    // C_GREG
00034     AT_CellularNetwork::RegistrationModeDisable,    // C_REG
00035     1,  // AT_CGSN_WITH_TYPE
00036     1,  // AT_CGDATA
00037     0,  // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
00038     1,  // AT_CNMI
00039     1,  // AT_CSMP
00040     1,  // AT_CMGF
00041     1,  // AT_CSDH
00042     1,  // PROPERTY_IPV4_STACK
00043     1,  // PROPERTY_IPV6_STACK
00044     0,  // PROPERTY_IPV4V6_STACK
00045     0,  // PROPERTY_NON_IP_PDP_TYPE
00046     0,  // PROPERTY_AT_CGEREP
00047 };
00048 
00049 QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
00050 {
00051     set_cellular_properties(cellular_properties);
00052 }
00053 
00054 nsapi_error_t QUECTEL_BC95::get_sim_state(SimState &state)
00055 {
00056     _at->lock();
00057     _at->flush();
00058     nsapi_error_t err = _at->at_cmd_discard("+NCCID", "?");
00059     _at->unlock();
00060 
00061     state = SimStateReady;
00062     if (err != NSAPI_ERROR_OK ) {
00063         tr_warn("SIM not readable.");
00064         state = SimStateUnknown;
00065     }
00066 
00067     return err;
00068 }
00069 
00070 AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at)
00071 {
00072     return new QUECTEL_BC95_CellularNetwork(at, *this);
00073 }
00074 
00075 AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
00076 {
00077     return new QUECTEL_BC95_CellularContext(at, this, apn, cp_req, nonip_req);
00078 }
00079 
00080 AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
00081 {
00082     return new QUECTEL_BC95_CellularInformation(at, *this);
00083 }
00084 
00085 nsapi_error_t QUECTEL_BC95::init()
00086 {
00087     setup_at_handler();
00088 
00089     _at->lock();
00090     _at->flush();
00091     _at->at_cmd_discard("", "");  //Send AT
00092 
00093     _at->at_cmd_discard("+CMEE", "=1"); // verbose responses
00094 
00095     return _at->unlock_return_error();
00096 }
00097 
00098 nsapi_error_t QUECTEL_BC95::set_baud_rate_impl(int baud_rate)
00099 {
00100     return _at->at_cmd_discard("+NATSPEED", "=", "%d%d%d%d%d%d%d", baud_rate, 30, 0, 2, 1, 0, 0);
00101 }
00102 
00103 #if MBED_CONF_QUECTEL_BC95_PROVIDE_DEFAULT
00104 #include "UARTSerial.h"
00105 CellularDevice *CellularDevice::get_default_instance()
00106 {
00107     static UARTSerial serial(MBED_CONF_QUECTEL_BC95_TX, MBED_CONF_QUECTEL_BC95_RX, MBED_CONF_QUECTEL_BC95_BAUDRATE);
00108 #if defined(MBED_CONF_QUECTEL_BC95_RTS) && defined(MBED_CONF_QUECTEL_BC95_CTS)
00109     tr_debug("QUECTEL_BC95 flow control: RTS %d CTS %d", MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS);
00110     serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_QUECTEL_BC95_RTS, MBED_CONF_QUECTEL_BC95_CTS);
00111 #endif
00112     static QUECTEL_BC95 device(&serial);
00113     return &device;
00114 }
00115 #endif