Explorar o código

红外接收错误统计

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

+ 3 - 1
Application/app/protocol.c

@@ -6,7 +6,7 @@
 #include "app/iap.h"
 static uint16_t _check_sum(uint8_t*data,uint16_t size);
 static uart_enum_t current_uart = SHARK_UART0;
-
+extern void health_add_uart_error(uint32_t c, uint32_t l, uint32_t d);
 void protocol_send_bms_info(uint8_t dest, uint8_t key, uint8_t *data, int len){
 	can_frame_t can_frame;
 	CAN_OUT(&(can_frame.head), dest);
@@ -57,10 +57,12 @@ void protocol_notify_old_frame(uart_enum_t uart_no){
 void protocol_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 	current_uart = uart_no;
 	if (len < sizeof(can_frame_t)){
+		health_add_uart_error(0, 1, 0);
 		return;
 	}
 	can_frame_t *can_frame = (can_frame_t *)data;
 	if (!CAN_IN(&(can_frame->head))) {//data is sent by myself, drop
+		health_add_uart_error(0 ,0 ,1);
 		return;
 	}
 

+ 0 - 1
Application/app/protocol_old.c

@@ -15,7 +15,6 @@
 
 static uart_enum_t current_uart = SHARK_UART0;
 extern char* bsp_get_fversion(void);
-
 uint16_t _checksum(uint8_t *data, uint16_t size) {
 	uint32_t checksum;
 	if((NULL == data) || (0 == size)) {

+ 7 - 0
Application/app/sox/health.c

@@ -80,12 +80,19 @@ void health_log(void){
 	health_debug("work temp: %d\n", _health.is_work_temp_normal);
 	health_debug("aux_short: %d, %d\n", error_counts.aux_short, error_counts.aux_real_short);
 	health_debug("lower voltage: %d, %d, %d, %d\n", discharger_lower_cell_voltage, discharger_lower_voltage, error_counts.cell_under_voltage, error_counts.pack_under_voltage);
+	health_debug("uart error %d, %d, %d\n", error_counts.uart_crc_error, error_counts.uart_len_error, error_counts.uart_dir_error);
 }
 
 bms_health_t *bms_health(){
 	return &_health;
 }
 
+void health_add_uart_error(uint32_t c, uint32_t l, uint32_t d) {
+	error_counts.uart_crc_error += c;
+	error_counts.uart_len_error += l;
+	error_counts.uart_dir_error += d;
+}
+
 uint32_t bms_health_pack_lower_voltage(void){
 	return min_discharger_vol[_health.is_work_temp_normal];
 }

+ 3 - 0
Application/app/sox/health.h

@@ -58,6 +58,9 @@ typedef struct {
 	uint32_t aux_real_short;
 	uint32_t cell_under_voltage;
 	uint32_t pack_under_voltage;
+	uint32_t uart_crc_error;
+	uint32_t uart_len_error;
+	uint32_t uart_dir_error;
 }error_counts_t;
 
 bms_health_t *bms_health(void);

+ 9 - 0
Application/bsp/uart.c

@@ -51,6 +51,7 @@ static u64 _rx_time;
 #define update_dma_w_pos(uart) circle_update_write_position(&uart->rx_queue, SHARK_UART_RX_MEM_SIZE - DMA_CHCNT(uart->rx_dma_ch))
 extern void protocol_recv_frame(uart_enum_t uart_no, char *data, int len);
 extern void protocol_old_recv_frame(uart_enum_t uart_no, uint8_t *data, int len);
+extern void health_add_uart_error(uint32_t c, uint32_t l, uint32_t d);
 // ================================================================================
 static uart_enum_t _uart_index(uint32_t com){
 	return com == SHARK_UART0_com?SHARK_UART0:SHARK_UART1;
@@ -61,6 +62,7 @@ static bool shark_uart_on_rx_frame(shark_uart_t *uart)
 	u16 crc1 = shark_crc16_check(uart->rx_frame, uart->rx_length);
 
 	if (crc0 != crc1) {
+		health_add_uart_error(1, 0, 0);
 		return false;
 	}
 	protocol_recv_frame(_uart_index(uart->uart_com), (char *)uart->rx_frame, uart->rx_length);
@@ -97,13 +99,17 @@ static void shark_uart_rx(shark_uart_t *uart){
 			case CH_START:
 				uart->rx_length = 0;
 				uart->escape = false;
+				uart->start = true;
 				break;
 			case CH_END:
 				if (uart->rx_length > 2 && uart->rx_length != 0xFFFF){
 					uart->rx_length -= 2; //skip crc
 					shark_uart_on_rx_frame(uart);
+				}else if (uart->start == true){
+					health_add_uart_error(0, 1, 0);
 				}
 				uart->rx_length = 0xFFFF;
+				uart->start = false;
 				break;
 			case CH_ESC:
 				uart->escape = true;
@@ -134,6 +140,9 @@ static void shark_uart_rx(shark_uart_t *uart){
 					uart->rx_length++;
 				} else {
 					uart->rx_length = 0xFFFF;
+					if (uart->start == true) {
+						health_add_uart_error(0, 1, 0);
+					}
 				}			
 		}
 	}

+ 1 - 0
Application/bsp/uart.h

@@ -38,6 +38,7 @@ typedef struct {
 	uint8_t rx_frame_old_prot[256];
 	uint16_t rx_length_old_prot;
 	bool escape;
+	bool start;
 	bool uart_no_data;
 }shark_uart_t;