Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 14, 2024
1 parent 7fa68b7 commit c978340
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/serial/SerialInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ static void serialSkipWhitespaces(SerialBuffer& buffer)

static void serialEchoBuffer(std::string_view buffer)
{
::Serial.printf(CLEAR_LINE "> %.*s\n", buffer.size(), buffer.data());
::Serial.printf(CLEAR_LINE "> %.*s", buffer.size(), buffer.data());
::Serial.flush();
}

Expand Down Expand Up @@ -474,13 +474,13 @@ static const OpenShock::Serial::CommandEntry* getCommandEntry(const std::vector<

if (commandName.empty()) {
// Unnamed commands: select if argument size fits and has the closest to that many arguments seen yet
if (commandArgs.size() <= arguments.size() && commandArgs.size() > bestMatchArgsCount) {
if (commandArgs.size() <= arguments.size() && commandArgs.size() >= bestMatchArgsCount) {
bestMatch = &command;
bestMatchArgsCount = commandArgs.size();
}
} else {
// Named commands: exact name match, argument size fits and has the closest to that many arguments seen yet
if (command.name() == arguments[0] && commandArgs.size() < arguments.size() && commandArgs.size() > bestMatchArgsCount) {
if (commandName == arguments[0] && commandArgs.size() < arguments.size() && commandArgs.size() >= bestMatchArgsCount) {
bestMatch = &command;
bestMatchArgsCount = commandArgs.size();
}
Expand Down Expand Up @@ -523,11 +523,17 @@ static void serialProcessLine(std::string_view line)
}

auto commandEntry = getCommandEntry(OpenShock::StringSplit(arguments, ' '), it->second.commands());
if (commandEntry != nullptr) {
commandEntry->commandHandler()(arguments, isAutomated);
if (commandEntry == nullptr) {
printCommandHelp(it->second);
return;
}

auto commandEntryName = commandEntry->name();
if (!commandEntryName.empty()) {
arguments = OpenShock::StringTrim(arguments.substr(commandEntryName.size()))
}

printCommandHelp(it->second);
commandEntry->commandHandler()(arguments, isAutomated);
}

static void serialTaskRX(void*)
Expand Down

0 comments on commit c978340

Please sign in to comment.