Skip to content

Commit a0f8066

Browse files
authored
Merge pull request #532 from LeeLeahy2/fix-rmt-cmd
Bug Fix: Receive remote command responses when in command mode
2 parents 4b41c06 + 497bf60 commit a0f8066

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

Firmware/LoRaSerial/Commands.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,12 @@ bool sendRemoteCommand(const char * commandString)
780780
commandTXBuffer[commandTXHead++] = commandString[x];
781781
commandTXHead %= sizeof(commandTXBuffer);
782782
}
783+
if (settings.debugSerial)
784+
{
785+
systemPrint("sendRemoteCommand moved ");
786+
systemPrint(commandLength);
787+
systemPrintln(" from commandBuffer into commandTXBuffer");
788+
}
783789
remoteCommandResponse = false;
784790
return true;
785791
}
@@ -812,8 +818,20 @@ void checkCommand()
812818
char * commandString;
813819
int index;
814820
int prefixLength;
821+
PrinterEndpoints responseDestination;
822+
uint16_t responseLength;
815823
bool success;
816824

825+
//Save previous index
826+
if (settings.debugSerial)
827+
{
828+
responseDestination = printerEndpoint;
829+
if (responseDestination == PRINT_TO_SERIAL)
830+
responseLength = txHead;
831+
else
832+
responseLength = commandTXHead;
833+
}
834+
817835
//Zero terminate the string
818836
success = false;
819837
commandBuffer[commandLength] = 0;
@@ -860,6 +878,28 @@ void checkCommand()
860878
systemPrintln("ERROR");
861879
commandComplete(false);
862880
}
881+
882+
//Display the response
883+
printerEndpoint = PRINT_TO_SERIAL;
884+
if (settings.debugSerial)
885+
{
886+
uint16_t tail;
887+
tail = responseLength;
888+
if (responseDestination == PRINT_TO_SERIAL)
889+
{
890+
responseLength = (txHead + sizeof(serialTransmitBuffer) - responseLength) % sizeof(serialTransmitBuffer);
891+
systemPrint("checkCommand placed ");
892+
systemPrint(responseLength);
893+
systemPrintln(" command response bytes into serialTransmitBuffer");
894+
}
895+
else
896+
{
897+
responseLength = (commandTXHead + sizeof(commandTXBuffer) - responseLength) % sizeof(commandTXBuffer);
898+
systemPrint("checkCommand placed ");
899+
systemPrint(responseLength);
900+
systemPrintln(" command response bytes into commandTXBuffer");
901+
}
902+
}
863903
outputSerialData(true);
864904
petWDT();
865905

@@ -911,6 +951,17 @@ char * trimCommand()
911951
int index;
912952
int j;
913953

954+
//Remove the comment
955+
for (index = 0; index < commandLength; index++)
956+
{
957+
if (commandBuffer[index] == '#')
958+
{
959+
commandBuffer[index] = 0;
960+
commandLength = index;
961+
break;
962+
}
963+
}
964+
914965
//Remove the white space
915966
for (index = 0; index < commandLength; index++)
916967
{

Firmware/LoRaSerial/Radio.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,10 @@ PacketType validateDatagram(VIRTUAL_CIRCUIT * vc, PacketType datagramType, uint8
23932393
}
23942394

23952395
//Verify that there is sufficient space in the serialTransmitBuffer
2396-
if (inCommandMode || (freeBytes < rxDataBytes))
2396+
//Apply back pressure if the remote system is trying to send data while
2397+
//the local system is in command mode. Remote command responses should
2398+
//be received.
2399+
if ((inCommandMode && (datagramType == DATAGRAM_DATA)) || (freeBytes < rxDataBytes))
23972400
{
23982401
if (settings.debugReceive || settings.debugDatagrams)
23992402
{

Firmware/LoRaSerial/Serial.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ void updateSerial()
375375
commandBuffer[0] = 'A'; //Convert this RT command to an AT command for local consumption
376376
printerEndpoint = PRINT_TO_RF; //Send prints to RF link
377377
checkCommand(); //Parse the command buffer
378-
printerEndpoint = PRINT_TO_SERIAL;
379378
remoteCommandResponse = true;
380379
}
381380
else
@@ -418,6 +417,12 @@ void processSerialInput()
418417
{
419418
printerEndpoint = PRINT_TO_SERIAL;
420419
systemPrintln();
420+
if (settings.debugSerial)
421+
{
422+
systemPrint("processSerialInput moved ");
423+
systemPrint(commandLength);
424+
systemPrintln(" from serialReceiveBuffer into commandBuffer");
425+
}
421426
checkCommand(); //Process command buffer
422427
}
423428
else if (incoming == '\n')

0 commit comments

Comments
 (0)