Skip to content

Commit 4b41c06

Browse files
authored
Merge pull request #529 from LeeLeahy2/remove-cmd-white-space
Allow white space in the command
2 parents 8e163d4 + 183a5d6 commit 4b41c06

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,12 @@ void checkCommand()
814814
int prefixLength;
815815
bool success;
816816

817-
//Verify the command length
817+
//Zero terminate the string
818818
success = false;
819-
commandString = trimCommand(); //Remove any leading or trailing whitespace
819+
commandBuffer[commandLength] = 0;
820+
821+
//Remove any whitespace
822+
commandString = trimCommand();
820823

821824
//Upper case the command
822825
for (index = 0; index < commandLength; index++)
@@ -845,6 +848,8 @@ void checkCommand()
845848
break;
846849
}
847850
}
851+
else if (!commandLength)
852+
success = true;
848853

849854
//Print the command failure
850855
petWDT();
@@ -903,24 +908,20 @@ void commandReset()
903908
//Remove any preceeding or following whitespace chars
904909
char * trimCommand()
905910
{
906-
char * commandString = commandBuffer;
911+
int index;
912+
int j;
907913

908-
//Remove the leading white space
909-
while (isspace(*commandString))
914+
//Remove the white space
915+
for (index = 0; index < commandLength; index++)
910916
{
911-
commandString++;
912-
--commandLength;
917+
while (isspace(commandBuffer[index]))
918+
{
919+
for (j = index + 1; j < commandLength; j++)
920+
commandBuffer[j - 1] = commandBuffer[j];
921+
commandBuffer[--commandLength] = 0;
922+
}
913923
}
914-
915-
//Zero terminate the string
916-
commandString[commandLength] = 0;
917-
918-
//Remove the trailing white space
919-
while (commandLength && isspace(commandString[commandLength - 1]))
920-
commandString[--commandLength] = 0;
921-
922-
//Return the remainder as the command
923-
return commandString;
924+
return commandBuffer;
924925
}
925926

926927
//Display all of the commands

0 commit comments

Comments
 (0)