Exemple #1
0
/*---------------------------------------------------------------------------*/
void
shell_start(void)
{
    shell_output_str(NULL, SHELL_CONF_BANNER, "");
    shell_output_str(NULL, "Type '?' and return for help", "");
    shell_prompt(SHELL_CONF_PROMPT);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_peek_process, ev, data)
{
    uint8_t *address;
    const char *args, *next;
    char buf[32];

    PROCESS_BEGIN();

    args = data;

    if(args == NULL) {
        shell_output_str(&peek_command, "usage 0", "");
        PROCESS_EXIT();
    }

    address = (uint8_t *)(int)shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&peek_command, "usage 1", "");
        PROCESS_EXIT();
    }

    snprintf(buf, sizeof(buf), "0x%02x", *address);

    shell_output_str(&peek_command, buf, "");

    PROCESS_END();
}
Exemple #3
0
/*---------------------------------------------------------------------------*/
void
shell_start(void)
{
  shell_output_str(NULL, shell_banner_text, "");
  shell_output_str(NULL, "Type '?' and return for help", "");
  shell_prompt(shell_prompt_text);
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_kill_process, ev, data)
{
  struct shell_command *c;
  char *name;
  PROCESS_BEGIN();

  name = data;
  if(name == NULL || strlen(name) == 0) {
    shell_output_str(&kill_command,
		     "kill <command>: command name must be given", "");
  }

  for(c = list_head(commands);
      c != NULL;
      c = c->next) {
    if(strcmp(name, c->command) == 0 &&
       c != &kill_command &&
       process_is_running(c->process)) {
      command_kill(c);
      PROCESS_EXIT();
    }
  }

  shell_output_str(&kill_command, "Command not found: ", name);
  
  PROCESS_END();
}
Exemple #5
0
PROCESS_THREAD(shell_ruc_close_process, ev, data)
{
  uint16_t channel;
  long channel_long;
  const char *next;
  char buf[6];
  PROCESS_BEGIN();

  channel_long = shell_strtolong((char *)data, &next);
  if(channel_long <= 0 || channel_long > 65535){
    shell_output_str(&ruc_close_command, "channel has to be in range of [1-65535]", "");
    PROCESS_EXIT();
  }
  channel = (uint16_t) channel_long;
  snprintf(buf, sizeof(buf), "%d", channel);
  struct runicast_entry *e = list_head(runicast_list);
  while(e != NULL){
    if(e->channel == channel){
      struct runicast_entry *to_remove = e;
      e = e->next;
      runicast_close(&to_remove->c);
      list_remove(runicast_list, to_remove);
      memb_free(&runicast_mem, to_remove);
      shell_output_str(&ruc_close_command, "closed unicast connection on channel: ", buf);
      PROCESS_EXIT();
    }
  }
  shell_output_str(&ruc_close_command, "uc_close error: channel not open","");

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_leds_process, ev, data)
{
    struct acc_msg *msg;
    struct shell_input *input;
    int val, i;
    static int num;
    const char *args, *next;

    PROCESS_BEGIN();

    args = data;
    if(args == NULL) {
        shell_output_str(&acc_command, "usage 0", "");
        PROCESS_EXIT();
    }

    num = shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&acc_command, "usage 1", "");
        PROCESS_EXIT();
    }

    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;
    msg = (struct acc_msg *)input->data1;
    val = 0;
    for(i = 0; i < msg->acc[num] >> 9; ++i) {
        val = (val << 1) | 1;
    }
    leds_on(val & 0xff);
    leds_off(~(val & 0xff));

    PROCESS_END();
}
Exemple #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sensors_process, ev, data)
{
  char str_buf[22];

  PROCESS_BEGIN();
  if(data == NULL) {
    shell_output_str(&sensors_command,
                     "sensors {temp|acc}: a sensor must be specified", "");
    PROCESS_EXIT();
  }

  if(strcmp(data, "temp") == 0) {
    unsigned int temp = temperature_sensor.value(0);
    snprintf(str_buf, sizeof(str_buf), "%d.%d degC", temp / 10,
             temp - (temp / 10) * 10);
    shell_output_str(&sensors_command, "Temp: ", str_buf);
  } else {
    if(strcmp(data, "acc") == 0) {
      snprintf(str_buf, sizeof(str_buf), "%d,%d,%d) mg",
               acc_sensor.value(ACC_X_AXIS), acc_sensor.value(ACC_Y_AXIS),
               acc_sensor.value(ACC_Z_AXIS));
      shell_output_str(&sensors_command, "(X,Y,Z): (", str_buf);
    }
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_poke_process, ev, data)
{
    uint8_t *address;
    uint8_t byte;
    const char *args, *next;

    PROCESS_BEGIN();

    args = data;

    if(args == NULL) {
        shell_output_str(&poke_command, "usage 0", "");
        PROCESS_EXIT();
    }

    address = (uint8_t *)(int)shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&poke_command, "usage 1", "");
        PROCESS_EXIT();
    }

    args = next;
    byte = shell_strtolong(args, &next);
    if(next == args) {
        shell_output_str(&poke_command, "usage 2", "");
        PROCESS_EXIT();
    }

    printf("address %p byte 0x%02x\n", address, byte);

    *address = byte;

    PROCESS_END();
}
Exemple #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ls_process, ev, data)
{
  static struct cfs_dir dir;
  static cfs_offset_t totsize;
  struct cfs_dirent dirent;
  char buf[32];
  PROCESS_BEGIN();
  
  if(data != NULL) {
    if(cfs_opendir(&dir, data) != 0) {
      shell_output_str(&ls_command, "Cannot open directory", "");
    } else {
      totsize = 0;
      while(cfs_readdir(&dir, &dirent) == 0) {
        totsize += dirent.size;
        sprintf(buf, "%lu ", (unsigned long)dirent.size);
        /*      printf("'%s'\n", dirent.name);*/
        shell_output_str(&ls_command, buf, dirent.name);
      }
      cfs_closedir(&dir);
      sprintf(buf, "%lu", (unsigned long)totsize);
      shell_output_str(&ls_command, "Total size: ", buf);
    }
  }
  PROCESS_END();
}
Exemple #10
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_udpsend_process, ev, data)
{
  const char *next, *nextptr;
  struct shell_input *input;
  uint16_t port, local_port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&udpsend_command,
		     "udpsend <server> <port> [localport]: server as address", "");
    PROCESS_EXIT();
  }
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &nextptr);

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  udpconn = udp_new(&serveraddr, htons(port), NULL);
  
  if(next != nextptr) {
    local_port = shell_strtolong(nextptr, &nextptr);
    udp_bind(udpconn, htons(local_port));
  }
  running = 1;


  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      if(uip_newdata()) {
	newdata(uip_appdata, uip_datalen());
      }
#if 0
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&udpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Exemple #11
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();
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_id_process, ev, data)
{
  char buf[40];
  PROCESS_BEGIN();
  snprintf(buf, sizeof(buf), "%d.%d.%d.%d", uip_ipaddr_to_quad(&uip_hostaddr));
  shell_output_str(&id_command, "IP address: ", buf);
  snprintf(buf, sizeof(buf), "%d.%d",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
  shell_output_str(&id_command, "Rime address: ", buf);
  PROCESS_END();
}
Exemple #13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_tcpsend_process, ev, data)
{
  char *next;
  const char *dummy; 
  struct shell_input *input;
  uint16_t port;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&tcpsend_command,
		     "tcpsend <server> <port>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  port = shell_strtolong(next, &dummy);
  
  running = 1;

  uiplib_ipaddrconv(server, &serveraddr);
  telnet_connect(&s, &serveraddr, port);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 + input->len2 == 0) {
	PROCESS_EXIT();
      }

      if(input->len1 > 0) {
	send_line(&s, input->data1, input->len1);
      }
    } else if(ev == tcpip_event) {
      telnet_app(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	telnet_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&tcpsend_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Exemple #14
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_binprint_process, ev, data)
{
  struct shell_input *input;
  uint16_t *ptr;
  int i;
  char buf[2*64], *bufptr;
  uint16_t val;

  PROCESS_BEGIN();

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;

    if(input->len1 + input->len2 == 0) {
      PROCESS_EXIT();
    }

    bufptr = buf;
    ptr = (uint16_t *)input->data1;
    for(i = 0; i < input->len1 && i < input->len1 - 1; i += 2) {
      memcpy(&val, ptr, sizeof(val));
      bufptr += sprintf(bufptr, "%u ", val);
      if(bufptr - buf >= sizeof(buf) - 6) {
	shell_output_str(&binprint_command, buf, "");
	bufptr = buf;
      }
      ptr++;
    }

    /* XXX need to check if input->len1 == 1 here, and then shift this
       byte into the sequence of 16-bitters below. */
    
    ptr = (uint16_t *)input->data2;
    for(i = 0; i < input->len2 && i < input->len2 - 1; i += 2) {
      memcpy(&val, ptr, sizeof(val));
      bufptr += sprintf(bufptr, "%u ", val);
      if(bufptr - buf >= sizeof(buf) - 6) {
	shell_output_str(&binprint_command, buf, "");
	bufptr = buf;
      }
      ptr++;
    }
    
    if(bufptr != buf) {
      shell_output_str(&binprint_command, buf, "");
    }
    
  }
  PROCESS_END();
}
Exemple #15
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(help_command_process, ev, data)
{
  struct shell_command *c;
  PROCESS_BEGIN();

  shell_output_str(&help_command, "Available commands:", "");
  for(c = list_head(commands);
      c != NULL;
      c = c->next) {
    shell_output_str(&help_command, c->description, "");
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_runicast_process, ev, data)
{
  struct shell_input *input;
  static rimeaddr_t receiver;
  int len;
  const char *nextptr;
  struct collect_msg *msg;
  char buf[30];
  
  PROCESS_BEGIN();
  
  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&runicast_command,
		     "runicast <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
  shell_output_str(&runicast_command, "Sending runicast packets to ", buf);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;

    len = input->len1 + input->len2;

    if(len == 0) {
      PROCESS_EXIT();
    }
    
    if(len < PACKETBUF_SIZE) {
      packetbuf_clear();
      packetbuf_set_datalen(len + COLLECT_MSG_HDRSIZE);
      msg = packetbuf_dataptr();
      memcpy(msg->data, input->data1, input->len1);
      memcpy(msg->data + input->len1, input->data2, input->len2);
#if TIMESYNCH_CONF_ENABLED
      msg->timestamp = timesynch_time();
#else
      msg->timestamp = 0;
#endif
      /*      printf("Sending %d bytes\n", len);*/
      runicast_send(&ruc, &receiver, 4);
    }
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
static void
print_usage(void)
{
  shell_output_str(&netperf_command,
		   "netperf [-b|u|p|s] <receiver> <num packets>: perform network measurements to receiver", "");
  shell_output_str(&netperf_command,
		   "        -b measure broadcast performance", "");
  shell_output_str(&netperf_command,
		   "        -u measure one-way unicast performance", "");
  shell_output_str(&netperf_command,
		   "        -p measure ping-pong unicast performance", "");
  shell_output_str(&netperf_command,
		   "        -s measure ping-pong stream unicast performance", "");
}
Exemple #18
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_ps_process, ev, data)
{
  struct process *p;
  PROCESS_BEGIN();

  shell_output_str(&ps_command, "Processes:", "");
  for(p = PROCESS_LIST(); p != NULL; p = p->next) {
    char namebuf[30];
    strncpy(namebuf, PROCESS_NAME_STRING(p), sizeof(namebuf));
    shell_output_str(&ps_command, namebuf, "");
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rime_ping_process, ev, data)
{
  static int i;
  static struct etimer timeout, periodic;
  static rimeaddr_t receiver;
  struct rime_ping_msg *ping;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&rime_ping_command,
		     "ping <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
  shell_output_str(&rime_ping_command, "Sending 4 pings to ", buf);

  for(i = 0; i < 4; ++i) {
    packetbuf_clear();
    ping = packetbuf_dataptr();
    packetbuf_set_datalen(sizeof(struct rime_ping_msg));
#if TIMESYNCH_CONF_ENABLED
    ping->pingtime = timesynch_time();
#else
    ping->pingtime = rtimer_arch_now();
#endif
    mesh_send(&mesh, &receiver);

    etimer_set(&timeout, CLOCK_SECOND * 8);
    etimer_set(&periodic, CLOCK_SECOND * 1);
    waiting_for_pong = 1;
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout) ||
			     waiting_for_pong == 0);
    if(waiting_for_pong == 0) {
      PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
    } else {
      shell_output_str(&rime_ping_command,
		       "Timed out", "");
    }
    waiting_for_pong = 0;
  }
  PROCESS_END();
}
Exemple #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_irc_process, ev, data)
{
  char *next;
  struct shell_input *input;
  
  PROCESS_BEGIN();

  next = strchr(data, ' ');
  if(next == NULL) {
    shell_output_str(&irc_command,
		     "irc <server> <nick>: server as address", "");
    PROCESS_EXIT();
  }
  *next = 0;
  ++next;
  strncpy(server, data, sizeof(server));
  strncpy(nick, next, sizeof(nick));
  
  running = 1;

  uiplib_ipaddrconv(server, (u8_t *)&serveraddr);
  ircc_connect(&s, server, &serveraddr, nick);
  while(running) {
    PROCESS_WAIT_EVENT();

    if(ev == shell_event_input) {
      input = data;
      if(input->len1 > 0) {
	parse_line(input->data1);
      }
    } else if(ev == tcpip_event) {
      ircc_appcall(data);
#if 0            
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	uip_ipaddr_copy(serveraddr, ipaddr);
	ircc_connect(&s, server, serveraddr, nick);
      } else {
	shell_output_str(&irc_command, "Host not found.", "");
      }
#endif /* 0 */
    }
  }

  PROCESS_END();
}
Exemple #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sendcmd_process, ev, data)
{
  struct cmd_msg  *msg;
  int len;
  linkaddr_t addr;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  addr.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&sendcmd_command,
             "sendcmd <node addr>: receiver must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  addr.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);
  shell_output_str(&sendcmd_command, "Sending command to ", buf);

  /* Get the length of the command line, excluding a terminating NUL character. */
  len = strlen((char *)nextptr);

  /* Check the length of the command line to see that it is small
     enough to fit in a packet. We count with 32 bytes of header,
     which may be a little too much, but at least we are on the safe
     side. */
  if(len > PACKETBUF_SIZE - 32) {
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&sendcmd_command, "command line too large: ", buf);
    PROCESS_EXIT();
  }

  packetbuf_clear();
  msg = packetbuf_dataptr();
  packetbuf_set_datalen(len + 1 + CMDMSG_HDR_SIZE);
  strcpy(msg->sendcmd, nextptr);

  /* Terminate the string with a NUL character. */
  msg->sendcmd[len] = 0;
  msg->crc = crc16_data((unsigned char *)msg->sendcmd, len, 0);
  /*    printf("sendcmd sending '%s'\n", msg->sendcmd);*/
  unicast_send(&uc, &addr);

  PROCESS_END();
}
Exemple #22
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_append_process, ev, data)
{
  static int fd = 0;
  struct shell_input *input;

  PROCESS_EXITHANDLER(cfs_close(fd));
  
  PROCESS_BEGIN();

  fd = cfs_open(data, CFS_WRITE | CFS_APPEND);

  if(fd < 0) {
    shell_output_str(&append_command,
		     "append: could not open file for writing: ", data);
  } else {
    while(1) {
      PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
      input = data;
      /*    printf("cat input %d %d\n", input->len1, input->len2);*/
      if(input->len1 + input->len2 == 0) {
	cfs_close(fd);
	PROCESS_EXIT();
      }
      
      cfs_write(fd, input->data1, input->len1);
      cfs_write(fd, input->data2, input->len2);
      
      shell_output(&append_command,
		   input->data1, input->len1,
		   input->data2, input->len2);
    }
  }
  
  PROCESS_END();
}
Exemple #23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_netcmd_process, ev, data)
{
  struct trickle_msg *msg;
  int len;
  
  PROCESS_BEGIN();

  /* Get the length of the command line, excluding a terminating NUL character. */
  len = strlen((char *)data);

  /* Check the length of the command line to see that it is small
     enough to fit in a packet. We count with 32 bytes of header,
     which may be a little too much, but at least we are on the safe
     side. */
  if(len > PACKETBUF_SIZE - 32) {
    char buf[32];
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&netcmd_command, "command line too large: ", buf);
  } else {
    
    packetbuf_clear();
    msg = packetbuf_dataptr();
    packetbuf_set_datalen(len + 1 + TRICKLEMSG_HDR_SIZE);
    strcpy(msg->netcmd, data);

    /* Terminate the string with a NUL character. */
    msg->netcmd[len] = 0;
    msg->crc = crc16_data(msg->netcmd, len, 0);
    printf("netcmd sending '%s'\n", msg->netcmd);
    trickle_send(&trickle);
  }
  
  PROCESS_END();
}
Exemple #24
0
/*---------------------------------------------------------------------------*/
static void
print_usage(void)
{
  shell_output_str(&sendtest_command,
		   "sendtest <receiver> <size> [packetsize]: recevier must be specified", "");

}
Exemple #25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_netstat_process, ev, data)
{
  char buf[BUFLEN];
  int i;
  struct uip_conn *conn;
  PROCESS_BEGIN();

  for(i = 0; i < UIP_CONNS; ++i) {
    conn = &uip_conns[i];
    snprintf(buf, BUFLEN,
	     "%d, %u.%u.%u.%u:%u, %s, %u, %u, %c %c",
	     htons(conn->lport),
	     conn->ripaddr.u8[0],
	     conn->ripaddr.u8[1],
	     conn->ripaddr.u8[2],
	     conn->ripaddr.u8[3],
	     htons(conn->rport),
	     states[conn->tcpstateflags & UIP_TS_MASK],
	     conn->nrtx,
	     conn->timer,
	     (uip_outstanding(conn))? '*':' ',
	     (uip_stopped(conn))? '!':' ');
    shell_output_str(&netstat_command, "TCP ", buf);
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_nodeid_process, ev, data)
{
    uint16_t nodeid;
    char buf[20];
    const char *newptr;
    PROCESS_BEGIN();

    nodeid = shell_strtolong(data, &newptr);

    /* If no node ID was given on the command line, we print out the
       current channel. Else we burn the new node ID. */
    if(newptr == data) {
        nodeid = node_id;
    } else {
        nodeid = shell_strtolong(data, &newptr);
        watchdog_stop();
        leds_on(LEDS_RED);
        node_id_burn(nodeid);
        leds_on(LEDS_BLUE);
        node_id_restore();
        leds_off(LEDS_RED + LEDS_BLUE);
        watchdog_start();
    }

    snprintf(buf, sizeof(buf), "%d", nodeid);
    shell_output_str(&nodeid_command, "Node ID: ", buf);

    PROCESS_END();
}
Exemple #27
0
/*---------------------------------------------------------------------------*/
static void
request_timedout(struct runicast_conn *c, rimeaddr_t *to, uint8_t retransmissions)
{
  shell_output_str(&download_command, "download: request timed out", "");
  downloading = 0;
  process_poll(&shell_download_process);
}
Exemple #28
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_wget_process, ev, data)
{
  PROCESS_BEGIN();

  strncpy(url, data, sizeof(url));
  open_url(url);

  running = 1;
  
  while(running) {
    PROCESS_WAIT_EVENT();
    
    if(ev == tcpip_event) {
      webclient_appcall(data);
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	open_url(url);
      } else {
	shell_output_str(&wget_command, "Host not found.", "");
      }
    }
  }

  PROCESS_END();
}
static void
recv_mesh(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
  struct rime_ping_msg ping;
  char buf[64];
  rtimer_clock_t pingrecvtime;
  
  memcpy(&ping, packetbuf_dataptr(), sizeof(struct rime_ping_msg));

  if(waiting_for_pong == 0) {
#if TIMESYNCH_CONF_ENABLED
    ping.pongtime = timesynch_time();
#else
    ping.pongtime = ping.pingtime;
#endif
    memcpy(packetbuf_dataptr(), &ping, sizeof(struct rime_ping_msg));
    mesh_send(&mesh, from);
  } else {
#if TIMESYNCH_CONF_ENABLED
    pingrecvtime = timesynch_time();
#else
    pingrecvtime = rtimer_arch_now();
#endif
    snprintf(buf, sizeof(buf), "%lu ms (%lu + %lu), %d hops.",
	    ((pingrecvtime  - ping.pingtime) * 1000L) / RTIMER_ARCH_SECOND,
	    ((ping.pongtime - ping.pingtime) * 1000L) / RTIMER_ARCH_SECOND,
	    ((pingrecvtime  - ping.pongtime) * 1000L) / RTIMER_ARCH_SECOND,
	    hops);

    shell_output_str(&rime_ping_command,
		     "Pong recived; rtt ", buf);
    waiting_for_pong = 0;
    process_post(&shell_rime_ping_process, PROCESS_EVENT_CONTINUE, NULL);
  }
}
Exemple #30
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_write_process, ev, data)
{
  static int fd = 0;
  struct shell_input *input;
  int r;

  PROCESS_EXITHANDLER(cfs_close(fd));
  
  PROCESS_BEGIN();

  fd = cfs_open(data, CFS_WRITE);

  if(fd < 0) {
    shell_output_str(&write_command,
		     "write: could not open file for writing: ", data);
  } else {
    while(1) {
      PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
      input = data;
      /*    printf("cat input %d %d\n", input->len1, input->len2);*/
      if(input->len1 + input->len2 == 0) {
	cfs_close(fd);
	PROCESS_EXIT();
      }

      r = 0;      
      if(input->len1 > 0) {
	r = cfs_write(fd, input->data1, input->len1);
      }

      if(r >= 0 && input->len2 > 0) {
	r = cfs_write(fd, input->data2, input->len2);
      }

      if(r < 0) {
	shell_output_str(&write_command, "write: could not write to the file",
			 NULL);
      } else {
	shell_output(&write_command,
		     input->data1, input->len1,
		     input->data2, input->len2);
      }
    }
  }
  
  PROCESS_END();
}