34 #include "contiki-conf.h"
40 #include "lib/random.h"
47 #if CONTIKI_TARGET_NETSIM
53 int snprintf(
char *str,
size_t size,
const char *format, ...);
57 #define CMDMSG_HDR_SIZE 2
64 static struct unicast_conn uc;
66 PROCESS(shell_sendcmd_process,
"sendcmd");
67 PROCESS(shell_sendcmd_server_process,
"sendcmd server");
70 "sendcmd <node addr> <command>: send a command to the specified one-hop node",
71 &shell_sendcmd_process);
75 static struct process *child_command;
84 (ev == PROCESS_EVENT_EXITED &&
85 data == child_command));
86 if(ev == PROCESS_EVENT_EXIT) {
105 if(nextptr == data || *nextptr !=
'.') {
107 "sendcmd <node addr>: receiver must be specified",
"");
113 snprintf(buf,
sizeof(buf),
"%d.%d", addr.u8[0], addr.u8[1]);
117 len = strlen((
char *)nextptr);
124 snprintf(buf,
sizeof(buf),
"%d", len);
132 strcpy(msg->sendcmd, nextptr);
135 msg->sendcmd[len] = 0;
138 unicast_send(&uc, &addr);
144 recv_uc(
struct unicast_conn *c,
const linkaddr_t *from)
160 msg->sendcmd[len] = 0;
161 memcpy(&crc, &msg->crc,
sizeof(crc));
165 process_start(&shell_sendcmd_server_process, (
void *)msg->sendcmd);
169 static const struct unicast_callbacks unicast_callbacks = { recv_uc };
172 shell_rime_sendcmd_init(
void)
174 unicast_open(&uc, SHELL_RIME_CHANNEL_SENDCMD, &unicast_callbacks);
int process_is_running(struct process *p)
Check if a process is running.
Header file for Rime's single-hop unicast
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_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
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.
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.
#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.
#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.