if(sim_ready_flag==1&&csq_test_end_falg==0) //判斷SIM卡是否準備就緒,信號檢測結束標識是否是0
{
if(csq_send_flag==0&&csq_send_frequ!=0) //判斷指令發送標識及發送次數
{
send_string(csq); //發送網絡信號檢測指令
csq_send_frequ--;
csq_send_flag=1;
wait_2s=2;
timing_2s_end_flag=0;
}
if(csq_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發出及計時是否結束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回數據中是否包含‘OK’字符串
{
if(Rec_buf[8]=='9'&&Rec_buf[9]=='9') //判斷檢測的信號強度是否是99
{
if(csq_send_frequ==0) //判斷發送是否結束
{
csq_test_flag=0; //信號測試標識值0
net_connect_flag=0; //關閉網絡連接
}
}
else
{
csq_test_flag=1; //信號測試標識值1
csq_send_frequ=0;
}
csq_send_flag=0;
sig_strength_num[0]=Rec_buf[8]; //提取信號強度值
sig_strength_num[1]=Rec_buf[9];
Clr_Rec_buf();
}
else //如果返回數據中不包含‘OK’字符串,則檢測失敗
{
csq_send_flag=0;
if(csq_send_frequ==0) //判斷發送是否結束
{
csq_test_flag=0; //信號測試標識值0
net_connect_flag=0; //關閉網絡連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(csq_send_frequ==0) //判斷發送是否結束
{
csq_test_end_falg=1; //信號檢測結束標識值1
sim_ready_flag=0;
}
}
}
/************檢測網絡注冊狀態************/
if(csq_test_flag==1&&creg_test_end_flag==0) //判斷信號檢測是否成功,網絡狀態測試結束標識是否為0
{
if(creg_send_flag==0&&creg_send_frequ!=0) //判斷指令是否發出及發送次數
{
send_string(creg); //發送網絡注冊狀態指令
creg_send_frequ--;
creg_send_flag=1;
wait_2s=2;
timing_2s_end_flag=0;
}
if(creg_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發出及計時是否結束
{
if(strstr(Rec_buf,"OK")!=NULL&&(Rec_buf[11]=='1'||Rec_buf[11]=='5')) //判斷返回字符串是否包含‘OK’,網絡注冊狀態是‘1’或‘5’
{
creg_succ_flag=1; //注冊成功標識值1
creg_send_frequ=0; //發送次數值0
creg_send_flag=0;
Clr_Rec_buf();
}
else
{
creg_send_flag=0;
if(creg_send_frequ==0) //判斷發送是否結束
{
creg_succ_flag=0; //注冊成功標識值0
net_connect_flag=0; //關閉連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(creg_send_frequ==0) //判斷發送是否結束
{
creg_test_end_flag=1; //網絡注冊狀態測試結束標識值1
//csq_test_flag=0;
}
}
}
/************GPRS附著狀態************/
if(creg_succ_flag==1&&cgatt_test_end_falg==0) //判斷網絡注冊是否成功,GPRS附著狀態檢測結束標識是否為0
{
if(cgatt_send_flag==0&&cgatt_send_frequ!=0) //判斷指令是否發送及發送次數
{
//Clr_Rec_buf();
send_string(cgatt); //發送測試指令
cgatt_send_frequ--;
cgatt_send_flag=1;
wait_2s=4;
timing_2s_end_flag=0;
}
if(cgatt_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發出及計時是否結束
{
if(strstr(Rec_buf,"OK")!=NULL&&Rec_buf[10]=='1')
{
cgatt_test_flag=1; //GPRS附著檢測標識值1
cgatt_send_frequ=0; //發送次數值0
cgatt_send_flag=0;
Clr_Rec_buf();
}
else
{
cgatt_send_flag=0;
if(cgatt_send_frequ==0) //判斷發送是否結束
{
cgatt_test_flag=0; //GPRS附著檢測標識值0
net_connect_flag=0; //關閉網絡連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(cgatt_send_frequ==0)
{
creg_succ_flag=0;
cgatt_test_end_falg=1; //GPRS附著檢測結束標識值1
}
}
}
/************設置APN************/
if(cgatt_test_flag==1&&cstt_set_end_falg==0) //判斷GPRS附著檢測標識值
{
if(cstt_send_flag==0&&cstt_send_frequ!=0) //判斷指令是否發送及發送次數
{
send_string(cstt); //發送設置APN指令
cstt_send_frequ--;
cstt_send_flag=1;
wait_2s=3;
timing_2s_end_flag=0;
;
}
if(cstt_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發送及計時是否結束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回字符串是否包含“OK”
{
cstt_set_flag=1; //APN設置標識值1
cstt_send_frequ=0;
cstt_send_flag=0;
Clr_Rec_buf();
}
else
{
cstt_send_flag=0;
if(cstt_send_frequ==0) //判斷發送是否結束
{
cstt_set_flag=0; //APN設置標識值0
net_connect_flag=0;
gprs_p=0;
}
Clr_Rec_buf();
}
if(cstt_send_frequ==0)
{
cgatt_test_flag=0; //GPRS附著檢測標識值0
cstt_set_end_falg=1;
}
}
}
/*****建立無線鏈路(GPRS或者CSD)*****/
if(cstt_set_flag==1&&ciicr_set_end_falg==0) //判斷APN設置狀態標識
{
if(ciicr_send_flag==0&&ciicr_send_frequ!=0) //判斷指令是否發送及發送次數
{
send_string(ciicr); //發送建立無線鏈路指令
ciicr_send_frequ--;
ciicr_send_flag=1;
wait_2s=3;
t_1s=0;
timing_2s_end_flag=0;
}
if(ciicr_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發送及計時是否結束
{
if(strstr(Rec_buf,"OK")!=NULL)
{
ciicr_set_flag=1; //無線鏈路設置標識值1
ciicr_send_frequ=0;
cstt_set_flag=0; //APN設置狀態標識值0
ciicr_set_end_falg=1;
ciicr_send_flag=0;
for(i=0;i<24;i++)
str2[i]=Rec_buf[i];
Clr_Rec_buf();
}
else
{
n++;
if(n<4)
{
wait_2s=3;
t_1s=0;
timing_2s_end_flag=0;
}
if(n==4) //判斷發送是否結束
{
ciicr_send_flag=0;
//Clr_Rec_buf();
n=0;
}
if(ciicr_send_frequ==0)
{
ciicr_set_flag=0; //無線鏈路設置標識值0
cstt_set_flag=0; //APN設置狀態標識值0
ciicr_set_end_falg=1;
net_connect_flag=0; //關閉網絡連接
gprs_p=0;
}
for(i=0;i<24;i++)
str2[i]=Rec_buf[i];
Clr_Rec_buf();
}
}
}
ciicr這條指令就是發不出去,其他的都正常 |