0

I am using Veins 4a2 in omnet++4.6. I would like to send the information contained in a function as a message to the neighbor nodes. How can achieve this? the function in .cc looks like this:

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;

}

I can call the method in void TraCITestApp::onData(WaveShortMessage* wsm) as showInfo_D(currentNumberofVehicles);

But how can i send this information to other neighbor vehicles. I want to send and accumulate the information in each vehicles but only the initial information i.e i dont send all the accumulated information.

user4786271
  • 1,555
  • 13
  • 18
Zecar
  • 29
  • 7
  • what is the specific information you want to send? which variable(s) contain that information? Why is `void TraCITestApp::append2List()` function included in this question at all? – user4786271 Mar 03 '16 at 09:02
  • I want to send the listedVehicles[i].id, theta value, and simulation time along with the WSM message if possible. I added append2List as it is linked with the showInfo_D() method. Is it possible to send this message as well as accumulated at the receiver side? – Zecar Mar 03 '16 at 11:17

1 Answers1

1

You can extend the WSM to contain the information that you want to exchange. Here is an example of extending WSM and creating a message for your own purpose.

Simply declare variables inside the message definition that will hold your data

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

class WaveShortMessage;

message MyAppsPacket extends WaveShortMessage {
    string sourceAddress;           
    string destinationAddress;      
    simtime_t sendingTime;
    string vehicleID;
    whateverType theta;
}

Then when generating MyAppsPacket you can do:

MyAppsPacket->setTheta(theta);
MyAppsPacket->setSendingTime(simeTime());
MyAppsPacket->setVehicleID(listedVehicles[i].id;

Unfortunately I can not give you a read-to-use solution since I don't know the very details of your code, but this should give you a rough idea of what you should do.

Community
  • 1
  • 1
user4786271
  • 1,555
  • 13
  • 18
  • HI, I am trying to use structure in waveshortmessage.msg as: cplusplus {{ #include "veins/base/utils/Coord.h" //Added structure struct knownVehicle1 { int ids; double theta1; simtime_t lastSeenAt; }; }} class noncobject Coord; class noncobject knownVehicle1; packet WaveShortMessage {.....knownVehicle1 knownVeh; // added..} how to send the structure and receive in .cc so that I can store and collect all the theta values... – Zecar Mar 05 '16 at 10:20
  • Also, I tried your method but where should I generate "MyAppsPacket" and send this and receive this (may be receive @ onData() method). I need to send the table with ID and theta value as well as collect these values from all the neighbor nodes after accident. – Zecar Mar 05 '16 at 10:29
  • I wanted to send the structure as: void attack1::sendMessage1(double theta1) { t_channel channel = dataOnSch ? type_SCH : type_CCH; EWaveShortMessage* wsm = prepareWSM("data", dataLengthBits, channel, dataPriority, -1,2); knownVehicle1 * veh = new knownVehicle1(); veh->theta1= 0.58; wsm->setKnownVeh(*veh); sendWSM(wsm); } and on OnData: method I used sendMessage1(wsm->getKnownVeh().theta1); But I faced errors like:error: no matching function for call to 'EWaveShortMessage::setKnownVeh(knownVehicle1&)' wsm->setKnownVeh(*veh); – Zecar Mar 06 '16 at 13:56