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"};
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};

View File

@ -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 *);

View File

@ -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;