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

From C4 Wiki
Jump to: navigation, search
(Projekt)
 
(15 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
aus Köln
 
aus Köln
  
==Team==
+
Motto: "Schrauben lieben Dunkelheit."
 +
 
 +
== Team ==
 
* Stefan
 
* Stefan
 
* Philipp
 
* Philipp
 
* Sebi
 
* Sebi
 
* Hanno
 
* Hanno
 +
* Mikael
  
==Links==
+
== Links ==
  
 
:'''I2C'''
 
:'''I2C'''
Line 15: Line 18:
 
:http://www.roboternetz.de/wissen/index.php/I2C
 
:http://www.roboternetz.de/wissen/index.php/I2C
  
==Projekt==
+
== Projekt==
===Idee===
+
=== Beschreibung ===
 +
Wir steuern mit dem etherape einen Hardware Audio Tuner Chip(tda 7318 [http://www.reichelt.de/?ACTION=7;LA=6;OPEN=1;INDEX=0;FILENAME=A200%252FTDA7318_STM.pdf 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-26 ====
 +
 
 +
* TDA7318-Code ins git-Repository aufgenommen
 +
** Fuer Schreibzugriff bitte bei Mikael melden
 +
* HTTP-Server sollte nach einigen Anlaufschwierigkeiten und einem "rewrite from scratch" endlich laufen
 +
** Benutzt nun memcmp_P und memmem_P zum parsen
 +
** Kann bereits den TDA7318-Status ausgeben
 +
** Muss noch getestet werden!
 +
 
 +
==== 2007-06-18 ====
 +
 
 +
Wir können auf der Seriellen-Console dem etherape Befehle geben, mit den denn dann alles ansteuern kann!<br />
 +
[http://h-lemoine.de/cccc_u23/etherrape_2007-06-18_V2_22_05Uhr.tar.gz 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?
 
Haben wir nun schon ein Ziel?
 
Vorschläge bitte :D
 
Vorschläge bitte :D
Line 43: Line 72:
 
@Hanno: Ja Monitoring interessiert mich auch besonders. --Philipp
 
@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.
  
==HTTP SERVER==
+
=== git ===
  
===zerohttp.c===
+
Das [http://de.wikipedia.org/wiki/Git Git]-Repository kann man sich mit folgendem Kommando besorgen:
  
[http://www.haemoglobin.org/U23_2007/zerohttp.c zerohttp.c]
 
 
<pre>
 
<pre>
#include <string.h>
+
git clone git://git.haemoglobin.org/etherrape
 +
cd etherrape
 +
git checkout zerohttp
 +
</pre>
  
#include "tokenize.h"
+
=== zerohttp.c ===
  
void zerohttp_invalid(char *data) {
+
[http://www.haemoglobin.org/U23_2007/zerohttp.c zerohttp.c]
strcpy_P(data, 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(data, strlen(data));
 
}
 
  
void zerohttp_succeed(char *data) {
+
<pre>
strcpy_P(data, PSTR("HTTP/1.1 200 OK\r\n"
+
#include <avr/io.h>
"Server: zerohttp\r\n"
+
#include <avr/pgmspace.h>
"Connection: close\r\n"
+
#include <string.h>
"Content-Type: text/plain\r\n\r\n"
 
"Thy wish is my command."));
 
uip_send(data, strlen(data));
 
}
 
  
void zerohttp_fail(char *data) {
+
#include "../uip/uip.h"
strcpy_P(data, PSTR("HTTP/1.1 404 Command not found\r\n"
+
#include "../tda7318.h"
"Server: zerohttp\r\n"
+
#include "../debug.h"
"Connection: close\r\n"
 
"Content-Type: text/plain\r\n\r\n"
 
"I could not fullfill thy humbly wish."));
 
uip_send(data, strlen(data));
 
}
 
  
 
void zerohttp_main() {
 
void zerohttp_main() {
char *data = (char*) uip_appdata;
+
if(uip_acked())
+
uip_close();
register char *garbage;
 
char *uri;
 
  
 +
if(uip_newdata()) {
 +
debug_printf("Parsing request...\n");
  
uip_listen(HTONS(80));
+
if(uip_datalen() < 17) { // At least "GET / HTTP/1.1\r\n"
 
+
debug_printf("Request is smaller than 17 bytes!\n");
if(uip_newdata()) {
+
uip_conn->appstate.zerohttp = 2;
garbage = strtokz(data, ' ');
+
goto leave;
if(garbage) {
 
zerohttp_invalid(data);
 
uip_close();
 
 
}
 
}
  
if(strncmp(garbage, PSTR("GET"), 4)) {
+
if(memcmp_P(uip_appdata, PSTR("GET "), 4)) {
zerohttp_invalid(data);
+
debug_printf("Method is not GET!\n");
uip_close();
+
uip_conn->appstate.zerohttp = 2;
 +
goto leave;
 
}
 
}
  
uri = strtokz(NULL, ' ');
+
register char *temp = (char *) memmem_P((char *) uip_appdata + 4, " HTTP/", uip_datalen() - 4);
if(uri) {
+
if(!temp) {
zerohttp_invalid(data);
+
debug_printf("Unterminated URI!\n");
uip_close();
+
uip_conn->appstate.zerohttp = 2;
 +
goto leave;
 
}
 
}
  
garbage = strtokz(NULL, '\r');
+
if(!memcmp_P((char *) uip_appdata + 4, PSTR("/"), 1)) {
if(garbage) {
+
debug_printf("Requested '/'\n");
zerohttp_invalid(data);
+
uip_conn->appstate.zerohttp = 0;
uip_close();
+
goto leave;
 
}
 
}
  
if(strncmp(garbage, PSTR("HTTP/1.0"), 9) && strncmp(garbage, PSTR("HTTP/1.1"), 9)) {
+
else if(!memcmp_P((char *) uip_appdata + 4, PSTR("/volinc"), 7)) {
zerohttp_invalid(data);
+
debug_printf("Requested '/volinc'\n");
uip_close();
+
uip_conn->appstate.zerohttp = 0;
 +
goto leave;
 
}
 
}
  
if(!strncmp(uri, PSTR("http://"), 7))
 
uri += 7;
 
else
 
uri++;
 
 
if(!strncmp(uri, PSTR("lauter"), 7)) {
 
// Lauter!
 
zerohttp_succeed();
 
uip_close();
 
}
 
else if(!strncmp(uri, PSTR("leiser"), 7)) {
 
// Leiser!
 
zerohttp_succeed();
 
uip_close();
 
}
 
 
else {
 
else {
zerohttp_fail();
+
debug_printf("Unknown URI\n");
uip_close();
+
uip_conn->appstate.zerohttp = 1;
}
+
goto leave;
 
 
}
 
}
 
 
 
</pre>
 
 
 
===tokenize.c===
 
 
 
[http://www.haemoglobin.org/U23_2007/tokenize.c tokenize.c]
 
<pre>
 
/*
 
* Copyright © MMVII
 
*      Mikael Voss <ffefd6 at haemoglobin dot org>
 
*
 
* 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.
 
*/
 
 
 
/*
 
* strtokn parses a string of length bytes into a sequence of tokens
 
* separated by delimiter. On the first call the string to be parsed
 
* should be specified in string and its size in length. On each sub-
 
* 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) {
 
static char *next;
 
static unsigned int rest;
 
register unsigned int iterator;
 
 
 
if(string != (char *) 0) {
 
next = string;
 
rest = length;
 
}
 
 
 
for(iterator = 0; iterator < rest; iterator++) {
 
if(next[iterator] == delimiter) {
 
next[iterator] = '\0';
 
string = next;
 
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]]

Latest revision as of 09:31, 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-26

  • TDA7318-Code ins git-Repository aufgenommen
    • Fuer Schreibzugriff bitte bei Mikael melden
  • HTTP-Server sollte nach einigen Anlaufschwierigkeiten und einem "rewrite from scratch" endlich laufen
    • Benutzt nun memcmp_P und memmem_P zum parsen
    • Kann bereits den TDA7318-Status ausgeben
    • Muss noch getestet werden!

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));
	}
}