Clean up, functional webserver for further testing of low power protocols

This commit is contained in:
dak664 2010-02-28 21:29:19 +00:00
parent d61676b8f7
commit 39e6f6a830
6 changed files with 323 additions and 262 deletions

View file

@ -30,13 +30,14 @@
*
* @(#)$$
*/
#define ANNOUNCE_BOOT 1 //adds about 600 bytes to program size
#define DEBUG 1
#if DEBUG
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
int pingtimer1=0,pingtimer2=0;
#if RF230BB
extern int rf230_interrupt_flag;
extern char rf230_interrupt_flag, rf230processflag;
#endif
#else
#define PRINTF(...)
@ -67,21 +68,6 @@ extern int rf230_interrupt_flag;
//#include "dev/xmem.h"
//#include "net/rime.h"
#if 0
#if WITH_NULLMAC
#define MAC_DRIVER nullmac_driver
#endif /* WITH_NULLMAC */
#ifndef MAC_DRIVER
#ifdef MAC_CONF_DRIVER
#define MAC_DRIVER MAC_CONF_DRIVER
#else
#define MAC_DRIVER sicslowmac1_driver
//#define MAC_DRIVER cxmac_driver
#endif /* MAC_CONF_DRIVER */
#endif /* MAC_DRIVER */
#endif
#else //radio driver using Atmel/Cisco 802.15.4'ish MAC
#include <stdbool.h>
#include "mac.h"
@ -159,10 +145,12 @@ void initialize(void)
/* Redirect stdout to second port */
rs232_redirect_stdout(RS232_PORT_1);
clock_init();
#if ANNOUNCE_BOOT
printf_P(PSTR("\n*******Booting %s*******\n"),CONTIKI_VERSION_STRING);
#endif
/* rtimers not used yet */
// rtimer_init();
/* rtimers needed for radio cycling */
rtimer_init();
/* Initialize process subsystem */
process_init();
@ -170,10 +158,11 @@ void initialize(void)
process_start(&etimer_process, NULL);
#if RF230BB
{
ctimer_init();
/* Start radio and radio receive process */
rf230_init();
NETSTACK_RADIO.init();
//rf230_init();
/* Set addresses BEFORE starting tcpip process */
@ -193,36 +182,33 @@ void initialize(void)
PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);
framer_set(&framer_802154);
// process_start(&tcpip_process, NULL); //must be done before network inits?
/* Setup X-MAC for 802.15.4 */
queuebuf_init();
NETSTACK_RDC.init(); //prints rs2048
NETSTACK_RDC.init();
NETSTACK_MAC.init();
NETSTACK_NETWORK.init();
//todo: makes raven reboot
// printf(" %s, channel check rate %d Hz, radio channel %u\n",
// sicslowpan_mac->name,
// CLOCK_SECOND / (sicslowpan_mac->channel_check_interval() == 0? 1:
// sicslowpan_mac->channel_check_interval()),
// RF_CHANNEL);
// uip_ip6addr(&ipprefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
// uip_netif_addr_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0, AUTOCONF);
// uip_nd6_prefix_add(&ipprefix, UIP_DEFAULT_PREFIX_LEN, 0);
// PRINTF("Prefix %x::/%u\n",ipprefix.u16[0],UIP_DEFAULT_PREFIX_LEN);
#if ANNOUNCE_BOOT
printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel());
if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
unsigned short tmp;
tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
NETSTACK_RDC.channel_check_interval());
printf_P(PSTR(", check rate %u Hz"),tmp);
}
printf_P(PSTR("\n"));
#endif
#if UIP_CONF_ROUTER
#warning Routing enabled
PRINTF("Routing Enabled\n")
#if ANNOUNCE_BOOT
printf_P(PSTR("Routing Enabled\n"));
#endif
rime_init(rime_udp_init(NULL));
uip_router_register(&rimeroute);
#endif
// sicslowpan_init(MAC_DRIVER.init(&rf230_driver));
// PRINTF("Driver: %s, Channel: %u\n\r", MAC_DRIVER.name, rf230_get_channel());
PRINTF("Driver: %s, Channel: %u\n", sicslowpan_mac->name, rf230_get_channel());
}
#endif /*RF230BB*/
#if RF230BB
@ -258,35 +244,7 @@ void initialize(void)
// fa = cfs_open("upload.html"), CFW_WRITE);
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
}
#endif
/*--------------------------Announce the configuration---------------------*/
#define ANNOUNCE_BOOT 1 //adds about 400 bytes to program size
#if ANNOUNCE_BOOT
#if WEBSERVER
uint8_t i;
char buf[80];
unsigned int size;
eeprom_read_block (buf,server_name, sizeof(server_name));
buf[sizeof(server_name)]=0;
printf_P(PSTR("%s"),buf);
eeprom_read_block (buf,domain_name, sizeof(domain_name));
buf[sizeof(domain_name)]=0;
size=httpd_fs_get_size();
#ifndef COFFEE_FILES
printf_P(PSTR(".%s online with fixed %u byte web content\n"),buf,size);
#elif COFFEE_FILES==1
printf_P(PSTR(".%s online with static %u byte EEPROM file system\n"),buf,size);
#elif COFFEE_FILES==2
printf_P(PSTR(".%s online with dynamic %u KB EEPROM file system\n"),buf,size>>10);
#elif COFFEE_FILES==3
printf_P(PSTR(".%s online with static %u byte program memory file system\n"),buf,size);
#elif COFFEE_FILES==4
printf_P(PSTR(".%s online with dynamic %u KB program memory file system\n"),buf,size>>10);
#endif
#endif /* COFFEE_FILES */
/* Add prefixes for testing */
#if 0
@ -306,28 +264,63 @@ void initialize(void)
}
#endif
/*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT
#if WEBSERVER
uint8_t i;
char buf[80];
unsigned int size;
for(i = 0; i < UIP_CONF_NETIF_MAX_ADDRESSES; i ++) {
if(uip_netif_physical_if.addresses[i].state != NOT_USED) {
httpd_cgi_sprint_ip6(*(uip_ipaddr_t*)&uip_netif_physical_if.addresses[i],buf);
printf_P(PSTR("IPv6 Address: %s\n"),buf);
}
}
eeprom_read_block (buf,server_name, sizeof(server_name));
buf[sizeof(server_name)]=0;
printf_P(PSTR("%s"),buf);
eeprom_read_block (buf,domain_name, sizeof(domain_name));
buf[sizeof(domain_name)]=0;
size=httpd_fs_get_size();
#ifndef COFFEE_FILES
printf_P(PSTR(".%s online with fixed %u byte web content\n"),buf,size);
#elif COFFEE_FILES==1
printf_P(PSTR(".%s online with static %u byte EEPROM file system\n"),buf,size);
#elif COFFEE_FILES==2
printf_P(PSTR(".%s online with dynamic %u KB EEPROM file system\n"),buf,size>>10);
#elif COFFEE_FILES==3
printf_P(PSTR(".%s online with static %u byte program memory file system\n"),buf,size);
#elif COFFEE_FILES==4
printf_P(PSTR(".%s online with dynamic %u KB program memory file system\n"),buf,size>>10);
#endif /* COFFEE_FILES */
#else
printf_P(PSTR("Online\n"));
#endif /* WEBSERVER */
#endif /* ANNOUNCE_BOOT */
}
#if RF230BB
extern uint8_t rf230processflag; //for debugging process call problems
#endif
/*---------------------------------------------------------------------------*/
void log_message(char *m1, char *m2)
{
printf_P(PSTR("%s%s\n"), m1, m2);
}
extern uint8_t rtimerworks;
/* Test rtimers, also useful for pings and time stamps in simulator */
#define TESTRTIMER 0
#if TESTRTIMER
#define PINGS 60
#define STAMPS 30
uint8_t rtimerflag=1;
uint16_t rtime;
struct rtimer rt;
void rtimercycle(void) {rtimerflag=1;}
#endif /* TESTRTIMER */
extern uint8_t packetreceived;
/*-------------------------------------------------------------------------*/
/*------------------------- Main Scheduler loop----------------------------*/
/*-------------------------------------------------------------------------*/
@ -335,41 +328,63 @@ int
main(void)
{
initialize();
while(1) {
process_run();
#if 0
if (rtimerworks>200) {
printf("%d",rtimerworks);
rtimerworks=0;
//Various entry points for debugging in AVR simulator
// NETSTACK_RADIO.send(packetbuf_hdrptr(), 42);
// process_poll(&rf230_process);
// packetbuf_clear();
// len = rf230_read(packetbuf_dataptr(), PACKETBUF_SIZE);
// packetbuf_set_datalen(42);
// NETSTACK_RDC.input();
#if TESTRTIMER
if (rtimerflag) { //8 seconds is maximum interval, my raven 6% slow
rtimer_set(&rt, RTIMER_NOW()+ RTIMER_ARCH_SECOND*1UL, 1,(void *) rtimercycle, NULL);
rtimerflag=0;
#if STAMPS
if ((rtime%STAMPS)==0) {
printf("%us ",rtime);
}
#endif
rtime+=1;
#if PINGS
if ((rtime%PINGS)==0) {
PRINTF("**Ping\n");
raven_ping6();
}
#endif
}
#endif
#if RF230BB && 0
//Use with RF230BB RADIOALWAYSON to show packets missed when radio is "off"
#if RF230BB&&1
if (packetreceived) {
if (packetreceived==1) { //missed
printf("-");
} else { //passed to stack
printf("+");
}
packetreceived=0;
}
#endif
#if RF230BB&&0
if (rf230processflag) {
printf("rf230p%d",rf230processflag);
rf230processflag=0;
}
}
#endif
#if 0
#if RF230BB&&0
if (rf230_interrupt_flag) {
// if (rf230_interrupt_flag!=11) {
// PRINTF("*****Radio interrupt %u\n",rf230_interrupt_flag);
// if (rf230_interrupt_flag!=11) {
PRINTSHORT("**RI%u",rf230_interrupt_flag);
rf230_interrupt_flag=0;
// }
// }
rf230_interrupt_flag=0;
}
#endif
#if PINGS
if (pingtimer1++==10000) {
pingtimer1=0;
if (pingtimer2++==1000) {
PRINTF("-------Ping\n");
pingtimer2=0;
raven_ping6();
}
}
#endif
}
return 0;
}