COM_CreatePacket

Generates a valid Bluetooth packet ready for transmission (i.e. sets length)

Contents

Syntax

bytes = COM_CreatePacket(CommandType, Command, ReplyMode, ContentBytes)

Description

bytes = COM_CreatePacket(CommandType, Command, ReplyMode, ContentBytes) creates a valid Bluetooth packet conform to the LEGO Mindstorms communication protocol. The CommandType specifies the telegram type (direct or system command (see the LEGO Mindstorms communication protocol documentation for more details)). This type is determined from the function name2commandbytes. The Command specifies the actual command according to the LEGO Mindstorms communication protocol. By the ReplyMode one can request an acknowledgement for the packet transmission. The two strings 'reply' and 'dontreply' are valid. The content byte-array is given by the ContentBytes.

The return value bytes represents the complete Bluetooth packet conform to the LEGO Mindstorms Communication protocol.

Note:

The activated ReplyMode should only be used if it is necessary. According to the official LEGO statement "Testing during development has shown that the Bluetooth Serial Port communication has some disadvantages when it comes to streaming data. ... One problem is a time penalty (of around 30ms) within the Bluecore chip when switching from receive-mode to transmit-mode. ... To handle the problem of the time penalty within the Bluecore chip, users should send data using Bluetooth without requesting a reply package. This will mean that the Bluecore chip won't have to switch direction for every received package and will not incur a 30ms penalty for every data package."

Example

   [type cmd] = name2commandbytes('PLAYTONE');
   content(1:2) = dec2wordbytes(frequency, 2);
   content(3:4) = dec2wordbytes(duration, 2);

   packet = COM_CreatePacket(type, cmd, 'dontreply', content);

See also

COM_SendPacket, COM_CollectPacket, name2commandbytes, dec2wordbytes,

Signature