void EtherShield::ES_register_ping_rec_callback(void (*callback)(uint8_t *srcip)) { register_ping_rec_callback(callback); }
/* * Main entry point */ int main(void) { //=====init green led LEDInit(); LEDSet(1); //=====setup eth interface uint16_t plen = 0, dat_p = 0; //initialize enc28j60 enc28j60Init(mymac); _delay_ms(100); // Magjack leds configuration, see enc28j60 datasheet, page 11 // LEDB=yellow LEDA=green // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); enc28j60PhyWrite(PHLCON,0x476); _delay_ms(100); //init the ethernet/ip layer: init_udp_or_www_server(mymac,myip); www_server_port(MYWWWPORT); register_ping_rec_callback(PingCallback); while(1){ // handle ping and wait for a tcp packet: dat_p = packetloop_arp_icmp_tcp(buf, enc28j60PacketReceive(BUFFER_SIZE, buf)); // dat_p will be unequal to zero if there is a valid http get if(dat_p==0){ // do nothing continue; } // tcp port 80 begin if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){ dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n")); dat_p = fill_tcp_data_p(buf, dat_p, PSTR("<h1>200 OK</h1>")); goto SENDTCP; } if (strncmp("/ ",(char *) & (buf[ dat_p + 4] ), 2) == 0 ){ nAccessCount++; dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n")); // webcontent char szWebText[130] = {0}; sprintf(szWebText, "<b>ATmega8 Webserver / ENC28J60</b><br><br>Server stats:<br>Acc:%d Png:%d<br><br>(C) Radu Motisan 2012, www.pocketmagic.net<br/>Tomasz Jokiel", nAccessCount, nPingCount); dat_p = fill_tcp_data(buf, dat_p, szWebText); // goto SENDTCP; } // all other URLs: dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>")); SENDTCP: www_server_reply(buf, dat_p); // send web page data } return (0); }