Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cc2420_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("cc2420_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "poll");
#endif /* CC2420_TIMETABLE_PROFILING */
    
    PRINTF("cc2420_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = cc2420_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    
    packetbuf_set_datalen(len);
    
    NETSTACK_RDC.input();
#if CC2420_TIMETABLE_PROFILING
    TIMETABLE_TIMESTAMP(cc2420_timetable, "end");
    timetable_aggregate_compute_detailed(&aggregate_time,
                                         &cc2420_timetable);
      timetable_clear(&cc2420_timetable);
#endif /* CC2420_TIMETABLE_PROFILING */
  }

  PROCESS_END();
}
Exemplo n.º 2
0
/*
 * process rx packet, when process receives poll
 */
static void
pollhandler(void)
{
  int len;

  do {
/*        printf("p(");*/
    packetbuf_clear();
    len = read_packet(packetbuf_dataptr(), PACKETBUF_SIZE);

    if(len > 0) {
      packetbuf_set_datalen(len);
/*            printf("RDC input %d\n", len);*/
      NETSTACK_RDC.input();
    }

    /* If we received a packet (or parts thereof) while processing the
       previous packet, we immediately pull it out from the RX
       FIFO. */
    /*    printf("[");*/
    cc1101_rx_interrupt();
    /*    printf("]");*/
    //    printf(")\n");
  } while(packet_rx_len > 0);
}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------*/
void
packetbuf_reference(void *ptr, uint16_t len)
{
  packetbuf_clear();
  packetbufptr = ptr;
  buflen = len;
}
static void recv_uc(struct unicast_conn *c, const rimeaddr_t * from)
{
    sec_since_start = clock_seconds();
    printf("\n%d - MSG from %d.%d\n", sec_since_start, from->u8[0], from->u8[1]);
    
    msg = (struct unicast_message *)packetbuf_dataptr();  
    packetbuf_clear();  
    //printf("MSG TYPE: %d \tCMD: %s \tVALUE: %d\n", msg->type, get_cmd(msg->cmd), msg->value);
    switch (msg->cmd) {
    case CMD_FAN_ON:
	printf("PG:FAN ON\n");
	break;
    case CMD_FAN_OFF:
	printf("PG:FAN OFF\n");
	break;
    case CMD_HEATER_ON:
	printf("PG:HEAT ON\n");
	break;
    case CMD_HEATER_OFF:
	printf("PG:HEAT OFF\n");
	break;
    case CMD_LIGHT_ON:
	printf("PG:LIGHT ON\n");
	break;
    case CMD_LIGHT_OFF:
	printf("PG:LIGHT OFF\n");
	break;
    default:
	printf("\n%s\n", get_cmd(msg->cmd));
    }

}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static int
slip_radio_cmd_handler(const uint8_t *data, int len)
{
  int i;
  if(data[0] == '!') {
    /* should send out stuff to the radio - ignore it as IP */
    /* --- s e n d --- */
    if(data[1] == 'S') {
      int pos;
      packet_ids[packet_pos] = data[2];

      packetbuf_clear();
      pos = packetutils_deserialize_atts(&data[3], len - 3);
      if(pos < 0) {
        PRINTF("slip-radio: illegal packet attributes\n");
        return 1;
      }
      pos += 3;
      len -= pos;
      if(len > PACKETBUF_SIZE) {
        len = PACKETBUF_SIZE;
      }
      memcpy(packetbuf_dataptr(), &data[pos], len);
      packetbuf_set_datalen(len);

      PRINTF("slip-radio: sending %u (%d bytes)\n",
             data[2], packetbuf_datalen());

      /* parse frame before sending to get addresses, etc. */
      no_framer.parse();
      NETSTACK_MAC.send(packet_sent, &packet_ids[packet_pos]);

      packet_pos++;
      if(packet_pos >= sizeof(packet_ids)) {
	packet_pos = 0;
      }
      return 1;
    } else if(data[1] == 'R' && len == 2) {
#if !CONTIKI_TARGET_CC2538DK
      PRINTF("Rebooting\n");
      watchdog_reboot();
#endif
      return 1;
    }
  } else if(uip_buf[0] == '?') {
    PRINTF("Got request message of type %c\n", uip_buf[1]);
    if(data[1] == 'M' && len == 2) {
      /* this is just a test so far... just to see if it works */
      uip_buf[0] = '!';
      uip_buf[1] = 'M';
      for(i = 0; i < 8; i++) {
        uip_buf[2 + i] = uip_lladdr.addr[i];
      }
      uip_len = 10;
      cmd_send(uip_buf, uip_len);
      return 1;
    }
  }
  return 0;
}
Exemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void
send_adv(clock_time_t interval)
{
  struct announcement_msg *adata;
  struct announcement *a;

  packetbuf_clear();
  adata = packetbuf_dataptr();
  adata->num = 0;
  for(a = announcement_list(); a != NULL; a = a->next) {
    adata->data[adata->num].id = a->id;
    adata->data[adata->num].value = a->value;
    adata->num++;
  }

  packetbuf_set_datalen(ANNOUNCEMENT_MSG_HEADERLEN +
		      sizeof(struct announcement_data) * adata->num);

  PRINTF("%d.%d: sending neighbor advertisement with %d announcements\n",
	 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], adata->num);

  if(adata->num > 0) {
    /* Send the packet only if it contains more than zero announcements. */
    ipolite_send(&c.c, interval, packetbuf_datalen());
  }
}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(stm32w_radio_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  PRINTF("stm32w_radio_process: started\r\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    PRINTF("stm32w_radio_process: calling receiver callback\r\n");

#if DEBUG > 1
    for(uint8_t c = 1; c <= RCVD_PACKET_LEN; c++) {
      PRINTF("%x", stm32w_rxbuf[c]);
    }
    PRINTF("\r\n");
#endif

    packetbuf_clear();
    len = stm32w_radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    if(len > 0) {
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    }
    if(!RXBUFS_EMPTY()) {
      /*
       * Some data packet still in rx buffer (this happens because process_poll
       * doesn't queue requests), so stm32w_radio_process needs to be called
       * again.
       */
      process_poll(&stm32w_radio_process);
    }
  }
  PROCESS_END();
}
Exemplo n.º 8
0
/**
 * \brief      Radio RF233 process, infinitely awaits a poll, then checks radio
 *             state and handles received data.
 */
PROCESS_THREAD(rf233_radio_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  PRINTF("RF233: started.\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    PRINTF("RF233: polled.\n");

    if(interrupt_callback_wants_poll) {
      rf233_interrupt_poll();
    }

    packetbuf_clear();
    // packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    len = rf233_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    if(len > 0) {
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    } else {
      PRINTF("RF233: error while reading: %d\n", len);
    }
  }
  PROCESS_END();
}
Exemplo n.º 9
0
struct net_buf *l2_buf_get_reserve(uint16_t reserve_head)
#endif
{
	struct net_buf *buf;

	buf = net_buf_get(&free_l2_bufs, reserve_head);
	if (!buf) {
#ifdef DEBUG_L2_BUFS
		NET_ERR("Failed to get free L2 buffer (%s():%d)\n",
			caller, line);
#else
		NET_ERR("Failed to get free L2 buffer\n");
#endif
		return NULL;
	}

	dec_free_l2_bufs(buf);

	NET_BUF_CHECK_IF_NOT_IN_USE(buf);

#ifdef DEBUG_L2_BUFS
	NET_DBG("[%d] buf %p reserve %u ref %d (%s():%d)\n",
		get_free_l2_bufs(), buf, reserve_head, buf->ref,
		caller, line);
#else
	NET_DBG("buf %p reserve %u ref %d\n", buf, reserve_head, buf->ref);
#endif

	packetbuf_clear(buf);

	return buf;
}
Exemplo n.º 10
0
/*---------------------------------------------------------------------------*/
static void
recv( const struct mac_driver *c)
{
	packetbuf_set_attr(PACKETBUF_ATTR_CHANNEL, 34);
	int len = c->read();
	char cleanString [128];
	int cleanLen = 0;
	int i;
	char* in=  (char*)packetbuf_dataptr();
	for ( i = 0; i < len; i++)
	{
		
		if ( ( in[i]  >= ' ' && in[i]  <= 'z' ))
		{
			cleanString[cleanLen] =  in[i];
			printf("%i %i\n",i,in[i]);
			cleanLen++;
		}
	}
	//cleanString[cleanLen] = '\0';
	cleanLen++;
	printf("message received, len = %d, '%s'\n", cleanLen, cleanString);
	//printf("message received, len = %d, '%s'\n", len, (char *)packetbuf_dataptr());
	leds_toggle(LEDS_GREEN);
	packetbuf_clear();
	//packetbuf_attr_clear();


}	
Exemplo n.º 11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(uz2400_process, ev, data)
{
  int len;
  PROCESS_BEGIN();

  PRINTF("uz2400_process: started\n");

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
//#if UZ2400_TIMETABLE_PROFILING
//    TIMETABLE_TIMESTAMP(uz2400_timetable, "poll");
//#endif /* UZ2400_TIMETABLE_PROFILING */

    PRINTF("uz2400_process: calling receiver callback\n");

    packetbuf_clear();
    packetbuf_set_attr(PACKETBUF_ATTR_TIMESTAMP, last_packet_timestamp);
    
    len = uz2400_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    packetbuf_set_datalen(len);

    NETSTACK_RDC.input();
    /* flushrx(); */
//#if UZ2400_TIMETABLE_PROFILING
//    TIMETABLE_TIMESTAMP(uz2400_timetable, "end");
//    timetable_aggregate_compute_detailed(&aggregate_time,
//                                         &uz2400_timetable);
//    timetable_clear(&uz2400_timetable);
//#endif /* UZ2400_TIMETABLE_PROFILING */
	//EXTI4_ClearBit();
  }

  PROCESS_END();
}
Exemplo n.º 12
0
/*---------------------------------------------------------------------------*/
void
rime_init(const struct mac_driver *m)
{
  queuebuf_init();
  route_init();
  packetbuf_clear();
  neighbor_init();
  announcement_init();
  rime_mac = m;
  rime_mac->set_receive_function(input);

  chameleon_init(&chameleon_bitopt);
#if ! RIME_CONF_NO_POLITE_ANNOUCEMENTS
  /* XXX This is initializes the transmission of announcements but it
   * is not currently certain where this initialization is supposed to
   * be. Also, the times are arbitrarily set for now. They should
   * either be configurable, or derived from some MAC layer property
   * (duty cycle, sleep time, or something similar). But this is OK
   * for now, and should at least get us started with experimenting
   * with announcements.
   */
  polite_announcement_init(POLITE_ANNOUNCEMENT_CHANNEL,
			   POLITE_ANNOUNCEMENT_START_TIME,
			   POLITE_ANNOUNCEMENT_MAX_TIME);
#endif /* ! RIME_CONF_NO_POLITE_ANNOUCEMENTS */
}
Exemplo n.º 13
0
/*---------------------------------------------------------------------------*/
static void
send_adv(void *ptr)
{
  struct announcement_msg *adata;
  struct announcement *a;

  packetbuf_clear();
  adata = packetbuf_dataptr();
  adata->num = 0;
  for(a = announcement_list(); a != NULL && a->has_value; a = list_item_next(a)) {
    adata->data[adata->num].id = a->id;
    adata->data[adata->num].value = a->value;
    adata->num++;
  }

  packetbuf_set_datalen(ANNOUNCEMENT_MSG_HEADERLEN +
		      sizeof(struct announcement_data) * adata->num);

  PRINTF("%d.%d: sending neighbor advertisement with %d announcements\n",
	 linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], adata->num);

  if(adata->num > 0) {
    /* Send the packet only if it contains more than zero announcements. */
    broadcast_send(&c.c);
  }
  PRINTF("%d.%d: sending neighbor advertisement with val %d\n",
	 linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
	 c.val);
}
Exemplo n.º 14
0
/**
 * @brief transmit_epidemic
 */
static void transmit_epidemic(){

    packetbuf_clear();
    
    data_packet_t *dpkt = (data_packet_t*)packetbuf_dataptr();
    
    if(isAnchorFlag){
        dpkt->type = ANCHOR_PKT;
    }else{
        dpkt->type = PROBE_PKT;
    }
    //add sender offset.
    dpkt->offset   = probe_offset;
    dpkt->period   = get_node_period();
    dpkt->src_id   = rimeaddr_node_addr.u8[0];
    
    uint8_t pldSize = 0;
    if(radio_read_flag == 0){
        if(list_access_flag == 0){
            list_access_flag = 1;
            pldSize = neighs_add2payload(&dpkt->data[0], isAnchorFlag, probe_offset);
            list_access_flag = 0;
        }

        //if(pldSize){

            rtimer_clock_t t0;
            uint8_t i = 0, pkt_seen = 0, ccaCounter= 0;

            //ccaCounter= randomint_between(CCA_COUNT_MAX, CCA_COUNT_MAX_TX);

	    ccaCounter = /*CCA_COUNT_MAX +*/ random_int(CCA_COUNT_MAX_TX);
	    //watchdog
	    watchdog_periodic();
	     
            for( i = 0; i < ccaCounter && beacon_2_flag; i++){

		//watchdog
		watchdog_periodic();	
		
		
                t0 = RTIMER_NOW();

                while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + CCA_CHECK_TIME)){
                    //do nothing.. KUNANGA
                }

                if(NETSTACK_RADIO.channel_clear() == 0){
                    pkt_seen = 1;
                    break; // maybe return here .. collision is expected
                }

            }

            if((pkt_seen == 0) && (radio_read_flag == 0)){
                NETSTACK_RADIO.send((void*)packetbuf_dataptr(),DATAPKT_HDR_LEN + pldSize);
            }
        //} //end of pldSize
    }
}
/**
 * send the broadcast list to the neighbor
 */
void send_br_list(struct broadcast_conn *broadcastConn){
    Br_msg_list *br_msg_list;
    Br_msg_list *remove;
    if(list_length(broadcast_list)>0){
        for(br_msg_list = list_head(broadcast_list);br_msg_list!=NULL;){
            packetbuf_copyfrom(&br_msg_list->broadcast_msg,sizeof(Broadcast_msg));
            printf("[BC] @%d @%u.%u base station@%u.%u\n", clock_seconds(),rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
                   br_msg_list->broadcast_msg.base_station.u8[0],br_msg_list->broadcast_msg.base_station.u8[1]);
            broadcast_send(broadcastConn);
            packetbuf_clear();
            print_br_list();
            remove = br_msg_list;
            br_msg_list = br_msg_list->next;
            if(local_node.sen_type == BASE_STATION && (remove->broadcast_msg.msg_type==SUBSCRIBE||
                                                       remove->broadcast_msg.msg_type==UNSUBSCRIBE)){
            }else if(remove!=NULL&&list_length(broadcast_list)>1){
                list_remove(broadcast_list,remove);
                memb_free(&broadcast_list_memb, remove);
                printf("[DELET-BR-MSG] msg sub_type %u msg_type %u br list length %u\n",remove->broadcast_msg.subscribe_type,
                       remove->broadcast_msg.msg_type,list_length(broadcast_list));
                remove = NULL;
                break;
            }
        }
    }

}
Exemplo n.º 16
0
PROCESS_THREAD(rime_udp_process, ev, data)
{
  static uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();

  broadcast_conn = udp_broadcast_new(UIP_HTONS(RIME_UDP_PORT), NULL);
  if(broadcast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a broadcast connection!\n");
  }

  uip_create_unspecified(&ipaddr);
  unicast_conn = udp_new(&ipaddr, UIP_HTONS(RIME_UDP_PORT), NULL);
  if(unicast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a unicast connection!\n");
  }

  udp_bind(unicast_conn, UIP_HTONS(RIME_UDP_PORT));

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    if(uip_newdata()) {
      packetbuf_clear();
      memmove(packetbuf_hdrptr(), uip_appdata, uip_datalen());
      PRINTF("rime-udp: received %d bytes\n", uip_datalen());
      receiver_callback(&rime_udp_driver);
    }
  }

  PROCESS_END();
}
Exemplo n.º 17
0
/*---------------------------------------------------------------------------*/
static void
send_rrep(struct route_discovery_conn *c, const rimeaddr_t *dest)
{
    struct rrep_hdr *rrepmsg;
    struct route_entry *rt;
    rimeaddr_t saved_dest;

    rimeaddr_copy(&saved_dest, dest);

    packetbuf_clear();
    dest = &saved_dest;
    rrepmsg = packetbuf_dataptr();
    packetbuf_set_datalen(sizeof(struct rrep_hdr));
    rrepmsg->hops = 0;
    rimeaddr_copy(&rrepmsg->dest, dest);
    rimeaddr_copy(&rrepmsg->originator, &rimeaddr_node_addr);
    rt = route_lookup(dest);
    if(rt != NULL)
    {
        PRINTF("%d.%d: send_rrep to %d.%d via %d.%d\n",
               rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
               dest->u8[0],dest->u8[1],
               rt->nexthop.u8[0],rt->nexthop.u8[1]);
        unicast_send(&c->rrepconn, &rt->nexthop);
    }
    else
    {
        PRINTF("%d.%d: no route for rrep to %d.%d\n",
               rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
               dest->u8[0],dest->u8[1]);
    }
}
Exemplo n.º 18
0
static void
send_announcement(void *ptr)
{
  struct cxmac_hdr *hdr;
  int announcement_len;

  /* Set up the probe header. */
  packetbuf_clear();
  hdr = packetbuf_dataptr();

  announcement_len = format_announcement((char *)hdr +
					 sizeof(struct cxmac_hdr));

  if(announcement_len > 0) {
    packetbuf_set_datalen(sizeof(struct cxmac_hdr) + announcement_len);
    hdr->dispatch = DISPATCH;
    hdr->type = TYPE_ANNOUNCEMENT;

    packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
    packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &rimeaddr_null);
    packetbuf_set_attr(PACKETBUF_ATTR_RADIO_TXPOWER, announcement_radio_txpower);
    if(NETSTACK_FRAMER.create()) {
      NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
    }
  }
}
Exemplo n.º 19
0
PROCESS_THREAD(uwb_process, ev, data)
{
  int len;
  PROCESS_BEGIN();
  UWBPROCESSFLAG(01);

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    UWBPROCESSFLAG(02);

    if (uwb_fsm != UWB_STATE_RX_PROCESS_POLLED)
      PRINTF("uwb: wrong state in process: %u\n",uwb_fsm);			

    packetbuf_clear();

    len = ram_rx_buffer[2];
    if ((len > 0) && (len < PACKETBUF_SIZE))
    {
      memcpy(packetbuf_dataptr(),&ram_rx_buffer[3],len); 
      packetbuf_set_datalen(len);
      UWBPROCESSFLAG(03);
      NETSTACK_RDC.input();
    }

    /* switch back to listen-state */
    PRINTF("uwb: enabling rx-mode\r\n");
    enable_rx_mode();

    PRINTF("uwb: read: %u bytes\n",len);

    UWBPROCESSFLAG(04);
  }

  PROCESS_END();
}
Exemplo n.º 20
0
/*---------------------------------------------------------------------------*/
static int
format_data(struct rudolph1mh_conn *c, int chunk)
{
  struct rudolph1mh_datapacket *p;
  
  packetbuf_clear();
  p = packetbuf_dataptr();
  p->h.type = TYPE_DATA;
  p->h.s_id = c->s_id;
  p->h.chunk = chunk;
  p->datalen = 0; //read_data(c, p->data, chunk);
  if(c->cb->read_chunk) {
    p->datalen = c->cb->read_chunk(c, chunk * RUDOLPH1MH_DATASIZE, p->data,
        RUDOLPH1MH_DATASIZE);
  }

  if(p->datalen != RUDOLPH1MH_DATASIZE){
    p->h.type = TYPE_FIN;
  }

  packetbuf_set_datalen(sizeof(struct rudolph1mh_datapacket) - (RUDOLPH1MH_DATASIZE
      - p->datalen));

  return p->datalen;
}
/**
 * the sensor node subscribed will send the data to the base station via the next hop according to the routing table
 */
void publish(struct runicast_conn *runicast){
    Ru_msg_list *ru_msg_list;
    Rt_table *chosen_route;
    if(list_length(runicast_list)>0){
        for(ru_msg_list = list_head(runicast_list);ru_msg_list!=NULL;){
            chosen_route = find_best_route();
            current_route = chosen_route;
            if(current_route!=NULL){
                packetbuf_copyfrom(&ru_msg_list->runicast_msg, sizeof(Runicast_msg));
                printf("[RU] @%d-@%u.%u->@%u.%u\n", clock_seconds(),rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
                       chosen_route->rt_entry.next_hop.u8[0],chosen_route->rt_entry.next_hop.u8[1]);
                runicast_send(runicast,&chosen_route->rt_entry.next_hop,MAX_RETRANSMISSIONS);
                packetbuf_clear();
                Ru_msg_list *to_remove;
                to_remove = ru_msg_list;
                ru_msg_list = ru_msg_list->next;
//                if(ru_send_success == true){
//                    list_remove(runicast_list,to_remove);
//                    memb_free(&runicast_list_memb,to_remove);
//                    printf("[DELET-RU-MSG]\n");
//                }
            }else{
                printf("[ERRO] current route is none");
            }


        }
    }
    remove_all_runicast_entry();
}
Exemplo n.º 22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_collect_process, ev, data)
{
  static struct etimer periodic;
  static struct etimer et;
  
  PROCESS_BEGIN();

  collect_open(&tc, 130, COLLECT_ROUTER, &callbacks);

  if(rimeaddr_node_addr.u8[0] == 1 &&
     rimeaddr_node_addr.u8[1] == 0) {
	printf("I am sink\n");
	collect_set_sink(&tc, 1);
  }

  /* Allow some time for the network to settle. */
  etimer_set(&et, 120 * CLOCK_SECOND);
  PROCESS_WAIT_UNTIL(etimer_expired(&et));

  while(1) {

    /* Send a packet every 30 seconds. */
    if(etimer_expired(&periodic)) {
      etimer_set(&periodic, CLOCK_SECOND * 30);
      etimer_set(&et, random_rand() % (CLOCK_SECOND * 30));
    }

    PROCESS_WAIT_EVENT();


    if(etimer_expired(&et)) {
      static rimeaddr_t oldparent;
      const rimeaddr_t *parent;

      printf("Sending\n");
      packetbuf_clear();
      packetbuf_set_datalen(sprintf(packetbuf_dataptr(),
				  "%s", "Hello") + 1);
      collect_send(&tc, 15);

      parent = collect_parent(&tc);
      if(!rimeaddr_cmp(parent, &oldparent)) {
	//alten parent ausgeben (falls der nicht null war)
        if(!rimeaddr_cmp(&oldparent, &rimeaddr_null)) {
          printf("#L %d 0\n", oldparent.u8[0]);
        }
	//neuen parent ausgeben (falls der nicht null ist)
        if(!rimeaddr_cmp(parent, &rimeaddr_null)) {
          printf("#L %d 1\n", parent->u8[0]);
        }
	//speichern
        rimeaddr_copy(&oldparent, parent);
      }
    }

  }

  PROCESS_END();
}
/**
 * publish a single message
 */
void single_publish(struct runicast_conn *runicast,Runicast_msg runicast_msg){

    packetbuf_copyfrom(&runicast_msg, sizeof(Runicast_msg));
    printf("[RU] timestamp @%d seqno %d last hop address %u.%u\n", runicast_msg.timestamp,runicast_msg.seqno,runicast_msg.last_hop.u8[0],runicast_msg.last_hop.u8[1]);

    runicast_send(runicast,&find_best_route()->rt_entry.next_hop,MAX_RETRANSMISSIONS);
    packetbuf_clear();
}
Exemplo n.º 24
0
/*---------------------------------------------------------------------------*/
static void
handle_beacon_send_timer(struct net_buf *buf, void *p)
{
  struct net_buf *mbuf;
  frame802154_t params;
  uint8_t len;

  mbuf = l2_buf_get_reserve(0);
  if(!mbuf) {
    return;
  }

  /* init to zeros */
  memset(&params, 0, sizeof(params));

  /* use packetbuf for sending ?? */
  packetbuf_clear(mbuf);
  /* Build the FCF. */
  params.fcf.frame_type = FRAME802154_BEACONFRAME;

  /* Insert IEEE 802.15.4 (2006) version bits. */
  params.fcf.frame_version = FRAME802154_IEEE802154_2006;

  /* assume long for now */
  params.fcf.src_addr_mode = FRAME802154_LONGADDRMODE;
  linkaddr_copy((linkaddr_t *)&params.src_addr, &linkaddr_node_addr);

  /* Set the source PAN ID to the global variable. */
  params.src_pid = panid;

  params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
  params.dest_addr[0] = 0xFF;
  params.dest_addr[1] = 0xFF;

  params.dest_pid = 0xffff;

  params.seq = framer_802154_next_seqno();

  /* Calculate beacon length and copy it to packetbuf */
  beacon_payload_len = handler_802154_calculate_beacon_payload_length(beacon_payload, BEACON_PAYLOAD_BUFFER_SIZE);
  packetbuf_copyfrom(mbuf, beacon_payload, beacon_payload_len);

  /* Set payload and payload length */
  params.payload = packetbuf_dataptr(mbuf);
  params.payload_len = packetbuf_datalen(mbuf);

  len = frame802154_hdrlen(&params);
  if(packetbuf_hdralloc(mbuf, len)) {
    frame802154_create(&params, packetbuf_hdrptr(mbuf), len);
    if(NETSTACK_RADIO.send(mbuf, packetbuf_hdrptr(mbuf),
                  packetbuf_totlen(mbuf)) != RADIO_TX_OK) {
      l2_buf_unref(mbuf);
      return;
    }

    HANDLER_802154_STAT(handler_802154_stats.beacons_sent++);
  }
}
Exemplo n.º 25
0
/*---------------------------------------------------------------------------*/
static void
recv(const struct mac_driver *c)
{
	printf("message received '%s'\n", (char *)packetbuf_dataptr());
	leds_toggle(LEDS_GREEN);
	packetbuf_clear();
	packetbuf_attr_clear();

}	
Exemplo n.º 26
0
/*---------------------------------------------------------------------------*/
static int
read(void)
{
  int len;
  packetbuf_clear();
  len = radio->read(packetbuf_dataptr(), PACKETBUF_SIZE);
  packetbuf_set_datalen(len);
  return len;
}
Exemplo n.º 27
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_download_process, ev, data)
{
  const char *nextptr;
  static rimeaddr_t addr;
  int len;
  char buf[32];

  PROCESS_BEGIN();

  /* Parse node addr */
  addr.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&download_command,
        "download <node addr> <filename>: need node address", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  addr.u8[1] = shell_strtolong(nextptr, &nextptr);

  /* Get the length of the file, excluding a terminating NUL character. */
  while(nextptr[0] == ' ') {
    nextptr++;
  }
  len = strlen(nextptr);

  /*snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);*/
  /*shell_output_str(&download_command, "Downloading from: ", buf);*/

  if(len > PACKETBUF_SIZE - 32) {
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&download_command, "filename too large: ", buf);
    PROCESS_EXIT();
  }

  /*shell_output_str(&download_command, "Downloading file: ", nextptr);*/

  /* Send file request */
  downloading = 1;
  rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
  packetbuf_clear();
  *((uint8_t *)packetbuf_dataptr()) = ++req_seq_counter;
  memcpy(((char *)packetbuf_dataptr()) + 1, nextptr, len + 1);
  packetbuf_set_datalen(len + 2);
  PRINTF("requesting '%s'\n", nextptr);
  runicast_send(&runicast, &addr, MAX_RETRANSMISSIONS);

  /* Wait for download to finish */
  leds_on(LEDS_BLUE);
  PROCESS_WAIT_UNTIL(!runicast_is_transmitting(&runicast) && !downloading);
  leds_off(LEDS_BLUE);

  rucb_close(&rucb);
  /*shell_output_str(&download_command, "Done!", "");*/

  PROCESS_END();
}
Exemplo n.º 28
0
void
packet_received(struct broadcast_conn *connection, const rimeaddr_t *from)
{
	struct subscription_item *si;
	switch(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE)) {
	case MWARE_MSG_SUB:
		si = subscription_get(&(packetbuf_msg_sub())->id);
		if (si != NULL) {
			if (subscription_is_unsubscribed(si)) {
				subscription_reset_last_shout(si);
			} else {
				if (!subscription_update(si, from,
							(packetbuf_msg_sub())->sub.hops + 1)) {
					si = NULL;

				}
			}
		} else if (!subscription_is_too_far(&(packetbuf_msg_sub())->sub)) {
			const rimeaddr_t * parent;
			parent = (identifier_is_mine(&(packetbuf_msg_sub())->id) ? &rimeaddr_null : from);
			si = subscription_insert(
					&(packetbuf_msg_sub())->id,
					&(packetbuf_msg_sub())->sub,
					parent,
					(packetbuf_msg_sub())->sub.hops + 1);
		}
		if (si != NULL) {
			subscription_print(si, "rs");
			subscription_sync_epoch(si, &(packetbuf_msg_sub())->sub);
			wind_item_timer(si, subscription_desync_jitter(si, &(packetbuf_msg_sub())->sub));
		}
	break;
	case MWARE_MSG_PUB:
		si = subscription_get(&(packetbuf_msg_pub())->id);
		if (si == NULL || subscription_is_unsubscribed(si)) {
			break;
		}
		if (rimeaddr_cmp(&si->next_hop, from)) {	
			subscription_update_last_heard(si);
		} else if (message_is_published_to_me()) {
			subscription_data_input(si,
					(packetbuf_msg_pub())->data,
					(packetbuf_msg_pub())->node_count);
		}
		break;
	case MWARE_MSG_UNSUB:
		si = subscription_get(&(packetbuf_msg_unsub())->id);
		if (si == NULL) {
			break;
		}
		subscription_print(si, "ru");
		subscription_unsubscribe(si);
		break;
	}
	packetbuf_clear();
}
Exemplo n.º 29
0
/*---------------------------------------------------------------------------*/
static void
send_ctrl_command(const rimeaddr_t *to, uint8_t command)
{
  struct ctrl_msg *msg;
  packetbuf_clear();
  packetbuf_set_datalen(sizeof(struct ctrl_msg));
  msg = packetbuf_dataptr();
  msg->command = command;
  runicast_send(&ctrl, to, MAX_RETRIES);
}
Exemplo n.º 30
0
/*---------------------------------------------------------------------------*/
int
packetbuf_copyfrom(const void *from, uint16_t len)
{
  uint16_t l;

  packetbuf_clear();
  l = len > PACKETBUF_SIZE? PACKETBUF_SIZE: len;
  memcpy(packetbufptr, from, l);
  buflen = l;
  return l;
}