Explorar o código

add max current event, and recorder min/max cell index

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=4) %!d(string=hai) anos
pai
achega
64b7fc11c5

+ 13 - 0
Application/app/event_record.c

@@ -5,6 +5,7 @@
 
 #define MAX_EVENT_SIZE 100
 static event_record_t _event[MAX_EVENT_SIZE];
+static event_record_t _max_current;
 static int event_w_idx = 0;
 static bool _event_full = false;
 
@@ -19,6 +20,14 @@ void push_event(event_id_t id, s32 data) {
 	pevent->data = data;
 }
 
+void push_max_current(s32 current) {
+	_max_current.id = Max_current_persis;
+	_max_current.timestamp = shark_get_seconds();
+	if (abs(current) > abs(_max_current.data)) {
+		_max_current.data = current;
+	}
+}
+
 static int _event_size(void) {
 	if (_event_full) {
 		return MAX_EVENT_SIZE;
@@ -28,6 +37,10 @@ static int _event_size(void) {
 
 int get_event(int num, int offset, u8 *recoder) {
 	if (offset >= _event_size()) {
+		if (offset == _event_size()) {
+			memcpy(recoder, &_max_current, sizeof(event_record_t));
+			return 1;
+		}
 		return 0;
 	}
 	num = MIN(num, _event_size()-offset);

+ 4 - 1
Application/app/event_record.h

@@ -17,7 +17,8 @@ typedef enum {
 	Temp_Low_Charger,
 	Min_Cap_For_Full,
 	Min_Cap_For_DisCharger,
-	Temp_Changed
+	Temp_Changed,
+	Max_current_persis,
 }event_id_t;
 
 typedef struct {
@@ -28,5 +29,7 @@ typedef struct {
 
 void push_event(event_id_t id, s32 data);
 int get_event(int num, int offset, u8 *recoder);
+void push_max_current(s32 current);
+
 #endif /* _Event_Recorde_H__ */
 

+ 3 - 2
Application/app/sox/health.c

@@ -196,6 +196,7 @@ void check_current_state(void){
 				soft_current_init();
 			}		
 		}
+		push_max_current((s32)current);
 	}	
 }
 
@@ -282,7 +283,7 @@ void check_voltage_state(void) {
 		if ((bms_state_get()->cell_max_vol>= SIGLE_CELL_MAX_CHARGER_VOLTAGE)){
 			if (judge_debounce(!_health.sigle_cell_over_voltage, &_sigle_cell_charger_max_vol)){
 				_health.sigle_cell_over_voltage = 1;
-				push_event(Cell_Over_Vol, bms_state_get()->cell_max_vol);
+				push_event(Cell_Over_Vol, bms_state_get()->cell_max_vol | (bms_state_get()->cell_index_of_max_vol << 16));
 				sys_debug("sigle cell %d\n", bms_state_get()->cell_max_vol);
 			}
 		}else if ((bms_state_get()->cell_max_vol < SIGLE_CELL_MAX_CHARGER_VOLTAGE)){
@@ -298,7 +299,7 @@ void check_voltage_state(void) {
 		if ((bms_state_get()->cell_min_vol <= min_discharger_cell_vol[_health.is_work_temp_normal])){
 			if (judge_debounce(!_health.sigle_cell_lower_voltage, &_sigle_cell_discharger_lower_vol)){
 				_health.sigle_cell_lower_voltage = 1;
-				push_event(Cell_Under_Vol, bms_state_get()->cell_min_vol);
+				push_event(Cell_Under_Vol, bms_state_get()->cell_min_vol | (bms_state_get()->cell_index_of_min_vol << 16));
 				_single_low_judge_current(true);
 				error_counts.cell_under_voltage++;
 			}

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

@@ -66,6 +66,7 @@ void bms_state_init(void){
 	cht8305_reset();
 #endif
 	_bms_state.cell_index_of_max_vol = 0xff;
+	_bms_state.cell_index_of_min_vol = 0xff;
 	_bms_state.bms_addr = 0x30;
 	measure_task_init(_current_notify, _voltage_notify, _temperature_notify);
 	io_state_init();
@@ -668,7 +669,6 @@ static void check_cell_balance(uint8_t current_max_index){
 		shark_timer_post(&_balance_timer, 5 * 1000); //stop balance after 30s
 		debounce_reset(_cell_balance);
 	}
-	_bms_state.cell_index_of_max_vol = current_max_index;	
 }
 #endif
 static uint8_t calc_cell_voltage(void){
@@ -676,6 +676,7 @@ static uint8_t calc_cell_voltage(void){
 	uint16_t max_cell = 0;
 	uint16_t min_cell = 0xf000;
 	uint8_t max_index = 0;
+	uint8_t min_index = 0;
 	for (int i = 0; i < CELLS_NUM; i++){
 		voltage += measure_value()->cell_vol[i];
 		if (max_cell < measure_value()->cell_vol[i]){
@@ -684,11 +685,14 @@ static uint8_t calc_cell_voltage(void){
 		}
 		if (min_cell > measure_value()->cell_vol[i]){
 			min_cell = measure_value()->cell_vol[i];
+			min_index = i;
 		}		
 	}
 	_bms_state.pack_voltage = voltage;
 	_bms_state.cell_max_vol = max_cell;
-	_bms_state.cell_min_vol = min_cell;	
+	_bms_state.cell_min_vol = min_cell;
+	_bms_state.cell_index_of_min_vol = min_index;
+	_bms_state.cell_index_of_max_vol = max_index;	
 	return max_index;
 }
 

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

@@ -32,6 +32,7 @@ typedef struct{
 	uint16_t cell_max_vol;
 	uint16_t cell_min_vol;
 	uint8_t  cell_index_of_max_vol;
+	uint8_t  cell_index_of_min_vol;
 	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测试模测试,整机测试模式