43 #include "sys/clock.h"
46 #include "lib/random.h"
51 #define MAX_COMMANDLENGTH 64
52 #define PERIOD_INTERVAL 60
55 #define MIN(a, b) ((a) < (b)? (a) : (b))
60 PROCESS(shell_time_process,
"time");
63 "time [seconds]: output time in binary format, or set time in seconds since 1970",
65 PROCESS(shell_timestamp_process,
"timestamp");
68 "timestamp: prepend a timestamp to data",
69 &shell_timestamp_process);
70 PROCESS(shell_repeat_process,
"repeat");
71 PROCESS(shell_repeat_server_process,
"repeat server");
74 "repeat <num> <time> <command>: run a command every <time> seconds",
75 &shell_repeat_process);
76 PROCESS(shell_randwait_process,
"randwait");
79 "randwait <maxtime> <command>: wait for a random time before running a command",
80 &shell_randwait_process);
89 uint16_t timesynch_authority;
92 unsigned long newtime;
100 shell_set_time(newtime);
106 #if TIMESYNCH_CONF_ENABLED
111 msg.timesynch_authority = -1;
113 msg.time[0] = (uint16_t)(shell_time() >> 16);
114 msg.time[1] = (uint16_t)(shell_time());
129 uint8_t data[MAX_COMMANDLENGTH];
137 if(input->len1 + input->len2 == 0) {
141 msg.len = 3 + *(uint16_t *)input->data1;
142 msg.time[0] = (uint16_t)(shell_time() >> 16);
143 msg.time[1] = (uint16_t)(shell_time());
144 #if TIMESYNCH_CONF_ENABLED
149 memcpy(msg.data, input->data1 + 2,
150 input->len1 - 2 > MAX_COMMANDLENGTH?
151 MAX_COMMANDLENGTH: input->len1 - 2);
154 input->data2, input->len2);
162 static char *command;
163 static struct process *started_process;
164 char command_copy[MAX_COMMANDLENGTH];
176 data == &shell_repeat_process);
178 strncpy(command_copy, command, MAX_COMMANDLENGTH);
180 &repeat_command, &started_process);
182 if(started_process !=
NULL &&
185 data == started_process);
202 repeat_print_usage(
void)
209 static int reps, period, period_left;
210 static char command[MAX_COMMANDLENGTH];
213 static clock_time_t start_time;
214 const char *args, *next;
220 if(input->len1 + input->len2 != 0) {
221 shell_output(&repeat_command, input->data1, input->len1,
222 input->data2, input->len2);
233 repeat_print_usage();
239 repeat_print_usage();
246 repeat_print_usage();
252 while(*args ==
' ') {
256 strncpy(command, args, MAX_COMMANDLENGTH);
257 if(strlen(command) == 0) {
258 repeat_print_usage();
267 for(i = 0; reps == 0 || i < reps; ++i) {
269 process_start(&shell_repeat_server_process, (
void *)command);
271 PROCESS_EVENT_CONTINUE,
272 &shell_repeat_process);
274 data == &shell_repeat_server_process);
294 static char command[MAX_COMMANDLENGTH];
296 static struct process *started_process;
297 const char *args, *next;
327 while(*args ==
' ') {
331 strncpy(command, args, MAX_COMMANDLENGTH);
332 if(strlen(command) == 0) {
347 randwait_command.child, &started_process);
349 if(started_process !=
NULL &&
352 data == started_process);
359 shell_time_init(
void)
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
int process_is_running(struct process *p)
Check if a process is running.
#define PROCESS_WAIT_UNTIL(c)
Wait for a condition to occur.
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.
A brief description of what this file is.
int timesynch_authority_level(void)
Get the current authority level of the time-synchronized time.
#define NULL
The null pointer.
Header file for a simple time synchronization mechanism
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.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
CCIF clock_time_t clock_time(void)
Get the current clock time.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
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.
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
int shell_event_input
The event number for shell input data.
void process_start(struct process *p, process_data_t data)
Start a process.
#define RTIMER_NOW()
Get the current clock time.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Representation of a real-time task.
unsigned short random_rand(void)
Generate the next state and return the upper part of it.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
#define CLOCK_SECOND
A second, measured in system clock time.