Просмотр исходного кода

字符类型统一用uint8_t 处理

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 лет назад
Родитель
Сommit
074d6f6e9f

+ 27 - 7
Application/app/protocol.c

@@ -11,24 +11,44 @@ void protocol_send_bms_info(protocol_head_t *head){
 	can_head_t *can = (can_head_t *)(((uint8_t *)head) - sizeof(can_head_t));
 	can_head_t *can = (can_head_t *)(((uint8_t *)head) - sizeof(can_head_t));
 	can->can_addr = 0x42;
 	can->can_addr = 0x42;
 	can->size = head->size;
 	can->size = head->size;
-	can->can_key = 0x00;
 	head->checksum = 0;
 	head->checksum = 0;
 	head->checksum = _check_sum((uint8_t *)head, head->size);
 	head->checksum = _check_sum((uint8_t *)head, head->size);
 
 
-	shark_uart_write_frame(current_uart, (char *)can, sizeof(can_head_t) + head->size);
+	shark_uart_write_frame(current_uart, (uint8_t *)can, sizeof(can_head_t) + head->size);
 }
 }
 
 
 
 
-void protocol_send_debug_info(uint8_t dest, char *data, int size){
-	can_head_t *can = (can_head_t *)(((uint8_t *)data) - sizeof(can_head_t));
+void protocol_send_debug_info(uint8_t dest, uint8_t *data, int size){
+	can_head_t *can = (can_head_t *)(data - sizeof(can_head_t));
 	can->can_addr = dest;
 	can->can_addr = dest;
 	can->size = size;
 	can->size = size;
-	can->can_key = 0x00;
 
 
-	shark_uart_write_frame(current_uart, (char *)can, sizeof(can_head_t) + size);
+	shark_uart_write_frame(current_uart, (uint8_t *)can, sizeof(can_head_t) + size);
 }
 }
 
 
-void protocol_recv_frame(uart_enum_t uart_no, char *data, int len){
+void protocol_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
+	current_uart = uart_no;
+	if (len < sizeof(can_head_t)){
+		return;
+	}
+	can_head_t *can_head = (can_head_t *)data;
+	if (can_head->can_addr == 0x45){ //pc sent
+
+	}else {
+		len -= sizeof(can_head_t);
+		if (len <sizeof(protocol_head_t)){
+			return;
+		}
+		protocol_head_t *head = (protocol_head_t *)(data + sizeof(can_head_t)) ;
+		if (len != head->size) {
+			return;
+		}
+		uint16_t check_sum_rx = head->checksum;
+		head->checksum = 0;
+		if (check_sum_rx != _check_sum(data, head->size)){
+			return;
+		}
+	}
 
 
 }
 }
 
 

+ 1 - 2
Application/app/protocol.h

@@ -7,7 +7,6 @@ typedef struct
 {
 {
 	uint8_t can_addr;
 	uint8_t can_addr;
 	uint8_t size; //Ö»°üº¬canÊý¾Ý²¿·Ö£¬²»º¬can_key
 	uint8_t size; //Ö»°üº¬canÊý¾Ý²¿·Ö£¬²»º¬can_key
-	uint16_t can_key;
 }can_head_t;
 }can_head_t;
 #pragma pack(pop)
 #pragma pack(pop)
 
 
@@ -83,6 +82,6 @@ typedef struct {
 #pragma pack(pop)
 #pragma pack(pop)
 
 
 void protocol_send_bms_info(protocol_head_t *head);
 void protocol_send_bms_info(protocol_head_t *head);
-void protocol_send_debug_info(uint8_t dest, char *data, int size);
+void protocol_send_debug_info(uint8_t dest, uint8_t *data, int size);
 
 
 
 

+ 5 - 4
Application/bsp/uart.c

@@ -69,7 +69,7 @@ static void shark_uart_rx(shark_uart_t *uart){
 	while(1) {
 	while(1) {
 		u8 data;
 		u8 data;
 		update_dma_w_pos(uart);
 		update_dma_w_pos(uart);
-		if (circle_get_one_data(&uart->rx_queue, (char *)&data) != 1) {
+		if (circle_get_one_data(&uart->rx_queue, &data) != 1) {
 			if (!new_prococol){//通过老协议发送过来的,需要回复一个信息,告知使用新协议,霍尔移除,通信超时需要reset new_protocol
 			if (!new_prococol){//通过老协议发送过来的,需要回复一个信息,告知使用新协议,霍尔移除,通信超时需要reset new_protocol
 				if (shark_get_mseconds() - _rx_time >= 30) {
 				if (shark_get_mseconds() - _rx_time >= 30) {
 					_rx_time = 0xFFFFFFFFFFFFL;
 					_rx_time = 0xFFFFFFFFFFFFL;
@@ -239,7 +239,8 @@ void shark_uart_deinit(uart_enum_t uart_no){
 		UART0_IR_EN(0);
 		UART0_IR_EN(0);
 	}else {
 	}else {
 		UART1_IR_EN(0);
 		UART1_IR_EN(0);
-	}	
+	}
+	new_prococol = false;
 }
 }
 
 
 
 
@@ -251,7 +252,7 @@ void shark_uart_init(uart_enum_t uart_no)
 	uart->tx_length = 0;
 	uart->tx_length = 0;
 	uart->uart_com = (uart_no == SHARK_UART0)?SHARK_UART0_com:SHARK_UART1_com;
 	uart->uart_com = (uart_no == SHARK_UART0)?SHARK_UART0_com:SHARK_UART1_com;
 
 
-	circle_buffer_init(&uart->rx_queue, (char *)shark_uart_rx_cache, SHARK_UART_TX_MEM_SIZE);
+	circle_buffer_init(&uart->rx_queue, shark_uart_rx_cache, SHARK_UART_TX_MEM_SIZE);
 	byte_queue_init(&uart->tx_queue,tx_cache_addr(uart_no), SHARK_UART_TX_MEM_SIZE);
 	byte_queue_init(&uart->tx_queue,tx_cache_addr(uart_no), SHARK_UART_TX_MEM_SIZE);
 
 
 	uart->rx_dma_ch = (uart_no == SHARK_UART0)?SHARK_UART0_rx_dma_ch:SHARK_UART1_rx_dma_ch;
 	uart->rx_dma_ch = (uart_no == SHARK_UART0)?SHARK_UART0_rx_dma_ch:SHARK_UART1_rx_dma_ch;
@@ -359,7 +360,7 @@ static void shark_uart_tx_end(shark_uart_t *uart)
 	shark_uart_write_byte(uart, CH_END);
 	shark_uart_write_byte(uart, CH_END);
 }
 }
 
 
-void shark_uart_write_frame(uart_enum_t uart_no, char *bytes, int len){
+void shark_uart_write_frame(uart_enum_t uart_no, uint8_t *bytes, int len){
 	shark_uart_t *uart = _shark_uart + uart_no;
 	shark_uart_t *uart = _shark_uart + uart_no;
 	shark_uart_tx_start(uart);
 	shark_uart_tx_start(uart);
 	shark_uart_tx_continue(uart, bytes, len);
 	shark_uart_tx_continue(uart, bytes, len);

+ 1 - 1
Application/bsp/uart.h

@@ -39,5 +39,5 @@ typedef struct {
 
 
 void shark_uart_init(uart_enum_t uart_no);
 void shark_uart_init(uart_enum_t uart_no);
 void shark_uart_deinit(uart_enum_t uart_no);
 void shark_uart_deinit(uart_enum_t uart_no);
-void shark_uart_write_frame(uart_enum_t uart_no, char *bytes, int len);
+void shark_uart_write_frame(uart_enum_t uart_no, uint8_t *bytes, int len);
 
 

+ 5 - 5
Application/libs/circle_buffer.c

@@ -5,7 +5,7 @@
 static int circle_get_write_space(c_buffer_t *cbuff);
 static int circle_get_write_space(c_buffer_t *cbuff);
 static int circle_get_read_space(c_buffer_t *cbuff);
 static int circle_get_read_space(c_buffer_t *cbuff);
 
 
-void circle_buffer_init(c_buffer_t *cbuff, char *buffer, int16_t max_len){
+void circle_buffer_init(c_buffer_t *cbuff, uint8_t *buffer, int16_t max_len){
 	cbuff->buffer = buffer;
 	cbuff->buffer = buffer;
 	cbuff->buffer_len = max_len;
 	cbuff->buffer_len = max_len;
 }
 }
@@ -15,7 +15,7 @@ void circle_reset(c_buffer_t *cbuff){
 }
 }
 
 
 
 
-int circle_put_data(c_buffer_t *cbuff, char *data, int16_t len){
+int circle_put_data(c_buffer_t *cbuff, uint8_t *data, int16_t len){
 	int16_t size = circle_get_write_space(cbuff);
 	int16_t size = circle_get_write_space(cbuff);
 	int16_t w_len = len;
 	int16_t w_len = len;
 	int16_t w1_len = len;
 	int16_t w1_len = len;
@@ -41,7 +41,7 @@ int circle_put_data(c_buffer_t *cbuff, char *data, int16_t len){
 	return min(len, size);
 	return min(len, size);
 }
 }
 
 
-int circle_put_one_data(c_buffer_t *cbuff, char data){
+int circle_put_one_data(c_buffer_t *cbuff, uint8_t data){
 	int16_t size = circle_get_write_space(cbuff);
 	int16_t size = circle_get_write_space(cbuff);
 	if (size < 0){
 	if (size < 0){
 		return size;
 		return size;
@@ -54,7 +54,7 @@ int circle_put_one_data(c_buffer_t *cbuff, char data){
 	return 1;
 	return 1;
 }
 }
 
 
-int circle_get_data(c_buffer_t *cbuff, char *data, int16_t len){
+int circle_get_data(c_buffer_t *cbuff, uint8_t *data, int16_t len){
 	int16_t size = circle_get_read_space(cbuff);
 	int16_t size = circle_get_read_space(cbuff);
 	int16_t r_len = len;
 	int16_t r_len = len;
 	int16_t r1_len = 0;
 	int16_t r1_len = 0;
@@ -82,7 +82,7 @@ int circle_get_data(c_buffer_t *cbuff, char *data, int16_t len){
 }
 }
 
 
 
 
-int circle_get_one_data(c_buffer_t *cbuff, char *data){
+int circle_get_one_data(c_buffer_t *cbuff, uint8_t *data){
 	int16_t size = circle_get_read_space(cbuff);
 	int16_t size = circle_get_read_space(cbuff);
 	if (size <= 0){
 	if (size <= 0){
 		return size;
 		return size;

+ 6 - 6
Application/libs/circle_buffer.h

@@ -11,7 +11,7 @@
 #define CBUFF_EMPTY -2
 #define CBUFF_EMPTY -2
 
 
 typedef struct {
 typedef struct {
-	char * buffer;
+	uint8_t * buffer;
 	int16_t buffer_len;
 	int16_t buffer_len;
 	int16_t w_pos;
 	int16_t w_pos;
 	int16_t r_pos;
 	int16_t r_pos;
@@ -26,12 +26,12 @@ static __inline__ int circle_get_read_position(c_buffer_t *cbuff){
 	return cbuff->r_pos;
 	return cbuff->r_pos;
 }
 }
 
 
-void circle_buffer_init(c_buffer_t *cbuff, char *buffer, int16_t max_len);
+void circle_buffer_init(c_buffer_t *cbuff, uint8_t *buffer, int16_t max_len);
 void circle_reset(c_buffer_t *cbuff);
 void circle_reset(c_buffer_t *cbuff);
-int circle_put_one_data(c_buffer_t *cbuff, char data);
-int circle_put_data(c_buffer_t *cbuff, char *data, int16_t len);
-int circle_get_one_data(c_buffer_t *cbuff, char *data);
-int circle_get_data(c_buffer_t *cbuffer, char *data, int16_t len);
+int circle_put_one_data(c_buffer_t *cbuff, uint8_t data);
+int circle_put_data(c_buffer_t *cbuff, uint8_t *data, int16_t len);
+int circle_get_one_data(c_buffer_t *cbuff, uint8_t *data);
+int circle_get_data(c_buffer_t *cbuffer, uint8_t *data, int16_t len);
 
 
 #endif /* _Cirule_Buffer_h__ */
 #endif /* _Cirule_Buffer_h__ */
 
 

+ 1 - 1
Application/libs/logger.c

@@ -49,7 +49,7 @@ void log_error(int mod, char *fmt, ...){
 	}
 	}
 }
 }
 //rewrite the fputc, so that the printf,vprintf can log the info the can
 //rewrite the fputc, so that the printf,vprintf can log the info the can
-static char log_buffer[64];
+static uint8_t log_buffer[64];
 static int log_index = sizeof(can_head_t);
 static int log_index = sizeof(can_head_t);
 int fputc(int c, FILE *fp){
 int fputc(int c, FILE *fp){
 	if (c == '\n'){ //don't send '\n'
 	if (c == '\n'){ //don't send '\n'