diff -u --recursive --new-file etherShield/Ethernet.cpp.cpp arduino-0016/hardware/libraries/Ethernet/Ethernet.cpp.cpp --- etherShield/Ethernet.cpp.cpp 1970-01-01 01:00:00.000000000 +0100 +++ arduino-0016/hardware/libraries/Ethernet/Ethernet.cpp.cpp 2009-07-30 22:56:24.947639800 +0200 @@ -0,0 +1,116 @@ +/* + Ethernet library for Arduino ethernet shield + + Copyright (c) 2008 Flamingo EDA. All right reserved. + http://www.flamingoeda.com + flamingoeda@gmail.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT EthernetANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +extern "C" { + #include "enc28j60.h" + #include "ip_arp_udp_tcp.h" + +} +#include "Ethernet.h" + +//constructor +Ethernet::Ethernet(){ +} + +uint16_t Ethernet::E_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s){ + return fill_tcp_data_p(buf, pos, progmem_s); +} + +uint16_t Ethernet::E_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s){ + return fill_tcp_data(buf,pos, s); +} + + +void Ethernet::E_enc28j60Init(uint8_t* macaddr){ + enc28j60Init(macaddr); + +} +void Ethernet::E_enc28j60clkout(uint8_t clk){ + enc28j60clkout(clk); +} + +void Ethernet::E_enc28j60PhyWrite(uint8_t address, uint16_t data){ + enc28j60PhyWrite(address, data); +} + +uint16_t Ethernet::E_enc28j60PacketReceive(uint16_t len, uint8_t* packet){ + return enc28j60PacketReceive(len, packet); +} + + +void Ethernet::E_init_ip_arp_udp_tcp(uint8_t *mymac,uint8_t *myip,uint8_t wwwp){ + init_ip_arp_udp_tcp(mymac,myip,wwwp); +} + +uint8_t Ethernet::E_eth_type_is_arp_and_my_ip(uint8_t *buf,uint16_t len){ + return eth_type_is_arp_and_my_ip(buf,len); +} + +void Ethernet::E_make_arp_answer_from_request(uint8_t *buf){ + make_arp_answer_from_request(buf); +} + +void Ethernet::E_make_arp_magicpacket(uint8_t *buf, uint8_t *dstmacaddr){ + make_arp_magicpacket(buf , dstmacaddr); +} + +uint8_t Ethernet::E_eth_type_is_ip_and_my_ip(uint8_t *buf,uint16_t len){ + return eth_type_is_ip_and_my_ip(buf, len); +} + + +void Ethernet::E_make_echo_reply_from_request(uint8_t *buf,uint16_t len){ + make_echo_reply_from_request(buf,len); +} + +void Ethernet::E_make_tcp_synack_from_syn(uint8_t *buf){ + make_tcp_synack_from_syn(buf); +} + +void Ethernet::E_init_len_info(uint8_t *buf){ + init_len_info(buf); +} + +uint16_t Ethernet::E_get_tcp_data_pointer(void){ + return get_tcp_data_pointer(); +} + +void Ethernet::E_make_tcp_ack_from_any(uint8_t *buf){ + make_tcp_ack_from_any(buf); +} + +void Ethernet::E_make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen){ + make_tcp_ack_with_data(buf,dlen); +} + + + + + + + + + + + + + diff -u --recursive --new-file etherShield/Ethernet.h arduino-0016/hardware/libraries/Ethernet/Ethernet.h --- etherShield/Ethernet.h 1970-01-01 01:00:00.000000000 +0100 +++ arduino-0016/hardware/libraries/Ethernet/Ethernet.h 2009-07-30 22:56:35.294889573 +0200 @@ -0,0 +1,58 @@ +/* + Ethernet library for Arduino ethernet shield + + Copyright (c) 2008 Flamingo EDA. All right reserved. + http://www.flamingoeda.com + flamingoeda@gmail.com + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT EthernetANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#ifndef ETHERNET_H +#define ETHERNET_H + +#include +#include "enc28j60.h" +#include "ip_arp_udp_tcp.h" +#include "net.h" + + +class Ethernet +{ + public: + + Ethernet(); + uint16_t E_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s); + uint16_t E_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s); + void E_enc28j60Init(uint8_t* macaddr); + void E_enc28j60clkout(uint8_t clk); + void E_enc28j60PhyWrite(uint8_t address, uint16_t data); + uint16_t E_enc28j60PacketReceive(uint16_t len, uint8_t* packet); + void E_init_ip_arp_udp_tcp(uint8_t *mymac,uint8_t *myip,uint8_t wwwp); + uint8_t E_eth_type_is_arp_and_my_ip(uint8_t *buf,uint16_t len); + void E_make_arp_answer_from_request(uint8_t *buf); + void E_make_arp_magicpacket(uint8_t *buf, uint8_t *dstmacaddr); + uint8_t E_eth_type_is_ip_and_my_ip(uint8_t *buf,uint16_t len); + void E_make_echo_reply_from_request(uint8_t *buf,uint16_t len); + void E_make_tcp_synack_from_syn(uint8_t *buf); + void E_init_len_info(uint8_t *buf); + uint16_t E_get_tcp_data_pointer(void); + void E_make_tcp_ack_from_any(uint8_t *buf); + void E_make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen); +}; + +#endif + diff -u --recursive --new-file etherShield/etherShield.cpp arduino-0016/hardware/libraries/Ethernet/etherShield.cpp --- etherShield/etherShield.cpp 2008-08-15 16:47:26.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/etherShield.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,109 +0,0 @@ -// a wrapper class for EtherShield - -extern "C" { - #include "enc28j60.h" - #include "ip_arp_udp_tcp.h" - -} -#include "EtherShield.h" - -//constructor -EtherShield::EtherShield(){ -} - -uint16_t EtherShield::ES_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s){ - return fill_tcp_data_p(buf, pos, progmem_s); -} - -uint16_t EtherShield::ES_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s){ - return fill_tcp_data(buf,pos, s); -} - - -void EtherShield::ES_enc28j60Init(uint8_t* macaddr){ - enc28j60Init(macaddr); - -} -void EtherShield::ES_enc28j60clkout(uint8_t clk){ - enc28j60clkout(clk); -} - -void EtherShield::ES_enc28j60PhyWrite(uint8_t address, uint16_t data){ - enc28j60PhyWrite(address, data); -} - -uint16_t EtherShield::ES_enc28j60PacketReceive(uint16_t len, uint8_t* packet){ - return enc28j60PacketReceive(len, packet); -} - - -void EtherShield::ES_init_ip_arp_udp_tcp(uint8_t *mymac,uint8_t *myip,uint8_t wwwp){ - init_ip_arp_udp_tcp(mymac,myip,wwwp); -} - -uint8_t EtherShield::ES_eth_type_is_arp_and_my_ip(uint8_t *buf,uint16_t len){ - return eth_type_is_arp_and_my_ip(buf,len); -} - -void EtherShield::ES_make_arp_answer_from_request(uint8_t *buf){ - make_arp_answer_from_request(buf); -} - -uint8_t EtherShield::ES_eth_type_is_ip_and_my_ip(uint8_t *buf,uint16_t len){ - return eth_type_is_ip_and_my_ip(buf, len); -} - - -void EtherShield::ES_make_echo_reply_from_request(uint8_t *buf,uint16_t len){ - make_echo_reply_from_request(buf,len); -} - -void EtherShield::ES_make_tcp_synack_from_syn(uint8_t *buf){ - make_tcp_synack_from_syn(buf); -} - -void EtherShield::ES_init_len_info(uint8_t *buf){ - init_len_info(buf); -} - -uint16_t EtherShield::ES_get_tcp_data_pointer(void){ - return get_tcp_data_pointer(); -} - -void EtherShield::ES_make_tcp_ack_from_any(uint8_t *buf){ - make_tcp_ack_from_any(buf); -} - -void EtherShield::ES_make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen){ - make_tcp_ack_with_data(buf,dlen); -} - -void EtherShield::ES_make_arp_request(uint8_t *buf, uint8_t *server_ip){ - make_arp_request(buf, server_ip); -} - -uint8_t EtherShield::ES_arp_packet_is_myreply_arp ( uint8_t *buf ){ - return arp_packet_is_myreply_arp (buf); -} - -void EtherShield::ES_tcp_client_send_packet(uint8_t *buf,uint16_t dest_port, uint16_t src_port, uint8_t flags, uint8_t max_segment_size, - uint8_t clear_seqck, uint16_t next_ack_num, uint16_t dlength, uint8_t *dest_mac, uint8_t *dest_ip){ - - tcp_client_send_packet(buf, dest_port, src_port, flags, max_segment_size, clear_seqck, next_ack_num, dlength,dest_mac,dest_ip); -} - -uint16_t EtherShield::ES_tcp_get_dlength( uint8_t *buf ){ - return tcp_get_dlength(buf); -} - - - - - - - - - - - - diff -u --recursive --new-file etherShield/etherShield.h arduino-0016/hardware/libraries/Ethernet/etherShield.h --- etherShield/etherShield.h 2008-08-15 16:46:58.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/etherShield.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,61 +0,0 @@ -/* - EHTERSHIELD_H library for Arduino etherShield - Copyright (c) 2008 Xing Yu. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ETHERSHIELD_H -#define ETHERSHIELD_H - -#include -#include "enc28j60.h" -#include "ip_arp_udp_tcp.h" -#include "net.h" - - -class EtherShield -{ - public: - - EtherShield(); - uint16_t ES_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s); - uint16_t ES_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s); - void ES_enc28j60Init(uint8_t* macaddr); - void ES_enc28j60clkout(uint8_t clk); - void ES_enc28j60PhyWrite(uint8_t address, uint16_t data); - uint16_t ES_enc28j60PacketReceive(uint16_t len, uint8_t* packet); - void ES_init_ip_arp_udp_tcp(uint8_t *mymac,uint8_t *myip,uint8_t wwwp); - uint8_t ES_eth_type_is_arp_and_my_ip(uint8_t *buf,uint16_t len); - void ES_make_arp_answer_from_request(uint8_t *buf); - uint8_t ES_eth_type_is_ip_and_my_ip(uint8_t *buf,uint16_t len); - void ES_make_echo_reply_from_request(uint8_t *buf,uint16_t len); - void ES_make_tcp_synack_from_syn(uint8_t *buf); - void ES_init_len_info(uint8_t *buf); - uint16_t ES_get_tcp_data_pointer(void); - void ES_make_tcp_ack_from_any(uint8_t *buf); - void ES_make_tcp_ack_with_data(uint8_t *buf,uint16_t dlen); - - // new web client functions - void ES_make_arp_request(uint8_t *buf, uint8_t *server_ip); - uint8_t ES_arp_packet_is_myreply_arp ( uint8_t *buf ); - void ES_tcp_client_send_packet(uint8_t *buf,uint16_t dest_port, uint16_t src_port, uint8_t flags, uint8_t max_segment_size, - uint8_t clear_seqck, uint16_t next_ack_num, uint16_t dlength, uint8_t *dest_mac, uint8_t *dest_ip); - uint16_t ES_tcp_get_dlength( uint8_t *buf ); - -}; - -#endif - diff -u --recursive --new-file etherShield/examples/etherShield_client/etherShield_client.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_client/etherShield_client.pde --- etherShield/examples/etherShield_client/etherShield_client.pde 2008-08-20 05:01:26.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_client/etherShield_client.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,411 +0,0 @@ -#include "etherShield.h" - -// please modify the following 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,0x24}; -static uint8_t myip[4] = {192,168,1,88}; -static uint16_t my_port = 1200; // client port - -// client_ip - modify it when you have multiple client on the network -// for server to distinguish each ethershield client -static char client_ip[] = "192.168.1.88"; - -// server settings - modify the service ip to your own server -static uint8_t dest_ip[4]={192,168,1,4}; -static uint8_t dest_mac[6]; - -enum CLIENT_STATE -{ - IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT - }; - -static CLIENT_STATE client_state; - -static uint8_t client_data_ready; - -static uint8_t syn_ack_timeout = 0; - - -#define BUFFER_SIZE 500 -static uint8_t buf[BUFFER_SIZE+1]; - -char sensorData[10]; - -EtherShield es=EtherShield(); - -// prepare the webpage by writing the data to the tcp send buffer -uint16_t print_webpage(uint8_t *buf); -int8_t analyse_cmd(char *str); -// get current temperature -#define TEMP_PIN 3 -void getCurrentTemp( char *temperature); -void client_process(void); - -void setup(){ - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=greed LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - // intialize varible; - syn_ack_timeout =0; - client_data_ready = 0; - client_state = IDLE; - // initialize DS18B20 datapin - digitalWrite(TEMP_PIN, LOW); - pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1) - - -} - -void loop(){ - - if(client_data_ready==0){ - delay(60000UL); // delay 60s - getCurrentTemp(sensorData); - client_data_ready = 1; - } - client_process(); - -} - -uint16_t gen_client_request(uint8_t *buf ) -{ - uint16_t plen; - byte i; - - plen= es.ES_fill_tcp_data_p(buf,0, PSTR ( "GET /ethershield_log/save.php?pwd=secret&client=" ) ); - for(i=0; client_ip[i]!='\0'; i++){ - buf[TCP_DATA_P+plen]=client_ip[i]; - plen++; - } - plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=temperature-" ) ); - for(i=0; sensorData[i]!='\0'; i++){ - - buf[TCP_DATA_P+plen]=sensorData[i]; - plen++; - } - - - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( " HTTP/1.0\r\n" )); - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Host: 192.168.1.4\r\n" )); - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "User-Agent: AVR ethernet\r\n" )); - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Accept: text/html\r\n" )); - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Keep-Alive: 300\r\n" )); - plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Connection: keep-alive\r\n\r\n" )); - - return plen; -} - -//***************************************************************************************** -// -// Function : client_process -// Description : send temparature to web server, this option is disabled by default. -// YOU MUST install webserver and server script before enable this option, -// I recommented Apache webserver and PHP script. -// More detail about Apache and PHP installation please visit http://www.avrportal.com/ -// -//***************************************************************************************** -void client_process ( void ) -{ - uint16_t plen; - uint8_t i; - - if (client_data_ready == 0) return; // nothing to send - - if(client_state == IDLE){ // initialize ARP - es.ES_make_arp_request(buf, dest_ip); - - client_state = ARP_SENT; - return; - } - - - if(client_state == ARP_SENT){ - - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - // destination ip address was found on network - if ( plen!=0 ) - { - if ( es.ES_arp_packet_is_myreply_arp ( buf ) ){ - client_state = ARP_REPLY; - syn_ack_timeout=0; - return; - } - - } - delay(10); - syn_ack_timeout++; - - - if(syn_ack_timeout== 100) { //timeout, server ip not found - client_state = IDLE; - client_data_ready =0; - syn_ack_timeout=0; - return; - } - } - - - - // send SYN packet to initial connection - if(client_state == ARP_REPLY){ - // save dest mac - for(i=0; i<6; i++){ - dest_mac[i] = buf[ETH_SRC_MAC+i]; - } - - es.ES_tcp_client_send_packet ( - buf, - 80, - 1200, - TCP_FLAG_SYN_V, // flag - 1, // (bool)maximum segment size - 1, // (bool)clear sequence ack number - 0, // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data - 0, // tcp data length - dest_mac, - dest_ip - ); - - client_state = SYNC_SENT; - } - // get new packet - if(client_state == SYNC_SENT){ - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - // no new packet incoming - if ( plen == 0 ) - { - return; - } - - // check ip packet send to avr or not? - // accept ip packet only - if ( es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){ - return; - } - - // check SYNACK flag, after AVR send SYN server response by send SYNACK to AVR - if ( buf [ TCP_FLAGS_P ] == ( TCP_FLAG_SYN_V | TCP_FLAG_ACK_V ) ) - { - - // send ACK to answer SYNACK - - es.ES_tcp_client_send_packet ( - buf, - 80, - 1200, - TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 1, // 0=use old seq, seqack : 1=new seq,seqack no data : new seq,seqack with data - 0, // tcp data length - dest_mac, - dest_ip - ); - // setup http request to server - plen = gen_client_request( buf ); - // send http request packet - // send packet with PSHACK - es.ES_tcp_client_send_packet ( - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_ACK_V | TCP_FLAG_PUSH_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - plen, // tcp data length - dest_mac, - dest_ip - ); - return; - } - // after AVR send http request to server, server response by send data with PSHACK to AVR - // AVR answer by send ACK and FINACK to server - if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PUSH_V) ) - { - plen = es.ES_tcp_get_dlength( (uint8_t*)&buf ); - - // send ACK to answer PSHACK from server - es.ES_tcp_client_send_packet ( - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - plen, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, // tcp data length - dest_mac, - dest_ip - );; - // send finack to disconnect from web server - - es.ES_tcp_client_send_packet ( - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_FIN_V|TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, - dest_mac, - dest_ip - ); - - return; - - } - // answer FINACK from web server by send ACK to web server - if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_FIN_V) ) - { - // send ACK with seqack = 1 - es.ES_tcp_client_send_packet( - - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, - dest_mac, - dest_ip - ); - client_state = IDLE; // return to IDLE state - client_data_ready =0; // client data sent - } - } -} - -void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse -{ - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); // bring low for 500 us - delayMicroseconds(500); - pinMode(Pin, INPUT); - delayMicroseconds(500); -} - -void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first). -{ - byte n; - - for(n=8; n!=0; n--) - { - if ((d & 0x01) == 1) // test least sig bit - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(5); - pinMode(Pin, INPUT); - delayMicroseconds(60); - } - else - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(60); - pinMode(Pin, INPUT); - } - - d=d>>1; // now the next bit is in the least sig bit position. - } - -} - -byte OneWireInByte(int Pin) // read byte, least sig byte first -{ - byte d, n, b; - - for (n=0; n<8; n++) - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(5); - pinMode(Pin, INPUT); - delayMicroseconds(5); - b = digitalRead(Pin); - delayMicroseconds(50); - d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position - } - return(d); -} - - -void getCurrentTemp(char *temp) -{ - int HighByte, LowByte, TReading, Tc_100, sign, whole, fract; - - OneWireReset(TEMP_PIN); - OneWireOutByte(TEMP_PIN, 0xcc); - OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec - - OneWireReset(TEMP_PIN); - OneWireOutByte(TEMP_PIN, 0xcc); - OneWireOutByte(TEMP_PIN, 0xbe); - - LowByte = OneWireInByte(TEMP_PIN); - HighByte = OneWireInByte(TEMP_PIN); - TReading = (HighByte << 8) + LowByte; - sign = TReading & 0x8000; // test most sig bit - if (sign) // negative - { - TReading = (TReading ^ 0xffff) + 1; // 2's comp - } - Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 - - whole = Tc_100 / 100; // separate off the whole and fractional portions - fract = Tc_100 % 100; - - if(sign) temp[0]='-'; - else temp[0]='+'; - - - temp[1]= (whole-(whole/100)*100)/10 +'0' ; - temp[2]= whole-(whole/10)*10 +'0'; - - temp[3]='.'; - temp[4]=fract/10 +'0'; - temp[5]=fract-(fract/10)*10 +'0'; - - temp[6] = '\0'; -} diff -u --recursive --new-file etherShield/examples/etherShield_client1/etherShield_client1.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_client1/etherShield_client1.pde --- etherShield/examples/etherShield_client1/etherShield_client1.pde 2008-08-20 08:21:18.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_client1/etherShield_client1.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,333 +0,0 @@ -#include "etherShield.h" -/*infrared sensor setting*/ -#define INFRARED_IN 3 -#define LED_STATUS 5 -#define ENABLE_EXTERNAL1_INTERRUPT() ( EIMSK |= ( 1<< INT1 ) ) -#define DISABLE_EXTERNAL1_INTERRUPT() ( EIMSK &= ~( 1<< INT1 ) ) - -// please modify the following 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,0x33}; -static uint8_t myip[4] = {192,168,1,89}; -static uint16_t my_port = 1200; // client port - -// client_ip - modify it when you have multiple client on the network -// for server to distinguish each ethershield client -static char client_ip[] = "192.168.1.89"; - -// server settings - modify the service ip to your own server -static uint8_t dest_ip[4]={192,168,1,4}; -static uint8_t dest_mac[6]; - -enum CLIENT_STATE -{ - IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT - }; - -static CLIENT_STATE client_state; - -static uint8_t client_data_ready; - -static uint8_t syn_ack_timeout = 0; - - -#define BUFFER_SIZE 500 -static uint8_t buf[BUFFER_SIZE+1]; - - - -EtherShield es=EtherShield(); - - -void setup(){ - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=greed LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - // intialize varible; - syn_ack_timeout =0; - client_data_ready = 0; - client_state = IDLE; - - // infrared sensor initialization - pinMode(LED_STATUS, OUTPUT); // infrad - digitalWrite(LED_STATUS,LOW); - - - pinMode(INFRARED_IN, INPUT); - - - ENABLE_EXTERNAL1_INTERRUPT(); - // tigger at INT1 rising edge - EICRA = 0x0c; - - - SREG|=1<1 new seq,seqack with data - plen, // tcp data length - dest_mac, - dest_ip - ); - return; - } - // after AVR send http request to server, server response by send data with PSHACK to AVR - // AVR answer by send ACK and FINACK to server - if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_PUSH_V) ) - { - plen = es.ES_tcp_get_dlength( (uint8_t*)&buf ); - - // send ACK to answer PSHACK from server - es.ES_tcp_client_send_packet ( - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - plen, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, // tcp data length - dest_mac, - dest_ip - );; - // send finack to disconnect from web server - - es.ES_tcp_client_send_packet ( - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_FIN_V|TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 0, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, - dest_mac, - dest_ip - ); - - return; - - } - // answer FINACK from web server by send ACK to web server - if ( buf [ TCP_FLAGS_P ] == (TCP_FLAG_ACK_V|TCP_FLAG_FIN_V) ) - { - // send ACK with seqack = 1 - es.ES_tcp_client_send_packet( - - buf, - 80, // destination port - 1200, // source port - TCP_FLAG_ACK_V, // flag - 0, // (bool)maximum segment size - 0, // (bool)clear sequence ack number - 1, // 0=use old seq, seqack : 1=new seq,seqack no data : >1 new seq,seqack with data - 0, - dest_mac, - dest_ip - ); - client_state = IDLE; // return to IDLE state - client_data_ready =0; // client data sent - } - } -} - diff -u --recursive --new-file etherShield/examples/etherShield_ping/etherShield_ping.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_ping/etherShield_ping.pde --- etherShield/examples/etherShield_ping/etherShield_ping.pde 2008-01-30 03:07:10.000000000 +0100 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_ping/etherShield_ping.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,87 +0,0 @@ -#include "etherShield.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,0x24}; -static uint8_t myip[4] = { - 192,168,1,15}; -// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX - -#define BUFFER_SIZE 250 -unsigned char buf[BUFFER_SIZE+1]; - -uint16_t plen; - -EtherShield es=EtherShield(); - - -void setup(){ - - - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=green LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - -} - -void loop(){ - - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - /*plen will be unequal to zero if there is a valid packet (without crc error) */ - if(plen!=0){ - if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){ - es.ES_make_arp_answer_from_request(buf); - } - // check if ip packets (icmp or udp) are for us: - if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)!=0){ - if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){ - // a ping packet, let's send pong - - es.ES_make_echo_reply_from_request(buf,plen); - } - } - - } -} diff -u --recursive --new-file etherShield/examples/etherShield_ping/Makefile arduino-0016/hardware/libraries/Ethernet/examples/etherShield_ping/Makefile --- etherShield/examples/etherShield_ping/Makefile 2008-01-27 20:22:28.000000000 +0100 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_ping/Makefile 1970-01-01 01:00:00.000000000 +0100 @@ -1,239 +0,0 @@ -# Arduino makefile -# -# This makefile allows you to build sketches from the command line -# without the Arduino environment (or Java). -# -# The Arduino environment does preliminary processing on a sketch before -# compiling it. If you're using this makefile instead, you'll need to do -# a few things differently: -# -# - Give your program's file a .cpp extension (e.g. foo.cpp). -# -# - Put this line at top of your code: #include -# -# - Write prototypes for all your functions (or define them before you -# call them). A prototype declares the types of parameters a -# function will take and what type of value it will return. This -# means that you can have a call to a function before the definition -# of the function. A function prototype looks like the first line of -# the function, with a semi-colon at the end. For example: -# int digitalRead(int pin); -# -# - Write a main() function for your program that returns an int, calls -# init() and setup() once (in that order), and then calls loop() -# repeatedly(): -# -# int main() -# { -# init(); -# setup(); -# -# for (;;) -# loop(); -# -# return 0; -# } -# -# Instructions for using the makefile: -# -# 1. Copy this file into the folder with your sketch. -# -# 2. Below, modify the line containing "TARGET" to refer to the name of -# of your program's file without an extension (e.g. TARGET = foo). -# -# 3. Modify the line containg "ARDUINO" to point the directory that -# contains the Arduino core (for normal Arduino installations, this -# is the hardware/cores/arduino sub-directory). -# -# 4. Modify the line containing "PORT" to refer to the filename -# representing the USB or serial connection to your Arduino board -# (e.g. PORT = /dev/tty.USB0). If the exact name of this file -# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*). -# -# 5. At the command line, change to the directory containing your -# program's file and the makefile. -# -# 6. Type "make" and press enter to compile/verify your program. -# -# 7. Type "make upload", reset your Arduino board, and press enter to -# upload your program to the Arduino board. -# -# $Id$ - -PORT = /dev/tty.usbserial* -TARGET = foo -ARDUINO = arduino -SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \ -$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \ -$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \ -$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c -CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WRandom.cpp -MCU = atmega168 -F_CPU = 16000000 -FORMAT = ihex -UPLOAD_RATE = 19200 - -# Name of this Makefile (used for "make depend"). -MAKEFILE = Makefile - -# Debugging format. -# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. -# AVR (extended) COFF requires stabs, plus an avr-objcopy run. -DEBUG = stabs - -OPT = s - -# Place -D or -U options here -CDEFS = -DF_CPU=$(F_CPU) -CXXDEFS = -DF_CPU=$(F_CPU) - -# Place -I options here -CINCS = -I$(ARDUINO) -CXXINCS = -I$(ARDUINO) - -# Compiler flag to set the C Standard level. -# c89 - "ANSI" C -# gnu89 - c89 plus GCC extensions -# c99 - ISO C99 standard (not yet fully implemented) -# gnu99 - c99 plus GCC extensions -CSTANDARD = -std=gnu99 -CDEBUG = -g$(DEBUG) -CWARN = -Wall -Wstrict-prototypes -CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -#CEXTRA = -Wa,-adhlns=$(<:.c=.lst) - -CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) -CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT) -#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs -LDFLAGS = -lm - - -# Programming support using avrdude. Settings and variables. -AVRDUDE_PROGRAMMER = stk500 -AVRDUDE_PORT = $(PORT) -AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex -AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \ - -b $(UPLOAD_RATE) - -# Program settings -CC = avr-gcc -CXX = avr-g++ -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump -AR = avr-ar -SIZE = avr-size -NM = avr-nm -AVRDUDE = avrdude -REMOVE = rm -f -MV = mv -f - -# Define all object files. -OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o) - -# Define all listing files. -LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst) - -# Combine all necessary flags and optional flags. -# Add target processor to flags. -ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) -ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS) -ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) - - -# Default target. -all: build - -build: elf hex - -elf: $(TARGET).elf -hex: $(TARGET).hex -eep: $(TARGET).eep -lss: $(TARGET).lss -sym: $(TARGET).sym - -# Program the device. -upload: $(TARGET).hex - $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) - - - - -# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. -COFFCONVERT=$(OBJCOPY) --debugging \ ---change-section-address .data-0x800000 \ ---change-section-address .bss-0x800000 \ ---change-section-address .noinit-0x800000 \ ---change-section-address .eeprom-0x810000 - - -coff: $(TARGET).elf - $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof - - -extcoff: $(TARGET).elf - $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof - - -.SUFFIXES: .elf .hex .eep .lss .sym - -.elf.hex: - $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ - -.elf.eep: - -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ - --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ - -# Create extended listing file from ELF output file. -.elf.lss: - $(OBJDUMP) -h -S $< > $@ - -# Create a symbol table from ELF output file. -.elf.sym: - $(NM) -n $< > $@ - - -core.a: $(OBJ) - @for i in $(OBJ); do echo $(AR) rcs core.a $$i; $(AR) rcs core.a $$i; done - -# Link: create ELF output file from library. -$(TARGET).elf: core.a - $(CC) $(ALL_CFLAGS) -o $@ $(TARGET).cpp -L. core.a $(LDFLAGS) -Map=$(TARGET).map - -# Compile: create object files from C++ source files. -.cpp.o: - $(CXX) -c $(ALL_CXXFLAGS) $< -o $@ - -# Compile: create object files from C source files. -.c.o: - $(CC) -c $(ALL_CFLAGS) $< -o $@ - - -# Compile: create assembler files from C source files. -.c.s: - $(CC) -S $(ALL_CFLAGS) $< -o $@ - - -# Assemble: create object files from assembler source files. -.S.o: - $(CC) -c $(ALL_ASFLAGS) $< -o $@ - - - -# Target: clean project. -clean: - $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \ - $(TARGET).map $(TARGET).sym $(TARGET).lss core.a \ - $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d) - -depend: - if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ - then \ - sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ - $(MAKEFILE).$$$$ && \ - $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ - fi - echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ - >> $(MAKEFILE); \ - $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) - -.PHONY: all build elf hex eep lss sym program coff extcoff clean depend diff -u --recursive --new-file etherShield/examples/etherShield_webserver/ethershield_webserver.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_webserver/ethershield_webserver.pde --- etherShield/examples/etherShield_webserver/ethershield_webserver.pde 2008-03-18 03:03:44.000000000 +0100 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_webserver/ethershield_webserver.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,187 +0,0 @@ -#include "etherShield.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,0x24}; -static uint8_t myip[4] = {192,168,1,15}; -static char baseurl[]="http://192.168.1.15/"; -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) -// - -#define BUFFER_SIZE 500 -static uint8_t buf[BUFFER_SIZE+1]; -#define STR_BUFFER_SIZE 22 -static char strbuf[STR_BUFFER_SIZE+1]; - -EtherShield es=EtherShield(); - -// prepare the webpage by writing the data to the tcp send buffer -uint16_t print_webpage(uint8_t *buf); -int8_t analyse_cmd(char *str); -void setup(){ - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=greed LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - -} - -void loop(){ - uint16_t plen, dat_p; - int8_t cmd; - - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - /*plen will ne unequal to zero if there is a valid packet (without crc error) */ - if(plen!=0){ - - // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address. - if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){ - es.ES_make_arp_answer_from_request(buf); - return; - } - - // check if ip packets are for us: - if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){ - return; - } - - if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){ - es.ES_make_echo_reply_from_request(buf,plen); - return; - } - - // 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){ - es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack - return; - } - if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){ - es.ES_init_len_info(buf); // init some data structures - dat_p=es.ES_get_tcp_data_pointer(); - if (dat_p==0){ // we can possibly have no data, just ack: - if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){ - es.ES_make_tcp_ack_from_any(buf); - } - return; - } - 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=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

200 OK

")); - goto SENDTCP; - } - if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){ - plen=print_webpage(buf); - goto SENDTCP; - } - cmd=analyse_cmd((char *)&(buf[dat_p+5])); - if (cmd==1){ - plen=print_webpage(buf); - } -SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get - es.ES_make_tcp_ack_with_data(buf,plen); // send data - } - } - } - -} -// The returned value is stored in the global var strbuf -uint8_t find_key_val(char *str,char *key) -{ - uint8_t found=0; - uint8_t i=0; - char *kp; - kp=key; - while(*str && *str!=' ' && found==0){ - if (*str == *kp){ - kp++; - if (*kp == '\0'){ - str++; - kp=key; - if (*str == '='){ - found=1; - } - } - }else{ - kp=key; - } - str++; - } - if (found==1){ - // copy the value to a buffer and terminate it with '\0' - while(*str && *str!=' ' && *str!='&' && i 0x2f){ - // is a ASCII number, return it - r=(*strbuf-0x30); - } - } - return r; -} - - -uint16_t print_webpage(uint8_t *buf) -{ - uint16_t plen; - plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

Welcome to Arduino Ethernet Shield V1.0

")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

-- Put your ARDUINO online -- ")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
Control digital outputs ")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
Read digital analog inputs HERE ")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

") ); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

V1.0 www.nuelectronics.com")); - - return(plen); - } \ Kein Zeilenumbruch am Dateiende. diff -u --recursive --new-file etherShield/examples/etherShield_web_switch/etherShield_web_switch.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_web_switch/etherShield_web_switch.pde --- etherShield/examples/etherShield_web_switch/etherShield_web_switch.pde 2008-07-04 07:12:02.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_web_switch/etherShield_web_switch.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,229 +0,0 @@ -#include "etherShield.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,0x24}; -static uint8_t myip[4] = {192,168,1,15}; -static char baseurl[]="http://192.168.1.15/"; -static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254) - - - -#define BUFFER_SIZE 500 -static uint8_t buf[BUFFER_SIZE+1]; -#define STR_BUFFER_SIZE 22 -static char strbuf[STR_BUFFER_SIZE+1]; - -EtherShield es=EtherShield(); - -// prepare the webpage by writing the data to the tcp send buffer -uint16_t print_webpage(uint8_t *buf, byte on_off); -int8_t analyse_cmd(char *str); - -// LED cathode connects the Pin4, anode to 5V through 1K resistor -#define LED_PIN 4 - - -void setup(){ - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=greed LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - pinMode(LED_PIN, OUTPUT); - digitalWrite(LED_PIN, LOW); // switch on LED -} - -void loop(){ - uint16_t plen, dat_p; - int8_t cmd; - byte on_off = 1; - - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - /*plen will ne unequal to zero if there is a valid packet (without crc error) */ - if(plen!=0){ - - // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address. - if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){ - es.ES_make_arp_answer_from_request(buf); - return; - } - - // check if ip packets are for us: - if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){ - return; - } - - if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){ - es.ES_make_echo_reply_from_request(buf,plen); - return; - } - - // 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){ - es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack - return; - } - if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){ - es.ES_init_len_info(buf); // init some data structures - dat_p=es.ES_get_tcp_data_pointer(); - if (dat_p==0){ // we can possibly have no data, just ack: - if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){ - es.ES_make_tcp_ack_from_any(buf); - } - return; - } - 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=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

200 OK

")); - goto SENDTCP; - } - if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){ - plen=print_webpage(buf, on_off); - goto SENDTCP; - } - cmd=analyse_cmd((char *)&(buf[dat_p+5])); - - if (cmd==2){ - on_off=1; - digitalWrite(LED_PIN, LOW); // switch on LED - } - else if (cmd==3){ - on_off=0; - digitalWrite(LED_PIN, HIGH); // switch off LED - } - plen=print_webpage(buf, on_off); - - plen=print_webpage(buf, on_off); -SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get - es.ES_make_tcp_ack_with_data(buf,plen); // send data - } - } - } - -} -// The returned value is stored in the global var strbuf -uint8_t find_key_val(char *str,char *key) -{ - uint8_t found=0; - uint8_t i=0; - char *kp; - kp=key; - while(*str && *str!=' ' && found==0){ - if (*str == *kp){ - kp++; - if (*kp == '\0'){ - str++; - kp=key; - if (*str == '='){ - found=1; - } - } - }else{ - kp=key; - } - str++; - } - if (found==1){ - // copy the value to a buffer and terminate it with '\0' - while(*str && *str!=' ' && *str!='&' && i 0x2f){ - // is a ASCII number, return it - r=(*strbuf-0x30); - } - } - return r; -} - - -uint16_t print_webpage(uint8_t *buf, byte on_off) -{ - - int i=0; - - - uint16_t plen; - - - - plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

Welcome to Arduino Ethernet Shield V1.0

")); - - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

REMOTE LED is

")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

")); - - if(on_off) - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("ON")); - else - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("OFF")); - - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("


") ); - - if(on_off){ - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
")); - } - else { - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("")); - } - - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

V1.0 www.nuelectronics.com")); - - return(plen); -} - diff -u --recursive --new-file etherShield/examples/etherShield_web_temperature/etherShield_web_temperature.pde arduino-0016/hardware/libraries/Ethernet/examples/etherShield_web_temperature/etherShield_web_temperature.pde --- etherShield/examples/etherShield_web_temperature/etherShield_web_temperature.pde 2008-08-17 22:34:22.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/examples/etherShield_web_temperature/etherShield_web_temperature.pde 1970-01-01 01:00:00.000000000 +0100 @@ -1,317 +0,0 @@ -#include "etherShield.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,0x24}; -static uint8_t myip[4] = {192,168,1,15}; -static char baseurl[]="http://192.168.1.15/"; -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) -// - - -#define BUFFER_SIZE 500 -static uint8_t buf[BUFFER_SIZE+1]; -#define STR_BUFFER_SIZE 22 -static char strbuf[STR_BUFFER_SIZE+1]; - -EtherShield es=EtherShield(); - -// prepare the webpage by writing the data to the tcp send buffer -uint16_t print_webpage(uint8_t *buf); -int8_t analyse_cmd(char *str); -// get current temperature -#define TEMP_PIN 3 -void getCurrentTemp( int *sign, int *whole, int *fract); - -void setup(){ - - /*initialize enc28j60*/ - es.ES_enc28j60Init(mymac); - es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz - delay(10); - - /* Magjack leds configuration, see enc28j60 datasheet, page 11 */ - // LEDA=greed LEDB=yellow - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x880 is PHLCON LEDB=on, LEDA=on - // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x880); - delay(500); - // - // 0x990 is PHLCON LEDB=off, LEDA=off - // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00); - es.ES_enc28j60PhyWrite(PHLCON,0x990); - delay(500); - // - // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit - // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10); - es.ES_enc28j60PhyWrite(PHLCON,0x476); - delay(100); - - //init the ethernet/ip layer: - es.ES_init_ip_arp_udp_tcp(mymac,myip,80); - - // initialize DS18B20 datapin - digitalWrite(TEMP_PIN, LOW); - pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1) - - -} - -void loop(){ - uint16_t plen, dat_p; - int8_t cmd; - - plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf); - - /*plen will ne unequal to zero if there is a valid packet (without crc error) */ - if(plen!=0){ - - // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address. - if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){ - es.ES_make_arp_answer_from_request(buf); - return; - } - - // check if ip packets are for us: - if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){ - return; - } - - if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){ - es.ES_make_echo_reply_from_request(buf,plen); - return; - } - - // 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){ - es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack - return; - } - if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){ - es.ES_init_len_info(buf); // init some data structures - dat_p=es.ES_get_tcp_data_pointer(); - if (dat_p==0){ // we can possibly have no data, just ack: - if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){ - es.ES_make_tcp_ack_from_any(buf); - } - return; - } - 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=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

200 OK

")); - goto SENDTCP; - } - if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){ - plen=print_webpage(buf); - goto SENDTCP; - } - cmd=analyse_cmd((char *)&(buf[dat_p+5])); - if (cmd==1){ - plen=print_webpage(buf); - } -SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get - es.ES_make_tcp_ack_with_data(buf,plen); // send data - } - } - } - -} -// The returned value is stored in the global var strbuf -uint8_t find_key_val(char *str,char *key) -{ - uint8_t found=0; - uint8_t i=0; - char *kp; - kp=key; - while(*str && *str!=' ' && found==0){ - if (*str == *kp){ - kp++; - if (*kp == '\0'){ - str++; - kp=key; - if (*str == '='){ - found=1; - } - } - }else{ - kp=key; - } - str++; - } - if (found==1){ - // copy the value to a buffer and terminate it with '\0' - while(*str && *str!=' ' && *str!='&' && i 0x2f){ - // is a ASCII number, return it - r=(*strbuf-0x30); - } - } - return r; -} - - -uint16_t print_webpage(uint8_t *buf) -{ - char temp_string[10]; - int i=0; - //char *temp_string="100"; - - uint16_t plen; - - getCurrentTemp(temp_string); - - plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

Welcome to Arduino Ethernet Shield V1.0

")); - - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

Current Temperature is

")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

")); - - - while (temp_string[i]) { - buf[TCP_CHECKSUM_L_P+3+plen]=temp_string[i++]; - plen++; - } - - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(" °C


") ); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
")); - plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

V1.0 www.nuelectronics.com")); - - return(plen); -} - - -void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse -{ - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); // bring low for 500 us - delayMicroseconds(500); - pinMode(Pin, INPUT); - delayMicroseconds(500); -} - -void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first). -{ - byte n; - - for(n=8; n!=0; n--) - { - if ((d & 0x01) == 1) // test least sig bit - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(5); - pinMode(Pin, INPUT); - delayMicroseconds(60); - } - else - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(60); - pinMode(Pin, INPUT); - } - - d=d>>1; // now the next bit is in the least sig bit position. - } - -} - -byte OneWireInByte(int Pin) // read byte, least sig byte first -{ - byte d, n, b; - - for (n=0; n<8; n++) - { - digitalWrite(Pin, LOW); - pinMode(Pin, OUTPUT); - delayMicroseconds(5); - pinMode(Pin, INPUT); - delayMicroseconds(5); - b = digitalRead(Pin); - delayMicroseconds(50); - d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position - } - return(d); -} - - -void getCurrentTemp(char *temp) -{ - int HighByte, LowByte, TReading, Tc_100, sign, whole, fract; - - OneWireReset(TEMP_PIN); - OneWireOutByte(TEMP_PIN, 0xcc); - OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec - - OneWireReset(TEMP_PIN); - OneWireOutByte(TEMP_PIN, 0xcc); - OneWireOutByte(TEMP_PIN, 0xbe); - - LowByte = OneWireInByte(TEMP_PIN); - HighByte = OneWireInByte(TEMP_PIN); - TReading = (HighByte << 8) + LowByte; - sign = TReading & 0x8000; // test most sig bit - if (sign) // negative - { - TReading = (TReading ^ 0xffff) + 1; // 2's comp - } - Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 - - whole = Tc_100 / 100; // separate off the whole and fractional portions - fract = Tc_100 % 100; - - - if(sign) temp[0]='-'; - else temp[0]='+'; - - if(whole/100==0) - temp[1] =' '; - else - temp[1]= whole/100+'0'; - temp[2]= (whole-(whole/100)*100)/10 +'0' ; - temp[3]= whole-(whole/10)*10 +'0'; - - temp[4]='.'; - temp[5]=fract/10 +'0'; - temp[6]=fract-(fract/10)*10 +'0'; - - temp[7] = '\0'; - - - -} diff -u --recursive --new-file etherShield/ip_arp_udp_tcp.c arduino-0016/hardware/libraries/Ethernet/ip_arp_udp_tcp.c --- etherShield/ip_arp_udp_tcp.c 2008-08-15 17:52:52.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/ip_arp_udp_tcp.c 2009-08-02 15:42:29.109449774 +0200 @@ -20,6 +20,7 @@ *********************************************/ #include #include +#include //#include "avr_compat.h" #include "net.h" #include "enc28j60.h" @@ -161,24 +162,6 @@ i++; } } - -// make a new eth header for IP packet -void make_eth_ip_new(uint8_t *buf, uint8_t* dst_mac) -{ - uint8_t i=0; - // - //copy the destination mac from the source and fill my mac into src - while(i<6){ - buf[ETH_DST_MAC +i]=dst_mac[i]; - buf[ETH_SRC_MAC +i]=macaddr[i]; - i++; - } - - buf[ ETH_TYPE_H_P ] = ETHTYPE_IP_H_V; - buf[ ETH_TYPE_L_P ] = ETHTYPE_IP_L_V; -} - - void fill_ip_hdr_checksum(uint8_t *buf) { uint16_t ck; @@ -194,50 +177,6 @@ buf[IP_CHECKSUM_P+1]=ck& 0xff; } -static uint16_t ip_identifier = 1; - -// make a new ip header for tcp packet - -// make a return ip header from a received ip packet -void make_ip_tcp_new(uint8_t *buf, uint16_t len,uint8_t *dst_ip) -{ - uint8_t i=0; - - // set ipv4 and header length - buf[ IP_P ] = IP_V4_V | IP_HEADER_LENGTH_V; - - // set TOS to default 0x00 - buf[ IP_TOS_P ] = 0x00; - - // set total length - buf[ IP_TOTLEN_H_P ] = (len >>8)& 0xff; - buf[ IP_TOTLEN_L_P ] = len & 0xff; - - // set packet identification - buf[ IP_ID_H_P ] = (ip_identifier >>8) & 0xff; - buf[ IP_ID_L_P ] = ip_identifier & 0xff; - ip_identifier++; - - // set fragment flags - buf[ IP_FLAGS_H_P ] = 0x00; - buf[ IP_FLAGS_L_P ] = 0x00; - - // set Time To Live - buf[ IP_TTL_P ] = 128; - - // set ip packettype to tcp/udp/icmp... - buf[ IP_PROTO_P ] = IP_PROTO_TCP_V; - - // set source and destination ip address - while(i<4){ - buf[IP_DST_P+i]=dst_ip[i]; - buf[IP_SRC_P+i]=ipaddr[i]; - i++; - } - fill_ip_hdr_checksum(buf); -} - - // make a return ip header from a received ip packet void make_ip(uint8_t *buf) { @@ -321,9 +260,6 @@ } } - - - void make_arp_answer_from_request(uint8_t *buf) { uint8_t i=0; @@ -347,6 +283,44 @@ enc28j60PacketSend(42,buf); } +void make_arp_magicpacket(uint8_t *buf, uint8_t *dstmacaddr) +{ + uint8_t i = 0; + uint8_t offset = 0; + // fill ethernet header + + while(i<6){ + buf[ETH_DST_MAC +i]=dstmacaddr[i]; + buf[ETH_SRC_MAC +i]=macaddr[i]; + i++; + } + /* ARP packet type*/ + buf[12] = 0x08; + buf[13] = 0x42; + /* sync stream */ + buf[14] = 0xff; + buf[15] = 0xff; + buf[16] = 0xff; + buf[17] = 0xff; + buf[18] = 0xff; + buf[19] = 0xff; + + offset = 20; + + /* dstmac 16 times */ + + for (i = 0; i < 16; i++) + { + memcpy(buf+offset, dstmacaddr, 6); + offset += 6; + } + + + // eth+arp+wol is 116 bytes: + enc28j60PacketSend(116, buf); +} + + void make_echo_reply_from_request(uint8_t *buf,uint16_t len) { make_eth(buf); @@ -404,7 +378,7 @@ buf[IP_TOTLEN_H_P]=0; buf[IP_TOTLEN_L_P]=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4; make_ip(buf); - buf[TCP_FLAG_P]=TCP_FLAGS_SYNACK_V; + buf[TCP_FLAGS_P]=TCP_FLAGS_SYNACK_V; make_tcphead(buf,1,1,0); // 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); @@ -477,7 +451,7 @@ uint16_t j; make_eth(buf); // fill the header: - buf[TCP_FLAG_P]=TCP_FLAG_ACK_V; + 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 @@ -510,7 +484,7 @@ // 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_FLAG_P]=TCP_FLAG_ACK_V|TCP_FLAG_PUSH_V|TCP_FLAG_FIN_V; + buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V|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 @@ -528,187 +502,4 @@ enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlen+ETH_HEADER_LEN,buf); } - -/* new functions for web client interface */ -void make_arp_request(uint8_t *buf, uint8_t *server_ip) -{ - uint8_t i=0; - - while(i<6) - { - buf[ETH_DST_MAC +i]=0xff; - buf[ETH_SRC_MAC +i]=macaddr[i]; - i++; - } - - buf[ ETH_TYPE_H_P ] = ETHTYPE_ARP_H_V; - buf[ ETH_TYPE_L_P ] = ETHTYPE_ARP_L_V; - - // generate arp packet - buf[ARP_OPCODE_H_P]=ARP_OPCODE_REQUEST_H_V; - buf[ARP_OPCODE_L_P]=ARP_OPCODE_REQUEST_L_V; - - // fill in arp request packet - // setup hardware type to ethernet 0x0001 - buf[ ARP_HARDWARE_TYPE_H_P ] = ARP_HARDWARE_TYPE_H_V; - buf[ ARP_HARDWARE_TYPE_L_P ] = ARP_HARDWARE_TYPE_L_V; - - // setup protocol type to ip 0x0800 - buf[ ARP_PROTOCOL_H_P ] = ARP_PROTOCOL_H_V; - buf[ ARP_PROTOCOL_L_P ] = ARP_PROTOCOL_L_V; - - // setup hardware length to 0x06 - buf[ ARP_HARDWARE_SIZE_P ] = ARP_HARDWARE_SIZE_V; - - // setup protocol length to 0x04 - buf[ ARP_PROTOCOL_SIZE_P ] = ARP_PROTOCOL_SIZE_V; - - // setup arp destination and source mac address - for ( i=0; i<6; i++) - { - buf[ ARP_DST_MAC_P + i ] = 0x00; - buf[ ARP_SRC_MAC_P + i ] = macaddr[i]; - } - - // setup arp destination and source ip address - for ( i=0; i<4; i++) - { - buf[ ARP_DST_IP_P + i ] = server_ip[i]; - buf[ ARP_SRC_IP_P + i ] = ipaddr[i]; - } - - // eth+arp is 42 bytes: - enc28j60PacketSend(42,buf); - -} - - -uint8_t arp_packet_is_myreply_arp ( uint8_t *buf ) -{ - uint8_t i; - - // if packet type is not arp packet exit from function - if( buf[ ETH_TYPE_H_P ] != ETHTYPE_ARP_H_V || buf[ ETH_TYPE_L_P ] != ETHTYPE_ARP_L_V) - return 0; - // check arp request opcode - if ( buf[ ARP_OPCODE_H_P ] != ARP_OPCODE_REPLY_H_V || buf[ ARP_OPCODE_L_P ] != ARP_OPCODE_REPLY_L_V ) - return 0; - // if destination ip address in arp packet not match with avr ip address - for(i=0; i<4; i++){ - if(buf[ETH_ARP_DST_IP_P+i] != ipaddr[i]){ - return 0; - } - } - return 1; -} - -// make a tcp header -void tcp_client_send_packet(uint8_t *buf,uint16_t dest_port, uint16_t src_port, uint8_t flags, uint8_t max_segment_size, - uint8_t clear_seqack, uint16_t next_ack_num, uint16_t dlength, uint8_t *dest_mac, uint8_t *dest_ip) -{ - uint8_t i=0; - uint8_t tseq; - uint16_t ck; - - make_eth_ip_new(buf, dest_mac); - - buf[TCP_DST_PORT_H_P]= (uint8_t) ( (dest_port>>8) & 0xff); - buf[TCP_DST_PORT_L_P]= (uint8_t) (dest_port & 0xff); - - buf[TCP_SRC_PORT_H_P]= (uint8_t) ( (src_port>>8) & 0xff); - buf[TCP_SRC_PORT_L_P]= (uint8_t) (src_port & 0xff); - - // sequence numbers: - // add the rel ack num to SEQACK - - if(next_ack_num) - { - for(i=4; i>0; i--) - { - next_ack_num=buf[TCP_SEQ_H_P+i-1]+next_ack_num; - tseq=buf[TCP_SEQACK_H_P+i-1]; - buf[TCP_SEQACK_H_P+i-1]=0xff&next_ack_num; - // copy the acknum sent to us into the sequence number - buf[TCP_SEQ_P + i - 1 ] = tseq; - next_ack_num>>=8; - } - } - - // initial tcp sequence number,require to setup for first transmit/receive - if(max_segment_size) - { - // put inital seq number - buf[TCP_SEQ_H_P+0]= 0; - buf[TCP_SEQ_H_P+1]= 0; - // we step only the second byte, this allows us to send packts - // with 255 bytes or 512 (if we step the initial seqnum by 2) - buf[TCP_SEQ_H_P+2]= seqnum; - buf[TCP_SEQ_H_P+3]= 0; - // step the inititial seq num by something we will not use - // during this tcp session: - seqnum+=2; - - // setup maximum segment size - buf[TCP_OPTIONS_P]=2; - buf[TCP_OPTIONS_P+1]=4; - buf[TCP_OPTIONS_P+2]=0x05; - buf[TCP_OPTIONS_P+3]=0x80; - // 24 bytes: - buf[TCP_HEADER_LEN_P]=0x60; - - dlength +=4; - } - else{ - // no options: - // 20 bytes: - buf[TCP_HEADER_LEN_P]=0x50; - } - - make_ip_tcp_new(buf,IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlength, dest_ip); - - // clear sequence ack numer before send tcp SYN packet - if(clear_seqack) - { - buf[TCP_SEQACK_P] = 0; - buf[TCP_SEQACK_P+1] = 0; - buf[TCP_SEQACK_P+2] = 0; - buf[TCP_SEQACK_P+3] = 0; - } - // zero the checksum - buf[TCP_CHECKSUM_H_P]=0; - buf[TCP_CHECKSUM_L_P]=0; - - // set up flags - buf[TCP_FLAG_P] = flags; - // setup maximum windows size - buf[ TCP_WINDOWSIZE_H_P ] = ((600 - IP_HEADER_LEN - ETH_HEADER_LEN)>>8) & 0xff; - buf[ TCP_WINDOWSIZE_L_P ] = (600 - IP_HEADER_LEN - ETH_HEADER_LEN) & 0xff; - - // setup urgend pointer (not used -> 0) - buf[ TCP_URGENT_PTR_H_P ] = 0; - buf[ TCP_URGENT_PTR_L_P ] = 0; - - // check sum - ck=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+dlength,2); - buf[TCP_CHECKSUM_H_P]=ck>>8; - buf[TCP_CHECKSUM_L_P]=ck& 0xff; - // add 4 for option mss: - enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlength+ETH_HEADER_LEN,buf); - -} - -uint16_t tcp_get_dlength ( uint8_t *buf ) -{ - int dlength, hlength; - - dlength = ( buf[ IP_TOTLEN_H_P ] <<8 ) | ( buf[ IP_TOTLEN_L_P ] ); - dlength -= IP_HEADER_LEN; - hlength = (buf[ TCP_HEADER_LEN_P ]>>4) * 4; // generate len in bytes; - dlength -= hlength; - if ( dlength <= 0 ) - dlength=0; - - return ((uint16_t)dlength); -} - /* end of ip_arp_udp.c */ diff -u --recursive --new-file etherShield/ip_arp_udp_tcp.h arduino-0016/hardware/libraries/Ethernet/ip_arp_udp_tcp.h --- etherShield/ip_arp_udp_tcp.h 2008-08-14 18:29:38.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/ip_arp_udp_tcp.h 2009-07-30 22:56:08.060890172 +0200 @@ -22,6 +22,7 @@ extern uint8_t eth_type_is_arp_and_my_ip(uint8_t *buf,uint16_t len); extern uint8_t eth_type_is_ip_and_my_ip(uint8_t *buf,uint16_t len); extern void make_arp_answer_from_request(uint8_t *buf); +extern void make_arp_magicpacket(uint8_t *buf, uint8_t *dstmacaddr); extern void make_echo_reply_from_request(uint8_t *buf,uint16_t len); extern void make_udp_reply_from_request(uint8_t *buf,char *data,uint8_t datalen,uint16_t port); @@ -33,11 +34,6 @@ 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_arp_request(uint8_t *buf, uint8_t *server_ip); -extern uint8_t arp_packet_is_myreply_arp ( uint8_t *buf ); -extern void tcp_client_send_packet(uint8_t *buf,uint16_t dest_port, uint16_t src_port, uint8_t flags, uint8_t max_segment_size, - uint8_t clear_seqck, uint16_t next_ack_num, uint16_t dlength, uint8_t *dest_mac, uint8_t *dest_ip); -extern uint16_t tcp_get_dlength ( uint8_t *buf ); #endif /* IP_ARP_UDP_TCP_H */ diff -u --recursive --new-file etherShield/keywords.txt arduino-0016/hardware/libraries/Ethernet/keywords.txt --- etherShield/keywords.txt 2008-08-14 18:31:18.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/keywords.txt 1970-01-01 01:00:00.000000000 +0100 @@ -1,39 +0,0 @@ -####################################### -# Syntax Coloring Map For Matrix -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -EtherShield KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -ES_fill_tcp_data_p KEYWORD2 -ES_fill_tcp_data KEYWORD2 -ES_enc28j60Init KEYWORD2 -ES_enc28j60clkout KEYWORD2 -ES_enc28j60PhyWrite KEYWORD2 -ES_enc28j60PacketReceive KEYWORD2 -ES_init_ip_arp_udp_tcp KEYWORD2 -ES_eth_type_is_arp_and_my_ip KEYWORD2 -ES_make_arp_answer_from_request KEYWORD2 -ES_eth_type_is_ip_and_my_ip KEYWORD2 -ES_make_echo_reply_from_request KEYWORD2 -ES_make_tcp_synack_from_syn KEYWORD2 -ES_init_len_info KEYWORD2 -ES_get_tcp_data_pointer KEYWORD2 -ES_make_tcp_ack_from_any KEYWORD2 -ES_make_tcp_ack_with_data KEYWORD2 -ES_make_arp_request KEYWORD2 -ES_arp_packet_is_myreply_arp KEYWORD2 -ES_tcp_client_send_packet KEYWORD2 -ES_tcp_get_dlength KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### - diff -u --recursive --new-file etherShield/net.h arduino-0016/hardware/libraries/Ethernet/net.h --- etherShield/net.h 2008-08-14 17:12:12.000000000 +0200 +++ arduino-0016/hardware/libraries/Ethernet/net.h 2008-01-26 15:29:00.000000000 +0100 @@ -27,7 +27,6 @@ // values of certain bytes: #define ETHTYPE_ARP_H_V 0x08 #define ETHTYPE_ARP_L_V 0x06 -#define ETHTYPE_IP_V 0x0800 #define ETHTYPE_IP_H_V 0x08 #define ETHTYPE_IP_L_V 0x00 // byte positions in the ethernet frame: @@ -56,62 +55,25 @@ #define ETH_ARP_DST_MAC_P 0x20 #define ETH_ARP_DST_IP_P 0x26 -#define ARP_OPCODE_REQUEST_H_V 0x00 -#define ARP_OPCODE_REQUEST_L_V 0x01 -#define ARP_OPCODE_REPLY_H_V 0x00 -#define ARP_OPCODE_REPLY_L_V 0x02 - -#define ARP_HARDWARE_TYPE_H_V 0x00 -#define ARP_HARDWARE_TYPE_L_V 0x01 -#define ARP_PROTOCOL_H_V 0x08 -#define ARP_PROTOCOL_L_V 0x00 -#define ARP_HARDWARE_SIZE_V 0x06 -#define ARP_PROTOCOL_SIZE_V 0x04 - -#define ARP_HARDWARE_TYPE_H_P 0x0E -#define ARP_HARDWARE_TYPE_L_P 0x0F -#define ARP_PROTOCOL_H_P 0x10 -#define ARP_PROTOCOL_L_P 0x11 -#define ARP_HARDWARE_SIZE_P 0x12 -#define ARP_PROTOCOL_SIZE_P 0x13 -#define ARP_OPCODE_H_P 0x14 -#define ARP_OPCODE_L_P 0x15 -#define ARP_SRC_MAC_P 0x16 -#define ARP_SRC_IP_P 0x1C -#define ARP_DST_MAC_P 0x20 -#define ARP_DST_IP_P 0x26 - - // ******* IP ******* -#define IP_HEADER_LEN 20 - -#define IP_PROTO_ICMP_V 0x01 -#define IP_PROTO_TCP_V 0x06 -#define IP_PROTO_UDP_V 0x11 -#define IP_V4_V 0x40 -#define IP_HEADER_LENGTH_V 0x05 - -#define IP_P 0x0E -#define IP_HEADER_VER_LEN_P 0x0E -#define IP_TOS_P 0x0F -#define IP_TOTLEN_H_P 0x10 -#define IP_TOTLEN_L_P 0x11 -#define IP_ID_H_P 0x12 -#define IP_ID_L_P 0x13 -#define IP_FLAGS_P 0x14 -#define IP_FLAGS_H_P 0x14 -#define IP_FLAGS_L_P 0x15 -#define IP_TTL_P 0x16 -#define IP_PROTO_P 0x17 -#define IP_CHECKSUM_P 0x18 -#define IP_CHECKSUM_H_P 0x18 -#define IP_CHECKSUM_L_P 0x19 -#define IP_SRC_IP_P 0x1A -#define IP_DST_IP_P 0x1E - -#define IP_SRC_P 0x1a -#define IP_DST_P 0x1e +#define IP_HEADER_LEN 20 +// ip.src +#define IP_SRC_P 0x1a +#define IP_DST_P 0x1e #define IP_HEADER_LEN_VER_P 0xe +#define IP_CHECKSUM_P 0x18 +#define IP_TTL_P 0x16 +#define IP_FLAGS_P 0x14 +#define IP_P 0xe +#define IP_TOTLEN_H_P 0x10 +#define IP_TOTLEN_L_P 0x11 + +#define IP_PROTO_P 0x17 + +#define IP_PROTO_ICMP_V 1 +#define IP_PROTO_TCP_V 6 +// 17=0x11 +#define IP_PROTO_UDP_V 17 // ******* ICMP ******* #define ICMP_TYPE_ECHOREPLY_V 0 #define ICMP_TYPE_ECHOREQUEST_V 8 @@ -134,43 +96,27 @@ #define UDP_DATA_P 0x2a // ******* TCP ******* +#define TCP_SRC_PORT_H_P 0x22 +#define TCP_SRC_PORT_L_P 0x23 +#define TCP_DST_PORT_H_P 0x24 +#define TCP_DST_PORT_L_P 0x25 +// the tcp seq number is 4 bytes 0x26-0x29 +#define TCP_SEQ_H_P 0x26 +#define TCP_SEQACK_H_P 0x2a +// flags: SYN=2 +#define TCP_FLAGS_P 0x2f +#define TCP_FLAGS_SYN_V 2 +#define TCP_FLAGS_FIN_V 1 +#define TCP_FLAGS_PUSH_V 8 +#define TCP_FLAGS_SYNACK_V 0x12 +#define TCP_FLAGS_ACK_V 0x10 +#define TCP_FLAGS_PSHACK_V 0x18 // plain len without the options: #define TCP_HEADER_LEN_PLAIN 20 - - -#define TCP_FLAG_FIN_V 0x01 -#define TCP_FLAGS_FIN_V 0x01 -#define TCP_FLAGS_SYN_V 0x02 -#define TCP_FLAG_SYN_V 0x02 -#define TCP_FLAG_RST_V 0x04 -#define TCP_FLAG_PUSH_V 0x08 -#define TCP_FLAGS_ACK_V 0x10 -#define TCP_FLAG_ACK_V 0x10 -#define TCP_FLAG_URG_V 0x20 -#define TCP_FLAG_ECE_V 0x40 -#define TCP_FLAG_CWR_V 0x80 -#define TCP_FLAGS_SYNACK_V 0x12 - -#define TCP_SRC_PORT_H_P 0x22 -#define TCP_SRC_PORT_L_P 0x23 -#define TCP_DST_PORT_H_P 0x24 -#define TCP_DST_PORT_L_P 0x25 -#define TCP_SEQ_P 0x26 // the tcp seq number is 4 bytes 0x26-0x29 -#define TCP_SEQ_H_P 0x26 -#define TCP_SEQACK_P 0x2A // 4 bytes -#define TCP_SEQACK_H_P 0x2A -#define TCP_HEADER_LEN_P 0x2E -#define TCP_FLAGS_P 0x2F -#define TCP_FLAG_P 0x2F -#define TCP_WINDOWSIZE_H_P 0x30 // 2 bytes -#define TCP_WINDOWSIZE_L_P 0x31 -#define TCP_CHECKSUM_H_P 0x32 -#define TCP_CHECKSUM_L_P 0x33 -#define TCP_URGENT_PTR_H_P 0x34 // 2 bytes -#define TCP_URGENT_PTR_L_P 0x35 -#define TCP_OPTIONS_P 0x36 -#define TCP_DATA_P 0x36 - +#define TCP_HEADER_LEN_P 0x2e +#define TCP_CHECKSUM_H_P 0x32 +#define TCP_CHECKSUM_L_P 0x33 +#define TCP_OPTIONS_P 0x36 // #endif //@}