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

📄 attention.i

📁 使用avr--cc2420模块程序,需要原理图的联系 QQ:120304948
💻 I
📖 第 1 页 / 共 2 页
字号:
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+CREG=1\r");
        bRet = g20_sp_waitfor("OK",NULL,"ERROR",NULL,NULL,2000);
        if(bRet)
            return TRUE;
    }
    return FALSE;
}

unsigned char attention_cgregset()
{
	unsigned char bRet = FALSE;
	volatile UINT nLoop = RETRY_TIMES;
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+CGREG=1\r");
        bRet = g20_sp_waitfor("OK",NULL,"ERROR",NULL,NULL,2000);
        if(bRet)
            return TRUE;
    }
    
    return FALSE;
}

unsigned char attention_cregchk()
{
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    g20_sp_init_buf(); 
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+CREG?\r");
        bRet = g20_sp_waitfor("+CREG: 001,001", "+CREG: 001,005","ERROR",NULL,NULL,200);
        if(bRet)
            return TRUE;
    }
    
    return FALSE;
}

unsigned char attention_cgregchk()
{
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+CGREG?\r");
        bRet = g20_sp_waitfor("+CGREG: 001,001", "+CGREG: 001,005","ERROR",NULL,NULL,200);
        if(bRet)
            return TRUE;
    }
    
    return FALSE;
}

unsigned char attention_gprscvr()
{
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+CGPRS?\r");
        bRet = g20_sp_waitfor("+CGPRS: 1", NULL,"ERROR",NULL,NULL,2000);
        if(bRet)
            return TRUE;
    }
    
    return FALSE;    
}*/

unsigned char attention_mipcall_on()
{
    BYTE szBuffer[50];
    unsigned char bRet = 0;
    volatile UINT nLoop = 5;

    memset(szBuffer, 0x00, 50);
	sprintf((unsigned char*)szBuffer, "AT+MIPCALL=1,\"dyshl.sd\"\r");
    
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        #asm("wdr");
        g20_sp_sendb(szBuffer);        
        timer_delay(3000);
//        bRet = g20_sp_waitfor("OK",NULL,"ERROR",NULL,NULL,3000);
        bRet = g20_sp_waitfor("+MIPCALL:",0,"ERROR",0,0,3000);
        if(bRet)
        {
            break;
        }
    }   
   
//    if(bRet)
//    {
        timer_delay(1000);
        nLoop = 5 - 3;
        while(nLoop -- > 0)
        {
            #asm("wdr");
            g20_sp_send("AT+MIPCALL?\r");
            
            timer_delay(500);
            bRet = g20_sp_waitfor("+MIPCALL: 1,", 0, "ERROR", 0, 0, 1000);
            if(bRet)
                return 1;  
        }
//    }
    
    return 0;
}

/*
unsigned char attention_mipcall(unsigned char bSwitch)
{
    BYTE szBuffer[50];
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;

    memset(szBuffer, 0x00, 50);
    if(bSwitch)
    {
	      sprintf((unsigned char*)szBuffer, "AT+MIPCALL=1,\"dyshl.sd\"\r");
//        sprintf((unsigned char*)szBuffer, "AT+MIPCALL=1,\"%s\",\"%s\",\"%s\"\r", "dyshl.sd","","");
    }
    else
    {
        sprintf((unsigned char*)szBuffer, "AT+MIPCALL=0\r");
    }
    
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_sendb(szBuffer);        
        timer_delay(1000);
        bRet = g20_sp_waitfor("OK",NULL,"ERROR",NULL,NULL,2000);
        if(bRet)
        {
            break;
        }
    }   
   
    if(bRet || bSwitch == FALSE)
    {
        timer_delay(6000);
        nLoop = RETRY_TIMES - 2;
        while(nLoop -- > 0)
        {
            wdr();
            g20_sp_send("AT+MIPCALL?\r");
            
            timer_delay(1000);
            if(bSwitch)
            {
                bRet = g20_sp_waitfor("+MIPCALL: 1,", NULL, "ERROR", NULL, NULL, 1000);
            }
            else
            {
                bRet = g20_sp_waitfor("+MIPCALL: 0", NULL, "ERROR", NULL, NULL, 1000);
            }        
            if(bRet)
                return TRUE;  
        }
    }
    
    return FALSE;
}
*/

unsigned char attention_mipopen()
{
    BYTE szBuffer[64];
    unsigned char bRet = 0;
    volatile UINT nLoop = 5;
    
    memset(szBuffer, 0x00, 64);
	sprintf((unsigned char*)szBuffer, "AT+MIPOPEN=1,3700,\"10.14.81.194\",3700,1\r");    //10.14.87.161
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        #asm("wdr");
        g20_sp_sendb(szBuffer);
        timer_delay(1000);    
        bRet = g20_sp_waitfor("+MIPOPEN: 1,1", 0,"ERROR",0,0,2000);
        if(bRet)
            return 1;
    }
    g20_sp_init_buf();
    nLoop = 5;
    while(nLoop -- > 0)
    {
        #asm("wdr");
        g20_sp_send("AT+MIPOPEN?\r");
        
        bRet = g20_sp_waitfor("+MIPOPEN: 2,3,4", 0, 
                                "ERROR", "+MIPOPEN: 1,2,3,4", 0, 2000);
        if(bRet)
            return 1;
        timer_delay(1000);    
    }
    return 0;
}

unsigned char attention_mipsend(BYTE * pBuf)
{
	//BYTE szBuffer[64];
    unsigned char bRet = 0;
//    volatile UINT nLoop = RETRY_TIMES;
    
    //memset((unsigned char*)szBuffer, 0x00, 64);
    //sprintf((unsigned char*)szBuffer, "AT+MIPSEND=1,\"%s\"\r", pBuf);
   
    g20_sp_init_buf();
    
//    while(nLoop -- > 0)
//    {
        #asm("wdr");
        g20_sp_send("AT+MIPSEND=1,\"");
        g20_sp_sendb(pBuf);
        g20_sp_send("\"\r");       
                
        bRet = g20_sp_waitfor("+MIPSEND: 1", 0,"ERROR",0,0,2000);
        if(bRet)
            return 1;
//    }
//    timer_delay(20);    
    return 0;
}

unsigned char attention_mippush(void)
{
    BYTE szBuffer[64];
    unsigned char bRet = 0;
    volatile UINT nLoop = 5; 
    
    memset(szBuffer, 0x00, 64);
    g20_sp_init_buf();
	sprintf((unsigned char*)szBuffer, "AT+MIPPUSH=1,\"10.14.81.194\",3700\r");   //10.14.87.161
    while(nLoop -- > 0)
    {
        #asm("wdr");
        g20_sp_sendb(szBuffer);
        bRet = g20_sp_waitfor("+MIPPUSH: 0",0, "ERROR", 0, 0,2000);
        if(bRet)
            return 1;            
    }
    
    return 0;
}

/*unsigned char attention_mippush(IP_ADDR *pAdd, UINT nPort)
{
    BYTE szBuffer[64];
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    
    g20_sp_init_buf();
    memset(szBuffer, 0x00, 64);
    sprintf((unsigned char*)szBuffer, "\"%d.%d.%d.%d\",%d", pAdd->classA,pAdd->classB,pAdd->classC,pAdd->classD, nPort);
    while(nLoop -- > 0)
    {
        wdr();
        g20_sp_send("AT+MIPPUSH=1,");
        g20_sp_sendb(szBuffer);
        g20_sp_send("\r");
        bRet = g20_sp_waitfor("+MIPPUSH: 0",NULL, "ERROR", NULL, NULL,2000);
        if(bRet)
            return TRUE;            
    }
    
    return FALSE;
}*/

unsigned char attention_cmgf()
{
    unsigned char bRet = 0;
    volatile UINT nLoop = 5;
    
    g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        #asm("wdr");
        g20_sp_send("AT+CMGF=0\r");
        bRet = g20_sp_waitfor("OK", 0,"ERROR", 0, 0, 2000);
        if(bRet)
            return 1;
    }
    return 0;
}

void exch_mobilephone(unsigned char nLoop)
{
	memset(bnumber, 0x00, 30);

    switch (nLoop)
	{
	    case 1:
	        bnumber[0]=MobilePhone1[1];
	        bnumber[1]=MobilePhone1[0];
	        bnumber[2]=MobilePhone1[3];
	        bnumber[3]=MobilePhone1[2];
	        bnumber[4]=MobilePhone1[5];
	        bnumber[5]=MobilePhone1[4];
	        bnumber[6]=MobilePhone1[7];
	        bnumber[7]=MobilePhone1[6];
	        bnumber[8]=MobilePhone1[9];
	        bnumber[9]=MobilePhone1[8];
	        bnumber[10]='F';
	        bnumber[11]=MobilePhone1[10];
		    break;
		case 2:
	        bnumber[0]=MobilePhone2[1];
	        bnumber[1]=MobilePhone2[0];
	        bnumber[2]=MobilePhone2[3];
	        bnumber[3]=MobilePhone2[2];
	        bnumber[4]=MobilePhone2[5];
	        bnumber[5]=MobilePhone2[4];
	        bnumber[6]=MobilePhone2[7];
	        bnumber[7]=MobilePhone2[6];
	        bnumber[8]=MobilePhone2[9];
	        bnumber[9]=MobilePhone2[8];
	        bnumber[10]='F';
	        bnumber[11]=MobilePhone2[10];
		    break;
		case 3:
	        bnumber[0]=MobilePhone3[1];
	        bnumber[1]=MobilePhone3[0];
	        bnumber[2]=MobilePhone3[3];
	        bnumber[3]=MobilePhone3[2];
	        bnumber[4]=MobilePhone3[5];
	        bnumber[5]=MobilePhone3[4];
	        bnumber[6]=MobilePhone3[7];
	        bnumber[7]=MobilePhone3[6];
	        bnumber[8]=MobilePhone3[9];
	        bnumber[9]=MobilePhone3[8];
	        bnumber[10]='F';
	        bnumber[11]=MobilePhone3[10];
			break;
	}
}

void unlicode_hex(BYTE * pBuf, unsigned char nLoop)
{
    unsigned char i;

	memset(bnumber, 0x00, 30);
	
	for (i=0;i<nLoop;i++)
	{
		bnumber[i*4+0] = 0x30;	
		bnumber[i*4+1] = 0x30;	
		bnumber[i*4+2] = 0x33;	
		bnumber[i*4+3] = *(pBuf+i) ;
		if (*(pBuf+i)=='.')
		{
			bnumber[i*4+2] = 0x32;	
			bnumber[i*4+3] = 0x45;
		}
		if (*(pBuf+i)==' ')
		{
			bnumber[i*4+2] = 0x32;	
			bnumber[i*4+3] = 0x30;
		}
	}	
}

unsigned char attention_cmgs(unsigned char value,unsigned char alarmNo)
{
    unsigned char bRet = 0;
    volatile UINT nLoop = 5;
//    unsigned char strdata[25];

//    attention_cmgf();
//	delay_ms(1000);
	g20_sp_init_buf();
    while(nLoop -- > 0)
    {
        #asm("wdr");
		g20_sp_send("AT+CMGS=143\r");    //5+6+3+1+128=133

		timer_delay(10);
		
//		bRet = g20_sp_waitfor(">", NULL,"ERROR", NULL, NULL, 2000);
//		g20_sp_send("0891683108506405F0  11000D9168  3116218102F4  000800  08 8C228C2200330034");

		g20_sp_send("0891683108506405F011000D9168");  //5

		exch_mobilephone(alarmNo);  //6
		g20_sp_sendb(bnumber);

		g20_sp_send("000800");  //3

		g20_sp_send("80");  //1        //26+18+10+5*2+6+8+5*2+6+4+3*2+8+4+4*2+4=128 (0x80)

        cmgs_no(1     );   //26
        
		switch (value)
		{
			case 0:
				g20_sp_send("53415206949F51FA5DE18B66621200210021");  //18  /*十分钟出巡警戒!!*/
				break;
			case 1:
				g20_sp_send("4E005C0F65F651FA5DE18B66621200210021");  //18  /*一小时出巡警戒!!*/
				break;
			case 2:
				g20_sp_send("65E5964D96E851FA5DE18B66621200210021");  //18  /*日降雨出巡警戒!!*/
				break;
			case 3:
				g20_sp_send("8FDE7EED964D96E851FA5DE18B6662120021");  //18  /*连续降雨出巡警戒!*/
				break;
			case 4:
				g20_sp_send("53415206949F537160258B66621200210021");  //18  /*十分钟危急警戒!!*/
				break;
			case 5:
				g20_sp_send("4E005C0F65F6537160258B66621200210021");  //18  /*一小时危急警戒!!*/
				break;
			case 6:
				g20_sp_send("65E5964D96E8537160258B66621200210021");  //18  /*日降雨危急警戒!!*/
				break;
			case 7:
				g20_sp_send("8FDE7EED964D96E8537160258B6662120021");  //18  /*连续降雨危急警戒!*/
				break;
		}


		g20_sp_sendb(chEnd);
		timer_delay(50);
		bRet = g20_sp_waitfor("+CMGS:", 0,"ERROR", 0, 0, 2000);
		if(bRet)
		{
			return 1;
		}
    }    
	return 0;
}

unsigned char attention_init()
{

	
    if(attention_at() == 1)
    {
		if(attention_atz() == 1)
		{
			if(attention_ate(1) == 1)
			{
				if(attention_cmgf() == 1)
				{
					return 1;
				}
			}
		}
	}
    return 0;
}

/*
unsigned char attention_dialproc()
{
#if defined (DEBUG_MODE)	
	sp_send("\r\nGPRS挂断\r\n");
#endif 
    while(!attention_mipcall(FALSE))
    {
        wdr();
        timer_delay(1000);
    }
#if defined (DEBUG_MODE)	
	sp_send("\r\nGPRS连接\r\n");
#endif 
    while(!attention_mipcall(TRUE))
    {
        wdr();
        timer_delay(1000);
    }
    return TRUE;
}
*/

unsigned char attention_dialproc()
{
	    call_time = 0;
    while(!attention_mipcall_on())
    {
        #asm("wdr");
        timer_delay(500);
        if (call_time >= 1200)     //3000
        {
            return 0;
        }
    }
    return 1;
}

unsigned char attention_udpproc()
{
	    call_time = 0;
    while(!attention_mipopen())
    {
        #asm("wdr");
        timer_delay(500);
        if (call_time >= 1200)     //3000
        {
            return 0;
        }
    }
    return 1;
}

⌨️ 快捷键说明

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