Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SVN move

Revision: 2
Author: ulrich
Date: 09:44:44, Donnerstag, 25. August 2011
Message:
newStack1_2_5 von Ulrich Readig als Grundlage eingecheckt
  • Loading branch information...
commit 0130cb262ee358ae48e56d2416538fe7a9495be4 1 parent 8d389fa
@uescher uescher authored
Showing with 8,911 additions and 0 deletions.
  1. +1 −0  ethernet-light-control/ETH_M32_EX.pnproj
  2. +57 −0 ethernet-light-control/analog.c
  3. +43 −0 ethernet-light-control/analog.h
  4. +89 −0 ethernet-light-control/base64.c
  5. +36 −0 ethernet-light-control/base64.h
  6. +181 −0 ethernet-light-control/camera/cam.c
  7. +95 −0 ethernet-light-control/camera/cam.h
  8. +37 −0 ethernet-light-control/camera/servo.c
  9. +28 −0 ethernet-light-control/camera/servo.h
  10. +390 −0 ethernet-light-control/cmd.c
  11. +74 −0 ethernet-light-control/cmd.h
  12. +134 −0 ethernet-light-control/config.h
  13. +476 −0 ethernet-light-control/dhcpc.c
  14. +46 −0 ethernet-light-control/dhcpc.h
  15. +279 −0 ethernet-light-control/dnsc.c
  16. +48 −0 ethernet-light-control/dnsc.h
  17. +110 −0 ethernet-light-control/http_get.c
  18. +39 −0 ethernet-light-control/http_get.h
  19. +587 −0 ethernet-light-control/httpd.c
  20. +79 −0 ethernet-light-control/httpd.h
  21. +291 −0 ethernet-light-control/lcd.c
  22. +82 −0 ethernet-light-control/lcd.h
  23. +243 −0 ethernet-light-control/main.c
  24. +438 −0 ethernet-light-control/makefile
  25. +622 −0 ethernet-light-control/networkcard/enc28j60.c
  26. +374 −0 ethernet-light-control/networkcard/enc28j60.h
  27. +273 −0 ethernet-light-control/networkcard/rtl8019.c
  28. +172 −0 ethernet-light-control/networkcard/rtl8019.h
  29. +266 −0 ethernet-light-control/ntp.c
  30. +86 −0 ethernet-light-control/ntp.h
  31. +290 −0 ethernet-light-control/sendmail.c
  32. +65 −0 ethernet-light-control/sendmail.h
  33. +1,229 −0 ethernet-light-control/stack.c
  34. +322 −0 ethernet-light-control/stack.h
  35. +176 −0 ethernet-light-control/telnetd.c
  36. +47 −0 ethernet-light-control/telnetd.h
  37. +100 −0 ethernet-light-control/timer.c
  38. +37 −0 ethernet-light-control/timer.h
  39. +65 −0 ethernet-light-control/udp_lcd.c
  40. +36 −0 ethernet-light-control/udp_lcd.h
  41. +258 −0 ethernet-light-control/usart.c
  42. +105 −0 ethernet-light-control/usart.h
  43. +359 −0 ethernet-light-control/webpage.h
  44. +103 −0 ethernet-light-control/wol.c
  45. +43 −0 ethernet-light-control/wol.h
View
1  ethernet-light-control/ETH_M32_EX.pnproj
@@ -0,0 +1 @@
+<Project name="ETH_M32_EX"><Folder name="camera"><File path="camera\cam.h"></File><File path="camera\cam.c"></File><File path="camera\servo.c"></File><File path="camera\servo.h"></File></Folder><Folder name="Netzwerktreiber"><File path="networkcard\enc28j60.c"></File><File path="networkcard\enc28j60.h"></File><File path="networkcard\rtl8019.c"></File><File path="networkcard\rtl8019.h"></File></Folder><File path="main.c"></File><File path="makefile"></File><File path="stack.c"></File><File path="stack.h"></File><File path="usart.c"></File><File path="usart.h"></File><File path="timer.c"></File><File path="cmd.h"></File><File path="cmd.c"></File><File path="httpd.h"></File><File path="httpd.c"></File><File path="telnetd.h"></File><File path="telnetd.c"></File><File path="config.h"></File><File path="base64.c"></File><File path="base64.h"></File><File path="webpage.h"></File><File path="ntp.h"></File><File path="ntp.c"></File><File path="timer.h"></File><File path="http_get.c"></File><File path="http_get.h"></File><File path="lcd.c"></File><File path="lcd.h"></File><File path="udp_lcd.h"></File><File path="udp_lcd.c"></File><File path="analog.h"></File><File path="analog.c"></File><File path="wol.h"></File><File path="wol.c"></File><File path="sendmail.c"></File><File path="sendmail.h"></File><File path="dnsc.c"></File><File path="dnsc.h"></File><File path="dhcpc.c"></File><File path="dhcpc.h"></File></Project>
View
57 ethernet-light-control/analog.c
@@ -0,0 +1,57 @@
+/*------------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 31.12.2007
+ Description: Analogeingänge Abfragen
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include "analog.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/pgmspace.h>
+#include "httpd.h" //für Variablen Array
+
+#if USE_ADC
+volatile unsigned char channel = 0;
+
+//------------------------------------------------------------------------------
+//
+void ADC_Init(void)
+{
+ ADMUX = (1<<REFS0);
+ //Free Running Mode, Division Factor 128, Interrupt on
+ ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE);
+}
+
+//------------------------------------------------------------------------------
+//
+ISR (ADC_vect)
+{
+ ANALOG_OFF; //ADC OFF
+ var_array[channel++] = ADC;
+ //usart_write("Kanal(%i)=%i\n\r",(channel-1),var_array[(channel-1)]);
+ if (channel > 7) channel = 0;
+ ADMUX =(1<<REFS0) + channel;
+ //ANALOG_ON;//ADC ON
+}
+
+#endif //USE_ADC
+
+
View
43 ethernet-light-control/analog.h
@@ -0,0 +1,43 @@
+/*------------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 31.12.2007
+ Description: Analogeingänge Abfragen
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#if USE_ADC
+
+#ifndef _ADC_H_
+ #define _ADC_H_
+
+ #define ANALOG_OFF ADCSRA=0
+ #define ANALOG_ON ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE);
+
+ volatile unsigned char channel;
+
+ extern void ADC_Init(void);
+
+#endif //_ADC_H_
+
+#endif //USE_ADC
+
+
+
+
+
View
89 ethernet-light-control/base64.c
@@ -0,0 +1,89 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 24.10.2007
+ Description: BASE64 decodieren/encodieren
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "base64.h"
+#include <avr/pgmspace.h>
+#include <avr/io.h>
+#include "usart.h"
+
+
+
+PROGMEM char BASE64CODE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+
+void decode_base64 (unsigned char *str1_in,unsigned char *str2_out)
+{
+ unsigned char *strp;
+ unsigned char end_byte = 0;
+
+ strp = str2_out;
+
+ while (*str1_in != 0)
+ {
+ *str2_out++= (*str1_in & 0xFC)>>2;
+
+ *str2_out = (((*str1_in++)&0x03)<<4);
+ if (*str1_in==0)
+ {
+ str2_out++;
+ end_byte = 2;
+ break;
+ }
+ else
+ {
+ *str2_out++ += ((*str1_in & 0xF0)>>4);
+ *str2_out = (((*str1_in++)& 0x0F)<<2);
+ if (*str1_in==0)
+ {
+ str2_out++;
+ end_byte = 1;
+ break;
+ }
+ else
+ {
+ *str2_out++ += ((*str1_in & 0xC0)>>6);
+ *str2_out++= *str1_in++ & 0x3F;
+ }
+ }
+ }
+ *str2_out = 0;
+
+ while(strp != str2_out)
+ {
+ *strp = pgm_read_byte(&BASE64CODE[(*strp) & 0x3F]);
+ strp++;
+ }
+
+ while (end_byte--)
+ {
+ *strp = '=';
+ strp++;
+ }
+ *strp = 0;
+}
+
+
+
+
+
+
+
View
36 ethernet-light-control/base64.h
@@ -0,0 +1,36 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 07.11.2007
+ Description: BASE64 decodieren/encodieren
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+
+#ifndef _BASE64_H
+ #define _BASE64_H
+
+ #define ENCODE_BYTE(b) BASE64CODE[((char)b) & 077];
+
+ extern void decode_base64 (unsigned char *str1,unsigned char *str2);
+
+#endif //_BASE64_H
+
+
+
+
View
181 ethernet-light-control/camera/cam.c
@@ -0,0 +1,181 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 24.10.2007
+ Description: RS232 Camera Routinen
+
+ Udo Matthe 15.1.08 max_bytes Berechnung korrigiert
+ Zaehl/Warteschleifen ersetzt durch Bufferfuellstandsabfragen.
+ 22.1184MHz eingebaut (funktioniert nicht fehlerfrei)
+
+----------------------------------------------------------------------------*/
+#include <config.h>
+#include "cam.h"
+#include <avr/interrupt.h>
+#include <avr/io.h>
+
+#if USE_CAM
+volatile unsigned long max_bytes;
+volatile long cmd_buffercounter = 0;
+volatile long dat_buffercounter = 0;
+volatile long cam_dat_start = CAM_HEADER;
+volatile long cam_dat_stop = CAM_HEADER + DAT_BUFFER_SIZE;
+volatile unsigned char cam_cmd_buffer[CMD_BUFFER_SIZE];
+volatile unsigned char cam_dat_buffer[DAT_BUFFER_SIZE];
+
+//----------------------------------------------------------------------------
+//Routine für die Serielle Ausgabe eines Zeichens (Schnittstelle)
+void cam_uart_write_char(char c)
+{
+ //Warten solange bis Zeichen gesendet wurde
+ while(!(USR & (1<<UDRE)));
+ //Ausgabe des Zeichens
+ UDR = c;
+ return;
+}
+
+//----------------------------------------------------------------------------
+//Sendet Commando an die Kamera
+void cam_command_send (unsigned char cmd1,unsigned char cmd2,unsigned char cmd3,
+ unsigned char cmd4,unsigned char cmd5)
+{
+ unsigned char error_count = 0;
+ while(1){
+ cmd_buffercounter = 0;
+ dat_buffercounter = 0;
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(cmd1);
+ cam_uart_write_char(cmd2);
+ cam_uart_write_char(cmd3);
+ cam_uart_write_char(cmd4);
+ cam_uart_write_char(cmd5);
+ for(unsigned long a = 0;a<100000;a++)
+ {
+ if(cmd_buffercounter>7 && cam_cmd_buffer[3]== 0x0E)
+ {
+ return;
+ }
+ }
+ if(error_count++ > 3) return;
+ }
+}
+
+//----------------------------------------------------------------------------
+//Ausgabe eines Bytes vom Bild
+char cam_data_get (unsigned long byte)
+{
+ byte = byte + 1;
+ unsigned long timeout = 300000;
+ unsigned long byte_tmp1 = byte / DAT_BUFFER_SIZE;
+
+ if(byte < (cam_dat_start-CAM_HEADER) || byte >= (cam_dat_stop-CAM_HEADER))
+ {
+ cam_dat_start = CAM_HEADER + (byte_tmp1 * DAT_BUFFER_SIZE);
+ cam_dat_stop = CAM_HEADER + DAT_BUFFER_SIZE + (byte_tmp1 * DAT_BUFFER_SIZE);
+ //request Data
+ cam_command_send (0x04,0x01,0x00,0x00,0x00);
+ while(cmd_buffercounter<cam_dat_stop && cmd_buffercounter<max_bytes && (timeout--) != 0);
+ }
+
+ byte = byte % DAT_BUFFER_SIZE;
+ return (cam_dat_buffer[byte]);
+}
+
+//----------------------------------------------------------------------------
+//Speichert ein neues Bild im Kameraspeicher
+unsigned long cam_picture_store (char mode)
+{
+ unsigned long bytes = 0;
+ unsigned long timeout = 300000;
+ cam_command_send (0x08,0x01,0x00,0x00,0x00);
+ cam_command_send (0x10,0x01,0x00,0x00,0x00);
+ cam_command_send (0x12,0x00,0x00,0x00,0x00);
+ cam_command_send (0x18,0x01,0x00,0x00,0x00);
+ cam_command_send (0x17,0x00,0x00,0x00,0x00);
+ cam_command_send (0x21,0x03,0x00,0x00,0x00);
+ //Auflösung 160x120
+ if (mode == 0)
+ {
+ cam_command_send (0x01,0x01,0x07,0x09,0x03);
+ }
+ //Auflösung 320x240
+ if (mode == 1)
+ {
+ cam_command_send (0x01,0x01,0x07,0x09,0x05);
+ }
+ //Auflösung 640x480
+ if (mode == 2)
+ {
+ cam_command_send (0x01,0x01,0x07,0x09,0x07);
+ }
+
+ cam_command_send (0x05,0x00,0x00,0x00,0x00);
+
+ cam_dat_start = CAM_HEADER;
+ cam_dat_stop = CAM_HEADER + DAT_BUFFER_SIZE;
+
+ cam_command_send (0x04,0x01,0x00,0x00,0x00);
+
+ while((cmd_buffercounter) < CMD_BUFFER_SIZE && (timeout--) != 0);
+
+ bytes = (unsigned long)cam_cmd_buffer[13];
+ bytes+= ((unsigned long)cam_cmd_buffer[14]<<8);
+ bytes+= ((unsigned long)cam_cmd_buffer[15]<<16);
+
+ return(bytes+1);
+}
+
+//----------------------------------------------------------------------------
+//Sendet Commando an die Kamera
+void cam_init (void)
+{
+ //Enable TXEN im Register UCR TX-Data Enable
+ UCR =(1 << TXEN | 1 << RXEN | 1<< RXCIE);
+ //Teiler wird gesetzt
+#if (F_CPU == 14745600)
+ UBRR=0;
+#elif (F_CPU == 22118400)
+ USR =(1<<U2X0);
+ UBRR=2;
+#else
+ #error "Kamera funktioniert nur mit F_CPU 14.745600MHz oder 22.118400MHz"
+#endif
+
+ unsigned char sync = 1;
+ do {
+ cam_command_send (0x0D,0x00,0x00,0x00,0x00);
+ for(unsigned long a = 0;a<100000;a++)
+ {
+ if (cmd_buffercounter >= 16){
+ for(unsigned long a = 0;a<100000;a++){asm("nop");};
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(0xFF);
+ cam_uart_write_char(0x0E);
+ cam_uart_write_char(0x0D);
+ cam_uart_write_char(0x00);
+ cam_uart_write_char(0x00);
+ cam_uart_write_char(0x00);
+ sync = 0;
+ break;
+ };
+ };
+ }while(sync);
+}
+
+//----------------------------------------------------------------------------
+//Empfang eines Zeichens
+ISR (USART_RX_CAM)
+{
+ char tmp = UDR;
+ if(cmd_buffercounter < CMD_BUFFER_SIZE) cam_cmd_buffer[cmd_buffercounter] = tmp;
+ if(cmd_buffercounter >= cam_dat_start && cmd_buffercounter < cam_dat_stop) cam_dat_buffer[dat_buffercounter++] = UDR;
+ cmd_buffercounter++;
+}
+#endif //USE_CAM
+
+
View
95 ethernet-light-control/camera/cam.h
@@ -0,0 +1,95 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 23.12.2007
+ Description: RS232 Camera Routinen
+ Kamera arbeitet nur mit einem 14,7456Mhz Quarz!
+----------------------------------------------------------------------------*/
+
+#if USE_CAM
+#ifndef _CAM_H
+ #define _CAM_H
+
+ //----------------------------------------------------------------------------
+
+ //----------------------------------------------------------------------------
+
+
+ #if defined (__AVR_ATmega32__)
+ #define DAT_BUFFER_SIZE 200
+ #endif
+
+ #if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
+ #define DAT_BUFFER_SIZE 1200
+ #endif
+
+ #define CMD_BUFFER_SIZE 17
+ #define CAM_HEADER 16
+
+ volatile unsigned long max_bytes;
+ volatile long cam_dat_start;
+ volatile long cam_dat_stop;
+ volatile long cmd_buffercounter;
+ volatile long dat_buffercounter;
+ volatile unsigned char cam_cmd_buffer[CMD_BUFFER_SIZE];
+ volatile unsigned char cam_dat_buffer[DAT_BUFFER_SIZE];
+
+ //Anpassen der seriellen Schnittstellen Register wenn ein ATMega128 benutzt wird
+ #if defined (__AVR_ATmega128__)
+ #define USR UCSR0A
+ #define UCR UCSR0B
+ #define UDR UDR0
+ #define UBRR UBRR0L
+ #define USART_RX_CAM USART0_RX_vect
+ #endif
+
+ #if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
+ #define USR UCSR0A
+ #define UCR UCSR0B
+ #define UBRR UBRR0L
+ #define EICR EICRB
+ #define TXEN TXEN0
+ #define RXEN RXEN0
+ #define RXCIE RXCIE0
+ #define UDR UDR0
+ #define UDRE UDRE0
+ #define USART_RX_CAM USART0_RX_vect
+ #endif
+
+ #if defined (__AVR_ATmega32__)
+ #define USR UCSRA
+ #define UCR UCSRB
+ #define UBRR UBRRL
+ #define EICR EICRB
+ #define USART_RX_CAM USART_RXC_vect
+ #endif
+
+ #if defined (__AVR_ATmega8__)
+ #define USR UCSRA
+ #define UCR UCSRB
+ #define UBRR UBRRL
+ #endif
+
+ #if defined (__AVR_ATmega88__)
+ #define USR UCSR0A
+ #define UCR UCSR0B
+ #define UBRR UBRR0L
+ #define TXEN TXEN0
+ #define UDR UDR0
+ #define UDRE UDRE0
+ #endif
+ //----------------------------------------------------------------------------
+
+ void cam_init (void);
+ void cam_uart_init(void);
+ void cam_uart_write_char(char);
+ void cam_command_send (unsigned char,unsigned char,unsigned char,unsigned char,unsigned char);
+ unsigned long cam_picture_store (char mode);
+ char cam_data_get (unsigned long byte);
+
+ //----------------------------------------------------------------------------
+
+#endif //_CAM_H
+#endif //USE_CAM
View
37 ethernet-light-control/camera/servo.c
@@ -0,0 +1,37 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 27.12.2007
+ Description: Servo Control
+----------------------------------------------------------------------------*/
+#include "config.h"
+#include "servo.h"
+
+#if USE_SERVO
+volatile unsigned char servo_pos;// min = 28/1ms max = 56/2ms
+
+void servo_init (void)
+{
+ DDRD |= (1<<7);
+
+#if defined (__AVR_ATmega644__)
+ TCCR2A = 1<<WGM00|1<<WGM01|1<<COM2A1;
+ TCCR2B = 1<<CS00|1<<CS01|1<<CS02;
+#endif
+
+#if defined (__AVR_ATmega32__)
+ TCCR2 = 1<<WGM00|1<<WGM01|1<<COM01|1<<CS00|1<<CS01|1<<CS02;
+#endif
+ servo_pos = 0;
+ servo_go_pos();
+}
+
+void servo_go_pos(void)
+{
+ OCR2 = ((F_CPU/1024/1000)-1) + (unsigned char)((unsigned int)servo_pos*(F_CPU/1024/1000)/255);
+}
+
+#endif
+
View
28 ethernet-light-control/camera/servo.h
@@ -0,0 +1,28 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 27.12.2007
+ Description: Servo Control
+----------------------------------------------------------------------------*/
+#ifndef _SERVO_H
+ #define _SERVO_H
+
+ #include <avr/io.h>
+
+ #if defined (__AVR_ATmega644__)
+ #define TCCR2 TCCR2A
+ #define OCR2 OCR2A
+ #define COM00 COM2A0
+ #define COM01 COM2A1
+ #endif
+
+ extern volatile unsigned char servo_pos;
+
+ extern void servo_init (void);
+ extern void servo_go_pos (void);
+
+#endif
+
+
View
390 ethernet-light-control/cmd.c
@@ -0,0 +1,390 @@
+/*------------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 24.10.2007
+ Description: Commando Interpreter
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include "networkcard/enc28j60.h"
+#include "networkcard/rtl8019.h"
+#include "cmd.h"
+#include <avr/io.h>
+#include <string.h>
+#include <stdlib.h>
+#include <avr/eeprom.h>
+#include "usart.h"
+#include "stack.h"
+#include "httpd.h"
+#include "ntp.h"
+#include "wol.h"
+#include "sendmail.h"
+#include "timer.h"
+#include "dnsc.h"
+
+volatile unsigned int variable[MAX_VAR];
+
+COMMAND_STRUCTUR COMMAND_TABELLE[] = // Befehls-Tabelle
+{
+ {"RESET",command_reset},
+ {"ARP",command_arp},
+ {"TCP",command_tcp},
+ {"IP",command_ip},
+ {"NET",command_net},
+ {"ROUTER",command_router},
+ {"NTP",command_ntp},
+ {"MAC",command_mac},
+ {"VER",command_ver},
+ {"SV",command_setvar},
+ {"TIME",command_time},
+ {"NTPR",command_ntp_refresh},
+ #if USE_WOL
+ {"WOL",command_wol},
+ #endif //USE_WOL
+ {"PING", command_ping},
+ #if USE_MAIL
+ {"mail", command_mail},
+ #endif //USE_MAIL
+ #if HELPTEXT
+ {"HELP",command_help},
+ {"?",command_help},
+ #endif //HELPTEXT
+ {NULL,NULL}
+};
+
+#if HELPTEXT
+ PROGMEM char helptext[] = {
+ "RESET - reset the AVR - Controller\r\n"
+ "ARP - list the ARP table\r\n"
+ "TCP - list the tcp table\r\n"
+ "IP - list/change ip\r\n"
+ "NET - list/change netmask\r\n"
+ "ROUTER - list/change router ip\r\n"
+ "NTP - list/change NTP\r\n"
+ "NTPR - NTP Refresh\r\n"
+ "MAC - list MAC-address\r\n"
+ "VER - list enc version number\r\n"
+ "SV - set variable\r\n"
+ "PING - send Ping\r\n"
+ #if USE_MAIL
+ "MAIL - send E_MAIL\r\n"
+ #endif //USE_MAIL
+ #if USE_WOL
+ "WOL - send WOL / set MAC / set MAC and IP\r\n"
+ #endif //USE_WOL
+ "TIME - get time\r\n"
+ "HELP - print Helptext\r\n"
+ "? - print Helptext\r\n"
+ };
+#endif
+
+//------------------------------------------------------------------------------
+//Commando auswerten
+unsigned char extract_cmd (char *string_pointer)
+{
+ //Stringzeiger;
+ char *string_pointer_tmp;
+ unsigned char cmd_index = 0;
+
+ string_pointer_tmp = strsep(&string_pointer," ");
+
+ //Kommando in Tabelle suchen
+ while(strcasecmp(COMMAND_TABELLE[cmd_index].cmd,string_pointer_tmp))
+ {
+ //Abruch Whileschleife und Unterprogramm verlassen
+ if (COMMAND_TABELLE[++cmd_index].cmd == 0) return(0);
+ }
+
+ //Variablen finden und auswerten
+ for (unsigned char a = 0; a<MAX_VAR;a++)
+ {
+ string_pointer_tmp = strsep(&string_pointer,"., ");
+ variable[a] = strtol(string_pointer_tmp,NULL,0);
+ }
+
+ //Kommando ausführen
+ COMMAND_TABELLE[cmd_index].fp();
+ return(1);
+}
+
+//------------------------------------------------------------------------------
+//Reset ausführen
+void command_reset (void)
+{
+ RESET();
+}
+
+//------------------------------------------------------------------------------
+//print/edit own IP
+void command_ip (void)
+{
+ write_eeprom_ip(IP_EEPROM_STORE);
+ (*((unsigned long*)&myip[0])) = get_eeprom_value(IP_EEPROM_STORE,MYIP);
+ usart_write("My IP: %1i.%1i.%1i.%1i\r\n",myip[0],myip[1],myip[2],myip[3]);
+}
+
+//------------------------------------------------------------------------------
+//
+void write_eeprom_ip (unsigned int eeprom_adresse)
+{
+ if (*((unsigned int*)&variable[0]) != 0x00000000)
+ {
+ //value ins EEPROM schreiben
+ for (unsigned char count = 0; count<4;count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(eeprom_adresse + count),variable[count]);
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+//print/edit NTP Server IP
+void command_ntp (void)
+{
+ #if USE_NTP
+ write_eeprom_ip(NTP_IP_EEPROM_STORE);
+ (*((unsigned long*)&ntp_server_ip[0])) = get_eeprom_value(NTP_IP_EEPROM_STORE,NTP_IP);
+ usart_write("NTP_Server: %1i.%1i.%1i.%1i\r\n",ntp_server_ip[0],ntp_server_ip[1],ntp_server_ip[2],ntp_server_ip[3]);
+ #endif //USE_NTP
+}
+
+//------------------------------------------------------------------------------
+//print/edit Netmask
+void command_net (void)
+{
+ write_eeprom_ip(NETMASK_EEPROM_STORE);
+ (*((unsigned long*)&netmask[0])) = get_eeprom_value(NETMASK_EEPROM_STORE,NETMASK);
+ usart_write("NETMASK: %1i.%1i.%1i.%1i\r\n",netmask[0],netmask[1],netmask[2],netmask[3]);
+}
+
+//------------------------------------------------------------------------------
+//print/edit Router IP
+void command_router (void)
+{
+ write_eeprom_ip(ROUTER_IP_EEPROM_STORE);
+ (*((unsigned long*)&router_ip[0])) = get_eeprom_value(ROUTER_IP_EEPROM_STORE,ROUTER_IP);
+ usart_write("Router IP: %1i.%1i.%1i.%1i\r\n",router_ip[0],router_ip[1],router_ip[2],router_ip[3]);
+}
+
+//------------------------------------------------------------------------------
+//print own mac
+void command_mac (void)
+{
+ usart_write("My MAC: %2x:%2x:%2x:%2x:%2x:%2x\r\n",mymac[0],mymac[1],mymac[2],mymac[3],mymac[4],mymac[5]);
+}
+
+//------------------------------------------------------------------------------
+//print enc28j60 chip version
+void command_ver (void)
+{
+#if USE_ENC28J60
+ usart_write("ENC28J60-Version: %1x\r\n", enc28j60_revision);
+#endif
+
+#if USE_RTL8019
+ usart_write("RTL8019 Ethernetcard\r\n");
+#endif
+}
+
+//------------------------------------------------------------------------------
+//print ARP table
+void command_arp (void)
+{
+ for (unsigned char index = 0;index<MAX_ARP_ENTRY;index++)
+ {
+ usart_write("%2i MAC:%2x",index,arp_entry[index].arp_t_mac[0]);
+ usart_write(".%2x",arp_entry[index].arp_t_mac[1]);
+ usart_write(".%2x",arp_entry[index].arp_t_mac[2]);
+ usart_write(".%2x",arp_entry[index].arp_t_mac[3]);
+ usart_write(".%2x",arp_entry[index].arp_t_mac[4]);
+ usart_write(".%2x",arp_entry[index].arp_t_mac[5]);
+
+ usart_write(" IP:%3i",(arp_entry[index].arp_t_ip&0x000000FF));
+ usart_write(".%3i",((arp_entry[index].arp_t_ip&0x0000FF00)>>8));
+ usart_write(".%3i",((arp_entry[index].arp_t_ip&0x00FF0000)>>16));
+ usart_write(".%3i",((arp_entry[index].arp_t_ip&0xFF000000)>>24));
+
+ usart_write(" Time:%4i\r\n",arp_entry[index].arp_t_time);
+ }
+}
+
+//------------------------------------------------------------------------------
+//print ARP table
+void command_tcp (void)
+{
+ for (unsigned char index = 0;index<MAX_TCP_ENTRY;index++)
+ {
+ usart_write("%2i",index);
+ usart_write(" IP:%3i",(tcp_entry[index].ip&0x000000FF));
+ usart_write(".%3i",((tcp_entry[index].ip&0x0000FF00)>>8));
+ usart_write(".%3i",((tcp_entry[index].ip&0x00FF0000)>>16));
+ usart_write(".%3i",((tcp_entry[index].ip&0xFF000000)>>24));
+ usart_write(" PORT:%4i",HTONS(tcp_entry[index].src_port));
+ usart_write(" Time:%4i\r\n",tcp_entry[index].time);
+ }
+}
+
+//------------------------------------------------------------------------------
+//ändern einer Variable
+void command_setvar (void)
+{
+ var_array[variable[0]] = variable[1];
+ usart_write("Inhalt der Variable[%2i] = %2i\r\n",variable[0],var_array[variable[0]]);
+}
+
+//------------------------------------------------------------------------------
+//print Time
+void command_time (void)
+{
+ unsigned char hh = (time/3600)%24;
+ unsigned char mm = (time/60)%60;
+ unsigned char ss = time %60;
+ usart_write ("\n\rTIME: %2i:%2i:%2i\r\n",hh,mm,ss);
+}
+
+//------------------------------------------------------------------------------
+//Time Refresh via NTP-Server
+void command_ntp_refresh (void)
+{
+ #if USE_NTP
+ ntp_request();
+ #endif //USE_NTP
+}
+
+//------------------------------------------------------------------------------
+//Sendet eine fertige E-MAIL
+#if USE_MAIL
+void command_mail (void)
+{
+ mail_enable = 1;
+}
+#endif //USE_MAIL
+
+//------------------------------------------------------------------------------
+//
+void command_wol (void)
+{
+ #if USE_WOL
+ // EEPROM beschreiben, falls Parameter angegeben wurden
+ if ((*((unsigned int*)&variable[0]) != 0x00000000) || (*((unsigned int*)&variable[1]) != 0x00000000) || (*((unsigned int*)&variable[2]) != 0x00000000))
+ {
+ //schreiben der MAC
+ for (unsigned char count = 0; count<6; count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(WOL_MAC_EEPROM_STORE + count),variable[count]);
+ }
+ //zusätzlich schreiben der Broadcast-Adresse, falls vorhandenden
+ for (unsigned char count = 0; count<4 && (*((unsigned int*)&variable[6]) != 0x00000000);count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char*)(WOL_BCAST_EEPROM_STORE + count),variable[count+6]);
+ }
+ //init
+ wol_init();
+ }else{
+ //MagicPacket senden
+ wol_request();
+ }
+ #endif //USE_WOL
+}
+
+//------------------------------------------------------------------------------
+// Sende "Ping" an angegebene Adresse
+void command_ping (void)
+{
+ if (*((unsigned int*)&variable[0]) != 0x00000000)
+ {
+ (*((unsigned long*)&ping.ip1[0])) = ((variable[0])+((unsigned long)(variable[1])<<8)+((unsigned long)(variable[2])<<16)+((unsigned long)(variable[3])<<24));
+ //ARP Request senden
+ arp_request ( (*(unsigned long*)&ping.ip1[0]));
+
+ //ICMP-Nachricht Type=8 Code=0: Echo-Anfrage
+ //TODO: Sequenznummer, Identifier
+ icmp_send( (*(unsigned long*)&ping.ip1[0]),0x08,0x00,1,1);
+ }
+}
+
+//------------------------------------------------------------------------------
+//print helptext
+void command_help (void)
+{
+#if HELPTEXT
+ unsigned char data;
+ PGM_P helptest_pointer = helptext;
+
+ do
+ {
+ data = pgm_read_byte(helptest_pointer++);
+ usart_write("%c",data);
+ }while(data != 0);
+#endif
+}
+
+//------------------------------------------------------------------------------
+//save all ip-datas
+void save_ip_addresses(void)
+{
+ for (unsigned char count = 0; count<4; count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(IP_EEPROM_STORE + count),myip[count]);
+ }
+ for (unsigned char count = 0; count<4; count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(NETMASK_EEPROM_STORE + count),netmask[count]);
+ }
+ for (unsigned char count = 0; count<4; count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(ROUTER_IP_EEPROM_STORE + count),router_ip[count]);
+ }
+ #if USE_DNS
+ for (unsigned char count = 0; count<4; count++)
+ {
+ eeprom_busy_wait ();
+ eeprom_write_byte((unsigned char *)(DNS_IP_EEPROM_STORE + count),dns_server_ip[count]);
+ }
+ #endif //USE_DNS
+}
+
+//------------------------------------------------------------------------------
+//Read all IP-Datas
+void read_ip_addresses (void)
+{
+ (*((unsigned long*)&myip[0])) = get_eeprom_value(IP_EEPROM_STORE,MYIP);
+ (*((unsigned long*)&netmask[0])) = get_eeprom_value(NETMASK_EEPROM_STORE,NETMASK);
+ (*((unsigned long*)&router_ip[0])) = get_eeprom_value(ROUTER_IP_EEPROM_STORE,ROUTER_IP);
+
+ #if USE_DNS
+ //DNS-Server IP aus EEPROM auslesen
+ (*((unsigned long*)&dns_server_ip[0])) = get_eeprom_value(DNS_IP_EEPROM_STORE,DNS_IP);
+ #endif
+}
+
+
+
+
+
+
+
+
+
View
74 ethernet-light-control/cmd.h
@@ -0,0 +1,74 @@
+/*------------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 24.10.2007
+ Description: Commando Interpreter
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+
+#ifndef _CMD_H_
+ #define _CMD_H_
+
+ typedef struct
+ {
+ char* cmd; // Stringzeiger auf Befehlsnamen
+ void(*fp)(void); // Zeiger auf auszuführende Funktion
+ } COMMAND_STRUCTUR;
+
+ #define MAX_VAR 10
+ #define HELPTEXT 1
+
+ extern unsigned char extract_cmd (char *);
+ extern void write_eeprom_ip (unsigned int);
+
+ extern void save_ip_addresses(void);
+ extern void read_ip_addresses (void);
+
+ //reset the unit
+ extern void command_reset (void);
+ //Ausgabe der ARP Tabelle
+ extern void command_arp (void);
+ //Ausgabe der TCP Tabelle
+ extern void command_tcp (void);
+
+ //ändern/ausgabe der IP, NETMASK, ROUTER_IP, NTP_IP
+ extern void command_ip (void);
+ extern void command_net (void);
+ extern void command_router (void);
+ extern void command_ntp (void);
+
+ extern void command_mac (void);
+ extern void command_ver (void);
+ extern void command_setvar (void);
+ extern void command_time (void);
+ extern void command_ntp_refresh (void);
+ #if USE_WOL
+ extern void command_wol (void);
+ #endif //USE_WOL
+ #if USE_MAIL
+ extern void command_mail (void);
+ #endif //USE_MAIL
+ extern void command_ping (void);
+ extern void command_help (void);
+
+ #define RESET() {asm("ldi r30,0"); asm("ldi r31,0"); asm("ijmp");}
+
+#endif //_CMD_H_
+
+
View
134 ethernet-light-control/config.h
@@ -0,0 +1,134 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 03.11.2007
+ Description: Webserver Config-File
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+
+#ifndef _CONFIG_H_
+ #define _CONFIG_H_
+
+ //ETH_M32_EX (www.ulrichradig.de)
+ #define USE_ENC28J60 1
+ //Holger Buss (www.mikrocontroller.com) Mega32-Board
+ #define USE_RTL8019 0
+
+ //Konfiguration der PORTS (HEX)
+ //1=OUTPUT / 0=INPUT
+ #define OUTA 0x07
+ #define OUTC 0x06
+ #define OUTD 0x00
+ //Achtung!!!! an PORTB ist der ENC
+ //nur ändern wenn man weiß was man macht!
+
+ //Watchdog timer for the ENC2860, resets the stack if timeout occurs
+ #define WTT 1200 //Watchdog timer in timer interrupt
+
+ //NTP refresh before stack timeout occurs...
+ #define NTP_REFRESH 1140
+
+ //Umrechnung von IP zu unsigned long
+ #define IP(a,b,c,d) ((unsigned long)(d)<<24)+((unsigned long)(c)<<16)+((unsigned long)(b)<<8)+a
+
+ //IP des Webservers und des Routers
+ #define MYIP IP(192,168,0,99)
+ #define ROUTER_IP IP(192,168,0,1)
+
+ //Netzwerkmaske
+ #define NETMASK IP(255,255,255,0)
+
+ //DHCP-Server
+ #define USE_DHCP 0 //1 = DHCP Client on
+
+ //DNS-Server
+ #define USE_DNS 0 //1 = DNS Client on
+ #define DNS_IP IP(192,168,0,1)
+
+
+ //IP des NTP-Servers z.B. Server 1.de.pool.ntp.org
+ #define USE_NTP 1 //1 = NTP Client on
+ #define NTP_IP IP(77,37,6,59)
+
+ //Broadcast-Adresse für WOL
+ #define USE_WOL 0 //1 = WOL on
+ #define WOL_BCAST_IP IP(192,168,0,255)
+ #define WOL_MAC {0x00,0x1A,0xA0,0x9C,0xC6,0x0A}
+
+ //MAC Adresse des Webservers
+ #define MYMAC1 0x00
+ #define MYMAC2 0x20
+ #define MYMAC3 0x18
+ #define MYMAC4 0xB1
+ #define MYMAC5 0x15
+ #define MYMAC6 0x6F
+
+ //Taktfrequenz
+ //#define F_CPU 20000000UL
+ #define F_CPU 16000000UL
+ //#define F_CPU 14745600UL
+ //#define F_CPU 11059200UL
+
+ //Timertakt intern oder extern
+ #define EXTCLOCK 0 //0=Intern 1=Externer Uhrenquarz
+
+ //Baudrate der seriellen Schnittstelle
+ #define BAUDRATE 9600
+
+ //LCD Routinen mit einbinden
+ #define USE_SER_LCD 0
+ //LCD im 4Bit Mode oder seriell
+ #define USE_LCD_4Bit 0
+
+ //AD-Wandler benutzen?
+ #define USE_ADC 0
+
+ //Kamera mit einbinden
+ //Kamera arbeitet nur mit einem 14,7456Mhz Quarz!
+ #define USE_CAM 0
+ #define USE_SERVO 0
+ //In cam.c können weitere Parameter eingestellt werde
+ //z.B. Licht, Kompression usw.
+ //Auflösungen
+ //0 = 160x120 Pixel kürzer (zum testen OK ;-)
+ //1 = 320x240 Pixel ca. 10 Sek. bei einem Mega644
+ //2 = 640x480 Pixel länger (dauert zu lang!)
+ #define CAM_RESOLUTION 0
+
+ //Webserver mit Passwort? (0 == mit Passwort)
+ #define HTTP_AUTH_DEFAULT 0
+
+ //AUTH String "USERNAME:PASSWORT" max 14Zeichen
+ //für Username:Passwort
+ #define HTTP_AUTH_STRING "admin:uli1"
+ //#define HTTP_AUTH_STRING "user:pass"
+
+ //Email vesand benutzen? Konfiguration des
+ //Emailclient in der Sendmail.h
+ #define USE_MAIL 0
+
+ //Empfang von Wetterdaten auf der Console (über HTTP_GET)
+ #define GET_WEATHER 0
+
+ //Commandos und Ausgaben erfolgen über Telnet
+ #define CMD_TELNET 0
+
+#endif //_CONFIG_H
+
+
View
476 ethernet-light-control/dhcpc.c
@@ -0,0 +1,476 @@
+/*----------------------------------------------------------------------------
+ Copyright: Michael Kleiber
+ Author: Michael Kleiber
+ Remarks:
+ known Problems: none
+ Version: 29.11.2008
+ Description: DHCP Client
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include "stack.h"
+#include "usart.h"
+#include "timer.h"
+#include "dnsc.h"
+#include "dhcpc.h"
+
+#if USE_DHCP
+
+struct dhcp_msg
+{
+ unsigned char op; //1
+ unsigned char htype; //2
+ unsigned char hlen; //3
+ unsigned char hops; //4
+ unsigned char xid[4]; //8
+ unsigned int secs; //12
+ unsigned int flags; //14
+ unsigned char ciaddr[4]; //16
+ unsigned char yiaddr[4]; //20
+ unsigned char siaddr[4]; //24
+ unsigned char giaddr[4]; //28
+ unsigned char chaddr[16]; //44
+ unsigned char sname[64]; //108
+ unsigned char file[128]; //Up to here 236 Bytes
+ unsigned char options[312]; // receive up to 312 bytes
+};
+
+struct dhcp_cache
+{
+ unsigned char type;
+ unsigned char ovld;
+ unsigned char router_ip[4];
+ unsigned char dns1_ip [4];
+ unsigned char dns2_ip [4];
+ unsigned char netmask [4];
+ unsigned char lease [4];
+ unsigned char serv_id [4];
+};
+
+//DHCP Message types for Option 53
+#define DHCPDISCOVER 1 // client -> server
+#define DHCPOFFER 2 // server -> client
+#define DHCPREQUEST 3 // client -> server
+#define DHCPDECLINE 4 // client -> server
+#define DHCPACK 5 // server -> client
+#define DHCPNAK 6 // server -> client
+#define DHCPRELEASE 7 // client -> server
+#define DHCPINFORM 8 // client -> server
+
+unsigned char dhcp_state;
+#define DHCP_STATE_IDLE 0
+#define DHCP_STATE_DISCOVER_SENT 1
+#define DHCP_STATE_OFFER_RCVD 2
+#define DHCP_STATE_SEND_REQUEST 3
+#define DHCP_STATE_REQUEST_SENT 4
+#define DHCP_STATE_ACK_RCVD 5
+#define DHCP_STATE_NAK_RCVD 6
+#define DHCP_STATE_ERR 7
+#define DHCP_STATE_FINISHED 8
+
+struct dhcp_cache cache;
+volatile unsigned long dhcp_lease;
+//----------------------------------------------------------------------------
+//Init of DHCP client port
+void dhcp_init (void)
+{
+ //Port in Anwendungstabelle eintragen für eingehende DHCP Daten!
+ add_udp_app (DHCP_CLIENT_PORT, (void(*)(unsigned char))dhcp_get);
+ dhcp_state = DHCP_STATE_IDLE;
+ return;
+}
+//----------------------------------------------------------------------------
+// Configure this client by DHCP
+unsigned char dhcp (void)
+{
+ unsigned char timeout_cnt;
+
+ timeout_cnt = 0;
+
+ if ( (dhcp_state == DHCP_STATE_FINISHED ) &&
+ (dhcp_lease < 600) )
+ {
+ dhcp_state = DHCP_STATE_SEND_REQUEST;
+ }
+
+ do
+ {
+ if ( timeout_cnt > 3 )
+ {
+ dhcp_state = DHCP_STATE_ERR;
+ DHCP_DEBUG("DHCP timeout\r\n");
+ return (1);
+ }
+ switch (dhcp_state)
+ {
+ case DHCP_STATE_IDLE:
+ dhcp_message(DHCPDISCOVER);
+ gp_timer = 5;
+ break;
+ case DHCP_STATE_DISCOVER_SENT:
+ if (gp_timer == 0)
+ {
+ dhcp_state = DHCP_STATE_IDLE;
+ timeout_cnt++;
+ }
+ break;
+ case DHCP_STATE_OFFER_RCVD:
+ timeout_cnt = 0;
+ dhcp_state = DHCP_STATE_SEND_REQUEST;
+ break;
+ case DHCP_STATE_SEND_REQUEST:
+ gp_timer = 5;
+ dhcp_message(DHCPREQUEST);
+ break;
+ case DHCP_STATE_REQUEST_SENT:
+ if (gp_timer == 0)
+ {
+ dhcp_state = DHCP_STATE_SEND_REQUEST;
+ timeout_cnt++;
+ }
+ break;
+ case DHCP_STATE_ACK_RCVD:
+ DHCP_DEBUG("LEASE %2x%2x%2x%2x\r\n", cache.lease[0],cache.lease[1],cache.lease[2],cache.lease[3]);
+
+ dhcp_lease = (unsigned long)cache.lease[0] << 24 | (unsigned long)cache.lease[1] << 16 | (unsigned long)cache.lease[2] << 8 |(unsigned long)cache.lease[3];
+
+ (*((unsigned long*)&netmask[0])) = (*((unsigned long*)&cache.netmask[0]));
+ (*((unsigned long*)&router_ip[0])) = (*((unsigned long*)&cache.router_ip[0]));
+ #if USE_DNS
+ (*((unsigned long*)&dns_server_ip[0])) = (*((unsigned long*)&cache.dns1_ip[0]));
+ #endif
+ dhcp_state = DHCP_STATE_FINISHED;
+ break;
+ case DHCP_STATE_NAK_RCVD:
+ dhcp_state = DHCP_STATE_IDLE;
+ break;
+ }
+ eth_get_data();
+ }
+ while ( dhcp_state != DHCP_STATE_FINISHED );
+ return(0);
+}
+
+//----------------------------------------------------------------------------
+//Sendet DHCP messages an Broadcast
+void dhcp_message (unsigned char type)
+{
+ struct dhcp_msg *msg;
+ unsigned char *options;
+
+ for (unsigned int i=0; i < sizeof (struct dhcp_msg); i++) //clear eth_buffer to 0
+ {
+ eth_buffer[UDP_DATA_START+i] = 0;
+ }
+
+ msg = (struct dhcp_msg *)&eth_buffer[UDP_DATA_START];
+ msg->op = 1; // BOOTREQUEST
+ msg->htype = 1; // Ethernet
+ msg->hlen = 6; // Ethernet MAC
+ msg->xid[0] = MYMAC6; //use the MAC as the ID to be unique in the LAN
+ msg->xid[1] = MYMAC5;
+ msg->xid[2] = MYMAC4;
+ msg->xid[3] = MYMAC3;
+ msg->flags = HTONS(0x8000);
+ msg->chaddr[0] = MYMAC1;
+ msg->chaddr[1] = MYMAC2;
+ msg->chaddr[2] = MYMAC3;
+ msg->chaddr[3] = MYMAC4;
+ msg->chaddr[4] = MYMAC5;
+ msg->chaddr[5] = MYMAC6;
+
+ options = &msg->options[0]; //options
+ *options++ = 99; //magic cookie
+ *options++ = 130;
+ *options++ = 83;
+ *options++ = 99;
+
+ *options++ = 53; // Option 53: DHCP message type DHCP Discover
+ *options++ = 1; // len = 1
+ *options++ = type; // 1 = DHCP Discover
+
+ *options++ = 55; // Option 55: parameter request list
+ *options++ = 3; // len = 3
+ *options++ = 1; // netmask
+ *options++ = 3; // router
+ *options++ = 6; // dns
+
+ *options++ = 50; // Option 54: requested IP
+ *options++ = 4; // len = 4
+ *options++ = myip[0];
+ *options++ = myip[1];
+ *options++ = myip[2];
+ *options++ = myip[3];
+
+ switch (type)
+ {
+ case DHCPDISCOVER:
+ dhcp_state = DHCP_STATE_DISCOVER_SENT;
+ DHCP_DEBUG("DISCOVER sent\r\n");
+ break;
+ case DHCPREQUEST:
+ *options++ = 54; // Option 54: server ID
+ *options++ = 4; // len = 4
+ *options++ = cache.serv_id[0];
+ *options++ = cache.serv_id[1];
+ *options++ = cache.serv_id[2];
+ *options++ = cache.serv_id[3];
+ dhcp_state = DHCP_STATE_REQUEST_SENT;
+ DHCP_DEBUG("REQUEST sent\r\n");
+ break;
+ default:
+ DHCP_DEBUG("Wrong DHCP msg type\r\n");
+ break;
+ }
+
+ *options++ = 12; // Option 12: host name
+ *options++ = 8; // len = 8
+ *options++ = 'M';
+ *options++ = 'i';
+ *options++ = 'n';
+ *options++ = 'i';
+ *options++ = '-';
+ *options++ = 'A';
+ *options++ = 'V';
+ *options++ = 'R';
+
+ *options = 0xff; //end option
+
+ create_new_udp_packet(sizeof (struct dhcp_msg),DHCP_CLIENT_PORT,DHCP_SERVER_PORT,(unsigned long)0xffffffff);
+}
+//----------------------------------------------------------------------------
+//liest 4 bytes aus einem buffer und speichert in dem anderen
+void get4bytes (unsigned char *source, unsigned char *target)
+{
+ unsigned char i;
+
+ for (i=0; i<4; i++)
+ {
+ *target++ = *source++;
+ }
+}
+//----------------------------------------------------------------------------
+//read all the options
+//pointer to the variables and size from options to packet end
+void dhcp_parse_options (unsigned char *msg, struct dhcp_cache *c, unsigned int size)
+{
+ unsigned int ix;
+
+ ix = 0;
+ do
+ {
+ switch (msg[ix])
+ {
+ case 0: //Padding
+ ix++;
+ break;
+ case 1: //Netmask
+ ix++;
+ if ( msg[ix] == 4 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->netmask[0]);
+ ix += 4;
+ }
+ else
+ {
+ ix += (msg[ix]+1);
+ }
+ break;
+ case 3: //router (gateway IP)
+ ix++;
+ if ( msg[ix] == 4 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->router_ip[0]);
+ ix += 4;
+ }
+ else
+ {
+ ix += (msg[ix]+1);
+ }
+ break;
+ case 6: //dns len = n * 4
+ ix++;
+ if ( msg[ix] == 4 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->dns1_ip[0]);
+ ix += 4;
+ }
+ else
+ if ( msg[ix] == 8 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->dns1_ip[0]);
+ ix += 4;
+ get4bytes(&msg[ix], &c->dns2_ip[0]);
+ ix += 4;
+ }
+ else
+ {
+ ix += (msg[ix]+1);
+ }
+ break;
+ case 51: //lease time
+ ix++;
+ if ( msg[ix] == 4 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->lease[0]);
+ ix += 4;
+ }
+ else
+ {
+ ix += msg[ix]+1;
+ }
+ break;
+ case 52: //Options overload
+ ix++;
+ if ( msg[ix] == 1 ) //size == 1
+ {
+ ix++;
+ c->ovld = msg[ix];
+ ix++;
+ }
+ else
+ {
+ ix += (msg[ix]+1);
+ }
+ break;
+ case 53: //DHCP Type
+ ix++;
+ if ( msg[ix] == 1 ) //size == 1
+ {
+ ix++;
+ c->type = msg[ix];
+ ix++;
+ }
+ else
+ {
+ ix += (msg[ix]+1);
+ }
+ break;
+ case 54: //Server identifier
+ ix++;
+ if ( msg[ix] == 4 )
+ {
+ ix++;
+ get4bytes(&msg[ix], &c->serv_id[0]);
+ ix += 4;
+ }
+ else
+ {
+ ix += msg[ix]+1;
+ }
+ break;
+ case 99: //Magic cookie
+ ix += 4;
+ break;
+ case 0xff: //end option
+ break;
+ default:
+ DHCP_DEBUG("Unknown Option: %2x\r\n", msg[ix]);
+ ix++;
+ ix += (msg[ix]+1);
+ break;
+ }
+ }
+ while ( (msg[ix] != 0xff) && (ix < size) );
+}
+
+//----------------------------------------------------------------------------
+//Wertet message vom DHCP Server aus
+// DHCP packets: 20 Bytes IP Header, 8 Bytes UDP_Header,
+// DHCP fixed fields 236 Bytes, min 312 Bytes options -> 576 Bytes min.
+void dhcp_get (void)
+{
+ struct dhcp_msg *msg;
+ struct IP_Header *ip;
+ unsigned char *p;
+ unsigned int i;
+
+ ip = (struct IP_Header *)&eth_buffer[IP_OFFSET];
+ if ( htons(ip->IP_Pktlen) > MTU_SIZE )
+ {
+ DHCP_DEBUG("DHCP too big, discarded\r\n");
+ return;
+ }
+
+ p = &cache.type; //clear the cache
+ for (i=0; i<sizeof(cache); i++)
+ {
+ p[i] = 0;
+ }
+
+ // set pointer of DHCP message to beginning of UDP data
+ msg = (struct dhcp_msg *)&eth_buffer[UDP_DATA_START];
+
+ //check the id
+ if ( (msg->xid[0] != MYMAC6) ||
+ (msg->xid[1] != MYMAC5) ||
+ (msg->xid[2] != MYMAC4) ||
+ (msg->xid[3] != MYMAC3) )
+ {
+ DHCP_DEBUG("Wrong DHCP ID, discarded\r\n");
+ return;
+ }
+
+
+ dhcp_parse_options(&msg->options[0], &cache, (htons(ip->IP_Pktlen)-264) );
+ // check if file field or sname field are overloaded (option 52)
+ switch (cache.ovld)
+ {
+ case 0: // no overload, do nothing
+ break;
+ case 1: // the file field contains options
+ dhcp_parse_options(&msg->file[0], &cache, 128);
+ break;
+ case 2: // the sname field contains options
+ dhcp_parse_options(&msg->sname[0], &cache, 64);
+ break;
+ case 3: // the file and the sname field contain options
+ dhcp_parse_options(&msg->file[0], &cache, 128);
+ dhcp_parse_options(&msg->sname[0], &cache, 64);
+ break;
+ default: // must not occur
+ DHCP_DEBUG("Option 52 Error\r\n");
+ break;
+ }
+
+ switch (cache.type)
+ {
+ case DHCPOFFER:
+ // this will be our IP address
+ (*((unsigned long*)&myip[0])) = (*((unsigned long*)&msg->yiaddr[0]));
+ DHCP_DEBUG("** DHCP OFFER RECVD! **\r\n");
+ dhcp_state = DHCP_STATE_OFFER_RCVD;
+ break;
+ case DHCPACK:
+ DHCP_DEBUG("** DHCP ACK RECVD! **\r\n");
+ dhcp_state = DHCP_STATE_ACK_RCVD;
+ break;
+ case DHCPNAK:
+ DHCP_DEBUG("** DHCP NAK RECVD! **\r\n");
+ dhcp_state = DHCP_STATE_NAK_RCVD;
+ break;
+ }
+}
+
+#endif
View
46 ethernet-light-control/dhcpc.h
@@ -0,0 +1,46 @@
+/*----------------------------------------------------------------------------
+ Copyright: Michael Kleiber
+ Author: Michael Kleiber
+ Remarks:
+ known Problems: none
+ Version: 29.04.2008
+ Description: DHCP Client
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+
+#if USE_DHCP
+#ifndef _DHCPCLIENT_H
+ #define _DHCPCLIENT_H
+
+ //#define DHCP_DEBUG usart_write
+ #define DHCP_DEBUG(...)
+
+ #define DHCP_CLIENT_PORT 68
+ #define DHCP_SERVER_PORT 67
+
+
+volatile unsigned long dhcp_lease;
+volatile unsigned char dhcp_timer;
+
+extern void dhcp_init (void);
+extern void dhcp_message (unsigned char type);
+extern void dhcp_get (void);
+extern unsigned char dhcp (void);
+
+#endif //_DHCPCLIENT_H
+#endif //USE_DHCP
+
View
279 ethernet-light-control/dnsc.c
@@ -0,0 +1,279 @@
+/*----------------------------------------------------------------------------
+ Copyright: Michael Kleiber
+ Author: Michael Kleiber
+ Remarks:
+ known Problems: none
+ Version: 29.11.2008
+ Description: DNS Client
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include "stack.h"
+#include "usart.h"
+#include "timer.h"
+
+#if USE_DNS
+
+#include "dnsc.h"
+
+//----------------------------------------------------------------------------
+
+unsigned char dns_server_ip[4];
+unsigned char dns_resolved_ip[4];
+unsigned char dns_state;
+
+#define DNS_STATE_IDLE 0
+#define DNS_STATE_REQ_SENT 1
+#define DNS_STATE_REQ_ERR 2
+#define DNS_STATE_FINISHED 3
+#define DNS_STATE_REC_ERR 4
+
+//----------------------------------------------------------------------------
+//Eintrag des DNS clients im stack
+void dns_init (void)
+{
+ //ADD the DNS port as apllication to the list
+ add_udp_app (DNS_CLIENT_PORT, (void(*)(unsigned char))dns_get);
+
+ //DNS IP read from EEPROM
+ (*((unsigned long*)&dns_server_ip[0])) = get_eeprom_value(DNS_IP_EEPROM_STORE,DNS_IP);
+
+ DNS_DEBUG("DNS %1i.%1i.%1i.%1i\r\n",dns_server_ip[0],dns_server_ip[1],dns_server_ip[2],dns_server_ip[3]);
+ return;
+}
+
+//----------------------------------------------------------------------------
+//resolve domain name
+unsigned char dns_resolve (char *name)
+{
+ dns_state = DNS_STATE_IDLE;
+
+ dns_query(name);
+
+ if (dns_state != DNS_STATE_REQ_SENT)
+ {
+ return(1);
+ }
+ gp_timer = 30; //is decremented in timer.c
+
+ do
+ {
+ eth_get_data();
+ }
+ while ( (dns_state == DNS_STATE_REQ_SENT) &&
+ (gp_timer > 0 ) );
+
+ if ( ( dns_state != DNS_STATE_FINISHED) ||
+ ( gp_timer == 0 ) )
+ {
+ return(1);
+ }
+ return (0);
+}
+//----------------------------------------------------------------------------
+//send query to DNS server
+void dns_query(char *name)
+{
+ unsigned char *nptr;
+ unsigned char n;
+ unsigned int byte_count;
+ unsigned long tmp_ip;
+
+ tmp_ip = (*(unsigned long*)&dns_server_ip[0]);
+
+ if (arp_request(tmp_ip) == 1) // if DNS server is answering to ARP
+ {
+ nptr = &eth_buffer[UDP_DATA_START];
+ *nptr++ = 0x12; //ID h
+ *nptr++ = 0x34; //ID l
+ *nptr++ = 0x01; //Flags h FLAG_RD ->Standard query
+ *nptr++ = 0x00; //Flags l
+ *nptr++ = 0x00; //QDCOUNT h
+ *nptr++ = 0x01; //QDCOUNT l
+ *nptr++ = 0x00; //ANCOUNT h
+ *nptr++ = 0x00; //ANCOUNT l
+ *nptr++ = 0x00; //NSCOUNT h
+ *nptr++ = 0x00; //NSCOUNT l
+ *nptr++ = 0x00; //ARCOUNT h
+ *nptr++ = 0x00; //ARCOUNT l
+
+ byte_count = 12;
+ --name;
+ /* Convert hostname to query format. */
+ do
+ {
+ ++name;
+ nptr = &eth_buffer[UDP_DATA_START+byte_count]; //remember the first byte
+ byte_count++;
+ for(n = 0; *name != '.' && *name != 0; ++name) //copy the name
+ {
+ eth_buffer[UDP_DATA_START+byte_count] = *name;
+ byte_count++;
+ n++;
+ }
+ *nptr = n; //store the length in the first byte
+ }
+ while(*name != 0); //until name string is finished
+
+ //end of query:
+ eth_buffer[UDP_DATA_START+byte_count] = 0; //zero string
+ byte_count++;
+
+ eth_buffer[UDP_DATA_START+byte_count] = 0; //2 bytes QTYPE 1=a host address
+ byte_count++;
+ eth_buffer[UDP_DATA_START+byte_count] = 1; //
+ byte_count++;
+
+ eth_buffer[UDP_DATA_START+byte_count] = 0; //2 bytes QCLASS 1=Internet
+ byte_count++;
+ eth_buffer[UDP_DATA_START+byte_count] = 1; //
+ byte_count++;
+
+ create_new_udp_packet(byte_count,DNS_CLIENT_PORT,DNS_SERVER_PORT,tmp_ip);
+ dns_state = DNS_STATE_REQ_SENT;
+ return;
+ }
+ dns_state = DNS_STATE_REQ_ERR;
+ DNS_DEBUG("No DNS server!!\r\n");
+}
+
+//----------------------------------------------------------------------------
+//Überspringt den Namen im RR und gibt die Länge zurück
+unsigned int skip_name (char *query)
+{
+ unsigned char n;
+ unsigned int count;
+
+ count = 0;
+ do
+ {
+ n = *query++;
+ count++;
+
+ while(n > 0)
+ {
+ query++;
+ count++;
+ n--;
+ };
+
+ }
+ while(*query != 0);
+
+ return count+1;
+}
+
+//----------------------------------------------------------------------------
+//Empfang der Antwort vom DNS Server
+void dns_get(void)
+{
+ unsigned int byte_count;
+ unsigned int id;
+ unsigned int flags;
+ unsigned int qdcount;
+ unsigned int answ_cnt;
+ unsigned int antype;
+ unsigned int anclass;
+ unsigned int rdlen;
+ unsigned char ip[4];
+
+ DNS_DEBUG("** DNS DATA GET! **\r\n");
+
+ id = eth_buffer[UDP_DATA_START+ 0]*256;
+ id += eth_buffer[UDP_DATA_START+ 1];
+ DNS_DEBUG("ID %4x\r\n", id);
+
+ flags = eth_buffer[UDP_DATA_START+ 2]*256;
+ flags += eth_buffer[UDP_DATA_START+ 3];
+ DNS_DEBUG("Flags %4x\r\n", flags);
+
+ qdcount = eth_buffer[UDP_DATA_START+ 4]*256;
+ qdcount += eth_buffer[UDP_DATA_START+ 5];
+ DNS_DEBUG("QDCOUNT %4x\r\n", qdcount);
+
+ answ_cnt = eth_buffer[UDP_DATA_START+ 6]*256;
+ answ_cnt += eth_buffer[UDP_DATA_START+ 7];
+ DNS_DEBUG("ANCOUNT %4x\r\n", answ_cnt);
+
+ if ( (flags & 0x000f) != 0 ) //RCODE 0=no error
+ {
+ DNS_DEBUG("Err in flags: %4x\r\n", flags);
+ dns_state = DNS_STATE_REC_ERR;
+ return;
+ }
+
+ // nscount and arcount discarded. Jump to the questions and answers
+ byte_count = 12;
+
+ // Skip the question...
+ byte_count += skip_name( (char *)&eth_buffer[UDP_DATA_START + byte_count] );
+ byte_count += 4; //QTYPE + QCLASS
+
+ // now the answer:
+ while(answ_cnt > 0)
+ {
+ // first byte of the ARR determines a compressed record or a normal one.
+ if( (eth_buffer[UDP_DATA_START + byte_count] & 0xc0) != 0 ) // Compressed name
+ { // the remaining 14 bits
+ byte_count += 2; // of the 2 bytes are the pointer
+ // to the name... but ignored
+ }
+ else // Not compressed...
+ {
+ byte_count += skip_name( (char *)&eth_buffer[UDP_DATA_START + byte_count] );
+ }
+
+ antype = eth_buffer[UDP_DATA_START + byte_count++]*256;
+ antype += eth_buffer[UDP_DATA_START + byte_count++];
+ //DNS_DEBUG("TYPE %4x\r\n",antype);
+ anclass = eth_buffer[UDP_DATA_START + byte_count++]*256;
+ anclass += eth_buffer[UDP_DATA_START + byte_count++];
+ //DNS_DEBUG("CLASS %4x\r\n",anclass);
+
+ // skip TTL
+ byte_count += 4;
+
+ rdlen = eth_buffer[UDP_DATA_START + byte_count++]*256;
+ rdlen += eth_buffer[UDP_DATA_START + byte_count++];
+ //DNS_DEBUG("RDLEN %4x\r\n",rdlen);
+
+ // Check for IP address type and Internet class. Others are discarded.
+ if(antype == 1 && anclass == 1 && rdlen == 4 )
+ {
+ ip[0] = eth_buffer[UDP_DATA_START + byte_count++];
+ ip[1] = eth_buffer[UDP_DATA_START + byte_count++];
+ ip[2] = eth_buffer[UDP_DATA_START + byte_count++];
+ ip[3] = eth_buffer[UDP_DATA_START + byte_count++];
+ DNS_DEBUG("IP address %1i.%1i.%1i.%1i\r\n",ip[0], ip[1], ip[2], ip[3]);
+ if ( dns_state != DNS_STATE_FINISHED )
+ {
+ (*((unsigned long*)&dns_resolved_ip[0])) = (*((unsigned long*)&ip[0]));
+ dns_state = DNS_STATE_FINISHED;
+ }
+ }
+ else
+ {
+ byte_count += rdlen;
+ }
+ answ_cnt -= 1;
+ } //while answ_cnt >0
+}
+/*---------------------------------------------------------------------------*/
+#endif //USE_DNS
+
View
48 ethernet-light-control/dnsc.h
@@ -0,0 +1,48 @@
+/*----------------------------------------------------------------------------
+ Copyright: Michael Kleiber
+ Author: Michael Kleiber
+ Remarks:
+ known Problems: none
+ Version: 25.04.2008
+ Description: DNS Client
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#if USE_DNS
+#ifndef _DNSCLIENT_H
+ #define _DNSCLIENT_H
+
+ //#define DNS_DEBUG usart_write
+ #define DNS_DEBUG(...)
+
+ #define DNS_CLIENT_PORT 1078
+ #define DNS_SERVER_PORT 53
+
+ #define DNS_IP_EEPROM_STORE 42
+
+ extern unsigned char dns_server_ip[4];
+ extern unsigned char dns_resolved_ip[4];
+ volatile unsigned int dns_timer;
+
+ extern void dns_init(void);
+ extern unsigned char dns_resolve (char *name);
+ extern void dns_query(char *name);
+ extern void dns_get(void);
+
+
+#endif //_DNSCLIENT_H
+#endif //USE_DNS
+
View
110 ethernet-light-control/http_get.c
@@ -0,0 +1,110 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 12.11.2007
+ Description: HTTP-Client (empfang einer Webseite)
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include "http_get.h"
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include "stack.h"
+#include "usart.h"
+#include "timer.h"
+
+PROGMEM char WEATHER_GET_STRING[] = {"GET /globalweather.asmx/GetWeather?CityName=Paderborn&CountryName=Germany HTTP/1.1\r\n"
+ //"GET / HTTP/1.1\r\n"
+ "Host: www.webservicex.net\r\n"
+ //"Host: www.ulrichradig.de\r\n"
+ "Keep-Alive: 300\r\n"
+ "Connection: Keep-Alive\r\n\r\n"};
+
+volatile unsigned int http_get_state = 0;
+
+//----------------------------------------------------------------------------
+//Daten kommen von einem Webserver an!!
+void test (unsigned char index)
+{
+ for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++)
+ {
+ HTTPC_DEBUG("%c",eth_buffer[a]);
+ }
+ tcp_entry[index].time = TCP_TIME_OFF;
+ tcp_entry[index].status = ACK_FLAG;
+ create_new_tcp_packet(0,index);
+}
+
+//----------------------------------------------------------------------------
+//HTTP Request an einen Webserver stelle
+void http_request (void)
+{
+ unsigned long index = MAX_TCP_ENTRY;
+
+ if (http_get_state > 1 && http_get_state < 20) http_get_state++;
+
+ if (http_get_state == 0)
+ {
+ //offnet eine Verbindung zu meinem Webserver
+ HTTPC_DEBUG("ARP Request\n\r");
+ unsigned int my_http_cp = 2354;
+ add_tcp_app (my_http_cp, (void(*)(unsigned char))test);
+
+ //ARP Request senden
+ if(arp_request (WEATHER_SERVER_IP))
+ {
+ for(unsigned long a=0;a<2000000;a++){asm("nop");};
+
+ tcp_port_open (WEATHER_SERVER_IP,HTONS(80),HTONS(my_http_cp));
+
+ unsigned char tmp_counter = 0;
+ while((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1))
+ {
+ index = tcp_entry_search (WEATHER_SERVER_IP,HTONS(80));
+ if (tmp_counter++ > 30)
+ {
+ HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n");
+ return;
+ }
+ }
+
+ HTTPC_DEBUG("TCP Eintrag gefunden (HTTP_CLIENT)!\r\n");
+ tcp_entry[index].first_ack = 1;
+ http_get_state = 2;
+ }
+ else
+ {
+ http_get_state = 1;
+ }
+ }
+
+ //if (http_get_state == 10)
+ if (http_get_state > 10 && http_get_state < 20)
+ {
+ HTTPC_DEBUG("\r\n\r\n\r\nDaten Anfordern\r\n");
+ index = tcp_entry_search (WEATHER_SERVER_IP,HTONS(80));
+ memcpy_P(&eth_buffer[TCP_DATA_START],WEATHER_GET_STRING,(sizeof(WEATHER_GET_STRING)-1));
+ tcp_entry[index].status = ACK_FLAG | PSH_FLAG;
+ create_new_tcp_packet((sizeof(WEATHER_GET_STRING)-1),index);
+ }
+}
+
+
+
+
View
39 ethernet-light-control/http_get.h
@@ -0,0 +1,39 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 12.11.2007
+ Description: HTTP-Client
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+
+//!!!!!!*************EXPERIMENTAL*************!!!!!!
+
+#ifndef _HTTPCLIENT_H
+ #define _HTTPCLIENT_H
+
+ #define HTTPC_DEBUG usart_write
+ //#define HTTPC_DEBUG(...)
+
+ #define WEATHER_SERVER_IP IP(209,162,186,60)
+ //#define WEATHER_SERVER_IP IP(87,106,58,153)
+
+ extern void http_request (void);
+ extern void test (unsigned char);
+
+#endif
View
587 ethernet-light-control/httpd.c
@@ -0,0 +1,587 @@
+/*----------------------------------------------------------------------------
+ Copyright: Radig Ulrich mailto: mail@ulrichradig.de
+ Author: Radig Ulrich
+ Remarks:
+ known Problems: none
+ Version: 24.10.2007
+ Description: Webserver Applikation
+
+ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der
+ GNU General Public License, wie von der Free Software Foundation veröffentlicht,
+ weitergeben und/oder modifizieren, entweder gemäß Version 2 der Lizenz oder
+ (nach Ihrer Option) jeder späteren Version.
+
+ Die Veröffentlichung dieses Programms erfolgt in der Hoffnung,
+ daß es Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE,
+ sogar ohne die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT
+ FÜR EINEN BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
+
+ Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
+ Programm erhalten haben.
+ Falls nicht, schreiben Sie an die Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+------------------------------------------------------------------------------*/
+#include "config.h"
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "stack.h"
+#include "base64.h"
+#include "analog.h"
+#include "wol.h"
+#include "timer.h"
+#include "usart.h"
+
+
+#if USE_CAM
+#include "camera/cam.h"
+#endif //USE_CAM
+
+#include "httpd.h"
+#include "webpage.h"
+#include "lcd.h"
+#include "ntp.h"
+
+struct http_table http_entry[MAX_TCP_ENTRY];
+
+//Hier wird das codierte Passwort aus config.h gespeichert.
+unsigned char http_auth_passwort[30];
+
+unsigned char post_in[5] = {'O','U','T','='};
+unsigned char post_ready[5] = {'S','U','B','='};
+unsigned char PORT_tmp = 0;
+char dstr[24]={"No Time... "};
+
+//----------------------------------------------------------------------------
+//Variablenarry zum einfügen in Webseite %VA@00 bis %VA@09
+unsigned int var_array[MAX_VAR_ARRAY] = {10,50,30,0,0,0,0,0,0,0};
+//----------------------------------------------------------------------------
+
+//TEXT_PLAIN
+PROGMEM char http_header0[]={ "HTTP/1.0 200 Document follows\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ "Content-Type: text/plain\r\n\r\n"};
+//TEXT_HTML
+PROGMEM char http_header1[]={ "HTTP/1.0 200 Document follows\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ "Content-Type: text/html\r\n\r\n"};
+//TEXT_HTML_AUTH
+PROGMEM char http_header2[]={ "HTTP/1.0 401 Unauthorized\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ "WWW-Authenticate: Basic realm=\"NeedPassword\""
+ "\r\nContent-Type: text/html\r\n\r\n"};
+//IMAGE_JPEG
+PROGMEM char http_header3[]={ "HTTP/1.0 200 Document follows\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ "Content-Type: image/jpeg\r\n\r\n"};
+//IMAGE_GIF
+PROGMEM char http_header4[]={ "HTTP/1.0 200 Document follows\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ /*"Last-Modified: Fri, 08 Jul 2008 16:48:29 GMT"*/
+ "Cache-Control: max-age=6000000"
+ /*"Expires: Fri, 08 Jul 2010 16:48:29 GMT"*/
+ "Content-Type: image/gif\r\n\r\n"};
+//TEXT_CSS
+PROGMEM char http_header5[]={ "HTTP/1.0 200 Document follows\r\n"
+ "Server: AVR_Small_Webserver\r\n"
+ /*"Last-Modified: Fri, 08 Jul 2008 16:48:29 GMT"*/
+ "Cache-Control: max-age=6000000"
+ /*"Expires: Fri, 08 Jul 2010 16:48:29 GMT"*/
+ "Content-Type: text/css\r\n\r\n"};
+
+
+
+//----------------------------------------------------------------------------
+//Kein Zugriff Seite bei keinem Passwort
+PROGMEM char Page0[] = {"401 Unauthorized%END"};
+
+unsigned char rx_header_end[5] = {"\r\n\r\n\0"};
+
+//----------------------------------------------------------------------------
+//Initialisierung des Httpd Testservers
+void httpd_init (void)
+{
+ //HTTP_AUTH_STRING
+ decode_base64((unsigned char*)HTTP_AUTH_STRING,http_auth_passwort);
+
+ //Serverport und Anwendung eintragen
+ add_tcp_app (HTTPD_PORT, (void(*)(unsigned char))httpd);
+}
+
+//----------------------------------------------------------------------------
+//http Testserver
+void httpd (unsigned char index)
+{
+ //Verbindung wurde abgebaut!
+ if (tcp_entry[index].status & FIN_FLAG)
+ {
+ return;
+ }
+
+ //Allererste Aufruf des Ports für diese Anwendung
+ //HTTPD_Anwendungsstack löschen
+ if(tcp_entry[index].app_status==1)
+ {
+ httpd_stack_clear(index);
+ }
+
+ //HTTP wurde bei dieser Verbindung zum ersten mal aufgerufen oder
+ //HTML Header Retransmission!
+ if (tcp_entry[index].app_status <= 2)
+ {
+ httpd_header_check (index);
+ return;
+ }
+
+ //Der Header wurde gesendet und mit ACK bestätigt (tcp_entry[index].app_status+1)
+ //war das HTML Packet fertig, oder müssen weitere Daten gesendet werden, oder Retransmission?
+ if (tcp_entry[index].app_status > 2 && tcp_entry[index].app_status < 0xFFFE)
+ {
+ httpd_data_send (index);
+ return;
+ }
+
+ //Verbindung kann geschlossen werden! Alle HTML Daten wurden gesendet TCP Port kann
+ //geschlossen werden (tcp_entry[index].app_status >= 0xFFFE)!!
+ if (tcp_entry[index].app_status >= 0xFFFE)
+ {
+ tcp_entry[index].app_status = 0xFFFE;
+ tcp_Port_close(index);
+ return;
+ }
+ return;
+}
+
+//----------------------------------------------------------------------------
+//HTTPD_STACK löschen
+void httpd_stack_clear (unsigned char index)
+{
+ http_entry[index].http_header_type = TEXT_HTML;
+ http_entry[index].first_switch = 0;
+ http_entry[index].http_auth = HTTP_AUTH_DEFAULT;
+ http_entry[index].new_page_pointer = 0;
+ http_entry[index].old_page_pointer = 0;
+ http_entry[index].post = 0;
+ http_entry[index].auth_ptr = http_auth_passwort;
+ http_entry[index].post_ptr = post_in;
+ http_entry[index].post_ready_ptr = post_ready;
+ http_entry[index].hdr_end_pointer = rx_header_end;
+ #if USE_CAM
+ http_entry[index].cam = 0;
+ #endif //USE_CAM
+ HTTP_DEBUG("\r\n**** NEUE HTTP ANFORDERUNG ****\r\n\r\n");
+ return;
+}
+
+//----------------------------------------------------------------------------
+//Eintreffenden Header vom Client checken
+void httpd_header_check (unsigned char index)
+{
+ unsigned int a = 0;
+
+ if(strcasestr_P((char*)&eth_buffer[TCP_DATA_START_VAR],PSTR("POST"))!=0)
+ {
+ http_entry[index].post = 1;
+ }
+
+ //finden der Authorization und das Ende im Header auch über mehrere Packete hinweg!!
+ if(*http_entry[index].hdr_end_pointer != 0)
+ {
+ for(a=TCP_DATA_START_VAR;a<(TCP_DATA_END_VAR);a++)
+ {
+ HTTP_DEBUG("%c",eth_buffer[a]);
+
+ if(!http_entry[index].http_auth)
+ {
+ if (eth_buffer[a] != *http_entry[index].auth_ptr++)
+ {
+ http_entry[index].auth_ptr = http_auth_passwort;
+ }
+ if(*http_entry[index].auth_ptr == 0)
+ {
+ http_entry[index].http_auth = 1;