Beispiel #1
0
U8 chb_write(U16 addr, oFrame *frame, U8 len)
{
    U8 status, frm_len, hdr_len;
	
    while (len > 0)
    {
        // calculate which frame len to use. if greater than max payload, split
        // up operation.
        frm_len = (len > CHB_MAX_PAYLOAD) ? CHB_MAX_PAYLOAD : len;

        // gen frame header
        hdr_len = chb_gen_hdr(hdr, addr, frm_len);	
		
		// Build the complete frame
		oFrame_Define(&chb_oFrame);
		oFrame_Set(hdr, 0, hdr_len, 0, frame);
		
        // send data to chip
        //status = chb_tx(hdr, data, frm_len);
		status = chb_tx(&chb_oFrame);

        if (status != CHB_SUCCESS)
        {
            switch (status)
            {
            case RADIO_SUCCESS:
                // fall through
            case CHB_SUCCESS_DATA_PENDING:
                pcb.txd_success++;
                break;

            case CHB_NO_ACK:
                pcb.txd_noack++;
                break;

            case CHB_CHANNEL_ACCESS_FAILURE:
                pcb.txd_channel_fail++;
                break;

            default:
                break;
            }
			
			if (status == RADIO_SUCCESS) 	// Added by Dario to manage the return properly
				return 1;
			else
				return 0;
        }

        // adjust len and restart
        len = len - frm_len;
    }
	
    return CHB_SUCCESS;
}
Beispiel #2
0
void srvcln_load(uint8_t *data, uint8_t len) 
{
	// If the frame is not empty, there are waiting data 	
	oFrame_Define(&vNetM1_oFrame);
	if(oFrame_isBusy())
		return ;
	
	// Assign data to the oFrame	
	oFrame_Set(0, data, 0, len, 0);

}
Beispiel #3
0
uint8_t vNet_Send_M1(uint16_t addr, oFrame *frame, uint8_t len)
{
	uint8_t ip_addr[4];
	uint16_t vNet_port;

	// Define the standard vNet port
	vNet_port = ETH_PORT;
	
	// Define the IP address to be used
	if((addr == 0xFFFF) || ((addr > VNET_ADDR_L_M3) && (addr < VNET_ADDR_H_M3)))
	{
		// Set the IP broadcast address
		for(U8 i=0;i<4;i++)
			ip_addr[i]=0xFF;
	}	
	else	
	{
		// Verify the User Mode	
		#if(UMODE_ENABLE)
		if ((addr & 0xFF00) != 0x0000)
		{	
			// The first byte is the User Mode Index, if in range 0x01 - 0x64
			// a standard client/server connection is used with the user interface
			// this give routing and NATting passthrough
			UserMode_Get(addr, &ip_addr[0], (uint8_t*)(&vNet_port));
		}
		else
		#endif
			eth_vNettoIP(addr, &ip_addr[0]);	// Get the IP address
	}
		
	// Build a frame with len of payload as first byte
	vNetM1_header = len+1;
	oFrame_Define(&vNetM1_oFrame);
	oFrame_Set(&vNetM1_header, 0, 1, 0, frame);

	// Send data	
	if(!sendto(UDP_SOCK, (uint8_t*)&vNetM1_oFrame, 0, &ip_addr[0], vNet_port))
	{
		oFrame_Reset();		// Free the frame
		
		// Restart the socket
		vNet_Stop_M1(UDP_SOCK);
		vNet_Begin_M1(UDP_SOCK);
		
		return ETH_FAIL;	// If data sent fail, return
	}
	
	// At this stage data are processed or socket is failed, so we can
	// securely reset the oFrame
	oFrame_Reset();		
		
	return ETH_SUCCESS;
}
Beispiel #4
0
uint8_t vNet_Send_M1(uint16_t addr, oFrame *frame, uint8_t len)
{
	uint8_t sock, ip_addr[4];
	uint16_t count = 0, vNet_port;

	// Check message length
	if ((len == 0) || (len >= UIP_PAYLOADSIZE))
		return ETH_FAIL;
	
	// If the frame is not empty, there are waiting data 	
	oFrame_Define(&vNetM1_oFrame);
	if(oFrame_isBusy())
		return ETH_FAIL;

	// Build a frame with len of payload as first byte
	vNetM1_header = len+1;
	oFrame_Set(&vNetM1_header, 0, 1, 0, frame);
	
	// Define the standard vNet port
	vNet_port = ETH_PORT;

	// Define the IP address to be used
	if((addr == VNET_ADDR_BRDC) ||  (addr == VNET_ADDR_wBRDC) ||  (addr == VNET_ADDR_nBRDC) || ((addr > VNET_ADDR_L_M3) && (addr < VNET_ADDR_H_M3)))
	{
		// Set the IP broadcast address
		for(U8 i=0;i<4;i++)
			ip_addr[i]=0xFF;
	}	
	else
	{
		// Verify the User Mode	
		#if(UMODE_ENABLE)
		if ((addr & 0xFF00) != 0x0000)
		{	
			// The first byte is the User Mode Index, if in range 0x01 - 0x64
			// a standard client/server connection is used with the user interface
			// this give routing and NATting passthrough
			if(!UserMode_Get(addr, &ip_addr[0], (uint8_t*)(&vNet_port)))
			{		
				// Flag the error
				oFrame_Reset();
				
				return ETH_FAIL;
			}	
		}
		else
		#endif
			eth_vNettoIP(addr, &ip_addr[0]);	// Get the IP address
	}
	
	// Setup the connection, data will be sent using a callback function
	if(!uip_udp_sock((u16_t*)ip_addr, vNet_port, (u16_t)ETH_PORT))
	{		
		// Flag the error
		oFrame_Reset();
		
		return ETH_FAIL;
	}
			
	// Data are processed with the IP stack		
	vNet_uIP();		
	
	// At this stage data are processed or socket is failed, so we can
	// securely reset the oFrame
	oFrame_Reset();	
	
	return ETH_SUCCESS;
}