diff --git a/JumperlessNano/src/MachineCommands.cpp b/JumperlessNano/src/MachineCommands.cpp index 3ebcf3b..824a783 100644 --- a/JumperlessNano/src/MachineCommands.cpp +++ b/JumperlessNano/src/MachineCommands.cpp @@ -24,7 +24,7 @@ enum machineModeInstruction lastReceivedInstruction = unknown; char machineModeInstructionString[NUMBEROFINSTRUCTIONS][20] = {"unknown", "netlist", "getnetlist", "bridgelist", "getbridgelist", "lightnode", "lightnet", "getmeasurement", "gpio", "uart", "arduinoflash", "setnetcolor", "setnodecolor", "setsupplyswitch"}; -enum machineModeInstruction parseMachineInstructions(void) +enum machineModeInstruction parseMachineInstructions(int *sequenceNumber) { int doneReading = 0; @@ -55,17 +55,26 @@ enum machineModeInstruction parseMachineInstructions(void) char instructionBuffer[20] = {0}; + int seqNumberSeparatorPos = -1; + for (int i = 0; i < 20; i++) { - if (inputBuffer[i] == '[') - { + if (inputBuffer[i] == '[') { // inputBuffer[i] = ' '; break; } + if (inputBuffer[i] == ':') { + seqNumberSeparatorPos = i; + } instructionBuffer[i] = inputBuffer[i]; inputBuffer[i] = ' '; } + if (seqNumberSeparatorPos > 0) { + instructionBuffer[seqNumberSeparatorPos] = 0; + *sequenceNumber = atoi(instructionBuffer + seqNumberSeparatorPos + 1); + } + for (int i = 0; i < NUMBEROFINSTRUCTIONS; i++) { if (strcasecmp(instructionBuffer, machineModeInstructionString[i]) == 0) @@ -107,6 +116,15 @@ enum machineModeInstruction parseMachineInstructions(void) return lastReceivedInstruction; } +void machineModeRespond(int sequenceNumber, bool ok) { + Serial.print(ok ? "::ok" : "::error"); + if (sequenceNumber >= 0) { + Serial.print(":"); + Serial.print(sequenceNumber); + } + Serial.println(""); +} + void machineNetlistToNetstruct(void) { char names[MAX_NETS][32] = {0}; diff --git a/JumperlessNano/src/MachineCommands.h b/JumperlessNano/src/MachineCommands.h index 55dd785..7d8ad92 100644 --- a/JumperlessNano/src/MachineCommands.h +++ b/JumperlessNano/src/MachineCommands.h @@ -24,7 +24,8 @@ enum machineModeInstruction extern char inputBuffer[INPUTBUFFERLENGTH]; extern char machineModeInstructionString[NUMBEROFINSTRUCTIONS][20]; -enum machineModeInstruction parseMachineInstructions(void); +enum machineModeInstruction parseMachineInstructions(int *sequenceNumber); +void machineModeRespond(int sequenceNumber, bool ok); void machineNetlistToNetstruct(void); void populateBridgesFromNodes(void); int nodeTokenToInt(char *); diff --git a/JumperlessNano/src/main.cpp b/JumperlessNano/src/main.cpp index d3db880..b58fc32 100644 --- a/JumperlessNano/src/main.cpp +++ b/JumperlessNano/src/main.cpp @@ -475,8 +475,8 @@ skipinput: void machineMode(void) // read in commands in machine readable format { - - enum machineModeInstruction receivedInstruction = parseMachineInstructions(); + int sequenceNumber = -1; + enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber); switch (receivedInstruction) { @@ -545,9 +545,13 @@ void machineMode(void) // read in commands in machine readable format // case gpio: // break; + + case unknown: + machineModeRespond(sequenceNumber, false); + return; } - + machineModeRespond(sequenceNumber, true); } unsigned long logoFlashTimer = 0;