User manual

422
mikoPascal PRO for PIC32
MikroElektronika
{*
* 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 dene this function with a return(0) as single statement
*
*}
function SPI_Ethernet_UserTCP(var remoteHost : array[4] of byte;
remotePort, localPort, reqLength : word; var ags:
TEthPktFlags) : word;
var i : word; // my reply length
bitMask : dword; // for bit mask
tmp: string[11]; // to copy const array to ram for memcmp
begin
result := 0;
// 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) then // I listen only to web request on port 80
begin
result := 0;
exit;
end;
// get 10 rst bytes only of the request, the rest does not matter here
for i := 0 to 9 do
getRequest[i] := SPI_Ethernet_getByte();
getRequest[i] := 0;
// copy httpMethod to ram for use in memcmp routine
for i := 0 to 4 do
tmp[i] := httpMethod[i];
if(memcmp(@getRequest, @tmp, 5) <> 0) then // only GET method is supported here
begin
result := 0;
exit;
end;
Inc(httpCounter); // one more request done
if(getRequest[5] = ‘s’) then // if request path name starts with s,
store dynamic data in transmit buffer
begin
// the text string replied by this request can be interpreted as javascript
statements
// by browsers