|
原理图
提供的程序 C51 AVR LPC STM32
C51程序
- #include "uip.h"
- #include "uip_arp.h"
- //#include "rtl8019as.h"
- #include "httpd.h"
- //#include "telnet.h"
- #include "mcu_uart.h"
- #include "enc28j60.h"
- #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
- #ifndef NULL
- #define NULL (void *)0
- #endif /* NULL */
- /*-----------------------------------------------------------------------------------*/
- int
- main(void)
- {
- idata u8_t i, arptimer;
- idata u16_t j;
- init_uart();
- printu("starting......\r\n");
- /* Initialize the device driver. */
- // rtl8019as_init();
- dev_init();
- uip_arp_init();
- /* Initialize the uIP TCP/IP stack. */
- uip_init();
- printu("11111111111111111111111\r\n");
- /* Initialize the HTTP server. */
- httpd_init();
-
- arptimer = 0;
- printu("222222222222222222222222222\r\n");
- while(1) {
- /* Let the tapdev network device driver read an entire IP packet
- into the uip_buf. If it must wait for more than 0.5 seconds, it
- will return with the return value 0. If so, we know that it is
- time to call upon the uip_periodic(). Otherwise, the tapdev has
- received an IP packet that is to be processed by uIP. */
- uip_len = dev_poll();
- for(j=0;j<500;j++);
- /*
- if(uip_len > 0)
- {
- printuf("--------------- uip_len = 0x%x", uip_len);
- printuf("%x ----------\r\n", uip_len);
- for(i=0;i<uip_len;i++)
- {
- printuf("%x ", uip_buf[i]);
- if((i+1)%16==0) printu("\r\n");
- }
- printu("\r\n");
- }
- */
- if(uip_len == 0) {
- for(i = 0; i < UIP_CONNS; i++) {
- uip_periodic(i);
- /* If the above function invocation resulted in data that
- should be sent out on the network, the global variable
- uip_len is set to a value > 0. */
- if(uip_len > 0) {
- uip_arp_out();
- dev_send();
- }
- }
- #if UIP_UDP
- for(i = 0; i < UIP_UDP_CONNS; i++) {
- uip_udp_periodic(i);
- /* If the above function invocation resulted in data that
- should be sent out on the network, the global variable
- uip_len is set to a value > 0. */
- if(uip_len > 0) {
- uip_arp_out();
- dev_send();
- }
- }
- #endif /* UIP_UDP */
-
- /* Call the ARP timer function every 10 seconds. */
- if(++arptimer == 20) {
- uip_arp_timer();
- arptimer = 0;
- }
-
- } else {
- if(BUF->type == htons(UIP_ETHTYPE_IP)) {
- uip_arp_ipin();
- uip_input();
- /* If the above function invocation resulted in data that
- should be sent out on the network, the global variable
- uip_len is set to a value > 0. */
- if(uip_len > 0) {
- uip_arp_out();
- dev_send();
- }
- } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
- uip_arp_arpin();
- /* If the above function invocation resulted in data that
- should be sent out on the network, the global variable
- uip_len is set to a value > 0. */
- if(uip_len > 0) {
- dev_send();
- }
- }
- }
-
- }
- return 0;
- }
- /*-----------------------------------------------------------------------------------*/
- void
- uip_log(char *m)
- {
- // printf("uIP log message: %s\n", m);
- }
- /*-----------------------------------------------------------------------------------*/
复制代码
AVR程序
- /*********************************************
- * vim:sw=8:ts=8:si:et
- * To use the above modeline in vim you must have "set modeline" in your .vimrc
- * Author: Guido Socher
- * Copyright: GPL V2
- * See http://www.gnu.org/licenses/gpl.html
- *
- * Ethernet remote device and sensor
- * UDP and HTTP interface
- url looks like this http://baseurl/password/command
- or http://baseurl/password/
- *
- * Chip type : Atmega88 or Atmega168 with ENC28J60
- * Note: there is a version number in the text. Search for tuxgraphics
- *********************************************/
- #include <avr/io.h>
- #include <stdlib.h>
- #include <string.h>
- #include <avr/pgmspace.h>
- #include "ip_arp_udp_tcp.h"
- #include "enc28j60.h"
- #include "timeout.h"
- #include "avr_compat.h"
- #include "net.h"
- // MAC 地址
- static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
- // IP 地址
- static uint8_t myip[4] = {192,168,1,88};
- // TCP WWW 服务监听端口
- #define MYWWWPORT 80
- // UDP 端口
- #define MYUDPPORT 1200
- #define BUFFER_SIZE 450
- static uint8_t buf[BUFFER_SIZE+1];
- // 下面是一个简单的密码验证
- // 字符串 password 中存放密码
- // 密码只能是 a-z,0-9,下划线,不大于9个字节,仅验证前5个字节
- static char password[]="lcsoft"; // must not be longer than 9 char
- // 验证密码
- uint8_t verify_password(char *str)
- {
- // the first characters of the received string are
- // a simple password/cookie:
- if (strncmp(password,str,5)==0){
- return(1);
- }
- return(0);
- }
- // takes a string of the form password/commandNumber and analyse it
- // return values: -1 invalid password, otherwise command number
- // -2 no command given but password valid
- // -3 valid password, no command and no trailing "/"
- int8_t analyse_get_url(char *str)
- {
- uint8_t loop=1;
- uint8_t i=0;
- while(loop){
- if(password[i]){
- if(*str==password[i]){
- str++;
- i++;
- }else{
- return(-1);
- }
- }else{
- // end of password
- loop=0;
- }
- }
- // is is now one char after the password
- if (*str == '/'){
- str++;
- }else{
- return(-3);
- }
- // check the first char, garbage after this is ignored (including a slash)
- if (*str < 0x3a && *str > 0x2f){
- // is a ASCII number, return it
- return(*str-0x30);
- }
- return(-2);
- }
- // answer HTTP/1.0 301 Moved Permanently\r\nLocation: password/\r\n\r\n
- // to redirect to the url ending in a slash
- uint16_t moved_perm(uint8_t *buf)
- {
- uint16_t plen;
- plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 301 Moved Permanently\r\nLocation: "));
- plen=fill_tcp_data(buf,plen,password);
- plen=fill_tcp_data_p(buf,plen,PSTR("/\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<h1>301 Moved Permanently</h1>\n"));
- plen=fill_tcp_data_p(buf,plen,PSTR("add a trailing slash to the url\n"));
- return(plen);
- }
- // 填充 Web Page
- uint16_t print_webpage(uint8_t *buf,uint8_t on_off)
- {
- uint16_t plen;
- plen=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"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<h1 align=center>LCSOT测试页面</h1><hr>"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<center><p>当前状态: "));
- if (on_off){
- plen=fill_tcp_data_p(buf,plen,PSTR("<font color="#00FF00"> 打开</font>"));
- }else{
- plen=fill_tcp_data_p(buf,plen,PSTR("关闭"));
- }
- plen=fill_tcp_data_p(buf,plen,PSTR(" <small><a href=".">[刷新]</a></small></p>\n<p><a href="."));
- if (on_off){
- plen=fill_tcp_data_p(buf,plen,PSTR("/0">关闭</a><p>"));
- }else{
- plen=fill_tcp_data_p(buf,plen,PSTR("/1">打开</a><p>"));
- }
- plen=fill_tcp_data_p(buf,plen,PSTR("</center><hr><p align=center>详细信息请访问:<a href="http://www.lcsoft.net">http://www.lcsoft.net</a></p>"));
- return(plen);
- }
- int main(void){
- uint16_t plen;
- uint16_t dat_p;
- uint8_t i=0;
- uint8_t cmd_pos=0;
- int8_t cmd;
- uint8_t payloadlen=0;
- char str[30];
- char cmdval;
-
- delay_ms(1);
- /* enable PD2/INT0, as input */
- DDRD&= ~(1<<DDD2);
- /*initialize enc28j60*/
- enc28j60Init(mymac);
- enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
- delay_ms(10);
-
- // LED
- /* enable PB1, LED as output */
- DDRC|= (1<<DDC0);
- /* set output to Vcc, LED off */
- PORTC|= (1<<PC0);
- // the transistor on PD7
- DDRD|= (1<<DDD7);
- PORTD &= ~(1<<PD7);// transistor off
-
- /* 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(20);
-
- /* set output to GND, red LED on */
- PORTC &= ~(1<<PC0);
- 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 ne unequal to 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;
- }
- // led----------
- if (i){
- /* set output to Vcc, LED off */
- PORTC|= (1<<PC0);
- i=0;
- }else{
- /* set output to GND, LED on */
- PORTC &= ~(1<<PC0);
- i=1;
- }
-
- 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){
- 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); // init some data structures
- // 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: http://host_or_ip/password</p>\n"));
- goto SENDTCP;
- }
- cmd=analyse_get_url((char *)&(buf[dat_p+5]));
- // for possible status codes see:
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
- if (cmd==-1){
- plen=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>"));
- goto SENDTCP;
- }
- if (cmd==1){
- PORTD|= (1<<PD7);// transistor on
- }
- if (cmd==0){
- PORTD &= ~(1<<PD7);// transistor off
- }
- if (cmd==-3){
- // redirect to add a trailing slash
- plen=moved_perm(buf);
- goto SENDTCP;
- }
- // if (cmd==-2) or any other value
- // just display the status:
- plen=print_webpage(buf,(PORTD & (1<<PD7)));
- //
- SENDTCP:
- make_tcp_ack_from_any(buf); // send ack for http get
- make_tcp_ack_with_data(buf,plen); // send data
- continue;
- }
- }
- // TCP WWW 部分结束
- // UDP 处理,监听端口 1200 = 0x4B0
- if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0){
- payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
- // you must sent a string starting with v
- // e.g udpcom version 10.0.0.24
- if (verify_password((char *)&(buf[UDP_DATA_P]))){
- // find the first comma which indicates
- // the start of a command:
- cmd_pos=0;
- while(cmd_pos<payloadlen){
- cmd_pos++;
- if (buf[UDP_DATA_P+cmd_pos]==','){
- cmd_pos++; // put on start of cmd
- break;
- }
- }
- // a command is one char and a value. At
- // least 3 characters long. It has an '=' on
- // position 2:
- if (cmd_pos<2 || cmd_pos>payloadlen-3 || buf[UDP_DATA_P+cmd_pos+1]!='='){
- strcpy(str,"e=no_cmd");
- goto ANSWER;
- }
- // supported commands are
- // t=1 t=0 t=?
- if (buf[UDP_DATA_P+cmd_pos]=='t'){
- cmdval=buf[UDP_DATA_P+cmd_pos+2];
- if(cmdval=='1'){
- PORTD|= (1<<PD7);// transistor on
- strcpy(str,"t=1");
- goto ANSWER;
- }else if(cmdval=='0'){
- PORTD &= ~(1<<PD7);// transistor off
- strcpy(str,"t=0");
- goto ANSWER;
- }else if(cmdval=='?'){
- if (PORTD & (1<<PD7)){
- strcpy(str,"t=1");
- goto ANSWER;
- }
- strcpy(str,"t=0");
- goto ANSWER;
- }
- }
- strcpy(str,"e=no_such_cmd");
- goto ANSWER;
- }
- strcpy(str,"e=invalid_pw");
- ANSWER:
- make_udp_reply_from_request(buf,str,strlen(str),MYUDPPORT);
- }
- }
- return (0);
- }
复制代码 LPC C程序
- /*
- * LPC2103开发板测试程序
- *
- * 用途:5110液晶+ENC28J60网络模块测试程序
- *
- */
- #include <stdio.h>
- #include <LPC2103.h>
- #include <string.h>
- #include "ip_arp_udp_tcp.h"
- #include "enc28j60.h"
- #include "net.h"
- #include "PCD5544.h"
- #define LED ( 1 << 17 ) //P0.17控制LED
- #define PSTR(s) s
- extern void delay_ms(unsigned char ms);
- static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
- static uint8_t myip[4] = {192,168,1,88};
- #define MYWWWPORT 80
- #define MYUDPPORT 1200
- #define BUFFER_SIZE 1500
- static uint8_t buf[BUFFER_SIZE+1];
- static char password[]="lcsoft";
-
- uint8_t verify_password(char *str)
- {
- if (strncmp(password,str,5)==0){
- return(1);
- }
- return(0);
- }
- int8_t analyse_get_url(char *str)
- {
- uint8_t loop=1;
- uint8_t i=0;
- while(loop){
- if(password[i]){
- if(*str==password[i]){
- str++;
- i++;
- }else{
- return(-1);
- }
- }else{
- loop=0;
- }
- }
- if (*str == '/'){
- str++;
- }else{
- return(-3);
- }
- if (*str < 0x3a && *str > 0x2f){
- return(*str-0x30);
- }
- return(-2);
- }
- uint16_t moved_perm(uint8_t *buf)
- {
- uint16_t plen;
- plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 301 Moved Permanently\r\nLocation: "));
- plen=fill_tcp_data(buf,plen,password);
- plen=fill_tcp_data_p(buf,plen,PSTR("/\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<h1>301 Moved Permanently</h1>\n"));
- plen=fill_tcp_data_p(buf,plen,PSTR("add a trailing slash to the url\n"));
- return(plen);
- }
- uint16_t print_webpage(uint8_t *buf,uint8_t on_off)
- {
- uint16_t plen;
- plen=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"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<h1 align=center>LCSOFT测试页面</h1><hr>"));
- plen=fill_tcp_data_p(buf,plen,PSTR("<center><p>当前状态: "));
- if (on_off){
- plen=fill_tcp_data_p(buf,plen,PSTR("<font color="#00FF00">开启</font>"));
- }else{
- plen=fill_tcp_data_p(buf,plen,PSTR("关闭"));
- }
- plen=fill_tcp_data_p(buf,plen,PSTR(" <small><a href=".">[刷新]</a></small></p>\n<p><a href="."));
- if (on_off){
- plen=fill_tcp_data_p(buf,plen,PSTR("/0">关闭</a><p>"));
- }else{
- plen=fill_tcp_data_p(buf,plen,PSTR("/1">开启</a><p>"));
- }
- plen=fill_tcp_data_p(buf,plen,PSTR("</center><hr><br><p align=center>更多信息请访问 <a href="http://www.lcsoft.net" target=blank>http://www.lcsoft.net\n"));
- return(plen);
- }
- int main()
- {
- uint16_t plen;
- uint16_t dat_p;
- uint8_t i=0;
- uint8_t cmd_pos=0;
- int8_t cmd;
- uint8_t payloadlen=0;
- char str[30];
- char cmdval;
-
- enc28j60Init(mymac);
- enc28j60clkout(2);
- delay_ms(10);
- IODIR |= LED;
- IOSET = LED;
- enc28j60PhyWrite(PHLCON,0xD76);
- delay_ms(20);
- IOCLR = LED;
- i=1;
- init_ip_arp_udp_tcp(mymac,myip,MYWWWPORT);
- LCD_Init();
- LCD_Cls();
- LCD_GotoXY(0,0);
- LCD_PrintStr("5110+ENC28J60");
- LCD_GotoXY(0,1);
- LCD_PrintStr("Lcsoft(C) 2010");
-
- LCD_GotoXY(0,2);
- LCD_PrintStr("--------------");
- LCD_GotoXY(0,5);
- LCD_PrintStr("--------------");
- for(;;)
- {
- plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
- if(plen==0){
- continue;
- }
- if(eth_type_is_arp_and_my_ip(buf,plen)){
- static int icmpcount = 0;
- char sip[15];
- char sicmp[14];
- sprintf(sip,"%u.%u.%u.%u",buf[ETH_ARP_SRC_IP_P],buf[ETH_ARP_SRC_IP_P+1],buf[ETH_ARP_SRC_IP_P+2],buf[ETH_ARP_SRC_IP_P+3]);
- LCD_GotoXY(0,3);
- LCD_PrintStr((unsigned char*)sip);
- sprintf(sicmp,"Packets:%d",++icmpcount);
- LCD_GotoXY(0,4);
- LCD_PrintStr((unsigned char*)sicmp);
- make_arp_answer_from_request(buf);
- continue;
- }
- if(eth_type_is_ip_and_my_ip(buf,plen)==0){
- continue;
- }
- if (i){
- IOSET = LED;
- i=0;
- }else{
- IOCLR = LED;
- i=1;
- }
-
- if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
- static int icmpcount = 0;
- char sip[15];
- char sicmp[14];
- sprintf(sip,"%u.%u.%u.%u",buf[IP_SRC_P],buf[IP_SRC_P+1],buf[IP_SRC_P+2],buf[IP_SRC_P+3]);
- LCD_GotoXY(0,3);
- LCD_PrintStr((unsigned char*)sip);
- sprintf(sicmp,"Packets:%d",++icmpcount);
- LCD_GotoXY(0,4);
- LCD_PrintStr((unsigned char*)sicmp);
- make_echo_reply_from_request(buf,plen);
- continue;
- }
- if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==MYWWWPORT){
- if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
- make_tcp_synack_from_syn(buf);
- continue;
- }
- if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
- init_len_info(buf);
- dat_p=get_tcp_data_pointer();
- if (dat_p==0){
- if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
- make_tcp_ack_from_any(buf);
- }
- continue;
- }
- if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
- 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: http://host_or_ip/password</p>\n"));
- goto SENDTCP;
- }
- cmd=analyse_get_url((char *)&(buf[dat_p+5]));
- if (cmd==-1){
- plen=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>"));
- goto SENDTCP;
- }
- if (cmd==1){
- IOCLR = LED;
- i = 1;
- LCD_GotoXY(0,4);
- LCD_PrintStr("STATUS:ON ");
- }
- if (cmd==0){
- IOSET = LED;
- i = 0;
- LCD_GotoXY(0,4);
- LCD_PrintStr("STATUS:OFF");
- }
- if (cmd==-3){
- plen=moved_perm(buf);
- goto SENDTCP;
- }
- plen=print_webpage(buf,(i));
- SENDTCP:
- make_tcp_ack_from_any(buf);
- make_tcp_ack_with_data(buf,plen);
- continue;
- }
- }
- if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0){
- payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
- if (verify_password((char *)&(buf[UDP_DATA_P]))){
- cmd_pos=0;
- while(cmd_pos<payloadlen){
- cmd_pos++;
- if (buf[UDP_DATA_P+cmd_pos]==','){
- cmd_pos++;
- break;
- }
- }
- if (cmd_pos<2 || cmd_pos>payloadlen-3 || buf[UDP_DATA_P+cmd_pos+1]!='='){
- strcpy(str,"e=no_cmd");
- goto ANSWER;
- }
- if (buf[UDP_DATA_P+cmd_pos]=='t'){
- cmdval=buf[UDP_DATA_P+cmd_pos+2];
- if(cmdval=='1'){
- IOCLR = LED;
- strcpy(str,"t=1");
- goto ANSWER;
- }else if(cmdval=='0'){
- IOSET = LED;
- strcpy(str,"t=0");
- goto ANSWER;
- }else if(cmdval=='?'){
- if (IOPIN & LED){
- strcpy(str,"t=1");
- goto ANSWER;
- }
- strcpy(str,"t=0");
- goto ANSWER;
- }
- }
- strcpy(str,"e=no_such_cmd");
- goto ANSWER;
- }
- strcpy(str,"e=invalid_pw");
- ANSWER:
- make_udp_reply_from_request(buf,str,strlen(str),MYUDPPORT);
- }
- }
- }
复制代码
程序:
STM32.zip
(474.7 KB, 下载次数: 60)
LPC.zip
(152.74 KB, 下载次数: 27)
AVR.zip
(68.38 KB, 下载次数: 24)
51.zip
(327.35 KB, 下载次数: 65)
原理图:
ENC28J60.pdf
(177.96 KB, 下载次数: 690)
相关资料:
相关资料
|
|