#ifndef DEFINE_H_
#define DEFINE_H_

// ************************* CAN通讯 ************************** //
// CAN的比特率值
#define CAN_BITERATE_10000 10000
#define CAN_BITERATE_20000 20000
#define CAN_BITERATE_50000 50000
#define CAN_BITERATE_100000 100000
#define CAN_BITERATE_125000 125000
#define CAN_BITERATE_250000 250000
#define CAN_BITERATE_500000 500000
#define CAN_BITERATE_800000 800000
#define CAN_BITERATE_1000000 1000000

// CAN数据结构: [Identifier+Node_ID, DLC, DATA0, DATA1, DATA2, DATA3...DATA7]
/*
 * DATA0: 发送/接收命令字
 * DATA1~2: 对象索引，例如0x6000
 * DATA3: 对象子索引，例如0x00
 * DATA4~7: 数据
 */

// SDO基本结构：Identifier
#define CAN_SDO_SEND_IDENTIFIER_HEADER 0x600
#define CAN_SDO_RECEIVE_IDENTIFIER_HEADER 0x580
// SDO基本结构：DLC
#define CAN_SDO_DLC 8
// SDO基本结构：写数据的发送命令字
#define CAN_SDO_WRITE_SEND_BYTE_1 0x2F
#define CAN_SDO_WRITE_SEND_BYTE_2 0x2B
#define CAN_SDO_WRITE_SEND_BYTE_4 0x23
// SDO基本结构：写数据的接收命令字
#define CAN_SDO_WRITE_RECEIVE_BYTE_SUCCESS 0x60
#define CAN_SDO_WRITE_RECEIVE_BYTE_FAIL 0x80
// SDO基本结构：读数据的发送命令字
#define CAN_SDO_READ_SEND_BYTE 0x40
// SDO基本结构：读数据的接收命令字
#define CAN_SDO_READ_RECEIVE_BYTE_1 0x4F
#define CAN_SDO_READ_RECEIVE_BYTE_2 0x4B
#define CAN_SDO_READ_RECEIVE_BYTE_4 0x43
#define CAN_SDO_READ_RECEIVE_BYTE_ERROR  0x80

/*
 * 以下只读模式，表示使用SDO基本结构的READ系列
 */

// 设备类型：只读
#define CAN_DEVICE_INDEX 0x6000
#define CAN_DEVICE_SUBINDEX 0x00
#define CAN_DEVICE_BYTE_COUNT 2
#define CAN_DEVICE_EKEY_NODEID 0x00
#define CAN_DEVICE_LOCK_NODEID 0x01
#define CAN_DEVICE_CKEY_NODEID 0x02
#define CAN_DEVICE_CABINET_NODEID 0x03
#define CAN_DEVICE_FOUR_LIGHT_NODEID 0x6E

// 版本号：只读
#define CAN_VERSION_INDEX 0x6003
#define CAN_VERSION_SUBINDEX 0x00
#define CAN_VERSION_BYTE_COUNT 4

// 电子钥匙底座
// 电子钥匙状态：有无钥匙、充电中、未充电，只读
#define CAN_EKEY_STATUS_INDEX 0x6010
#define CAN_EKEY_STATUS_SUBINDEX 0x00
#define CAN_EKEY_STATUS_BYTE_COUNT 2
// 卡扣充电控制和状态：有无上锁、未充电、充电中，有无工作，读写
#define CAN_FASTENER_CONTROL_INDEX 0x6011
#define CAN_FASTENER_CONTROL_SUBINDEX 0x00
#define CAN_FASTENER_CONTROL_BYTE_COUNT 2
// 无线充电温度：只读
#define CAN_EKEY_TEMPERATURE_INDEX 0x6017
#define CAN_EKEY_TEMPERATURE_SUBINDEX 0x00
#define CAN_EKEY_TEMPERATURE_BYTE_COUNT 4
// 左钥匙卡号：只读
#define CAN_LEFT_EKEY_CARD_INDEX 0x6020
#define CAN_LEFT_EKEY_CARD_SUBINDEX 0x00
#define CAN_LEFT_EKEY_CARD_BYTE_COUNT 4
// 右钥匙卡号：只读
#define CAN_RIGHT_EKEY_CARD_INDEX 0x6024
#define CAN_RIGHT_EKEY_CARD_SUBINDEX 0x00
#define CAN_RIGHT_EKEY_CARD_BYTE_COUNT 4

// 5路挂锁底座
// 锁状态：有无锁，只读
#define CAN_LOCK_STATUS_INDEX 0x6010
#define CAN_LOCK_STATUS_SUBINDEX 0x00
#define CAN_LOCK_STATUS_BYTE_COUNT 1
// 卡扣控制/状态：解锁/锁住、工作不工作，读写
#define CAN_LOCK_CONTROL_INDEX 0x6011
#define CAN_LOCK_CONTROL_SUBINDEX 0x00
#define CAN_LOCK_CONTROL_BYTE_COUNT 2
// 1~5号位锁卡号：只读
#define CAN_LOCK_CARD_INDEX 0x6020
#define CAN_LOCK_CARD_BYTE_COUNT 4
#define CAN_LOCK_1_CARD_SUBINDEX 0x00
#define CAN_LOCK_2_CARD_SUBINDEX 0x01
#define CAN_LOCK_3_CARD_SUBINDEX 0x02
#define CAN_LOCK_4_CARD_SUBINDEX 0x03
#define CAN_LOCK_5_CARD_SUBINDEX 0x04

// 钥匙柜控制板
// 钥匙状态：有无钥匙，只读
#define CAN_CKEY_STATUS_INDEX 0x6010
#define CAN_CKEY_STATUS_SUBINDEX 0x00
#define CAN_CKEY_STATUS_BYTE_COUNT 1
// 卡扣控制/状态：读写
#define CAN_CFASTENER_CONTROL_INDEX 0x6011
#define CAN_CFASTENER_CONTROL_SUBINDEX 0x00
#define CAN_CFASTENER_CONTROL_BYTE_COUNT 2
// 1~5号位钥匙卡号：只读
#define CAN_CKEY_CARD_INDEX 0x6020
#define CAN_CKEY_CARD_BYTE_COUNT 4
#define CAN_CKEY_1_CARD_SUBINDEX 0x00
#define CAN_CKEY_2_CARD_SUBINDEX 0x01
#define CAN_CKEY_3_CARD_SUBINDEX 0x02
#define CAN_CKEY_4_CARD_SUBINDEX 0x03
#define CAN_CKEY_5_CARD_SUBINDEX 0x04

// 物资柜主控制板
// 物资状态：只读
#define CAN_CABINET_STATUS_INDEX 0x6010
#define CAN_CABINET_STATUS_BYTE_COUNT 4
// 门锁控制/状态：是否开锁、是否工作、是否已锁，读写
#define CAN_CDOOR_CONTROL_INDEX 0x6011
#define CAN_CDOOR_CONTROL_SUBINDEX 0x00
#define CAN_CDOOR_CONTROL_BYTE_COUNT 2
// 存储指示：读写
#define CAN_CSTORAGE_STATUS_INDEX 0x6012
#define CAN_CSTORAGE_STATUS_BYTE_COUNT 4
// 照明消毒设置/亮度: 读写
#define CAN_DISINFECT_LIGHT_INDEX 0x6015
#define CAN_DISINFECT_LIGHT_SUBINDEX 0x00
#define CAN_DISINFECT_LIGHT_BYTE_COUNT 4
// 灯带控制/状态：读写
#define CAN_LIGHT_STRIP_CONTROL_INDEX 0x6016
#define CAN_LEFT_LIGHT_STRIP_CONTROL_SUBINDEX 0x00
#define CAN_RIGHT_LIGHT_STRIP_CONTROL_SUBINDEX 0x01
#define CAN_LIGHT_STRIP_CONTROL_BYTE_COUNT 4
// 板载温度值：有符号，0xFF8C(读取的值除以10)表示-11.6℃，只读
#define CAN_CTEMPERATURE_INDEX 0x6017
#define CAN_CTEMPERATURE_SUBINDEX 0x00
#define CAN_CTEMPERATURE_BYTE_COUNT 2
// 板载温度值：无符号，0x0271(读取的值除以10)表示62.5℃，只读
#define CAN_UCTEMPERATURE_INDEX 0x6018
#define CAN_UCTEMPERATURE_SUBINDEX 0x00
#define CAN_UCTEMPERATURE_BYTE_COUNT 2
// 光敏采集扩展板：只读
#define CAN_CPHOTOSENSITIVE_INDEX 0x6019
// 系统上总计下挂的光敏采集扩展板的数量
#define CAN_CPHOTOSENSITIVE_COUNT_SUBINDEX 0x00
#define CAN_CPHOTOSENSITIVE_COUNT_BYTE_COUNT 2

// 4路RGB灯带控制板
// 灯带控制/状态：只读
#define CAN_FOUR_LIGHT_STRIP_INDEX 0x6016
#define CAN_FOUR_LIGHT_STRIP_0_SUBINDEX 0x00
#define CAN_FOUR_LIGHT_STRIP_0_BYTE_COUNT 4
#define CAN_FOUR_LIGHT_STRIP_1_SUBINDEX 0x01
#define CAN_FOUR_LIGHT_STRIP_1_BYTE_COUNT 4
#define CAN_FOUR_LIGHT_STRIP_2_SUBINDEX 0x02
#define CAN_FOUR_LIGHT_STRIP_2_BYTE_COUNT 4
#define CAN_FOUR_LIGHT_STRIP_3_SUBINDEX 0x03
#define CAN_FOUR_LIGHT_STRIP_3_BYTE_COUNT 4
// ********************************************************** //
#endif // DEFINE_H_
