Permalink
Browse files

move a LOT around and fix the system broadcasting.

DHCP stil ldoesn't work.
  • Loading branch information...
cnlohr committed Aug 7, 2013
1 parent ce54dcd commit 09ad7e6f4b6e0c624839b79c32ea15f7bd4d3e95
@@ -2,6 +2,7 @@ all : program.hex burn program.lst
CC = avr-gcc
SRCS = test.c \
+ dumbgame.c \
../libs/avr_print.c \
../ipcore/enc424j600.c \
../ipcore/iparpetc.c \
@@ -15,15 +16,18 @@ SRCS = test.c \
PROCESSOR=atmega328
PROGRAMCODE=m328
+#CPUFREQ=28636363UL
+CPUFREQ=20000000UL
COMMON_FLAGS= -mmcu=$(PROCESSOR) -I. -I.. -I../http -I../microsd -I../libs -I../ipcore -I../dumbcraft
-CFLAGS = -std=gnu99 -Os $(COMMON_FLAGS) -DF_CPU=28636363UL -DNO_HTTP #-DMUTE_PRINTF #-DNO_HTTP #-Wall
+CFLAGS = -std=gnu99 -Os $(COMMON_FLAGS) -DF_CPU=$(CPUFREQ) -DNO_HTTP #-DMUTE_PRINTF #-DNO_HTTP #-Wall
+CFLAGS:=$(CFLAGS) --combine -fwhole-program
AS = avr-gcc
ASFLAGS = $(COMMON_FLAGS) -c
EXTRA_LD_FLAGS=-Wl,--relax -Wa,-a,-ad -mcall-prologues
program.elf : $(SRCS)
- avr-gcc --combine -fwhole-program -I -mmcu=$(PROCESSOR) $(CFLAGS) -o $@ $^ -L /usr/lib64/binutils/avr/2.19.1 $(EXTRA_LD_FLAGS) > program.lst
+ avr-gcc -I -mmcu=$(PROCESSOR) $(CFLAGS) -o $@ $^ -L /usr/lib64/binutils/avr/2.19.1 $(EXTRA_LD_FLAGS) > program.lst
avr-size -A $@
@echo "Total = .data + .text"
avr-objdump program.elf -t > program.map
@@ -42,13 +42,15 @@
// static void PlayerUpdate( uint8_t playerid );
// static void DoCustomPreloadStep( uint8_t playerid );
// static void InitDumbgame();
+// int ClientHandleChat( chat, chatlen ); //return 1 if you want the chat to propogate.
/* General notes for writing the game portion:
1) You have a limited send-size, it's around 512 bytes. Split up your commands among multiple packets.
2) Do not send when receiving. Add extra flags to the player structure to send when it's time to send.
*/
-
+#include "dumbcraft.h"
+#include <string.h>
uint8_t regaddr_set;
uint8_t regval_set;
@@ -59,12 +61,12 @@ volatile uint8_t regval_get;
uint8_t hasset_value;
uint8_t latch_setting_value;
-static void InitDumbgame()
+void InitDumbgame()
{
//no code.
}
-static void DoCustomPreloadStep( uint8_t playerid )
+void DoCustomPreloadStep( uint8_t playerid )
{
struct Player * p = &Players[playerid];
@@ -98,7 +100,7 @@ static void DoCustomPreloadStep( uint8_t playerid )
p->need_to_send_lookupdate = 1;
}
-static void PlayerTickUpdate( int playerid )
+void PlayerTickUpdate( int playerid )
{
//printf( "%f %f %f\n", SetDouble(p->x), SetDouble(p->y), SetDouble(p->z) );
struct Player * p = &Players[playerid];
@@ -117,7 +119,7 @@ static void PlayerTickUpdate( int playerid )
}
}
-static void PlayerClick( uint8_t playerid, uint8_t x, uint8_t y, uint8_t z )
+void PlayerClick( uint8_t playerid, uint8_t x, uint8_t y, uint8_t z )
{
struct Player * p = &Players[playerid];
@@ -168,7 +170,7 @@ static void PlayerClick( uint8_t playerid, uint8_t x, uint8_t y, uint8_t z )
}
-static void PlayerUpdate( uint8_t playerid )
+void PlayerUpdate( uint8_t playerid )
{
uint8_t i;
struct Player * p = &Players[playerid];
@@ -237,4 +239,22 @@ static void PlayerUpdate( uint8_t playerid )
}
}
+
+void SetServerName( const char * stname );
+
+uint8_t ClientHandleChat( char * chat, uint8_t chatlen )
+{
+ if( chat[0] == '/' )
+ {
+ if( strncmp( &chat[1], "title", 5 ) == 0 && chatlen > 8 )
+ {
+ chat[chatlen] = 0;
+ SetServerName( &chat[7] );
+ return 0;
+ }
+ }
+ return chatlen;
+}
+
+
#endif
@@ -51,6 +51,11 @@
//Do this to disable printf's and save space
//#define MUTE_PRINTF
+
+//DHCP will allow your device to automatically acquire an IP address.
+#define ENABLE_DHCP_CLIENT
+
+
//UDP is pretty well tested. It takes up ~350 bytes
//If you use UDP, you will need to implement the following function:
// void HandleUDP( uint16_t len ) { ... }
@@ -86,10 +91,11 @@
//Additional applications
+#ifndef NO_HTTP
#define INCLUDE_HTTP_SERVER
#define HTTP_SERVER_TIMEOUT (10000)
#define HTTP_CONNECTIONS 6
-
+#endif
//Scratchpad for sending out packets like UDP, ICMP, ARP, etc.
#define TX_SCRATCHPAD_END 1024
View
@@ -14,6 +14,7 @@
#include <http.h>
#include <string.h>
#include <basicfat.h>
+#include <avr/eeprom.h>
/*
Useful ports:
@@ -53,6 +54,14 @@ unsigned char cc;
int8_t lastconnection = -1; //for dumbcraft
uint16_t bytespushed; //for dumbcraft
+uint8_t EEMEM my_server_name_eeprom[16];
+char my_server_name[16];
+
+void SetServerName( const char * stname )
+{
+ memcpy( my_server_name, stname, strlen( stname ) + 1 );
+ eeprom_write_block( stname, my_server_name_eeprom, strlen( stname ) + 1 );
+}
#ifdef NO_HTTP
#undef HTTP_CONNECTIONS
@@ -324,7 +333,7 @@ void HTTPCustomCallback( )
unsigned char MyIP[4] = { 192, 168, 0, 142 };
unsigned char MyMask[4] = { 255, 255, 255, 0 };
-
+unsigned char MyGateway[4] = { 192, 168, 0, 1 };
unsigned char MyMAC[6];
@@ -340,6 +349,10 @@ int main( void )
sendstr( "HELLO\n" );
setup_clock();
+ eeprom_read_block( &my_server_name[0], &my_server_name_eeprom[0], 16 );
+ if( my_server_name[0] == 0 || my_server_name[0] == (char)0xff )
+ SetServerName( "AVRCraft" );
+
//Configure T2 to "overflow" at 100 Hz, this lets us run the TCP clock
TCCR2A = _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS22) | _BV(CS21) | _BV(CS20);
@@ -375,6 +388,8 @@ int main( void )
}
sendstr( "OK.\n" );
+ SetupDHCPName( my_server_name );
+
InitDumbcraft();
while(1)
@@ -400,6 +415,7 @@ int main( void )
delayctr++;
if( delayctr==10 )
{
+ TickDHCP();
delayctr = 0;
TickServer();
}
Oops, something went wrong.

0 comments on commit 09ad7e6

Please sign in to comment.