-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerDriver.cpp
More file actions
117 lines (103 loc) · 3.6 KB
/
powerDriver.cpp
File metadata and controls
117 lines (103 loc) · 3.6 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************
*
* DESCRIPTION: The Atomic Model of power driver.
* It keeps the power (heat) on the configured level during cooking
* This atomic model has the following two inputs:
* <power_set> is used to turn on/off the heating system.
* <powerlevel_in> is used to adjust the level of the power,
* indicated as 1, 2, 3 ( low, medium, high)
* There is one output generated from this atomic model.
* <heatlevel_out> indicate the level of the power during it is cooking,
* but if it is not cooking, it is shown zero. All heat level is generated
* from the model as 0 (uncooking) and 1,2,3(cooking)
*
*
*******************************************************************/
/** include files **/
#include "powerDriver.h" // class PowerDrv
#include "message.h" // class ExternalMessage, InternalMessage
#include "mainsimu.h" // MainSimulator::Instance().getParameter( ... )
/** public functions **/
/*******************************************************************
* PowerDrv constructor
* Description: creates an initial atomic model of the PowerDrv
********************************************************************/
PowerDrv::PowerDrv( const string &name )
: Atomic( name )
, power_set( addInputPort( "power_set" ) )
, powerlevel_in( addInputPort( "powerlevel_in" ) )
, heatlevel_out( addOutputPort( "heatlevel_out" ) )
{
}
/*******************************************************************
* PowerDrv init function
* Description: This method is invoked when simulation starts. It
* simply sets heatlevel to 1.
********************************************************************/
Model &PowerDrv::initFunction()
{
this->heatlevel = 1;
// Activate the output function so the minute is displayed
// right away
holdIn( passive, Time::Zero );
return *this ;
}
/*******************************************************************
* Function Name: externalFunction
* Description: This method handles external events coming from
* any of the three input ports.
********************************************************************/
Model &PowerDrv::externalFunction( const ExternalMessage &msg )
{
if( msg.port() == power_set )
{
if( msg.value() == true )
{
// time_set was pressed. Go active until
// an external event comes in.
holdIn( active, Time::Inf );
holdIn( this->state(), Time::Zero);
}
else {
// time_set was released. Go passive
// until an external event comes in.
passivate();
holdIn( this->state(), Time::Zero);
}
}
else if( msg.port() == powerlevel_in )
{
if (this->state() == passive)
this->heatlevel = msg.value();
}
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 &PowerDrv::internalFunction( const InternalMessage & )
{
holdIn ( state(), Time::Inf );
return *this;
}
/*******************************************************************
* Function Name: outputFunction
* Description: This routine sens the value of the minute variable
* to the <time_minutes> output port.
********************************************************************/
Model &PowerDrv::outputFunction( const InternalMessage &msg )
{
if (this->state ()== active)
{
// cooking state, output the powerlevel)
sendOutput( msg.time(), heatlevel_out, this->heatlevel ) ;
}
else
{
//uncooking state
sendOutput( msg.time(), heatlevel_out, 0) ;
}
return *this ;
}