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

解决设置和查询挡位问题

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 лет назад
Родитель
Сommit
8ce40ff0f7
2 измененных файлов с 12 добавлено и 8 удалено
  1. 1 0
      Applications/app/nv_storage.c
  2. 11 8
      Applications/foc/commands.c

+ 1 - 0
Applications/app/nv_storage.c

@@ -207,6 +207,7 @@ void nv_read_foc_params(void) {
 		}
 	}
 	foc_params.s_maxTorque = foc_params.s_PhaseCurrLim;//overwrite
+	sys_debug("maxTorque=%f\n", foc_params.s_maxTorque);
 }
 
 void nv_save_gear_configs(void) {

+ 11 - 8
Applications/foc/commands.c

@@ -177,14 +177,16 @@ static void process_foc_command(foc_cmd_body_t *command) {
 		}
 		case Foc_Set_Gear_Limit:
 		{
-			if (command->len < 7) {
+			sys_debug("len = %d\n", command->len);
+			if (command->len < 9) {
 				erroCode = FOC_Param_Err;
 			}else {
 				u8  gear = decode_u8(command->data);
 				u16 maxRPM = decode_u16((u8 *)command->data + 1);
-				u16 maxPhaseCurr = decode_u8((u8 *)command->data + 3);
-				u16 maxiDC = decode_u8((u8 *)command->data + 5);
-				u16 accline = decode_u8((u8 *)command->data + 7);
+				u16 maxPhaseCurr = decode_u16((u8 *)command->data + 3);
+				u16 maxiDC = decode_u16((u8 *)command->data + 5);
+				u16 accline = decode_u16((u8 *)command->data + 7);
+				sys_debug("gear 0x%x, rpm %d, phase %d idc %d acc %d\n", gear, maxRPM, maxPhaseCurr, maxiDC, accline);
 				if (!nv_set_gear_config((gear>>4 & 0xF), (gear & 0xF), maxRPM, maxPhaseCurr, maxiDC, accline)){
 					erroCode = FOC_Param_Err;
 				}
@@ -198,14 +200,15 @@ static void process_foc_command(foc_cmd_body_t *command) {
 			u16 maxPhaseCurr;
 			u16 maxiDC;
 			u16 accline;
+			sys_debug("gear = 0x%x\n", gear);
 			if (!nv_get_gear_config((gear>>4 & 0xF), (gear & 0xF), &maxRPM, &maxPhaseCurr, &maxiDC, &accline)){
 				erroCode = FOC_Param_Err;
 			}else {
 				encode_u8(response + 3, gear);
-				encode_u8(response + 4, maxRPM);
-				encode_u8(response + 6, maxPhaseCurr);
-				encode_u8(response + 8, maxiDC);
-				encode_u8(response + 10, accline);
+				encode_u16(response + 4, maxRPM);
+				encode_u16(response + 6, maxPhaseCurr);
+				encode_u16(response + 8, maxiDC);
+				encode_u16(response + 10, accline);
 				len += 9;
 			}
 			break;