Beispiel #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(announce_blink_process, ev, data)
{
  PROCESS_BEGIN();

  /* XXX the Sentilla JCreate has 8 LEDs, and we need to set the ports
     correctly. */
#if CONTIKI_TARGET_SKY
  LEDS_PxDIR = 0xff;
  LEDS_PxOUT = 0xff;
#endif /* CONTIKI_TARGET_SKY */

  announcement_register(&announcement, 80, 0,
			received_announcement);

  list_init(neighbor_table);
  memb_init(&neighbor_mem);

#if CONTIKI_TARGET_NATIVE
  {
    int i;
    for(i = 0; i < 10; ++i) {
      rimeaddr_t r;
      r.u8[0] = r.u8[1] = i;
      received_announcement(NULL, &r, 0, 0);
      received_announcement(NULL, &r, 0, 0);
    }
  }
#endif /* CONTIKI_TARGET_NATIVE */
  
#if CONTIKI_TARGET_SKY
  acc_sensor.activate();

  /* Lower the transmission power for the announcements so that only
     close-range neighbors are noticed. (Makes for a nicer visual
     effect.) */
  xmac_set_announcement_radio_txpower(1);
#endif /* CONTIKI_TARGET_SKY */
  
  while(1) {
    static struct etimer e;
    static uint16_t last_value;
    
    etimer_set(&e, CLOCK_SECOND / 8);
    PROCESS_WAIT_EVENT();
#if CONTIKI_TARGET_SKY
    if(acc_sensor.value(1) / 256 != last_value) {
      last_value = acc_sensor.value(1) / 256;
      announcement_listen(1);
    }
#endif /* CONTIKI_TARGET_SKY */
  }
  
  PROCESS_END();
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
int
collect_send(struct collect_conn *tc, int rexmits)
{
    struct neighbor *n;

    packetbuf_set_attr(PACKETBUF_ATTR_EPACKET_ID, tc->seqno++);
    packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, &rimeaddr_node_addr);
    packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
    packetbuf_set_attr(PACKETBUF_ATTR_TTL, MAX_HOPLIM);
    packetbuf_set_attr(PACKETBUF_ATTR_MAX_REXMIT, rexmits);

    if(tc->rtmetric == SINK) {
        packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 0);
        if(tc->cb->recv != NULL) {
            tc->cb->recv(packetbuf_addr(PACKETBUF_ADDR_ESENDER),
                         packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID),
                         packetbuf_attr(PACKETBUF_ATTR_HOPS));
        }
        return 1;
    } else {
        n = neighbor_best();
        if(n != NULL) {
#if CONTIKI_TARGET_NETSIM
            ether_set_line(n->addr.u8[0], n->addr.u8[1]);
#endif /* CONTIKI_TARGET_NETSIM */
            PRINTF("%d.%d: sending to %d.%d\n",
                   rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1],
                   n->addr.u8[RIMEADDR_SIZE-2], n->addr.u8[RIMEADDR_SIZE-1]);
            if(packetqueue_enqueue_packetbuf(&forwarding_queue, FORWARD_PACKET_LIFETIME,
                                             tc)) {
                send_queued_packet();
                return 1;
            } else {
                PRINTF("%d.%d: drop originated packet: no queuebuf\n",
                       rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
            }
        } else {
            /*      printf("Didn't find any neighbor\n");*/
            PRINTF("%d.%d: did not find any neighbor to send to\n",
                   rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
            announcement_listen(1);
            if(packetqueue_enqueue_packetbuf(&forwarding_queue, FORWARD_PACKET_LIFETIME,
                                             tc)) {
                return 1;
            } else {
                PRINTF("%d.%d: drop originated packet: no queuebuf\n",
                       rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1]);
            }
        }
    }
    return 0;
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighborscall(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  announcement_listen(1);
  
  /*  printf("neighbor_num %d\n", collect_neighbor_list_num(&neighbor_list)); */
  
  for(s->u.count = 0; s->u.count < collect_neighbor_list_num(&neighbor_list); s->u.count++) {
    /*  printf("count %d\n", s->u.count); */
    if(collect_neighbor_list_get(&neighbor_list, s->u.count) != NULL) {
      /*  printf("!= NULL\n"); */
      PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
    }
  }

  PSOCK_END(&s->sout);
}
Beispiel #4
0
void
httpd_cgi_init(void)
{
  
  httpd_cgi_add(&sensors);
  httpd_cgi_add(&nodeid);
  httpd_cgi_add(&neighbors);

  announcement_register(&announcement, 31,
			received_announcement);
  announcement_listen(2);

  /*  neighbor_discovery_open(&conn, 31,
			  CLOCK_SECOND * 4,
			  CLOCK_SECOND * 20,
			  CLOCK_SECOND * 60,
			  &neighbor_discovery_callbacks);
			  neighbor_discovery_start(&conn, 0);*/
}
Beispiel #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(announce_blink_process, ev, data)
{
  PROCESS_BEGIN();

  announcement_register(&announcement, 80, received_announcement);

  list_init(neighbor_table);
  memb_init(&neighbor_mem);

  {
    int i;
    for(i = 0; i < 10; ++i) {
      rimeaddr_t r;
      r.u8[0] = r.u8[1] = i;
      received_announcement(NULL, &r, 0, 0);
      received_announcement(NULL, &r, 0, 0);
    }
  }
  
  SENSORS_ACTIVATE(acc_sensor);

  /* Lower the transmission power for the announcements so that only
     close-range neighbors are noticed. (Makes for a nicer visual
     effect.) */
  xmac_set_announcement_radio_txpower(1);
  
  while(1) {
    static struct etimer e;
    static uint16_t last_value;
    
    etimer_set(&e, CLOCK_SECOND / 8);
    PROCESS_WAIT_EVENT();
    if(acc_sensor.value(1) / 256 != last_value) {
      last_value = acc_sensor.value(1) / 256;
      announcement_listen(1);
    }
  }
  
  PROCESS_END();
}
Beispiel #6
0
/*---------------------------------------------------------------------------*/
void
collect_open(struct collect_conn *tc, uint16_t channels,
             const struct collect_callbacks *cb)
{
#if !COLLECT_ANNOUNCEMENTS
    neighbor_discovery_open(&tc->neighbor_discovery_conn, channels,
                            CLOCK_SECOND * 2,
                            CLOCK_SECOND * 10,
                            CLOCK_SECOND * 60,
                            &neighbor_discovery_callbacks);
#endif /* !COLLECT_ANNOUNCEMENTS */
    runicast_open(&tc->runicast_conn, channels + 1, &runicast_callbacks);
    channel_set_attributes(channels + 1, attributes);
    tc->rtmetric = RTMETRIC_MAX;
    tc->cb = cb;
#if COLLECT_ANNOUNCEMENTS
    announcement_register(&tc->announcement, channels, tc->rtmetric,
                          received_announcement);
    announcement_listen(2);
#else
    neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
#endif /* COLLECT_ANNOUNCEMENTS */
    neighbor_init();
}