/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ 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(); }
PROCESS_THREAD(shell_sendfile_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 != '.') { printf("sendfile <node addr> <filename>: need node address\n"); PROCESS_EXIT(); } ++nextptr; addr.u8[1] = shell_strtolong(nextptr, &nextptr); printf("\nnode address: %d.%d\n", addr.u8[0], addr.u8[1]); while(nextptr[0] == ' ') nextptr++; len = strlen(nextptr); //snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]); if(len > MAX_FILENAME_SIZE) { snprintf(buf, sizeof(buf), "%d", len); printf("filename too large: ", buf); PROCESS_EXIT(); } sendfile_filename = nextptr; printf("filename: %s\n", sendfile_filename); sprintf(filenameOriginatorSent.name, "%s", sendfile_filename); filenameOriginatorSent.originator = node_id; packetbuf_copyfrom(&filenameOriginatorSent, sizeof(filenameOriginatorSent)); runicast_send(&runicastSendCommand, &addr, MAX_RETRANSMISSIONS); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_unicast_send_process, ev, data) { struct shell_input *input; static linkaddr_t receiver; int len; const char *nextptr; struct unicast_msg *msg; PROCESS_BEGIN(); receiver.u8[0] = shell_strtolong(data, &nextptr); if(nextptr == data || *nextptr != '.') { shell_output_str(&unicast_send_command, "unicast <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(&unicast_send_command, "Sending unicast 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 < MAX_DATALEN) { packetbuf_clear(); packetbuf_set_datalen(len + UNICAST_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);*/ unicast_send(&uc, &receiver); } } 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(); }
/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_rfchannel_process, ev, data) { struct { uint16_t len; uint16_t channel; } msg; const char *newptr; PROCESS_BEGIN(); msg.channel = shell_strtolong(data, &newptr); /* If no channel was given on the command line, we print out the current channel. */ if(newptr == data) { msg.channel = RADIO_GET_CHANNEL(); } else { RADIO_SET_CHANNEL(msg.channel); } msg.len = 1; shell_output(&rfchannel_command, &msg, sizeof(msg), "", 0); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_txpower_process, ev, data) { struct { uint16_t len; uint16_t txpower; } msg; const char *newptr; PROCESS_BEGIN(); msg.txpower = shell_strtolong(data, &newptr); /* If no transmission power was given on the command line, we print out the current txpower. */ if(newptr == data) { msg.txpower = RADIO_GET_TXPOWER(); } else { RADIO_SET_TXPOWER(msg.txpower); } msg.len = 1; shell_output(&txpower_command, &msg, sizeof(msg), "", 0); PROCESS_END(); }
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_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(); }
/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ 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(); }
PROCESS_THREAD(shell_bc_send_process, ev, data) { uint16_t channel; long channel_long; const char *next; char buf[6]; char msg_buf[128]; size_t msg_size; PROCESS_BEGIN(); channel_long = shell_strtolong((char *)data, &next); if(channel_long <= 0 || channel_long > 65535){ shell_output_str(&bc_send_command, "channel has to be in range [1-65535]", ""); PROCESS_EXIT(); } channel = (uint16_t) channel_long; snprintf(buf, sizeof(buf), "%d", channel); msg_size = strlen(next); if(msg_size == 0){ shell_output_str(&bc_send_command, "bc_send usage:", bc_send_command.description); PROCESS_EXIT(); } memcpy(msg_buf, next, msg_size); packetbuf_copyfrom(&msg_buf, msg_size); struct broadcast_entry *e = NULL; for(e = list_head(broadcast_list); e != NULL; e = e->next){ if(e->channel == channel){ broadcast_send(&e->c); shell_output_str(&bc_send_command, "sent broadcast message on channel: ", buf); PROCESS_EXIT(); } } shell_output_str(&bc_send_command, "bc_send error: channel not open, use bc_open <channel> before trying to send",""); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_mac_process, ev, data) { int onoroff; const char *next; PROCESS_BEGIN(); onoroff = shell_strtolong((char *)data, &next); if(next == data) { shell_output_str(&mac_command, "mac: current MAC layer: ", rime_mac->name); shell_output_str(&mac_command, "mac usage: ", mac_command.description); } else { if(onoroff) { rime_mac->on(); shell_output_str(&mac_command, "mac: turned MAC on: ", rime_mac->name); } else { rime_mac->off(1); shell_output_str(&mac_command, "mac: turned MAC off (keeping radio on): ", rime_mac->name); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_time_process, ev, data) { struct { uint16_t len; uint16_t clock; uint16_t rtimer; uint16_t timesynch; uint16_t timesynch_authority; uint16_t time[2]; } msg; unsigned long newtime; const char *nextptr; PROCESS_BEGIN(); if(data != NULL) { newtime = shell_strtolong(data, &nextptr); if(data != nextptr) { shell_set_time(newtime); } } msg.clock = (uint16_t)clock_time(); msg.rtimer = (uint16_t)RTIMER_NOW(); #if TIMESYNCH_CONF_ENABLED msg.timesynch = timesynch_time(); msg.timesynch_authority = timesynch_authority_level(); #else msg.timesynch = 0; msg.timesynch_authority = -1; #endif msg.time[0] = (uint16_t)(shell_time() >> 16); msg.time[1] = (uint16_t)(shell_time()); msg.len = 6; shell_output(&time_command, &msg, sizeof(msg), "", 0); PROCESS_END(); }
PROCESS_THREAD(shell_ruc_open_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_open_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 *to_add = memb_alloc(&runicast_mem); list_add(runicast_list, to_add); to_add->channel = channel; runicast_open(&to_add->c, channel, &runicast_callback); shell_output_str(&ruc_open_command, "opened reliable unicast connection on channel: ", buf); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_randwait_process, ev, data) { static int maxwait; static char command[MAX_COMMANDLENGTH]; static struct etimer etimer; static struct process *started_process; const char *args, *next; int ret; /* if(ev == shell_event_input) { struct shell_input *input; input = data; printf("shell randwait input %d %d\n", input->len1, input->len2); if(input->len1 + input->len2 != 0) { shell_output(&randwait_command, input->data1, input->len1, input->data2, input->len2); } }*/ PROCESS_BEGIN(); args = data; if(args == NULL) { shell_output_str(&randwait_command, "usage 0", ""); PROCESS_EXIT(); } maxwait = shell_strtolong(args, &next); if(next == args) { shell_output_str(&randwait_command, "usage 1", ""); PROCESS_EXIT(); } args = next; while(*args == ' ') { args++; } strncpy(command, args, MAX_COMMANDLENGTH); if(strlen(command) == 0) { shell_output_str(&repeat_command, "usage 3", ""); PROCESS_EXIT(); } /* printf("randwait %d command '%s'\n", maxwait, command);*/ etimer_set(&etimer, random_rand() % (CLOCK_SECOND * maxwait)); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); /* printf("Starting '%s' child %p (%s)\n", command, randwait_command.child, */ /* randwait_command.child == NULL? "null": randwait_command.child->command); */ ret = shell_start_command(command, (int)strlen(command), randwait_command.child, &started_process); if(started_process != NULL && process_is_running(started_process)) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXITED && data == started_process); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_repeat_process, ev, data) { static int reps, period, period_left; static char command[MAX_COMMANDLENGTH]; static struct etimer etimer; static int i; static clock_time_t start_time; const char *args, *next; if(ev == shell_event_input) { struct shell_input *input; input = data; /* printf("shell repeat input %d %d\n", input->len1, input->len2);*/ if(input->len1 + input->len2 != 0) { shell_output(&repeat_command, input->data1, input->len1, input->data2, input->len2); } } PROCESS_BEGIN(); /* printf("data '%s'\n", data);*/ args = data; if(args == NULL) { repeat_print_usage(); PROCESS_EXIT(); } reps = shell_strtolong(args, &next); if(next == args) { repeat_print_usage(); PROCESS_EXIT(); } args = next; period = shell_strtolong(args, &next); if(next == args) { repeat_print_usage(); PROCESS_EXIT(); } args = next; while(*args == ' ') { args++; } strncpy(command, args, MAX_COMMANDLENGTH); if(strlen(command) == 0) { repeat_print_usage(); PROCESS_EXIT(); } /* printf("repeats %d period %d command '%s'\n", reps, period, command);*/ start_time = clock_time(); etimer_set(&etimer, CLOCK_SECOND * period); for(i = 0; reps == 0 || i < reps; ++i) { process_start(&shell_repeat_server_process, (void *)command); process_post(&shell_repeat_server_process, PROCESS_EVENT_CONTINUE, &shell_repeat_process); PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXITED && data == &shell_repeat_server_process); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); etimer_reset(&etimer); /* PROCESS_PAUSE(); for(period_left = period; period_left > 0; period_left -= MIN(PERIOD_INTERVAL, period_left)) { etimer_set(&etimer, CLOCK_SECOND * MIN(PERIOD_INTERVAL, period_left)); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); }*/ } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ 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(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_read_process, ev, data) { static int fd = 0; static int block_size = MAX_BLOCKSIZE; char *next; char filename[MAX_FILENAME_LEN]; int len; int offset = 0; char buf[MAX_BLOCKSIZE]; struct shell_input *input; PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_BEGIN(); if(data != NULL) { next = strchr(data, ' '); if(next == NULL) { strncpy(filename, data, sizeof(filename)); } else { len = (int)(next - (char *)data); if(len <= 0) { shell_output_str(&read_command, "read: filename too short: ", data); PROCESS_EXIT(); } if(len > MAX_FILENAME_LEN) { shell_output_str(&read_command, "read: filename too long: ", data); PROCESS_EXIT(); } memcpy(filename, data, len); filename[len] = 0; offset = shell_strtolong(next, NULL); next++; next = strchr(next, ' '); if(next != NULL) { block_size = shell_strtolong(next, NULL); if(block_size > MAX_BLOCKSIZE) { shell_output_str(&read_command, "read: block size too large: ", data); PROCESS_EXIT(); } } } fd = cfs_open(filename, CFS_READ); cfs_seek(fd, offset, CFS_SEEK_SET); if(fd < 0) { shell_output_str(&read_command, "read: could not open file for reading: ", filename); } else { while(1) { len = cfs_read(fd, buf, block_size); if(len <= 0) { cfs_close(fd); PROCESS_EXIT(); } shell_output(&read_command, buf, len, "", 0); process_post(&shell_read_process, PROCESS_EVENT_CONTINUE, NULL); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE || ev == shell_event_input); if(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(); } } } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_netperf_process, ev, data) { static struct etimer e; static rimeaddr_t receiver; const char *nextptr; const char *args; static char recvstr[40]; static int i, num_packets; static uint8_t do_broadcast, do_unicast, do_pingpong, do_stream_pingpong; PROCESS_BEGIN(); current_type = TYPE_NONE; do_broadcast = do_unicast = do_pingpong = do_stream_pingpong = 0; args = data; /* Parse the -bups options */ while(*args == '-') { ++args; while(*args != ' ' && *args != 0) { if(*args == 'b') { do_broadcast = 1; } if(*args == 'u') { do_unicast = 1; } if(*args == 'p') { do_pingpong = 1; } if(*args == 's') { do_stream_pingpong = 1; } ++args; } while(*args == ' ') { args++; } } /* Parse the receiver address */ 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); /* Store the receiver address as a string since we need to print it out later. */ snprintf(recvstr, sizeof(recvstr), "%d.%d", receiver.u8[0], receiver.u8[1]); /* Parse the number of packets to send */ args = nextptr; while(*args == ' ') { ++args; } num_packets = shell_strtolong(args, &nextptr); if(nextptr == data || num_packets == 0) { print_usage(); PROCESS_EXIT(); } /* Send broadcast packets, if requested */ if(do_broadcast) { current_type = TYPE_BROADCAST; shell_output_str(&netperf_command, "-------- Broadcast --------", ""); shell_output_str(&netperf_command, "Contacting ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_CLEAR); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); shell_output_str(&netperf_command, "Measuring broadcast performance to ", recvstr); setup_sending(&receiver, num_packets); for(i = 0; i < num_packets; ++i) { if(construct_next_packet()) { broadcast_send(&broadcast); stats.sent++; } PROCESS_PAUSE(); } shell_output_str(&netperf_command, "Requesting statistics from ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_STATS); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); /* Wait for reply */ PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); finalize_stats(&stats); print_local_stats(&stats); } if(do_unicast) { current_type = TYPE_UNICAST; shell_output_str(&netperf_command, "-------- Unicast one-way --------", ""); shell_output_str(&netperf_command, "Contacting ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_CLEAR); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); shell_output_str(&netperf_command, "Measuring unicast performance to ", recvstr); setup_sending(&receiver, num_packets); for(i = 0; i < num_packets; ++i) { if(construct_next_packet()) { unicast_send(&unicast, &receiver); stats.sent++; } PROCESS_PAUSE(); } shell_output_str(&netperf_command, "Requesting statistics from ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_STATS); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); /* Wait for reply */ PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); finalize_stats(&stats); print_local_stats(&stats); } if(do_pingpong) { current_type = TYPE_UNICAST_PINGPONG; shell_output_str(&netperf_command, "-------- Unicast ping-pong--------", ""); shell_output_str(&netperf_command, "Contacting ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_CLEAR); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); shell_output_str(&netperf_command, "Measuring two-way unicast performance to ", recvstr); setup_sending(&receiver, num_packets); for(i = 0; i < num_packets; ++i) { if(construct_next_echo()) { unicast_send(&unicast, &receiver); stats.sent++; } etimer_set(&e, CLOCK_SECOND); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT || etimer_expired(&e)); } shell_output_str(&netperf_command, "Requesting statistics from ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_STATS); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); /* Wait for reply */ PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); finalize_stats(&stats); print_local_stats(&stats); } if(do_stream_pingpong) { current_type = TYPE_UNICAST_STREAM; shell_output_str(&netperf_command, "-------- Unicast stream ping-pong--------", ""); shell_output_str(&netperf_command, "Contacting ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_CLEAR); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); shell_output_str(&netperf_command, "Measuring two-way unicast stream performance to ", recvstr); setup_sending(&receiver, num_packets); for(i = 0; i < num_packets; ++i) { if(construct_next_stream_echo()) { unicast_send(&unicast, &receiver); stats.sent++; } etimer_set(&e, CLOCK_SECOND); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT || etimer_expired(&e)); } shell_output_str(&netperf_command, "Requesting statistics from ", recvstr); send_ctrl_command(&receiver, CTRL_COMMAND_STATS); PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); /* Wait for reply */ PROCESS_YIELD_UNTIL(ev == CONTINUE_EVENT); finalize_stats(&stats); print_local_stats(&stats); } shell_output_str(&netperf_command, "Done", ""); PROCESS_END(); }
PROCESS_THREAD(shell_ruc_send_process, ev, data) { uint16_t channel; long channel_long; const char *next; linkaddr_t target; long rime_long; char buf[6]; char msg_buf[128]; size_t msg_size; PROCESS_BEGIN(); channel_long = shell_strtolong((char *)data, &next); if(channel_long <= 0 || channel_long > 65535){ shell_output_str(&ruc_send_command, "channel has to be in range [1-65535]", ""); PROCESS_EXIT(); } channel = (uint16_t) channel_long; snprintf(buf, sizeof(buf), "%d", channel); rime_long = shell_strtolong(next, &next); if(rime_long < 0 || rime_long > 255){ shell_output_str(&ruc_send_command, "rimeaddress[0] has to be in range [0-255]",""); PROCESS_EXIT(); } if(*next != '.'){ shell_output_str(&ruc_send_command, "wrong target address format, need u8[0].u8[1]",""); PROCESS_EXIT(); } target.u8[0] = (uint8_t) rime_long; ++next; rime_long = shell_strtolong(next, &next); if(rime_long < 0 || rime_long > 255){ shell_output_str(&ruc_send_command, "rimeaddress[1] has to be in range [0-255]",""); PROCESS_EXIT(); } target.u8[1] = (uint8_t) rime_long; while(*next == ' '){ next++; } msg_size = strlen(next); if(msg_size == 0){ shell_output_str(&ruc_send_command, "ruc_send usage:", ruc_send_command.description); PROCESS_EXIT(); } memcpy(msg_buf, next, msg_size); packetbuf_copyfrom(&msg_buf, msg_size); struct runicast_entry *e = NULL; for(e = list_head(runicast_list); e != NULL; e = e->next){ if(e->channel == channel){ runicast_send(&e->c, &target,3); shell_output_str(&ruc_send_command, "sent reliable unicast message on channel: ", buf); PROCESS_EXIT(); } } shell_output_str(&ruc_send_command, "ruc_send error: channel not open, use ruc_open <channel> before trying to send",""); PROCESS_END(); }