Contiki 3.x
shell-run.c
1 /*
2  * Copyright (c) 2008, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  */
32 
33 #include <string.h>
34 
35 #include "contiki.h"
36 
37 #include "shell-run.h"
38 
39 /*---------------------------------------------------------------------------*/
40 PROCESS(shell_run_process, "run");
41 SHELL_COMMAND(run_command,
42  "run",
43  "run: load and run a PRG file",
44  &shell_run_process);
45 /*---------------------------------------------------------------------------*/
46 PROCESS_THREAD(shell_run_process, ev, data)
47 {
48  char *name, *print;
49 
50  PROCESS_BEGIN();
51 
52  name = data;
53  if(name == NULL || strlen(name) == 0) {
54  shell_output_str(&run_command,
55  "run <file>: filename must be given", "");
56  PROCESS_EXIT();
57  }
58 
59  switch(LOADER_LOAD(name, NULL)) {
60  case LOADER_OK:
61  print = "OK";
62  break;
63  case LOADER_ERR_READ:
64  print = "Read error";
65  break;
66  case LOADER_ERR_HDR:
67  print = "Header error";
68  break;
69  case LOADER_ERR_OS:
70  print = "Wrong OS";
71  break;
72  case LOADER_ERR_FMT:
73  print = "Data format error";
74  break;
75  case LOADER_ERR_MEM:
76  print = "Not enough memory";
77  break;
78  case LOADER_ERR_OPEN:
79  print = "Could not open file";
80  break;
81  case LOADER_ERR_ARCH:
82  print = "Wrong architecture";
83  break;
84  case LOADER_ERR_VERSION:
85  print = "Wrong OS version";
86  break;
88  print = "Program loading not supported";
89  break;
90  default:
91  print = "Unknown return code from the loader (internal bug)";
92  break;
93  }
94  shell_output_str(&run_command, print, ".");
95 
96  PROCESS_END();
97 }
98 /*---------------------------------------------------------------------------*/
99 void
100 shell_run_init(void)
101 {
102  shell_register_command(&run_command);
103 }
104 /*---------------------------------------------------------------------------*/
#define LOADER_ERR_ARCH
Wrong architecture.
Definition: loader.h:67
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
Definition: shell.c:383
#define LOADER_OK
No error.
Definition: loader.h:60
#define PROCESS_EXIT()
Exit the currently running process.
Definition: process.h:200
#define PROCESS_BEGIN()
Define the beginning of a process.
Definition: process.h:120
#define LOADER_ERR_VERSION
Wrong OS version.
Definition: loader.h:68
#define LOADER_ERR_OS
Wrong OS.
Definition: loader.h:63
#define NULL
The null pointer.
#define LOADER_ERR_READ
Read error.
Definition: loader.h:61
#define LOADER_ERR_HDR
Header error.
Definition: loader.h:62
#define LOADER_ERR_MEM
Not enough memory.
Definition: loader.h:65
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
Definition: process.h:273
#define PROCESS_END()
Define the end of a process.
Definition: process.h:131
void shell_register_command(struct shell_command *c)
Register a command with the shell.
Definition: shell.c:413
#define PROCESS(name, strname)
Declare a process.
Definition: process.h:307
#define LOADER_ERR_OPEN
Could not open file.
Definition: loader.h:66
#define LOADER_ERR_NOLOADER
Program loading not supported.
Definition: loader.h:69
#define LOADER_LOAD(name, arg)
Load and execute a program.
Definition: loader.h:92
#define LOADER_ERR_FMT
Data format error.
Definition: loader.h:64
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.
Definition: shell.h:219