Hana
Hana

Reputation: 33

"Cannot cast from integer to double" error when running an example on Castalia3.3 using Omnet 5.3

When I run any example of Castalia 3.3 using Omnet5.3 on ubuntu, for example the connectivityMap one, I got this error:

"Cannot evaluate parameter 'packetSpacing': (omnetpp::cIntParImpl)packetSpacing: Cannot cast from type integer to double -- in module (ConnectivityMap) SN.node[1].Application (id=25), at t=0.003536244016s, event #13" .

When I looked at SensorNetwork.ned file, I found parameters that are of double type

parameters:

double field_x = default (30);          // the length of the deployment field
double field_y = default (30);          // the width of the deployment field
double field_z = default (0);           // the height of the deployment field (2-D field by default)

int numNodes;                       // the number of nodes

string deployment = default ("");

int numPhysicalProcesses = default (1);
string physicalProcessName = default ("CustomizablePhysicalProcess");
string wirelessChannelName = default ("WirelessChannel");
string debugInfoFileName = default ("Castalia-Trace.txt");

Is it a bug problem ? a parameter casting problem with the new version of omnet ? Help me please, I am not that expert with Omnet yet

Upvotes: 1

Views: 847

Answers (1)

Jerzy D.
Jerzy D.

Reputation: 7002

No, this is not a bug, it is an intentional change since OMNeT++ 5.3.
The expression:

(double) par("packetSpacing")

results in calling doubleValue(). There is the following description of this method in cPar.h:

Returns value as double. The cPar type must be DOUBLE.
Note: Implicit conversion from INT is intentionally missing.


There are two ways of resolving this issue:

  1. Change the type of packetSpacing form int to double in ConnectivityMap.ned.

or

  1. Force reading the parameter as int by adding intValue(), for example in ConnectivityMap.cc:

    packetSpacing = (double) par("packetSpacing").intValue() / 1000.0;
    

Upvotes: 2

Related Questions