Skip to content

Commit

Permalink
Limit value range
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Dec 19, 2023
1 parent 5ed638d commit a841af4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tfrog-motordriver/communication.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ int32_t atoi(char* buf)
}
buf++;
}
if (buf[0] == '-')
{
ret = -ret;
}
return ret;
}

Expand Down Expand Up @@ -1242,10 +1246,18 @@ int32_t extended_command_analyze(char* data)
}
else if (strstr(data, "$SETSOFTBRAKEMS") == data)
{
saved_param.soft_brake_ms = atoi(data + 15);

send(data);
send("\n00P\n\n");
const int32_t v = atoi(data + 15);
if (v < 0 || v > 10000)
{
send(data);
send("\n01Q\nOut of range\n\n");
}
else
{
saved_param.soft_brake_ms = v;
send(data);
send("\n00P\n\n");
}
}
else if (strstr(data, "$SETBUZZERLEVEL") == data)
{
Expand Down

0 comments on commit a841af4

Please sign in to comment.