Interfacing with a speaker (UART-commands)

Hello everyone!

Im trying to interface with a portable speaker, i got in contact with the manufacturer and they sent me a list off commands i can use to interface with it.

Im not really sure how the commands work, i know i have to send the data over the UART but the commands are a little strange, are they packets of HEX (4 bytes of hexadecimal)?

I would be really grateful if anybody could shine some light on this!

Some Commands:

BE 00 00 00 0c EB
BE 00 00 00 12 EB
BE 70 00 00 06 EB
BE 00 00 00 21 EB
BE 00 00 00 22 EB

It looks more like packets of 6 bytes. 0xbe is the start byte and 0xeb is the end byte. The four bytes in between build the actual command.

You can't put a zero byte in a string so you will have to send them as an array of bytes a specified count:

const byte CommandPlayPause[] = {0xBE, 0x00, 0x00, 0x00, 0x02, 0xEB};

  Serial.write(CommandPlayPause, sizeof CommandPlayPause);

johnwasser:
You can't put a zero byte in a string so you will have to send them as an array of bytes a specified count:

const byte CommandPlayPause[] = {0xBE, 0x00, 0x00, 0x00, 0x02, 0xEB};

Serial.write(CommandPlayPause, sizeof CommandPlayPause);

Thanks!
How would i go about receiving a commands with identical structure?

UNI-T:
Thanks!
How would i go about receiving a commands with identical structure?

My guess would be:

void loop()
{
  static chr buffer[MaximumCommandSize];
  static int index = 0;
  if (Serial.available())
  {
    char c = Serial.read();
    buffer[index++] = c;


    if (c == 0xBE)  // Start of command
    {
      index = 0;
      buffer[index++] = c;
    }
    else if (c == 0xEB && buffer[0] == 0xBE)  // End of command
    {
      processCommand(buffer);
      index = 0;
    }
    else if (index >= MaximumCommandSize)
    {
      index = 0;  // Command too long
    }
  }
}