Exemplo n.º 1
0
/*---------------------------------------------------------------------------*/
int
runicast_send(struct runicast_conn *c, const rimeaddr_t *receiver,
	      uint8_t max_retransmissions)
{
  int ret;
  if(runicast_is_transmitting(c)) {
    PRINTF("%d.%d: runicast: already transmitting\n",
        rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
    return 0;
  }
  packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
  packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_DATA);
  packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, c->sndnxt);
  packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, 3);
  c->max_rxmit = max_retransmissions;
  c->rxmit = 0;
  c->is_tx = 1;
  RIMESTATS_ADD(reliabletx);
  PRINTF("%d.%d: runicast: sending packet %d\n",
	 rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
	 c->sndnxt);
  ret = stunicast_send_stubborn(&c->c, receiver, REXMIT_TIME);
  if(!ret) {
    c->is_tx = 0;
  }
  return ret;
}
Exemplo n.º 2
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.º 3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_test_process, ev, data)
{
  PROCESS_BEGIN();

  puts("unicast test start");

  runicast_open(&runicast, 144, &runicast_callbacks);

  /* Receiver node: do nothing */
  if(linkaddr_node_addr.u8[0] == RX_ADDR1 &&
     linkaddr_node_addr.u8[1] == RX_ADDR2) {
    puts("wait forever");
  }
  while(1) {
    static struct etimer et;
    static int seqno;

    etimer_set(&et, CLOCK_SECOND * 5);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    if(linkaddr_node_addr.u8[0] == RX_ADDR1 &&
       linkaddr_node_addr.u8[1] == RX_ADDR2) {
      puts("tick...");
      continue;
    }

    if(!runicast_is_transmitting(&runicast)) {
      static char buffer[100] = "hello";
      linkaddr_t recv;

      memset(&recv, 0, LINKADDR_SIZE);
      packetbuf_copyfrom(buffer, sizeof(buffer));
      recv.u8[0] = RX_ADDR1;
      recv.u8[1] = RX_ADDR2;

      printf("%u.%u: sending runicast to address %u.%u\n",
             linkaddr_node_addr.u8[0],
             linkaddr_node_addr.u8[1],
             recv.u8[0],
             recv.u8[1]);

      packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, ++seqno);
      runicast_send(&runicast, &recv, MAX_RETRANSMISSIONS);
    }
  }

  PROCESS_END();
}
PROCESS_THREAD(download_and_execute_process, ev, data)
{
    PROCESS_BEGIN();
    // turn on blue leds while downloading, then
    leds_on(LEDS_BLUE);
    PROCESS_WAIT_UNTIL(!runicast_is_transmitting(&runicast) && !downloading);
    leds_off(LEDS_BLUE);

    printf("Downloaded Code!\n");
    printf("originator: %u\n", filenameOriginatorRecv.originator);
    printf("filename: %s\n", filename_download);

    runReceivedProgram();

    PROCESS_END();
}
/**
 * subscribe node will assemble the data according to the conditions
 */
void assemble_data(){
    uint8_t value = random_rand()%10;
    assemble_total+=value;
    assemble_count++;
    if(value>max){
        max = value;
    }
    if(assemble_count>= local_node.assemble_count){
        Runicast_msg runicast_msg;
        runicast_msg.native_sen_type = local_node.sen_type;
        runicast_msg.seqno = clct_data_seqno;
        //runicast_msg.timestamp = CLOCK_SECOND;
        if(local_node.condition == MAX){
            runicast_msg.value = max;
        }else if(local_node.condition == AVERAGE ){
            runicast_msg.value = (assemble_total)/(assemble_count);
        }
        rimeaddr_copy(&runicast_msg.last_hop,&rimeaddr_node_addr);
        rimeaddr_copy(&runicast_msg.source,&rimeaddr_node_addr);
        //add_to_RU_list(runicast_msg);

        if(!runicast_is_transmitting(&runicast)){
            printf("[PUBLISH] publish data value->%u seqno %u\n",runicast_msg.value,runicast_msg.seqno);
            //single_publish(&runicast,runicast_msg);
            printf("[RU] timestamp %d seqno %u last hop address %u.%u\n", runicast_msg.timestamp,runicast_msg.seqno,runicast_msg.last_hop.u8[0],runicast_msg.last_hop.u8[1]);
            packetbuf_copyfrom(&runicast_msg, sizeof(Runicast_msg));
            runicast_send(&runicast,&find_best_route()->rt_entry.next_hop,MAX_RETRANSMISSIONS);
            packetbuf_clear();
        }


        if(clct_data_seqno>254){
            clct_data_seqno = 0;
        }
        clct_data_seqno++;
        assemble_count = 0;
        assemble_total = 0.0f;
        max = 0.0f;
    }
}