/*---------------------------------------------------------------------------*/
static void request_recv(struct runicast_conn *c, const rimeaddr_t *from, uint8_t seqno)
{
  const char *filename;
  uint8_t seq;
  if(packetbuf_datalen() < 2) {
    printf("download: bad filename request (null)\n");
    return;
  }
  seq = ((uint8_t *)packetbuf_dataptr())[0];
  if(seq == req_last_seq) {
    printf("download: ignoring duplicate request\n");
    return;
  }
  req_last_seq = seq;
  filename = ((char *)packetbuf_dataptr()) + 1;

  printf("file requested: '%s'\n", filename);
  /* Initiate file transfer */
  leds_on(LEDS_GREEN);
  if(fd >= 0) {
    cfs_close(fd);
  }
  fd = cfs_open(filename, CFS_READ);
  if(fd < 0) {
    printf("download: bad filename request (no read access): %s\n", filename);
  }

  rucb_close(&rucb);
  rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
  rucb_send(&rucb, from);

}
示例#2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sendtest_process, ev, data)
{
  static rimeaddr_t receiver;
  static unsigned long cpu, lpm, rx, tx;
  const char *nextptr;
  const char *args;
  char buf[40];
  unsigned long cpu2, lpm2, rx2, tx2;
  
  PROCESS_BEGIN();

  args = data;
  receiver.u8[0] = shell_strtolong(args, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    print_usage();
    PROCESS_EXIT();
  }
  args = nextptr + 1;
  receiver.u8[1] = shell_strtolong(args, &nextptr);

  
  args = nextptr;
  while(*args == ' ') {
    ++args;
  }
  filesize = shell_strtolong(args, &nextptr);  
  if(nextptr == data || filesize == 0) {
    print_usage();
    PROCESS_EXIT();
  }

  args = nextptr;
  while(*args == ' ') {
    ++args;
  }
  packetsize = 64;
  packetsize = shell_strtolong(args, &nextptr);  
  if(packetsize == 0) {
    print_usage();
    PROCESS_EXIT();
  }

  snprintf(buf, sizeof(buf), "%d.%d, %lu bytes, packetsize %lu",
	   receiver.u8[0], receiver.u8[1], filesize, packetsize);
  shell_output_str(&sendtest_command, "Sending data to ", buf);

  bytecount = 0;
  download_complete = 0;

  start_time_rucb = clock_time();
  rucb_send(&rucb, &receiver);

  energest_flush();
  lpm = energest_type_time(ENERGEST_TYPE_LPM);
  cpu = energest_type_time(ENERGEST_TYPE_CPU);
  rx = energest_type_time(ENERGEST_TYPE_LISTEN);
  tx = energest_type_time(ENERGEST_TYPE_TRANSMIT);

  PROCESS_WAIT_UNTIL(download_complete);

  energest_flush();
  lpm2 = energest_type_time(ENERGEST_TYPE_LPM);
  cpu2 = energest_type_time(ENERGEST_TYPE_CPU);
  rx2 = energest_type_time(ENERGEST_TYPE_LISTEN);
  tx2 = energest_type_time(ENERGEST_TYPE_TRANSMIT);

  sprintf(buf, "%d seconds, %lu bytes/second",
	  (int)((end_time_rucb - start_time_rucb) / CLOCK_SECOND),
	  CLOCK_SECOND * filesize / (end_time_rucb - start_time_rucb));
  shell_output_str(&sendtest_command, "Completed in ", buf);

  sprintf(buf, "%lu/%d rx %lu/%d tx (seconds)",
	  (rx2 - rx), RTIMER_ARCH_SECOND,
	  (tx2 - tx), RTIMER_ARCH_SECOND);
  shell_output_str(&sendtest_command, "Radio total on time ", buf);

  sprintf(buf, "%lu/%lu = %lu%%",
	  (rx2 - rx),
	  (cpu2 + lpm2 - cpu - lpm),
	  100 * (rx2 - rx)/(cpu2 + lpm2 - cpu - lpm));
  shell_output_str(&sendtest_command, "Radio rx duty cycle ", buf);

  sprintf(buf, "%lu/%lu = %lu%%",
	  (tx2 - tx),
	  (cpu2 + lpm2 - cpu - lpm),
	  100 * (tx2 - tx)/(cpu2 + lpm2 - cpu - lpm));
  shell_output_str(&sendtest_command, "Radio tx duty cycle ", buf);

  PROCESS_END();
}