如何在静脉Car2X模拟器中从TraCIDemoRSU11p访问TraCI命令界面

How to access TraCI command interface from TraCIDemoRSU11p in Veins Car2X simulator?

本文关键字:TraCIDemoRSU11p 访问 TraCI 界面 命令 模拟器 Car2X      更新时间:2023-10-16

我想从 OMNet++ 的 Veins Source 中的 RSU 模型应用层访问 TraCI 的命令接口。但我找不到。谁能帮我这样做?

请注意,在RSU节点的情况下,我没有将TraciMobility作为父模块。它只有BaseMobility,这就是我希望它拥有的。现在我想访问命令界面,以便该 RSU 可以执行相扑指令,例如更改交通信号灯和获取感应回路数据。

Veins 4.3 提供了一个TraCIScenarioManagerAccess辅助类,可用于快速访问代码中处理 TraCI 的类(以及通过此访问包装命令接口的类)。

有关如何使用此接口的示例,请参阅TraCIScreenRecorder中的以下代码:

#include "veins/modules/mobility/traci/TraCIScenarioManager.h"
#include "veins/modules/mobility/traci/TraCICommandInterface.h"
[...]
TraCIScenarioManager* manager = TraCIScenarioManagerAccess().get();
ASSERT(manager);
TraCICommandInterface* traci = manager->getCommandInterface();
if (!traci) {
    error("Cannot create screenshot: TraCI is not connected yet");
}
TraCICommandInterface::GuiView view = traci->guiView(par("viewName"));
view.takeScreenshot(filename);

在静脉 4.4 中,我尝试从 TraCIDemoRSU11p 访问 TraCI 命令接口。最后我能够访问,我在TraCIDemoRSU11p.h中插入以下代码:

#include "veins/modules/mobility/traci/TraCICommandInterface.h"
[...]
using Veins::TraCICommandInterface;
[...]   
protected:
        TraCICommandInterface* traci;

然后,您可以访问TraCICommandInterface。祝你好运。