The KarateLight uses a very simple protocol to transfer data.

Each command consists of a 4-byte header and up to 60 bytes payload data.
For larger transfers data has to be send in multiple packets. This limitation
is due to the fact that the USB-Endpoint-Buffers on the Pic-Microcontroller are
only 64 bytes large.

After each command send, the controller responds with an ACK-Message using the
same format convention as for data send to the controller.

Structure of the 4-Byte-Header:
Pos     Value
0       Sync-Byte, always 0xAA for the host, 0x55 for the controller
1       Command/Staus-Byte. See the command or status list
2       Checksum-Byte. Contains a simple XOR-Checksum over all bytes, except itself
3       Lenght-Byte. Number of Payload bytes Transmitted after the header.

Status-List: (Send by the controller to the host)
CMD_SYS_ACK = 0x01          The command has ben successfully processed
CMD_SYS_NACK = 0x02         Error: while processing the command
CMD_SYS_NACK_LENGTH = 0x03  Error: payload-lenght mismatch
CMD_SYS_NACK_CHECK = 0x03   Error: Checksum mismatch
CMD_SYS_NIMP = 0xFF         Error: Command not implemented
CMD_SYS_IR = 0x10           (not used)
CMD_SYS_DATA = 0x20         Same as ACK, but with payload-data

Command-List: (Send by the host to the controller)
ID-Code                      Payload   Description
CMD_GET_VERSION = 0x01       0         Read the Firmware Version
CMD_GET_HARDWARE = 0x02      0         Read the Hardware Version
CMD_GET_TLC_PWM_VALUE = 0x14 0         Read the PWM-Callibration Value.
CMD_SET_TLC_PWM_VALUE = 0x15 2         Set PWM-Callibration Value (only for debugging)
CMD_SET_DATA_00 = 0x20       32        Send a batch of 32 data bytes (1st. slot)
...                          32        ... 
CMD_SET_DATA_0F = 0x2F       32        Send a batch of 32 data bytes (16th. slot)
CMD_GET_N_CHANNELS = 0x30    0         Read the number of Channels
CMD_READ_ADC0 = 0x40         0         Read the value of A/D-Channel 0 (may be used for ambient light compensation)
CMD_READ_EEPROM = 0x50       1         Read a single byte from the eeprom
CMD_WRITE_EEPROM = 0x51      2         Write a single byte to the eeprom
CMD_BOOT_REQUEST = 0x80      0         Start bootload-sequence
CMD_BOOT_START = 0x81        2         Enter bootload-sequence

Example:
Host Sends "0xAA 0x01 0xAB 0x00" (Read Firmware Version)
Controller Replies "0x55 0x20 0x44 0x01 0x30" (Send Data, Value = 0x30)


For more information please take a look at the firmware. The protocol handler is in the file comm.c.
