Reputation: 571
I'm having trouble emitting some signals from my modules in OMNeT. In particular, one of my module has an array of signals to emit, something like:
simsignal_t* signalInputInterarrivalTime;
...
signalInputInterarrivalTime = new simsignal_t[N];
and then I registerSignal
each element in the array with a different name.
This way works, however in my .ned file I have to use as many @statistic
rows as the maximum size of the array. This is of course not the best way, being nor parametric neither readable. Is it possible to declare a vector of signals to emit, something that fits better my case?
Upvotes: 2
Views: 1232
Reputation: 7002
Yes, it is possible to dynamically create statistics in OMNeT++
.
Add these lines to your NED
file:
@signal[interarrivalTime*](type=simtime_t); // note an asterisk and the type of emitted values
@statisticTemplate[interarrivalTimeTemplate](record=vector);
Then declare in your C++
class:
simsignal_t interarrivalTimeSignals[10];
and create multiple instances of statistics:
for (int i = 0; i < 10; ++i) {
char signalName[32];
sprintf(signalName, "interarrivalTime%d", i);
simsignal_t signal = registerSignal(signalName);
cProperty *statisticTemplate = getProperties()->get("statisticTemplate", "interarrivalTimeTemplate");
getEnvir()->addResultRecorders(this, signal, signalName, statisticTemplate);
interarrivalTimeSignals[i] = signal;
}
An example of using it:
simtime_t delay = simTime() - msg->getSendingTime();
emit(interarrivalTimeSignals[3], delay);
Note that the type of emitting value has to match the type declared in NED
.
Upvotes: 6