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;
136 msg->crc =
crc16_data((
unsigned char *)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));
163 if(crc ==
crc16_data((
unsigned char *)msg->sendcmd, len, 0)) {
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);
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
static uip_ds6_addr_t * addr
Pointer to a router list entry.
A brief description of what this file is.
void packetbuf_clear(void)
Clear and reset the packetbuf.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_EXIT()
Exit the currently running process.
void process_exit(struct process *p)
Cause a process to exit.
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
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.
Header file for Rime's single-hop unicast
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
int process_is_running(struct process *p)
Check if a process is running.
Header file for the Rime stack
#define NULL
The null pointer.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void process_start(struct process *p, process_data_t data)
Start a process.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
Header file for a simple time synchronization mechanism
unsigned short crc16_data(const unsigned char *data, int len, unsigned short acc)
Calculate the CRC16 over a data area.
Header file for the CRC16 calculcation
#define PROCESS_BEGIN()
Define the beginning of a process.