module enc_ss
include "eth_enc28j60_api" ' modulo del compilador
include "unixtime"
dim getRequest as byte[20] ' variables de uso general
dyna as byte[30]
NTPr as byte[48] ' Variable donde se guarda los datos provenienes del Server
txt as string[20]
i,l as byte
dim IPD as byte [4]
const httpHeader as string[31] = "HTTP/1.1 200 OK"+chr(10)+"Content-type: " ' HTTP header
const httpMimeTypeHTML as string[13] = "text/html"+chr(10)+chr(10) ' HTML MIME type
const httpMimeTypeScript as string[14] = "text/plain"+chr(10)+chr(10) ' TEXT MIME type
const httpMethod as string[5] = "GET /"
'///////////////////////////// ' Pagina a mostrar ////////////////////////////////
const pagina as string [837]=
"<meta http-equiv=" + Chr(34) + "refresh" + Chr(34) + " content=" + Chr(34) + "20;url=/" + Chr(34) + chr(62)+
"<html>"+
"<head>"+
"<script src=/x></script>"+
"<title>PIC NTP</title>"+
"</head>"+
"<body>"+
"<div align='center' style='font-size:3cm'>"+
"<strong><script>document.write(Fecha)</script></strong><br>"+
"<strong><script>document.write(Hora)</script></strong><br>"+
"</div>"+
"<hr><br>"+
"Actualice la Configuración<br><br>"+
"<form method='get'><table width='273' border='1' bordercolor='black'>"+
"<tr>"+
"<td width='119' height='40'>"+
"Servidor NTP <br>"+
"</td>"+
"<td width='144'><input type='text' maxlength='15' name='ip'></td>"+
"</tr>"+
"<tr>"+
"<td height='40'>GMT"+
"<input type='checkbox' name='m'>"+
chr(43)+
"<input type='checkbox' name='n'>"+
" - </td>"+
"<td><input type='text' maxlength='4' name='g'></td>"+
"</tr>"+
"<tr>"+
"<td height='47' colspan='2'> "+
"<div align='center'>"+
"<input name='Enviar' type='submit' value='Actualizar'>"+
"</div></td>"+
"</tr>"+
"</table></form>"+
"</body>"+
"</html>"
'/////////////////////////// Implementacion TCP
sub function Spi_Ethernet_UserTCP(dim byref remoteHost as byte[4], dim remotePort, localPort, reqLength as word) as word
result=0
if localport<>80 then 'escuchamos puerto 80
result=0
end if
for i = 0 to 23
getRequest[i] = Spi_Ethernet_getByte()
next i
getRequest[i] = 0
i = 0
while (httpMethod[i] <> 0)
txt[i] = httpMethod[i]
i = i + 1
wend
if(memcmp(@getRequest, @txt, 5)<>0) then ' Solo se soporta en metodo GET
result = 0
exit
end if
if(getRequest[5] = "x") then 'Si el byte 5 corresponde a "x" mostramos los valores
'el texto puede interpretarse como javascritp /x
result = Spi_Ethernet_putConstString(@httpHeader) ' HTTP header
result = result + Spi_Ethernet_putConstString(@httpMimeTypeScript) ' MIME type
'Mostramos Fecha Contruyendo una variable tipo string JS: var= " fecha";
dyna = fecha.str1
txt = "var Fecha= "
result = result + Spi_Ethernet_putString(@txt)
txt = ""+chr(34)
result = result + Spi_Ethernet_putString(@txt)
result = result + Spi_Ethernet_putString(@dyna)
txt = ""+chr(34)
result = result + Spi_Ethernet_putString(@txt)
txt = ";"
result = result + Spi_Ethernet_putString(@txt)
' Mostramos Hora Contruyendo una variable tipo string JS: var= " Hora";
txt = "var Hora= "
result = result + Spi_Ethernet_putString(@txt)
dyna = fecha.str2
txt = ""+chr(34)
result = result + Spi_Ethernet_putString(@txt)
result = result + Spi_Ethernet_putString(@dyna)
txt = ""+chr(34)
result = result + Spi_Ethernet_putString(@txt)
txt = ";"
result = result + Spi_Ethernet_putString(@txt)
end if
if(result = 0) then 'Mostrar por defalt
result = Spi_Ethernet_putConstString(@httpHeader) ' HTTP header
result = result + Spi_Ethernet_putConstString(@httpMimeTypeHTML) ' HTML MIME type
result = result + Spi_Ethernet_putConstString(@pagina) ' Pagina HTML
end if
end sub
'//////////////////////////// Implementacion UDP
sub function Spi_Ethernet_UserUDP(dim byref remoteHost as byte[4], dim remotePort, destPort, reqLength as word) as word
result = 0 ' reseteo de la funcion
if destport = 123 then ' Escuchamos por el puerto 123 para capturar datos NTP
for i=0 to 47
NTPr[i]=spi_ethernet_getbyte() 'Grabamos los datos en la variable
next i
FSR2Ptr = @UTCseg ' Converimos los valores separados en una variable de 32bits
POSTINC2 = NTPr[43]
POSTINC2 = NTPr[42]
POSTINC2 = NTPr[41]
INDF2 = NTPr[40]
actualdate() ' Llamamos al Procedimiento para convertir la hora.
end if
end sub
end.