本帖最后由 我是土匪 于 2015-9-30 11:20 编辑
7 个性化AT返回值解析:CSQ应用举例 AtcRspType CsqHandle( bool *urc) { char *Rsp_Str[ ] = {"OK","ERROR","+CSQ:"}; s16 res = -1; u8 i = 0; char *p = (char *)Rx_Data.buf; u8 rssi = 0; u8 ber = 0;
while ( '\r' == *p || '\n' == *p) { p++; }
for (i = 0; i < sizeof(Rsp_Str) / sizeof(Rsp_Str[0]); i++) { if (strstr( p,Rsp_Str)) { res = i; break; } }
*urc = FALSE; switch (res) { case 0: /* OK */ { if(SevrerConnectStatus == FALSE) { if (Csq_Ok) { //connectto server } else { bsp_StartTimer(CSQ_TIMER_ID,CSQ_TIMERPERIOD, (bspTimerHandler)AT_GetCSQ);
} }
At_Status = ATC_RSP_FINISH; } break; case 1: /* ERROR */ { bsp_StartTimer(CSQ_TIMER_ID,CSQ_TIMERPERIOD, (bspTimerHandler)AT_GetCSQ);
At_Status = ATC_RSP_FINISH;
} break; case 2: /* +CSQ: */ {
p += strlen("+CSQ:"); while (' ' == *p) { p++; }
while (*p >= '0' && *p <= '9') {
rssi *= 10; rssi += *p++ - '0'; }
while ((' '== *p) || (',' == *p)) { p++; } while (*p >= '0' && *p <= '9') {
ber *= 10; ber += *p++ - '0';
}
if (rssi > MIN_CSQ) { Csq_Ok = TRUE;
}
break; default: *urc = TRUE; break; }
} returnAt_Status; } |