static void processLine(const char *line) { pthread_mutex_lock(&s_commandmutex); if (sp_response == NULL) { /* no command pending */ handleUnsolicited(line); } else if (isFinalResponseSuccess(line)) { sp_response->success = 1; handleFinalResponse(line); } else if (isFinalResponseError(line)) { sp_response->success = 0; handleFinalResponse(line); } else if (s_smsPDU != NULL && 0 == strcmp(line, "> ")) { // See eg. TS 27.005 4.3 // Commands like AT+CMGS have a "> " prompt writeCtrlZ(s_smsPDU); s_smsPDU = NULL; } else switch (s_type) { case NO_RESULT: handleUnsolicited(line); break; case NUMERIC: if (sp_response->p_intermediates == NULL && isdigit(line[0]) ) { addIntermediate(line); } else { /* either we already have an intermediate response or the line doesn't begin with a digit */ handleUnsolicited(line); } break; case SINGLELINE: if (sp_response->p_intermediates == NULL && strStartsWith (line, s_responsePrefix) ) { addIntermediate(line); } else { /* we already have an intermediate response */ handleUnsolicited(line); } break; case MULTILINE: if (strStartsWith (line, s_responsePrefix)) { addIntermediate(line); } else { handleUnsolicited(line); } break; default: /* this should never be reached */ RLOGE("Unsupported AT command type %d\n", s_type); handleUnsolicited(line); break; } pthread_mutex_unlock(&s_commandmutex); }
static void processLine(const char *line) { struct atcontext *ac = getAtContext(); pthread_mutex_lock(&ac->commandmutex); if (ac->response == NULL) { /* No command pending. */ handleUnsolicited(line); } else if (isFinalResponseSuccess(line)) { ac->response->success = 1; handleFinalResponse(line); } else if (isFinalResponseError(line)) { ac->response->success = 0; handleFinalResponse(line); } else if (ac->smsPDU != NULL && 0 == strcmp(line, "> ")) { /* See eg. TS 27.005 4.3. Commands like AT+CMGS have a "> " prompt. */ writeCtrlZ(ac->smsPDU); ac->smsPDU = NULL; } else switch (ac->type) { case NO_RESULT: handleUnsolicited(line); break; case NUMERIC: if (ac->response->p_intermediates == NULL && isdigit(line[0])) { addIntermediate(line); } else { /* Either we already have an intermediate response or the line doesn't begin with a digit. */ handleUnsolicited(line); } break; case SINGLELINE: if (ac->response->p_intermediates == NULL && strStartsWith (line, ac->responsePrefix)) { addIntermediate(line); } else { /* We already have an intermediate response. */ handleUnsolicited(line); } break; case MULTILINE: if (strStartsWith (line, ac->responsePrefix)) { addIntermediate(line); } else { handleUnsolicited(line); } break; default: /* This should never be reached */ ALOGE("%s() Unsupported AT command type %d", __func__, ac->type); handleUnsolicited(line); break; } pthread_mutex_unlock(&ac->commandmutex); }
/** * returns 1 if line is a final response, either error or success * See 27.007 annex B * WARNING: NO CARRIER and others are sometimes unsolicited */ static int isFinalResponse(const char *line) { return isFinalResponseSuccess(line) || isFinalResponseError(line); }