src/atchannel.c
/**
 * Periodically issue an AT command and wait for a response.
 * Used to ensure channel has start up and is active
 */
Periodically issue an AT command and wait for a response.
Used to ensure channel has start up and is active
Periodically issue an AT command and wait for a response . Used to ensure channel has start up and is active
ATReturn at_handshake(ATChannel* atch, const char* command, int retryCount, long long timeoutMsec)
{
    const char* HANDSHAKE_DEFAULT_COMMAND = "ATE0Q0V1";
    const int HANDSHAKE_DEFAULT_RETRY_COUNT = 8;
    const int HANDSHAKE_DEFAULT_TIMEOUT_MSEC = 250;
    if (!atch) {
        return AT_ERROR_INVALID_ARGUMENT;
    }
    if (!atch->impl) {
        return AT_ERROR_INVALID_OPERATION;
    }
    if (retryCount < 0) {
        return AT_ERROR_INVALID_ARGUMENT;
    }
    if (timeoutMsec < 0) {
        return AT_ERROR_INVALID_ARGUMENT;
    }
    int i;
    ATReturn err = 0;
    if (!command) {
        command = HANDSHAKE_DEFAULT_COMMAND;
    }
    if (retryCount == 0) {
        retryCount = HANDSHAKE_DEFAULT_RETRY_COUNT;
    }
    if (timeoutMsec == 0) {
        timeoutMsec = HANDSHAKE_DEFAULT_TIMEOUT_MSEC;
    }
    if (0 != pthread_equal(atch->impl->tid_reader, pthread_self())) {
        return AT_ERROR_INVALID_THREAD;
    }
    pthread_mutex_lock(&atch->impl->commandmutex);
    for (i = 0 ; i < retryCount; i++) {
        err = at_send_command_full_nolock(atch, command, NO_RESULT,
                    NULL, NULL, timeoutMsec, NULL);
        if (err == 0) {
            break;
        }
    }
    if (err == 0) {
        sleepMsec(timeoutMsec);
    }
    pthread_mutex_unlock(&atch->impl->commandmutex);
    return err;
}
ATReturn at_handshake ( ATChannel * atch , const char * command , int retryCount , long long timeoutMsec ) { const char * HANDSHAKE_DEFAULT_COMMAND = " " ; const int HANDSHAKE_DEFAULT_RETRY_COUNT = 8 ; const int HANDSHAKE_DEFAULT_TIMEOUT_MSEC = 250 ; if ( ! atch ) { return AT_ERROR_INVALID_ARGUMENT ; } if ( ! atch -> impl ) { return AT_ERROR_INVALID_OPERATION ; } if ( retryCount < 0 ) { return AT_ERROR_INVALID_ARGUMENT ; } if ( timeoutMsec < 0 ) { return AT_ERROR_INVALID_ARGUMENT ; } int i ; ATReturn err = 0 ; if ( ! command ) { command = HANDSHAKE_DEFAULT_COMMAND ; } if ( retryCount == 0 ) { retryCount = HANDSHAKE_DEFAULT_RETRY_COUNT ; } if ( timeoutMsec == 0 ) { timeoutMsec = HANDSHAKE_DEFAULT_TIMEOUT_MSEC ; } if ( 0 != pthread_equal ( atch -> impl -> tid_reader , pthread_self ( ) ) ) { return AT_ERROR_INVALID_THREAD ; } pthread_mutex_lock ( & atch -> impl -> commandmutex ) ; for ( i = 0 ; i < retryCount ; i ++ ) { err = at_send_command_full_nolock ( atch , command , NO_RESULT , NULL , NULL , timeoutMsec , NULL ) ; if ( err == 0 ) { break ; } } if ( err == 0 ) { sleepMsec ( timeoutMsec ) ; } pthread_mutex_unlock ( & atch -> impl -> commandmutex ) ; return err ; }
Periodically issue an AT command and wait for a response.
Periodically issue an AT command and wait for a response .
/* cannot be called from reader thread */ /* some stacks start with verbose off */ /* pause for a bit to let the input buffer drain any unmatched OK's
           (they will appear as extraneous unsolicited responses) */