# Config command data frame
CMD_HEADER = "FDFCFBFA"
CMD_MFR = "04030201"

# Command Constants
CMD_CONFIG_ENABLE = "0400FF000100"
CMD_CONFIG_DISABLE = "0200FE00"
CMD_PARAM_EDIT = "14006000"
CMD_PARAM_READ = "02006100"
CMD_ENG_MODE_ENABLE = "02006200"
CMD_ENG_MODE_DISABLE = "02006300"
CMD_GATE_SENS_EDIT = "14006400"
CMD_FIRMWARE_READ = "0200A000"
CMD_BAUD_RATE_SET = "0400A100"
CMD_FACTORY_RESET = "0200A200"
CMD_RESTART = "0200A300"
CMD_BT_ENABLE = "0400A4000100"
CMD_BT_DISABLE = "0400A4000000"
CMD_BT_MAC_QUERY = "0400A5000100"

# Read constants
REF_READ_HEADER = "F4F3F2F1"

# Parameter Constants

# Configure base settings
PARAM_MAX_MOVING_GATE = "0000"
PARAM_MAX_STATIC_GATE = "0100"
PARAM_EMPTY_DURATION = "0200"
# Configure individual gates
PARAM_GATE_SELECT = "0000"
PARAM_MOVING_GATE_WORD = "0100"
PARAM_STATIC_GATE_WORD = "0200"
# Special case
PARAM_SELECT_ALL_GATE = "FFFF"

# Set Baud Rate
PARAM_BAUD_9600 = "0100"
PARAM_BAUD_19200 = "0200"
PARAM_BAUD_38400 = "0300"
PARAM_BAUD_57600 = "0400"
PARAM_BAUD_115200 = "0500"
PARAM_BAUD_230400 = "0600"
PARAM_BAUD_256000 = "0700"
PARAM_BAUD_460800 = "0800"

PARAM_ACCEPTABLE_BAUDS = [PARAM_BAUD_9600  ,
                          PARAM_BAUD_19200 ,
                          PARAM_BAUD_38400 ,
                          PARAM_BAUD_57600 ,
                          PARAM_BAUD_115200,
                          PARAM_BAUD_230400,
                          PARAM_BAUD_256000,
                          PARAM_BAUD_460800]

PARAM_DEFAULT_BAUD = PARAM_BAUD_256000

# I know, it's very hacky lol
BAUD_LOOKUP = {PARAM_BAUD_9600  : 9600,
             PARAM_BAUD_19200 : 19200,
             PARAM_BAUD_38400 : 38400,
             PARAM_BAUD_57600 : 57600,
             PARAM_BAUD_115200: 115200,
             PARAM_BAUD_230400: 230400,
             PARAM_BAUD_256000: 256000,
             PARAM_BAUD_460800: 460800}

# Ack Constants
ACK_CONFIG_ENABLE = "0800FF01000001004000"

# Validation Constants
MAX_BUFFER_SIZE = 64 # 32 byte buffer read
GATE_MIN = 0
GATE_MAX = 8
TIMEOUT_MIN = 0
TIMEOUT_MAX = 65535
SENS_MIN = 0
SENS_MAX = 100

# Read Parameter Indices
REF_MAX_MOVING_GATE = 12
REF_MAX_STATIC_GATE = 13

REF_MOVING_GATE_SENS_0 = 14
REF_MOVING_GATE_SENS_1 = 15
REF_MOVING_GATE_SENS_2 = 16
REF_MOVING_GATE_SENS_3 = 17
REF_MOVING_GATE_SENS_4 = 18
REF_MOVING_GATE_SENS_5 = 19
REF_MOVING_GATE_SENS_6 = 20
REF_MOVING_GATE_SENS_7 = 21
REF_MOVING_GATE_SENS_8 = 22

REF_STATIC_GATE_SENS_0 = 23
REF_STATIC_GATE_SENS_1 = 24
REF_STATIC_GATE_SENS_2 = 25
REF_STATIC_GATE_SENS_3 = 26
REF_STATIC_GATE_SENS_4 = 27
REF_STATIC_GATE_SENS_5 = 28
REF_STATIC_GATE_SENS_6 = 29
REF_STATIC_GATE_SENS_7 = 30
REF_STATIC_GATE_SENS_8 = 31

REF_EMPTY_TIMEOUT = 32

REF_FW_MAJOR_HEAD = 12
REF_FW_MAJOR_TAIL = 14
REF_FW_MINOR_HEAD = 14
REF_FW_MINOR_TAIL = 18

REF_BT_ADDR_HEAD = 10
REF_BT_ADDR_TAIL = 16

REF_NORMAL_PACKET_LEN = 15
REF_ENG_MODE_PACKET_LEN = 37

REF_PACKET_CRC = "5500"

REF_TARGET_TYPE = 4

REF_TARGET_LOOKUP = {0: "No Target",
                     1: "Moving Target",
                     2: "Static Target",
                     3: "Moving + Static Target"}

REF_TARGET_MOVE_DIST_HEAD = 5
REF_TARGET_MOVE_DIST_TAIL = 6
REF_TARGET_MOVE_ENERGY = 7
REF_TARGET_STATIC_DIST_HEAD = 8
REF_TARGET_STATIC_DIST_TAIL = 9
REF_TARGET_STATIC_ENERGY = 10
REF_DETECT_DIST = 11

# Cut out 1-7 for brevity
REF_MOVING_GATE_ENERGY_0 = 14
REF_MOVING_GATE_ENERGY_8 = 23

REF_STATIC_GATE_ENERGY_0 = 24
REF_STATIC_GATE_ENERGY_8 = 33

REF_RADAR_POLING_RATE = 10 # Radar updates at 10Hz

REF_PACKET_CRC_IDX = -2

REF_ENG_CHECK_IDX = 0
REF_ENG_CHECK = 35