-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoorController.cpp
110 lines (99 loc) · 3.54 KB
/
doorController.cpp
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
/*******************************************************************
*
* DESCRIPTION: Atomic Model Door Controller
*
* AUTHOR: Ronnie Farrell
*
* Email: ronnie@sce.carleton.ca
*
* DATE: December 7, 2011
*
*******************************************************************/
/** include files **/
#include <math.h> // fabs( ... )
#include <stdlib.h>
#include "DoorController.h" // base header
#include "message.h" // InternalMessage ....
#include "mainsimu.h" // class MainSimulator
#include "strutil.h" // str2float( ... )
/*******************************************************************
* Function Name: DoorController
* Description: constructor
********************************************************************/
DoorController::DoorController( const std::string &name ) : Atomic( name )
, inHall( addInputPort( "inHall" ) )
, inRoom( addInputPort( "inRoom" ) )
, outHall( addOutputPort( "outHall" ) )
, outRoom( addOutputPort( "outRoom" ) )
, controllerTime (00,00,00,100)
{
std::string timeController( MainSimulator::Instance().getParameter( description(), "doorProcessingTime" ) ) ;
//test
if (timeController !="") controllerTime = timeController;
//MainSimulator::Instance().Spin_Motor_Clockwise(30);
cout<<"controllerTime="<<controllerTime<<"\n";
}
/*******************************************************************
* Function Name: DoorController::initFunction()
* Description: Initialization Function
********************************************************************/
Model &DoorController::initFunction()
{
this->state = Idle; // detecting
return *this ;
}
/*******************************************************************
* Function Name: DoorController::externalFunction()
* Description: External Function DoorController
********************************************************************/
Model &DoorController::externalFunction( const ExternalMessage &msg )
{
if (state == Idle && msg.port() == inHall)
{
this->state = Perform;
this->value = msg.value();
this->fromRoom = 0;
this->holdIn(Atomic::active, controllerTime);
}
else if (state == Idle && msg.port() == inRoom)
{
this->state = Perform;
this->value = msg.value();
this->fromRoom = 1;
this->holdIn(Atomic::active, controllerTime);
}
return *this;
}
/*******************************************************************
* Function Name: DoorController::internalFunction()
* Description: Internal Function DoorController
********************************************************************/
Model &DoorController::internalFunction( const InternalMessage & )
{
if(state == Perform){
this->state = Idle;
this->passivate();
}
return *this;
}
/*******************************************************************
* Function Name: DoorController::outputFunction()
* Description: Output function DoorController - writes info about time and events
********************************************************************/
Model &DoorController::outputFunction( const InternalMessage &msg )
{
// person walks from hall to room
if (state == Perform && fromRoom == 0){
this->sendOutput( msg.time(), this->outHall, this->value) ;//pedestrian exited hall / entered room
}
// person walks from room to hall
else if(state == Perform && fromRoom == 1)
{
this->sendOutput( msg.time(), this->outRoom, this->value) ;//pedestrian exited room / entered hall
}
return *this ;
}
DoorController::~DoorController()
{
//MainSimulator::Instance().Spin_Motor_Stop();
}