riebl / artery

OMNeT++ V2X simulation framework for ETSI ITS-G5
GNU General Public License v2.0
203 stars 131 forks source link

Problem in encoding the CPM messages #183

Closed inesbj closed 3 years ago

inesbj commented 3 years ago

Hi,

I am trying to send CPM that contains

The problem is that I got the following error when testing a simple scenario : std::runtime_error: Can't determine size for unaligned PER encoding of type CPM because of PerceivedObjectContainer sub-type -- in module (artery::VehicleMiddleware) World.node[3].middleware (id=240)

I can not figure out where is the problem in my code. I set the perceivedobject struct data to some predefined values as showed in my code below (to avoid the constraints), and I tried to include all the non-optional fields.

if (objects.size() > 0) { cpm.cpmParameters.numberOfPerceivedObjects = objects.size(); cpm.cpmParameters.perceivedObjectContainer = vanetza::asn1::allocate(); for (const auto& obj : objects) { auto perceivedobject = vanetza::asn1::allocate(); std::weak_ptr obj_ptr = obj.first; if (obj_ptr.expired()) continue; const auto& vd = obj_ptr.lock()->getVehicleData();
uint16_t timeofmeasurement = countTaiMilliseconds(mTimer->getTimeFor(vd.updated())); perceivedobject->objectID = vd.station_id(); perceivedobject->timeOfMeasurement = timeofmeasurement TimeOfMeasurement_oneMilliSecond; perceivedobject->xDistance.value = DistanceValue_oneMeter; perceivedobject->xDistance.confidence = DistanceConfidence_zeroPointZeroOneMeter; perceivedobject->yDistance.value = DistanceValue_oneMeter; perceivedobject->yDistance.confidence = DistanceConfidence_zeroPointZeroOneMeter; perceivedobject->xSpeed.value = SpeedValueExtended_oneCentimeterPerSec 100 ; perceivedobject->xSpeed.confidence = SpeedConfidence_equalOrWithinOneCentimeterPerSec * 3; int flag = ASN_SEQUENCE_ADD(cpm.cpmParameters.perceivedObjectContainer, perceivedobject); std::cout<< "flag"<<flag <<std::endl;
} }

The printed flag value is equal to 0. Your help will be very much appreciated.

riebl commented 3 years ago

Unfortunately, the error messages from asn1c are not always very helpful to pinpoint the exact problem. I guess the ySpeed of your object has invalid values and thus cannot be encoded. Following code is working fine for me:

    asn1::Cpm cpm;
    cpm->cpm.cpmParameters.numberOfPerceivedObjects = 1;
    cpm->cpm.cpmParameters.perceivedObjectContainer = asn1::allocate<PerceivedObjectContainer_t>();

    auto object = asn1::allocate<PerceivedObject_t>();
    ASN_SEQUENCE_ADD(cpm->cpm.cpmParameters.perceivedObjectContainer, object);
    object->objectID = 1;
    object->timeOfMeasurement = TimeOfMeasurement_oneMilliSecond;
    object->xDistance.value = DistanceValue_oneMeter;
    object->xDistance.confidence = DistanceConfidence_unavailable;
    object->yDistance.value = DistanceValue_oneMeter;
    object->yDistance.confidence = DistanceConfidence_unavailable;
    object->xSpeed.value = SpeedValueExtended_unavailable;
    object->xSpeed.confidence = SpeedConfidence_unavailable;
    object->ySpeed.value = SpeedValueExtended_unavailable;
    object->ySpeed.confidence = SpeedConfidence_unavailable;
rtobi commented 3 years ago

Had a similar problem a couple of times with CAM. You need to ensure that the value is in the range as specified in the corresponding standard. Else encoding/decoding may be an issue. Using datatypes of int, long, etc. does not ensure this.

inesbj commented 3 years ago

Hi @riebl : thanks for your help. Your code works also fine for me and I could get the source of the problem which is the data ranges as specified by the asn1c. @rtobi Yes you're right it was a data range problem. thanks.