Skip to content

Command Structure

IoliteCoding edited this page Aug 5, 2024 · 1 revision

Command Structure

This document describes the structure of commands used for communication over a serial interface. Each command is a structured message consisting of several key components. The protocol is designed to ensure reliable and efficient data transmission.

Command Components

Each command consists of the following components:

  1. Start Byte:

    • Value: 0xFE (254)
    • Purpose: Marks the beginning of a command message.
  2. Message Length:

    • Purpose: Specifies the total length of the command excluding the start byte, stop byte, and the length byte itself.
    • Value Range: The length can range from 0x00 to 0xFD (253) since 0xFE and 0xFF are reserved.
  3. Address:

    • Purpose: Identifies the target or type of the command.
    • Format: At least one byte is required to specify the address. Addresses use a base-200 numbering system, allowing for extended address ranges.
  4. Data (Optional):

    • Purpose: Contains the command's payload or additional information.
    • Format: May include zero or more bytes. The data field is optional and can be omitted if not needed.
  5. Stop Byte:

    • Value: 0xFF (255)
    • Purpose: Indicates the end of the command.

Example Commands

Here are examples illustrating commands with and without data:

Command with Data

Start Message Length Address Data Stop
0xFE 0x02 0x0A 0x7C 0xFF
  • 0xFE: Start byte.
  • 0x02: Message length indicates a total of 2 bytes for address and data.
  • 0x0A: Address byte for command number 10.
  • 0x7C: Data byte ('|' in ASCII).
  • 0xFF: Stop byte.

Command without Data

Start Message Length Address Stop
0xFE 0x01 0x0B 0xFF
  • 0xFE: Start byte.
  • 0x01: Message length indicates 1 byte for the address.
  • 0x0B: Address byte for command number 11.
  • 0xFF: Stop byte.

Addressing System

  • Single Byte Address: Supports values from 0x00 to 0xC7.
  • Multiple Byte Address: For larger address ranges, multiple bytes can be used, leveraging a base-200 system.

Examples of Extended Addresses

  • Address 316:

    • Requires two bytes: 0x01 (1) and 0x74 (116)
    • Calculation: (1 * 200^1) + (116 * 200^0)
  • Address 605:

    • Requires two bytes: 0x03 (3) and 0x05 (5)
    • Calculation: (3 * 200^1) + (5 * 200^0)
  • Address 456703:

    • Requires three bytes: 0x11 (11), 0x53 (83), 0x67 (103)
    • Calculation: (11 * 200^2) + (83 * 200^1) + (103 * 200^0)

Conclusion

The command structure is designed for flexible and efficient serial communication, supporting optional data fields and an extended addressing system while maintaining a consistent framework for transmitting commands and data.

Clone this wiki locally