mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			PR review fixed: removed dead code, removed magic numbers.
							parent
							
								
									ea41e18aa0
								
							
						
					
					
						commit
						9e85767c80
					
				| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
coverage/
 | 
			
		||||
lcov/
 | 
			
		||||
results/
 | 
			
		||||
coverages/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,11 +22,6 @@
 | 
			
		|||
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
 | 
			
		||||
#endif
 | 
			
		||||
#include "CellularLog.h"
 | 
			
		||||
/*#define log_debug printf
 | 
			
		||||
#define log_info printf
 | 
			
		||||
#define log_warn printf
 | 
			
		||||
#define log_error printf
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
// timeout to wait for AT responses
 | 
			
		||||
#define TIMEOUT_POWER_ON     (1*1000)
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +38,7 @@ CellularConnectionUtil::CellularConnectionUtil() : _serial(0), _state(STATE_POWE
 | 
			
		|||
        _status_callback(0), _network(0), _power(0), _queue(8 * EVENTS_EVENT_SIZE),
 | 
			
		||||
        _queue_thread(0), _cellularDevice(&cellularDevice)
 | 
			
		||||
{
 | 
			
		||||
    memset(_sim_pin, sizeof(_sim_pin), 0);
 | 
			
		||||
    memset(_sim_pin, 0, sizeof(_sim_pin));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CellularConnectionUtil::~CellularConnectionUtil()
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +88,7 @@ bool CellularConnectionUtil::open_power(FileHandle *fh)
 | 
			
		|||
 | 
			
		||||
void CellularConnectionUtil::set_sim_pin(const char * sim_pin)
 | 
			
		||||
{
 | 
			
		||||
    strncpy(_sim_pin, sim_pin, PIN_SIZE+1);
 | 
			
		||||
    strncpy(_sim_pin, sim_pin, sizeof(_sim_pin));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool CellularConnectionUtil::open_sim()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,6 +24,13 @@
 | 
			
		|||
 | 
			
		||||
namespace mbed {
 | 
			
		||||
 | 
			
		||||
/* Maximum length of IPV6 address in ipv4-like dotted format. More info in 3gpp 27007.*/
 | 
			
		||||
const int MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT = 63;
 | 
			
		||||
/* Maximum length of access point name */
 | 
			
		||||
const int MAX_ACCESSPOINT_NAME_LENGTH = 100;
 | 
			
		||||
const int MAX_OPERATOR_NAME_LONG = 16;
 | 
			
		||||
const int MAX_OPERATOR_NAME_SHORT = 8;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  Class CellularNetwork
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -135,9 +142,9 @@ public:
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
        Status op_status;
 | 
			
		||||
        char op_long[16+9];
 | 
			
		||||
        char op_short[8+4];
 | 
			
		||||
        char op_num[8+4];
 | 
			
		||||
        char op_long[MAX_OPERATOR_NAME_LONG+1];
 | 
			
		||||
        char op_short[MAX_OPERATOR_NAME_SHORT+1];
 | 
			
		||||
        char op_num[MAX_OPERATOR_NAME_SHORT+1];
 | 
			
		||||
        RadioAccessTechnology op_rat;
 | 
			
		||||
        operator_t *next;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -152,14 +159,14 @@ public:
 | 
			
		|||
 | 
			
		||||
    /* PDP Context information */
 | 
			
		||||
    struct pdpcontext_params_t {
 | 
			
		||||
        char apn[100+1];
 | 
			
		||||
        char local_addr[63+1];
 | 
			
		||||
        char local_subnet_mask[63+1];
 | 
			
		||||
        char gateway_addr[63+1];
 | 
			
		||||
        char dns_primary_addr[63+1];
 | 
			
		||||
        char dns_secondary_addr[63+1];
 | 
			
		||||
        char p_cscf_prim_addr[63+1];
 | 
			
		||||
        char p_cscf_sec_addr[63+1];
 | 
			
		||||
        char apn[MAX_ACCESSPOINT_NAME_LENGTH+1];
 | 
			
		||||
        char local_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char local_subnet_mask[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char gateway_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char dns_primary_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char dns_secondary_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char p_cscf_prim_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        char p_cscf_sec_addr[MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT+1];
 | 
			
		||||
        int cid;
 | 
			
		||||
        int bearer_id;
 | 
			
		||||
        int im_signalling_flag;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -872,9 +872,6 @@ bool ATHandler::consume_to_stop_tag()
 | 
			
		|||
void ATHandler::resp_stop()
 | 
			
		||||
{
 | 
			
		||||
    // Do not return on error so that we can consume whatever there is in the buffer
 | 
			
		||||
    /*if (_last_err) {
 | 
			
		||||
        return;
 | 
			
		||||
    }*/
 | 
			
		||||
 | 
			
		||||
    log_debug("%s", __func__);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,10 +32,10 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a
 | 
			
		|||
 | 
			
		||||
    _at.set_urc_handler("NO CARRIER", callback(this, &AT_CellularNetwork::urc_no_carrier));
 | 
			
		||||
 | 
			
		||||
    memset(_apn, 0, MAX_APN_LENGTH);
 | 
			
		||||
    memset(_apn, 0, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
 | 
			
		||||
#ifdef MBED_CONF_APP_CELLULAR_APN
 | 
			
		||||
    strncpy(_apn, MBED_CONF_APP_CELLULAR_APN, MAX_APN_LENGTH);
 | 
			
		||||
    strncpy(_apn, MBED_CONF_APP_CELLULAR_APN, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
    log_debug("Using APN [%s] from json", _apn);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +55,7 @@ void AT_CellularNetwork::urc_no_carrier()
 | 
			
		|||
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
 | 
			
		||||
        const char *username, const char *password)
 | 
			
		||||
{
 | 
			
		||||
    strncpy(_apn, apn, MAX_APN_LENGTH);
 | 
			
		||||
    strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
    _uname = username;
 | 
			
		||||
    _pwd = password;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -65,7 +65,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
 | 
			
		|||
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
 | 
			
		||||
     AuthenticationType type, const char *username, const char *password)
 | 
			
		||||
{
 | 
			
		||||
    strncpy(_apn, apn, MAX_APN_LENGTH);
 | 
			
		||||
    strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
    _uname = username;
 | 
			
		||||
    _pwd = password;
 | 
			
		||||
    _authentication_type = type;
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +76,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
 | 
			
		|||
nsapi_error_t AT_CellularNetwork::connect(const char *apn,
 | 
			
		||||
        const char *username, const char *password)
 | 
			
		||||
{
 | 
			
		||||
    strncpy(_apn, apn, MAX_APN_LENGTH);
 | 
			
		||||
    strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
    _uname = username;
 | 
			
		||||
    _pwd = password;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -262,7 +262,7 @@ bool AT_CellularNetwork::get_context(nsapi_ip_stack_t requested_stack)
 | 
			
		|||
    _at.resp_start("+CGDCONT:");
 | 
			
		||||
    _cid = -1;
 | 
			
		||||
    int cid_max = 0; // needed when creating new context
 | 
			
		||||
    char apn[MAX_APN_LENGTH] = {0};
 | 
			
		||||
    char apn[MAX_ACCESSPOINT_NAME_LENGTH] = {0};
 | 
			
		||||
    int apn_len = 0;
 | 
			
		||||
 | 
			
		||||
    while (_at.info_resp()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -318,7 +318,7 @@ bool AT_CellularNetwork::get_context(nsapi_ip_stack_t requested_stack)
 | 
			
		|||
 | 
			
		||||
    // save the apn
 | 
			
		||||
    if (apn_len > 0 && !strlen(_apn)) {
 | 
			
		||||
        strncpy(_apn, apn, MAX_APN_LENGTH);
 | 
			
		||||
        strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    log_debug("Context id %d", _cid);
 | 
			
		||||
| 
						 | 
				
			
			@ -438,8 +438,6 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
 | 
			
		|||
        cell_id_read = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _AcT = (operator_t::RadioAccessTechnology)_at.read_int();
 | 
			
		||||
 | 
			
		||||
    _at.resp_stop();
 | 
			
		||||
 | 
			
		||||
    _at.cmd_start(cmd[i]);
 | 
			
		||||
| 
						 | 
				
			
			@ -884,15 +882,15 @@ nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &o
 | 
			
		|||
 | 
			
		||||
        switch (format) {
 | 
			
		||||
            case 0:
 | 
			
		||||
                _at.read_string(operator_params.op_long, 16+9);
 | 
			
		||||
                _at.read_string(operator_params.op_long, sizeof(operator_params.op_long));
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case 1:
 | 
			
		||||
                _at.read_string(operator_params.op_short, 8+4);
 | 
			
		||||
                _at.read_string(operator_params.op_short, sizeof(operator_params.op_short));
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            default:
 | 
			
		||||
                _at.read_string(operator_params.op_num, 8+4);
 | 
			
		||||
                _at.read_string(operator_params.op_num, sizeof(operator_params.op_num));
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,6 @@
 | 
			
		|||
namespace mbed {
 | 
			
		||||
 | 
			
		||||
#define AT_NETWORK_TRIALS 5
 | 
			
		||||
#define MAX_APN_LENGTH 63
 | 
			
		||||
 | 
			
		||||
class AT_CellularNetwork : public CellularNetwork, public AT_CellularBase
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -280,7 +279,7 @@ private:
 | 
			
		|||
 | 
			
		||||
protected:
 | 
			
		||||
    NetworkStack *_stack;
 | 
			
		||||
    char _apn[MAX_APN_LENGTH];
 | 
			
		||||
    char _apn[MAX_ACCESSPOINT_NAME_LENGTH];
 | 
			
		||||
    const char *_uname;
 | 
			
		||||
    const char *_pwd;
 | 
			
		||||
    nsapi_ip_stack_t _ip_stack_type_requested;
 | 
			
		||||
| 
						 | 
				
			
			@ -291,7 +290,6 @@ protected:
 | 
			
		|||
    AuthenticationType _authentication_type;
 | 
			
		||||
    int _lac;
 | 
			
		||||
    int _cell_id;
 | 
			
		||||
    operator_t::RadioAccessTechnology _AcT;
 | 
			
		||||
    RegistrationType _last_reg_type;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,6 +20,8 @@
 | 
			
		|||
 | 
			
		||||
using namespace mbed;
 | 
			
		||||
 | 
			
		||||
const int MAX_SIM_RESPONSE_LENGTH = 16;
 | 
			
		||||
 | 
			
		||||
AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +32,7 @@ AT_CellularSIM::~AT_CellularSIM()
 | 
			
		|||
 | 
			
		||||
nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state)
 | 
			
		||||
{
 | 
			
		||||
    char simstr[16];
 | 
			
		||||
    char simstr[MAX_SIM_RESPONSE_LENGTH];
 | 
			
		||||
    _at.lock();
 | 
			
		||||
    _at.flush();
 | 
			
		||||
    _at.cmd_start("AT+CPIN?");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -153,8 +153,6 @@ nsapi_error_t AT_CellularStack::socket_close(nsapi_socket_t handle)
 | 
			
		|||
 | 
			
		||||
    _at.lock();
 | 
			
		||||
 | 
			
		||||
    //_atHandler.setTimeout(...)
 | 
			
		||||
 | 
			
		||||
    err = socket_close_impl(sock_id);
 | 
			
		||||
 | 
			
		||||
    _at.unlock();
 | 
			
		||||
| 
						 | 
				
			
			@ -279,13 +277,6 @@ nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, S
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    unsigned max_packet_size = get_max_packet_size();
 | 
			
		||||
 | 
			
		||||
    /* Check parameters */
 | 
			
		||||
    if (size < max_packet_size) {
 | 
			
		||||
        //log_warn("Socket receive buffer smaller than max packet size! size:%d max_packet_size:%d", size, max_packet_size);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _at.lock();
 | 
			
		||||
 | 
			
		||||
    ret_val = socket_recvfrom_impl(socket, addr, buffer, size);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -56,8 +56,6 @@ void log_init(PinName tx, PinName rx, int baud)
 | 
			
		|||
    mbed_trace_mutex_release_function_set(serial_unlock);
 | 
			
		||||
    mbed_trace_init();
 | 
			
		||||
#else
 | 
			
		||||
    /*UARTSerial trace_serial(tx, rx, baud);
 | 
			
		||||
    FILE *trace = fdopen(&trace_serial, "w");*/
 | 
			
		||||
    serial_init(&stdio_uart, tx, rx);
 | 
			
		||||
    serial_baud(&stdio_uart, baud);
 | 
			
		||||
    stdio_uart_inited = 1;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,9 +20,6 @@
 | 
			
		|||
 | 
			
		||||
namespace mbed {
 | 
			
		||||
 | 
			
		||||
#define UART 1
 | 
			
		||||
#define MUX 2
 | 
			
		||||
 | 
			
		||||
#ifndef CELLULAR_DEVICE
 | 
			
		||||
#if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
 | 
			
		||||
#define CELLULAR_DEVICE QUECTEL_BC95
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,8 +22,7 @@ using namespace mbed;
 | 
			
		|||
 | 
			
		||||
QUECTEL_BC95_CellularNetwork::QUECTEL_BC95_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
 | 
			
		||||
{
 | 
			
		||||
    //TODO Set default to NB1 or leave it UNKNOWN
 | 
			
		||||
    //_ops_act = operator_t::OPS_NB1;
 | 
			
		||||
    _op_act = operator_t::RAT_NB1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QUECTEL_BC95_CellularNetwork::~QUECTEL_BC95_CellularNetwork()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue