-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplayer.cpp
More file actions
99 lines (90 loc) · 3.39 KB
/
displayer.cpp
File metadata and controls
99 lines (90 loc) · 3.39 KB
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
/*******************************************************************
*
* DESCRIPTION: The Atomic Model of Displayer.
* It accepts the current time of the day or the remaining time of a heating job
* and then send them to the appropriate output ports.
* The time that is going to be sent is in the format of HHMM. E.g., 12:23 will
* be sent as 1223.
* There are two input ports which are discribed as follows:
* <day_time> The time of the day which is also in the format of HHMM.
* <counter_time> the remaing time of a heating job which in the format as
* MMSS. E.g. 8 minutes and 20 seconds will be represented as 820.
* There are two output ports as follows:
* <cur_time> the current time that is generated from the model. It has the
* following format: hours*100 + minutes. Therefore, 10:23AM will be sent as
* 1023.
* <rem_time> the remaining time of a heating job. the same format as
*<counter_time>
*
*
*******************************************************************/
/** include files **/
#include "displayer.h" // The header file
#include "message.h" // header file of ExternalMessage, InternalMessage
#include "mainsimu.h" // header file of the main simulator
/** public functions **/
/*******************************************************************
* constructor
* Description: creates an initial atomic model of Displayer
********************************************************************/
Displayer::Displayer( const string &name )
: Atomic( name )
, day_time( addInputPort( "day_time" ) )
, counter_time( addInputPort( "counter_time" ) )
, cur_time( addOutputPort( "cur_time" ) )
, rem_time( addOutputPort( "rem_time" ) )
, ten_sec(0,0,10,0)
{
}
/*******************************************************************
* initFunction
* Description: starts the simulation.
********************************************************************/
Model &Displayer::initFunction()
{
this->out_time = 0;
//Stay in passive state until an external event comes
holdIn( passive, Time::Inf );
return *this ;
}
/*******************************************************************
* externalFunction
* Description: This method handles external events coming from
* any of the two input ports.
********************************************************************/
Model &Displayer::externalFunction( const ExternalMessage &msg )
{
out_time=msg.value();
if( msg.port() == day_time )
{
if (state()==passive) //only display the current time when in passive state
{
this->sendOutput( msg.time(), cur_time, this->out_time );
}
}
else if( msg.port() == counter_time)
{
if (out_time>0)
{
holdIn(active, Time::Zero); //change to active immediately
this->sendOutput( msg.time(), rem_time, this->out_time );
}
else //the heating job is finished or cleared
holdIn(passive, ten_sec); //change to passive for 10 seconds
}
return *this;
}
/*******************************************************************
* Function Name: internalFunction
* Description: The internal function simply consists in keeping the
* model in the current state until an external event comes in.
********************************************************************/
Model &Displayer::internalFunction( const InternalMessage & )
{
holdIn ( state(), Time::Inf );
return *this;
}
Model &Displayer:: outputFunction( const InternalMessage &msg)
{
return *this;
}