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

📄 attention.c

📁 使用avr--cc2420模块程序,需要原理图的联系 QQ:120304948
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <mega128.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#include "typedef.h"

#include "app.h"
#include "attention.h"
#include "g20modem.h"
#include "g20serialdrv.h"

#include "rtc.h"
#include "serialdrv.h"
#include "timer.h"
#include "UDP.h"
#include "protocol.h"

#include "data.h"

#define RETRY_TIMES 5

unsigned char bnumber[30];


unsigned char chEnd[4] = 
{
	0x1A, 0x1D, 0x1A, 0x1A
};

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

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

unsigned char attention_ate(unsigned char bDisplay)
{
    unsigned char bRet = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    g20_sp_init_buf();   
    while(nLoop -- > 0)
    {
        wdr();
        if(bDisplay)
            g20_sp_send("ATE1\r");
        else
            g20_sp_send("ATE0\r");
        bRet = g20_sp_waitfor("OK",NULL, "ERROR", NULL, NULL, 2000);
        if(bRet)
            return TRUE;
    }
    return FALSE;    
}

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

unsigned char attention_csq()
{    
	unsigned char bRet = FALSE;
	volatile UINT nLoop = RETRY_TIMES;
	volatile UINT nGetChar = 0;
	volatile BYTE chTemp = 0x00;
	volatile UINT nCSQ;

    nCSQ = 0;
    g20_sp_init_buf();
	while(nLoop -- > 0)
	{
        wdr();
		g20_sp_send("AT+CSQ?\r");
		bRet = g20_sp_waitfor("+CSQ:",NULL,"ERROR", NULL, NULL, 2000);
		if(bRet == TRUE)
		{
		    
			for(nGetChar = 0; nGetChar < 4; nGetChar ++)
			{
			    chTemp = 0x00;			 
				chTemp = g20_sp_getchar();
				if((chTemp >= (BYTE)0x30)&&(chTemp <= (BYTE)0x39))
				{
					//nCSQ = nCSQ + (UINT)(chTemp - 0x30)*(10^(3-nGetChar));
                    // (10^(3-nGetChar)    ~~~~~~~~~~~~~~~ ERROR: 10^0 = 10
                    switch(nGetChar)
                    {
                    case 1:
                        nCSQ = nCSQ +(UINT)(chTemp - 0x30)*100;
                        break;
                    case 2:
                        nCSQ = nCSQ + (UINT)(chTemp - 0x30)*10;
                        break;
                    case 3:
                        nCSQ = nCSQ + (UINT)(chTemp - 0x30);
                    }                  
				}
			}
//            memset(sztemp, 0x00, 10);
//            sprintf((unsigned char*)sztemp, "MY SEQ: %d\r\n", nCSQ);
//            sp_send(sztemp);
			return TRUE;
		}
	}	
    return FALSE;
}

/*unsigned char attention_cregset()
{
	unsigned char bRet = FALSE;
	volatile UINT nLoop = RETRY_TIMES;
    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 = FALSE;
    volatile UINT nLoop = RETRY_TIMES;

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

/*
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 = FALSE;
    volatile UINT nLoop = RETRY_TIMES;
    
    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();

⌨️ 快捷键说明

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