Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ElevatorSystem/ElevatorSystem.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@
RelativePath=".\Lift.cpp"
>
</File>
<File
RelativePath=".\Lift1.cpp"
>
</File>
<File
RelativePath=".\Lift2.cpp"
>
</File>
<File
RelativePath=".\Parent.cpp"
>
Expand All @@ -208,6 +216,14 @@
RelativePath=".\Lift.h"
>
</File>
<File
RelativePath=".\Lift1.h"
>
</File>
<File
RelativePath=".\Lift2.h"
>
</File>
<File
RelativePath=".\rt.h"
>
Expand Down
116 changes: 70 additions & 46 deletions ElevatorSystem/IO.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include ".\IO.h"
#include ".\rt.h"
#include <stdio.h>
#include <conio.h>

Expand Down Expand Up @@ -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 */
Expand Down
35 changes: 34 additions & 1 deletion ElevatorSystem/Lift.cpp
Original file line number Diff line number Diff line change
@@ -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");
9 changes: 5 additions & 4 deletions ElevatorSystem/Lift.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "rt.h"

class Lift
{
private:

int liftnum;
public:

Lift();
~Lift();
Lift(int I) { liftnum = I; };
~Lift();

};

Empty file added ElevatorSystem/Lift1.cpp
Empty file.
11 changes: 11 additions & 0 deletions ElevatorSystem/Lift1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "rt.h"

class Lift1
{
private:
int liftnum;
public:
Lift1(int I) { liftnum = I; };
~Lift1();

};
Empty file added ElevatorSystem/Lift2.cpp
Empty file.
11 changes: 11 additions & 0 deletions ElevatorSystem/Lift2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "rt.h"

class Lift2
{
private:
int liftnum;
public:
Lift2(int I) { liftnum = I; };
~Lift2();

};