⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wcegprs.cpp

📁 Open DMT Client C Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }    return rtn;}// ----------------------------------------------------------------------------/* make sure a connection has been established */static utBool _wceGprsConnect(HRASCONN *pRasConn){    const char *entryName = propGetString(PROP_COMM_CONNECTION, DEFAULT_ENTRY_NAME);    if (pRasConn) { *pRasConn = NULL; }    /* already connected? */    HRASCONN hExistingRasConn = wceGprsGetConnection(entryName);    if (wceGprsIsConnected(hExistingRasConn)) {        logDEBUG(LOGSRC,"GPRS already connected: %s", entryName);        _wceResetTimerLong  = 0L;        _wceResetTimerShort = 0L;        if (pRasConn) { *pRasConn = hExistingRasConn; }        return utTrue;    }    //logDEBUG(LOGSRC,"GPRS attempt connection: %s", entryName);    /* signal strength */    // check signal strength here    /* RASDIALPARAMS structure */    RASDIALPARAMS rasDialParms;    memset(&rasDialParms, 0, sizeof(rasDialParms));    rasDialParms.dwSize = sizeof(rasDialParms);    strWideCopy(rasDialParms.szEntryName, RAS_MaxEntryName, entryName, -1);    /* init RAS configuration from system parameters */    BOOL hasRasParams = FALSE;    BOOL inclPass = FALSE;	DWORD rasEntryErr = RasGetEntryDialParams(NULL, &rasDialParms, &inclPass);    if (rasEntryErr) {        // Possible errors:        //  1168  ERROR_NOT_FOUND   Element not found        logERROR(LOGSRC,"No dial params [%ld]: %ls", rasEntryErr, rasDialParms.szEntryName);        //return utFalse;    } else {        hasRasParams = TRUE;    }    //logINFO(LOGSRC,"S) inclPass : %d\n" , inclPass);    /* override parameters */    // szPhoneNumber    const char *phoneNum = propGetString(PROP_COMM_APN_PHONE, "");    if (phoneNum && *phoneNum) {        strWideCopy(rasDialParms.szPhoneNumber, RAS_MaxPhoneNumber, phoneNum, -1);        hasRasParams = TRUE;    }    // szCallbackNumber    const char *callback = "";    if (callback && *callback) {        strWideCopy(rasDialParms.szCallbackNumber, RAS_MaxCallbackNumber, callback, -1);        hasRasParams = TRUE;    }    // szUserName    const char *apnUser = propGetString(PROP_COMM_APN_USER,"");    if (apnUser && *apnUser) {        strWideCopy(rasDialParms.szUserName, UNLEN, apnUser, -1);        hasRasParams = TRUE;    }    // szPassword    const char *apnPass = propGetString(PROP_COMM_APN_PASSWORD,"");    if (apnPass && *apnPass) {        strWideCopy(rasDialParms.szPassword, PWLEN, apnPass, -1);        hasRasParams = TRUE;    }    // szDomain    const char *apnDomain = propGetString(PROP_COMM_APN_SERVER,"");    if (apnDomain && *apnDomain) {        strWideCopy(rasDialParms.szDomain, DNLEN, apnDomain, -1);        hasRasParams = TRUE;    }        /* do we have any dialing parameters? */    if (!hasRasParams) {        logERROR(LOGSRC,"No RAS dialing parameters!");        return utFalse;    }    /* Dial/Connect */#if defined(WCEGPRS_CONNECT_VIA_RASDIAL_EXE)    // External RASDIAL connection here (if implemented)#else    // "RasDial(...)" appears to have its share of problems:    // - On several occasions, 'RasDial' has caused the program to terminate.    // - On at least one occasion, a call to 'RasDial' never returned.  I suspect    //   that it had terminated the current thread.    // - 'RasDial' may get in an endless 'ERROR_PORT_DISCONNECTED' error loop even    //   though a valid SIM card is in place and GPRS coverage is fine.  (I've been    //   able to recover in this situation by hard-resetting the phone).    /* call 'RasDial(...)' */    // In marginal GPRS coverage, this call can hang for more than 60 seconds     // before returning a failed connection attempt.    UInt32 rasDialStartTime = utcGetTimeSec();    logDEBUG(LOGSRC,"[%lu] 'RasDial' start ...", rasDialStartTime);    HRASCONN hRasConn = NULL;    DWORD rasDialErr = RasDial(NULL,NULL,&rasDialParms,NULL,NULL,&hRasConn);    UInt32 rasDialEndTime = utcGetTimeSec();    logDEBUG(LOGSRC,"[%lu] 'RasDial' end ... [%ld sec]", rasDialEndTime, (rasDialEndTime - rasDialStartTime));    if (pRasConn) { *pRasConn = hRasConn; }        /* check returned errors */	if (rasDialErr != SUCCESS) {        // Errors encountered (see 'raserror.h' for a complete list)        // 604  ERROR_WRONG_INFO_SPECIFIED  [may be sent when GPRS is unavailable]        // 608  ERROR_DEVICE_DOES_NOT_EXIST [likely an invalid entry name]        // 619  ERROR_PORT_DISCONNECTED     [may already be connected]        // 631  ERROR_USER_DISCONNECTION        // 633  ERROR_PORT_NOT_AVAILABLE        // 660  ERROR_NO_RESPONSES        // 679  ERROR_NO_CARRIER        // ---------------------------------                /* hang-up */        if (hRasConn) {            wceGprsDisconnect(hRasConn);        } else {            // wait here even if 'RasDial' failed and 'hRasConn' is null            threadSleepMS(3500L);        }                /* check specific error */        if (rasDialErr == ERROR_WRONG_INFO_SPECIFIED) {            // - I've seen this error occur when either GPRS is unavailable, or the            // phone is turned off.  For now, just continue with the retry ...        } else        if (rasDialErr == ERROR_PORT_DISCONNECTED) {            // - This most likely indicates that GPRS coverage is not available.            // - When this error occurs multiple times and GPRS *IS* available, I've been             //   able to recover by manually turning off the phone connection, then turning             //   it back on (while testing on an HP hw6945).  In an attempt to perform this             //   reset automatically, we'll try to detect this state and attempt to hang-up             //   the connection, hopefully clearing this error state on the next iteration.            //   This will not be effective if GPRS coverage is not available.            // - This error may also occur if the SIM card is not installed, in which            //   case this error will continue forever.            logERROR(LOGSRC,"RasDial ERROR_PORT_DISCONNECTED [%ld]", (Int32)rasDialErr);        } else        if (rasDialErr == ERROR_PORT_NOT_AVAILABLE) {            // - This likely indicates that the phone/modem is locked up and unusable.            // - Or we may actually be connected, but under a different entry-name.            // - This error can also occur if the SIM card is not installed, in which            //   case this error will continue forever.            logERROR(LOGSRC,"RasDial ERROR_PORT_NOT_AVAILABLE [%ld]", (Int32)rasDialErr);        } else        if (rasDialErr == ERROR_DEVICE_DOES_NOT_EXIST) {            // - This likely indicates an invalid entry name            logERROR(LOGSRC,"RasDial ERROR_DEVICE_DOES_NOT_EXIST [%ld] - %s", (Int32)rasDialErr, entryName);            wceGprsListEntryNames(); // displa entry names         } else {            logINFO(LOGSRC,"RasDial connection failed [raserr=%ld]", (Int32)rasDialErr);        }                /* short timeout */        // Short timeouts specifically checks for ERROR_PORT_NOT_AVAILABLE errors.        // 'ERROR_PORT_NOT_AVAILABLE' errors may not be recoverable.        if (rasDialErr == ERROR_PORT_NOT_AVAILABLE) {            // we may not be able to recover without a rebbot, set a short timer            if (_wceResetTimerShort == 0L) {                // default reset timer, short delay                _wceResetTimerShort = utcGetTimer();            }        } else {            // we may be able to recover from non-port-not-available errors            _wceResetTimerShort = 0L;        }        /* long timeout */        // Long timeouts check for no connectivity, for any reason, for a long period of time.        if (_wceResetTimerLong == 0L) {            // default reset timer, long delay            _wceResetTimerLong = utcGetTimer();        }        /* check timeouts */        if ((MODEM_LONG_RESET_TIMEOUT > 0L) && (_wceResetTimerLong > 0L) &&             utcIsTimerExpired(_wceResetTimerLong,MODEM_LONG_RESET_TIMEOUT)) {            // we've been trying unsuccessfully for awhile now, just reset the modem            _wceResetTimerLong  = utcGetTimer();            _wceResetTimerShort = 0L;            wceGprsResetModem();            // (if we've rebooted, control should not reach here)        } else        if ((MODEM_SHORT_RESET_TIMEOUT > 0L) && (_wceResetTimerShort > 0L) &&             utcIsTimerExpired(_wceResetTimerShort,MODEM_SHORT_RESET_TIMEOUT)) {            // we've been trying unsuccessfully for awhile now, just reset the modem            _wceResetTimerLong  = utcGetTimer();            _wceResetTimerShort = 0L;            wceGprsResetModem();            // (if we've rebooted, control should not reach here)        }        /* 'continue' attempt */        // after a few minutes, start indicating that we've made a connection        // (the protocol transport will fail if it cannot actually transmit)        // we do this just-in-case this error is incorrect, which may in fact         // be the case if we are connected using a different "Connection name".        if (utcIsTimerExpired(_wceResetTimerLong,MODEM_CONTINUE_TIMEOUT)) {            logERROR(LOGSRC,"Continuing as if connected ...");            return utTrue;        }        /* connection failed */        return utFalse;    }    #endif // else defined(WCEGPRS_CONNECT_VIA_RASDIAL_EXE)    /* connected! */    logINFO(LOGSRC,"------- GPRS Connection Success ------");    _wceResetTimerLong  = 0L;    _wceResetTimerShort = 0L;    threadSleepMS(2000L);    return utTrue;}/* make sure a connection has been established */utBool wceGprsConnect(HRASCONN *pRasConn, utBool disconnectFirst){    utBool rtn = utFalse;    /* force a disconnect first? */    if (disconnectFirst && pRasConn) {        // This usually indicates that the caller was unable to establish a socket         // connection during the last GPRS connection.  Disconnect the previous         // failing connection before establishing a new connection.  In this         // situation, it is possible that if enough time has passed since the last        // socket-connection attempt, the OS may have already closed the old failing        // GPRS-connection and established a new one.  In which case we may be closing         // a good GPRS-connection.  There's no easy way to determine if the OS has        // in fact already established a connection, so going ahead and closing the        // current GPRS-connection, and establishing a new connection is the safest        // thing to do at this point.        logINFO(LOGSRC,"Forcing a disconnect before establishing a new connection");        wceGprsDisconnect(*pRasConn);    }    /* connect (may use an existing connection, if available) */    // This can take up to 60 seconds in a marginal GPRS coverage area.    rtn = _wceGprsConnect(pRasConn);        return rtn;}// ----------------------------------------------------------------------------#endif // defined(TARGET_WINCE)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -