Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  putstring("Starting UDP server\n");

#if BUTTON_SENSOR_ON
  putstring("Button 1: Print RIME stats\n");
#endif

#if SERVER_RPL_ROOT
  create_dag();
#endif

  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
#if (BUTTON_SENSOR_ON && (DEBUG==DEBUG_PRINT))
    } else if(ev == sensors_event && data == &button_sensor) {
      print_stats();
#endif /* BUTTON_SENSOR_ON */
    }
  }

  PROCESS_END();
}
Ejemplo n.º 2
0
/* --------------------------------------------------------------- */
PROCESS_THREAD(node_process, ev, data)
{
    // All the process start with this
    PROCESS_BEGIN();
    PRINTF("# Starting...\n");

    // Configure the network
    network_config();
    if (!conn) {
         printf("E01\n");
         PROCESS_EXIT();
    }

    #if IS_RPL_ROOT
    create_dag();
    #endif

    // Main, infinite, loop of the process
    PRINTF("# Ready!\n");
    while (1) {
        // Wait, block the process, until an event happens.
        // Meanwhile, other process will continue running.
        PROCESS_WAIT_EVENT();

        // Check the type of event that unblock the process
        if (ev == tcpip_event)
            tcpip_handler();
        else if (ev == serial_line_event_message)
            input_handler((char*)data);
    }

    // All the process ends with this
    PROCESS_END();
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  static struct sensors_sensor *b1;
  static struct sensors_sensor *b2;
#endif

  PROCESS_BEGIN();
  putstring("Starting UDP server\n");

#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  putstring("Button 1: Print RIME stats\n");
  putstring("Button 2: Reboot\n");
#endif

#if SERVER_RPL_ROOT
  create_dag();
#endif

  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl);

#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
  b1 = sensors_find(BUTTON_1_SENSOR);
  b2 = sensors_find(BUTTON_2_SENSOR);
#endif

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON)
    } else if(ev == sensors_event && data != NULL) {
      if(data == b1) {
        print_stats();
      } else if(data == b2) {
        watchdog_reboot();
      }
#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */
    }
  }

  PROCESS_END();
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{
#if UIP_CONF_ROUTER
  uip_ipaddr_t ipaddr;
#endif /* UIP_CONF_ROUTER */

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if RESOLV_CONF_SUPPORTS_MDNS
  resolv_set_hostname("contiki-udp-server");
#endif

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

#if SERVER_RPL_ROOT
  create_dag();
#endif
  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));
PRINTF("Listen port: 3000, TTL=%u\n\r", server_conn->ttl);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Ejemplo n.º 5
0
void dag_build(CSOUND *csound, INSDS *chain)
{
    INSDS *save = chain;
    INSDS **task_map;
    int i;

    //printf("DAG BUILD***************************************\n");
    csound->dag_num_active = 0;
    while (chain != NULL) {
      csound->dag_num_active++;
      chain = chain->nxtact;
    }
    if (csound->dag_num_active>csound->dag_task_max_size) {
      //printf("**************need to extend task vector\n");
      csound->dag_task_max_size = csound->dag_num_active+INIT_SIZE;
      recreate_dag(csound);
    }
    if (csound->dag_task_status == NULL)
      create_dag(csound); /* Should move elsewhere */
    else {
      memset((void*)csound->dag_task_watch, '\0',
             sizeof(watchList*)*csound->dag_task_max_size);
      for (i=0; i<csound->dag_task_max_size; i++) {
        if (csound->dag_task_dep[i]) {
          csound->dag_task_dep[i]= NULL;
        }
        csound->dag_wlmm[i].id = INVALID;
      }
    }
    task_map = csound->dag_task_map;
    for (i=0; i<csound->dag_num_active; i++) {
      csound->dag_task_status[i] = AVAILABLE;
      csound->dag_wlmm[i].id=i;
    }
    csound->dag_changed = 0;
    if (UNLIKELY(csound->oparms->odebug))
      printf("dag_num_active = %d\n", csound->dag_num_active);
    i = 0; chain = save;
    while (chain != NULL) {     /* for each instance check against later */
      int j = i+1;              /* count of instance */
      if (UNLIKELY(csound->oparms->odebug))
        printf("\nWho depends on %d (instr %d)?\n", i, chain->insno);
      INSDS *next = chain->nxtact;
      INSTR_SEMANTICS *current_instr = dag_get_info(csound, chain->insno);
      //csp_set_print(csound, current_instr->read);
      //csp_set_print(csound, current_instr->write);
      while (next) {
        INSTR_SEMANTICS *later_instr = dag_get_info(csound, next->insno);
        int cnt = 0;
        if (UNLIKELY(csound->oparms->odebug)) printf("%d ", j);
        //csp_set_print(csound, later_instr->read);
        //csp_set_print(csound, later_instr->write);
        //csp_set_print(csound, later_instr->read_write);
        if (dag_intersect(csound, current_instr->write,
                          later_instr->read, cnt++)       ||
            dag_intersect(csound, current_instr->read_write,
                          later_instr->read, cnt++)       ||
            dag_intersect(csound, current_instr->read,
                          later_instr->write, cnt++)      ||
            dag_intersect(csound, current_instr->write,
                          later_instr->write, cnt++)      ||
            dag_intersect(csound, current_instr->read_write,
                          later_instr->write, cnt++)      ||
            dag_intersect(csound, current_instr->read,
                          later_instr->read_write, cnt++) ||
            dag_intersect(csound, current_instr->write,
                          later_instr->read_write, cnt++)) {
          char *tt = csound->dag_task_dep[j];
          if (tt==NULL) {
            /* get dep vector if missing and set watch first time */
            tt = csound->dag_task_dep[j] =
              (char*)csound->Calloc(csound, sizeof(char)*(j+1));
            csound->dag_task_status[j] = WAITING;
            csound->dag_wlmm[j].next = csound->dag_task_watch[i];
            csound->dag_wlmm[j].id = j;
            csound->dag_task_watch[i] = &(csound->dag_wlmm[j]);
            //printf("set watch %d to %d\n", j, i);
          }
          tt[i] = 1;
          //printf("-yes ");
        }
        j++; next = next->nxtact;
      }
      task_map[i] = chain;
      i++; chain = chain->nxtact;
    }
    if (UNLIKELY(csound->oparms->odebug)) dag_print_state(csound);
}
Ejemplo n.º 6
0
PROCESS_THREAD(udp_server_process, ev, data)
{
    static int distance_flag,i;
    static struct etimer reset_timer,rssi_wait;
    static unsigned char rbuf[20], *buf_p;

    PROCESS_BEGIN();

    distance_flag=0;
    create_dag();

    server_conn = udp_new(NULL, NULL, NULL);
    if(server_conn == NULL) {
        PRINTF("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(server_conn, UIP_HTONS(2345));


    PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport),
           UIP_HTONS(server_conn->rport));
    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT), tcpip_handler);

    init_rssi();
    uip_ip6addr(&myip, 0xaaaa, 0, 0, 0, 0, 0, 0, 1);
    PRINTF("Listen port: 2345, TTL=%u\n", server_conn->ttl);
    etimer_set(&nw_settle_timer, (nwsettime + 4*Nodes_in_nw-20)* CLOCK_SECOND);//network setting time
    etimer_set(&addmyinfo_wait, 30 * CLOCK_SECOND);
    PROCESS_WAIT_UNTIL(etimer_expired(&addmyinfo_wait));
    addmyinfo();
    etimer_set(&reset_timer, (reset_time)*CLOCK_SECOND);
    


    while(1) {

        PROCESS_YIELD();
        if(rssi_stored==3 && monitor!=0)// if got 5 rssi value from parent or child
        {
            monitor=0;
            rssi_stored=0;

            buf_p=rbuf;
            MAPPER_ADD_PACKETDATA(buf_p,myip.u8[15]);
            MAPPER_ADD_PACKETDATA(buf_p,monitor_target);
            for(i=0; i<3; i++)
            {
                MAPPER_ADD_PACKETDATA(buf_p,mrssi[i]);
                printf("%d ",mrssi[i]);
            }
            printf("\n");
            if(current_victim[1]==myip.u8[15])
            {
                printf("Rssi stored\n");
                victim[1].id=myip.u8[15];
                victim[1].suspect=monitor_target;
                victim[1].mrssi=(int)(mrssi[0] + mrssi[1] + mrssi[2])/3;
                victim[1].is_rssi_stored=1;
                printf("snd rssi %d %u %u %d\n",5,myip.u8[15],monitor_target,victim[1].mrssi);
                monitor_target=0;
            }

        }
        if(ev==tcpip_event)
        {
            tcpip_handler();
        }

        if(rssi_timer_flag)
        {
            rssi_timer_flag=0;
            printf("Set rssi time using flag \n");
            etimer_set(&rssi_wait, rssi_wait_time*CLOCK_SECOND);
        }
        if(reset_timer_flag)
        {
            reset_timer_flag=0;
            printf("Reset time using flag \n");
            etimer_set(&reset_timer, reset_time*CLOCK_SECOND);
        }

        if(distance_flag==0 && etimer_expired(&nw_settle_timer))
        {        
            distance_flag=1;
            process_start(&distance_process, NULL);
        }
        if(rssi_flag==1 && etimer_expired(&rssi_wait))
        {
            rssi_flag=0;
            printf("Ready to process rssi\n");
            process_start(&postrssi_process, NULL);
        }

        if(etimer_expired(&reset_timer))
        {
            attack_processing=0;
            printf("Reset time expired %d %d\n",reset_time,rssi_wait_time);
            victim[0].id=victim[1].id=0;
            victim[0].is_rssi_stored=victim[1].is_rssi_stored=0;
            victim_count=0;
            current_victim[0]=0;
            current_victim[1]=0;

            monitor=0;
            monitor_target=0;
            last_target=0;
            suspect_c=0;
            suspect_send=0;

            etimer_set(&reset_timer, reset_time*CLOCK_SECOND);
            printf("Total nodes %d\n",total_nodes);
	    
	    chk_my_nbr();
	    node_to_v=1;
	    process_start(&validatepc_process, NULL);		
	    
            //for(i=0;i<total_nodes;i++)
            {
                //	printf("N %u x %d y %d p %u\n",nodes[i].id,nodes[i].x,nodes[i].y,nodes[i].parent_id);
            }
        }
    }

    PROCESS_END();
}