44 #include "sys/clock.h"
47 #include "lib/random.h"
52 #define MAX_COMMANDLENGTH 64
53 #define PERIOD_INTERVAL 60
56 PROCESS(shell_time_process,
"time");
59 "time [seconds]: output time in binary format, or set time in seconds since 1970",
61 PROCESS(shell_timestamp_process,
"timestamp");
64 "timestamp: prepend a timestamp to data",
65 &shell_timestamp_process);
66 PROCESS(shell_repeat_process,
"repeat");
67 PROCESS(shell_repeat_server_process,
"repeat server");
70 "repeat <num> <time> <command>: run a command every <time> seconds",
71 &shell_repeat_process);
72 PROCESS(shell_randwait_process,
"randwait");
75 "randwait <maxtime> <command>: wait for a random time before running a command",
76 &shell_randwait_process);
85 uint16_t timesynch_authority;
88 unsigned long newtime;
96 shell_set_time(newtime);
102 #if TIMESYNCH_CONF_ENABLED
107 msg.timesynch_authority = -1;
109 msg.time[0] = (uint16_t)(shell_time() >> 16);
110 msg.time[1] = (uint16_t)(shell_time());
125 uint8_t data[MAX_COMMANDLENGTH];
133 if(input->len1 + input->len2 == 0) {
137 msg.len = 3 + *(uint16_t *)input->data1;
138 msg.time[0] = (uint16_t)(shell_time() >> 16);
139 msg.time[1] = (uint16_t)(shell_time());
140 #if TIMESYNCH_CONF_ENABLED
145 memcpy(msg.data, input->data1 + 2,
146 input->len1 - 2 > MAX_COMMANDLENGTH?
147 MAX_COMMANDLENGTH: input->len1 - 2);
150 input->data2, input->len2);
158 static char *command;
159 static struct process *started_process;
160 char command_copy[MAX_COMMANDLENGTH];
171 data == &shell_repeat_process);
173 strncpy(command_copy, command, MAX_COMMANDLENGTH);
175 &repeat_command, &started_process);
177 if(started_process !=
NULL &&
180 data == started_process);
197 repeat_print_usage(
void)
204 static int reps, period;
205 static char command[MAX_COMMANDLENGTH];
208 const char *args, *next;
214 if(input->len1 + input->len2 != 0) {
215 shell_output(&repeat_command, input->data1, input->len1,
216 input->data2, input->len2);
227 repeat_print_usage();
233 repeat_print_usage();
240 repeat_print_usage();
246 while(*args ==
' ') {
250 strncpy(command, args, MAX_COMMANDLENGTH);
251 if(strlen(command) == 0) {
252 repeat_print_usage();
260 for(i = 0; reps == 0 || i < reps; ++i) {
262 process_start(&shell_repeat_server_process, (
void *)command);
264 PROCESS_EVENT_CONTINUE,
265 &shell_repeat_process);
267 data == &shell_repeat_server_process);
287 static char command[MAX_COMMANDLENGTH];
289 static struct process *started_process;
290 const char *args, *next;
319 while(*args ==
' ') {
323 strncpy(command, args, MAX_COMMANDLENGTH);
324 if(strlen(command) == 0) {
339 randwait_command.child, &started_process);
341 if(started_process !=
NULL &&
344 data == started_process);
351 shell_time_init(
void)
A brief description of what this file is.
#define RTIMER_NOW()
Get the current clock time.
rtimer_clock_t timesynch_time(void)
Get the current time-synchronized time.
CCIF clock_time_t clock_time(void)
Get the current clock time.
Default definitions of C compiler quirk work-arounds.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
static void input(void)
Process a received 6lowpan packet.
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 shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data 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 SHELL_COMMAND(name, command, description, process)
Define a shell command.
int shell_event_input
The event number for shell input data.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
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.
#define NULL
The null pointer.
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
Structure for shell input data.
#define CLOCK_SECOND
A second, measured in system clock time.
void process_start(struct process *p, process_data_t data)
Start a process.
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
Representation of a real-time task.
Header file for a simple time synchronization mechanism
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
int timesynch_authority_level(void)
Get the current authority level of the time-synchronized time.
#define PROCESS_BEGIN()
Define the beginning of a process.