41 #include "contiki-conf.h"
47 #include "lib/random.h"
55 #if CONTIKI_TARGET_NETSIM
61 int snprintf(
char *str,
size_t size,
const char *format, ...);
66 #define DEFAULT_COLLECT_REXMITS 15
69 #define COLLECT_MSG_HDRSIZE 4
76 struct collect_conn shell_collect_conn;
77 static int waiting_for_collect = 0;
79 static int is_sink = 0;
82 PROCESS(shell_mac_process,
"mac");
85 "mac <onoroff>: turn MAC protocol on (1) or off (0)",
87 PROCESS(shell_send_process,
"send");
90 "send <rexmits>: send data to the collector node, with rexmits hop-by-hop retransmissions",
92 PROCESS(shell_collect_process,
"collect");
95 "collect: collect data from the network",
96 &shell_collect_process);
98 PROCESS(shell_treedepth_process,
"treedepth");
101 "treedepth: print the collection tree depth",
102 &shell_treedepth_process);
104 PROCESS(shell_routes_process,
"routes");
107 "routes: dump route list in binary format",
108 &shell_routes_process);
109 PROCESS(shell_packetize_process,
"packetize");
112 "packetize: put data into one packet",
113 &shell_packetize_process);
123 shell_output_str(&mac_command,
"mac: current MAC layer: ", NETSTACK_RDC.name);
140 static struct queuebuf *q =
NULL;
152 q = queuebuf_new_from_packetbuf();
154 shell_output_str(&packetize_command,
"packetize: could not allocate packet buffer",
"");
157 ptr = queuebuf_dataptr(q);
163 len = input->len1 + input->len2;
175 memcpy(ptr + size, input->data1, input->len1);
177 memcpy(ptr + size, input->data2, input->len2);
195 struct route_entry *r;
199 memset(&msg, 0,
sizeof(msg));
201 for(i = 0; i < route_num(); ++i) {
205 msg.hop_count = r->cost;
206 msg.seqno = r->seqno;
207 shell_output(&routes_command, &msg,
sizeof(msg),
"", 0);
220 snprintf(buf,
sizeof(buf),
"%d", collect_depth(&collect));
233 #if TIMESYNCH_CONF_ENABLED
236 collect_set_sink(&shell_collect_conn, 1);
239 waiting_for_collect = 1;
243 waiting_for_collect = 0;
252 struct collect_msg *msg;
253 static int num_rexmits;
263 num_rexmits = DEFAULT_COLLECT_REXMITS;
270 len = input->len1 + input->len2;
280 memcpy(msg->data, input->data1, input->len1);
281 memcpy(msg->data + input->len1, input->data2, input->len2);
282 #if TIMESYNCH_CONF_ENABLED
288 collect_send(&shell_collect_conn, num_rexmits);
295 recv_collect(
const linkaddr_t *originator, uint8_t seqno, uint8_t hops)
297 struct collect_msg collect_msg;
299 rtimer_clock_t latency;
306 #if TIMESYNCH_CONF_ENABLED
312 if(waiting_for_collect) {
324 if(collect_msg.crc ==
crc16_data(dataptr, len, 0)) {
329 msg.latency = latency;
339 static const struct collect_callbacks collect_callbacks = { recv_collect };
342 shell_rime_init(
void)
344 collect_open(&shell_collect_conn, SHELL_RIME_CHANNEL_COLLECT,
345 COLLECT_ROUTER, &collect_callbacks);
346 collect_set_keepalive(&shell_collect_conn, 10 * 60 *
CLOCK_SECOND);
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 a simple time synchronization mechanism
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Header file for the Rime stack
rtimer_clock_t timesynch_time(void)
Get the current time-synchronized time.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
void timesynch_set_authority_level(int level)
Set the authority level of the current time.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
Structure for shell input data.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
void packetbuf_clear(void)
Clear and reset the packetbuf.
A brief description of what this file is.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
Header file for the CRC16 calculcation
unsigned short crc16_data(const unsigned char *data, int len, unsigned short acc)
Calculate the CRC16 over a data area.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
Include file for the Contiki low-layer network stack (NETSTACK)
Header file for the Rime route table
#define CLOCK_SECOND
A second, measured in system clock time.