Time in omnet

550 views
Skip to first unread message

Jens Buysse

unread,
Jan 24, 2012, 11:09:40 AM1/24/12
to omnetpp
Dear all,

I just have a small question which I cannot see begin answered in the
manual.
How does omnet deal with time?

In omnet you can define units i.e. @unit(s) tag. So if I use delay =
1ms as parameter in my ini file, how can I relate this in my code?

My problem is: I need to schedule something in the future (now+delay).
If I do double delay= par("delay") I get 1 but I want to add this to
the simtime function I need to covert this to 0.001 right?

Of course I can do this, but it's not nice. If somebody else want to
use my simulator and wants the delay to be 1s my code will still
change the 1 to 0.001.

So how do I check the unit of the parameter I get from par("name").

Andras Varga

unread,
Jan 24, 2012, 12:11:04 PM1/24/12
to omn...@googlegroups.com
You always get the value of the parameter in the unit specified with @unit,
i.e no need to convert within modules. I.e. if your parameter is @unit(s),
you'll always get the value in seconds, no matter whether it was entered in
milliseconds, microseconds, hours or any other unit.

So:
double delay @unit(s);
**.delay = 1ms
double delay = par("delay"); --> returns 0.001

You can still read the parameters via
par("delay").getProperties()->get("unit")->getValue(cProperty::DEFAULTKEY).

Andras

> --
> Sent from the OMNeT++ mailing list. To configure your membership,
> visit http://groups.google.com/group/omnetpp

Reply all
Reply to author
Forward
0 new messages