You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Writing a MOOS app and need to post your array of data to ACOMMS_TRANSMIT_DATA?  Here's two slightly different ways.  

// better - pass a pointer to Notify along with the size 
m_Comms.Notify( "ACOMMS_TRANSMIT_DATA_BINARY", &packet[0], packet.size() );

// okay - convert to a string and pass to Notify
m_Comms.Notify( "ACOMMS_TRANSMIT_DATA", string( (char*) &packet[0], packet.size() ) );

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:

// perhaps we copied the string in onNewMail
string msg_string = msg.GetString();

// the .data() method gives us a pointer to the string's data in contiguous memory
memcpy(&data_received.packet_id, msg_string.data(), msg_string.size());
  • No labels