omnet 收发信息

发送

void TMEDRSU::handleSelfMsg(cMessage* msg)
{
    // this method is for self messages (mostly timers)
    // it is important to call the DemoBaseApplLayer function for BSM and WSM transmission
    if(msg == sendMsgToFindPath){

        hello* sp = new hello("hello");
        sp->setPosition(RSUposition);
        sp->setSendTime(time);
        sp->setSenderId(myApplAddr());
        sp->setBeginId(RSUID);
        sp->setEndid(descarID);
        populateWSM(sp);
        sendDown(sp); 

        return ;
    }
    DemoBaseApplLayer::handleSelfMsg(msg); //note
}

接受

void TMEDRSU::handleLowerMsg(cMessage* msg){
    if(  dynamic_cast<hello*>(msg)){

         hello* bc = dynamic_cast<hello*>(msg);
         EV<<"sendID= "<<bc->getSenderId()<<endl;

         EV<<"position= "<<bc->getPosition()<<endl;
    }
    DemoBaseApplLayer::handleLowerMsg(msg);
}

一个简单的收发过程就结束啦

当然你需要初始化创立一个hello类型的message,然后定义hello里面的信息类型,并在主文件里面引用

namespace veins;

class BaseFrame1609_4;
class noncobject Coord;
class LAddress::L2Type extends void;

packet hello extends BaseFrame1609_4 {
    string demoData;
    LAddress::L2Type senderAddress = -1;
    int serial = 0;
    Coord position ;


    double speed = 0;
    double speedchanged=0;
    double dertSpeedScale = 0;
    int beginId ;
    int endid ;
    simtime_t sendTime;
    int direc = -1;// 0 1 2 3 上下右左
 
    int senderId;
    int senderType;
    int nextRelayCarId = -1;  
    int nextRSUId = -1;
    int path[100];
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值