Modestus Moon OS  R4
CS 450 project
comm_list.c File Reference
#include <comm_vars.h>
#include <core/rtc.h>
#include <string.h>
#include <input.h>
#include "include/comm_list.h"
#include <core/pcb.h>
#include <linked_list.h>
#include <core/mcb.h>
#include "../procsr3.h"
Include dependency graph for comm_list.c:

Go to the source code of this file.

Functions

int getNumDaysInMonth (int month, int year)
 getNumDaysInMonth is a helper function to allow the easy retrieval of days in a month based on the month input by the user. More...
 
int isEmpty (char parameters[][MAX_LENGTH])
 
int helpFunc (char parameters[][MAX_LENGTH])
 helpFunc calls the other help functions More...
 
void help ()
 help prints out a list of all possible commands and a brief description of what they do. More...
 
void helpMCB (char parameters[][MAX_LENGTH])
 The command handler for mcb's checking for valid input. More...
 
void helpMcbPrint ()
 Prints the help menu for all mcb functions. More...
 
void helpMCBInitHeap ()
 prints the all details about the initheap func More...
 
void helpMCBAllocate ()
 Prints the details for Allocating an mcb. More...
 
void helpMCBFreeMem ()
 Prints the details for freeing an mcb. More...
 
void helpMCBIsEmpty ()
 Prints details for IsEmpty func. More...
 
void helpMCBShowFree ()
 Prints details for showing all the free memory blocks in the heap. More...
 
void helpMCBShowAllocated ()
 Prints details for showing all the allocated memory blocks in the heap. More...
 
void helpLoadR3 ()
 helpLoadR3 prints out the help commands for helpLoadR3 Loads all of the processes from procsr3 More...
 
int helpGetVersion ()
 helpGetVersion prints the help instructions for version. Tells the user what the command and arguments for 'version' are. More...
 
void helpGetDate ()
 helpGetDate prints the help instructions for get date. Tells the user what the command and arguments for 'get date' are. More...
 
void helpSetDate ()
 helpSetDate prints the help instructions for set date. Tells the user what the command and arguments for 'set date' are. More...
 
void helpGetTime ()
 helpGetTime prints the help instructions for get time. Tells the user what the commands and arguments for 'get time' are. More...
 
void helpSetTime ()
 helpSetTime prints the help instructions for set time. Tells the user what the command and arguments for 'set time' are. More...
 
void helpShutdown ()
 helpShutdown prints the help instructions for set date. Tells the user what the command and arguments for 'set date' are. More...
 
void helpVersion ()
 helpVersion prints the help instructions for using the version command. No arguments are required. More...
 
void helpDate (char parameters[][MAX_LENGTH])
 helpDate prints out the help information for date, for date –set and date –get More...
 
void helpTime (char parameters[][MAX_LENGTH])
 helpTime prints out the help information for time, for time –set and time –get More...
 
void helpPcb (char parameters[][MAX_LENGTH])
 helpPcb takes in the command to print the help information for. Calls the proper function to print the help information for the selected command. More...
 
void helpPcbPrint ()
 helpPcbPrint prints out the commands for PCBs. More...
 
void helpSuspendPCB ()
 helpSuspendPCB prints the help instructions for the suspendPCB command. More...
 
void helpResumePCB ()
 helpResumePCB prints out the parameters and usage of the resume pcb command. More...
 
void helpSetPriority ()
 helpSetPriority prints out to console the parameters and usage for –setpriority. More...
 
void helpShowPCB ()
 
void helpShowAllProcesses ()
 helpShowAllProcesses shows all processes in the system. Takes in no parameters and prints out to the console. More...
 
void helpShowReadyProcesses ()
 helpShowReadyProcesses shows the parameters and usage for showing ready PCBs. More...
 
void helpShowBlockedProcesses ()
 helpShowBlockedProcesses shows the parameters and usage for showing the blocked PCBs. More...
 
void helpCreatePCB ()
 helpCreatePCB prints out the parameters and usage for createPCB. More...
 
void helpDeletePCB ()
 helpDeletePCB prints out the parameters and usage for deleting a PCB. More...
 
void helpBlockPCB ()
 helpBlockPCB prints out the parameters and usage for blocking a PCB. More...
 
void helpUnblockPCB ()
 helpUnblockPCB prints out the parameters and usage for unblocking a PCB. More...
 
int version (char parameters[][MAX_LENGTH])
 version prints out the current version of the operating system. It will print out R1, R2, R3, ... depending on the current module. More...
 
int date (char parameters[][MAX_LENGTH])
 
void getDate ()
 getDate Get the current date from the system. More...
 
void setDate (char parameters[][MAX_LENGTH])
 setDate sets the system date using the input from the user. More...
 
int time (char parameters[][MAX_LENGTH])
 
void getTime ()
 getTime this function has the side-effect of printing the current time to the terminal. More...
 
void setTime (char parameters[][MAX_LENGTH])
 setTime sets the current system time from the users input. More...
 
int shutdownFunc (char parameters[][MAX_LENGTH])
 shutdownFunc shuts down the OS. More...
 
int pcbFunc (char parameters[][MAX_LENGTH])
 takes in parameters and makes sure its valid then runs what you want to. More...
 
int suspendPCB (char parameters[][MAX_LENGTH])
 suspendPCB suspends the pcb passed in by the user More...
 
int resumePCB (char parameters[][MAX_LENGTH])
 resumePCB resumes the PCB passed in by the user More...
 
int setPriority (char *procName, char *procPrio)
 setPriority sets the priority of a particular process More...
 
int showPCB (char parameters[][MAX_LENGTH])
 showPCB shows the process information for the process requested by the user More...
 
int showAllProcesses (char parameters[][MAX_LENGTH])
 showAllProcesses shows all processes in the system. More...
 
int showReadyProcesses (char parameters[][MAX_LENGTH])
 showReadyProcesses shows all processes that are ready, in the ready queue (linked list). More...
 
int showBlockedProcesses (char parameters[][MAX_LENGTH])
 showBlockedProcesses shows all processes that are blocked. More...
 
int createPCB (const char *pcbName, const char *pcbPriority, const char *pcbClass)
 createPCB creates a new PCB and allocates memory for the PCB. More...
 
int deletePCB (char parameters[][MAX_LENGTH])
 deletePCB deletes the PCB requested by the user. More...
 
int blockPCB (char parameters[][MAX_LENGTH])
 blockPCB blocks the specified PCB More...
 
int unblockPCB (char parameters[][MAX_LENGTH])
 unblockPCB unblocks the specified PCB. More...
 
int yield ()
 stops the exection of commhand and executes each process in the ready queue More...
 
int loadr3 (char parameters[][MAX_LENGTH])
 loads all processes into memory in a suspended ready state at any priority of the users choosing More...
 
int mcbFunc (char parameters[][MAX_LENGTH])
 takes in whatever you are looking for and checks to see if it can be done for mcb More...
 

Function Documentation

int blockPCB ( char  parameters[][MAX_LENGTH])

blockPCB blocks the specified PCB

Parameters
parameterstakes in the name of the PCB to move to the blocked queue.
Returns
an integer, normally 0.

Definition at line 794 of file comm_list.c.

References BLOCKED, changeProcessState(), errorToString(), printf, showPCB(), and SUCCESS.

Referenced by pcbFunc().

794  {
795  e_PCB_ERROR_CODE_t retVal = changeProcessState((const char*)parameters[0], BLOCKED);
796  if(retVal == SUCCESS)
797  {
798  showPCB(parameters);
799  }
800  printf("Status: %s\r\n", errorToString(retVal));
801  return retVal;
802 // const char* name = (const char*)parameters[0];
803 // changeProcessState(name, BLOCKED);
804 // return 0;
805 }
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
Definition: comm_list.c:737
Definition: pcb.h:38
Definition: pcb.h:47
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
Definition: pcb.h:38
e_PCB_ERROR_CODE_t changeProcessState(const char *processName, e_PROCESS_STATE_t state)
changeProcessState changes the state of the process being called
Definition: pcb.c:168
int createPCB ( const char *  pcbName,
const char *  pcbPriority,
const char *  pcbClass 
)

createPCB creates a new PCB and allocates memory for the PCB.

Parameters
pcbNamethe name of the PCB to be created
pcbPrioritythe priority of the PCB to be created
pcbClassthe class of the PCB to be created
Returns
an integer, normally 0.

Definition at line 773 of file comm_list.c.

References atoi(), errorToString(), prevPCBError, printf, setupPCB(), and stringToClass().

Referenced by pcbFunc().

773  {
774  setupPCB(pcbName, stringToClass(pcbClass), atoi(pcbPriority));
775  //printf("Clas String %s: num %d\r\n", pcbClass, (int) stringToClass(pcbClass));
776  printf("Status: %s\r\n", errorToString(prevPCBError));
777 
778  return prevPCBError;
779 
780 }
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
e_PROCESS_CLASS_t stringToClass(const char *stringifiedClass)
stringToClass returns the enum representation of a string
Definition: pcb.c:328
int atoi(const char *s)
atoi converts and ASCII string to an integer
Definition: string.c:46
pcb_t * setupPCB(const char *processName, e_PROCESS_CLASS_t processClass, processPriority_t processPriority)
setupPCB calls allocatePCB, initializes the PCB with the arguments and sets it state to ready ...
Definition: pcb.c:71
int date ( char  parameters[][MAX_LENGTH])

Definition at line 436 of file comm_list.c.

References getDate(), serial_println(), setDate(), and strcmp().

Referenced by initCmdArray().

436  {
437  if(!strcmp(parameters[0],"--get")) {
438  getDate();
439  } else if(!strcmp(parameters[0],"--set")) {
440  setDate(&parameters[1]);
441  } else {
442  serial_println("Check your input, there are only 12 months in a year.");
443  }
444  return 0;
445 }
void getDate()
getDate Get the current date from the system.
Definition: comm_list.c:447
void setDate(char parameters[][MAX_LENGTH])
setDate sets the system date using the input from the user.
Definition: comm_list.c:453
int serial_println(const char *msg)
Definition: serial.c:44
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
int deletePCB ( char  parameters[][MAX_LENGTH])

deletePCB deletes the PCB requested by the user.

Parameters
parameterstakes in the name of the PCB to be deleted.
Returns
an integer, normally 0.

Definition at line 782 of file comm_list.c.

References errorToString(), findPCB(), freePCB(), prevPCBError, and printf.

Referenced by pcbFunc().

782  {
783  pcb_t* foundPCB = findPCB((const char*)parameters[0]);
784  if(!foundPCB)
785  {
786  printf("Status: %s\r\n", errorToString(prevPCBError));
787  return prevPCBError;
788  }
789  e_PCB_ERROR_CODE_t retval = freePCB(foundPCB);
790  printf("Status: %s\r\n", errorToString(retval));
791  return retval;
792 }
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
typedef for pcb_t struct
e_PCB_ERROR_CODE_t freePCB(pcb_t *pcbToFree)
freePCB free all associated memory with the PCB, including the stack and other pointers ...
Definition: pcb.c:32
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
Definition: pcb.h:38
void getDate ( )

getDate Get the current date from the system.

No parameters required, prints out a date.

Definition at line 447 of file comm_list.c.

References get_date(), and printf.

Referenced by date(), and setDate().

447  {
448  int month=0, day=0, year=0;
449  get_date(&day, &month, &year);
450  printf("The current date is %d/%d/20%d UTC\r\n", day, month, year);
451 }
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
void get_date(int *day, int *month, int *year)
get_date this function will retrieve the system date and place in three pointers
Definition: rtc.c:56
int getNumDaysInMonth ( int  month,
int  year 
)

getNumDaysInMonth is a helper function to allow the easy retrieval of days in a month based on the month input by the user.

Parameters
monthis an integer from 1-12
yearis an integer representing the year to check if it's a leap year
Returns
the number of days in the corresponding month

Definition at line 15 of file comm_list.c.

Referenced by setDate().

15  {
16  int days = 0;
17  switch (month) {
18  case 01: case 3: case 5: case 7: case 8: case 10: case 12:
19  days = 31;
20  break;
21  case 4: case 6: case 9: case 11:
22  days = 30;
23  break;
24  case 2:
25  if(year%4==0)
26  days = 29;
27  else
28  days = 28;
29  default:
30  break;
31  }
32  return days;
33 }
void getTime ( )

getTime this function has the side-effect of printing the current time to the terminal.

No parameters are required.

Definition at line 490 of file comm_list.c.

References get_time(), serial_print(), and sprintf().

Referenced by setTime(), and time().

490  {
491  int hour=0, minutes=0, seconds=0;
492  get_time(&hour, &minutes, &seconds);
493 
494  char buf[500]; \
495  sprintf(buf, 500, "\033[38;2;255;0;255mThe current time is %d:%d.%d UTC\r\n\033[38;2;255;255;255m", hour, minutes, seconds); \
496  serial_print(buf);
497  //printf("\033[38;2;255;0;255mThe current time is %d:%d.%d UTC\r\n\033[38;2;255;255;255m", hour, minutes, seconds);
498 }
int serial_print(const char *msg)
Definition: serial.c:59
void get_time(int *hours, int *minutes, int *seconds)
get_time this function will retrieve the system time and place it in three pointers. Military time
Definition: rtc.c:10
int sprintf(char *str, int bufLength, const char *format,...) __attribute__((format(printf
sprintf print with format to specified string buffer
void help ( )

help prints out a list of all possible commands and a brief description of what they do.

Definition at line 72 of file comm_list.c.

References BG_BLUE, BG_GREEN, BG_MAGENTA, BG_ORANGE, BG_RED, BG_WHITE, BG_YELLOW, COLOR_BLACK, COLOR_RED_DARK, COLOR_STOP, COLOR_WHITE, printf, and serial_println().

Referenced by helpFunc().

72  {
73 
74  printf("%s%sUNIX style commands%s\r\n",COLOR_BLACK, BG_WHITE, COLOR_STOP);
75  printf("%s%sCommand | what it does%s\r\n", COLOR_BLACK, BG_WHITE, COLOR_STOP);
76  printf("%s%s------- | -----------------------------------%s\r\n", COLOR_BLACK, BG_WHITE, COLOR_STOP);
77  printf("%s%sdate | Interact with the current system date%s\r\n",COLOR_BLACK, BG_RED, COLOR_STOP);
78  printf("%s%shelp | Shows the command options%s\r\n", COLOR_WHITE, BG_ORANGE, COLOR_STOP);
79  printf("%s%spcb | Work with the processes%s\r\n", COLOR_BLACK, BG_YELLOW, COLOR_STOP);
80  printf("%s%sshutdown | Shut down the system%s\r\n", COLOR_BLACK, BG_GREEN, COLOR_STOP);
81  printf("%s%stime | Interact with the current system time%s\r\n", COLOR_WHITE, BG_BLUE, COLOR_STOP);
82  printf("%s%sversion | Get the current version of the OS%s\r\n", COLOR_RED_DARK, BG_MAGENTA, COLOR_STOP);
83  printf("%s%sloadr3 | Loads all of the processes from procsr3%s\r\n",COLOR_BLACK, BG_RED, COLOR_STOP);
84  //serial_println("loadr3 | Loads all of the processes from procsr3");//,COLOR_BLACK, BG_RED, COLOR_STOP);
85  printf("%s%smcb | Work with MCB%s\r\n", COLOR_BLACK, BG_ORANGE, COLOR_STOP);
86 
87 
88  serial_println(" ");
89 
90 
91 }
#define BG_MAGENTA
Definition: input.h:30
#define COLOR_WHITE
Definition: input.h:39
#define BG_YELLOW
Definition: input.h:29
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
#define BG_BLUE
Definition: input.h:28
#define BG_RED
Definition: input.h:26
int serial_println(const char *msg)
Definition: serial.c:44
#define BG_GREEN
Definition: input.h:27
#define COLOR_STOP
Definition: input.h:47
#define BG_ORANGE
Definition: input.h:32
#define COLOR_BLACK
Definition: input.h:40
#define BG_WHITE
Definition: input.h:23
#define COLOR_RED_DARK
Definition: input.h:45
void helpBlockPCB ( )

helpBlockPCB prints out the parameters and usage for blocking a PCB.

Definition at line 407 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

407  {
408  serial_println("Removes the PCB from current queue and places it into the blocked queue.");
409  serial_println("Command: pcb --block");
410  serial_println("Arguments:");
411  serial_println("-n/--name 'name of the PCB'");
412  serial_println(" ");
413 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpCreatePCB ( )

helpCreatePCB prints out the parameters and usage for createPCB.

Definition at line 391 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

391  {
392  serial_println("Creates a new PCB and allocates memory.");
393  serial_println("Command: pcb --create");
394  serial_println("Arguments:");
395  serial_println("-n/--name 'the name of the PCB'\n-p/--priority 'priority from 0-9 of pcb'\n-c/--class 'System or User_app'");
396  serial_println(" ");
397 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpDate ( char  parameters[][MAX_LENGTH])

helpDate prints out the help information for date, for date –set and date –get

Parameters
parameterstakes in a char array

[0] can be –set or –get or empty –set tells the parameters and usage for setting the date –get tells the parameters and usage for getting the date

Definition at line 238 of file comm_list.c.

References serial_println(), strcmp(), and strlen().

Referenced by helpFunc().

239 {
240  if(!strlen(parameters[0]))
241  {
242  serial_println("Retireves or Sets the system date");
243  serial_println("Command: 'date'");
244  serial_println("\033[38;2;255;255;0mArguments available: \033[38;2;255;0;0m--set, --get\033[0m");
245  serial_println("Enter the command 'help date --get' or 'help date --set'");
246  }
247  else if(!strcmp(parameters[0], "--set"))
248  {
249  serial_println("Sets the system date");
250  serial_println("Command: 'date --set'");
251  serial_println("Usage: \033[38;2;255;255;0m 'date --set' \"DD/MM/YYYY\" \033[0m");
252  }
253  else if(!strcmp(parameters[0], "--get"))
254  {
255  serial_println("Gets the system date");
256  serial_println("Command: 'date --get'");
257  serial_println("Usage: \033[38;2;255;255;0m 'date --get' \033[0m");
258  }
259 }
int serial_println(const char *msg)
Definition: serial.c:44
int strlen(const char *s)
strlen returns the length of a string
Definition: string.c:10
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void helpDeletePCB ( )

helpDeletePCB prints out the parameters and usage for deleting a PCB.

Definition at line 399 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

399  {
400  serial_println("Delete the specified PCB and frees memory. Removes the PCB from any queues it is currently in.");
401  serial_println("Command: pcb --delete");
402  serial_println("Arguments:");
403  serial_println("-n/--name 'the name of the PCB'");
404  serial_println(" ");
405 }
int serial_println(const char *msg)
Definition: serial.c:44
int helpFunc ( char  parameters[][MAX_LENGTH])

helpFunc calls the other help functions

Parameters
parametersused to determine if just help or help set date was called
Returns
an integer.

Definition at line 49 of file comm_list.c.

References help(), helpDate(), helpGetVersion(), helpLoadR3(), helpMCB(), helpPcb(), helpShutdown(), helpTime(), IMPROPER_COMMAND, serial_println(), and strcmp().

Referenced by initCmdArray().

49  {
50  if(!strcmp(parameters[0],"") || !strcmp(parameters[0],"\0")) {
51  help();
52  } else if(strcmp(parameters[0],"shutdown")==0) {
53  helpShutdown();
54  } else if(strcmp(parameters[0],"version")==0) {
56  } else if(strcmp(parameters[0],"time")==0) {
57  helpTime(&parameters[1]);
58  } else if(strcmp(parameters[0],"date")==0) {
59  helpDate(&parameters[1]);
60  } else if(strcmp(parameters[0], "pcb")==0) {
61  helpPcb(&parameters[1]);
62  } else if(strcmp(parameters[0], "loadr3")==0) {
63  helpLoadR3();
64  } else if(strcmp(parameters[0], "mcb")==0) {
65  helpMCB(&parameters[1]);
66  } else {
68  }
69  return 0;
70 }
void helpMCB(char parameters[][MAX_LENGTH])
The command handler for mcb&#39;s checking for valid input.
Definition: comm_list.c:93
void helpTime(char parameters[][MAX_LENGTH])
helpTime prints out the help information for time, for time –set and time –get
Definition: comm_list.c:261
void help()
help prints out a list of all possible commands and a brief description of what they do...
Definition: comm_list.c:72
void helpLoadR3()
helpLoadR3 prints out the help commands for helpLoadR3 Loads all of the processes from procsr3 ...
Definition: comm_list.c:174
int serial_println(const char *msg)
Definition: serial.c:44
void helpPcb(char parameters[][MAX_LENGTH])
helpPcb takes in the command to print the help information for. Calls the proper function to print th...
Definition: comm_list.c:284
void helpShutdown()
helpShutdown prints the help instructions for set date. Tells the user what the command and arguments...
Definition: comm_list.c:222
#define IMPROPER_COMMAND
Definition: comm_vars.h:2
void helpDate(char parameters[][MAX_LENGTH])
helpDate prints out the help information for date, for date –set and date –get
Definition: comm_list.c:238
int helpGetVersion()
helpGetVersion prints the help instructions for version. Tells the user what the command and argument...
Definition: comm_list.c:181
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void helpGetDate ( )

helpGetDate prints the help instructions for get date. Tells the user what the command and arguments for 'get date' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 190 of file comm_list.c.

References serial_println().

190  {
191  serial_println("Get the current date.");
192  serial_println("Command: 'get date'");
193  serial_println("There are no arguments required.");
194  serial_println(" ");
195 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpGetTime ( )

helpGetTime prints the help instructions for get time. Tells the user what the commands and arguments for 'get time' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 206 of file comm_list.c.

References serial_println().

206  {
207  serial_println("Get the current time in UTC.");
208  serial_println("Command: 'get time'");
209  serial_println("There are no arguments required.");
210  serial_println(" ");
211 }
int serial_println(const char *msg)
Definition: serial.c:44
int helpGetVersion ( )

helpGetVersion prints the help instructions for version. Tells the user what the command and arguments for 'version' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 181 of file comm_list.c.

References COLOR_RED, COLOR_STOP, COLOR_YELLOW, and printf.

Referenced by helpFunc().

181  {
182  printf("%sGet the current version of the operating system%s\r\n",COLOR_RED, COLOR_STOP);
183  printf("Command: '%sversion%s'\r\n",COLOR_YELLOW,COLOR_STOP);
184  printf("%sThere are no arguments required.\r\n","");
185  printf("%sThis will return R1, R2,... showing the current module.\r\n","");
186  printf("%s\r\n","");
187  return 0;
188 }
#define COLOR_YELLOW
Definition: input.h:38
#define COLOR_RED
Definition: input.h:35
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
#define COLOR_STOP
Definition: input.h:47
void helpLoadR3 ( )

helpLoadR3 prints out the help commands for helpLoadR3 Loads all of the processes from procsr3

Definition at line 174 of file comm_list.c.

References serial_println().

Referenced by helpFunc().

174  {
175  serial_println("Loads all of the processes from procsr3.");
176  serial_println("Command: 'loadr3'");
177  serial_println("No arguments required.");
178  serial_println("\r\n");
179 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCB ( char  parameters[][MAX_LENGTH])

The command handler for mcb's checking for valid input.

Parameters
Validcommands for each function

Definition at line 93 of file comm_list.c.

References helpMcbPrint(), helpMCBShowAllocated(), helpMCBShowFree(), isEmpty(), serial_println(), and strcmp().

Referenced by helpFunc().

93  {
94 
95  if(isEmpty(&parameters[0])) {
96  helpMcbPrint();
97  } /*else if(!strcmp(parameters[0],"--initheap")) {
98  helpMCBInitHeap();
99  } else if(!strcmp(parameters[0],"--allocate")) {
100  helpMCBAllocate();
101  } else if(!strcmp(parameters[0], "--freemem")) {
102  helpMCBFreeMem();
103  } else if(!strcmp(parameters[0], "--isempty")) {
104  helpMCBIsEmpty();
105  }*/ else if(!strcmp(parameters[0], "--showfree")) {
106  helpMCBShowFree();
107  } else if(!strcmp(parameters[0], "--showallocated")) {
109  } else {
110  serial_println("Invalid parameter, run 'help mcb' to see the valid parameters.");
111  }
112 
113 
114 }
void helpMcbPrint()
Prints the help menu for all mcb functions.
Definition: comm_list.c:116
int isEmpty(char parameters[][MAX_LENGTH])
Definition: comm_list.c:35
void helpMCBShowAllocated()
Prints details for showing all the allocated memory blocks in the heap.
Definition: comm_list.c:166
int serial_println(const char *msg)
Definition: serial.c:44
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void helpMCBShowFree()
Prints details for showing all the free memory blocks in the heap.
Definition: comm_list.c:159
void helpMCBAllocate ( )

Prints the details for Allocating an mcb.

Parameters
Typehelp –allocate

Definition at line 136 of file comm_list.c.

References serial_println().

136  {
137  serial_println("Allocate memory from heap. Amount of bytes to be allocated from the heap.");
138  serial_println("Command: 'mcb --allocate'");
139  serial_println("Arguments:");
140  serial_println("-s/--size 'size of the memory (integer value)'");
141  serial_println("\r\n");
142 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCBFreeMem ( )

Prints the details for freeing an mcb.

Parameters
Typehelp –freemem

Definition at line 144 of file comm_list.c.

References serial_println().

144  {
145  serial_println("Free a particular block of memory that was previously allocated. Takes in the pointer to an address in memory");
146  serial_println("Command: 'mcb --freemem'");
147  serial_println("Arguments:");
148  serial_println("-p/--pointer 'pointer to an address'");
149  serial_println("\r\n");
150 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCBInitHeap ( )

prints the all details about the initheap func

Parameters
Typehelp –initHeap

Definition at line 128 of file comm_list.c.

References serial_println().

128  {
129  serial_println("Allocate memory for MPX. Size of the heap in bytes.");
130  serial_println("Command: 'mcb --initheap'");
131  serial_println("Arguments:");
132  serial_println("-s/--size 'size of the memory (integer value)'");
133  serial_println("\r\n");
134 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCBIsEmpty ( )

Prints details for IsEmpty func.

Parameters
Typehelp –isempty

Definition at line 152 of file comm_list.c.

References serial_println().

152  {
153  serial_println("Returns true or false based on whether the heap is empty.");
154  serial_println("Command: 'mcb --isempty'");
155  serial_println("No arguments required.");
156  serial_println("\r\n");
157 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMcbPrint ( )

Prints the help menu for all mcb functions.

Parameters
Typehelp mcb

Definition at line 116 of file comm_list.c.

References serial_println().

Referenced by helpMCB().

116  {
117  serial_println("MCB commands\r\n");
118  serial_println("Use 'mcb [command]'");
119  serial_println(" Command | what it does");
120  serial_println("______________ | _________________________________");
121  serial_println("--showfree | Shows all free memory in heap");
122  serial_println("--showallocated | Shows all allocated memory");
123 
124  serial_println("Type 'help [command]' to see what the command does and arguments it requires.");
125  serial_println(" ");
126 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCBShowAllocated ( )

Prints details for showing all the allocated memory blocks in the heap.

Parameters
Typehelp –showallocated

Definition at line 166 of file comm_list.c.

References serial_println().

Referenced by helpMCB().

166  {
167  serial_println("Show the address and size of the blocks in the allocated list.");
168  serial_println("Command: 'mcb --showallocated'");
169  serial_println("No arguments required.");
170  serial_println("\r\n");
171 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpMCBShowFree ( )

Prints details for showing all the free memory blocks in the heap.

Parameters
Typehelp –showfree

Definition at line 159 of file comm_list.c.

References serial_println().

Referenced by helpMCB().

159  {
160  serial_println("Show the address and size of the blocks in the free list.");
161  serial_println("Command: 'mcb --showfree'");
162  serial_println("No arguments required.");
163  serial_println("\r\n");
164 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpPcb ( char  parameters[][MAX_LENGTH])

helpPcb takes in the command to print the help information for. Calls the proper function to print the help information for the selected command.

Parameters
parameterstakes in a character array

Definition at line 284 of file comm_list.c.

References helpBlockPCB(), helpCreatePCB(), helpDeletePCB(), helpPcbPrint(), helpResumePCB(), helpSetPriority(), helpShowAllProcesses(), helpShowBlockedProcesses(), helpShowPCB(), helpShowReadyProcesses(), helpSuspendPCB(), helpUnblockPCB(), isEmpty(), serial_println(), and strcmp().

Referenced by helpFunc().

284  {
285  if(isEmpty(&parameters[0])) {
286  helpPcbPrint();
287  } else if(!strcmp(parameters[0],"--block")) {
288  helpBlockPCB();
289  } else if(!strcmp(parameters[0],"--create")) {
290  helpCreatePCB();
291  } else if(!strcmp(parameters[0], "--delete")) {
292  helpDeletePCB();
293  } else if(!strcmp(parameters[0], "--resume")) {
294  helpResumePCB();
295  } else if(!strcmp(parameters[0], "--setpriority")) {
296  helpSetPriority();
297  } else if(!strcmp(parameters[0], "--show")) {
298  helpShowPCB();
299  } else if(!strcmp(parameters[0],"--showall")) {
301  } else if(!strcmp(parameters[0], "--showblocked")) {
303  } else if(!strcmp(parameters[0], "--showready")) {
305  } else if(!strcmp(parameters[0], "--suspend")) {
306  helpSuspendPCB();
307  } else if(!strcmp(parameters[0],"--unblock")) {
308  helpUnblockPCB();
309  } else {
310  serial_println("Invalid parameter, run 'help pcb' to see the valid parameters.");
311  }
312 }
void helpResumePCB()
helpResumePCB prints out the parameters and usage of the resume pcb command.
Definition: comm_list.c:343
void helpSuspendPCB()
helpSuspendPCB prints the help instructions for the suspendPCB command.
Definition: comm_list.c:335
void helpUnblockPCB()
helpUnblockPCB prints out the parameters and usage for unblocking a PCB.
Definition: comm_list.c:415
void helpBlockPCB()
helpBlockPCB prints out the parameters and usage for blocking a PCB.
Definition: comm_list.c:407
void helpSetPriority()
helpSetPriority prints out to console the parameters and usage for –setpriority. ...
Definition: comm_list.c:351
void helpShowReadyProcesses()
helpShowReadyProcesses shows the parameters and usage for showing ready PCBs.
Definition: comm_list.c:375
int isEmpty(char parameters[][MAX_LENGTH])
Definition: comm_list.c:35
void helpCreatePCB()
helpCreatePCB prints out the parameters and usage for createPCB.
Definition: comm_list.c:391
void helpPcbPrint()
helpPcbPrint prints out the commands for PCBs.
Definition: comm_list.c:314
int serial_println(const char *msg)
Definition: serial.c:44
void helpShowAllProcesses()
helpShowAllProcesses shows all processes in the system. Takes in no parameters and prints out to the ...
Definition: comm_list.c:367
void helpDeletePCB()
helpDeletePCB prints out the parameters and usage for deleting a PCB.
Definition: comm_list.c:399
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void helpShowPCB()
Definition: comm_list.c:359
void helpShowBlockedProcesses()
helpShowBlockedProcesses shows the parameters and usage for showing the blocked PCBs.
Definition: comm_list.c:383
void helpPcbPrint ( )

helpPcbPrint prints out the commands for PCBs.

Definition at line 314 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

314  {
315  serial_println("PCB commands\r\n");
316  serial_println("Use 'pcb [command]'");
317  serial_println(" Command | what it does");
318  serial_println("____________ | _________________________________");
319  serial_println("--block | Sends the PCB to the blocked queue");
320  serial_println("--create | Creates a new PCB and allocates memory");
321  serial_println("--delete | Delete specified PCB and frees memory");
322  serial_println("--resume | Resume the specified PCB");
323  serial_println("--setpriority | Set/change the priority of the specified PCB");
324  serial_println("--show | Show the specified PCB");
325  serial_println("--showall | Show all of the PCBs");
326  serial_println("--showblocked | Show the PCBs in the blocked queue");
327  serial_println("--showready | Show the PCBs in the ready queue");
328  serial_println("--suspend | Suspends the specified PCB");
329  serial_println("--unblock | Moves the specified PCB from the blocked state to ready queue");
330  serial_println(" ");
331  serial_println("Type 'help [command]' to see what the command does and arguments it requires.");
332  serial_println(" ");
333 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpResumePCB ( )

helpResumePCB prints out the parameters and usage of the resume pcb command.

Definition at line 343 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

343  {
344  serial_println("Resume the specified PCB. Removes PCB from suspended queue and places it into the appropriate queue.");
345  serial_println("Command: pcb --resume");
346  serial_println("Arguments:");
347  serial_println("-n/--name 'name of the PCB'");
348  serial_println(" ");
349 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpSetDate ( )

helpSetDate prints the help instructions for set date. Tells the user what the command and arguments for 'set date' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 197 of file comm_list.c.

References serial_println().

197  {
198  serial_println("Set the current date");
199  serial_println("Command: 'set date --set \"DD/MM/YYYY\" ");
200  serial_println("Arguments:");
201  serial_println("--set \"MM/DD/YYYY\"");
202  serial_println("ex. 'set date --set \"03/12/2017\"'");
203  serial_println(" ");
204 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpSetPriority ( )

helpSetPriority prints out to console the parameters and usage for –setpriority.

Definition at line 351 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

351  {
352  serial_println("Set/change the priority of a particular PCB.");
353  serial_println("Command: pcb --setpriority");
354  serial_println("Arguments:");
355  serial_println("-n/--name 'name of PCB'\n-p/--priority 'priority from 0-9'");
356  serial_println(" ");
357 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpSetTime ( )

helpSetTime prints the help instructions for set time. Tells the user what the command and arguments for 'set time' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 213 of file comm_list.c.

References serial_println().

213  {
214  serial_println("Set the current time in UTC");
215  serial_println("Command: 'set time --set \"HH:MM.SS\"'");
216  serial_println("Arguments: ");
217  serial_println("--set \"HH:MM.SS\" using 24 hour");
218  serial_println("ex. 'set time --set[14:20.00]' to set the system time to 2:20.00 PM");
219  serial_println(" ");
220 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpShowAllProcesses ( )

helpShowAllProcesses shows all processes in the system. Takes in no parameters and prints out to the console.

Definition at line 367 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

367  {
368  serial_println("Show all of the processes in the system.");
369  serial_println("Command: pcb --showall");
370  serial_println("Arguments:");
371  serial_println("No arguments required.");
372  serial_println(" ");
373 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpShowBlockedProcesses ( )

helpShowBlockedProcesses shows the parameters and usage for showing the blocked PCBs.

Definition at line 383 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

383  {
384  serial_println("Show all of the processes that are in the blocked queue.");
385  serial_println("Command: pcb --showblocked");
386  serial_println("Arguments:");
387  serial_println("No arguments required.");
388  serial_println(" ");
389 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpShowPCB ( )

Definition at line 359 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

359  {
360  serial_println("Show the information for a particular PCB.");
361  serial_println("Command: pcb --show");
362  serial_println("Arguments:");
363  serial_println("-n/--name 'name of the PCB'");
364  serial_println(" ");
365 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpShowReadyProcesses ( )

helpShowReadyProcesses shows the parameters and usage for showing ready PCBs.

Definition at line 375 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

375  {
376  serial_println("Show all of the processes that are in the ready queue.");
377  serial_println("Command: pcb --showready");
378  serial_println("Arguments:");
379  serial_println("No arguments required.");
380  serial_println(" ");
381 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpShutdown ( )

helpShutdown prints the help instructions for set date. Tells the user what the command and arguments for 'set date' are.

No parameters are needed to be passed in, as it just prints to the console.

Definition at line 222 of file comm_list.c.

References serial_println().

Referenced by helpFunc().

222  {
223 
224  serial_println("Shut down the system.");
225  serial_println("Command: 'shutdown'");
226  serial_println("No arguments required.");
227  serial_println("You will be prompted to confirm that you want to shutdown.");
228  serial_println(" ");
229 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpSuspendPCB ( )

helpSuspendPCB prints the help instructions for the suspendPCB command.

Definition at line 335 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

335  {
336  serial_println("Suspend a particular PCB.");
337  serial_println("Command: pcb --suspend");
338  serial_println("Arguments:");
339  serial_println("-n/--name 'name of the pcb");
340  serial_println(" ");
341 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpTime ( char  parameters[][MAX_LENGTH])

helpTime prints out the help information for time, for time –set and time –get

Parameters
parameterstakes in a char array

[0] can be –set or –get or empty –set tells the parameters and usage for setting the time –get tells the parameters and usage for getting the time

Definition at line 261 of file comm_list.c.

References serial_println(), strcmp(), and strlen().

Referenced by helpFunc().

262 {
263  if(!strlen(parameters[0]))
264  {
265  serial_println("Retrieves or Sets the system time");
266  serial_println("Command: 'time'");
267  serial_println("\033[38;2;255;255;0mArguments available: \033[38;2;255;0;0m--set, --get\033[0m");
268  serial_println("Enter the command 'help time --get' or 'help time --set'");
269  }
270  else if(!strcmp(parameters[0], "--set"))
271  {
272  serial_println("Sets the system time");
273  serial_println("Command: 'time --set'");
274  serial_println("Usage: \033[38;2;255;255;0m 'time --set' \"HH:MM.SS\" \033[0m");
275  }
276  else if(!strcmp(parameters[0], "--get"))
277  {
278  serial_println("Gets the system date");
279  serial_println("Command: 'time --get'");
280  serial_println("Usage: \033[38;2;255;255;0m 'time --get' \033[0m");
281  }
282 }
int serial_println(const char *msg)
Definition: serial.c:44
int strlen(const char *s)
strlen returns the length of a string
Definition: string.c:10
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void helpUnblockPCB ( )

helpUnblockPCB prints out the parameters and usage for unblocking a PCB.

Definition at line 415 of file comm_list.c.

References serial_println().

Referenced by helpPcb().

415  {
416  serial_println("Removes the PCB from the blocked queue and places it into the ready queue.");
417  serial_println("Command: pcb --unblock");
418  serial_println("Arguments:");
419  serial_println("-n/--name 'name of the PCB'");
420  serial_println(" ");
421 }
int serial_println(const char *msg)
Definition: serial.c:44
void helpVersion ( )

helpVersion prints the help instructions for using the version command. No arguments are required.

Definition at line 231 of file comm_list.c.

References serial_println().

231  {
232  serial_println("Shows the version of the operating system.");
233  serial_println("Command: 'version'");
234  serial_println("No arguments required.");
235  serial_println("\r\n");
236 }
int serial_println(const char *msg)
Definition: serial.c:44
int isEmpty ( char  parameters[][MAX_LENGTH])

Definition at line 35 of file comm_list.c.

References strcmp().

Referenced by helpMCB(), helpPcb(), and pcbFunc().

35  {
36  int empty = 0;
37  if((!strcmp(parameters[0],"")) || (!strcmp(parameters[0],"\0"))) {
38  empty = 1;
39  }
40  return empty;
41 }
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
int mcbFunc ( char  parameters[][MAX_LENGTH])

takes in whatever you are looking for and checks to see if it can be done for mcb

Parameters
typeanthing into the command line prompt

Definition at line 904 of file comm_list.c.

References COLOR_RED, COLOR_STOP, COLOR_YELLOW, heapTest(), mcbAllocList, mcbFreeList, printf, printList(), and strcmp().

Referenced by initCmdArray().

904  {
905  /*if(!strcmp(parameters[0],"--allocate")) {
906  int returnError = (int)allocateMemFromHeap((size_t)atoi(parameters[2]));
907  if(returnError == 0 ) {
908  printf("%sNo blocks large enough%s\r\n",COLOR_RED,COLOR_STOP);
909  }
910  printf("%s", "Alloc list\r\n")
911  printList(&mcbAllocList);
912  printf("%s", "free list\r\n")
913  printList(&mcbFreeList);
914  }*/ /*else if(!strcmp(parameters[0],"--freemem")) {
915 
916  if(strcmp(parameters[2],"")) {
917  freeHeapMem((void*)atoi(parameters[2]));
918  printf("Result: %s\r\n",mcbResultToString(lastMCBError));
919  } else {
920  serial_println("Enter a valid address to free");
921  }
922  }*/ /*else if(!strcmp(parameters[0],"--initheap")) {
923  initHeap((size_t)atoi(parameters[2]));
924  serial_println("Heap initialized");
925  } else *//*if(!strcmp(parameters[0],"--isempty")) {
926  if(heapIsEmpty()) {
927  printf("%sHeap is not empty%s\r\n",BG_ORANGE, COLOR_STOP);
928  } else {
929  printf("%s%sHeap is empty%s\r\n",COLOR_BLUE,BG_GREEN, COLOR_STOP);
930  }
931  } else*/ if(!strcmp(parameters[0],"--showfree")) {
932  printf("%s", "free list\r\n")
934  } else if(!strcmp(parameters[0],"--showallocated")) {
935  printf("%s", "Alloc list\r\n")
937  } else if(!strcmp(parameters[0],"--showall")) {
938  printf("%s", "Free list\r\n")
939  printList(&mcbFreeList);
940  printf("%s", "Alloc list\r\n")
941  printList(&mcbAllocList);
942  } else if(!strcmp(parameters[0],"--testheap")) {
943  heapTest();
944  } else {
945  printf("Here are some possible commands: %s--showfree %s--showallocated%s\r\n", COLOR_RED, COLOR_YELLOW, COLOR_STOP);
946  }
947 
948  return 0;
949 }
#define COLOR_YELLOW
Definition: input.h:38
linkedList_t mcbAllocList
Definition: mcb.c:6
linkedList_t mcbFreeList
Definition: mcb.c:5
#define COLOR_RED
Definition: input.h:35
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
void heapTest()
heapTest test function to create sample mcbs.
Definition: mcb.c:286
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
#define COLOR_STOP
Definition: input.h:47
int pcbFunc ( char  parameters[][MAX_LENGTH])

takes in parameters and makes sure its valid then runs what you want to.

Parameters
Typeanything in command line, valid inputs work.

Definition at line 558 of file comm_list.c.

References blockPCB(), createPCB(), deletePCB(), EXTRA_PARAMETERS, isEmpty(), printf, procName, resumePCB(), serial_print(), serial_println(), setPriority(), showAllProcesses(), showBlockedProcesses(), showPCB(), showReadyProcesses(), strcmp(), suspendPCB(), and unblockPCB().

Referenced by initCmdArray().

558  {
559  if(!strcmp(parameters[0],"--suspend")) {
560  if(isEmpty(&parameters[1])) {
561  serial_println("Missing name of PCB to suspend.");
562  } else {
563  if(!isEmpty(&parameters[2]) &&
564  (!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name"))) {
565  suspendPCB(&parameters[2]);
566  } else {
567  suspendPCB((&parameters[2]));
569  serial_print(parameters[3]);
570  serial_print("\r\n");
571  }
572  }
573  } else if(!strcmp(parameters[0],"--resume")) {
574  if(isEmpty(&parameters[1])) {
575  serial_println("Missing name of PCB to suspend.");
576  } else {
577  if(!isEmpty(&parameters[2]) &&
578  (!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name"))) {
579  resumePCB(&parameters[2]);
580  } else {
581  resumePCB((&parameters[2]));
583  serial_print(parameters[3]);
584  serial_print("\r\n"); }
585  }
586 
587  } else if(!strcmp(parameters[0],"--setpriority")) {
588  if(isEmpty(&parameters[4])) {
589  serial_println("Missing parameters.");
590  } else {
591  if((!strcmp(parameters[1],"--name") || !strcmp(parameters[1],"-n")) && (!strcmp(parameters[3],"--priority") || !strcmp(parameters[3],"-p"))) {
592  setPriority(parameters[2], parameters[4]);
593  } else if((!strcmp(parameters[3],"--name") || !strcmp(parameters[3],"-n")) && (!strcmp(parameters[1],"--priority") || !strcmp(parameters[1],"-p"))) {
594  setPriority(parameters[4], parameters[2]);
595  } else {
596  printf("%sProper command: 'pcb --setpriority -n \"pcb name\" -p \"pcb priority\"","");
597  }
598  }
599  } else if(!strcmp(parameters[0],"--show")) {
600  if(isEmpty(&parameters[2])) {
601  printf("Missing name of pcb to show%s.\n","");
602  } else {
603  if(!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name")) {
604  showPCB(&parameters[2]);
605  } else {
606  printf("Type 'help pcb --show' to see the arguments required.%s\n","");
607  }
608  }
609  } else if(!strcmp(parameters[0],"--showall")) {
610  if(isEmpty(&parameters[1])) {
611  showAllProcesses(&parameters[0]);
612 
613  } else {
614  printf("No arguments required%s\n","");
615  showAllProcesses(&parameters[0]);
616  }
617  } else if(!strcmp(parameters[0],"--showready")) {
618  if(isEmpty(&parameters[1])) {
619  showReadyProcesses(&parameters[0]);
620 
621  } else {
622  printf("No arguments required%s\n","");
623  showReadyProcesses(&parameters[0]);
624  }
625  } else if(!strcmp(parameters[0],"--showblocked")) {
626  if(isEmpty(&parameters[1])) {
627  showBlockedProcesses(&parameters[0]);
628 
629  } else {
630  printf("No arguments required%s\n","");
631  showBlockedProcesses(&parameters[0]);
632  }
633  } else if(!strcmp(parameters[0],"--create")) {
634  if(isEmpty(&parameters[6])) {
635  printf("Missing parameters of pcb to create%s.\n","");
636  } else {
637  char * procName; char * procPrio; char * procClass;
638  int i = 0;
639  for(;!isEmpty(&parameters[i]); i++) {
640  if(!strcmp(parameters[i], "--name") || !strcmp(parameters[i],"-n")) {
641  i++;
642  procName = parameters[i];
643  } else if(!strcmp(parameters[i], "--priority") || !strcmp(parameters[i],"-p")) {
644  i++;
645  procPrio = parameters[i];
646  } else if(!strcmp(parameters[i], "--class") || !strcmp(parameters[i],"-c")) {
647  i++;
648  procClass = parameters[i];
649  }
650  }
651 
652  createPCB(procName, procPrio, procClass);
653  }
654  } else if(!strcmp(parameters[0],"--delete")) {
655  if(isEmpty(&parameters[2])) {
656  printf("Missing name of pcb to create%s.\n","");
657  } else {
658  if(!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name")) {
659  deletePCB(&parameters[2]);
660  } else {
661  printf("Type 'help pcb --delete' to see the arguments required.%s\n","");
662  }
663  }
664  } else if(!strcmp(parameters[0],"--block")) {
665  if(isEmpty(&parameters[2])) {
666  printf("Missing name of pcb to create%s.\n","");
667  } else {
668  if(!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name")) {
669  blockPCB(&parameters[2]);
670  } else {
671  printf("Type 'help pcb --block' to see the arguments required.%s\n","");
672  }
673  }
674  } else if(!strcmp(parameters[0],"--unblock")) {
675  if(isEmpty(&parameters[2])) {
676  printf("Missing name of pcb to create%s.\n","");
677  } else {
678  if(!strcmp(parameters[1],"-n") || !strcmp(parameters[1],"--name")) {
679  unblockPCB(&parameters[2]);
680  } else {
681  printf("Type 'help pcb --unblock' to see the arguments required.%s\n","");
682  }
683  }
684  }
685  return 0;
686 }
int deletePCB(char parameters[][MAX_LENGTH])
deletePCB deletes the PCB requested by the user.
Definition: comm_list.c:782
const char * procName
Definition: mcb.h:43
int createPCB(const char *pcbName, const char *pcbPriority, const char *pcbClass)
createPCB creates a new PCB and allocates memory for the PCB.
Definition: comm_list.c:773
int blockPCB(char parameters[][MAX_LENGTH])
blockPCB blocks the specified PCB
Definition: comm_list.c:794
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int serial_print(const char *msg)
Definition: serial.c:59
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
Definition: comm_list.c:737
int isEmpty(char parameters[][MAX_LENGTH])
Definition: comm_list.c:35
int suspendPCB(char parameters[][MAX_LENGTH])
suspendPCB suspends the pcb passed in by the user
Definition: comm_list.c:688
int resumePCB(char parameters[][MAX_LENGTH])
resumePCB resumes the PCB passed in by the user
Definition: comm_list.c:709
int serial_println(const char *msg)
Definition: serial.c:44
int showReadyProcesses(char parameters[][MAX_LENGTH])
showReadyProcesses shows all processes that are ready, in the ready queue (linked list)...
Definition: comm_list.c:759
int showBlockedProcesses(char parameters[][MAX_LENGTH])
showBlockedProcesses shows all processes that are blocked.
Definition: comm_list.c:766
int showAllProcesses(char parameters[][MAX_LENGTH])
showAllProcesses shows all processes in the system.
Definition: comm_list.c:746
int unblockPCB(char parameters[][MAX_LENGTH])
unblockPCB unblocks the specified PCB.
Definition: comm_list.c:807
int setPriority(char *procName, char *procPrio)
setPriority sets the priority of a particular process
Definition: comm_list.c:730
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
#define EXTRA_PARAMETERS
Definition: comm_vars.h:4
int resumePCB ( char  parameters[][MAX_LENGTH])

resumePCB resumes the PCB passed in by the user

Parameters
parameters- the rest of the input from the user, the name of the PCB to be resumed.
Returns
an integer, normally 0.

Definition at line 709 of file comm_list.c.

References changeProcessSuspensionState(), errorToString(), NOT_SUSPENDED, printf, showPCB(), and SUCCESS.

Referenced by pcbFunc().

709  {
710 
711  e_PCB_ERROR_CODE_t retVal = changeProcessSuspensionState((const char*)parameters[0], NOT_SUSPENDED);
712  if(retVal == SUCCESS)
713  {
714  showPCB(parameters);
715  }
716  printf("Status: %s\r\n", errorToString(retVal));
717  return retVal;
718 
719 // const char* name = (const char*)parameters[0];
720 // pcb_t* process = findPCB(name);
721 // e_PROCESS_STATE_t state = process->processState;
722 // if (state == READY)
723 // {
724 // changeProcessState(name, RUNNING);
725 // }
726 // else printf("%s", "\nThe process must be in the ready state to resume.\n");
727 // return 0;
728 }
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
Definition: comm_list.c:737
Definition: pcb.h:38
e_PCB_ERROR_CODE_t changeProcessSuspensionState(const char *processName, e_PROCESS_SUSPENSION_STATE_t suspensionState)
changeProcessSuspensionState
Definition: pcb.c:190
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
Definition: pcb.h:38
void setDate ( char  parameters[][MAX_LENGTH])

setDate sets the system date using the input from the user.

Parameters
parameterstake the unconsumed parameters from commhandler from the command prompt.

Checks if the parameters exist, otherwise will return improper command. If paramters exist, will check to make sure the parameters are correct, such that the days and months are valid.

Calls set_date from rtc to set the current date. After setting the date, will print the current date.

Ex. Command is "date –set '03/12/2017', 03, 12 , 2017 are passed over. parameters[0] is the day parameters[1] is the month parameters[2] is the year

Definition at line 453 of file comm_list.c.

References atoi(), getDate(), getNumDaysInMonth(), IMPROPER_COMMAND, printf, serial_println(), set_date(), and strlen().

Referenced by date().

453  {
454  //printf("day %d %s, month %d %s, year %d %s\r\n", atoi(parameters[0]), parameters[0], atoi(parameters[1]), parameters[1], atoi(parameters[2]), parameters[2]);
455  if(!strlen(parameters[2]) || !atoi(parameters[0]) || !atoi(parameters[1]) || !atoi(parameters[2]))
456  {
458  serial_println("\r\nInvalid Parameters");
459  }
460  else
461  {
462  int daysInMonth = getNumDaysInMonth(atoi(parameters[1]), atoi(parameters[2]));
463  if((atoi(parameters[0]) > 0) && (daysInMonth >= atoi(parameters[0]))){
464  set_date(atoi(parameters[0]), atoi(parameters[1]), atoi(parameters[2]));
465  } else {
466  serial_println("Double check the input parameters");
467  printf("\033[38;2;255;0;255mTotal days in your selected month are: %d UTC\r\n\033[38;2;255;255;255m", daysInMonth);
468  serial_println("\r\n");
469  }
470  }
471  getDate();
472 }
int getNumDaysInMonth(int month, int year)
getNumDaysInMonth is a helper function to allow the easy retrieval of days in a month based on the mo...
Definition: comm_list.c:15
void getDate()
getDate Get the current date from the system.
Definition: comm_list.c:447
void set_date(int day, int month, int year)
set_date sets the RTC Date
Definition: rtc.c:79
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int serial_println(const char *msg)
Definition: serial.c:44
int strlen(const char *s)
strlen returns the length of a string
Definition: string.c:10
int atoi(const char *s)
atoi converts and ASCII string to an integer
Definition: string.c:46
#define IMPROPER_COMMAND
Definition: comm_vars.h:2
int setPriority ( char *  procName,
char *  procPrio 
)

setPriority sets the priority of a particular process

Parameters
procNameis the process name to be modified
procPriois the new priority of the PCB
Returns
an integer, normally 0 procPrio is the process procName is the priority

Definition at line 730 of file comm_list.c.

References atoi(), changeProcessPriority(), errorToString(), findPCB(), printf, and printPCBFunc().

Referenced by pcbFunc().

730  {
731  //serial_println("PRINTING OUT");
732  printf("Status: %s\r\n", errorToString(changeProcessPriority(procName, atoi(procPrio))));
733  printPCBFunc((void*)findPCB(procName));
734  return 0;
735 }
void printPCBFunc(void *pcb)
printPCBFunc prints the status of a process
Definition: pcb.c:335
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
const char * procName
Definition: mcb.h:43
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
e_PCB_ERROR_CODE_t changeProcessPriority(const char *procName, processPriority_t newPriority)
changeProcessPriority
Definition: pcb.c:342
int atoi(const char *s)
atoi converts and ASCII string to an integer
Definition: string.c:46
void setTime ( char  parameters[][MAX_LENGTH])

setTime sets the current system time from the users input.

Parameters
parameterstake the unconsumed parameters from commhandler from the command prompt.

Calls set_time from rtc to set the sytem time. Then prints out the current time.

Ex. Command is "time –set '14:20.55', 14, 20 , 55 are passed over. parameters[1] is the hour (24 hour) parameters[2] is the minute parameters[3] is the second

Definition at line 500 of file comm_list.c.

References atoi(), getTime(), IMPROPER_COMMAND, serial_println(), set_time(), and strlen().

Referenced by time().

500  {
501  if(!strlen(parameters[2]) || !atoi(parameters[0]) || !atoi(parameters[1]) || !atoi(parameters[2]))
502  {
504  serial_println("\r\nInvalid Parameters");
505  }
506  else
507  {
508  if(atoi(parameters[0]) < 0 || atoi(parameters[0]) > 24 || atoi(parameters[1]) < 0 || atoi(parameters[1]) > 59 || atoi(parameters[2]) < 0 || atoi(parameters[2]) > 59) {
509  serial_println("Double check the input parameters");
510  serial_println("Make sure 0 HH 24 and 0 MM 59 and 0 SS 59");
511  serial_println("\r\n");
512  } else {
513  set_time(atoi(parameters[0]), atoi(parameters[1]), atoi(parameters[2]));
514  }
515  }
516  getTime();
517 }
void set_time(int hours, int minutes, int seconds)
set_time sets the RTC time. Military time
Definition: rtc.c:33
void getTime()
getTime this function has the side-effect of printing the current time to the terminal.
Definition: comm_list.c:490
int serial_println(const char *msg)
Definition: serial.c:44
int strlen(const char *s)
strlen returns the length of a string
Definition: string.c:10
int atoi(const char *s)
atoi converts and ASCII string to an integer
Definition: string.c:46
#define IMPROPER_COMMAND
Definition: comm_vars.h:2
int showAllProcesses ( char  parameters[][MAX_LENGTH])

showAllProcesses shows all processes in the system.

Definition at line 746 of file comm_list.c.

References blockedQueue, printf, printList(), readyQueue, suspendedBlockedQueue, and suspendedReadyQueue.

Referenced by pcbFunc().

746  {
747  (void)parameters;
748  printf("\n\nReady Queue:%s","\r\n");
750  printf("\n\nBlocked Queue:%s","\r\n");
752  printf("\n\nSuspended-Ready Queue:%s","\r\n");
754  printf("\n\nSuspended-Blocked Queue:%s","\r\n");
756  return 0;
757 }
linkedList_t readyQueue
Definition: pcb.c:3
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
linkedList_t blockedQueue
Definition: pcb.c:4
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
linkedList_t suspendedBlockedQueue
Definition: pcb.c:6
linkedList_t suspendedReadyQueue
Definition: pcb.c:5
int showBlockedProcesses ( char  parameters[][MAX_LENGTH])

showBlockedProcesses shows all processes that are blocked.

Returns
an integer, normally 0.

Definition at line 766 of file comm_list.c.

References blockedQueue, printf, and printList().

Referenced by pcbFunc().

766  {
767  (void)parameters;
768  printf("%s", "\n\nBlocked Queue:\n");
770  return 0;
771 }
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
linkedList_t blockedQueue
Definition: pcb.c:4
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
int showPCB ( char  parameters[][MAX_LENGTH])

showPCB shows the process information for the process requested by the user

Parameters
parametersthe name of the PCB to show the information of.

Definition at line 737 of file comm_list.c.

References errorToString(), findPCB(), prevPCBError, printf, and printPCBFunc().

Referenced by blockPCB(), pcbFunc(), resumePCB(), suspendPCB(), and unblockPCB().

737  {
738  pcb_t* process = findPCB((const char*)parameters[0]);
739  if(!process) { printf("Status: %s\r\n", errorToString(prevPCBError)); return prevPCBError; }
740 
741  printPCBFunc((void*)process);
742 
743  return prevPCBError;
744 }
e_PCB_ERROR_CODE_t prevPCBError
Definition: pcb.c:13
void printPCBFunc(void *pcb)
printPCBFunc prints the status of a process
Definition: pcb.c:335
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
pcb_t * findPCB(const char *processName)
findPCB will search all queues for the PCB with the input name
Definition: pcb.c:100
typedef for pcb_t struct
int showReadyProcesses ( char  parameters[][MAX_LENGTH])

showReadyProcesses shows all processes that are ready, in the ready queue (linked list).

Definition at line 759 of file comm_list.c.

References printf, printList(), and readyQueue.

Referenced by pcbFunc().

759  {
760  (void)parameters;
761  printf("%s", "\n\nReady Queue:\n");
763  return 0;
764 }
linkedList_t readyQueue
Definition: pcb.c:3
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
void printList(linkedList_t *list)
test function to show list functionality. uses const char* as test data
Definition: linked_list.c:212
int shutdownFunc ( char  parameters[][MAX_LENGTH])

shutdownFunc shuts down the OS.

Parameters
parametersthe input from the user
Returns
an integer, if the user confirms to shutdown will return 9, otherwise will return 0.

Definition at line 521 of file comm_list.c.

References EXIT, in_string, MAX_LENGTH, serial_poll(), serial_print(), serial_println(), sprintf(), strcmp(), and sys_req().

Referenced by initCmdArray().

521  {
522  int retVal = 0;
523 
524 
525  char buf[500]; \
526  sprintf(buf, 500, "\033[38;2;255;0;255mShutdown called\r\n\033[38;2;255;255;255m"); \
527 
528  serial_println("Shutdown was called.\r\n");
529 
530  if(strcmp(parameters[1],"")==0) {
531  int confirm = 0;
532  char in_string[MAX_LENGTH];
533  serial_print("Confirm shutdown y/n?: ");
534 
535  if(confirm == 0) {
536  serial_print("");
537  serial_poll(in_string);
538  if(strcmp(in_string, "y")==0)
539  {
540  confirm = 1;
541  serial_println("");
542  sys_req(EXIT);
543  }
544  else if (strcmp(in_string, "n")==0)
545  confirm = 2;
546  }
547  serial_println(" ");
548  if(confirm == 1)
549  retVal = 9;
550  } else {
551  serial_println("UNKNOWN_COMMAND");
552  }
553  return retVal;
554 }
int sys_req(int op_code)
Definition: mpx_supt.c:11
#define MAX_LENGTH
Definition: input.h:6
int serial_print(const char *msg)
Definition: serial.c:59
#define EXIT
Definition: mpx_supt.h:6
char in_string[MAX_LENGTH]
Definition: commhand.c:10
int serial_println(const char *msg)
Definition: serial.c:44
char * serial_poll(char in_string[MAX_LENGTH])
Definition: serial.c:114
int sprintf(char *str, int bufLength, const char *format,...) __attribute__((format(printf
sprintf print with format to specified string buffer
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
int suspendPCB ( char  parameters[][MAX_LENGTH])

suspendPCB suspends the pcb passed in by the user

Parameters
parameterstakes in the name of the PCB to be suspended.
Returns
an integer, normally 0.

Definition at line 688 of file comm_list.c.

References changeProcessSuspensionState(), errorToString(), printf, showPCB(), SUCCESS, and SUSPENDED.

Referenced by pcbFunc().

688  {
689 
690  e_PCB_ERROR_CODE_t retVal = changeProcessSuspensionState((const char*)parameters[0], SUSPENDED);
691  if(retVal == SUCCESS)
692  {
693  showPCB(parameters);
694  }
695  printf("Status: %s\r\n", errorToString(retVal));
696  return retVal;
697 
698 // const char* name = (const char*)parameters[0];
699 // pcb_t* process = findPCB(name);
700 // e_PROCESS_STATE_t state = process->processState;
701 // if (state == READY || state == RUNNING)
702 // {
703 // changeProcessState(name, BLOCKED);
704 // }
705 // else printf("%s", "\nThe process needs to either be in the ready or the running state to suspend.\n");
706 // return 0;
707 }
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
Definition: pcb.h:49
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
Definition: comm_list.c:737
Definition: pcb.h:38
e_PCB_ERROR_CODE_t changeProcessSuspensionState(const char *processName, e_PROCESS_SUSPENSION_STATE_t suspensionState)
changeProcessSuspensionState
Definition: pcb.c:190
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
Definition: pcb.h:38
int time ( char  parameters[][MAX_LENGTH])

Definition at line 479 of file comm_list.c.

References getTime(), serial_println(), setTime(), and strcmp().

Referenced by initCmdArray().

479  {
480  if(!strcmp(parameters[0],"--get")) {
481  getTime();
482  } else if(!strcmp(parameters[0],"--set")) {
483  setTime(&parameters[1]);
484  } else {
485  serial_println("ERROR HAS BEEN NOTICED");
486  }
487  return 0;
488 }
void getTime()
getTime this function has the side-effect of printing the current time to the terminal.
Definition: comm_list.c:490
int serial_println(const char *msg)
Definition: serial.c:44
int strcmp(const char *s1, const char *s2)
strcmp compares two strings.
Definition: string.c:77
void setTime(char parameters[][MAX_LENGTH])
setTime sets the current system time from the users input.
Definition: comm_list.c:500
int unblockPCB ( char  parameters[][MAX_LENGTH])

unblockPCB unblocks the specified PCB.

Parameters
parameterstakes in the name of the PCB to move from the blocked queue to the ready queue.

Definition at line 807 of file comm_list.c.

References changeProcessState(), errorToString(), printf, READY, showPCB(), and SUCCESS.

Referenced by pcbFunc().

807  {
808  e_PCB_ERROR_CODE_t retVal = changeProcessState((const char*)parameters[0], READY);
809  if(retVal == SUCCESS)
810  {
811  showPCB(parameters);
812  }
813  printf("Status: %s\r\n", errorToString(retVal));
814  return retVal;
815 // const char* name = (const char*)parameters[0];
816 // changeProcessState(name, READY);
817 // return 0;
818 }
Definition: pcb.h:47
const char * errorToString(e_PCB_ERROR_CODE_t error)
errorToString creates a string form of the error passed in
Definition: pcb.c:267
#define printf(format,...)
printf is simply a wrapper macro around sprintf with built in terminal print builtin needs to be a ma...
Definition: string.h:112
int showPCB(char parameters[][MAX_LENGTH])
showPCB shows the process information for the process requested by the user
Definition: comm_list.c:737
Definition: pcb.h:38
e_PCB_ERROR_CODE_t
The e_PCB_ERROR_CODE_t enum defines the return status of functions working with PCBs.
Definition: pcb.h:38
e_PCB_ERROR_CODE_t changeProcessState(const char *processName, e_PROCESS_STATE_t state)
changeProcessState changes the state of the process being called
Definition: pcb.c:168
int version ( char  parameters[][MAX_LENGTH])

version prints out the current version of the operating system. It will print out R1, R2, R3, ... depending on the current module.

No parameters are required.

Definition at line 425 of file comm_list.c.

References serial_print(), serial_println(), and VERSION.

Referenced by initCmdArray().

425  {
426  (void)parameters;
427  serial_print("Version: ");
429  serial_println(" ");
430  return 0;
431 }
int serial_print(const char *msg)
Definition: serial.c:59
int serial_println(const char *msg)
Definition: serial.c:44
#define VERSION
Definition: comm_vars.h:1