Omnet ++,将引发cRuntimeError异常

时间:2018-07-15 15:21:34

标签: omnet++ veins

我当前正在使用Omnet ++和静脉,并且我突然出现此运行时错误,并且我无法理解它以进行正确修复。

  

模块(TraCIDemoRSU11p)中的错误RSUExampleScenario.rsu [0] .appl   (id = 8)事件#6180,t = 53.956510612297:索引号为220的数组   220。       由于出现debug-on-errors = true配置选项,因此会在上述异常上进行TRAPPING。调试器准备好了吗?

我假设这可能与我从RSU发送到带有此代码的车辆的消息有关,但是我不确定它是如何相关的。

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

}}
class WaveShortMessage;


message DelayedFromControllerMessage extends WaveShortMessage {
    string vehiclesList [220] ;

}

我正在使用omnet ++版本:5.0和Veins 4.4

编辑后,我在以下位置使用了数组:

1-

void TraCIDemoRSU11p::sendDelayedMessage(std::list<const char *> vehicleList) {
    sentDelayedMessage = true;
    //vehicleList = {};
    t_channel channel = dataOnSch ? type_SCH : type_CCH;
    DelayedFromControllerMessage* dsm = prepareDelayedSM("delayed",dataLengthBits, channel, dataPriority, -1,2,vehicleList);

    std::list<const char *>::iterator it = vehicleList.begin();
    //const char * v;
    char* vx = new char [100];
    vx[0] = '\0';
    for(int i=0; i<vehicleList.size(); i++){
        //v =*it;
        strcpy(vx,*it);
        //vx = *it;
        ++it;
        dsm->setVehiclesList(i, vx);
     }
    if (sendDelayedEvt->isScheduled()) {
        cancelAndDelete(sendDelayedEvt);
    }else {
        delete sendDelayedEvt;
    }
    sendDelayedEvt = new cMessage("delayed evt", SEND_DELAYED_EVT); // create event object to use it in timing

    simtime_t offSet = dblrand() * (par("beaconInterval").doubleValue());
    TimeStart = simTime() + offSet;
    scheduleAt(TimeStart, sendDelayedEvt);
    sendDelayedSM(dsm);

}

2-

DelayedFromControllerMessage*  BaseWaveApplLayer:: prepareDelayedSM(const char * name, int lengthBits, t_channel channel, int priority, int rcvId,int serial,std::list<const char *>vehicleList ) {
    DelayedFromControllerMessage* dsm =       new DelayedFromControllerMessage(name);

    dsm->addBitLength(headerLength);
    dsm->addBitLength(lengthBits);

    switch (channel) {
        case type_SCH: dsm->setChannelNumber(Channels::SCH1); break; //will be rewritten at Mac1609_4 to actual Service Channel. This is just so no controlInfo is needed
        case type_CCH: dsm->setChannelNumber(Channels::CCH); break;
    }

    dsm->setPsid(0);
    dsm->setPriority(priority);
    dsm->setWsmVersion(1);
    dsm->setTimestamp(simTime());
    dsm->setSenderAddress(myId);
    dsm->setRecipientAddress(rcvId);
    dsm->setSenderPos(curPosition);
    dsm->setSerial(serial);



    std::list<const char *>::iterator it = vehicleList.begin();
    const char * v;

       for(int i=0; i<vehicleList.size(); i++){
           v =*it;
           ++it;
           VLvar1.push_back(v);
           dsm->setVehiclesList(i, v);
       }



    if ((std::string)name == "beacon") {
        DBG << "Creating Beacon with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }
    if ((std::string)name == "delayed") {
        DBG << "Creating Data with Priority " << priority << " at Applayer at " << dsm->getTimestamp() << std::endl;
    }

    return dsm;
}

3-

void MyTraCIDemo11p::onDataDelayed(DelayedFromControllerMessage* dsm) {
    int x = 0;
    std::string vehichleId = mobility->getExternalId();

        for (int i=0 ; i < dsm->getVehiclesListArraySize();i++)
        {
            vehicleList.push_back(std::string(dsm->getVehiclesList(i)));

        }


        ttry = std::find(vehicleList.begin(), vehicleList.end(), vehichleId);
        if (vehichleId == *ttry){
            x = 1;
        }


        if (state == QUEUING  && x == 1){
            findHost()->bubble("Received ");
             state = WAITING;
             stateToString(state);
        }
}

该消息应从RSU发送到车辆。

3 个答案:

答案 0 :(得分:1)

即使没有从应用程序(foreach ($patients as $key => $item) { if (count($item['data']) < 2) continue; $labels[] = $item['month']; usort($labels, "compare_months"); $labels = array_unique($labels); $chartData[ $item['brand_name'] ]['data'][] = $item['patientsCount']; $chartData[ $item['brand_name'] ]['brand_data'] = [ "name" => $item['brand_name'], "color" => $item['color'] ]; } foreach ($chartData as $item) { $pointRadius++; if (count($item['data']) < 2) continue; $dataSet[] = [ 'label' => $item['brand_data']['name'], 'data' => $item['data'], 'pointRadius' => $pointRadius, 'fill' => false, 'borderWidth' => 1, 'backgroundColor' => "#" . $item['brand_data']['color'], 'borderColor' => "#" . $item['brand_data']['color'], ]; } $finalData[] = [ 'labels' => $labels, 'datasets' => $dataSet ]; )或正在使用的配置文件中看到实际的代码,我猜您也在试图从数组中获取最后一个元素(元素220)。

该错误消息已经说明了问题所在。您的数组大小为220,并且由于数组索引从0开始,因此您尝试使用不可能的索引220。因此,要寻址数组中的最后一个元素,必须使用索引221。

答案 1 :(得分:0)

我不确定这是否是您出错的原因:

ttry = std::find(vehicleList.begin(), vehicleList.end(), vehichleId);
    if (vehichleId == *ttry){
        x = 1;
    }

但是,最好这样写:

    if (std::find(vehicleList.begin(), vehicleList.end(), vehichleId) !=  vehicleList.end()){
        x = 1;
    }

如果不找到查找迭代器(即*ttry),我不建议引用它,就像引用*(vehicleList.end())一样。

在我看来,您有两个veichleList变量,一个是dsm中的数组,另一个是向量。它是否正确?如果是,则应确保veichleList.size()始终小于或等于220。

检查本教程,以了解如何在omnet ++中调试项目: https://docs.omnetpp.org/tutorials/tictoc/part2/

答案 2 :(得分:0)

所以我最终还是找到了解决此问题的方法。

这是通过这样做的:

null

=====

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

}}
class WaveShortMessage;


message DelayedFromControllerMessage extends WaveShortMessage {
    string vehiclesList [] ;

}

我删除了数组大小,并使用while循环在BaseWaveApplLayer :: prepareDelayedSM中放置了手动计数器。我考虑过发布解决方案以在遇到类似问题时帮助其他人。 :)