Exemplo n.º 1
0
void backlight_on(uint8_t level, clock_time_t length)
{
  if (level > 8) level = 8;

  level *= 2;
  if (level == 0)
  {
    LIGHTCONTROL = OUTMOD_0;
  }
  else
  {
    LIGHTCONTROL = OUTMOD_7;
    LIGHTLEVEL = level * 2;
    if (length > 0)
      ctimer_set(&light_timer, length, light_stop, (void*)(CLOCK_SECOND/8));
  }
}
Exemplo n.º 2
0
void motor_on(uint8_t level, clock_time_t length)
{
  if (level > 16) level = 16;
  level *= 2;

  if (level == 0)
  {
    motor_stop(NULL);
  }
  else
  {
    MOTORCONTROL = OUTMOD_7;
    MOTORLEVEL = level;
    if (length > 0)
      ctimer_set(&motor_timer, length, motor_stop, NULL);
  }
}
Exemplo n.º 3
0
static void
new_dio_interval(rpl_instance_t *instance)
{
  uint32_t time;

  /* TODO: too small timer intervals for many cases */
  time = 1UL << instance->dio_intcurrent;

  /* Convert from milliseconds to CLOCK_TICKS. */
  time = (time * CLOCK_SECOND) / 1000;

  instance->dio_next_delay = time;

  /* random number between I/2 and I */
  time = time >> 1;
  time += (time * random_rand()) / RANDOM_RAND_MAX;

  /*
   * The intervals must be equally long among the nodes for Trickle to
   * operate efficiently. Therefore we need to calculate the delay between
   * the randomized time and the start time of the next interval.
   */
  instance->dio_next_delay -= time;
  instance->dio_send = 1;

#if RPL_CONF_STATS
  /* keep some stats */
  instance->dio_totint++;
  instance->dio_totrecv += instance->dio_counter;
  ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n",
	   DAG_RANK(instance->current_dag->rank, instance),
           (10 * (instance->current_dag->rank % instance->min_hoprankinc)) / instance->min_hoprankinc,
           instance->current_dag->version,
           instance->dio_totint, instance->dio_totsend,
           instance->dio_totrecv,instance->dio_intcurrent,
	   instance->current_dag->rank == ROOT_RANK(instance) ? "BLUE" : "ORANGE");
#endif /* RPL_CONF_STATS */

  /* reset the redundancy counter */
  instance->dio_counter = 0;

  /* schedule the timer */
  PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", time);
  ctimer_set(&instance->dio_timer, time, &handle_dio_timer, instance);
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(scheduler_process, ev, data)
{
  PROCESS_BEGIN();	

#ifdef TESTLIST
	test_list();
	//PROCESS_YIELD_SCH();
#else

printf("<-init -> runqueues\n");	
	init_runqueues();
printf("<-begin-> scheduler process - [%s]\n", process_current->name);
printf("<-init -> sch process\n")	;
	sch_process_init(example_process1);
	sch_process_init(example_process2);
	sch_process_init(example_process3);
	sch_process_init(example_process4);
	sch_process_init(example_process5);
	sch_process_init(example_process6);
	sch_process_init(end_process);
//	sch_process_current = NULL;
#if (0)
//e test to see if it really push into the list!
printf("after push\n");
p = (struct sch_process	*)list_head(run_queues->arrays[0].queue[10].list);
printf("after get\n");
printf("example_process3 fuc[%s] [%s]\n", example_process3.name, sch_example_process3.old->name);
printf("<-test -> name - [%d][%d]\n", p->add->prio, p->old->thread);
#endif

printf("<-timer-> set\n");
	ctimer_set(&ct_sch_tick, QUANTUM_DURATION, ct_callback_sch_tick, NULL);

	while (1) {
		//printf("<-in   -> scheduler_process before yield\n");
		PROCESS_YIELD_SCH();
		//printf("<-in   -> scheduler_process after  yield\n");
	}

	printf("<-end  -> scheduler process - [%s] - should not reach here\n", 
					process_current->name);

#endif
  PROCESS_END();
}
Exemplo n.º 5
0
static void
handle_dao_timer(void *ptr)
{
  rpl_instance_t *instance;

  instance = (rpl_instance_t *)ptr;

  if(!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
    PRINTF("RPL: Postpone DAO transmission\n");
    ctimer_set(&instance->dao_timer, CLOCK_SECOND, handle_dao_timer, instance);
    return;
  }

  /* Send the DAO to the DAO parent set -- the preferred parent in our case. */
  if(instance->current_dag->preferred_parent != NULL) {
    PRINTF("RPL: handle_dao_timer - sending DAO\n");
    /* Set the route lifetime to the default value. */
    dao_output(instance->current_dag->preferred_parent, instance->default_lifetime, NULL);
#if UIP_IPV6_MULTICAST_RPL
    if(instance->mop == RPL_MOP_STORING_MULTICAST) {
      /* Send a DAO for own multicast addresses */
      for(i = 0; i < UIP_DS6_MADDR_NB; i++) {
        if(uip_ds6_if.maddr_list[i].isused
            && uip_is_addr_mcast_global(&uip_ds6_if.maddr_list[i].ipaddr)) {
          dao_output(instance->current_dag->preferred_parent, RPL_MCAST_LIFETIME,
              &uip_ds6_if.maddr_list[i].ipaddr);
        }
      }
      /* Iterate multicast routes and send DAOs */
      for(i = 0; i < UIP_DS6_MCAST_ROUTES; i++) {
        /* Don't send if it's also our own address, done that already */
        if(uip_ds6_mcast_table[i].isused) {
          if(uip_ds6_maddr_lookup(&uip_ds6_mcast_table[i].group) == NULL) {
            dao_output(instance->current_dag->preferred_parent, RPL_MCAST_LIFETIME,
                &uip_ds6_mcast_table[i].group);
          }
        }
      }
    }
#endif
  } else {
    PRINTF("RPL: No suitable DAO parent\n");
  }
  ctimer_stop(&instance->dao_timer);
}
Exemplo n.º 6
0
PROCESS_THREAD(blinker_test_loop, ev, data)
{
  PROCESS_BEGIN();

  //	(1)	UART Output
  printf("OTA Image Example: Starting\n");
#if PLATFORM_HAS_LEDS
  //	(2)	Start blinking green LED
  leds_init();
  leds_on(BLINKER_PIN);
#else
  printf("Platform does not support LED. Unique ID: %u\n", OTA_EXAMPLE_UNIQUE_ID);
#endif

  ctimer_set( &blink_timer, (CLOCK_SECOND/2), blink_looper, NULL);

  //  (3) Get metadata about the current firmware version
  OTAMetadata_t current_firmware;
  get_current_metadata( &current_firmware );
  printf("\nCurrent Firmware\n");
  print_metadata( &current_firmware );

  ext_flash_init();

  int ota_slot;
  OTAMetadata_t ota_metadata;

  printf("\nNewest Firmware:\n");
  ota_slot = find_newest_ota_image();
  while( get_ota_slot_metadata( ota_slot, &ota_metadata ) );
  print_metadata( &ota_metadata );

  printf("\nOldest Firmware:\n");
  ota_slot = find_oldest_ota_image();
  while( get_ota_slot_metadata( ota_slot, &ota_metadata ) );
  print_metadata( &ota_metadata );

  int empty_slot = find_empty_ota_slot();
  printf("\nEmpty OTA slot: #%u\n", empty_slot);

  //  (4) OTA Download!
  process_start(ota_download_th_p, NULL);

  PROCESS_END();
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
static void
create_dag_callback(void *ptr)
{
  const uip_ipaddr_t *root, *ipaddr;
  printf("\r\nCtimer timer callback for dag root");
  root = simple_rpl_root();
  ipaddr = simple_rpl_global_address();

  if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) {
    /* The RPL network we are joining is one that we created, so we
       become root. */
	printf("\r\n No root available, we'll make ourself as root ");
    if(to_become_root) {
      simple_rpl_init_dag_immediately();
      to_become_root = 0;
    }
  } else {
    rpl_dag_t *dag;

    dag = rpl_get_any_dag();
#if 1
    printf("\r\nFound a network we did not create, ");
    printf("version %d grounded %d preference %d used %d joined %d rank %d\n\r",
           dag->version, dag->grounded,
           dag->preference, dag->used,
           dag->joined, dag->rank);
#endif /* DEBUG */

    /* We found a RPL network that we did not create so we just join
       it without becoming root. But if the network has an infinite
       rank, we assume the network has broken, and we become the new
       root of the network. */

    if(dag->rank == INFINITE_RANK) {
      if(to_become_root) {
		printf("\r\n The dag rank is infinite, so we'll become the root");
        simple_rpl_init_dag_immediately();
        to_become_root = 0;
      }
    }

    /* Try again after the grace period */
    ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
  }
}
Exemplo n.º 8
0
// Handlers for unicast
static void recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
{ 
 if((from->u8[0] == RECEIVER) && (from->u8[1] == 0)){	 
 	 // Receive message
	 leds_on(LEDS_GREEN);
	 struct message mesg;
	 memcpy(&mesg, packetbuf_dataptr(), sizeof(mesg));
	 total_to_be_sent = mesg.seqno;
	 printf("Total to be sent: %d\n",total_to_be_sent);
	 leds_off(LEDS_GREEN); 	 
	 // Starting sending
	 //clock_delay(353*50);
	 ctimer_set(&timer1, 2*PACKETS_TIME, ctimer1_callback, NULL);
 }
 else{
	printf("ERROR: received an unexpected unicast from host (%d:%d)!\n",from->u8[0],from->u8[1]);  
 }
}
Exemplo n.º 9
0
/*
 * active scan - will scan all 16 channels in the 802.15.4 network
 * NOTE: this assumes 16 channels, starting from 11. Needs to be changed
 * if running on other than 2.4 GHz
 */
int
handler_802154_active_scan(scan_callback_t cb)
{
  /* if no scan is active - start one */
  if(!scan) {
    callback = cb;
    current_channel = 0;
#if (DISABLE_NETSELECT_RANDOM_CHANNEL == 0)
    channel_index = 0;
#endif /* (DISABLE_NETSELECT_RANDOM_CHANNEL == 0) */
    scan = 1;
    chseqno = framer_802154_next_seqno();
    NETSTACK_RADIO.set_value(RADIO_PARAM_RX_MODE, 0);
    ctimer_set(NULL, &scan_timer, (CLOCK_SECOND * 6) / 10, &handle_scan_timer, callback);
    return 1;
  }
  return 0;
}
Exemplo n.º 10
0
/*---------------------------------------------------------------------------*/
void
rudolph2_send(struct rudolph2_conn *c, clock_time_t send_interval)
{
  int len;

  c->hops_from_base = 0;
  c->version++;
  c->snd_nxt = 0;
  len = RUDOLPH2_DATASIZE;
  packetbuf_clear();
  for(c->rcv_nxt = 0; len == RUDOLPH2_DATASIZE; c->rcv_nxt++) {
    len = read_data(c, packetbuf_dataptr(), c->rcv_nxt);
  }
  c->flags = FLAG_LAST_RECEIVED;
  /*  printf("Highest chunk %d\n", c->rcv_nxt);*/
  send_data(c, SEND_INTERVAL);
  ctimer_set(&c->t, SEND_INTERVAL, timed_send, c);
}
PROCESS_THREAD(simple_process, ev, data)
{
	PROCESS_BEGIN();

	cc2420_set_txpower(12);
	init_router(&message_received);

	static struct ctimer ct;
	ctimer_set(&ct, CLOCK_SECOND * 60 * 5, send_message_after_5_minutes, NULL);

	process_start(&neighbor_discovery_process, NULL);

	printf("K = %d, MAX_NODES = %d, MAX_EDGES = %d, LINKADDR = %d.%d\n", (int) K, (int) MAX_NODES, (int) MAX_EDGES, linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
	printf("NODE_MEM = %dB, EDGE_MEM = %dB\n", (int)(sizeof(p_node_t) * MAX_NODES), (int)(sizeof(p_edge_t) * MAX_EDGES));
	printf("PACKETBUF_SIZE = %d, TXPOWER = %d, INTERVAL = %d - %d\n", PACKETBUF_SIZE, cc2420_get_txpower(), DISCOVERY_INTERVAL_MIN, DISCOVERY_INTERVAL_MAX);

	PROCESS_END();
}
Exemplo n.º 12
0
void motor_on(uint8_t level, clock_time_t length)
{	
	CMU_ClockEnable(cmuClock_TIMER2, true);  	
	TIMER_Enable(TIMER2,true);	
  	
  	if (level > 16) level = 16;
  	if (level == 0)
  	{
    		motor_stop(NULL);
  	}
  	else
  	{
  		TIMER_CompareBufSet(TIMER2, 0, level*200);

    		if (length > 0)
      			ctimer_set(&motor_timer, length, motor_stop, NULL);
  	}
}
Exemplo n.º 13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(gpio_output_process, ev, data)
{
    PROCESS_BEGIN();

    quarkX1000_gpio_init();
    quarkX1000_gpio_config(PIN, QUARKX1000_GPIO_OUT);

    quarkX1000_gpio_clock_enable();

    ctimer_set(&timer, CLOCK_SECOND / 2, timeout, NULL);

    printf("GPIO output example is running\n");
    PROCESS_YIELD();

    quarkX1000_gpio_clock_disable();

    PROCESS_END();
}
Exemplo n.º 14
0
void
rpl_schedule_dao(rpl_instance_t *instance)
{
  clock_time_t expiration_time;

  expiration_time = etimer_expiration_time(&instance->dao_timer.etimer);

  if(!etimer_expired(&instance->dao_timer.etimer)) {
    PRINTF("RPL: DAO timer already scheduled\n");
  } else {
    expiration_time = RPL_DAO_LATENCY / 2 +
      (random_rand() % (RPL_DAO_LATENCY));
    PRINTF("RPL: Scheduling DAO timer %u ticks in the future\n",
           (unsigned)expiration_time);
    ctimer_set(&instance->dao_timer, expiration_time,
               handle_dao_timer, instance);
  }
}
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(virtualsense_shell_process, ev, data)
{
  PROCESS_BEGIN();

#if WITH_PERIODIC_DEBUG
  ctimer_set(&debug_timer, 20 * CLOCK_SECOND, periodic_debug, NULL);
#endif /* WITH_PERIODIC_DEBUG */

  serial_shell_init();
  shell_reboot_init();
  shell_gateway_init(NULL);

#if DEBUG_SNIFFERS
  rime_sniffer_add(&s);
#endif /* DEBUG_SNIFFERS */
  
  PROCESS_END();
}
Exemplo n.º 16
0
/*---------------------------------------------------------------------------*/
static void
get_hdc_reading()
{
  int value;
  static int seq_id;
  clock_time_t next = HDC_SENSOR_READING_PERIOD;

  value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP);
  hdc1000_buffer[0] = value;
  value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY);
  hdc1000_buffer[1] = value;
  memset(buf, 0, MAX_PAYLOAD_LEN);
  snprintf(buf, MAX_PAYLOAD_LEN, "%d %d.%02d,%d.%02d", ++seq_id, hdc1000_buffer[0] / 100,
               hdc1000_buffer[0] % 100, hdc1000_buffer[1] / 100,
               hdc1000_buffer[1] % 100);
  uip_udp_packet_send(client_conn, buf, strlen(buf));
  ctimer_set(&hdc_timer, next, init_hdc_reading, NULL);
}
Exemplo n.º 17
0
/*---------------------------------------------------------------------------*/
struct uip_packetqueue_packet *
uip_packetqueue_alloc(struct net_buf *buf, struct uip_packetqueue_handle *handle, clock_time_t lifetime)
{
  PRINTF("uip_packetqueue_alloc %p\n", handle);
  if(handle->packet != NULL) {
    PRINTF("handle->packet != NULL, so failed to alloc\n");
    return NULL;
  }
  handle->packet = memb_alloc(&packets_memb);
  if(handle->packet != NULL) {
    PRINTF("uip_packetqueue_alloc packet %p\n", handle->packet);
    ctimer_set(buf, &handle->packet->lifetimer, lifetime,
               packet_timedout, handle);
  } else {
    PRINTF("uip_packetqueue_alloc failed\n");
  }
  return handle->packet;
}
Exemplo n.º 18
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
  PROCESS_BEGIN();

  NETSTACK_MAC.off(0);
  printf("hello world\n");



  SX1276IoInit();

  RadioEvents.TxDone = OnTxDone;
  RadioEvents.RxDone = OnRxDone;
  RadioEvents.TxTimeout = OnTxTimeout;
  RadioEvents.RxTimeout = OnRxTimeout;
  RadioEvents.RxError = OnRxError;

  Radio.Init( &RadioEvents );

  Radio.SetChannel( RF_FREQUENCY );
  Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                 true, 0, 0, LORA_IQ_INVERSION_ON, 3000000 );
  printf("tx config done\n");
  Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                                 LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                                 LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                                 0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

  printf("rx config done\n");
  Buffer[0] = 'H';
  Buffer[1] = 'E';
  Buffer[2] = 'L';
  Buffer[3] = 'L';
  Buffer[4] = 'O';

  ctimer_set(&sendtimer, 128*10, sendMessage,NULL);

while(1){
  PROCESS_YIELD();
}
  PROCESS_END();
}
Exemplo n.º 19
0
/*---------------------------------------------------------------------------*/
void
rpl_host_determination(rpl_instance_t *instance)
{
  uint8_t num;
  uip_ds6_nbr_t *nbr;

  num = 0;
  nbr = nbr_table_head(ds6_neighbors);
  while(nbr != NULL) {
    if(nbr->state == NBR_REGISTERED && nbr->isrouter == ISROUTER_NODEFINE) {
      nbr->isrouter = ISROUTER_TESTING;
      num++;
    }
    nbr = nbr_table_next(ds6_neighbors, nbr);
  }
  if(num != 0) {
    ctimer_set(&instance->host_timer, 60 * CLOCK_SECOND, &handle_host_timer, instance);
  }
}
Exemplo n.º 20
0
/*---------------------------------------------------------------------------*/
static void
at_cmd_reset_callback(struct at_cmd *cmd, uint8_t len, char *data)
{
  uint8_t reset_val = atoi(&data[9]);
  /* AT&RESET=n, where n:
   * 0 : CC2538 soft reset
   */
  if((reset_val != 0) && (reset_val != 1)) {
    AT_RESPONSE(AT_DEFAULT_RESPONSE_ERROR);
    return;
  }

  /* Send the response and wait a second until executing the command */
  AT_RESPONSE(AT_DEFAULT_RESPONSE_OK);

  if(reset_val == 0) {
    ctimer_set(&ct, CLOCK_SECOND, sys_ctrl_reset, NULL);
  }
}
Exemplo n.º 21
0
Arquivo: csma.c Projeto: cetic/6lbr
/*---------------------------------------------------------------------------*/
static void
schedule_transmission(struct neighbor_queue *n)
{
  clock_time_t delay;
  int backoff_exponent; /* BE in IEEE 802.15.4 */

  backoff_exponent = MIN(n->collisions, CSMA_MAX_BE);

  /* Compute max delay as per IEEE 802.15.4: 2^BE-1 backoff periods  */
  delay = ((1 << backoff_exponent) - 1) * backoff_period();
  if(delay > 0) {
    /* Pick a time for next transmission */
    delay = random_rand() % delay;
  }

  PRINTF("csma: scheduling transmission in %u ticks, NB=%u, BE=%u\n",
      (unsigned)delay, n->collisions, backoff_exponent);
  ctimer_set(&n->transmit_timer, delay, transmit_packet_list, n);
}
Exemplo n.º 22
0
/*---------------------------------------------------------------------------*/
static void
recv(struct broadcast_conn *bc, const rimeaddr_t *from)
{
    struct trickle_conn *c = (struct trickle_conn *)bc;
    uint16_t seqno = packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID);

    PRINTF("%d.%d: trickle recv seqno %d from %d.%d our %d data len %d channel %d\n",
           rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
           seqno,
           from->u8[0], from->u8[1],
           c->seqno,
           packetbuf_datalen(),
           packetbuf_attr(PACKETBUF_ATTR_CHANNEL));

    if(seqno == c->seqno)
    {
        /*    c->cb->recv(c);*/
        ++c->duplicates;
    }
    else if(SEQNO_LT(seqno, c->seqno))
    {
        c->interval_scaling = 0;
        send(c);
    }
    else     /* hdr->seqno > c->seqno */
    {
#if CONTIKI_TARGET_NETSIM
        /*    ether_set_line(from->u8[0], from->u8[1]);*/
#endif /* CONTIKI_TARGET_NETSIM */
        c->seqno = seqno;
        /* Store the incoming data in the queuebuf */
        if(c->q != NULL)
        {
            queuebuf_free(c->q);
        }
        c->q = queuebuf_new_from_packetbuf();
        c->interval_scaling = 0;
        reset_interval(c);
        ctimer_set(&c->first_transmission_timer, random_rand() % c->interval,
                   send, c);
        c->cb->recv(c);
    }
}
Exemplo n.º 23
0
/*---------------------------------------------------------------------------*/
static void
periodic(void *ptr)
{
  struct route_entry *e;

  for(e = list_head(route_table); e != NULL; e = list_item_next(e)) {
    e->time++;
    if(e->time >= max_time) {
      PRINTF("route periodic: removing entry to %d.%d with nexthop %d.%d and cost %d\n",
	     e->dest.u8[0], e->dest.u8[1],
	     e->nexthop.u8[0], e->nexthop.u8[1],
	     e->cost);
      list_remove(route_table, e);
      memb_free(&route_mem, e);
    }
  }

  ctimer_set(&t, CLOCK_SECOND, periodic, NULL);
}
Exemplo n.º 24
0
/*---------------------------------------------------------------------------*/
static void
free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
{
  if(p != NULL) {

//ADILA EDIT 09/02/14
//cc2420_set_channel(list_length(n->queued_packet_list) + 10);
//printf("%d BEFORE FREE Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));
//-------------------

    /* Remove packet from list and deallocate */
    list_remove(n->queued_packet_list, p);

    queuebuf_free(p->buf);
    memb_free(&metadata_memb, p->ptr);
    memb_free(&packet_memb, p);

//ADILA EDIT 09/02/14
if((list_length(n->queued_packet_list)) == 0) {
cc2420_set_channel(26);
//printf("%d empty Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));

}
//-------------------

    PRINTF("csma: free_queued_packet, queue length %d\n",
        list_length(n->queued_packet_list));
    if(list_head(n->queued_packet_list) != NULL) {
      /* There is a next packet. We reset current tx information */
      n->transmissions = 0;
      n->collisions = 0;
      n->deferrals = 0;
      /* Set a timer for next transmissions */
      ctimer_set(&n->transmit_timer, default_timebase(),
                 transmit_packet_list, n);
    } else {
      /* This was the last packet in the queue, we free the neighbor */
      ctimer_stop(&n->transmit_timer);
      list_remove(neighbor_list, n);
      memb_free(&neighbor_memb, n);
    }
  }
}
Exemplo n.º 25
0
PROCESS_THREAD(sender_process, ev, data)
{
    
    static struct etimer periodic;
    static struct ctimer backoff_timer;

    PROCESS_BEGIN();

//    PROCESS_PAUSE();

    set_global_address();
    
    PRINTF("The sender process begins.\n");
    
    print_local_addresses();
    /* new connection with remote host */
    sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL);
    if(sender_conn == NULL)
    {
        PRINTF("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT));
    PRINTF("Created a connection with the server ");
    PRINT6ADDR(&sender_conn->ripaddr);
    PRINTF(" local/remote port %u/%u\n", UIP_HTONS(sender_conn->lport),
                UIP_HTONS(sender_conn->rport));

    etimer_set(&periodic, SEND_INTERVAL * CLOCK_SECOND);
    while(1) {
        PROCESS_YIELD();
        if(ev == tcpip_event)
          tcpip_handler();

        if(etimer_expired(&periodic))
        {
            etimer_reset(&periodic);
            ctimer_set(&backoff_timer, RANDWAIT * CLOCK_SECOND, send_packet, NULL);
        }
    }

    PROCESS_END();
}
Exemplo n.º 26
0
/*---------------------------------------------------------------------------*/
static void
create_dag_callback(void *ptr)
{
  const uip_ipaddr_t *root, *ipaddr;

  root = dag_root();
  ipaddr = get_global_address();

  if(root == NULL || uip_ipaddr_cmp(root, ipaddr)) {
    /* The RPL network we are joining is one that we created, so we
       become root. */
    if(to_become_root) {
      rpl_dag_root_init_dag_immediately();
      to_become_root = 0;
    }
  } else {
    rpl_dag_t *dag;

    dag = rpl_get_any_dag();

    PRINTF("RPL: Found a network we did not create\n");
    PRINTF("RPL: version %d grounded %d preference %d used %d joined %d rank %d\n",
           dag->version, dag->grounded,
           dag->preference, dag->used,
           dag->joined, dag->rank);

    /* We found a RPL network that we did not create so we just join
       it without becoming root. But if the network has an infinite
       rank, we assume the network has broken, and we become the new
       root of the network. */

    if(dag->rank == INFINITE_RANK) {
      if(to_become_root) {
        rpl_dag_root_init_dag_immediately();
        to_become_root = 0;
      }
    }

    /* Try again after the grace period */
    ctimer_set(&c, RPL_DAG_GRACE_PERIOD, create_dag_callback, NULL);
  }
}
Exemplo n.º 27
0
/*---------------------------------------------------------------------------*/
static void
free_queued_packet(void)
{
  struct queued_packet *q;

  //  printf("q %d\n", list_length(queued_packet_list));

  q = list_head(queued_packet_list);

  if(q != NULL) {
    queuebuf_free(q->buf);
    list_remove(queued_packet_list, q);
    memb_free(&packet_memb, q);
    PRINTF("csma: free_queued_packet, queue length %d\n",
           list_length(queued_packet_list));
    if(list_length(queued_packet_list) > 0) {
      ctimer_set(&transmit_timer, default_timebase(), transmit_queued_packet, NULL);
    }
  }
}
Exemplo n.º 28
0
/* Removes a queuebuf from its swap file */
static void
queuebuf_remove_from_file(int swap_id)
{
  int fileid;
  if(swap_id != -1) {
    fileid = swap_id / NQBUF_PER_FILE;
    qbuf_files[fileid].usage--;

    /* The file is full but doesn't contain any more queuebuf, mark it as renewable */
    if(qbuf_files[fileid].usage == 0 && fileid != next_swap_id / NQBUF_PER_FILE) {
      qbuf_files[fileid].renewable = 1;
      /* This file is renewable, set a timer to renew files */
      ctimer_set(&renew_timer, 0, qbuf_renew_all, NULL);
    }

    if(tmpdata_qbuf->swap_id == swap_id) {
      tmpdata_qbuf->swap_id = -1;
    }
  }
}
Exemplo n.º 29
0
static void
set_dao_lifetime_timer(rpl_instance_t *instance)
{
  if(rpl_get_mode() == RPL_MODE_FEATHER) {
    return;
  }

  /* Set up another DAO within half the expiration time, if such a
     time has been configured */
  if(instance->lifetime_unit != 0xffff && instance->default_lifetime != 0xff) {
    clock_time_t expiration_time;
    expiration_time = (clock_time_t)instance->default_lifetime *
      (clock_time_t)instance->lifetime_unit *
      CLOCK_SECOND / 2;
    PRINTF("RPL: Scheduling DAO lifetime timer %u ticks in the future\n\r",
           (unsigned)expiration_time);
    ctimer_set(&instance->dao_lifetime_timer, expiration_time,
               handle_dao_timer, instance);
  }
}
Exemplo n.º 30
0
/*---------------------------------------------------------------------------*/
int
handler_802154_frame_received(frame802154_t *frame)
{
  if(answer_beacon_requests &&
     frame->fcf.frame_type == FRAME802154_CMDFRAME &&
     frame->payload[0] == FRAME802154_BEACONREQ) {
    others_beacon_reply = 0;
    ctimer_set(NULL, &beacon_send_timer,
               CLOCK_SECOND / 16 +
               (CLOCK_SECOND * (random_rand() & 0xff)) / 0x200,
               &handle_beacon_send_timer, NULL);
    return 1;
  }
  if(frame->fcf.frame_type == FRAME802154_BEACONFRAME) {
    HANDLER_802154_STAT(handler_802154_stats.beacons_received++);
    handle_beacon(frame);
    return 1;
  }
  return 0;
}