Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TELIT_ME910.cpp Source File

TELIT_ME910.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 "TELIT_ME910.h"
00019 #include "TELIT_ME910_CellularContext.h"
00020 #include "AT_CellularNetwork.h"
00021 #include "PinNames.h"
00022 #include "rtos/ThisThread.h"
00023 
00024 using namespace mbed;
00025 using namespace rtos;
00026 using namespace events;
00027 
00028 #if !defined(MBED_CONF_TELIT_ME910_PWR)
00029 #define MBED_CONF_TELIT_ME910_PWR    NC
00030 #endif
00031 
00032 #if !defined(MBED_CONF_TELIT_ME910_TX)
00033 #define MBED_CONF_TELIT_ME910_TX    NC
00034 #endif
00035 
00036 #if !defined(MBED_CONF_TELIT_ME910_RX)
00037 #define MBED_CONF_TELIT_ME910_RX    NC
00038 #endif
00039 
00040 #if !defined(MBED_CONF_TELIT_ME910_POLARITY)
00041 #define MBED_CONF_TELIT_ME910_POLARITY    1 // active high
00042 #endif
00043 
00044 static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
00045     AT_CellularNetwork::RegistrationModeLAC,    // C_EREG
00046     AT_CellularNetwork::RegistrationModeLAC,    // C_GREG
00047     AT_CellularNetwork::RegistrationModeLAC,    // C_REG
00048     0,  // AT_CGSN_WITH_TYPE
00049     0,  // AT_CGDATA
00050     1,  // AT_CGAUTH
00051     1,  // AT_CNMI
00052     1,  // AT_CSMP
00053     1,  // AT_CMGF
00054     1,  // AT_CSDH
00055     1,  // PROPERTY_IPV4_STACK
00056     1,  // PROPERTY_IPV6_STACK
00057     1,  // PROPERTY_IPV4V6_STACK
00058     0,  // PROPERTY_NON_IP_PDP_TYPE
00059     1,  // PROPERTY_AT_CGEREP
00060 };
00061 
00062 //the delay between sending AT commands
00063 static const uint16_t DEFAULT_DELAY_BETWEEN_AT_COMMANDS = 20;
00064 
00065 TELIT_ME910::TELIT_ME910(FileHandle *fh, PinName pwr, bool active_high)
00066     : AT_CellularDevice(fh),
00067       _active_high(active_high),
00068       _pwr_key(pwr, !_active_high)
00069 {
00070     set_cellular_properties(cellular_properties);
00071 }
00072 
00073 AT_CellularContext *TELIT_ME910::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req)
00074 {
00075     return new TELIT_ME910_CellularContext(at, this, apn, cp_req, nonip_req);
00076 }
00077 
00078 
00079 uint16_t TELIT_ME910::get_send_delay() const
00080 {
00081     return DEFAULT_DELAY_BETWEEN_AT_COMMANDS;
00082 }
00083 
00084 nsapi_error_t TELIT_ME910::init()
00085 {
00086     nsapi_error_t err = AT_CellularDevice::init();
00087     if (err != NSAPI_ERROR_OK ) {
00088         return err;
00089     }
00090     _at->lock();
00091 #if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS)
00092     _at->at_cmd_discard("&K3;&C1;&D0", "");
00093 #else
00094     _at->at_cmd_discard("&K0;&C1;&D0", "");
00095 #endif
00096 
00097     // AT#QSS=1
00098     // Enable the Query SIM Status unsolicited indication in the ME. The format of the
00099     // unsolicited indication is the following:
00100     // #QSS: <status>
00101     // The ME informs at
00102     // every SIM status change through the basic unsolicited indication where <status> range is 0...1
00103     // <status> values:
00104     // - 0: SIM not inserted
00105     // - 1: SIM inserted
00106     _at->at_cmd_discard("#QSS", "=1");
00107 
00108     // AT#PSNT=1
00109     // Set command enables unsolicited result code for packet service network type (PSNT)
00110     // having the following format:
00111     // #PSNT:<nt>
00112     // <nt> values:
00113     // - 0: GPRS network
00114     // - 4: LTE network
00115     // - 5: unknown or not registered
00116     _at->at_cmd_discard("#PSNT", "=1");
00117 
00118     // AT+CMER=2
00119     // Set command enables sending of unsolicited result codes from TA to TE in the case of
00120     // indicator state changes.
00121     // Current setting: buffer +CIEV Unsolicited Result Codes in the TA when TA-TE link is
00122     // reserved (e.g. on-line data mode) and flush them to the TE after
00123     // reservation; otherwise forward them directly to the TE
00124     _at->at_cmd_discard("+CMER", "=2");
00125 
00126     // AT+CMEE=2
00127     // Set command disables the use of result code +CME ERROR: <err> as an indication of an
00128     // error relating to the +Cxxx command issued. When enabled, device related errors cause the +CME
00129     // ERROR: <err> final result code instead of the default ERROR final result code. ERROR is returned
00130     // normally when the error message is related to syntax, invalid parameters or DTE functionality.
00131     // Current setting: enable and use verbose <err> values
00132     _at->at_cmd_discard("+CMEE", "=2");
00133 
00134     // AT&W&P
00135     // - AT&W: Execution command stores on profile <n> the complete configuration of the device. If
00136     //         parameter is omitted, the command has the same behavior of AT&W0.
00137     // - AT&P: Execution command defines which full profile will be loaded at startup. If parameter
00138     //         is omitted, the command has the same behavior as AT&P0
00139     _at->at_cmd_discard("&W&P", "");
00140 
00141     return _at->unlock_return_error();
00142 }
00143 
00144 #if MBED_CONF_TELIT_ME910_PROVIDE_DEFAULT
00145 #include "UARTSerial.h"
00146 CellularDevice *CellularDevice::get_default_instance()
00147 {
00148     static UARTSerial serial(MBED_CONF_TELIT_ME910_TX, MBED_CONF_TELIT_ME910_RX, MBED_CONF_TELIT_ME910_BAUDRATE);
00149 #if defined (MBED_CONF_TELIT_ME910_RTS) && defined (MBED_CONF_TELIT_ME910_CTS)
00150     serial.set_flow_control(SerialBase::RTSCTS, MBED_CONF_TELIT_ME910_RTS, MBED_CONF_TELIT_ME910_CTS);
00151 #endif
00152     static TELIT_ME910 device(&serial,
00153                               MBED_CONF_TELIT_ME910_PWR,
00154                               MBED_CONF_TELIT_ME910_POLARITY);
00155     return &device;
00156 }
00157 #endif
00158 
00159 nsapi_error_t TELIT_ME910::hard_power_on()
00160 {
00161     soft_power_on();
00162 
00163     return NSAPI_ERROR_OK ;
00164 }
00165 
00166 nsapi_error_t TELIT_ME910::soft_power_on()
00167 {
00168     _pwr_key = _active_high;
00169     ThisThread::sleep_for(500);
00170     _pwr_key = !_active_high;
00171     ThisThread::sleep_for(5000);
00172     _pwr_key = _active_high;
00173     ThisThread::sleep_for(5000);
00174 
00175     return NSAPI_ERROR_OK ;
00176 }
00177 
00178 nsapi_error_t TELIT_ME910::hard_power_off()
00179 {
00180     _pwr_key = !_active_high;
00181     ThisThread::sleep_for(10000);
00182 
00183     return NSAPI_ERROR_OK ;
00184 }
00185 
00186 nsapi_error_t TELIT_ME910::soft_power_off()
00187 {
00188     return AT_CellularDevice::soft_power_off();
00189 }