0

I would like to make a new message type called wsm_info.

In this message type, I want to include a vehicle structure, as it follows:

struct vehicle{
   int vehicle_id;
   Coord vehicle_pos;
   float speed;
};

In the veins example there is a function called: prepareWSM that's declared in BaseWaveApplLayer.h. This function is a virtual WaveShortMessage* type.

If the wsm_info was inherented from WaveShortMessage I wouldn't need to write and declare a new prepareWSM for wsm_info, right?

So how can I make this wsm_info message inherented of WaveShortMessage?

I tried to write like this in the wsm_info.h:

class wsm_info : public WaveShortMessage

Instead of, that was written previously:

class wsm_info : public ::omnetpp::cPacket

But the error that I get is the following one:

cannot initialize a variable of type wsm_info * with an rvalue of type WaveShortMessage

The full code of my msg_info is below:

cplusplus {{
#include "veins/base/utils/Coord.h"
#include "veins/modules/messages/WaveShortMessage_m.h"
}}

class noncobject Coord;

class WaveShortMessage;

struct vehicle {
        int vehicle_id;
        Coord vehicle_pos;
        float speed;
    };

message wsm_info extends WaveShortMessage {
    //Version of the Wave Short Message
    int wsmVersion = 0;
    //Determine which security mechanism was used
    int securityType = 0;
    //Channel Number on which this packet was sent
    int channelNumber;
    //Data rate with which this packet was sent
    int dataRate = 1;
    //Power Level with which this packet was sent
    int priority = 3;
    //Unique number to identify the service
    int psid = 0;
    //Provider Service Context
    string psc = "Service with some Data";
    //Length of Wave Short Message
    int wsmLength;

    vehicle data;

    int senderAddress = 0;
    int recipientAddress = -1;
    int serial = 0;
    Coord senderPos;
    simtime_t timestamp = 0;
}

Can anyone take a look on my code and point me where is wrong and why? Thanks!

pb772
  • 539
  • 1
  • 3
  • 14

3 Answers3

4

If i get you right, you want to extend your wsm_info.msg, is that correct?

According to THIS question, you can modify your wsm_info.msg in the following way:

cplusplus {{
#include "veins/modules/messages/WaveShortMessage_m.h"
}}

class WaveShortMessage;

message wsm_info extends WaveShortMessage {
   int vehicle_id;
   Coord vehicle_pos;
   float speed;
}
Community
  • 1
  • 1
Dirk Hennsen
  • 135
  • 7
  • I did what you suggested but still get the same error when I try to build the project: `cannot initialize a variable of type wsm_info * with an rvalue of type WaveShortMessage`. It happens when `wsm_info* wsm = prepareWSM("data",dataLengthBits, channel, dataPriority, -1,2)` – pb772 Feb 28 '17 at 00:18
4

The msg_info.msg should have the following content:

cplusplus {{
#include "veins/modules/messages/WaveShortMessage_m.h"
}}

class noncobject Coord;

struct vehicle {
   int vehicle_id;
   Coord vehicle_pos;
   float speed;
};

class WaveShortMessage;

packet wsm_info extends WaveShortMessage {
    vehicle data;
}

You cannot use prepareWSM() because it creates a WaveShortMessage object which cannot be cast to wsm_info. Instead you may write a new method, for example:

  1. In /veins/src/veins/modules/application/ieee80211p/BaseWaveApplLayer.h add:

    #include "veins/modules/messages/wsm_info_m.h"
    

    and in the class add the declaration:

    wsm_info* prepare_wsm_info(std::string name, int dataLengthBits, t_channel channel, int priority, int rcvId, int serial=0);
    
  2. In /veins/src/veins/modules/application/ieee80211p/BaseWaveApplLayer.cc add:

    wsm_info*  BaseWaveApplLayer::prepare_wsm_info(std::string name, int lengthBits, t_channel channel, int priority, int rcvId, int serial) {
    wsm_info* wsm = new wsm_info(name.c_str());
    // ... content similar to prepareWSM()
    }
    
  3. In order to set vehicle structure you can just write:

    wsm_info* info = prepare_wsm_info(/* parameters */);
    vehicle veh;
    veh.speed = 60;
    veh.vehicle_id = 3;
    // ...
    
    info->setData(veh);
    

Alternatively you can add parameters for vehicle in the definition of prepare_wsm_info().

Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
0

where must be declare wsm_info.msg ?in which folder?

  • `veins-veins-4.4/src/veins/modules/messages/msg_info.msg` – pb772 Apr 03 '17 at 01:09
  • i want to create a packet collector with a specific structure,is it true that i must define a packet collector.msg like msg_info.msg and define my variables and extend from waveshortmessage.is it true? where must be add this:"and in the class add the declaration: 'code' wsm_info* prepare_wsm_info(std::string name, int dataLengthBits, t_channel channel, int priority, int rcvId, int serial=0);' "pb772" – hana rahmati Apr 06 '17 at 22:22
  • there are three files: msg_info.msg, msg_info.h (in this file there are msg_info functions definitions), msg_info.cc(in this file, functions declarations) – pb772 Apr 07 '17 at 08:51
  • is it true that in BaseWaveApplLayer.h in protected add this? `virtual PacketCollector* prepareWSM(std::string name, int dataLengthBits, t_channel channel, int priority, int rcvId, int serial=0);` @pb772 – hana rahmati Apr 07 '17 at 12:52