-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeepDriver.cpp
More file actions
105 lines (93 loc) · 3.18 KB
/
beepDriver.cpp
File metadata and controls
105 lines (93 loc) · 3.18 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
/*******************************************************************
*
* DESCRIPTION: The Atomic Model of beep driver.
* It keeps the beep sound for two seconds when there is event from
* external. It won't accept any outside event during it is beeping
* This atomic model has the following one input:
* <beep_in> is used to indicate the beeper should beep.
* There is one output generated from this atomic model.
* <sound_out> is used to express the start and end of duration of beeping
* 1 is for the beginning of beeping and 0 means beeping is finished.
*
*******************************************************************/
/** include files **/
#include "beepDriver.h" // class BeepDrv
#include "message.h" // class ExternalMessage, InternalMessage
#include "mainsimu.h" // MainSimulator::Instance().getParameter( ... )
/** public functions **/
/*******************************************************************
* BeepDrv constructor
* Description: This method creats an atomic BeepDrv model
********************************************************************/
BeepDrv::BeepDrv( const string &name )
: Atomic( name )
, beep_in( addInputPort( "beep_in" ) )
, sound_out( addOutputPort( "sound_out" ) )
, onesecond( 0, 0, 1, 0 )
{
}
/*******************************************************************
* BeepDrv init function
* Description: This method is invoked when simulation starts.
* the beeping time is zero seconds
********************************************************************/
Model &BeepDrv::initFunction()
{
// Activate the output function so the minute is displayed
// right away
holdIn( passive, Time::Zero );
counter = 0;
return *this ;
}
/*******************************************************************
* externalFunction
* Description: This method handles external events coming from
* one input port.
********************************************************************/
Model &BeepDrv::externalFunction( const ExternalMessage &msg )
{
if( msg.port() == beep_in)
{
if (this->state () == passive)
{
counter=3;
this->state(active);
holdIn( this->state(), Time::Zero );
sendOutput( msg.time(), sound_out, 1 ) ;
}
}
return *this;
}
/*******************************************************************
* Function Name: internalFunction
* Description: The internal function simply consists in keeping the
* model in the active state for beeping time.
********************************************************************/
Model &BeepDrv::internalFunction( const InternalMessage & )
{
if (this->state() == active)
{
holdIn( this->state(), onesecond);
counter --;
if (counter == 0)
{
this->state(passive);
holdIn( this->state(), Time::Zero );
}
}
else holdIn( this->state(), Time::Inf );
return *this;
}
/*******************************************************************
* Function Name: outputFunction
* Description: This routine sends 0 to the <sound_out> output port
* to indicate the beep is off.
********************************************************************/
Model &BeepDrv::outputFunction( const InternalMessage &msg )
{
if (this->state() == passive)
{
sendOutput( msg.time(), sound_out, 0 ) ;
}
return *this ;
}