Skip to content

Commit

Permalink
Change Programming Mode Entry Strategy (Issue #24)
Browse files Browse the repository at this point in the history
Since EQMOD V2.00, the :Oxx is issued as part of run time. This caused AstroEQ to spuriously enter programming mode causing connection issues.

To combat the problem, programming mode entry now requires 20 successive :O1x commands with no other commands in between.

It is highly unlikely EQMOD will ever issue this many :O1x commands without other commands interleaved. EQMOD always appears to send :O1x commands together with a companion :O2x command. This is enough to prevent entry as only an :O1x command is considered.
  • Loading branch information
TCWORLD committed Jun 23, 2018
1 parent a13cdad commit 0e0e9af
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
22 changes: 14 additions & 8 deletions AstroEQ-ConfigUtility/AstroEQUploader/Executioner.pde
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,20 @@ public class EEPROMInterface extends Executioner {
} catch (Exception e){

}
write(":O1"+mode+"\r");
buffer.add(":O1"+mode);
println(":O1"+mode);
String readback = getResponse(10000,'\r');
println(readback);
if((readback==null) || !readback.equals("=\r")){ //try to find a response within 10 seconds
exitCode = 3; //could not set mode, fatal error
println("Failed to recieve response.");

String readback;
//Send the entry command 20 times and AstroEQ will only update programming mode after 10 successful entry requests.
for (int i = 0; i < 20; i++) {
write(":O1"+mode+"\r");
buffer.add(":O1"+mode);
println(":O1"+mode);

readback = getResponse(10000,'\r');
println(readback);
if((readback==null) || !readback.equals("=\r")){ //try to find a response within 10 seconds
exitCode = 3; //could not set mode, fatal error
println("Failed to recieve response.");
}
}

while ((args.size() > 0) && (exitCode == 0)) {
Expand Down
34 changes: 25 additions & 9 deletions AstroEQ-Firmware/AstroEQ/AstroEQ.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ byte readyToGo[2] = {0,0};
unsigned long gotoPosn[2] = {0UL,0UL}; //where to slew to
bool encodeDirection[2];
byte progMode = RUNMODE; //MODES: 0 = Normal Ops (EQMOD). 1 = Validate EEPROM. 2 = Store to EEPROM. 3 = Rebuild EEPROM
byte progModeEntryCount = 0; //Must send 10 non-zero progMode commands to switch out of run-time. This is to prevent accidental entry by EQMOD.
byte microstepConf;
byte driverVersion;
bool standaloneMode = false; //Initially not in standalone mode (EQMOD mode)
Expand Down Expand Up @@ -1065,6 +1066,10 @@ bool decodeCommand(char command, char* buffer){ //each command is axis specific.
byte axis = synta_getaxis();
unsigned int correction;
byte oldSREG;
if ((progMode == RUNMODE) && (command != 'O')) {
//If any command other than programming entry request is sent, reset the entry count.
progModeEntryCount = 0;
}
switch(command) {
case 'e': //read-only, return the eVal (version number)
responseData = cmd.eVal[axis]; //response to the e command is stored in the eVal function for that axis.
Expand Down Expand Up @@ -1148,15 +1153,26 @@ bool decodeCommand(char command, char* buffer){ //each command is axis specific.
//Command required for entering programming mode. All other programming commands cannot be used when progMode = 0 (normal ops)
case 'O': //set the programming mode.
progMode = buffer[0] - '0'; //MODES: 0 = Normal Ops (EQMOD). 1 = Validate EEPROM. 2 = Store to EEPROM. 3 = Rebuild EEPROM
if (progMode != RUNMODE) {
motorStop(RA,1); //emergency axis stop.
motorDisable(RA); //shutdown driver power.
motorStop(DC,1); //emergency axis stop.
motorDisable(DC); //shutdown driver power.
readyToGo[RA] = 0;
readyToGo[DC] = 0;
} else { //reset the uC to return to normal ops mode.
success = false;
if (progModeEntryCount != 20) {
//If we haven't sent enough entry commands to switch into programming mode
if ((progMode != PROGMODE) && (progMode != STOREMODE) && (progMode != REBUILDMODE) && (axis != RA)) {
//If we sent an entry command that asks for normal operation, reset the entry count.
progModeEntryCount = 0;
} else {
//Otherwise increment the count of entry requests.
progModeEntryCount = progModeEntryCount + 1;
}
} else {
if (progMode != RUNMODE) {
motorStop(RA,1); //emergency axis stop.
motorDisable(RA); //shutdown driver power.
motorStop(DC,1); //emergency axis stop.
motorDisable(DC); //shutdown driver power.
readyToGo[RA] = 0;
readyToGo[DC] = 0;
} else { //reset the uC to return to normal ops mode.
success = false;
}
}
break;

Expand Down
5 changes: 3 additions & 2 deletions AstroEQ-Firmware/AstroEQ/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ const char cmd_commands[numberOfCommands][3] = { {'j', 0, 6}, //arranged in orde
{'P', 1, 0},
{'F', 0, 0},
{'L', 0, 0},
//Programmer Commands
//Programmer Entry Command
{'O', 1, 0},
//Programmer Commands - Ignored in Run-Mode
{'A', 6, 0},
{'B', 6, 0},
{'S', 6, 0},
Expand All @@ -113,7 +115,6 @@ const char cmd_commands[numberOfCommands][3] = { {'j', 0, 6}, //arranged in orde
{'z', 0, 2},
{'R', 6, 0},
{'r', 0, 6},
{'O', 1, 0},
{'Q', 2, 0},
{'q', 0, 2},
{'X', 6, 0},
Expand Down

0 comments on commit 0e0e9af

Please sign in to comment.