/* returns number of bytes sent on success, negative on failure */ int ethernet_send_pdu( BACNET_ADDRESS * dest, /* destination address */ BACNET_NPDU_DATA * npdu_data, /* network information */ uint8_t * pdu, /* any data to be sent - may be null */ unsigned pdu_len) { /* number of bytes of data */ int i = 0; /* counter */ int bytes = 0; BACNET_ADDRESS src = { 0 }; /* source address for npdu */ uint8_t mtu[MAX_MPDU] = { 0 }; /* our buffer */ int mtu_len = 0; (void) npdu_data; /* load the BACnet address for NPDU data */ for (i = 0; i < 6; i++) { src.mac[i] = Ethernet_MAC_Address[i]; src.mac_len++; } /* don't waste time if the socket is not valid */ if (!ethernet_valid()) { return -1; } /* load destination ethernet MAC address */ if (dest->mac_len == 6) { for (i = 0; i < 6; i++) { mtu[i] = dest->mac[i]; } } else { return -2; } /* load source ethernet MAC address */ if (src.mac_len == 6) { for (i = 0; i < 6; i++) { mtu[6 + i] = src.mac[i]; } } else { return -3; } /* Logical PDU portion */ mtu[14] = 0x82; /* DSAP for BACnet */ mtu[15] = 0x82; /* SSAP for BACnet */ mtu[16] = 0x03; /* Control byte in header */ mtu_len = 17; if ((mtu_len + pdu_len) > MAX_MPDU) { return -4; } memcpy(&mtu[mtu_len], pdu, pdu_len); mtu_len += pdu_len; /* packet length - only the logical portion, not the address */ encode_unsigned16(&mtu[12], 3 + pdu_len); /* Send the packet */ bytes = R_Ether_Write(0, mtu, mtu_len); return bytes; }
int ethernet_send( uint8_t * mtu, int mtu_len) { int bytes = 0; /* Send the packet */ bytes = R_Ether_Write(0, mtu, mtu_len); return bytes; }
/*----------------------------------------------------------------------------*/ int main(void) { int i; // Renesas -- uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; struct uip_eth_addr my_mac; uint32_t ch = 0; // Renesas ++ InitialiseLCD(); DisplayuIPDemo(); timer_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); Exosite_Get_MAC((unsigned char *)&my_mac); // Renesas -- network_device_init(); /* Wait until Ether device initailize succesfully. Make sure Ethernet cable is plugged in. */ while (R_ETHER_ERROR == R_Ether_Open(ch, (uint8_t*)&my_mac)); // Renesas ++ set Ethernet address uip_setethaddr(my_mac); uip_init(); // Renesas -- //uip_ipaddr(ipaddr, 192,168,0,2); //uip_sethostaddr(ipaddr); dhcpc_init(&my_mac, 6); if (!Exosite_Init(APP_NAME, APP_VERSION)) DisplayLCD(LCD_LINE8, "==NEED CIK=="); while (1) { // Renesas -- uip_len = network_device_read(); uip_len = R_Ether_Read(ch, (void *)uip_buf); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len); } } } else if (timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for (i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len); } } #if UIP_UDP for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); // Renesas -- network_device_send(); R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if (timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } // Insert user aplications here. // Call WEB application that controls LEDs on the target board. user_app(); } return 0; }