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 COLLECT_REXMITS 4
68 #define TRICKLEMSG_HDR_SIZE 2
75 static struct trickle_conn trickle;
77 PROCESS(shell_netcmd_process,
"netcmd");
78 PROCESS(shell_netcmd_server_process,
"netcmd server");
81 "netcmd <command>: run a command on all nodes in the network",
82 &shell_netcmd_process);
86 static struct process *child_command;
91 printf(
"netcmd server got command string '%s'\n", (
char *)data);
95 (ev == PROCESS_EVENT_EXITED &&
96 data == child_command));
97 if(ev == PROCESS_EVENT_EXIT) {
107 struct trickle_msg *msg;
113 len = strlen((
char *)data);
121 snprintf(buf,
sizeof(buf),
"%d", len);
128 strcpy(msg->netcmd, data);
131 msg->netcmd[len] = 0;
133 printf(
"netcmd sending '%s'\n", msg->netcmd);
134 trickle_send(&trickle);
141 recv_trickle(
struct trickle_conn *c)
143 struct trickle_msg *msg;
157 msg->netcmd[len] = 0;
158 memcpy(&crc, &msg->crc,
sizeof(crc));
162 process_start(&shell_netcmd_server_process, (
void *)msg->netcmd);
166 const static struct trickle_callbacks trickle_callbacks = { recv_trickle };
169 shell_rime_netcmd_init(
void)
171 trickle_open(&trickle,
CLOCK_SECOND * 4, SHELL_RIME_CHANNEL_NETCMD,
int process_is_running(struct process *p)
Check if a process is running.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
int shell_start_command(char *commandline, int commandline_len, struct shell_command *child, struct process **started_process)
Start a shell command from another shell command.
#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
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
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.
void packetbuf_clear(void)
Clear and reset the packetbuf.
void process_start(struct process *p, process_data_t data)
Start a process.
A brief description of what this file is.
Header file for Trickle (reliable single source flooding) for Rime
#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.
void process_exit(struct process *p)
Cause a process to exit.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
Header file for the Rime route table
#define CLOCK_SECOND
A second, measured in system clock time.