Beispiel #1
0
/*---------------------------------------------------------------------------*/
static u8_t
raven_gui_loop(process_event_t ev, process_data_t data)
{

    switch (ev){
    case ICMP6_ECHO_REQUEST:
        /* We have received a ping request over the air. Send frame back to 3290 */
        send_frame(PING_REQUEST, 0, 0);
        break;
    case ICMP6_ECHO_REPLY:
        /* We have received a ping reply over the air.  Send frame back to 3290 */
        send_frame(PING_REPLY, 1, &seqno);
        break;
    case SERIAL_CMD:        
        /* Check for command from serial port, execute it. */
        if (cmd.done){
            /* Execute the waiting command */
            switch (cmd.cmd){
            case CMD_PING:
                /* Send ping request over the air */
                seqno = cmd.frame[0];
                raven_ping6();
                break;
            case CMD_TEMP:
                /* Set temperature string in web server */
                web_set_temp((char *)cmd.frame);
                break;
            default:
                break;
            }
            /* Reset command done flag. */
            cmd.done = 0;
        }
        break;
    default:
        break;
    }
    return 0;
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
static uint8_t
raven_gui_loop(process_event_t ev, process_data_t data)
{
    uint8_t i,activeconnections,radio_state;
    
// PRINTF("\nevent %d ",ev);
#if DEBUGSERIAL
    printf_P(PSTR("Buffer [%d]="),serialcount);
    serialcount=0;
    for (i=0;i<30;i++) {
       printf_P(PSTR(" %d"),dbuf[i]);
       dbuf[i]=0;
    }
#endif
    if(ev == tcpip_icmp6_event) switch(*((uint8_t *)data)) {

//   case ICMP6_NS:
        /*Tell the 3290 we are being solicited. */
//       send_frame(REPORT_NS,...);
//       break;  //fall through for beep
//   case ICMP6_RA:
        /*Tell the 3290 we have a router. */
//       send_frame(REPORT_NA,...);
//       break;  //fall through for beep
    case ICMP6_ECHO_REQUEST:
        /* We have received a ping request over the air. Tell the 3290 */
        send_frame(REPORT_PING_BEEP, 0, 0);
        break;
    case ICMP6_ECHO_REPLY:
        /* We have received a ping reply over the air.  Send frame back to 3290 */
        send_frame(REPORT_PING, 1, &seqno);
        break;

    } else switch (ev) {
     case SERIAL_CMD:        
        /* Check for command from serial port, execute it. */
        /* Note cmd frame is written in an interrupt - delays here can cause overwriting by next command */
        PRINTF("\nCommand %d length %d done %d",cmd.cmd,cmd.len,cmd.done);
        if (cmd.done){
            /* Execute the waiting command */
            switch (cmd.cmd){
            case SEND_PING:
                /* Send ping request over the air */
                seqno = cmd.frame[0];
                raven_ping6();
                break;
            case SEND_TEMP:
#if AVR_WEBSERVER
                /* Set temperature string in web server */
                web_set_temp((char *)cmd.frame);
#endif
                break;
            case SEND_ADC2:
#if AVR_WEBSERVER
                /* Set ext voltage string in web server */
                web_set_voltage((char *)cmd.frame);
#endif
                break;
            case SEND_SLEEP:
                /* Sleep radio and 1284p. */
                if (cmd.frame[0]==0) {  //Time to sleep in seconds
                /* Unconditional sleep. Don't wake until a serial interrupt. */
                } else {
                /* Sleep specified number of seconds (3290p "DOZE" mode) */
                /* It sleeps a bit longer so we will be always be awake for the next sleep command. */
#if UIP_CONF_TCP
                /* Only sleep this cycle if no active TCP/IP connections, for fast browser responsed */
                   activeconnections=0;
                   for(i = 0; i < UIP_CONNS; ++i) {
                      if((uip_conns[i].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) activeconnections++;
                   }
                   if (activeconnections) {
                     PRINTF("\nWaiting for %d connections",activeconnections);
                     break;
                   }
#endif
                }
                radio_state = NETSTACK_RADIO.off();
                PRINTF ("\nsleep %d radio state %d...",cmd.frame[0],radio_state);

                /*Sleep for specified time*/
                PRINTF("\nSleeping...");
                micro_sleep(cmd.frame[0]);

                radio_state = NETSTACK_RADIO.on();
                if (radio_state > 0) {
                   PRINTF("Awake!");
                } else {
                    PRINTF("Radio wake error %d\n",radio_state);
                }
                break;
            case SEND_WAKE:
               /* 3290p requests return message showing awake status */
                send_frame(REPORT_WAKE, 0, 0);
                break;
            default:
                break;
            }
            /* Reset command done flag. */
            cmd.done = 0;
        }
        break;
    default:
        break;
    }
    return 0;
}