-
Notifications
You must be signed in to change notification settings - Fork 4
/
CCI.c
191 lines (156 loc) · 6.33 KB
/
CCI.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include "rtx.h"
void CCI()
{
//printf("You're in the CCI\n");
int HH=0;
int MM=0;
int SS=0;
int pri=0;
int id=0;
int U = 0;
int dun = 0;
msg_env* env = request_msg_env();
msg_env* first = request_msg_env();
while(1)
{
// send the welcome message
/*
if (first == NULL){
terminate(1);
}
strcpy(first->msg_text, "Enter input for the CCI [s, ps, c [##:##:##], cd, ct, b, n [new_prio] [pid], e... , t]:\0");
int F = 0;
F = send_console_chars(first);
if (F == 0){
terminate(1);
}
*/
U = get_console_chars(env); //keyboard input
//sleep(5);
// only do this if there was input
if (U==1)
{
env = receive_message();
while (env->msg_type != CONSOLE_INPUT)
{
env = receive_message(); //***STOPS HERE TO WAIT FOR INPUT
}
char* input_txt = env->msg_text;
// send envelope to Process A
if (strcmp(input_txt,"s")==0)
{
// printf("input was s\n");
//if the text in the field is "s"
env = request_msg_env(); //request an envelope
int Z =0;
Z = send_message(3,env); // send message to Process A
}
// display process status of all processes
else if (strcmp(input_txt,"ps")==0)
{
// printf("input was ps\n");
env = request_msg_env(); //request an envelope
int J=request_process_status(env);
if (J==0)
printf("Error with getting Process Status\n");
}
// allows time to be displayed on console and halts if getting ct
else if (strcmp(input_txt,"cd")==0)
{
// printf("input was cd\n");
wallClockOut = 1;
}
else if (strcmp(input_txt,"ct")==0)
{
// printf("input was ct\n");
wallClockOut = 0;
}
// set clock to any valid 24hr time
else if (strncmp(input_txt,"c", 1)==0)
{
// printf("input was c\n");
int HH = atoi(input_txt+2);
int MM = atoi(input_txt+5);
int SS = atoi(input_txt+8);
int R = clock_set(wallclock, HH, MM, SS);
if (R==0)
printf("Error with setting clock in CCI\n");
}
// b displays past instances of send and receive messages
else if (strcmp(input_txt,"b")==0)
{
// printf("input was b\n");
env = request_msg_env(); //request an envelope
int U=get_trace_buffers(env);
if (U==0)
printf("Error performing call on Trace Buffers\n");
}
// terminates RTX
else if (strcmp(input_txt,"t")==0)
{
terminate(0);
}
// changes priority
else if (strncmp(input_txt,"n",1)==0)
{
// printf("input was n\n");
int new_pri = atoi(input_txt+2);
int ID = atoi(input_txt+4);
int R = change_priority(new_pri, ID);
if (R==0)
printf("Error with changing priority in CCI\n");
}
// echo the input back
else if (strncmp(input_txt,"e", 1)==0)
{
// printf("input was e\n");
env = request_msg_env(); //request an envelope
input_txt[0] = ' ';
strcat(input_txt, "\n\n");
strcpy(env->msg_text, "echo is: ");
strcpy(env->msg_text, input_txt);
int R = send_console_chars(env);
if (R==0)
printf("Error with echoing to screen\n");
}
else
{
env = request_msg_env(); //request an envelope
char* temp = (char*) malloc(sizeof(SIZE));
sprintf(temp, "'%s' is not valid CCI input. Please try again.\n\n", input_txt);
strcpy(env->msg_text, temp);
int R = send_console_chars(env);
if (R==0)
printf("Error with printing invalid input message\n");
// printf("'%s' is not valid CCI input. Please try again.\n\n", input_txt);
}
dun = release_msg_env(env);
if (dun == 0)
{
env = request_msg_env(); //request an envelope
strcpy(env->msg_text, "ERROR IN DEALLOCATING ENVELOPE AT END OF CCI\n");
int R = send_console_chars(env);
if (R==0)
printf("Error with printing error message\n");
}
//else
// printf("CCI finished, I think\n");
}
env = request_msg_env();
// if there was no input
release_processor();
}
}