创建WSM inherented消息

时间:2017-02-27 09:12:52

标签: omnet++ veins

我想创建一个名为wsm_info的新消息类型。

在此消息类型中,我想要包含一个车辆结构,如下所示:

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

在静脉示例中,有一个名为prepareWSM的函数,它在BaseWaveApplLayer.h中声明。此函数是virtual WaveShortMessage*类型。

如果wsm_info来自WaveShortMessage,我就不需要为prepareWSM撰写并宣布新的wsm_info了,对吧?

那么我怎样才能将这条wsm_info讯息改为WaveShortMessage

我试着在wsm_info.h

中写这样的内容
class wsm_info : public WaveShortMessage

而不是之前写的:

class wsm_info : public ::omnetpp::cPacket

但我得到的错误如下:

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

我的msg_info的完整代码如下:

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;
}

任何人都可以查看我的代码并指出我哪里出错了,为什么?谢谢!

3 个答案:

答案 0 :(得分:4)

如果我说得对,你想扩展你的wsm_info.msg,这是正确的吗?

根据THIS问题,您可以通过以下方式修改wsm_info.msg:

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

class WaveShortMessage;

message wsm_info extends WaveShortMessage {
   int vehicle_id;
   Coord vehicle_pos;
   float speed;
}

答案 1 :(得分:3)

msg_info.msg应包含以下内容:

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;
}

您无法使用prepareWSM(),因为它会创建一个无法转换为WaveShortMessage的{​​{1}}对象。相反,您可以编写一个新方法,例如:

  1. wsm_info添加:

    /veins/src/veins/modules/application/ieee80211p/BaseWaveApplLayer.h

    并在类中添加声明:

    #include "veins/modules/messages/wsm_info_m.h"
    
  2. wsm_info* prepare_wsm_info(std::string name, int dataLengthBits, t_channel channel, int priority, int rcvId, int serial=0); 添加:

    /veins/src/veins/modules/application/ieee80211p/BaseWaveApplLayer.cc
  3. 为了设置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() } 结构,您只需编写:

    vehicle
  4. 或者,您可以在wsm_info* info = prepare_wsm_info(/* parameters */); vehicle veh; veh.speed = 60; veh.vehicle_id = 3; // ... info->setData(veh); 的定义中添加vehicle的参数。

答案 2 :(得分:0)

哪里必须在哪个文件夹中声明wsm_info.msg?