int VodafoneUSBModem::init() { if( !m_dongleConnected ) { if(!power()) { //Obviously cannot initialize the dongle if it is disconnected... ERR("Power is off"); return NET_INVALID; } m_dongleConnected = true; while( !m_dongle.connected() ) { m_dongle.tryConnect(); Thread::wait(10); } } if(m_atOpen) { return OK; } DBG("Starting AT thread if needed"); int ret = m_at.open(); if(ret) { return ret; } DBG("Sending initialisation commands"); ret = m_at.init(); if(ret) { return ret; } if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VODAFONEK3770) { INFO("Using a Vodafone K3770 Dongle"); #if USE_ONE_PORT DBG("Configuring unsolicited result codes support properly"); //Configuring port to enable 3GPP-compliant unsollicited response codes but disable Huawei-specific unsollicited response codes ret = m_at.executeSimple("AT^CURC=0;^PORTSEL=1", NULL); //Huawei-specific, not 3GPP-compliant if(ret != OK) { return NET_PROTOCOL; } #else //Configuring port to disable Huawei-specific unsollicited response codes ret = m_at.executeSimple("AT^CURC=0", NULL); //Huawei-specific, not 3GPP-compliant if(ret != OK) { return NET_PROTOCOL; } #endif } else if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VODAFONEK3772Z) { INFO("Using a Vodafone K3772-Z Dongle"); //FIXME this returns %USBMODEM: [0] MODEM DRIVER<CR><LF><CR><LF><CR><LF>OK<CR><LF> which is not a compliant response /* //Configuring modem to directly boot into modem mode ret = m_at.executeSimple("AT%USBMODEM=0", NULL); //Icera-specific, not 3GPP-compliant if(ret != OK) { return NET_PROTOCOL; } */ } else { WARN("Using an Unknown Dongle"); } ATCommandsInterface::ATResult result; //Wait for network registration CREGProcessor cregProcessor; do { DBG("Waiting for network registration"); ret = m_at.execute("AT+CREG?", &cregProcessor, &result); DBG("Result of command: Err code=%d\n", ret); DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); if(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING) { Thread::wait(3000); } } while(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING); if(cregProcessor.getStatus() == CREGProcessor::STATUS_FAILED) { ERR("Registration denied"); return NET_AUTH; } m_atOpen = true; return OK; }
int UbloxUSBGSMModem::init() { if( !m_dongleConnected ) { if(!power()) { //Obviously cannot initialize the dongle if it is disconnected... ERR("Power is off"); return NET_INVALID; } m_dongleConnected = true; while( !m_dongle.connected() ) { m_dongle.tryConnect(); Thread::wait(10); } } if(m_atOpen) { return OK; } DBG("Starting AT thread if needed"); int ret = m_at.open(); if(ret) { return ret; } DBG("Sending initialisation commands"); ret = m_at.init(); if(ret) { return ret; } if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_UBX) { INFO("Using a u-blox LISA-U"); } else { WARN("Using an Unknown Dongle"); } ATCommandsInterface::ATResult result; //Wait for network registration CREGProcessor cregProcessor; do { DBG("Waiting for network registration"); ret = m_at.execute("AT+CREG?", &cregProcessor, &result); DBG("Result of command: Err code=%d\n", ret); DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); if(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING) { Thread::wait(3000); } } while(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING); if(cregProcessor.getStatus() == CREGProcessor::STATUS_FAILED) { ERR("Registration denied"); return NET_AUTH; } m_atOpen = true; return OK; }