📄 httpd.lst
字号:
652:net/httpd.c **** httpd_conn[socketnum].state = HTTPD_STATE_FINISHED;
653:net/httpd.c **** return ret-TCP_POS_TXDATA;
654:net/httpd.c **** }
655:net/httpd.c ****
656:net/httpd.c **** return NIC_BUFFERSIZE-TCP_POS_TXDATA;
657:net/httpd.c **** break;
658:net/httpd.c ****
659:net/httpd.c **** case(HTTPD_STATE_FINISHED):
660:net/httpd.c **** //if this was an filesystem format request, do it !
661:net/httpd.c **** //takes a very long time !!!
662:net/httpd.c **** if (httpd_conn[socketnum].file_id == HTTPD_STATE_FILE_MKFS2){
663:net/httpd.c **** LED_STATUS_OFF();
664:net/httpd.c **** filesystem_format();
665:net/httpd.c **** LED_STATUS_ON();
666:net/httpd.c **** }
667:net/httpd.c ****
668:net/httpd.c **** httpd_conn[socketnum].state = HTTPD_STATE_IDLE;
669:net/httpd.c **** *appstate = TCP_APPSTATE_FINISHED;
670:net/httpd.c **** return 0;
671:net/httpd.c ****
672:net/httpd.c **** case(HTTPD_STATE_POST):
673:net/httpd.c **** #if HTTPD_DEBUG
674:net/httpd.c **** softuart_puts_progmem("HTTP: upload todo (low 16bit only): ");
675:net/httpd.c **** softuart_put_uint16(httpd_conn[socketnum].data_position & 0xFFFF);
676:net/httpd.c **** softuart_puts_progmem(" datalen=");
677:net/httpd.c **** softuart_put_uint16(datalen&0xFFFF);
678:net/httpd.c **** softuart_putnewline();
679:net/httpd.c **** #endif
680:net/httpd.c **** if (httpd_conn[socketnum].data_position <= datalen){
681:net/httpd.c **** //find termination:
682:net/httpd.c **** unsigned int endpos;
683:net/httpd.c **** for(endpos=TCP_POS_TXDATA; endpos<TCP_POS_TXDATA+datalen; endpos++){
684:net/httpd.c **** //quick hack, might return false positives !
685:net/httpd.c **** if (string_compare_progmem_noeof("---------------", &buffer[endpos])){
686:net/httpd.c **** endpos-=2;
687:net/httpd.c **** break;
688:net/httpd.c **** }
689:net/httpd.c **** }
690:net/httpd.c ****
691:net/httpd.c **** filesystem_write_data(&buffer[TCP_POS_TXDATA], (endpos-TCP_POS_TXDATA),0);
692:net/httpd.c ****
693:net/httpd.c **** filesystem_close_file();
694:net/httpd.c **** //pos = httpd_add_progmem_data(HTTPD_CTYPE_HTML,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
695:net/httpd.c **** //pos = httpd_add_progmem_data(HTTPD_RNRN,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
696:net/httpd.c **** //pos = httpd_add_progmem_data(PSTR("HTTP/1.0 200 Document follows\r\nContent-Type: text/html\r
697:net/httpd.c **** //httpd_conn[socketnum].state = 123;
698:net/httpd.c **** pos = httpd_add_progmem_data(PSTR("HTTP/1.0 200 Document follows\r\nContent-Type: text/html\r\n
699:net/httpd.c **** httpd_conn[socketnum].state = HTTPD_STATE_ACTIVE;
700:net/httpd.c ****
701:net/httpd.c **** //check if upload successfull
702:net/httpd.c **** if (httpd_conn[socketnum].data_position == datalen)
703:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_UP_DONE;
704:net/httpd.c **** else
705:net/httpd.c **** httpd_conn[socketnum].file_id = HTTPD_STATE_FILE_UP_ERR;
706:net/httpd.c ****
707:net/httpd.c **** httpd_conn[socketnum].seq_offset = pos - datapos + 1;
708:net/httpd.c ****
709:net/httpd.c **** *appstate = TCP_APPSTATE_HAS_TXDATA;
710:net/httpd.c ****
711:net/httpd.c ****
712:net/httpd.c **** return (pos-TCP_POS_TXDATA);
713:net/httpd.c **** }else{
714:net/httpd.c **** httpd_conn[socketnum].data_position -= datalen;
715:net/httpd.c **** //filesystem_seek_to(tcp_sockets[socketnum].ack);
716:net/httpd.c **** filesystem_write_data(&buffer[TCP_POS_TXDATA], datalen,0);
717:net/httpd.c ****
718:net/httpd.c **** *appstate = TCP_APPSTATE_EMPTYACK;
719:net/httpd.c **** }
720:net/httpd.c ****
721:net/httpd.c **** return 0;
722:net/httpd.c ****
723:net/httpd.c **** case(123):
724:net/httpd.c **** *appstate = TCP_APPSTATE_FINISHED;
725:net/httpd.c **** return 0;
726:net/httpd.c **** break;
727:net/httpd.c ****
728:net/httpd.c **** /* case(4):
729:net/httpd.c **** case(5):
730:net/httpd.c ****
731:net/httpd.c **** pos = TCP_POS_TXDATA;
732:net/httpd.c **** buffer[pos++] = '.';
733:net/httpd.c **** *appstate = TCP_APPSTATE_HAS_TXDATA;
734:net/httpd.c ****
735:net/httpd.c ****
736:net/httpd.c ****
737:net/httpd.c **** tcp_sockets[socketnum].misc_state = tcp_sockets[socketnum].misc_state+1;
738:net/httpd.c **** return (pos-TCP_POS_TXDATA);
739:net/httpd.c ****
740:net/httpd.c **** case(6):
741:net/httpd.c **** //finished...
742:net/httpd.c **** *appstate = TCP_APPSTATE_FINISHED;
743:net/httpd.c **** tcp_sockets[socketnum].misc_state = 0;
744:net/httpd.c **** return 0;
745:net/httpd.c **** */
746:net/httpd.c **** default:
747:net/httpd.c **** *appstate = TCP_APPSTATE_EMPTYACK;
748:net/httpd.c **** }
749:net/httpd.c ****
750:net/httpd.c **** return 0;
751:net/httpd.c **** }
752:net/httpd.c ****
753:net/httpd.c **** //add program data to buffer
754:net/httpd.c **** //replaces $$ by data pointed to by include ptr,
755:net/httpd.c **** //while parsing <include> replace $$.. by special data!
756:net/httpd.c **** //WARNING: very big !! -> rewrite later !
757:net/httpd.c **** unsigned int httpd_add_progmem_data(PGM_P pointer, PGM_P include,unsigned char *buffer, unsigned in
758:net/httpd.c **** unsigned char data;
759:net/httpd.c **** unsigned char data_next;
760:net/httpd.c **** unsigned char smallbuffer[10];
761:net/httpd.c **** unsigned char data_available;
762:net/httpd.c **** PGM_P data_ptr;
763:net/httpd.c **** PGM_P data_ptr_old;
764:net/httpd.c **** unsigned char skip_next_data_byte;
765:net/httpd.c ****
766:net/httpd.c **** //start with main data pointer:
767:net/httpd.c **** data_ptr = pointer;
768:net/httpd.c **** data_ptr_old = NULL;
769:net/httpd.c **** data_available = 1;
770:net/httpd.c **** data = pgm_read_byte(data_ptr++);
771:net/httpd.c **** skip_next_data_byte = 0;
772:net/httpd.c ****
773:net/httpd.c **** while (data_available != 0){
774:net/httpd.c **** if (skip_next_data_byte){
775:net/httpd.c **** skip_next_data_byte = 0;
776:net/httpd.c **** }else{
777:net/httpd.c **** if (offset == 0){
778:net/httpd.c **** //append data:
779:net/httpd.c **** buffer[pos++] = data;
780:net/httpd.c **** len--;
781:net/httpd.c **** }else{
782:net/httpd.c **** offset--;
783:net/httpd.c **** }
784:net/httpd.c **** }
785:net/httpd.c **** if (len == 0)
786:net/httpd.c **** return 0;
787:net/httpd.c ****
788:net/httpd.c **** data = pgm_read_byte(data_ptr++);
789:net/httpd.c **** data_next = pgm_read_byte(data_ptr);
790:net/httpd.c ****
791:net/httpd.c **** //while parsing the include file we replace
792:net/httpd.c **** //$$TN -> temp now
793:net/httpd.c **** //$$T+ -> max temp today
794:net/httpd.c **** //$$T- -> min temp today
795:net/httpd.c **** //$$CK -> current time
796:net/httpd.c **** //$$FF -> show include file
797:net/httpd.c **** //$$Ixy -> show PORTx.y pin as icon
798:net/httpd.c **** //$$?? -> show enc28j60 revision
799:net/httpd.c **** if ((data == '$') && (data_next == '$')){
800:net/httpd.c **** switch (pgm_read_byte(data_ptr + 1)){
801:net/httpd.c **** case ('F'):
802:net/httpd.c **** //include other file !
803:net/httpd.c **** if (include != NULL){
804:net/httpd.c **** //reconfigure data pointer
805:net/httpd.c **** //+/- 3: see bolow data_ptr+=3 !
806:net/httpd.c **** data_ptr_old = data_ptr + 3;
807:net/httpd.c **** data_ptr = include -3;
808:net/httpd.c **** data_available = 2;
809:net/httpd.c **** }
810:net/httpd.c **** break;
811:net/httpd.c ****
812:net/httpd.c **** case ('L'):
813:net/httpd.c **** //dataflash file list
814:net/httpd.c **** pos = filesystem_generate_index(buffer, pos, &len, &offset);
815:net/httpd.c **** if (pos == 0)
816:net/httpd.c **** return 0; //eof
817:net/httpd.c **** break;
818:net/httpd.c ****
819:net/httpd.c **** case ('T'):
820:net/httpd.c **** //temperature request!
821:net/httpd.c **** //if there is not enough space in buffer, abort & wait for next packet: <0XX,X>
822:net/httpd.c **** ///if (pos+5 > NIC_BUFFERSIZE)
823:net/httpd.c **** /// return 0;
824:net/httpd.c ****
825:net/httpd.c **** //temperature fits!
826:net/httpd.c **** //calculate buffer
827:net/httpd.c **** if (pgm_read_byte(data_ptr + 2) == 'N') //TEMP NOW:
828:net/httpd.c **** logger_output_temp(&smallbuffer[0], LOGGER_NOW);
829:net/httpd.c **** else if (pgm_read_byte(data_ptr + 2) == '-') //TEMP MIN
830:net/httpd.c **** logger_output_temp(&smallbuffer[0], LOGGER_MIN);
831:net/httpd.c **** else //TEMP MAX
832:net/httpd.c **** logger_output_temp(&smallbuffer[0], LOGGER_MAX);
833:net/httpd.c ****
834:net/httpd.c **** //copy smallbuffer to ethernetbuffer
835:net/httpd.c **** for (unsigned char i=0; i<5; i++){
836:net/httpd.c **** if (offset == 0){
837:net/httpd.c **** buffer[pos++] = smallbuffer[i];
838:net/httpd.c **** len--;
839:net/httpd.c **** if (len == 0)
840:net/httpd.c **** return 0;
841:net/httpd.c **** }else{
842:net/httpd.c **** offset--;
843:net/httpd.c **** }
844:net/httpd.c **** }
845:net/httpd.c **** break;
846:net/httpd.c ****
847:net/httpd.c **** case ('C'):
848:net/httpd.c **** //CLOCK:
849:net/httpd.c **** //if there is not enough space in buffer, abort & wait for next packet: <0XX,X>
850:net/httpd.c **** ///if (pos+8 > NIC_BUFFERSIZE)
851:net/httpd.c **** /// return 0;
852:net/httpd.c ****
853:net/httpd.c **** //make sure the time is correct
854:net/httpd.c **** clock_do();
855:net/httpd.c ****
856:net/httpd.c **** //fill small buffer
857:net/httpd.c **** string_uint8_to_buffer_02dez(&smallbuffer[0], clock[CLOCK_HOUR]);
858:net/httpd.c **** smallbuffer[2] = ':';
859:net/httpd.c **** string_uint8_to_buffer_02dez(&smallbuffer[3], clock[CLOCK_MIN]);
860:net/httpd.c **** smallbuffer[5] = ':';
861:net/httpd.c **** string_uint8_to_buffer_02dez(&smallbuffer[6], clock[CLOCK_SEC]);
862:net/httpd.c ****
863:net/httpd.c **** //copy small buffer to ethernet buffer
864:net/httpd.c **** for (unsigned char i=0; i<8; i++){
865:net/httpd.c **** if (offset == 0){
866:net/httpd.c **** buffer[pos++] = smallbuffer[i];
867:net/httpd.c **** len--;
868:net/httpd.c **** if (len == 0)
869:net/httpd.c **** return 0;
870:net/httpd.c **** }else{
871:net/httpd.c **** offset--;
872:net/httpd.c **** }
873:net/httpd.c **** }
874:net/httpd.c **** break;
875:net/httpd.c ****
876:net/httpd.c **** case ('I'):
877:net/httpd.c **** smallbuffer[0] = pgm_read_byte(data_ptr + 2);
878:net/httpd.c **** smallbuffer[1] = pgm_read_byte(data_ptr + 3);
879:net/httpd.c **** smallbuffer[2] = '_';
880:net/httpd.c **** smallbuffer[3] = '0' + port_get_portbit(pgm_read_byte(data_ptr + 2), pgm_read_byte(data_ptr +
881:net/httpd.c **** string_progmem_to_buffer(PSTR(".gif"), &smallbuffer[4], 4);
882:net/httpd.c ****
883:net/httpd.c **** //copy small buffer to ethernet buffer
884:net/httpd.c **** for (unsigned char i=0; i<8; i++){
885:net/httpd.c **** if (offset == 0){
886:net/httpd.c **** buffer[pos++] = smallbuffer[i];
887:net/httpd.c **** len--;
888:net/httpd.c **** if (len == 0)
889:net/httpd.c **** return 0;
890:net/httpd.c **** }else{
891:net/httpd.c **** offset--;
892:net/httpd.c **** }
893:net/httpd.c **** }
894:net/httpd.c **** data_ptr += 1; //we use one byte more here !
895:net/httpd.c **** break;
896:net/httpd.c ****
897:net/httpd.c **** case ('?'):
898:net/httpd.c **** string_uint8_to_buffer(&smallbuffer[0], enc28j60_revision);
899:net/httpd.c **** for (unsigned char i=0; i<3; i++){
900:net/httpd.c **** if (offset == 0){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -