Modestus Moon OS  R4
CS 450 project
commhand.c
Go to the documentation of this file.
1 #include <core/serial.h>
2 #include <input.h>
3 #include <string.h>
4 #include "include/comm_list.h"
5 #include <linked_list.h>
6 
7 
8 
9 char parsed[MAX_IN][MAX_LENGTH]={{""}};
10 char in_string[MAX_LENGTH] = {""};
11 int shutdown = 0;
12 
13 
14 // Command array that matches comm_list.h
16 
23 void parse_comm(char in_string[MAX_LENGTH], char parsed[MAX_IN][MAX_LENGTH]) {
24  const char *tokens = " '\"/:.";
25  char *token = strtok(in_string, tokens);
26  int i = 0;
27  while (token != NULL) {
28  strcpy(parsed[i], token);
29  token = strtok(NULL, tokens);
30  i++;
31  }
32 }
33 
39  serial_println("");
40 
41 
42 
44 
45  /*OLD WAY*/
46 // if(strcmp(parsed[0],"help")==0) {
47 // if(strcmp(parsed[1],"")==0) {
48 // help();
49 // } else if(strcmp(parsed[1],"version")==0) {
50 // helpGetVersion();
51 // } else if(strcmp(parsed[1],"shutdown")==0) {
52 // helpShutdown();
53 // } else if(strcmp(parsed[1],"time")==0) {
54 // helpTime(&parsed[2]);
55 // //serial_println("Did you mean 'get time' or 'get date'?");
56 // } else if(strcmp(parsed[1],"date")==0) {
57 // helpDate(&parsed[2]);
58 // //serial_println("Did you mean 'set time' or 'set date'?");
59 // } else {
60 // serial_println(IMPROPER_COMMAND);
61 // }
62 // // else {
63 // // serial_println(IMPROPER_COMMAND);
64 // // }
65 
66 
67 // } else if(strcmp(parsed[0],"version")==0) {
68 // if(strcmp(parsed[2],"")==0) {
69 // if(strcmp(parsed[1],"")==0) {
70 // version();
71 
72 // } else {
73 // serial_println(UNKNOWN_COMMAND);
74 // }
75 // }
76 // } else if(strcmp(parsed[0],"date")==0) {
77 // if(strcmp(parsed[1],"get")==0) {
78 // getDate();
79 // } else if(strcmp(parsed[1],"set")==0) {
80 // setDate(&parsed[2]);
81 // } else {
82 // serial_println(IMPROPER_COMMAND);
83 // }
84 
85 // } else if(strcmp(parsed[0],"time")==0) {
86 // if(strcmp(parsed[1],"set")==0) {
87 // setTime(&parsed[2]);
88 // } else if(strcmp(parsed[1],"get")==0) {
89 // getTime();
90 // } else {
91 // serial_println(IMPROPER_COMMAND);
92 // }
93 
94 // } else if(strcmp(parsed[0],"shutdown")==0) {
95 // if(strcmp(parsed[1],"")==0) {
96 // int confirm = 0;
97 
98 // serial_print("Confirm shutdown y/n?: ");
99 
100 // if(confirm == 0) {
101 // serial_print(PROMPT);
102 // strcpy(in_string, serial_poll(in_string));
103 // if(strcmp(in_string, "y")==0)
104 // confirm = 1;
105 // else if (strcmp(in_string, "n")==0)
106 // confirm = 2;
107 // }
108 // serial_println(" ");
109 // if(confirm == 1)
110 // shutdown = 1;
111 // } else {
112 // serial_println(UNKNOWN_COMMAND);
113 // }
114 
115 
116 // } else {
117 // serial_println(IMPROPER_COMMAND);
118 // }
119 
120  /*END OLD WAY*/
121  /*
122  serial_println("0");
123  serial_println((const char *)parsed[0]);
124  serial_println("1");
125  serial_println((const char *)parsed[1]);
126  serial_println("2");
127  serial_println((const char *)parsed[2]);
128  serial_println("3");
129  serial_println((const char *)parsed[3]);
130  serial_println("4");
131  serial_println((const char *)parsed[4]);
132  serial_println("5");
133  serial_println((const char *)parsed[5]);
134  serial_println("6");
135  serial_println((const char *)parsed[6]);
136  serial_println("7");
137  serial_println((const char *)parsed[7]);
138 */
139 
140  /* Check for valid input */
141  int j=0;
142  int output = -99;
143  for(;j<MAX_CMD_LIST_LENGTH;j++) {
144  if(strcmp(cmdArray[j].cmdName, parsed[0])==0) {
145  output = (*(cmdArray[j].cmdFunc))(&(parsed[1]));
146  if(output == 9) {
147  shutdown = 1;
148  break;
149  }
150  }
151  }
152 
153 
154 
155 
156  /* Reset the array of parsed input */
157  int i=0;//, j=0;
158  for(;i<MAX_LENGTH;i++) {
159  *parsed[i] = (char)'\0';
160  }
161  if(output == -99)
162  {
163  serial_println("Invalid Command! \r\n");
164  }
165 
166 
167 }
168 
170  arr[0].cmdName = "help";
171  arr[0].cmdFunc = &helpFunc;
172 
173  arr[1].cmdName = "version";
174  arr[1].cmdFunc = &version;
175 
176  arr[2].cmdName = "date";
177  arr[2].cmdFunc = &date;
178 
179  arr[3].cmdName = "time";
180  arr[3].cmdFunc = &time;
181 
182  arr[4].cmdName = "shutdown";
183  arr[4].cmdFunc = &shutdownFunc;
184 
185  arr[5].cmdName = "pcb";
186  arr[5].cmdFunc = &pcbFunc;
187 
188  arr[6].cmdName = "loadr3";
189  arr[6].cmdFunc = &loadr3;
190 
191  arr[7].cmdName = "mcb";
192  arr[7].cmdFunc = &mcbFunc;
193 }
194 
195 
200 void init_commhand(void) {
201  initCmdArray(cmdArray);
202 
203  *parsed[0]=0;
204  (*(cmdArray[0].cmdFunc))(&(parsed[0]));
205 
206  int i=0;//, j=0;
207  for(;i<MAX_LENGTH;i++) {
208  *parsed[i] = (char)'\0';
209  }
210  while(!shutdown) {
214  sys_req(IDLE);
215  }
216 
217 }
218 
cmd_struct_t cmdArray[MAX_CMD_LIST_LENGTH]
Definition: commhand.c:15
#define PROMPT
Definition: input.h:8
int sys_req(int op_code)
Definition: mpx_supt.c:11
#define MAX_LENGTH
Definition: input.h:6
void initCmdArray(cmd_struct_t *arr)
Definition: commhand.c:169
int time(char parameters[][MAX_LENGTH])
Definition: comm_list.c:479
int serial_print(const char *msg)
Definition: serial.c:59
void exec_comm(char in_string[MAX_LENGTH])
exec_comm Takes parsed input and calls the proper command
Definition: commhand.c:38
#define NULL
Definition: system.h:4
int date(char parameters[][MAX_LENGTH])
Definition: comm_list.c:436
char parsed[MAX_IN][MAX_LENGTH]
Definition: commhand.c:9
const char * cmdName
Definition: comm_list.h:13
char * strcpy(char *s1, const char *s2)
strcpy copies one string to another string
Definition: string.c:26
int mcbFunc(char parameters[][MAX_LENGTH])
takes in whatever you are looking for and checks to see if it can be done for mcb ...
Definition: comm_list.c:904
char in_string[MAX_LENGTH]
Definition: commhand.c:10
#define MAX_CMD_LIST_LENGTH
Definition: comm_list.h:7
int version(char parameters[][MAX_LENGTH])
version prints out the current version of the operating system. It will print out R1...
Definition: comm_list.c:425
int shutdownFunc(char parameters[][MAX_LENGTH])
shutdownFunc shuts down the OS.
Definition: comm_list.c:521
char * strtok(char *s1, const char *s2)
strtok Split string into tokens.
Definition: string.c:154
void init_commhand(void)
init_commhand Starts input loop and waits for shutdown code
Definition: commhand.c:200
int loadr3(char parameters[][MAX_LENGTH])
loads all processes into memory in a suspended ready state at any priority of the users choosing ...
Definition: comm_list.c:825
#define MAX_IN
Definition: input.h:7
int pcbFunc(char parameters[][MAX_LENGTH])
takes in parameters and makes sure its valid then runs what you want to.
Definition: comm_list.c:558
int serial_println(const char *msg)
Definition: serial.c:44
int(* cmdFunc)(char[][MAX_LENGTH])
Definition: comm_list.h:14
char * serial_poll(char in_string[MAX_LENGTH])
Definition: serial.c:114
#define IDLE
Definition: mpx_supt.h:7
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
int helpFunc(char parameters[][MAX_LENGTH])
helpFunc calls the other help functions
Definition: comm_list.c:49
void parse_comm(char in_string[MAX_LENGTH], char parsed[MAX_IN][MAX_LENGTH])
parse_comm Parses the input recieved from the user input using &#39; &#39; as a delimeter ...
Definition: commhand.c:23
int shutdown
Definition: commhand.c:11