User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
463
/*
* this function is called by the library
* the user accesses to the UDP request by successive calls to Spi_Ethernet_getByte()
* the user puts data in the transmit buffer by successive calls to Spi_Ethernet_
putByte()
* the function must return the length in bytes of the UDP reply, or 0 if nothing to
transmit
*
* if you don’t need to reply to UDP requests,
* just dene this function with a return(0) as single statement
*
*/
unsigned int SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort,
unsigned int destPort, unsigned int reqLength, TEthPktFlags *ags)
{
unsigned int len; // my reply length
// reply is made of the remote host IP address in human readable format
ByteToStr(remoteHost[0], dyna); // rst IP address byte
dyna[3] = ‘.’;
ByteToStr(remoteHost[1], dyna + 4); // second
dyna[7] = ‘.’;
ByteToStr(remoteHost[2], dyna + 8); // third
dyna[11] = ‘.’;
ByteToStr(remoteHost[3], dyna + 12); // fourth
dyna[15] = ‘:’; // add separator
// then remote host port number
WordToStr(remotePort, dyna + 16);
dyna[21] = ‘[‘;
WordToStr(destPort, dyna + 22);
dyna[27] = ‘]’;
dyna[28] = 0;
// the total length of the request is the length of the dynamic string plus the
text of the request
len = 28 + reqLength;
// puts the dynamic string into the transmit buffer
SPI_Ethernet_putBytes(dyna, 28);
// then puts the request string converted into upper char into the transmit buffer
while(reqLength--)
{
SPI_Ethernet_putByte(toupper(SPI_Ethernet_getByte()));
}
return(len); // back to the library with the length of the UDP reply
}