I have a problem like this .
http://forum.arduino.cc/index.php?topic=345134.5
I want to know how to add the code which was written in a comment to library of UDP
The beginPacketMAC and endPacketMAC functions dont exist so lets add them to libraries\ethernet\src\ethernetudp.cpp and the header file
Code: [Select]
int EthernetUDP::beginPacketMAC(IPAddress ip, uint8_t* mac, uint16_t port)
{
_offset = 0;
return startUDPMAC(_sock, rawIPAddress(ip), mac, port);
}
int EthernetUDP::endPacketMAC()
{
return sendUDPMAC(_sock);
}
The startUDPMAC and sendUDPMAC functions also dont exist so lets add them to libraries\ethernet\src\utility\socket.h and the header file ... this is where the real work gets done.
Code: [Select]
int startUDPMAC(SOCKET s, uint8_t* addr, uint8_t* mac, uint16_t port)
{
if
(((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
((mac[0] == 0x00) && (mac[1] == 0x00) && (mac[2] == 0x00) && (mac[3] == 0x00) && (mac[4] == 0x00) && (mac[5] == 0x00)) ||
(port == 0x00)
)
{
return 0;
}
else
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.writeSnDIPR(s, addr);
// this is where we tell it the mac address we are sending to
W5100.writeSnDHAR(s, mac);
W5100.writeSnDPORT(s, port);
SPI.endTransaction();
return 1;
}
}
int sendUDPMAC(SOCKET s)
{
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
W5100.execCmdSn(s, Sock_SEND_MAC);
/* +2008.01 bj /
while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK )
{
if (W5100.readSnIR(s) & SnIR::TIMEOUT)
{
/ +2008.01 [bj]: clear interrupt */
W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
SPI.endTransaction();
return 0;
}
SPI.endTransaction();
yield();
SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
}
/* +2008.01 bj */
W5100.writeSnIR(s, SnIR::SEND_OK);
SPI.endTransaction();
/* Sent ok */
return 1;
}