Update README and add contrib dir
This commit is contained in:
98
contrib/tsn/model/clock.cc
Normal file
98
contrib/tsn/model/clock.cc
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "clock.h"
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/simulator.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE("Clock");
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED(Clock);
|
||||
|
||||
TypeId
|
||||
Clock::GetTypeId()
|
||||
{
|
||||
static TypeId tid =
|
||||
TypeId("ns3::Clock")
|
||||
.SetParent<Object>()
|
||||
.SetGroupName("tsn")
|
||||
.AddConstructor<Clock>()
|
||||
.AddAttribute("Granularity",
|
||||
"Clock granularity in ns",
|
||||
TimeValue(Time(NanoSeconds(1))),
|
||||
MakeTimeAccessor(&Clock::m_granularity),
|
||||
MakeTimeChecker());
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
Clock::Clock()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
}
|
||||
|
||||
Clock::~Clock()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
}
|
||||
|
||||
Time
|
||||
Clock::GetLocalTime()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
return GetUncorrectedLocalTime() + m_correctionOffset;
|
||||
}
|
||||
|
||||
Time
|
||||
Clock::GetUncorrectedLocalTime()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
return Simulator::Now();
|
||||
}
|
||||
|
||||
Time
|
||||
Clock::GetTimeAt(Time t)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
return t;
|
||||
}
|
||||
|
||||
Time
|
||||
Clock::GetDuration(Time d)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
return d;
|
||||
}
|
||||
|
||||
void
|
||||
Clock::UpdateTime(){
|
||||
NS_LOG_FUNCTION(this);
|
||||
}
|
||||
|
||||
void
|
||||
Clock::SetOffsetTime(Time offset)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
m_correctionOffset = offset;
|
||||
TriggerCorrectionCallback();
|
||||
}
|
||||
|
||||
void
|
||||
Clock::AddClockCorrectionCallback(Callback<void> cb)
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
m_callbacks.insert(m_callbacks.end(), cb);
|
||||
}
|
||||
|
||||
void
|
||||
Clock::TriggerCorrectionCallback()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
for(int i = 0; i < (int)m_callbacks.size(); i++)
|
||||
{
|
||||
m_callbacks[i]();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user