Explorar el Código

add bms_addr 兼容老协议

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui hace 5 años
padre
commit
e28c86b1e1
Se han modificado 3 ficheros con 9 adiciones y 2 borrados
  1. 2 2
      Application/app/protocol_old.c
  2. 6 0
      Application/app/sox/state.c
  3. 1 0
      Application/app/sox/state.h

+ 2 - 2
Application/app/protocol_old.c

@@ -43,7 +43,7 @@ uint16_t _checksum(uint8_t *data, uint16_t size) {
 static int get_response_data(uint8_t *data, uint8_t operate, uint8_t result){
 	comm_head_t *head = (comm_head_t *)data;
 	head->size = sizeof(comm_head_t);
-	head->type = 0x30;
+	head->type = bms_state_get()->bms_addr;
 	head->dir = 0x16;
 	head->bStatus = 1;
 	head->cmd = 0x10;
@@ -111,7 +111,7 @@ static int get_response_data(uint8_t *data, uint8_t operate, uint8_t result){
 static int protocol_old_process_binary(uart_enum_t uart_no, uint8_t *data, int len){
 	current_uart = uart_no;
 	comm_head_t *head = (comm_head_t *)data;
-	if (/*head->type != 0x30 || */head->dir != 0x16 || head->bStatus == 1 || head->size < sizeof(comm_head_t)){
+	if (head->type != bms_state_get()->bms_addr || head->dir != 0x16 || head->bStatus == 1 || head->size < sizeof(comm_head_t)){
 		return -1;
 	}
 	uint16_t checksum = head->checksum;

+ 6 - 0
Application/app/sox/state.c

@@ -32,6 +32,7 @@ void bms_state_init(void){
 	set_log_level(MOD_STATE, L_debug);
 	state_debug("BMS System Starting......\n");	
 	_bms_state.cell_index_of_max_vol = 0xff;
+	_bms_state.bms_addr = 0x30;
 	measure_task_init(_current_notify, _voltage_notify, _temperature_notify);
 	io_state_init();
 	health_init();
@@ -329,6 +330,11 @@ static void _process_iostate_changed(s32 unhealth){
 			charger_open(1);
 		}
 	}
+	if (io_state()->hall_detect){
+		_bms_state.bms_addr = 0x30 + 1;
+	}else {
+		_bms_state.bms_addr = 0x30;
+	}
 }
 
 static u32 _bms_main_task_handler(void){

+ 1 - 0
Application/app/sox/state.h

@@ -33,6 +33,7 @@ typedef struct{
 	int      used_by;//where this battery is used for: on motor, on charger docker, on charger box, NONE
 	uint32_t user_request;
 	uint32_t work_mode;//正常模式,老化测试模式,pcba测试模测试,整机测试模式
+	uint8_t  bms_addr;
 }bms_state_t;
 
 #define WORK_MODE_NORMAL 0      //正常模式