Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The third MOOS variable type

While we usually thing of MOOS variables as having only two types - double and string - a third type called "binary string" is also defined.  While any string can hold binary data, the character 0x00 is special and usually used to indicate the end of a string.  That means if you tried to send some binary data that contained the byte 0x00 in the middle using a normal string MOOS variable, everything after the 0x00 would be lost.  A binary string MOOS variable keeps track of its data length separately so it knows to keep looking for data after the 0x00.  

iacomms_driver has two input variables to transmit data - ACOMMS_TRANSMIT_DATA and ACOMMS_TRANSMIT_DATA_BINARY.  As expected, the first is a string variable and the second a binary string.  You can still post binary Writing a MOOS app and need to post your array of data to ACOMMS_TRANSMIT_DATA ?  Here's two slightly different waysas long as there isn't an 0x00.  Both messages are handled identically inside the driver.  

Implementation

First we look at how to post binary data to a MOOS variable.  

Code Block

string data_payload = "hello world";
vector<unsigned char> packet;


// 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() ) );

...