diff -Nru eth_lcd_tcp-2.8/CHANGES ethlcd-0.1-20080813/CHANGES --- eth_lcd_tcp-2.8/CHANGES 1970-01-01 01:00:00.000000000 +0100 +++ ethlcd-0.1-20080813/CHANGES 2008-08-20 10:35:14.000000000 +0200 @@ -0,0 +1 @@ +0.1-20080813 - initial release based on eth_lcd_tcp-2.8.tar.gz diff -Nru eth_lcd_tcp-2.8/ethlcd_proto.h ethlcd-0.1-20080813/ethlcd_proto.h --- eth_lcd_tcp-2.8/ethlcd_proto.h 1970-01-01 01:00:00.000000000 +0100 +++ ethlcd-0.1-20080813/ethlcd_proto.h 2008-08-19 14:45:09.000000000 +0200 @@ -0,0 +1,24 @@ +/* + * ethlcd protocol constants + * + */ + +#ifndef ETHLCD_PROTO_H +#define ETHLCD_PROTO_H + +#define ETHLCD_SEND_INSTR 0x01 +#define ETHLCD_SEND_DATA 0x02 +#define ETHLCD_GET_BUTTONS 0x03 +#define ETHLCD_SET_BACKLIGHT 0x04 +#define ETHLCD_SET_BEEP 0x05 +#define ETHLCD_GET_FIRMWARE_VERSION 0x06 +#define ETHLCD_GET_PROTOCOL_VERSION 0x07 +#define ETHLCD_GET_ENC_REVISION 0x08 +#define ETHLCD_CLOSE_CONN 0x09 +#define ETHLCD_UNRECOGNIZED_COMMAND 0x0A + +#define ETHLCD_BACKLIGHT_ON 0x01 +#define ETHLCD_BACKLIGHT_HALF 0x02 +#define ETHLCD_BACKLIGHT_OFF 0x03 + +#endif //ETHLCD_PROTO_H diff -Nru eth_lcd_tcp-2.8/ip_arp_udp_tcp.c ethlcd-0.1-20080813/ip_arp_udp_tcp.c --- eth_lcd_tcp-2.8/ip_arp_udp_tcp.c 2006-11-26 21:53:57.000000000 +0100 +++ ethlcd-0.1-20080813/ip_arp_udp_tcp.c 2008-08-17 21:23:24.000000000 +0200 @@ -21,7 +21,6 @@ #include "net.h" #include "enc28j60.h" -static uint8_t wwwport=80; static uint8_t macaddr[6]; static uint8_t ipaddr[4]; static int16_t info_hdr_len=0; @@ -93,7 +92,6 @@ // you must call this function once before you use any of the other functions: void init_ip_arp_udp_tcp(uint8_t *mymac,uint8_t *myip,uint8_t wwwp){ uint8_t i=0; - wwwport=wwwp; while(i<4){ ipaddr[i]=myip[i]; i++; @@ -193,7 +191,7 @@ // After calling this function you can fill in the first data byte at TCP_OPTIONS_P+4 // If cp_seq=0 then an initial sequence number is used (should be use in synack) // otherwise it is copied from the packet we received -void make_tcphead(uint8_t *buf,uint16_t rel_ack_num,uint8_t mss,uint8_t cp_seq) +void make_tcphead(uint8_t *buf,uint16_t rel_ack_num,uint8_t mss,uint8_t cp_seq, uint16_t srcport) { uint8_t i=0; uint8_t tseq; @@ -203,7 +201,8 @@ i++; } // set source port (http): - buf[TCP_SRC_PORT_L_P]=wwwport; + buf[TCP_SRC_PORT_H_P]=srcport>>8; + buf[TCP_SRC_PORT_L_P]=srcport & 0xff; i=4; // sequence numbers: // add the rel ack num to SEQACK @@ -327,7 +326,7 @@ enc28j60PacketSend(UDP_HEADER_LEN+IP_HEADER_LEN+ETH_HEADER_LEN+datalen,buf); } -void make_tcp_synack_from_syn(uint8_t *buf) +void make_tcp_synack_from_syn(uint8_t *buf, uint16_t srcport) { uint16_t ck; make_eth(buf); @@ -337,7 +336,7 @@ buf[IP_TOTLEN_L_P]=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4; make_ip(buf); buf[TCP_FLAGS_P]=TCP_FLAGS_SYNACK_V; - make_tcphead(buf,1,1,0); + make_tcphead(buf,1,1,0, srcport); // calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + 4 (one option: mss) ck=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+4,2); buf[TCP_CHECKSUM_H_P]=ck>>8; @@ -359,7 +358,7 @@ } // do some basic length calculations and store the result in static varibales -void init_len_info(uint8_t *buf) +int16_t init_len_info(uint8_t *buf) { info_data_len=(buf[IP_TOTLEN_H_P]<<8)|(buf[IP_TOTLEN_L_P]&0xff); info_data_len-=IP_HEADER_LEN; @@ -368,6 +367,7 @@ if (info_data_len<=0){ info_data_len=0; } + return (info_data_len); } // fill in tcp data at position pos. pos=0 means start of @@ -404,7 +404,7 @@ // Make just an ack packet with no tcp data inside // This will modify the eth/ip/tcp header -void make_tcp_ack_from_any(uint8_t *buf) +void make_tcp_ack_from_any(uint8_t *buf, uint16_t srcport) { uint16_t j; make_eth(buf); @@ -412,9 +412,9 @@ buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V; if (info_data_len==0){ // if there is no data then we must still acknoledge one packet - make_tcphead(buf,1,0,1); // no options + make_tcphead(buf,1,0,1,srcport); // no options }else{ - make_tcphead(buf,info_data_len,0,1); // no options + make_tcphead(buf,info_data_len,0,1,srcport); // no options } // total length field in the IP header must be set: @@ -435,14 +435,16 @@ // You can use this function only immediately after make_tcp_ack_from_any // This is because this function will NOT modify the eth/ip/tcp header except for // length and checksum -void make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen) +void make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen,int fin) { uint16_t j; // fill the header: // This code requires that we send only one data packet // because we keep no state information. We must therefore set // the fin here: - buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V|TCP_FLAGS_FIN_V; + buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V; + if (fin) + buf[TCP_FLAGS_P] |= TCP_FLAGS_FIN_V; // total length field in the IP header must be set: // 20 bytes IP + 20 bytes tcp (when no options) + len of data diff -Nru eth_lcd_tcp-2.8/ip_arp_udp_tcp.h ethlcd-0.1-20080813/ip_arp_udp_tcp.h --- eth_lcd_tcp-2.8/ip_arp_udp_tcp.h 2006-11-26 21:54:19.000000000 +0100 +++ ethlcd-0.1-20080813/ip_arp_udp_tcp.h 2008-08-14 12:20:22.000000000 +0200 @@ -23,13 +23,13 @@ extern void make_udp_reply_from_request(uint8_t *buf,char *data,uint8_t datalen,uint16_t port); -extern void make_tcp_synack_from_syn(uint8_t *buf); -extern void init_len_info(uint8_t *buf); +extern void make_tcp_synack_from_syn(uint8_t *buf, uint16_t srcport); +extern int16_t init_len_info(uint8_t *buf); extern uint16_t get_tcp_data_pointer(void); extern uint16_t fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s); extern uint16_t fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s); -extern void make_tcp_ack_from_any(uint8_t *buf); -extern void make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen); +extern void make_tcp_ack_from_any(uint8_t *buf, uint16_t srcport); +extern void make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen,int fin); #endif /* IP_ARP_UDP_TCP_H */ diff -Nru eth_lcd_tcp-2.8/lcd_hw.h ethlcd-0.1-20080813/lcd_hw.h --- eth_lcd_tcp-2.8/lcd_hw.h 2007-01-22 18:57:24.000000000 +0100 +++ ethlcd-0.1-20080813/lcd_hw.h 2008-08-01 17:01:11.000000000 +0200 @@ -33,7 +33,7 @@ /* normally you do not change the following */ -#define LCD_LINES 2 /* visible lines */ +#define LCD_LINES 4 /* visible lines */ /* no need to change the next 4 lines. This is standard for HD44780 */ #define LCD_START_LINE1 0x00 /* DDRAM address of first char of line 1 */ diff -Nru eth_lcd_tcp-2.8/main.c ethlcd-0.1-20080813/main.c --- eth_lcd_tcp-2.8/main.c 2008-06-06 05:35:27.000000000 +0200 +++ ethlcd-0.1-20080813/main.c 2008-08-19 14:48:58.000000000 +0200 @@ -13,6 +13,11 @@ * * http://tuxgraphics.org/electronics/ * Note: there is a version number in the text. Search for "tuxgraphics" + * + * ethlcd + * (c) 2008 Mariusz Bialonczyk + * http://manio.skyboo.net/ethlcd/ + * *********************************************/ #include #include @@ -24,21 +29,24 @@ #include "avr_compat.h" #include "net.h" #include "lcd.h" +#include "ethlcd_proto.h" // please modify the following two lines. mac and ip have to be unique // in your local area network. You can not have the same numbers in // two devices: -static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x25}; -// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX -static uint8_t myip[4] = {10,0,0,25}; +static uint8_t mymac[6] = {0x00,0x04,0x25,0x54,0x55,0x58}; +// how did I get the mac addr? Translate the last 3 numbers into ascii is: TUX, +// first 3 bytes are Atmel company vendor ID +static uint8_t myip[4] = {10,1,0,7}; // base url (you can put a DNS name instead of an IP addr. if you have // a DNS server (baseurl must end in "/"): -static char baseurl[]="http://10.0.0.25/"; -static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254) -// or on a different port: -//static char baseurl[]="http://10.0.0.24:88/"; -//static uint16_t mywwwport =88; // listen port for tcp/www (max range 1-254) -// +static char baseurl[]="http://10.1.0.7/"; +static uint16_t mywwwport =80; // listen port for tcp/www +static uint16_t mydataport =2425; // listen port for tcp/dataport + +#define FIRMWARE_VERSION "v0.1-20080813" +#define PROTOCOL_VERSION 1 +#define WELCOME_LINE "ethlcd " FIRMWARE_VERSION #define BUFFER_SIZE 750 static uint8_t buf[BUFFER_SIZE+1]; @@ -219,13 +227,27 @@ } +void lcd_send_instr(uint8_t *data, uint16_t len) +{ + int16_t i=0; + for (i=0; i>8) && buf[TCP_DST_PORT_L_P]==(mywwwport&0xFF)){ if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){ - make_tcp_synack_from_syn(buf); + make_tcp_synack_from_syn(buf, mywwwport); // make_tcp_synack_from_syn does already send the syn,ack continue; } @@ -329,7 +341,7 @@ if (dat_p==0){ if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){ // finack, answer with ack - make_tcp_ack_from_any(buf); + make_tcp_ack_from_any(buf, mywwwport); } // just an ack with no data, wait for next packet continue; @@ -358,22 +370,128 @@ goto SENDTCP; } if (cmd==1){ - PORTD|= (1<>8) && buf[TCP_DST_PORT_L_P]==(mydataport&0xFF)){ + if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){ + make_tcp_synack_from_syn(buf, mydataport); + // make_tcp_synack_from_syn does already send the syn,ack + continue; + } + if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){ + dlen=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, mydataport); + } + // just an ack with no data, wait for next packet + continue; + } + switch (buf[dat_p]) //first byte of data is command + { + case ETHLCD_SEND_INSTR: + lcd_send_instr(&(buf[dat_p+1]), dlen-1); + strbuf[0] = ETHLCD_SEND_INSTR; + strbuf[1] = 0; + plen=fill_tcp_data(buf,0,strbuf); + break; + case ETHLCD_SEND_DATA: + lcd_send_data(&(buf[dat_p+1]), dlen-1); + strbuf[0] = ETHLCD_SEND_DATA; + strbuf[1] = 0; + plen=fill_tcp_data(buf,0,strbuf); + break; + case ETHLCD_GET_BUTTONS: + strbuf[0] = ETHLCD_GET_BUTTONS; + strbuf[1] = (PINC & 0x3E) | ((PINB & 1<<1) >> 1); + strbuf[2] = 0; + plen=fill_tcp_data(buf,0,strbuf); + break; + case ETHLCD_SET_BACKLIGHT: //set the backlight + if (buf[dat_p+1]==ETHLCD_BACKLIGHT_ON) + { + DDRB |= (1< diff -Nru eth_lcd_tcp-2.8/test0.c ethlcd-0.1-20080813/test0.c --- eth_lcd_tcp-2.8/test0.c 2007-02-11 19:31:18.000000000 +0100 +++ ethlcd-0.1-20080813/test0.c 2008-08-17 20:34:56.000000000 +0200 @@ -38,15 +38,18 @@ //CLKPR=((1<