47 #if CONTIKI_TARGET_NETSIM
51 int snprintf(
char *str,
size_t size,
const char *format, ...);
55 PROCESS(shell_sendtest_process,
"sendtest");
58 "sendtest: measure single-hop throughput",
59 &shell_sendtest_process);
61 static clock_time_t start_time_rucb, end_time_rucb;
62 static unsigned long filesize, bytecount, packetsize;
63 static int download_complete;
65 write_chunk(
struct rucb_conn *c,
int offset,
int flag,
66 char *data,
int datalen)
68 #if CONTIKI_TARGET_NETSIM
71 printf(
"received %d; %d\n", offset, datalen);
72 sprintf(buf,
"%lu%%", (100 * (offset + datalen)) / filesize);
79 read_chunk(
struct rucb_conn *c,
int offset,
char *to,
int maxsize)
84 if(bytecount + maxsize >= filesize) {
85 size = filesize - bytecount;
87 if(size > packetsize) {
91 if(bytecount == filesize) {
93 download_complete = 1;
103 const static struct rucb_callbacks rucb_callbacks = {write_chunk,
106 static struct rucb_conn rucb;
112 "sendtest <receiver> <size> [packetsize]: recevier must be specified",
"");
118 static linkaddr_t receiver;
119 static unsigned long cpu, lpm, rx, tx;
123 unsigned long cpu2, lpm2, rx2, tx2;
129 if(nextptr == data || *nextptr !=
'.') {
138 while(*args ==
' ') {
142 if(nextptr == data || filesize == 0) {
148 while(*args ==
' ') {
153 if(packetsize == 0) {
158 snprintf(buf,
sizeof(buf),
"%d.%d, %lu bytes, packetsize %lu",
159 receiver.u8[0], receiver.u8[1], filesize, packetsize);
163 download_complete = 0;
166 rucb_send(&rucb, &receiver);
169 lpm = energest_type_time(ENERGEST_TYPE_LPM);
170 cpu = energest_type_time(ENERGEST_TYPE_CPU);
171 rx = energest_type_time(ENERGEST_TYPE_LISTEN);
172 tx = energest_type_time(ENERGEST_TYPE_TRANSMIT);
177 lpm2 = energest_type_time(ENERGEST_TYPE_LPM);
178 cpu2 = energest_type_time(ENERGEST_TYPE_CPU);
179 rx2 = energest_type_time(ENERGEST_TYPE_LISTEN);
180 tx2 = energest_type_time(ENERGEST_TYPE_TRANSMIT);
182 sprintf(buf,
"%d seconds, %lu bytes/second",
183 (
int)((end_time_rucb - start_time_rucb) /
CLOCK_SECOND),
184 CLOCK_SECOND * filesize / (end_time_rucb - start_time_rucb));
187 sprintf(buf,
"%lu/%d rx %lu/%d tx (seconds)",
188 (rx2 - rx), RTIMER_ARCH_SECOND,
189 (tx2 - tx), RTIMER_ARCH_SECOND);
192 sprintf(buf,
"%lu/%lu = %lu%%",
194 (cpu2 + lpm2 - cpu - lpm),
195 100 * (rx2 - rx)/(cpu2 + lpm2 - cpu - lpm));
198 sprintf(buf,
"%lu/%lu = %lu%%",
200 (cpu2 + lpm2 - cpu - lpm),
201 100 * (tx2 - tx)/(cpu2 + lpm2 - cpu - lpm));
208 shell_sendtest_init(
void)
210 rucb_open(&rucb, SHELL_RIME_CHANNEL_SENDTEST, &rucb_callbacks);
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_EXIT()
Exit the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define NULL
The null pointer.
Header file for the Rime stack
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
CCIF clock_time_t clock_time(void)
Get the current clock time.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
Header file for process-related Contiki shell commands
#define PROCESS(name, strname)
Declare a process.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
#define CLOCK_SECOND
A second, measured in system clock time.