<commit_before>/* Copyright (c) 2017 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <mbed.h>

#include "CellularConnectionUtil.h"
#include "CellularTargets.h"
#include "CellularUtil.h"
#include "CellularConnectionUtil.h"

#include "EasyCellularConnection.h"

#include "CellularLog.h"

static CellularConnectionUtil cellularConnection;
static rtos::Semaphore cellularSemaphore(0);
static UARTSerial cellularSerial(MDMTXD, MDMRXD, MBED_CONF_APP_CELLULAR_SERIAL_SPEED);

static int cellular_status(int state, int next_state)
{
    if (state == CellularConnectionUtil::STATE_READY) {
        MBED_ASSERT(cellularSemaphore.release() == osOK);
    }
    return 1;
}

EasyCellularConnection::EasyCellularConnection()
{
    log_info("EasyCellularConnection start");
#if defined (MDMRTS) && defined (MDMCTS)
    log_info("Serial RTS/CTS flow control in use");
    cellularSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
#endif
    cellularConnection.set_serial(&cellularSerial);
    cellularConnection.set_callback(callback(cellular_status));
/*    if (cellularConnection.start()) {
        int ret_wait = cellularSemaphore.wait(180*1000);
        if (ret_wait == 1) {
            network_interface = cellularConnection.get_network();
            if (network_interface) {
                connect_success = true;
            }
            if (log_messages) {
                printf("[EasyConnect] Cellular connection %s!\n", connect_success?"succesful":"failed");
            }
        }
    }*/
}

EasyCellularConnection::~EasyCellularConnection()
{
    cellularConnection.stop();
}

void EasyCellularConnection::set_credentials(const char *apn, const char *uname, const char *pwd)
{
}

void EasyCellularConnection::set_sim_pin(const char *sim_pin)
{
}

nsapi_error_t EasyCellularConnection::connect(const char *sim_pin, const char *apn, const char *uname, const char *pwd)
{
    /*if (!connected) {
        wait();
    }
    cellularConnection.connect(sim_pin, apn, uname, pwd);*/
    return 0;
}

nsapi_error_t EasyCellularConnection::connect()
{
    /*attach();
    cellularConnection.connect();*/
    return 0;
}

nsapi_error_t EasyCellularConnection::disconnect()
{
    return 0;
}

bool EasyCellularConnection::is_connected()
{
    return 0;
}

const char *EasyCellularConnection::get_ip_address()
{
    return 0;
}

const char *EasyCellularConnection::get_netmask()
{
    return 0;
}

const char *EasyCellularConnection::get_gateway()
{
    return 0;
}

NetworkStack *EasyCellularConnection::get_stack()
{
    return 0;
}
<commit_msg>Smoke test changes with easy-connect<commit_after>/* Copyright (c) 2017 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <mbed.h>

#include "CellularConnectionUtil.h"
#include "CellularTargets.h"
#include "CellularUtil.h"
#include "CellularConnectionUtil.h"

#include "EasyCellularConnection.h"

#include "CellularLog.h"

#include "CellularConnectionUtil.h"
static CellularConnectionUtil cellularConnection;
static Semaphore cellularSemaphore(0);
static UARTSerial cellularSerial(MDMTXD, MDMRXD, MBED_CONF_APP_CELLULAR_SERIAL_SPEED);
static int cellular_status(int state, int next_state)
{
    printf("cellular_status %d=>%d", state, next_state);
    if (state == CellularConnectionUtil::STATE_READY) {
        MBED_ASSERT(cellularSemaphore.release() == osOK);
    }
    return 1;
}

EasyCellularConnection::EasyCellularConnection()
{
    log_info("EasyCellularConnection start");
}

EasyCellularConnection::~EasyCellularConnection()
{
    cellularConnection.stop();
}

void EasyCellularConnection::set_credentials(const char *apn, const char *uname, const char *pwd)
{
}

void EasyCellularConnection::set_sim_pin(const char *sim_pin)
{
}

nsapi_error_t EasyCellularConnection::connect(const char *sim_pin, const char *apn, const char *uname, const char *pwd)
{
    return connect();
}

nsapi_error_t EasyCellularConnection::connect()
{
#if defined (MDMRTS) && defined (MDMCTS)
    cellularSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
#endif
    cellularConnection.set_serial(&cellularSerial);
    cellularConnection.set_callback(callback(cellular_status));
    if (cellularConnection.start()) {
        int ret_wait = cellularSemaphore.wait(10*60*1000); // cellular network searching may take several minutes
        if (ret_wait != 1) {
            log_error("No cellular connection");
        }
    }

    return cellularConnection.get_network()?NSAPI_ERROR_OK:NSAPI_ERROR_NO_CONNECTION;
}

nsapi_error_t EasyCellularConnection::disconnect()
{
    return 0;
}

bool EasyCellularConnection::is_connected()
{
    return 0;
}

const char *EasyCellularConnection::get_ip_address()
{
    return cellularConnection.get_network()->get_ip_address();
}

const char *EasyCellularConnection::get_netmask()
{
    return cellularConnection.get_network()->get_netmask();
}

const char *EasyCellularConnection::get_gateway()
{
    return cellularConnection.get_network()->get_gateway();
}

NetworkStack *EasyCellularConnection::get_stack()
{
    return nsapi_ppp_get_stack();
}

{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.007706181341203476, 'mean_word_length': 4.722326454033771, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789174', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1840, 'n_words': 460}