Exemplo n.º 1
0
void NRF24L01::set_rx_mode()
{
    ce->reset();
    
    set_addr_width(5);
    set_local_addr(0,rx_addr_0);//写RX节点地址
    
   	set_chanal_ack(0,ENABLE);    //使能通道0的自动应答    
  	set_chanal(0,ENABLE);//使能通道0的接收地址  
    
  	set_rf_frq(40);	     //设置RF通信频率	
    
  	set_pload_width(0,4);//选择通道0的有效数据宽度 	    

  	set_gain(RF_N_0DB);//设置TX发射参数,0db增益,低噪声增益开启   
    set_baudrate(_2MBPS);//2Mbps
    
    set_power(1);//PWR_UP
    set_tx_rx_mode(RX_MODE);//接收模式 
    set_crc(1,1);//EN_CRC,16BIT_CRC
    
    ce->set();
}
Exemplo n.º 2
0
static int execute_app_request(char *buf, int len)
{
	char *command=NULL; //Pointer pointing command
	char *value=NULL;   //Pointer pointing value
	RTE_DBG("%s(%d),buf:%s.\n",__FUNCTION__,__LINE__,buf);
	//add \0 at the end of buffer
	*(buf+len) = '\0'; len++;
	//Contents format: "<command>,<value>\n"
	command = buf;		
	{
		int i=0;
		int return_char_ctr = 0;

		for(i=0;i<len;i++)
		{
			if(*(buf+i)==',' && (i+1)<len)
			{
				value=(buf+i+1);
			}

			if(*(buf+i)==',')
			{
				*(buf+i)='\0';
			}

			if((*(buf+i)=='\n') || (*(buf+i)=='\r')) 
			{
				*(buf+i)='\0';
				return_char_ctr++;
			}
		}
	}

	RTE_DBG("%s(%d),command:%s,value:%s.\n",__FUNCTION__,__LINE__,command,value);
    
/*
	if(!strcmp(command, "enableL2CT"))
	{
		 u32 enable = (u32)strtoul(value, NULL, 10);
		 if(enable == 1)
			set_flags_l2ct_enable();
		 else
			clear_flags_l2ct_enable();
	}
	
	else if(!strcmp(command, "enableDPI"))
	{
		 u32 enable = (u32)simple_strtoul(value, NULL, 10);
		 if(enable == 1)
			set_flags_dpi_enable();
		 else
			clear_flags_dpi_enable();
	}
	else if(!strcmp(command, "enableTC"))
	{
		 u32 enableTC = (u32)simple_strtoul(value, NULL, 10);
		 if(enableTC == 1)
			set_flags_tc_enable();
		 else
			clear_flags_tc_enable();
	}	
	else if(!strcmp(command, "unreg_surfront"))
	{
		//will unreg surfront module
		local_bh_disable();
		do_unreg_surfront_work();
		local_bh_enable();
	}
	else if(!strcmp(command, "debuglevel"))
	{
		sft_debug_flags = simple_strtoul(value, NULL, 10);
	}
	else 
*/    
    if(!strcmp(command, "set_localip"))
	{
		//echo "set_localip,192.168.1.70" > /proc/surfront/io
		if((*value) == 'X')
		{
			set_local_addr(0);
		}
		else
		{
			uint8_t network_id_octets[4];
			if((parse_string_to_ip_address(network_id_octets, value)==TRUE))
			{
				int last = network_id_octets[3] & 0xFF;
				RTE_DBG("%s(%d),last is %d.\n",__FUNCTION__,__LINE__,last);
				RTE_DBG("%s(%d),%u.%u.%u.%u.\n",__FUNCTION__,__LINE__,RTE_NIPQUAD(network_id_octets));
				set_local_addr(network_id_octets[0] | (network_id_octets[1] << 8) | (network_id_octets[2] << 16) | (network_id_octets[3] << 24));
				RTE_DBG("%s(%d),local ip %u.%u.%u.%u.\n",__FUNCTION__,__LINE__,RTE_NIPQUAD(get_local_addr));
			}
		}
	}
	else
	{
		RTE_DBG("%s(%d),noknown command:%s.\n",__FUNCTION__,__LINE__,command);
	}
	return 0;
}