📄 main.c
字号:
plen = fill_tcp_data_p(buf, plen, PSTR("The time is: <input type=text name=\"theTime\" style=\"font-family: Arial Black\" style=\"font-size=15\">")); plen = fill_tcp_data_p(buf, plen, PSTR("</form></center></body></HTML>")); } else { plen = fill_tcp_data_p(buf, plen, PSTR("<HTML><HEAD><TITLE>WebServer</TITLE></HEAD> ")); plen = fill_tcp_data_p(buf, plen, PSTR("<FRAMESET cols=\"10%,90%\"><FRAMESET rows=\"90%,10%\">")); plen = fill_tcp_data_p(buf, plen, PSTR("<FRAME noresize name=\"links\" src=\"http://"MY_IP_STR"/sec/l.htm\">")); plen = fill_tcp_data_p(buf, plen, PSTR("<FRAME noresize name=\"time\" src=\"http://"MY_IP_STR"/sec/t.htm\">")); plen = fill_tcp_data_p(buf, plen, PSTR("</FRAMESET><FRAMESET rows=\"15%,85%\">")); plen = fill_tcp_data_p(buf, plen, PSTR("<FRAME noresize name=\"banner\" src=\"http://"MY_IP_STR"/sec/b.htm\">")); plen = fill_tcp_data_p(buf, plen, PSTR("<FRAME noresize name=\"content\" src=\"http://"MY_IP_STR"/sec/h.htm\">")); plen = fill_tcp_data_p(buf, plen, PSTR("</FRAMESET></FRAMESET></HTML>")); } return plen;}// Init timer2 to generate an interrupt every milisecond.void initTimer2(void){ // TODO: // Configurati timer2 ca sa dea o intrerupere la o milisecunda // (Prescaler & Output Compare Interrupt)}// Output compare interrupt handler for timer2.SIGNAL(SIG_OUTPUT_COMPARE2){ // TODO: // Faceti "algoritmul" pentru incrementarea secundelor, minutelor // si orelor (vezi variabilele milisec, secunde, minute, ore declarate // mai sus).}int main(void) { uint16_t plen; uint16_t dat_p; uint8_t i = 0; int8_t cmd; delay_ms(10); initTimer2(); sei(); // Enable PD4, reset as output. DDRD |= (1<<DDD4); DDRA |= (1<<DDA0) | (1<<DDA1) | (1<<DDA2) | (1<<DDA3) | (1<<DDA4) | (1<<DDA5) | (1<<DDA6) | (1<<DDA7); // Set output to gnd, reset the ethernet chip. PORTD &= ~(1<<PD4); delay_ms(10); // Set output to Vcc, reset inactive. PORTD |= (1<<PD4); delay_ms(200); // Initialize enc28j60. enc28j60Init(mymac); delay_ms(20); // Enable PB1, LED as output. DDRB |= (1<<DDB0); // Set output to Vcc, LED off. PORTB |= (1<<PB1); enc28j60PhyWrite(PHLCON, 0x476); delay_ms(20); // Set output to GND, red LED on. PORTB &= ~(1<<PB0); i = 1; // Init the ethernet/ip layer. init_ip_arp_udp_tcp(mymac, myip, mywwwport); while (1) { // Get the next new packet. plen = enc28j60PacketReceive(BUFFER_SIZE, buf); // plen will be different than zero if there is a valid // packet (without crc error). if (plen == 0) { continue; } // Arp is broadcast if unknown but a host may also // verify the mac address by sending it to // a unicast address. if (eth_type_is_arp_and_my_ip(buf, plen)) { make_arp_answer_from_request(buf); continue; } // Check if ip packets are for us. if (eth_type_is_ip_and_my_ip(buf,plen) == 0) { continue; } if (buf[IP_PROTO_P] == IP_PROTO_ICMP_V && buf[ICMP_TYPE_P] == ICMP_TYPE_ECHOREQUEST_V) { // A ping packet, let's send pong. make_echo_reply_from_request(buf,plen); continue; } // TCP port www start, compare only the lower byte. if (buf[IP_PROTO_P] == IP_PROTO_TCP_V && buf[TCP_DST_PORT_H_P] == 0 && buf[TCP_DST_PORT_L_P] == mywwwport) { // Read source IP. yip[0] = buf[26]; yip[1] = buf[27]; yip[2] = buf[28]; yip[3] = buf[29]; if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V) { make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack. continue; } if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V) { init_len_info(buf); // We can possibly have no data, just ack. dat_p = get_tcp_data_pointer(); if (dat_p == 0) { if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V) { // Finack, answer with ack. make_tcp_ack_from_any(buf); } // Just an ack with no data, wait for next packet. continue; } if (strncmp("GET ", (char *)&(buf[dat_p]), 4) != 0) { // Head, post and other methods. // For possible status codes see: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html plen = fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>")); goto SENDTCP; } if (strncmp("/ ", (char *)&(buf[dat_p + 4]), 2) == 0) { plen=fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")); plen=fill_tcp_data_p(buf, plen, PSTR("<p>Usage: ")); plen=fill_tcp_data(buf, plen, baseurl); plen=fill_tcp_data_p(buf, plen, PSTR("/</p>")); goto SENDTCP; } cmd = analyse_get_url((char *)&(buf[dat_p + 5])); if (page == 0) // aprins/stins ledurile PORTA = cmd; plen = print_webpage(buf,cmd);SENDTCP: make_tcp_ack_from_any(buf); // send ack for http get make_tcp_ack_with_data(buf,plen); // send data continue; } } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -