47 int snprintf(
char *str,
size_t size,
const char *format, ...);
50 struct rime_ping_msg {
51 rtimer_clock_t pingtime;
52 rtimer_clock_t pongtime;
55 static struct mesh_conn mesh;
56 static int waiting_for_pong = 0;
59 PROCESS(shell_rime_ping_process,
"rime-ping");
62 "rime-ping <node addr>: send a message to a specific node and get a reply",
63 &shell_rime_ping_process);
68 static struct etimer timeout, periodic;
69 static linkaddr_t receiver;
70 struct rime_ping_msg *ping;
77 if(nextptr == data || *nextptr !=
'.') {
79 "ping <receiver>: recevier must be specified",
"");
85 snprintf(buf,
sizeof(buf),
"%d.%d", receiver.u8[0], receiver.u8[1]);
88 for(i = 0; i < 4; ++i) {
92 #if TIMESYNCH_CONF_ENABLED
101 waiting_for_pong = 1;
103 waiting_for_pong == 0);
104 if(waiting_for_pong == 0) {
110 waiting_for_pong = 0;
116 timedout_mesh(
struct mesh_conn *c)
121 sent_mesh(
struct mesh_conn *c)
125 recv_mesh(
struct mesh_conn *c,
const linkaddr_t *from, uint8_t hops)
127 struct rime_ping_msg ping;
129 rtimer_clock_t pingrecvtime;
133 if(waiting_for_pong == 0) {
134 #if TIMESYNCH_CONF_ENABLED
137 ping.pongtime = ping.pingtime;
142 #if TIMESYNCH_CONF_ENABLED
147 snprintf(buf,
sizeof(buf),
"%lu ms (%lu + %lu), %d hops.",
148 (1000L * (pingrecvtime - ping.pingtime)) / RTIMER_ARCH_SECOND,
149 (1000L * (ping.pongtime - ping.pingtime)) / RTIMER_ARCH_SECOND,
150 (1000L * (pingrecvtime - ping.pongtime)) / RTIMER_ARCH_SECOND,
154 "Pong recived; rtt ", buf);
155 waiting_for_pong = 0;
164 shell_rime_ping_init(
void)
166 mesh_open(&mesh, SHELL_RIME_CHANNEL_PING, &mesh_callbacks);
int mesh_send(struct mesh_conn *c, const linkaddr_t *to)
Send a mesh packet.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
#define CC_CONST_FUNCTION
Configure if the C compiler have problems with const function pointers.
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.
Main header file for the Contiki shell
#define NULL
The null pointer.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Header file for the Rime stack
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
rtimer_clock_t timesynch_time(void)
Get the current time-synchronized time.
#define rtimer_arch_now()
#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 etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void mesh_open(struct mesh_conn *c, uint16_t channels, const struct mesh_callbacks *callbacks)
Open a mesh connection.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
#define CLOCK_SECOND
A second, measured in system clock time.