int at_handshake() { int i; int err = 0; if (0 != pthread_equal(s_tid_reader, pthread_self())) { /* cannot be called from reader thread */ return AT_ERROR_INVALID_THREAD; } pthread_mutex_lock(&s_commandmutex); for (i = 0 ; i < HANDSHAKE_RETRY_COUNT ; i++) { /* some stacks start with verbose off */ err = at_send_command_full_nolock ("ATE0Q0V1", NO_RESULT, NULL, NULL, HANDSHAKE_TIMEOUT_MSEC, NULL); if (err == 0) { break; } } if (err == 0) { /* pause for a bit to let the input buffer drain any unmatched OK's (they will appear as extraneous unsolicited responses) */ sleepMsec(HANDSHAKE_TIMEOUT_MSEC); } pthread_mutex_unlock(&s_commandmutex); return err; }
/** * Periodically issue an AT command and wait for a response. * Used to ensure channel has start up and is active. */ int at_handshake(void) { int i; int err = 0; struct atcontext *ac = getAtContext(); if (0 != pthread_equal(ac->tid_reader, pthread_self())) /* Cannot be called from reader thread. */ return AT_ERROR_INVALID_THREAD; pthread_mutex_lock(&ac->commandmutex); for (i = 0 ; i < HANDSHAKE_RETRY_COUNT ; i++) { /* Some stacks start with verbose off. */ err = at_send_command_full_nolock ("ATE0V1", NO_RESULT, NULL, NULL, HANDSHAKE_TIMEOUT_MSEC, NULL); if (err == 0) break; } if (err == 0) { /* Pause for a bit to let the input buffer drain any unmatched OK's (they will appear as extraneous unsolicited responses). */ ALOGD("%s() pausing %d ms to drain unmatched OK's...", __func__, HANDSHAKE_TIMEOUT_MSEC); sleepMsec(HANDSHAKE_TIMEOUT_MSEC); } pthread_mutex_unlock(&ac->commandmutex); return err; }