TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DummySync.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include "DummySync.h"
17 #include "TTEScheduler.h"
19 #include "SyncNotification_m.h"
20 
21 using namespace TTEthernetModel;
22 
24 
26 {
27  return 3;
28 }
29 
30 void DummySync::initialize(int stage)
31 {
32  if(stage==1)
33  {
34  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
36  event->setAction_time(par("action_time").longValue());
37  event->setDestinationGate(gate("schedulerIn"));
38  tteScheduler->registerEvent(event);
39  }
40  if(stage==2)
41  {
42  notify(SYNC);
43  getDisplayString().setTagArg("i", 1, "green");
44  }
45 }
46 
47 void DummySync::handleMessage(cMessage *msg)
48 {
49  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
50  if(msg->arrivedOn("schedulerIn")){
51  if(tteScheduler->getCycles()>1){
52  uint32_t cycleTicks = tteScheduler->par("cycle_ticks").longValue();
53  simtime_t tick = tteScheduler->par("tick").doubleValue();
54 
55  int64_t modticks = ((int64_t)(simTime()/tick)-par("action_time").longValue())%cycleTicks;
56  if(modticks>((int64_t)cycleTicks/2))
57  modticks=modticks-cycleTicks;
58  modticks+=uniform(-par("precission").doubleValue()/2, par("precission").doubleValue()/2)/tick;
59 
60  tteScheduler->clockCorrection(-modticks);
61  }
62 
64  tteScheduler->registerEvent(event);
65  }
66 }