0

I have a structure

struct info{
int id;
int color;
double speed;
}

How do I send it using senddown?
I am currently using formatted string to send the struct

char buff[100];
info inf = {1,1,1.4}
snprintf(buff , sizeof(buff), "%d,%d%f" ,inf.id, inf.color,inf.speed);
wsm->setWsmData(buff);
sendDown(wsm);

But I need to extract all parameters from string and make then make a new struct.
Is it possible that I can just senddown the structure such that I don't need to parse it on every receiving node.

thardes2
  • 1,162
  • 12
  • 28
Vishal
  • 145
  • 7
  • 1
    If anyone other than me is wondering, `veins` is a vehicle simulation framework: http://veins.car2x.org/ – Morten Jensen Jan 07 '19 at 14:20
  • In general, serializing the data to text and transmitting it in that form is the safest alternative. I'm uncertain what additional guarantees veins might provide, but in the general case, you cannot assume that the source and destination machines will interpret the binary representation of your structure or of its individual members the same way. – John Bollinger Jan 07 '19 at 14:23

1 Answers1

1

You can create your own message definition, wich inherits the WaveShortMessage / DemoSafetyMessage (Depending on the Veins version you're using.). The TicToc Tutorial shows you how to do this.

thardes2
  • 1,162
  • 12
  • 28