Kaynağa Gözat

PC message and bms message 合并处理

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 yıl önce
ebeveyn
işleme
6ce4ec87f4

+ 1 - 19
Application/app/bms_message.c

@@ -36,7 +36,7 @@ void process_bms_message(can_frame_t *frame, int len){
 	// set_log_all(L_debug);
 	// set_log_all(L_debug);
 	switch(frame->key) {
 	switch(frame->key) {
 		case CAN_KEY_BMS_SET_POWER:
 		case CAN_KEY_BMS_SET_POWER:
-			if (len != sizeof(pwr_cmd_t)){
+			if (len != sizeof(pwr_cmd_t) || frame->head.can_addr != 0x42){//¿ª¹Ø´óµç±ØÐë42·¢¹ýÀ´
 				result = 1;
 				result = 1;
 			}else {
 			}else {
 				pwr_cmd_t *cmd = (pwr_cmd_t *)frame->data;
 				pwr_cmd_t *cmd = (pwr_cmd_t *)frame->data;
@@ -211,24 +211,6 @@ void process_bms_message(can_frame_t *frame, int len){
 			}
 			}
 			protocol_send_ack(frame->head.can_addr, frame->key, result);
 			protocol_send_ack(frame->head.can_addr, frame->key, result);
 			break;
 			break;
-		case CAN_KEY_START_CALI:
-			if (len != sizeof(cali_cmd_t)) {
-				current_calibrate();//just for debug
-				result = 1;
-			}else {
-				cali_cmd_t * cmd = (cali_cmd_t *)frame->data;
-				uint8_t adc = cmd->flags & 0x01;
-				uint8_t flags = ((cmd->flags>>1) & 0x03);
-				if (flags == 1) {
-					result = measure_start_cali(adc, cmd->gain, cmd->totol_samples);
-				}else if (flags == 2) {
-					result = measure_continue_cali(adc, cmd->voltage, cmd->current);
-				}else {
-					result = measure_stop_cali(adc, cmd->gain);
-				}
-			}
-			protocol_send_ack(frame->head.can_addr, frame->key, result);
-			break;
 	}
 	}
 }
 }
 
 

+ 24 - 1
Application/app/pc_message.c

@@ -1,11 +1,34 @@
 #include "pc_message.h"
 #include "pc_message.h"
 #include "pcba_test.h"
 #include "pcba_test.h"
+#include "app/sox/measure.h"
 
 
-void process_pc_message(can_frame_t *frame, int len){
+int process_pc_message(can_frame_t *frame, int len){
+	int processed = 0;
 	if (frame->key == CAN_KEY_PCBA_TEST) {
 	if (frame->key == CAN_KEY_PCBA_TEST) {
 		uint8_t response[16];
 		uint8_t response[16];
 		int resp_len = pcba_test(frame->data, len, response);
 		int resp_len = pcba_test(frame->data, len, response);
 		protocol_send_bms_info(frame->head.can_addr, frame->key, response, resp_len);
 		protocol_send_bms_info(frame->head.can_addr, frame->key, response, resp_len);
+		processed = 1;
+	}else if (frame->key == CAN_KEY_START_CALI) {
+		uint8_t result = 0;
+		if (len != sizeof(cali_cmd_t)) {
+			current_calibrate();//just for debug
+			result = 1;
+		}else {
+			cali_cmd_t * cmd = (cali_cmd_t *)frame->data;
+			uint8_t adc = cmd->flags & 0x01;
+			uint8_t flags = ((cmd->flags>>1) & 0x03);
+			if (flags == 1) {
+				result = measure_start_cali(adc, cmd->gain, cmd->totol_samples);
+			}else if (flags == 2) {
+				result = measure_continue_cali(adc, cmd->voltage, cmd->current);
+			}else {
+				result = measure_stop_cali(adc, cmd->gain);
+			}
+		}
+		protocol_send_ack(frame->head.can_addr, frame->key, result);
+		processed = 1;
 	}
 	}
+	return processed;
 }
 }
 
 

+ 1 - 1
Application/app/pc_message.h

@@ -1,5 +1,5 @@
 #pragma once
 #pragma once
 #include <stdint.h>
 #include <stdint.h>
 #include "protocol.h"
 #include "protocol.h"
-void process_pc_message(can_frame_t *frame, int len);
+int process_pc_message(can_frame_t *frame, int len);
 
 

+ 1 - 3
Application/app/protocol.c

@@ -68,9 +68,7 @@ void protocol_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 	if (can_frame->key >= CAN_KEY_IAP_ENTER){
 	if (can_frame->key >= CAN_KEY_IAP_ENTER){
 		process_iap_message(can_frame, len);
 		process_iap_message(can_frame, len);
 	}else {
 	}else {
-		if (can_frame->head.can_addr == 0x45){ //pc sent
-			process_pc_message(can_frame, len);
-		}else {
+		if (!process_pc_message(can_frame, len)) {
 			process_bms_message(can_frame, len);
 			process_bms_message(can_frame, len);
 		}
 		}
 	}
 	}