From 37f7a2a90c34b471a316106ca2cf979695071d77 Mon Sep 17 00:00:00 2001 From: calebcng Date: Mon, 28 Oct 2013 18:20:51 -0700 Subject: [PATCH 1/4] Test --- ElevatorSystem/IO.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ElevatorSystem/IO.cpp b/ElevatorSystem/IO.cpp index 9acacdf..2cff05e 100644 --- a/ElevatorSystem/IO.cpp +++ b/ElevatorSystem/IO.cpp @@ -8,6 +8,9 @@ I/O Program Link to datapools, semaphores, open pipeline install signal handler using intercept() primitive */ + +//Testing + struct LiftDataPool { int CurrentFloor; From f50b62b027fe6cea29ad836276daf9c21f06fd90 Mon Sep 17 00:00:00 2001 From: calebcng Date: Mon, 28 Oct 2013 18:41:21 -0700 Subject: [PATCH 2/4] Updated IO.cpp Additional detailed pseudo code for P1-C1 and P3-C3, as well as input code for exiting simulation. --- ElevatorSystem/IO.cpp | 119 ++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 51 deletions(-) diff --git a/ElevatorSystem/IO.cpp b/ElevatorSystem/IO.cpp index 2cff05e..d4d4b1f 100644 --- a/ElevatorSystem/IO.cpp +++ b/ElevatorSystem/IO.cpp @@ -8,9 +8,6 @@ I/O Program Link to datapools, semaphores, open pipeline install signal handler using intercept() primitive */ - -//Testing - struct LiftDataPool { int CurrentFloor; @@ -41,60 +38,80 @@ int main() //Initialize variables char input[2]; - -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 -// } - - //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" ); + int Lift1Floor; + int Lift1Direction; + int Lift1Status; + int Lift1DoorStatus; + + 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 + // } + + //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" ); + } + else { + printf( "Invalid inputs.\n" ); + continue; + } + } + else if( input[0]=='e' && input[1] == 'e' ) { + //trigger end simulation flag } 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 */ From ba932b52fd228459120982163bf83b2f720c0e93 Mon Sep 17 00:00:00 2001 From: calebcng Date: Mon, 28 Oct 2013 18:58:19 -0700 Subject: [PATCH 3/4] Fixed variable initialization --- ElevatorSystem/IO.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ElevatorSystem/IO.cpp b/ElevatorSystem/IO.cpp index d4d4b1f..e302bec 100644 --- a/ElevatorSystem/IO.cpp +++ b/ElevatorSystem/IO.cpp @@ -1,5 +1,4 @@ #include ".\IO.h" -#include ".\rt.h" #include #include @@ -38,10 +37,10 @@ int main() //Initialize variables char input[2]; - int Lift1Floor; - int Lift1Direction; - int Lift1Status; - int Lift1DoorStatus; + int Lift1Floor, Lift2Floor; + int Lift1Direction, Lift2Direction; + int Lift1Status, Lift2Status; + int Lift1DoorStatus, Lift2DoorStatus; do { //test keyboard for 2 characters @@ -60,6 +59,7 @@ int main() { //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" ); From eac5402b68ae6a374a4068e85a5e7d0303cafcf5 Mon Sep 17 00:00:00 2001 From: yutad Date: Fri, 1 Nov 2013 12:15:27 -0700 Subject: [PATCH 4/4] fhjfjfhjfhj --- ElevatorSystem/ElevatorSystem.vcproj | 16 +++++++++++++ ElevatorSystem/IO.cpp | 4 ++++ ElevatorSystem/Lift.cpp | 35 +++++++++++++++++++++++++++- ElevatorSystem/Lift.h | 9 +++---- ElevatorSystem/Lift1.cpp | 0 ElevatorSystem/Lift1.h | 11 +++++++++ ElevatorSystem/Lift2.cpp | 0 ElevatorSystem/Lift2.h | 11 +++++++++ 8 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 ElevatorSystem/Lift1.cpp create mode 100644 ElevatorSystem/Lift1.h create mode 100644 ElevatorSystem/Lift2.cpp create mode 100644 ElevatorSystem/Lift2.h 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 e302bec..3e61797 100644 --- a/ElevatorSystem/IO.cpp +++ b/ElevatorSystem/IO.cpp @@ -68,6 +68,10 @@ int main() } 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" ); 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(); + +};