コード例 #1
0
int
main(void)
{
  /*
   * GCC depends on register r1 set to 0.
   */
  asm volatile ("clr r1");

  /* Initialize hardware */
  init_lowlevel();

  /* Clock */
  clock_init();

  /* Process subsystem */
  process_init();

  /* Register initial processes */
  procinit_init();

  /* Perform rest of initializations */
  process_start(&contiki_stk501_main_init_process, NULL);

  rs232_print_p (RS232_PORT_1, PSTR ("Initialized.\n"));

#ifdef MT_DEMO
  mt_start (&threads[0], thread_handler1, &d1);
  mt_start (&threads[1], thread_handler2, &d2);
  mt_start (&threads[2], thread_handler2, &d3);

  uint8_t i;
#endif

  /* Main scheduler loop */
  while(1) {

    process_run();

#ifdef MT_DEMO
    for (i=0; i<3; ++i) {
      mt_exec (&threads[i]);
    }
#endif
  }

  return 0;
}
コード例 #2
0
/*---------------------------------------------------------------------------*/
void
checkpoint_arch_init(void)
{
  mt_init();
  mt_start(&checkpoint_thread, thread_loop, NULL);

  /*mt_stop(&checkpoint_thread);*/
  /*mt_remove();*/
}
コード例 #3
0
void
checkpoint_arch_init(void)
{
  if(inited) {
    return;
  }

  mt_init();
  mt_start(&checkpoint_thread, checkpoint_thread_loop, NULL);
  inited = 1;

#if CHECKPOINT_ROLLBACK_BUTTON
  process_start(&checkpoint_button_process, NULL);
#endif /* CHECKPOINT_ROLLBACK_BUTTON */

  /*mt_stop(&checkpoint_thread);*/
  /*mt_remove();*/
}
コード例 #4
0
PROCESS_THREAD(udp_client_process, ev, data)
{
    static struct etimer start_timer, send_timer;
    static int flag=1;int i=0;
    static struct mt_thread sending_thread, attackinit_thread;	

    PROCESS_BEGIN();

    SENSORS_ACTIVATE(button_sensor);
    SENSORS_ACTIVATE(radio_sensor);

    set_global_address();

    printf("UDP client process started\n");

    print_local_addresses();

	myip=uip_ds6_get_link_local(ADDR_PREFERRED)->ipaddr;

    /* new connection with remote host */
    client_conn = udp_new(NULL, NULL, NULL);
    if(client_conn == NULL) {
        printf("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(client_conn, UIP_HTONS(10000+(int)myip.u8[15]));

    udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),tcpip_handler);
    //uip_create_unspecified(&udp_bconn->ripaddr);	
    if(udp_bconn == NULL) {
        printf("No UDP broadcast connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
	
    printf("Created a connection with the server ");
    PRINT6ADDR(&client_conn->ripaddr);
    printf(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

    etimer_set(&start_timer, 60 * CLOCK_SECOND);//network setting time
    etimer_set(&send_timer, CLOCK_SECOND * ((int)myip.u8[15]+60+40));//node check/send parent info
    char buf[3]="hi";


    mt_init();
    mt_start(&sending_thread, sendpacket, 0);
    mt_start(&attackinit_thread, attack_init, NULL);	
    while(1) {

        PROCESS_YIELD();

        //NETSTACK_RDC.off(0);
        //NETSTACK_MAC.off(0);
        //NETSTACK_RADIO.off();
        //button_sensor::value(0);

        if(ev==tcpip_event)
        {
			
	    tcpip_handler();	                  
        }
	if(rssi_stored==5)// if got 5 rssi value from parent or child
	{
		monitor=0;
		monitor_target=0;
		for(i=0;i<5;i++)
			printf("Monitered value %d \n",mrssi[i]);
		rssi_stored=0;
	}
        if((ev==sensors_event) && (data == &button_sensor)) {            
	if(attack_flag)      
	{
		printf("Attack deactivated\n");   
		attack_flag=0;
		attacker=0;
		attacker_set=0;
		dis_output(NULL);
	}else {
		printf("Attack activated\n");   
		mt_exec(&attackinit_thread);
	}	
        }
        if((ev==sensors_event) && (data == &radio_sensor))
        {
            printf("Radio value %d",radio_sensor.value(0));
        }
        if(etimer_expired(&send_timer))
	{
		//uip_udp_packet_sendto(client_conn, buf, sizeof(buf), &server_ipaddr, UIP_HTONS(2345));
		//uip_create_unspecified(&client_conn->ripaddr); 
		//if(myip.u8[15]==4)
		//sendpacket(0);
		etimer_set(&send_timer, CLOCK_SECOND*(myip.u8[15]+60));
		if(parent_change)        // send only at parent change event
		{	            
	            if(!attack_flag)	//  this is not attacker and
		    {	
			mt_exec(&sending_thread);
			//sendpacket(0);	//  send nbr info by broadcast 0 for broadcast 
			parent_change=0;
			printf("Thread initiated\n");
		    }
	        }
	}
        if(etimer_expired(&start_timer) && flag==1)
        {
            flag=0;
            send_xy();
	    etimer_set(&start_timer, CLOCK_SECOND*(myip.u8[15]+1));
	    PROCESS_WAIT_UNTIL(etimer_expired(&start_timer));
	    send_broadcast("hi",sizeof("hi"));	
	    sendpacket(1);	// 0 means send by unicast	
	    	
        }
    }

    PROCESS_END();
}