|
還有一個問題就是單片機(jī)在控制GPRS模塊聯(lián)網(wǎng)時有一條指令不發(fā),其他的都很正常,真是不知道是怎么回事了
if(sim_ready_flag==1&&csq_test_end_falg==0) //判斷SIM卡是否準(zhǔn)備就緒,信號檢測結(jié)束標(biāo)識是否是0
{
if(csq_send_flag==0&&csq_send_frequ!=0) //判斷指令發(fā)送標(biāo)識及發(fā)送次數(shù)
{
send_string(csq); //發(fā)送網(wǎng)絡(luò)信號檢測指令
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) //判斷指令是否發(fā)出及計(jì)時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回?cái)?shù)據(jù)中是否包含‘OK’字符串
{
if(Rec_buf[8]=='9'&&Rec_buf[9]=='9') //判斷檢測的信號強(qiáng)度是否是99
{
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_flag=0; //信號測試標(biāo)識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
}
}
else
{
csq_test_flag=1; //信號測試標(biāo)識值1
csq_send_frequ=0;
}
csq_send_flag=0;
sig_strength_num[0]=Rec_buf[8]; //提取信號強(qiáng)度值
sig_strength_num[1]=Rec_buf[9];
Clr_Rec_buf();
}
else //如果返回?cái)?shù)據(jù)中不包含‘OK’字符串,則檢測失敗
{
csq_send_flag=0;
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_flag=0; //信號測試標(biāo)識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_end_falg=1; //信號檢測結(jié)束標(biāo)識值1
sim_ready_flag=0;
}
}
}
/************檢測網(wǎng)絡(luò)注冊狀態(tài)************/
if(csq_test_flag==1&&creg_test_end_flag==0) //判斷信號檢測是否成功,網(wǎng)絡(luò)狀態(tài)測試結(jié)束標(biāo)識是否為0
{
if(creg_send_flag==0&&creg_send_frequ!=0) //判斷指令是否發(fā)出及發(fā)送次數(shù)
{
send_string(creg); //發(fā)送網(wǎng)絡(luò)注冊狀態(tài)指令
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) //判斷指令是否發(fā)出及計(jì)時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL&&(Rec_buf[11]=='1'||Rec_buf[11]=='5')) //判斷返回字符串是否包含‘OK’,網(wǎng)絡(luò)注冊狀態(tài)是‘1’或‘5’
{
creg_succ_flag=1; //注冊成功標(biāo)識值1
creg_send_frequ=0; //發(fā)送次數(shù)值0
creg_send_flag=0;
Clr_Rec_buf();
}
else
{
creg_send_flag=0;
if(creg_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
creg_succ_flag=0; //注冊成功標(biāo)識值0
net_connect_flag=0; //關(guān)閉連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(creg_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
creg_test_end_flag=1; //網(wǎng)絡(luò)注冊狀態(tài)測試結(jié)束標(biāo)識值1
//csq_test_flag=0;
}
}
}
/************GPRS附著狀態(tài)************/
if(creg_succ_flag==1&&cgatt_test_end_falg==0) //判斷網(wǎng)絡(luò)注冊是否成功,GPRS附著狀態(tài)檢測結(jié)束標(biāo)識是否為0
{
if(cgatt_send_flag==0&&cgatt_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
//Clr_Rec_buf();
send_string(cgatt); //發(fā)送測試指令
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) //判斷指令是否發(fā)出及計(jì)時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL&&Rec_buf[10]=='1')
{
cgatt_test_flag=1; //GPRS附著檢測標(biāo)識值1
cgatt_send_frequ=0; //發(fā)送次數(shù)值0
cgatt_send_flag=0;
Clr_Rec_buf();
}
else
{
cgatt_send_flag=0;
if(cgatt_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
cgatt_test_flag=0; //GPRS附著檢測標(biāo)識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(cgatt_send_frequ==0)
{
creg_succ_flag=0;
cgatt_test_end_falg=1; //GPRS附著檢測結(jié)束標(biāo)識值1
}
}
}
/************設(shè)置APN************/
if(cgatt_test_flag==1&&cstt_set_end_falg==0) //判斷GPRS附著檢測標(biāo)識值
{
if(cstt_send_flag==0&&cstt_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
send_string(cstt); //發(fā)送設(shè)置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) //判斷指令是否發(fā)送及計(jì)時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回字符串是否包含“OK”
{
cstt_set_flag=1; //APN設(shè)置標(biāo)識值1
cstt_send_frequ=0;
cstt_send_flag=0;
Clr_Rec_buf();
}
else
{
cstt_send_flag=0;
if(cstt_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
cstt_set_flag=0; //APN設(shè)置標(biāo)識值0
net_connect_flag=0;
gprs_p=0;
}
Clr_Rec_buf();
}
if(cstt_send_frequ==0)
{
cgatt_test_flag=0; //GPRS附著檢測標(biāo)識值0
cstt_set_end_falg=1;
}
}
}
/*****建立無線鏈路(GPRS或者CSD)*****/
if(cstt_set_flag==1&&ciicr_set_end_falg==0) //判斷APN設(shè)置狀態(tài)標(biāo)識
{
if(ciicr_send_flag==0&&ciicr_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
send_string(ciicr); //發(fā)送建立無線鏈路指令
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) //判斷指令是否發(fā)送及計(jì)時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL)
{
ciicr_set_flag=1; //無線鏈路設(shè)置標(biāo)識值1
ciicr_send_frequ=0;
cstt_set_flag=0; //APN設(shè)置狀態(tài)標(biāo)識值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) //判斷發(fā)送是否結(jié)束
{
ciicr_send_flag=0;
//Clr_Rec_buf();
n=0;
}
if(ciicr_send_frequ==0)
{
ciicr_set_flag=0; //無線鏈路設(shè)置標(biāo)識值0
cstt_set_flag=0; //APN設(shè)置狀態(tài)標(biāo)識值0
ciicr_set_end_falg=1;
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
for(i=0;i<24;i++)
str2[i]=Rec_buf[i];
Clr_Rec_buf();
}
}
} |
|