【发布时间】:2022-10-03 05:42:28
【问题描述】:
我试图让我的节点在不更改消息中的任何数据的情况下相互通信。 就像节点 1 和 2 回显 tictocMsg 一样,节点 2 和 3 在这种情况下会回显不同的消息 rndMsg。 这对我怎么不起作用。
simple Txc1
{
gates:
input in1;
input in2;
output out1;
output out2;
}
//
// Two instances (tic and toc) of Txc1 connected both ways.
// Tic and toc will pass messages to one another.
//
network Tictoc1
{
@display(\"bgb=628,433\");
submodules:
tic: Txc1 {
@display(\"p=264,321\");
}
toc: Txc1;
rnd: Txc1 {
@display(\"p=474,100\");
}
connections allowunconnected:
toc.out1 --> tic.in1;
tic.out1 --> toc.in1;
toc.out2 --> rnd.in1;
rnd.out1 --> toc.in2;
}
我想让 toc 节点仅将 tictocMsg 发送到 tic 节点,将 rndMsg 发送到 rnd 节点
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
/**
* Derive the Txc1 class from cSimpleModule. In the Tictoc1 network,
* both the `tic\' and `toc\' modules are Txc1 objects, created by OMNeT++
* at the beginning of the simulation.
*/
class Txc1 : public cSimpleModule
{
protected:
// The following redefined virtual function holds the algorithm.
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
// The module class needs to be registered with OMNeT++
Define_Module(Txc1);
void Txc1::initialize()
{
// Initialize is called at the beginning of the simulation.
// To bootstrap the tic-toc-tic-toc process, one of the modules needs
// to send the first message. Let this be `tic\'.
// Am I Tic or Toc?
if (strcmp(\"tic\", getName()) == 0) {
// create and send first message on gate \"out\". \"tictocMsg\" is an
// arbitrary string which will be the name of the message object.
cMessage *msg = new cMessage(\"tictocMsg\");
send(msg, \"out1\");
}
if (strcmp(\"rnd\",getName())==0){
cMessage *msg = new cMessage(\"rndMsg\");
send(msg, \"out1\");
}
}
void Txc1::handleMessage(cMessage *msg)
{
// The handleMessage() method is called whenever a message arrives
// at the module. Here, we just send it to the other module, through
// gate `out\'. Because both `tic\' and `toc\' does the same, the message
send(msg,\"out1\");
// send out the message
}
我试图将其更改为
send(msg,\"in1\",\"out1\") ;
send(msg,\"in2\",\"out2\") ;
试过了
send(msg,out1)}
else{
send(msg,out2)}
}
到目前为止,两者都对我不起作用有什么办法可以实现吗?