Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RM1000_AT.cpp Source File

RM1000_AT.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 "RM1000_AT.h"
00019 
00020 #include "RM1000_AT_CellularContext.h"
00021 #include "RM1000_AT_CellularNetwork.h"
00022 
00023 #include "mbed-trace/mbed_trace.h"
00024 #ifndef TRACE_GROUP
00025 #define TRACE_GROUP  "RIOT"
00026 #endif // TRACE_GROUP
00027 
00028 using namespace mbed;
00029 using namespace events;
00030 static const uint16_t retry_timeout[] = {1, 2, 4};
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     0,  // AT_CGSN_WITH_TYPE
00036     0,  // AT_CGDATA
00037     0,  // AT_CGAUTH
00038     0,  // AT_CNMI
00039     0,  // AT_CSMP
00040     0,  // AT_CMGF
00041     0,  // AT_CSDH
00042     1,  // PROPERTY_IPV4_STACK
00043     1,  // PROPERTY_IPV6_STACK
00044     1,  // PROPERTY_IPV4V6_STACK
00045     0,  // PROPERTY_NON_IP_PDP_TYPE
00046     0,  // PROPERTY_AT_CGEREP
00047 };
00048 
00049 RM1000_AT::RM1000_AT(FileHandle *fh) : AT_CellularDevice(fh)
00050 {
00051     tr_debug("RM1000_AT::RM1000_AT");
00052     set_cellular_properties(cellular_properties);
00053     set_retry_timeout_array(retry_timeout, sizeof(retry_timeout) / sizeof(retry_timeout[0]));
00054 }
00055 
00056 AT_CellularNetwork *RM1000_AT::open_network_impl(ATHandler &at)
00057 {
00058     tr_debug("RM1000_AT::open_network_impl");
00059     return new RM1000_AT_CellularNetwork(at, *this);
00060 }
00061 
00062 AT_CellularContext *RM1000_AT::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
00063 {
00064     tr_debug("RM1000_AT::create_context_impl");
00065     return new RM1000_AT_CellularContext(at, this, apn, cp_req, nonip_req);
00066 }
00067 
00068 nsapi_error_t RM1000_AT::init()
00069 {
00070     tr_debug("RM1000_AT::init");
00071 
00072     _at->lock();
00073     _at->flush();
00074     _at->at_cmd_discard("E0", ""); // echo off
00075 
00076     _at->at_cmd_discard("+SIM", "=physical");
00077 
00078     _at->set_at_timeout(5000);
00079     _at->at_cmd_discard("+CFUN", "=1"); // set full functionality
00080 
00081     _at->at_cmd_discard("+VERBOSE", "=0"); // verbose responses
00082 
00083     return _at->unlock_return_error();
00084 }
00085 
00086 #if MBED_CONF_RM1000_AT_PROVIDE_DEFAULT
00087 #include "UARTSerial.h"
00088 CellularDevice *CellularDevice::get_default_instance()
00089 {
00090     tr_debug("Calling CellularDevice::get_default_instance from RM1000_AT");
00091 
00092     static UARTSerial serial(MBED_CONF_RM1000_AT_TX, MBED_CONF_RM1000_AT_RX, MBED_CONF_RM1000_AT_BAUDRATE);
00093 #if defined (MBED_CONF_RM1000_AT_RTS) && defined(MBED_CONF_RM1000_AT_CTS)
00094     tr_debug("RM1000_AT flow control: RTS %d CTS %d", MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
00095     serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_RM1000_AT_RTS, MBED_CONF_RM1000_AT_CTS);
00096 #endif
00097     static RM1000_AT device(&serial);
00098     return &device;
00099 }
00100 #endif
00101