User manual
518
mikoC PRO for dsPIC
MikroElektronika
#dene putString SPI_Ethernet_putString
/*
 * this function is called by the library
 * the user accesses to the HTTP 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 HTTP reply, or 0 if nothing to 
transmit
 *
 * if you don't need to reply to HTTP requests,
 * just dene this function with a return(0) as single statement
 *
 */
unsigned int    SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, 
unsigned int localPort, unsigned int reqLength, TEthPktFlags *ags)
 {
 unsigned int len; // my reply length
 // should we close tcp socket after response is sent?
 // library closes tcp socket by default if canCloseTCP ag is not reset here
 // ags->canCloseTCP = 0; // 0 - do not close socket
 // otherwise - close socket
 if(localPort != 80) // I listen only to web request on port 80
 {
 return(0);
 }
 // get 10 rst bytes only of the request, the rest does not matter here
 for(len = 0; len < 10; len++)
 {
 getRequest[len] = SPI_Ethernet_getByte();
 }
 getRequest[len] = 0;
 len = 0;
 if(memcmp(getRequest, httpMethod, 5)) // only GET method is supported here
 {
 return(0);
 }
 httpCounter++; // one more request done
 if(getRequest[5] == ‘s’)                   // if request path name starts with s, store 
dynamic data in transmit buffer
 {
                // the text string replied by this request can be interpreted as javascript 
statements
 // by browsers
 len = putConstString(httpHeader); // HTTP header
 len += putConstString(httpMimeTypeScript); // with text MIME type










