-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmSource.cpp
More file actions
114 lines (95 loc) · 3.11 KB
/
rmSource.cpp
File metadata and controls
114 lines (95 loc) · 3.11 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
/*******************************************************************
*
* DESCRIPTION: Atomic Model RmSource
*
* AUTHOR: Abdullah Alfaify
*
* EMAIL: mailto://aalfa064@uottawa.ca
*
* DATE: 14/12/2011
*
*******************************************************************/
/** include files **/
#include "rmSource.h" // class RmSource
#include "message.h" // class ExternalMessage, InternalMessage
#include "mainsimu.h" // MainSimulator::Instance().getParameter( ... )
/** public functions **/
/*******************************************************************
* Function Name: RmSource
* Description:
********************************************************************/
RmSource::RmSource( const string &name )
: Atomic( name )
, out( addOutputPort( "out" ) )
, rmCount( addOutputPort( "rmCount" ) )
, mg( addInputPort( "mg" ) )
, preparationTime( 0, 0, 1, 0 )
{ string time( MainSimulator::Instance().getParameter( description(), "preparation" ) ) ;
if( time != "" )
preparationTime = time ;
}
/*******************************************************************
* Function Name: initFunction
* Description:
********************************************************************/
Model &RmSource::initFunction()
{
counter = 0; // to count RM
BufferMaxSize = 5; // used for compression with received buffer size in order to send or not
requierdToSend = BufferMaxSize;
state = generate;
// Initially, full up the buffer, after that the buffer will ask for more elements.
holdIn(active, Time::Zero );
return *this ;
}
/*******************************************************************
* Function Name: externalFunction
* Description:
********************************************************************/
Model &RmSource::externalFunction( const ExternalMessage &msg )
{
if( msg.port() == mg )
{
if ( static_cast < int > (msg.value()) < BufferMaxSize )
{
state = generate;
requierdToSend = BufferMaxSize - static_cast < int > (msg.value()) ;
// in this case we have available space in the buffer, so call the output function to sent raw material (RM)
holdIn(active, preparationTime );
}
else
{
// wait and do not sent RM to buffer
state = wait;
}
}
return *this;
}
/*******************************************************************
* Function Name: internalFunction
* Description:
********************************************************************/
Model &RmSource::internalFunction( const InternalMessage & )
{
switch (state)
{
case generate:
holdIn(active, preparationTime );
case wait:
passivate();
};
return *this ;
}
/*******************************************************************
* Function Name: outputFunction
* Description:
********************************************************************/
Model &RmSource::outputFunction( const InternalMessage &msg )
{
for (int i=1 ; i <= requierdToSend ;i++){
sendOutput( msg.time(), out, 1 ) ; // 1 means the value of the message
counter++;
sendOutput( msg.time(), rmCount, counter ) ; // send counter
}
return *this ;
}