User manual
mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
496
function SPI_Ethernet_UserUDP(var remoteHost : array[4] of byte;
remotePort, destPort, reqLength : word; var ags:
TEthPktFlags) : word;
var tmp : string[5];
begin
result := 0;
// 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], tmp); // second
dyna[4] := tmp[0];
dyna[5] := tmp[1];
dyna[6] := tmp[2];
dyna[7] := ‘.’;
byteToStr(remoteHost[2], tmp); // second
dyna[8] := tmp[0];
dyna[9] := tmp[1];
dyna[10] := tmp[2];
dyna[11] := ‘.’;
byteToStr(remoteHost[3], tmp); // second
dyna[12] := tmp[0];
dyna[13] := tmp[1];
dyna[14] := tmp[2];
dyna[15] := ‘:’; // add separator
// then remote host port number
WordToStr(remotePort, tmp);
dyna[16] := tmp[0];
dyna[17] := tmp[1];
dyna[18] := tmp[2];
dyna[19] := tmp[3];
dyna[20] := tmp[4];
dyna[21] := ‘[‘;
WordToStr(destPort, tmp);
dyna[22] := tmp[0];
dyna[23] := tmp[1];
dyna[24] := tmp[2];
dyna[25] := tmp[3];
dyna[26] := tmp[4];
dyna[27] := ‘]’;
dyna[28] := 0;
// the total length of the request is the length of the dynamic string plus the
text of the request
result := 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 <> 0) do
begin
SPI_Ethernet_putByte(SPI_Ethernet_getByte());
reqLength := reqLength - 1;
end;
// back to the library with the length of the UDP reply
end;