#ifndef PROTOCOL_COMM_H_
#define PROTOCOL_COMM_H_

#ifdef __cplusplus
extern "C" {
#endif 

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

#include "drv_can.h"
#include "fault_manager.h"


typedef void (*CanCommReceive)(CanMsg *msg, can_dev_e can);
typedef void (*CanCommPoll)(uint32_t base_time, can_dev_e can);
typedef void (*CanCommSend)(uint32_t base_time, can_dev_e can);

void protocol_comm_init(void);
void protocol_can_none_init(can_dev_e can);
void modbus_rtu_inter_handler(uint32_t base_time);
void modbus_rtu_extern_handler(uint32_t base_time);
void modbus_rtu_externII_handler(uint32_t base_time);

void protocol_exter2_modbus_poll(uint32_t base_time);
void protocol_can_poll(uint32_t base_time, can_dev_e can);
void protocol_can_set_call(can_dev_e can, CanCommReceive rx, CanCommSend tx, CanCommPoll poll);


void protocol_modbus_bcu_init(void * const mb_item,uint16_t addr);
void protocol_modbus_demo(void * const mb_item,uint16_t addr);
//void protocol_can_bcu_init(can_dev_e can);
void protocol_pylon_can_init(can_dev_e can);
void protocol_can_invt_pcs_init(can_dev_e can);

//根据位，转换告警的位
uint16_t set_bit_based_on_source_pylon(uint8_t status, FaultLevel alarmLevel);

void bms_analyse_model_data(void);
uint16_t bms_read_model_data(uint8_t *buf);
bool bms_write_model_data(uint8_t *buf, uint16_t len);

void protocol_w5500_modbus_tcp_server1_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server2_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server3_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server4_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server5_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server6_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server7_poll(uint32_t base_time);
void protocol_w5500_modbus_tcp_server8_poll(uint32_t base_time);


#ifdef __cplusplus
}
#endif

#endif

