57 #define DEBUG 0 //Making this 1 will slightly alter command timings
59 #define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
63 #define DEBUGSERIAL 0 //Making this 1 will significantly alter command timings
66 #include "contiki-lib.h"
67 #include "contiki-net.h"
68 #include "webserver-nogui.h"
69 #include "httpd-cgi.h"
70 #include "raven-lcd.h"
74 #include <avr/pgmspace.h>
75 #include <avr/eeprom.h>
76 #include <avr/sleep.h>
77 #include <dev/watchdog.h>
79 static u8_t count = 0;
83 #define MAX_CMD_LEN 20
85 u8_t frame[MAX_CMD_LEN];
92 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
93 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
94 #define PING6_DATALEN 16
96 void rs232_send(uint8_t port,
unsigned char c);
104 #if UIP_CONF_IPV6_RPL||1
106 #define PING_GOOGLE 1
118 }
else if (seqno==2) {
120 }
else if (seqno==3) {
137 count, PING6_DATALEN);
150 #if defined(__AVR_ATmega128RFA1__)
154 send_frame(uint8_t cmd, uint8_t len, uint8_t *payload)
161 send_frame(uint8_t cmd, uint8_t len, uint8_t *payload)
173 char serial_char_received;
186 void micro_sleep(uint8_t howlong)
188 uint8_t saved_sreg = SREG, saved_howlong = howlong;
189 #if AVR_CONF_USE32KCRYSTAL
191 uint8_t savedTCNT2=TCNT2, savedTCCR2A=TCCR2A, savedTCCR2B = TCCR2B, savedOCR2A = OCR2A;
197 set_sleep_mode(SLEEP_MODE_PWR_SAVE);
198 if (howlong==0) howlong=3;
202 TCCR2B =((1<<CS22)|(1<<CS21)|(1<<CS20));
217 while(ASSR & (1 << TCN2UB));
218 TIMSK2 |= (1 << OCIE2A);
223 serial_char_received=0;
227 extern void clock_adjust_ticks(uint16_t howmany);
232 if (saved_howlong)
break;
233 PRINTF(
"%d",serial_char_received);
234 if (serial_char_received)
break;
239 #if AVR_CONF_USE32KCRYSTAL
243 TCCR2A = savedTCCR2A;
244 TCCR2B = savedTCCR2B;
249 TIMSK2 &= ~(1 << OCIE2A);
254 #if !AVR_CONF_USE32KCRYSTAL
258 ISR(TIMER2_COMPA_vect)
270 extern uint16_t ledtimer;
272 raven_gui_loop(process_event_t ev, process_data_t data)
274 uint8_t i,activeconnections,radio_state;
278 printf_P(PSTR(
"Buffer [%d]="),serialcount);
281 printf_P(PSTR(
" %d"),dbuf[i]);
285 if(ev == tcpip_icmp6_event)
switch(*((uint8_t *)data)) {
298 #if RF230BB_CONF_LEDONPORTE1
299 PORTE|=(1<<PE1);ledtimer=1000;
311 PRINTF(
"\nCommand %d length %d done %d",cmd.cmd,cmd.len,cmd.done);
317 seqno = cmd.frame[0];
330 if (cmd.frame[0]==0) {
338 if((uip_conns[i].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) activeconnections++;
340 if (activeconnections) {
341 PRINTF(
"\nWaiting for %d connections",activeconnections);
345 radio_state = NETSTACK_RADIO.off();
346 PRINTF (
"\nsleep %d radio state %d...",cmd.frame[0],radio_state);
349 PRINTF(
"\nSleeping...");
350 micro_sleep(cmd.frame[0]);
352 radio_state = NETSTACK_RADIO.on();
353 if (radio_state > 0) {
356 PRINTF(
"Radio wake error %d\n",radio_state);
361 send_frame(REPORT_WAKE, 0, 0);
381 int raven_lcd_serial_input(
unsigned char ch)
385 if (ch) serial_char_received++;
387 if (serialcount<25) dbuf[serialcount]=ch;
416 if (cmd.ndx >= (MAX_CMD_LEN+3)) {
423 if (cmd.ndx >= cmd.len+3){
441 cmd.frame[cmd.ndx - 3] = ch;
452 raven_lcd_show_text(
char *text) {
453 uint8_t textlen=strlen(text)+1;
454 if (textlen > MAX_CMD_LEN) textlen=MAX_CMD_LEN;
455 send_frame(REPORT_TEXT_MSG, textlen, (uint8_t *) text);
460 lcd_show_servername(
void) {
463 extern uint8_t server_name[16];
465 char buf[
sizeof(server_name)+1];
466 eeprom_read_block (buf,server_name,
sizeof(server_name));
467 buf[
sizeof(server_name)]=0;
468 raven_lcd_show_text(buf);
472 PROCESS(raven_lcd_process,
"Raven LCD interface process");
479 lcd_show_servername();
483 if(icmp6_new(
NULL) == 0) {
488 raven_gui_loop(ev, data);