⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gprs_modem.c

📁 C语言源代码及相关资料
💻 C
📖 第 1 页 / 共 3 页
字号:
							case 13: //RCV_STARP_PLUS_AIPA:
								break;
							case 14: //RCV_STARP_PLUS_AIPO:
								break;
							case 15: //RCV_STARP_PLUS_AIPW:
								break;
							case 16: //RCV_STARP_PLUS_AIPR:
								break;
							case 17: //RCV_STARP_PLUS_AIPC:
								break;
							case 18: //RCV_STARP_PLUS_AIPRTCP:
								if((p=strstr((char *)pGSMDataBuf,"+AIPRTCP: 1"))!=NULL)	//"+AIPRTCP"
								{
									if((p1=strstr((char *)p,str1))!=NULL)
									{
										*puiNum=p1-(p+2);
										memmove(pGSMDataBuf,p+2,*puiNum);
										nRtnStatus = 1;
									}
								}
								break;
							case 19: //RCV_STARP_PLUS_AIPRUDP:
								if((p=strstr((char *)pGSMDataBuf,"+AIPRUDP"))!=NULL)	//"+AIPRTCP"
								{
									if((p=strstr((char *)p,str))!=NULL)
									{
										if((p1=strstr((char *)p,str1))!=NULL)
										{
											*puiNum=p1-(p+2);
											// Chad
											gw_szUartBuffer[0]='\0';
											iLoopidx = 0;
											p1 = p-1;
											while ( *p1 != ',' ) {
												iLoopidx++;
												p1--;
											}
											p1 = p-iLoopidx;
											iMaxidx = 0;
											while ( iLoopidx>0 ) {
												gw_szUartBuffer[iMaxidx]=*p1;
												p1++;
												iLoopidx--;
												iMaxidx++;
											}
											gw_szUartBuffer[iMaxidx]='\0';
											iLoopidx = atoi(gw_szUartBuffer);
											if ( *puiNum!=iLoopidx ) {
												sprintf(gw_szOutBuffer,"\r\n++ UDP: Rsp=(%d:%d) ++\r\n", *puiNum, iLoopidx);
												//uartWrite(UART3,(uint8	*)gw_szOutBuffer,strlen(gw_szOutBuffer),NULL);
												__DBG2_printf1(gw_szOutBuffer);
											}
											
											// Chad
											iMaxidx=iLoopidx*2;
											if ( iMaxidx == *puiNum ) {
												sprintf(gw_szOutBuffer,"\r\n++ UDP: move data=%d ++\r\n", *puiNum);
												//uartWrite(UART3,(uint8	*)gw_szOutBuffer,strlen(gw_szOutBuffer),NULL);
												__DBG2_printf1(gw_szOutBuffer);
												memmove(GPRS_data,p+2,*puiNum);
											}
											nRtnStatus = 1;
										} // end of if((p1=strstr((char *)p,str1))!=NULL)
									} // end of if((p=strstr((char *)p,str))!=NULL)
								}
								break;
							case 20: //RCV_STARP_PLUS_AIPRIPI:
								break;
							default:
								break;
						} // end of switch(gw_nRCVState_RFPLUS)
#endif

						if ( nHasParserBytes != nHasRevBytes ) {
							// We have to consider this condition, 
							// and other message wait to be processing, and
							// then if continue to parse some other sentence?
						} // end of if ( nHasParserBytes != nHasRevBytes ) 
					} else {
						// Not get effective data, it means that
						// we do not get completely incoming message, and parser not over,
						// or not get valid incoming message
	
						// Contunue to get more data to check incoming message..
					} // end of else if ( struSendRCVUartParas.cParsRspTypeStatus == 0 )
				} else if ( cGetType==2 ) {
					// cGetType==2: Flush data and not parser GPRS data
					nHasParserBytes += nHasRevBytes;
				} // end of else if ( cGetType==2 )
				shDlyTime = 0; // Reset timer count
			// end of if (*puiNum>0)
			} else {
				// else if (*puiNum<=0)
				OSTimeDly(10);	 // 10 ticks == 50 milliseconds == 0.05 seconds
				shDlyTime += 10; // OS_TICKS_PER_SEC: 200 ticks == 1 second				
			} // end of else if ( (*puiNum > 0) || (nHasParserBytes < nHasRevBytes) )
		//} while ( fHasGetResp==0 || (shDlyTime < shTimeout) );
		//} while ( ((fHasGetResp == 0) || (nHasParserBytes < nHasRevBytes)) && (shDlyTime<shTimeout) );
		//} while (  (shDlyTime<shTimeout) );
			if ( cGetType==1 ) {
				if ( (fHasGetResp>0 ) && (nHasParserBytes == nHasRevBytes) )
					break;
			} // end of if ( cGetType==0 ) 
		} while ( ((fHasGetResp == 0) || (nHasParserBytes < nHasRevBytes)) && (shDlyTime<shTimeout) );
		// end of while
		
		// Save return value
		*puiNum = nHasRevBytes;
			
// Chad add: display debug information
#if 1
		if ( nDispBgEdMsg==1 ) {
			nDispBgEdMsg = 2;		
			//sprintf(gw_szUartBuffer,"\r\n++ GPRS: end: Rsp=(%d:%d), Rcv:Pars=(%d:%d) ++\r\n", fHasGetResp, nNeedProcessRsp, nHasParserBytes, nHasRevBytes);
			//uartWrite(UART3,(uint8	*)gw_szUartBuffer,strlen(gw_szUartBuffer),NULL);			
			sprintf(gw_szOutBuffer,"\r\n++ GPRS: end: Rsp=(%d:%d), Rcv:Pars=(%d:%d) ++\r\n", fHasGetResp, nNeedProcessRsp, nHasParserBytes, nHasRevBytes);
			strcat(gw_szUartBuffer, gw_szOutBuffer);
			//uartWrite(UART3,(unsigned char *)gw_szUartBuffer,strlen( gw_szUartBuffer ),NULL); 	// output debug messasge to UART3			
			__DBG2_printf1(gw_szUartBuffer);
		}
#endif // #if 1 or 0

#if 0
		if ( nHasRevBytes>0 ) {
			sprintf(gw_szUartBuffer,"\r\n++ GPRS: begin get message ++\r\n");
			nDisplayIndex = strlen( gw_szUartBuffer );
			gw_szUartBuffer[nDisplayIndex++]='\r';
			gw_szUartBuffer[nDisplayIndex++]='\n';
			for ( iLoopidx=2; iLoopidx<12; iLoopidx++) {
				gw_szUartBuffer[nDisplayIndex++]='=';
			} // end of for ( iLoopidx=0; iLoopidx<10; iLoopidx++
			gw_szUartBuffer[nDisplayIndex++]='\r'; iLoopidx++;
			gw_szUartBuffer[nDisplayIndex++]='\n'; iLoopidx++;
			memcpy(gw_szUartBuffer+nDisplayIndex, GPRS_data, nHasRevBytes);
			nDisplayIndex += nHasRevBytes;
			gw_szUartBuffer[nDisplayIndex++]='\r';
			gw_szUartBuffer[nDisplayIndex++]='\n';
			for ( iLoopidx=2; iLoopidx<12; iLoopidx++) {
				gw_szUartBuffer[nDisplayIndex++]='=';
			} // end of for ( iLoopidx=0; iLoopidx<10; iLoopidx++
			gw_szUartBuffer[nDisplayIndex++]='\r';
			gw_szUartBuffer[nDisplayIndex++]='\n';
			gw_szUartBuffer[nDisplayIndex]='\0';
			sprintf(gw_szOutBuffer,"\r\n++ GPRS: end: Rsp=(%d:%d), Rcv:Pars=(%d:%d), rtn=%d ++\r\n", fHasGetResp, nNeedProcessRsp, nHasParserBytes, nHasRevBytes, *puiNum);
			iLoopidx = strlen(gw_szOutBuffer);
			memcpy(gw_szUartBuffer+nDisplayIndex, gw_szOutBuffer, iLoopidx);
			nDisplayIndex+=iLoopidx;
			gw_szUartBuffer[nDisplayIndex]='\0';
			//uartWrite(UART3,(unsigned char *)gw_szUartBuffer,nDisplayIndex,NULL); 	// output debug messasge to UART3
			__DBG2_printf1(gw_szUartBuffer);
		}
#endif

#if 1
	if ( nHasRevBytes>0 )
	{   		
		if((p=strstr((char *)GPRS_data,"+CLIP"))!=NULL)
	 	{
	 		MotormanLoadingOrExit(GPRS_data,puiNum);	//驾驶员登陆或退出
	 	}
	 	//else	
	 	if((p=strstr((char *)GPRS_data,"NO CARRIER"))!=NULL)
	 	{
	 		RING_COU=0;
	 	}
	 	//else
		if(strstr((char *)GPRS_data,"+CMTI")!=NULL)
		{
			char 	strAT[30];
			char 	*	str="\r\nAT+CMGR=";
			
			memset(strAT,0,sizeof(strAT));
			
			if((p=strstr((char *)GPRS_data,"\","))!=NULL)
			{
				//取短信标号
				
				char *	p2=NULL;
				p+=strlen("\",");
				//if((p2=strstr(p,"\r\n"))!=NULL)
				if((p2=strstr(p,"\r"))!=NULL)
				{
					memset(MsgNum,0,sizeof(MsgNum));
					memcpy(MsgNum,p,p2-p);
					
					strcat(strAT,str);
					memcpy(strAT+strlen(str),p,p2-p);
					strcat(strAT,"\r\n");
					uartWrite(UART2,(uint8	*)("\r\nAT+CMGF=1\r\n\0"),strlen("\r\nAT+CMGF=1\r\n\0"),NULL);
					OSTimeDlyHMSM(0,0,0,300);
					uartWrite(UART2,(uint8	*)strAT,strlen(strAT),NULL); 
				}
				
				
			 }
		   	//return	FALSE;
		}
		//else	
		if((p=strstr((char *)GPRS_data,"+CMGR"))!=NULL)
		{
			MsgWatchOrSet(GPRS_data,puiNum);	//手机调度及自定义手机查询设置
		}
		//else	
		if((p=strstr((char *)GPRS_data,"+AIPRUDP"))!=NULL)	//"+AIPRTCP"
		{
		   	if((p=strstr((char *)p,str))!=NULL)
		   	{
		      	if((p1=strstr((char *)p,str1))!=NULL)
		      	{
		      		//uartWrite(UART3,(uint8	*)p, nHasRevBytes-20, NULL);
		      		*puiNum=p1-(p+2);
		      		// Chad
		      		gw_szUartBuffer[0]='\0';
		      		iLoopidx = 0;
		      		p1 = p-1;
		      		while ( *p1 != ',' ) {
		      			iLoopidx++;
		      			p1--;
		      		}
		      		p1 = p-iLoopidx;
		      		iMaxidx = 0;
		      		while ( iLoopidx>0 ) {
		      			gw_szUartBuffer[iMaxidx]=*p1;
		      			p1++;
		      			iLoopidx--;
		      			iMaxidx++;
		      		}
		      		gw_szUartBuffer[iMaxidx]='\0';
							iLoopidx = atoi(gw_szUartBuffer);
							if ( *puiNum!=iLoopidx ) {
								sprintf(gw_szUartBuffer,"\r\n++ UDP: Rsp=(%d:%d) ++\r\n", *puiNum, iLoopidx);
								//uartWrite(UART3,(uint8	*)gw_szUartBuffer,strlen(gw_szUartBuffer),NULL);
								__DBG2_printf1(gw_szUartBuffer);
							}
						
						// Chad
						iMaxidx=iLoopidx*2;
						if ( iMaxidx == *puiNum ) {
							sprintf(gw_szUartBuffer,"\r\n++ UDP: move data=%d ++\r\n", *puiNum);
							//uartWrite(UART3,(uint8	*)gw_szUartBuffer,strlen(gw_szUartBuffer),NULL);
							__DBG2_printf1(gw_szUartBuffer);
		     			memmove(GPRS_data,p+2,*puiNum);
		     		}
		     		
		     		return	TRUE;
		    	}
		   	}
		 }
		 //else	
		 if((p=strstr((char *)GPRS_data,"+AIPRTCP: 1"))!=NULL)	//"+AIPRTCP"
		 {
		   	//uartWrite(UART3,GPRS_data,*puiNum,NULL);	//测试
		   	if((p=strstr((char *)p,str))!=NULL)
		   	{
		      	if((p1=strstr((char *)p,str1))!=NULL)
		      	{
		      		*puiNum=p1-(p+2);
		     		memmove(GPRS_data,p+2,*puiNum);
		     		
		     		return	TRUE;
		    	}
		   	}
		 }
		 //else	
		 /*
		 if((p=strstr((char *)GPRS_data,"+AIPC"))!=NULL)	//AIPCI
		 {
		 	//表示服务器主动断开连接。
		 	Connect_OK=FALSE;
			ReConnect_OK=0;
			FTP_UPGRADE_FLAG=0; //返回UDP连接程序
			
		 	return	FALSE;
		 }*/
		  //else	
		if((p=strstr((char *)GPRS_data,"+CREG: "))!=NULL)
		{
			
			p+=strlen("+CREG: ");
			if((p=strstr(p,","))!=NULL)
			{	
				p+=strlen(",");
				
				if(*p=='1'||*p=='5')
					gsm_BlindBorough=0;		
				else
					gsm_BlindBorough=1;//GSM通讯盲区
			}
			//return	FALSE;
		}
		  //else	
		if((p=strstr((char *)GPRS_data,"+CGREG: "))!=NULL)
		{
			
			p+=strlen("+CGREG: ");
			if((p=strstr(p,","))!=NULL)
			{	
				p+=strlen(",");
				
				if(*p=='1'||*p=='5')
					gprs_BlindBorough=0;		
				else
					gprs_BlindBorough=1;//gprs通讯盲区
			}
			//return	FALSE;
		}
		
		//else	
		if((p=strstr((char *)GPRS_data,"+CSQ: "))!=NULL)
		{
			
			char temp[2];
			memset(temp,0,sizeof(temp));
			p+=strlen("+CSQ: ");
			if((*(p+1)>=0x30)&&(*(p+1)<=0x39))
			{
				temp[0]=*p;
				temp[1]=*(p+1);
				
			}
			else
				temp[0]=*p;
			CSQVal=(uint8)atoi(temp);
			
			//return	FALSE;
		}
	 	/*
	 	else	if((p=strstr((char *)GPRS_data,"RING"))!=NULL)
	 	{
	 		char	paramValue[20];
	 		memset(paramValue,0,sizeof(paramValue));
	 		GetParamValue(0x0101,(uint8 *)paramValue);
	 		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -