Skip to content

Commit 183a5d6

Browse files
committed
Allow white space in the command
Valid commands may now include space, horizontal tab(0x09), line feed (0x0a), vertical tab (0x0b), form feed (0x0c) and are terminated with a carriage return (0x0d). These characters are removed prior to processing the command. Blank lines return OK. Valid commands: at-netID = 1 translates into AT-NETID=1 a t i 1 translates into ATI1
1 parent 3f7adee commit 183a5d6

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)