|
|
@@ -177,19 +177,36 @@ static void process_foc_command(foc_cmd_body_t *command) {
|
|
|
}
|
|
|
case Foc_Set_Gear_Limit:
|
|
|
{
|
|
|
- if (command->len < 5) {
|
|
|
+ if (command->len < 7) {
|
|
|
erroCode = FOC_Param_Err;
|
|
|
}else {
|
|
|
- u16 maxRPM = decode_u16(command->data);
|
|
|
- u16 maxPhaseCurr = decode_u8((u8 *)command->data + 2);
|
|
|
- u8 maxiDC = decode_u8((u8 *)command->data + 4);
|
|
|
- PMSM_FOC_SpeedLimit((float)maxRPM);
|
|
|
- PMSM_FOC_PhaseCurrLim((float)maxPhaseCurr);
|
|
|
- PMSM_FOC_DCCurrLimit((float)maxiDC);
|
|
|
- encode_u16(response + 3, (u16)PMSM_FOC_GetSpeedLimit());
|
|
|
- encode_u16(response + 5, (u16)PMSM_FOC_GetPhaseCurrLim());
|
|
|
- encode_u8(response + 7, (u8)PMSM_FOC_GetDCCurrLimit());
|
|
|
- len += 5;
|
|
|
+ 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);
|
|
|
+ if (!nv_set_gear_config((gear>>4 & 0xF), (gear & 0xF), maxRPM, maxPhaseCurr, maxiDC, accline)){
|
|
|
+ erroCode = FOC_Param_Err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case Foc_Get_Gear_Limit:
|
|
|
+ {
|
|
|
+ u8 gear = decode_u8(command->data);
|
|
|
+ u16 maxRPM;
|
|
|
+ u16 maxPhaseCurr;
|
|
|
+ u16 maxiDC;
|
|
|
+ u16 accline;
|
|
|
+ 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);
|
|
|
+ len += 9;
|
|
|
}
|
|
|
break;
|
|
|
}
|