Skip to content

Commit

Permalink
Added validation of values from NV at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
hjd1964 committed Jun 27, 2020
1 parent c27c4c6 commit e3e14f3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
8 changes: 8 additions & 0 deletions AlignEq.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ void TGeoAlign::init() {
// remember the alignment between sessions
void TGeoAlign::readCoe() {
ax1Cor=nv.readFloat(EE_ax1Cor);
if (ax1Cor < -360 || ax1Cor > 360) { ax1Cor=0.0; DL("NV: bad ax1Cor"); } // valid ax1Cor?
ax2Cor=nv.readFloat(EE_ax2Cor);
if (ax2Cor < -360 || ax2Cor > 360) { ax2Cor=0.0; DL("NV: bad ax2Cor"); } // valid ax2Cor?
dfCor=nv.readFloat(EE_dfCor); // dfCor is ffCor for fork mounts
if (dfCor < -10 || dfCor > 10) { dfCor=0.0; DL("NV: bad dfCor"); } // valid dfCor?
tfCor=nv.readFloat(EE_tfCor);
if (tfCor < -10 || tfCor > 10) { tfCor=0.0; DL("NV: bad tfCor"); } // valid tfCor?
doCor=nv.readFloat(EE_doCor);
if (doCor < -10 || doCor > 10) { doCor=0.0; DL("NV: bad doCor"); } // valid doCor?
pdCor=nv.readFloat(EE_pdCor);
if (pdCor < -10 || pdCor > 10) { pdCor=0.0; DL("NV: bad pdCor"); } // valid pdCor?
altCor=nv.readFloat(EE_altCor);
if (altCor < -10 || altCor > 10) { altCor=0.0; DL("NV: bad altCor"); } // valid altCor?
azmCor=nv.readFloat(EE_azmCor);
if (azmCor < -10 || azmCor > 10) { azmCor=0.0; DL("NV: bad azmCor"); } // valid azmCor?
}

void TGeoAlign::writeCoe() {
Expand Down
8 changes: 8 additions & 0 deletions AlignHor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ void TGeoAlignH::init() {
// remember the alignment between sessions
void TGeoAlignH::readCoe() {
ax1Cor=nv.readFloat(EE_ax1Cor);
if (ax1Cor < -360 || ax1Cor > 360) { ax1Cor=0.0; DL("NV: bad ax1Cor"); } // valid ax1Cor?
ax2Cor=nv.readFloat(EE_ax2Cor);
if (ax2Cor < -360 || ax2Cor > 360) { ax2Cor=0.0; DL("NV: bad ax2Cor"); } // valid ax2Cor?
dfCor=nv.readFloat(EE_dfCor); // dfCor is ffCor for fork mounts
if (dfCor < -10 || dfCor > 10) { dfCor=0.0; DL("NV: bad dfCor"); } // valid dfCor?
tfCor=nv.readFloat(EE_tfCor);
if (tfCor < -10 || tfCor > 10) { tfCor=0.0; DL("NV: bad tfCor"); } // valid tfCor?
doCor=nv.readFloat(EE_doCor);
if (doCor < -10 || doCor > 10) { doCor=0.0; DL("NV: bad doCor"); } // valid doCor?
pdCor=nv.readFloat(EE_pdCor);
if (pdCor < -10 || pdCor > 10) { pdCor=0.0; DL("NV: bad pdCor"); } // valid pdCor?
altCor=nv.readFloat(EE_altCor);
if (altCor < -10 || altCor > 10) { altCor=0.0; DL("NV: bad altCor"); } // valid altCor?
azmCor=nv.readFloat(EE_azmCor);
if (azmCor < -10 || azmCor > 10) { azmCor=0.0; DL("NV: bad azmCor"); } // valid azmCor?
}

void TGeoAlignH::writeCoe() {
Expand Down
6 changes: 5 additions & 1 deletion Command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2053,9 +2053,13 @@ void processCommands() {
if (command[0] == 'W') {
if (command[1] >= '0' && command[1] <= '3' && parameter[0] == 0) {
currentSite=command[1]-'0'; nv.update(EE_currentSite,currentSite); booleanReply=false;
setLatitude(nv.readFloat(EE_sites+(currentSite*25+0)));
double f=nv.readFloat(EE_sites+(currentSite*25+0));
if (f < -90 || f > 90) { f=0.0; DL("NV: bad latitude"); } // valid latitude?
setLatitude(f);
longitude=nv.readFloat(EE_sites+(currentSite*25+4));
if (longitude < -360 || longitude > 360) { longitude=0.0; DL("NV: bad longitude"); } // valid longitude?
timeZone=nv.read(EE_sites+(currentSite)*25+8)-128;
if (timeZone < -12 || timeZone > 14) { timeZone=0.0; DL("NV: bad timeZone"); } // valid time zone?
timeZone=decodeTimeZone(timeZone);
} else
if (command[1] == '?') {
Expand Down
2 changes: 2 additions & 0 deletions Home.ino
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ CommandErrors setHome() {

// reset PEC, unless we have an index to recover from this
pecRecorded=nv.read(EE_pecRecorded);
if (pecRecorded != true && pecRecorded != false) { pecRecorded=false; DL("NV: bad pecRecorded"); } // valid PEC recorded?
#if PEC_SENSE == OFF
pecStatus=IgnorePEC;
nv.write(EE_pecStatus,pecStatus);
#else
pecStatus=nv.read(EE_pecStatus);
if (pecStatus < PEC_STATUS_FIRST || pecStatus > PEC_STATUS_LAST) { pecStatus=IgnorePEC; DL("NV: bad pecStatus"); } // valid PEC status?
#endif
if (!pecRecorded) pecStatus=IgnorePEC;

Expand Down
14 changes: 12 additions & 2 deletions OnStep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
#include "src/HAL/HAL.h"
#include "Validate.h"

// Enable debugging messages on DebugSer -------------------------------------------------------------
// Enable debugging and messages on DebugSer ---------------------------------------------------------
#define DEBUG_OFF // default=_OFF, use "DEBUG_ON" to activate
#define MESSAGE_LOG_OFF // default=_OFF, use "MESSAGE_LOG_ON" to activate
#define DebugSer SerialA // default=SerialA, or SerialB for example (always 9600 baud)

// Helper macros for debugging, with less typing
Expand All @@ -79,6 +80,14 @@
#define DHL(x,y)
#endif

// Helper macros for messages, with less typing
#if defined(MESSAGE_LOG_ON)
#define ML(x) DebugSer.print(x)
#define MLL(x) DebugSer.println(x)
#else
#define ML(x)
#define MLL(x)
#endif
// ---------------------------------------------------------------------------------------------------

#include "src/lib/St4SerialMaster.h"
Expand Down Expand Up @@ -230,6 +239,7 @@ void setup() {

// this sets up the sidereal timer and tracking rates
siderealInterval=nv.readLong(EE_siderealInterval); // the number of 16MHz clocks in one sidereal second (this is scaled to actual processor speed)
if (siderealInterval < 14360682L || siderealInterval > 17551944L) { siderealInterval=15956313L; DL("NV: bad siderealInterval"); } // valid siderealInterval?
SiderealRate=siderealInterval/StepsPerSecondAxis1;
timerRateAxis1=SiderealRate;
timerRateAxis2=SiderealRate;
Expand Down Expand Up @@ -442,7 +452,7 @@ void loop2() {
// It is still low, there must be a problem
generalError=ERR_LIMIT_SENSE;
stopLimit();
}
}
}
#endif

Expand Down
26 changes: 18 additions & 8 deletions Park.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ CommandErrors park() {
double parkTargetAxis1=nv.readFloat(EE_posAxis1);
double parkTargetAxis2=nv.readFloat(EE_posAxis2);
int parkPierSide=nv.read(EE_pierSide);
if (parkPierSide != PierSideNone && parkPierSide != PierSideEast && parkPierSide != PierSideWest) { parkPierSide=PierSideNone; DL("NV: bad parkPierSide"); } // valid parkPierSide?

// now, goto this target coordinate
e=goTo(parkTargetAxis1,parkTargetAxis2,parkTargetAxis1,parkTargetAxis2,parkPierSide);
Expand Down Expand Up @@ -155,14 +156,14 @@ bool doParkClearBacklash(int phase) {

int parkClearBacklash() {
static int phase=1;
if (phase == 1) { if (doParkClearBacklash(1)) { phase++; DL("PCB: phase1 done"); } } else
if (phase == 2) { if (doParkClearBacklash(2)) { phase++; DL("PCB: phase2 done"); } } else
if (phase == 3) { if (doParkClearBacklash(3)) { phase++; DL("PCB: phase3 done"); } } else
if (phase == 4) { if (doParkClearBacklash(4)) { phase++; DL("PCB: phase4 done"); } } else
if (phase == 5) { if (doParkClearBacklash(5)) { phase++; DL("PCB: phase5 done"); } } else
if (phase == 6) { if (doParkClearBacklash(6)) { phase++; DL("PCB: phase6 done"); } } else
if (phase == 7) { if (doParkClearBacklash(7)) { phase++; DL("PCB: phase7 done"); } } else
if (phase == 8) { phase=1; if (doParkClearBacklash(8)) return PCB_SUCCESS; else return PCB_FAILURE; DL("PCB: phase8 done"); }
if (phase == 1) { if (doParkClearBacklash(1)) phase++; } else
if (phase == 2) { if (doParkClearBacklash(2)) phase++; } else
if (phase == 3) { if (doParkClearBacklash(3)) phase++; } else
if (phase == 4) { if (doParkClearBacklash(4)) phase++; } else
if (phase == 5) { if (doParkClearBacklash(5)) phase++; } else
if (phase == 6) { if (doParkClearBacklash(6)) phase++; } else
if (phase == 7) { if (doParkClearBacklash(7)) phase++; } else
if (phase == 8) { phase=1; if (doParkClearBacklash(8)) return PCB_SUCCESS; else { DL("PCB: failure"); return PCB_FAILURE; } }
return PCB_BUSY;
}

Expand Down Expand Up @@ -198,6 +199,8 @@ CommandErrors unPark(bool withTrackingOn) {

// get suggested park position
int parkPierSide=nv.read(EE_pierSide);
if (parkPierSide != PierSideNone && parkPierSide != PierSideEast && parkPierSide != PierSideWest) { parkPierSide=PierSideNone; DL("NV: bad parkPierSide"); } // valid parkPierSide?

setTargetAxis1(nv.readFloat(EE_posAxis1),parkPierSide);
setTargetAxis2(nv.readFloat(EE_posAxis2),parkPierSide);

Expand Down Expand Up @@ -228,7 +231,10 @@ CommandErrors unPark(bool withTrackingOn) {

// get PEC status
pecStatus =nv.read(EE_pecStatus);
if (pecStatus < PEC_STATUS_FIRST || pecStatus > PEC_STATUS_LAST) { pecStatus=IgnorePEC; DL("NV: bad pecStatus"); } // valid PEC status?

pecRecorded=nv.read(EE_pecRecorded); if (!pecRecorded) pecStatus=IgnorePEC;
if (pecRecorded != true && pecRecorded != false) { pecRecorded=false; DL("NV: bad pecRecorded"); } // valid PEC recorded?
}
return CE_NONE;
}
Expand All @@ -248,9 +254,13 @@ boolean saveAlignModel() {
boolean loadAlignModel() {
// get align/corrections
indexAxis1=nv.readFloat(EE_indexAxis1);
if (indexAxis1 < -720 || indexAxis1 > 720) { indexAxis1=0; DL("NV: bad indexAxis1"); } // valid indexAxis1 recorded?
indexAxis1Steps=(long)(indexAxis1*(double)AXIS1_STEPS_PER_DEGREE);

indexAxis2=nv.readFloat(EE_indexAxis2);
if (indexAxis2 < -720 || indexAxis2 > 720) { indexAxis2=0; DL("NV: bad indexAxis2"); } // valid indexAxis2 recorded?
indexAxis2Steps=(long)(indexAxis2*(double)AXIS2_STEPS_PER_DEGREE);

Align.readCoe();
return true;
}

0 comments on commit e3e14f3

Please sign in to comment.