41 #include "contiki-conf.h"
46 #include "lib/random.h"
56 int snprintf(
char *str,
size_t size,
const char *format, ...);
61 #define COLLECT_MSG_HDRSIZE 2
67 static struct broadcast_conn broadcast;
68 static struct unicast_conn uc;
70 PROCESS(shell_broadcast_process,
"broadcast");
73 "broadcast: broadcast data to all neighbors",
74 &shell_broadcast_process);
75 PROCESS(shell_unicast_process,
"unicast");
78 "unicast <node addr>: unicast data to specific neighbor",
79 &shell_unicast_process);
85 struct collect_msg *msg;
93 len = input->len1 + input->len2;
103 memcpy(msg->data, input->data1, input->len1);
104 memcpy(msg->data + input->len1, input->data2, input->len2);
105 #if TIMESYNCH_CONF_ENABLED
117 recv_broadcast(
struct broadcast_conn *c,
const linkaddr_t *from)
119 struct collect_msg *msg;
120 rtimer_clock_t latency;
124 #if TIMESYNCH_CONF_ENABLED
130 printf(
"broadcast message received from %d.%d, latency %lu ms, data '%.*s'\n",
131 from->u8[0], from->u8[1],
132 (1000L * latency) / RTIMER_ARCH_SECOND,
141 static linkaddr_t receiver;
144 struct collect_msg *msg;
150 if(nextptr == data || *nextptr !=
'.') {
152 "unicast <receiver>: recevier must be specified",
"");
158 snprintf(buf,
sizeof(buf),
"%d.%d", receiver.u8[0], receiver.u8[1]);
165 len = input->len1 + input->len2;
175 memcpy(msg->data, input->data1, input->len1);
176 memcpy(msg->data + input->len1, input->data2, input->len2);
177 #if TIMESYNCH_CONF_ENABLED
183 unicast_send(&uc, &receiver);
189 recv_uc(
struct unicast_conn *c,
const linkaddr_t *from)
191 struct collect_msg *msg;
192 rtimer_clock_t latency;
196 #if TIMESYNCH_CONF_ENABLED
202 printf(
"unicast message received from %d.%d, latency %lu ms, data '%.*s'\n",
203 from->u8[0], from->u8[1],
204 (1000L * latency) / RTIMER_ARCH_SECOND,
208 static const struct unicast_callbacks unicast_callbacks = {recv_uc};
211 shell_rime_debug_init(
void)
213 unicast_open(&uc, SHELL_RIME_CHANNEL_UNICAST,
216 &broadcast_callbacks);
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.
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.
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.
Callback structure for broadcast.
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 broadcast_send(struct broadcast_conn *c)
Send an identified best-effort broadcast packet.
int shell_event_input
The event number for shell input data.
void packetbuf_clear(void)
Clear and reset the packetbuf.
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.
void broadcast_open(struct broadcast_conn *c, uint16_t channel, const struct broadcast_callbacks *u)
Set up an identified best-effort broadcast connection.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
A brief description of what this file is.
Header file for the Rime route table