#ifndef BMS_COMM_H_
#define BMS_COMM_H_

#ifdef __cplusplus
extern "C" {
#endif 

#include <stdint.h>
#include "bsp_modbus.h"
#include "drv_misc.h"

//#define INTER_CAN_PORT      kcan_dev_e_2
//#define EXTER_CAN_PORT      kcan_dev_e_1
//gary @update 调整顺序
#define INTER_CAN_PORT      kcan_dev_e_1
#define EXTER_CAN_PORT      kcan_dev_e_2
#define INTER_UART_PORT     kUartDev_1
#define EXTER_UART1_PORT    kUartDev_3
#define EXTER_UART2_PORT    kUartDev_4
#define BMS_485_CHANNEL     (3u)

#define W5500_MODBUS_NUM    (8u)

typedef enum
{
    kModbusIdx_Inter,
    kModbusIdx_Exter1,
	kModbusIdx_Exter2,
    kModbusIdx_End,
}ModbusIdx;

extern ModbusItem *modbus_rtu_array[kModbusIdx_End];
//extern HmiItem *hmi_rtu_array[kModbusIdx_End];

void bms_init_comm(void);
uint16_t bms_get_gate_read_data_idx(void);
uint16_t bms_get_gate_write_data_idx(void);
uint16_t bms_get_gate_read_data(uint16_t addr);
uint16_t bms_set_gate_write_data(uint16_t addr, uint16_t value);

uint32_t bms_fill_gate_read_data(uint8_t *buf);
uint32_t bms_fill_gate_write_data(uint8_t *buf);
uint32_t hmi_fill_modbus_cfg(uint8_t *buf);
uint16_t hmi_write_modbus_cfg(uint16_t offset_addr, uint16_t data);


void bms_poll_w5500(void);
void bms_w5500_net_protocol(void);
#ifdef __cplusplus
}
#endif

#endif

