...
Writing a MOOS app and need to post your array of data to ACOMMS_TRANSMIT_DATA? Here's two ways - one good and one bad:slightly different ways.
Code Block |
---|
// badbetter - pass a pointer to Notify along with the size m_Comms.Notify( "ACOMMS_TRANSMIT_DATA_BINARY", &packet[0], packet.size() ); // goodokay - convert to a string and pass to Notify m_Comms.Notify( "ACOMMS_TRANSMIT_DATA", string( (char*) &packet[0], packet.size() ) ); |
While these two methods might look the same, and in fact calling the first will ultimate use the same string constructor as the second inside the Notify method, they do have slightly different outcomes. Using the first method will flag the message as a binary string while the latter will flag it as a normal string. Just like a moos variable can't be a double and a string, it also can't be a binary string and a normal string (even though they're the same)The first method will yield a binary string moos variable with the second will give us just a normal string. The first is safer because it will correctly handle an 0x00 value whereas the second will not. We want our variables to be flagged as normal strings only, so use the second method. To get your data from ACOMMS_RECEIVED_DATA on the receiving side:
...