mirror of
https://github.com/Architeuthis-Flux/Jumperless.git
synced 2024-11-30 18:24:36 +01:00
Merge pull request #21 from nilclass/machine-mode-response
Machine mode: respond to commands to signal success
This commit is contained in:
commit
30f6214cda
@ -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};
|
||||
|
@ -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 *);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user