Merge pull request #21 from nilclass/machine-mode-response

Machine mode: respond to commands to signal success
This commit is contained in:
Kevin Santo Cappuccio 2024-01-03 00:25:04 -08:00 committed by GitHub
commit 30f6214cda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View File

@ -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"}; 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; int doneReading = 0;
@ -55,17 +55,26 @@ enum machineModeInstruction parseMachineInstructions(void)
char instructionBuffer[20] = {0}; char instructionBuffer[20] = {0};
int seqNumberSeparatorPos = -1;
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
if (inputBuffer[i] == '[') if (inputBuffer[i] == '[') {
{
// inputBuffer[i] = ' '; // inputBuffer[i] = ' ';
break; break;
} }
if (inputBuffer[i] == ':') {
seqNumberSeparatorPos = i;
}
instructionBuffer[i] = inputBuffer[i]; instructionBuffer[i] = inputBuffer[i];
inputBuffer[i] = ' '; inputBuffer[i] = ' ';
} }
if (seqNumberSeparatorPos > 0) {
instructionBuffer[seqNumberSeparatorPos] = 0;
*sequenceNumber = atoi(instructionBuffer + seqNumberSeparatorPos + 1);
}
for (int i = 0; i < NUMBEROFINSTRUCTIONS; i++) for (int i = 0; i < NUMBEROFINSTRUCTIONS; i++)
{ {
if (strcasecmp(instructionBuffer, machineModeInstructionString[i]) == 0) if (strcasecmp(instructionBuffer, machineModeInstructionString[i]) == 0)
@ -107,6 +116,15 @@ enum machineModeInstruction parseMachineInstructions(void)
return lastReceivedInstruction; 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) void machineNetlistToNetstruct(void)
{ {
char names[MAX_NETS][32] = {0}; char names[MAX_NETS][32] = {0};

View File

@ -24,7 +24,8 @@ enum machineModeInstruction
extern char inputBuffer[INPUTBUFFERLENGTH]; extern char inputBuffer[INPUTBUFFERLENGTH];
extern char machineModeInstructionString[NUMBEROFINSTRUCTIONS][20]; extern char machineModeInstructionString[NUMBEROFINSTRUCTIONS][20];
enum machineModeInstruction parseMachineInstructions(void); enum machineModeInstruction parseMachineInstructions(int *sequenceNumber);
void machineModeRespond(int sequenceNumber, bool ok);
void machineNetlistToNetstruct(void); void machineNetlistToNetstruct(void);
void populateBridgesFromNodes(void); void populateBridgesFromNodes(void);
int nodeTokenToInt(char *); int nodeTokenToInt(char *);

View File

@ -475,8 +475,8 @@ skipinput:
void machineMode(void) // read in commands in machine readable format void machineMode(void) // read in commands in machine readable format
{ {
int sequenceNumber = -1;
enum machineModeInstruction receivedInstruction = parseMachineInstructions(); enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber);
switch (receivedInstruction) switch (receivedInstruction)
{ {
@ -545,9 +545,13 @@ void machineMode(void) // read in commands in machine readable format
// case gpio: // case gpio:
// break; // break;
case unknown:
machineModeRespond(sequenceNumber, false);
return;
} }
machineModeRespond(sequenceNumber, true);
} }
unsigned long logoFlashTimer = 0; unsigned long logoFlashTimer = 0;