Difference between revisions of "U23 2007/NULL.0"

From C4 Wiki
Jump to: navigation, search
(2007-06-18)
(HTTP-Server)
Line 62: Line 62:
  
 
== HTTP-Server ==
 
== HTTP-Server ==
 +
 +
Nach einigen Anlaufschwierigkeiten sollte es nun endlich gelungen sein, unseren Pseudo-HTTP-Server zum Laufen gebracht zu haben.
  
 
=== git ===
 
=== git ===
Line 83: Line 85:
  
 
#include "../uip/uip.h"
 
#include "../uip/uip.h"
#include "tokenize.h"
+
#include "../tda7318.h"
 
+
#include "../debug.h"
#ifndef NULL
 
#define NULL (char *) 0
 
#endif
 
 
 
void zerohttp_invalid() {
 
        strcpy_P(uip_appdata, PSTR("HTTP/1.1 400 Invalid request\r\n"
 
        "Server: zerohttp\r\n"
 
        "Connection: close\r\n"
 
        "Content-Type: text/plain\r\n\r\n"
 
        "Invalid request!"));
 
        uip_send(uip_appdata, strlen(uip_appdata));
 
}
 
 
 
void zerohttp_succeed() {
 
        strcpy_P(uip_appdata, PSTR("HTTP/1.1 200 OK\r\n"
 
        "Server: zerohttp\r\n"
 
        "Connection: close\r\n"
 
        "Content-Type: text/plain\r\n\r\n"
 
        "Thy wish is my command."));
 
        uip_send(uip_appdata, strlen(uip_appdata));
 
}
 
 
 
void zerohttp_fail() {
 
        strcpy_P(uip_appdata, PSTR("HTTP/1.1 404 Command not found\r\n"
 
        "Server: zerohttp\r\n"
 
        "Connection: close\r\n"
 
        "Content-Type: text/plain\r\n\r\n"
 
        "I could not fullfill thy humble wish."));
 
        uip_send(uip_appdata, strlen(uip_appdata));
 
}
 
  
 
void zerohttp_main() {
 
void zerohttp_main() {
        register char *garbage;
+
if(uip_acked())
        char *uri;
+
uip_close();
  
        if(uip_newdata()) {
+
if(uip_newdata()) {
                garbage = strtokz(uip_appdata, ' ');
+
debug_printf("Parsing request...\n");
                if(garbage) {
 
                        zerohttp_invalid();
 
                        uip_close();
 
return;
 
                }
 
               
 
                if(strncmp_P(garbage, PSTR("GET"), 4)) {
 
                        zerohttp_invalid();
 
                        uip_close();
 
return;
 
                }
 
               
 
                uri = strtokz(NULL, ' ');
 
                if(uri) {
 
                        zerohttp_invalid();
 
                        uip_close();
 
return;
 
                }
 
               
 
                garbage = strtokz(NULL, '\r');
 
                if(garbage) {
 
zerohttp_invalid();
 
                        uip_close();
 
return;
 
                }
 
               
 
                if(strncmp_P(garbage, PSTR("HTTP/1.0"), 9) && strncmp(garbage, PSTR("HTTP/1.1"), 9)) {
 
                        zerohttp_invalid();
 
                        uip_close();
 
return;
 
                }
 
       
 
                if(!strncmp_P(uri, PSTR("http://"), 7))
 
                        uri += 7;
 
                else
 
                        uri++;
 
               
 
                if(!strncmp_P(uri, PSTR("lauter"), 7)) {
 
                        // Lauter!
 
                        zerohttp_succeed();
 
                        uip_close();
 
return;
 
                }
 
                else if(!strncmp_P(uri, PSTR("leiser"), 7)) {
 
                        // Leiser!
 
                        zerohttp_succeed();
 
                        uip_close();
 
return;
 
                }
 
                else {         
 
                        zerohttp_fail();
 
                        uip_close();
 
return;
 
                }
 
               
 
        }     
 
}
 
</pre>
 
  
===tokenize.c===
+
if(uip_datalen() < 17) { // At least "GET / HTTP/1.1\r\n"
 +
debug_printf("Request is smaller than 17 bytes!\n");
 +
uip_conn->appstate.zerohttp = 2;
 +
goto leave;
 +
}
  
[http://www.haemoglobin.org/U23_2007/tokenize.c tokenize.c]
+
if(memcmp_P(uip_appdata, PSTR("GET "), 4)) {
 +
debug_printf("Method is not GET!\n");
 +
uip_conn->appstate.zerohttp = 2;
 +
goto leave;
 +
}
  
<pre>
+
register char *temp = (char *) memmem_P((char *) uip_appdata + 4, " HTTP/", uip_datalen() - 4);
/*
+
if(!temp) {
* Copyright © MMVII
+
debug_printf("Unterminated URI!\n");
*      Mikael Voss <ffefd6 at haemoglobin dot org>
+
uip_conn->appstate.zerohttp = 2;
*
+
goto leave;
* Provided that these terms and disclaimer and all copyright notices
+
}
* are retained or reproduced in an accompanying document, permission
 
* is granted to deal in this work without restriction, including un-
 
* limited rights to use, publicly perform, distribute, sell, modify,
 
* merge, give away, or sublicence.
 
*
 
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
 
* the utmost extent permitted by applicable law, neither express nor
 
* implied; without malicious intent or gross negligence. In no event
 
* may a licensor, author or contributor be held liable for indirect,
 
* direct, other damage, loss, or other issues arising in any way out
 
* of dealing in the work, even if advised of the possibility of such
 
* damage or existence of a defect, except proven that it results out
 
* of said person's immediate fault when using the work as intended.
 
*/
 
  
/*
+
if(!memcmp_P((char *) uip_appdata + 4, PSTR("/"), 1)) {
* strtokn parses a string of length bytes into a sequence of tokens
+
debug_printf("Requested '/'\n");
* separated by delimiter. On the first call the string to be parsed
+
uip_conn->appstate.zerohttp = 0;
* should be specified in string and its size in length. On each sub-
+
goto leave;
* sequent call that should parse the same string, string should be
+
}
* (char *) 0 and length will be ignored.
 
* It returns the next token delimited by delimiter or (char *) 0 if
 
* no other token is found.
 
*/
 
  
char *strtokn(char *string, unsigned int length, char delimiter) {
+
else if(!memcmp_P((char *) uip_appdata + 4, PSTR("/volinc"), 7)) {
static char *next;
+
debug_printf("Requested '/volinc'\n");
static unsigned int rest;
+
uip_conn->appstate.zerohttp = 0;
register unsigned int iterator;
+
goto leave;
 
+
}
if(string != (char *) 0) {
 
next = string;
 
rest = length;
 
}
 
  
for(iterator = 0; iterator < rest; iterator++) {
+
else {
if(next[iterator] == delimiter) {
+
debug_printf("Unknown URI\n");
next[iterator] = '\0';
+
uip_conn->appstate.zerohttp = 1;
string = next;
+
goto leave;
next += iterator + 1;
 
rest -= iterator - 1;
 
return string;
 
 
}
 
}
 
}
 
}
 +
leave:
  
return (char *) 0;
+
if(uip_newdata() || uip_rexmit()) {
}
+
switch(uip_conn->appstate.zerohttp) {
 
+
case 0:
 
+
debug_printf("200\n");
/*
+
snprintf_P((char *) uip_appdata,
* strtokz does the same as strtokn, but operates on a zero-terminated
+
  UIP_APPDATA_SIZE,
* string and thus does not take a length argument. Be careful as this
+
  PSTR("HTTP/1.1 200 OK\r\n"
* function might lead to buffer overflows if string is not properly
+
  "Server: zerohttp\r\n"
* terminated!
+
  "Connection: close\r\n"
*/
+
  "Content-Type: text/plain\r\n\r\n"
 +
  "Input: %hhu\r\n"
 +
  "Gain: %hhu\r\n"
 +
  "Master: %hhu\r\n"
 +
  "Front left: %hhu\r\n"
 +
  "Front right: %hhu\r\n"
 +
  "Rear left: %hhu\r\n"
 +
  "Rear right %hhu\r\n"
 +
  "Bass: %hhu\r\n"
 +
  "Treble: %hhu\r\n"),
 +
  (uint8_t) tda7318_global.input,
 +
  (uint8_t) tda7318_global.gain,
 +
  (uint8_t) tda7318_global.volume,
 +
  (uint8_t) tda7318_global.sp_LF,
 +
  (uint8_t) tda7318_global.sp_RF,
 +
  (uint8_t) tda7318_global.sp_LR,
 +
  (uint8_t) tda7318_global.sp_RR,
 +
  (uint8_t) tda7318_global.bass,
 +
  (uint8_t) tda7318_global.treble);
 +
break;
  
char *strtokz(char *string, char delimiter) {
+
case 1:
static char *next;
+
debug_printf("404\n");
 +
strncpy_P((char *) uip_appdata,
 +
  PSTR("HTTP/1.1 404 Command not found\r\n"
 +
  "Server: zerohttp\r\n"
 +
  "Connection: close\r\n"
 +
  "Content-Type: text/plain\r\n\r\n"
 +
  "I could not fullfill thy humble wish."),
 +
  UIP_APPDATA_SIZE);
 +
break;
  
if(string != (char *) 0)
+
case 2:
next = string;
+
default:
else
+
debug_printf("400\n");
string = next;
+
strncpy_P((char *) uip_appdata,
 +
  PSTR("HTTP/1.1 400 Invalid request\r\n"
 +
  "Server: zerohttp\r\n"
 +
  "Connection: close\r\n"
 +
  "Content-Type: text/plain\r\n\r\n"
 +
  "Invalid request!"),
 +
  UIP_APPDATA_SIZE);
 +
break;
  
while(*next++) {
 
if(*next == delimiter) {
 
*next++ = '\0';
 
return string;
 
 
}
 
}
 +
uip_send(uip_appdata, strnlen((char *) uip_appdata, UIP_APPDATA_SIZE));
 
}
 
}
 
return (char *) 0;
 
 
}
 
}
 
</pre>
 
 
=== tokenize.h ===
 
 
[http://www.haemoglobin.org/U23_2007/tokenize.h tokenize.h]
 
 
<pre>
 
char *strtokn(char *, unsigned int, char);
 
char *strtokz(char *, char);
 
 
</pre>
 
</pre>
  
 
[[Category:U23 2007]]
 
[[Category:U23 2007]]

Revision as of 09:22, 26 June 2007

Gruppe NULL.0

aus Köln

Motto: "Schrauben lieben Dunkelheit."

Team

  • Stefan
  • Philipp
  • Sebi
  • Hanno
  • Mikael

Links

I2C
http://www.roboternetz.de/wissen/index.php/I2C

Projekt

Beschreibung

Wir steuern mit dem etherape einen Hardware Audio Tuner Chip(tda 7318 Datenblatt) an. Dieser bietet uns 4 Stereo Eingänge, 4 Lautsprecher Ausgang, Bass- und Höhensteuerung sowie Hauptvolumen! Das wird zum Audiochip über I2C verbunden!

Momentaner Stand

2007-06-18

Wir können auf der Seriellen-Console dem etherape Befehle geben, mit den denn dann alles ansteuern kann!
Code vom 2007-06-18 Kommentar: Sorry, total unaufgeräumt! Mehr Infos in Anleitung.txt

audio
 	input 0-3 0-3	//Eingangssignal und Vorverstärkung! 0->laut 3->leise!
	vol 0-63	//Hauptausgangssignal                0->laut 63->leise [Standard 30]
	speaker 0-31 0-31 0-31 0-31 //Ausgangslautsprecher   0-laut 15->leise [Standard 15]
	bass 0-15	//Bass Einstellung                   Achtung Steuerung etwas doof! (vgl. Datenblatt S.11)
	treble 0-15	//Höhen Einstellung!

Der andre Teil der Gruppe beschäftigt sich mit dem Grafischen HTTP Server, damit man mit Schiebereglern bedienen kann!

Idee (alt)

Haben wir nun schon ein Ziel? Vorschläge bitte :D

Ich finde Server und Netzwerkgeschichten interessant: hier die die schon genannt wurden:

  1. NAS-Server zu Hause übers www einschalten(evtl. auch per Tel. zu aktivieren?) //dirtyheizer aka Marcus
  2. Network monitoring // Obstfliege aka Philipp
  3. Diverse Server: DHCP,DNS,FTP,HTTP... // Obstfliege aka Philipp

Hatten wir uns nicht grob auf folgendes geeinigt?

  • Audio Sound Steuerung
    • 4 analog Stereo in & 4 Lautsprecher out = front Rear Stero OUT
    • Lautstärkeregelung & Wahl des Einganges
    • WWW Interface
    • Infrarot Fernbedienung zum Ansteuern

Das waren dann 4 Teilprojekte (JavaScript, Infrarot, C-Software, Hardware Löten), das kann man teilweise noch aufteilen. Und beinhaltet so grob jedes Gebiet!
Aber ich weiß nicht, ob so nen Tuner so viel bringt. Mein Interesse ist da eher gering.

Alternativ:

  1. USB Ansteuerung

@Philipp deine Vorschläge sind aber auch ganz nett, auch wenn sie rein softwaremäßig ablaufen. Network Monitoring würde mich glaub ich am meisten interessieren. --Hanno 23:14, 31 May 2007 (CEST)

@Hanno: Ja Monitoring interessiert mich auch besonders. --Philipp

HTTP-Server

Nach einigen Anlaufschwierigkeiten sollte es nun endlich gelungen sein, unseren Pseudo-HTTP-Server zum Laufen gebracht zu haben.

git

Das Git-Repository kann man sich mit folgendem Kommando besorgen:

git clone git://git.haemoglobin.org/etherrape
cd etherrape
git checkout zerohttp

zerohttp.c

zerohttp.c

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <string.h>

#include "../uip/uip.h"
#include "../tda7318.h"
#include "../debug.h"

void zerohttp_main() {
	if(uip_acked())
		uip_close();

	if(uip_newdata()) {
		debug_printf("Parsing request...\n");

		if(uip_datalen() < 17) {	// At least "GET / HTTP/1.1\r\n"
			debug_printf("Request is smaller than 17 bytes!\n");
			uip_conn->appstate.zerohttp = 2;
			goto leave;
		}

		if(memcmp_P(uip_appdata, PSTR("GET "), 4)) {
			debug_printf("Method is not GET!\n");
			uip_conn->appstate.zerohttp = 2;
			goto leave;
		}

		register char *temp = (char *) memmem_P((char *) uip_appdata + 4, " HTTP/", uip_datalen() - 4);
		if(!temp) {
			debug_printf("Unterminated URI!\n");
			uip_conn->appstate.zerohttp = 2;
			goto leave;
		}

		if(!memcmp_P((char *) uip_appdata + 4, PSTR("/"), 1)) {
			debug_printf("Requested '/'\n");
			uip_conn->appstate.zerohttp = 0;
			goto leave;
		}

		else if(!memcmp_P((char *) uip_appdata + 4, PSTR("/volinc"), 7)) {
			debug_printf("Requested '/volinc'\n");
			uip_conn->appstate.zerohttp = 0;
			goto leave;
		}

		else {
			debug_printf("Unknown URI\n");
			uip_conn->appstate.zerohttp = 1;
			goto leave;
		}
	}
leave:

	if(uip_newdata() || uip_rexmit()) {
		switch(uip_conn->appstate.zerohttp) {
			case 0:
			 debug_printf("200\n");
			 snprintf_P((char *) uip_appdata,
			  UIP_APPDATA_SIZE,
			  PSTR("HTTP/1.1 200 OK\r\n"
			  "Server: zerohttp\r\n"
			  "Connection: close\r\n"
			  "Content-Type: text/plain\r\n\r\n"
			  "Input: %hhu\r\n"
			  "Gain: %hhu\r\n"
			  "Master: %hhu\r\n"
			  "Front left: %hhu\r\n"
			  "Front right: %hhu\r\n"
			  "Rear left: %hhu\r\n"
			  "Rear right %hhu\r\n"
			  "Bass: %hhu\r\n"
			  "Treble: %hhu\r\n"),
			  (uint8_t) tda7318_global.input,
			  (uint8_t) tda7318_global.gain,
			  (uint8_t) tda7318_global.volume,
			  (uint8_t) tda7318_global.sp_LF,
			  (uint8_t) tda7318_global.sp_RF,
			  (uint8_t) tda7318_global.sp_LR,
			  (uint8_t) tda7318_global.sp_RR,
			  (uint8_t) tda7318_global.bass,
			  (uint8_t) tda7318_global.treble);
			 break;

			case 1:
			 debug_printf("404\n");
			 strncpy_P((char *) uip_appdata,
			  PSTR("HTTP/1.1 404 Command not found\r\n"
			  "Server: zerohttp\r\n"
			  "Connection: close\r\n"
			  "Content-Type: text/plain\r\n\r\n"
			  "I could not fullfill thy humble wish."),
			  UIP_APPDATA_SIZE);
			 break;

			case 2:
			default:
			 debug_printf("400\n");
			 strncpy_P((char *) uip_appdata,
			  PSTR("HTTP/1.1 400 Invalid request\r\n"
			  "Server: zerohttp\r\n"
			  "Connection: close\r\n"
			  "Content-Type: text/plain\r\n\r\n"
			  "Invalid request!"),
			  UIP_APPDATA_SIZE);
			 break;

		}
		uip_send(uip_appdata, strnlen((char *) uip_appdata, UIP_APPDATA_SIZE));
	}
}