diff --git a/ElevatorSystem/ElevatorSystem.vcproj b/ElevatorSystem/ElevatorSystem.vcproj
index 0e2e6d5..359a21a 100644
--- a/ElevatorSystem/ElevatorSystem.vcproj
+++ b/ElevatorSystem/ElevatorSystem.vcproj
@@ -182,6 +182,14 @@
RelativePath=".\Lift.cpp"
>
+
+
+
+
@@ -208,6 +216,14 @@
RelativePath=".\Lift.h"
>
+
+
+
+
diff --git a/ElevatorSystem/IO.cpp b/ElevatorSystem/IO.cpp
index 9acacdf..3e61797 100644
--- a/ElevatorSystem/IO.cpp
+++ b/ElevatorSystem/IO.cpp
@@ -1,5 +1,4 @@
#include ".\IO.h"
-#include ".\rt.h"
#include
#include
@@ -38,60 +37,85 @@ int main()
//Initialize variables
char input[2];
+ int Lift1Floor, Lift2Floor;
+ int Lift1Direction, Lift2Direction;
+ int Lift1Status, Lift2Status;
+ int Lift1DoorStatus, Lift2DoorStatus;
-do {
- //test keyboard for 2 characters
- input[0] = getch();
- input[1] = getch();
+ do {
+ //test keyboard for 2 characters
+ input[0] = getch();
+ input[1] = getch();
-// if(2 characters present) {
-// read them,
-// check they make sense and if so write them to the pipeline
-// }
+ // if(2 characters present) {
+ // read them,
+ // check they make sense and if so write them to the pipeline
+ // }
- //Check inputs to make sure they are valid
- if( input[0]=='U' || input[0]=='D' || input[0]=='1' || input[0]=='2' ) {
- if( input[1]=='0' || input[1]=='1' || input[1]=='2' || input[1]=='3' || input[1]=='4' || input[1]=='5' || input[1]=='6' ||
- input[1]=='7' || input[1]=='8' || input[1]=='9' )
- {
- //Input characters make sense. Proceed to send to Dispatcher.
- printf( "Input characters make sense. Proceeding to Dispatcher.\n" );
+ //Check inputs to make sure they are valid
+ if( input[0]=='U' || input[0]=='D' || input[0]=='1' || input[0]=='2' ) {
+ if( input[1]=='0' || input[1]=='1' || input[1]=='2' || input[1]=='3' || input[1]=='4' || input[1]=='5' || input[1]=='6' ||
+ input[1]=='7' || input[1]=='8' || input[1]=='9' )
+ {
+ //Input characters make sense. Proceed to send to Dispatcher.
+ printf( "Input characters make sense. Proceeding to Dispatcher.\n" );
+ pipe3.Write( &input, sizeof(input) );
+ }
+ else {
+ printf( "Invalid inputs.\n" );
+ continue;
+ }
+ }
+ else if( input[0]=='e' && input[1] == 'e' ) {
+ //trigger end simulation flag
+<<<<<<< HEAD
+=======
+ printf( "Request to end simulation.\n" );
+>>>>>>> upstream/master
}
else {
printf( "Invalid inputs.\n" );
continue;
}
- }
- else {
- printf( "Invalid inputs.\n" );
- continue;
- }
-
-/*
- if(read_semaphore(PS3) > 0) car1 produced data
- WAIT(PS3) ;
- read car1’s datapool into local structure
- SIGNAL(CS3) ;
- Redraw Lift1 screen
- }
-*/
- if( P1 > 0 ) {
- P1.Wait();
- int Lift1Floor = Lift1;
- int Lift1Direction;
- int Lift1Status;
- int Lift1DoorStatus;
- }
-
- if(read_semaphore(PS4) > 0) /* car2 produced data */
- WAIT(PS4) ;
- read car2’s datapool into local structure
- SIGNAL(CS4) ;
- Redraw Car2 screen
- }
-} while(end of simulation flag is not TRUE) /* do until end of simulation*/
-end program
+ /*
+ if(read_semaphore(PS3) > 0) car1 produced data
+ WAIT(PS3) ;
+ read car1’s datapool into local structure
+ SIGNAL(CS3) ;
+ Redraw Lift1 screen
+ }
+ */
+ if( P1.Read() > 0 ) {
+ //WAIT(PS1)
+ P1.Wait();
+ //read Lift1's datapool into local structure
+ Lift1Floor = Lift1->CurrentFloor;
+ Lift1Direction = Lift1->Direction;
+ Lift1Status = Lift1->LiftStatus;
+ Lift1DoorStatus = Lift1->DoorStatus;
+ //Signal(CS1)
+ C1.Signal();
+ //Redraw Lift1 screen
+ }
+
+ if( P3.Read() > 0 ) {
+ //WAIT(PS3)
+ P3.Wait();
+ //read Lift2's datapool into local structure
+ Lift2Floor = Lift2->CurrentFloor;
+ Lift2Direction = Lift2->Direction;
+ Lift2Status = Lift2->LiftStatus;
+ Lift2DoorStatus = Lift2->DoorStatus;
+ //Signal(CS1)
+ C3.Signal();
+ //Redraw Lift2 screen
+ }
+ } while(end of simulation flag is not TRUE) /* do until end of simulation*/
+
+ //end program
+ return 0;
+}
Signal_handler() /* installed with intercept primitive, dispatcher sends this process signals */
diff --git a/ElevatorSystem/Lift.cpp b/ElevatorSystem/Lift.cpp
index dd1aed5..e44c978 100644
--- a/ElevatorSystem/Lift.cpp
+++ b/ElevatorSystem/Lift.cpp
@@ -1,6 +1,39 @@
-#include "rt.h"
+#include "Lift.h"
+struct LiftDataPool
+{
+ int CurrentFloor;
+ int Direction;
+ int LiftStatus;
+ int DoorStatus;
+};
int main()
{
+ if( liftnum == 1 ) {
+ //Create datapools
+ CDataPool dp("Lift1", sizeof(struct LiftDataPool));
+ struct LiftDataPool* Lift = (struct LiftDataPool*)(dp1.LinkDataPool);
+ //Create pipelines
+ CPipe p1( "Lift1Pipe" );
+ //Create Semaphores
+ CSemaphore P1( "Producer1", 0, 1 );
+ CSemaphore C1( "Consumer1", 0, 1 );
+ CSemaphore P2( "Producer1", 0, 1 );
+ CSemaphore C2( "Consumer1", 0, 1 );
+ }
+ else if( liftnum == 2 ) {
+ //Create
+ CDataPool dp("Lift2", sizeof(struct LiftDataPool));
+ struct LiftDataPool* Lift = (struct LiftDataPool*)(dp2.LinkDataPool);
+ //Create
+
+ CSemaphore P3( "Producer2", 0, 1 );
+ CSemaphore C3( "Consumer2", 0, 1 );
+ CSemaphore P4( "Producer2", 0, 1 );
+ CSemaphore C4( "Consumer2", 0, 1 );
+ }
+
+
+
CPipe p1("Lift1Pipe");
\ No newline at end of file
diff --git a/ElevatorSystem/Lift.h b/ElevatorSystem/Lift.h
index d54ada6..d06640e 100644
--- a/ElevatorSystem/Lift.h
+++ b/ElevatorSystem/Lift.h
@@ -1,11 +1,12 @@
+#include "rt.h"
+
class Lift
{
private:
-
+ int liftnum;
public:
-
- Lift();
- ~Lift();
+ Lift(int I) { liftnum = I; };
+ ~Lift();
};
diff --git a/ElevatorSystem/Lift1.cpp b/ElevatorSystem/Lift1.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/ElevatorSystem/Lift1.h b/ElevatorSystem/Lift1.h
new file mode 100644
index 0000000..7aa2798
--- /dev/null
+++ b/ElevatorSystem/Lift1.h
@@ -0,0 +1,11 @@
+#include "rt.h"
+
+class Lift1
+{
+ private:
+ int liftnum;
+ public:
+ Lift1(int I) { liftnum = I; };
+ ~Lift1();
+
+};
diff --git a/ElevatorSystem/Lift2.cpp b/ElevatorSystem/Lift2.cpp
new file mode 100644
index 0000000..e69de29
diff --git a/ElevatorSystem/Lift2.h b/ElevatorSystem/Lift2.h
new file mode 100644
index 0000000..c073133
--- /dev/null
+++ b/ElevatorSystem/Lift2.h
@@ -0,0 +1,11 @@
+#include "rt.h"
+
+class Lift2
+{
+ private:
+ int liftnum;
+ public:
+ Lift2(int I) { liftnum = I; };
+ ~Lift2();
+
+};