54 #define DEBUG 0 //Making this 1 will slightly alter command timings
56 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
60 #define DEBUGSERIAL 0 //Making this 1 will significantly alter command timings
63 #include "contiki-lib.h"
64 #include "contiki-net.h"
65 #include "webserver-nogui.h"
66 #include "httpd-cgi.h"
67 #include "raven-lcd.h"
71 #include <avr/pgmspace.h>
72 #include <avr/eeprom.h>
73 #include <avr/sleep.h>
74 #include <dev/watchdog.h>
76 static uint8_t count = 0;
78 uip_ipaddr_t dest_addr;
80 #define MAX_CMD_LEN 20
82 uint8_t frame[MAX_CMD_LEN];
89 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
90 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
91 #define PING6_DATALEN 16
93 void rs232_send(uint8_t port,
unsigned char c);
101 #if UIP_CONF_IPV6_RPL||1
103 #define PING_GOOGLE 1
115 }
else if (seqno==2) {
117 }
else if (seqno==3) {
134 count, PING6_DATALEN);
147 #if defined(__AVR_ATmega128RFA1__)
151 send_frame(uint8_t cmd, uint8_t len, uint8_t *payload)
158 send_frame(uint8_t cmd, uint8_t len, uint8_t *payload)
170 char serial_char_received;
183 void micro_sleep(uint8_t howlong)
185 uint8_t saved_sreg = SREG, saved_howlong = howlong;
186 #if AVR_CONF_USE32KCRYSTAL
188 uint8_t savedTCNT2=TCNT2, savedTCCR2A=TCCR2A, savedTCCR2B = TCCR2B, savedOCR2A = OCR2A;
194 set_sleep_mode(SLEEP_MODE_PWR_SAVE);
195 if (howlong==0) howlong=3;
199 TCCR2B =((1<<CS22)|(1<<CS21)|(1<<CS20));
214 while(ASSR & (1 << TCN2UB));
215 TIMSK2 |= (1 << OCIE2A);
220 serial_char_received=0;
229 if (saved_howlong)
break;
230 PRINTF(
"%d",serial_char_received);
231 if (serial_char_received)
break;
236 #if AVR_CONF_USE32KCRYSTAL
240 TCCR2A = savedTCCR2A;
241 TCCR2B = savedTCCR2B;
246 TIMSK2 &= ~(1 << OCIE2A);
251 #if !AVR_CONF_USE32KCRYSTAL
255 ISR(TIMER2_COMPA_vect)
267 extern uint16_t ledtimer;
269 raven_gui_loop(process_event_t ev, process_data_t data)
271 uint8_t i,activeconnections,radio_state;
275 printf_P(PSTR(
"Buffer [%d]="),serialcount);
278 printf_P(PSTR(
" %d"),dbuf[i]);
282 if(ev == tcpip_icmp6_event)
switch(*((uint8_t *)data)) {
295 #if RF230BB_CONF_LEDONPORTE1
296 PORTE|=(1<<PE1);ledtimer=1000;
308 PRINTF(
"\nCommand %d length %d done %d",cmd.cmd,cmd.len,cmd.done);
314 seqno = cmd.frame[0];
327 if (cmd.frame[0]==0) {
335 if((uip_conns[i].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) activeconnections++;
337 if (activeconnections) {
338 PRINTF(
"\nWaiting for %d connections",activeconnections);
342 radio_state = NETSTACK_RADIO.off();
343 PRINTF (
"\nsleep %d radio state %d...",cmd.frame[0],radio_state);
346 PRINTF(
"\nSleeping...");
347 micro_sleep(cmd.frame[0]);
349 radio_state = NETSTACK_RADIO.on();
350 if (radio_state > 0) {
353 PRINTF(
"Radio wake error %d\n",radio_state);
358 send_frame(REPORT_WAKE, 0, 0);
378 int raven_lcd_serial_input(
unsigned char ch)
382 if (ch) serial_char_received++;
384 if (serialcount<25) dbuf[serialcount]=ch;
413 if (cmd.ndx >= (MAX_CMD_LEN+3)) {
420 if (cmd.ndx >= cmd.len+3){
438 cmd.frame[cmd.ndx - 3] = ch;
449 raven_lcd_show_text(
char *text) {
450 uint8_t textlen=strlen(text)+1;
451 if (textlen > MAX_CMD_LEN) textlen=MAX_CMD_LEN;
452 send_frame(REPORT_TEXT_MSG, textlen, (uint8_t *) text);
457 lcd_show_servername(
void) {
460 extern uint8_t server_name[16];
462 char buf[
sizeof(server_name)+1];
463 eeprom_read_block (buf,server_name,
sizeof(server_name));
464 buf[
sizeof(server_name)]=0;
465 raven_lcd_show_text(buf);
469 PROCESS(raven_lcd_process,
"Raven LCD interface process");
476 lcd_show_servername();
480 if(icmp6_new(
NULL) == 0) {
485 raven_gui_loop(ev, data);
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
uip_len
The length of the packet in the uip_buf buffer.
void tcpip_ipv6_output(void)
This function does address resolution and then calls tcpip_output.
#define PORTE
Peripheral PORTE base pointer.
#define PROCESS_BEGIN()
Define the beginning of a process.
void watchdog_start(void)
Starts the WDT in watchdog mode if enabled by user configuration, maximum interval.
#define ICMP6_ECHO_REPLY
Echo reply.
#define NULL
The null pointer.
#define SOF_CHAR
Start-of-frame character.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
void clock_adjust_ticks(clock_time_t howmany)
Adjust the system current clock time.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define UIP_IP_BUF
Pointer to IP header.
#define PROCESS_END()
Define the end of a process.
void watchdog_stop(void)
In watchdog mode, the WDT can not be stopped.
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define ICMP6_ECHO_REQUEST
Echo request.
#define PROCESS(name, strname)
Declare a process.
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
#define UIP_ICMP_BUF
Pointer to ICMP header.
#define PROCESS_YIELD()
Yield the currently running process.
#define EOF_CHAR
End-of-frame character.
#define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7)
Construct an IPv6 address from eight 16-bit words.
void rs232_send(uint8_t port, unsigned char c)
Print a character on RS232.
#define UIP_ICMP6_ECHO_REQUEST_LEN
Echo Request constant part length.
#define CLOCK_SECOND
A second, measured in system clock time.