我在 omnet++4.6 中使用 Veins 4a2。我想将函数中包含的信息作为消息发送给邻居节点。怎样才能做到这一点?.cc 中的函数如下所示:
void TraCITestApp::append2List(short carId, short firstEmptyArrayIndex, simtime_t messageTime, double theta, std::string vType) {
listedVehicles[firstEmptyArrayIndex].id = carId; // ~~here the Id is changed name to car ID.
listedVehicles[firstEmptyArrayIndex].lastSeenAt = messageTime;
listedVehicles[firstEmptyArrayIndex].vType = vType;
listedVehicles[firstEmptyArrayIndex].theta = theta;
EV << "Appending car with id " << carId <<" type "<< vType << " to the list of known vehicle." << endl;
/* @brief Increase related counting variable
* The total number always increased for each vehicle
*/
currentNumberofTotalDetectedVehicles++;
}
.
void TraCITestApp::showInfo_D(short counter){
EV << "Listed Table for Truthtelling:" << endl;
for (int i = 0; i < counter; i++)
{ EV << "Serial [" << i << "] " <<"ID="<< listedVehicles[i].id << "\tTruthtelling prob.\t" << listedVehicles[i].theta <<endl;
std::ofstream tracefile;
tracefile.open("traceFiledata.txt", std::ios_base::app);
tracefile << "============================================";
tracefile << "MyID=" << getMyID() << ";" <<"Serial [" << i << "] " <<"ID="<< listedVehicles[i].id << ";" << "Time=" << simTime() << ";" << "TTP=" << listedVehicles[i].theta << getMetaData() << std::endl;
tracefile.close();
}
EV << "Total number of detected vehicle\t: " << currentNumberofTotalDetectedVehicles << endl;
}
我可以将方法void TraCITestApp::onData(WaveShortMessage* wsm)
称为showInfo_D(currentNumberofVehicles);
但是我怎样才能将此信息发送给其他邻居车辆。我想发送和累积每辆车的信息,但只发送初始信息,即我不发送所有累积的信息。