User manual

512
mikoC PRO for dsPIC
MikroElektronika
SPI_Ethernet_sendUDP
SPI_Ethernet_dnsResolve
Prototype
unsigned int SPI_Ethernet_sendUDP(unsigned char *destIP, unsigned int
sourcePort, unsigned int destPort, unsigned char *pkt, unsigned int
pktLen);
Description This is UDP module routine. It sends an UDP packet on the network.
Parameters - destIP: remote host IP address.
- sourcePort: local UDP source port number.
- destPort: destination UDP port number.
- pkt: packet to transmit.
- pktLen: length in bytes of packet to transmit.
Returns - 1 - UDP packet was sent successfully.
- 0 - otherwise.
Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
unsigned char IpAddr[4] = {192, 168, 1, 1 }; // remote IP address
...
SPI_Ethernet_sendUDP(IpAddr, 10001, 10001, “Hello”, 5); // send Hello message
to the above IP address, from UDP port 10001 to UDP port 10001
Notes None.
Prototype
unsigned char * SPI_Ethernet_dnsResolve(unsigned char *host, unsigned char
tmax);
Description This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply. If
the requested host name was resolved, it’s IP address is stored in library global variable and a pointer
containing this address is returned by the routine. UDP port 53 is used as DNS port.
Parameters - host: host name to be resolved.
- tmax: time in seconds to wait for an reply.
Returns - pointer to the location holding the IP address - the requested host name was resolved.
- 0 - otherwise.
Requires Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
unsigned char * remoteHostIpAddr[4]; // user host IP address buffer
...
// SNTP server:
// Zurich, Switzerland: Integrated Systems Lab, Swiss Fed. Inst. of
Technology
// 129.132.2.21: swisstime.ethz.ch
// Service Area: Switzerland and Europe
memcpy(remoteHostIpAddr, SPI_Ethernet_dnsResolve(“swisstime.ethz.ch”, 5),
4);
Notes The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will
be processed normaly during this time.
User should always copy the IP address from the RAM location returned by this routine into it’s own
resolved host IP address buffer. These locations should not be altered by the user in any case!