From 98d08e6179902f9c51df9bdf7e2f97fb91f7c1da Mon Sep 17 00:00:00 2001 From: PeiHao <33123544+CodeMan-P@users.noreply.github.com> Date: Sat, 12 Oct 2024 20:12:30 +0800 Subject: [PATCH] Fix the issue of abnormal modification of motion_rownsample Fix the issue of abnormal modification of motion_rownsample Problem reproduction command sequence: send: MMS1111111\n MMS0\n MCD\n rcv: Motion: downsample: 11111 --- src/communication/Commander.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/communication/Commander.cpp b/src/communication/Commander.cpp index d2822b04..650e0d57 100644 --- a/src/communication/Commander.cpp +++ b/src/communication/Commander.cpp @@ -43,11 +43,11 @@ void Commander::run(Stream& serial, char eol){ run(received_chars); // reset the command buffer - received_chars[0] = 0; + memset(received_chars, 0, MAX_COMMAND_LENGTH); rec_cnt=0; } if (rec_cnt>=MAX_COMMAND_LENGTH) { // prevent buffer overrun if message is too long - received_chars[0] = 0; + memset(received_chars, 0, MAX_COMMAND_LENGTH); rec_cnt=0; } } @@ -363,7 +363,8 @@ void Commander::motor(FOCMotor* motor, char* user_command) { void Commander::motion(FOCMotor* motor, char* user_cmd, char* separator){ char cmd = user_cmd[0]; char sub_cmd = user_cmd[1]; - bool GET = isSentinel(user_cmd[1]); + int value_index = (sub_cmd == SCMD_DOWNSAMPLE) ? 2 : 1; + bool GET = isSentinel(user_cmd[value_index]); float value = atof(&user_cmd[(sub_cmd >= 'A' && sub_cmd <= 'Z') ? 2 : 1]); switch(cmd){