34 static std::unique_ptr<CelestronSCT> celestronSCT(
new CelestronSCT());
39 calibrateInProgress(false),
41 focuserIsCalibrated(false)
67 IUFillNumber(&FocusMinPosN[0],
"FOCUS_MIN_VALUE",
"Steps",
"%.f", 0, 40000., 1., 0.);
77 IUFillText(&CalibrateStateT[0],
"CALIBRATE_STATE",
"Calibrate state",
"");
139 if (getStartupParameters())
140 LOG_INFO(
"Celestron SCT focuser parameters updated, focuser ready for use.");
142 LOG_WARN(
"Failed to retrieve some focuser parameters. Check logs.");
160 LOG_INFO(
"Celestron SCT Focuser is online. Getting focus parameters...");
164 LOG_INFO(
"Error retrieving data from Celestron SCT, please ensure Celestron SCT controller is powered and the port is correct.");
170 return "Celestron SCT";
173 bool CelestronSCT::Ack()
182 if (reply.size() == 4)
184 LOGF_INFO(
"Firmware Version %i.%i.%i", reply[0], reply [1], (reply[2] << 8) + reply[3]);
187 LOGF_INFO(
"Firmware Version %i.%i", reply[0], reply [1]);
191 bool CelestronSCT::readPosition()
197 int position = (reply[0] << 16) + (reply[1] << 8) + reply[2];
203 bool CelestronSCT::isMoving()
208 return reply[0] !=
static_cast<uint8_t
>(0xFF);
212 bool CelestronSCT::readLimits()
218 int lo = (reply[0] << 24) + (reply[1] << 16) + (reply[2] << 8) + reply[3];
219 int hi = (reply[4] << 24) + (reply[5] << 16) + (reply[6] << 8) + reply[7];
230 FocusMinPosN[0].value = lo;
235 if (hi > 0 && lo > 0 && hi - lo > 2000 && hi <= 60000 && lo < 50000)
237 focuserIsCalibrated =
true;
238 LOGF_INFO(
"Focus range %i to %i valid", hi, lo);
242 focuserIsCalibrated =
false;
243 LOGF_INFO(
"Focus range %i to %i invalid", hi, lo);
271 if (!strcmp(name, CalibrateSP.
name))
280 LOG_INFO(
"Focuser Calibrate start");
281 calibrateInProgress =
true;
286 LOG_INFO(
"Focuser Calibrate abort");
302 bool CelestronSCT::getStartupParameters()
304 bool rc1 =
false, rc2 =
false;
306 if ( (rc1 = readPosition()))
309 if ( !(rc2 = readLimits()))
311 LOG_WARN(
"Focuser not calibrated, You MUST calibrate before moves are allowed.");
324 if (!focuserIsCalibrated)
326 LOG_ERROR(
"Move not allowed because focuser is not calibrated.");
329 if (calibrateInProgress)
331 LOG_WARN(
"Move not allowed because a calibration is in progress");
337 targetTicks < FocusMinPosN[0].value)
339 LOGF_ERROR(
"Move to %i not allowed because it is out of range", targetTicks);
343 uint32_t position = targetTicks;
351 finalPosition = position;
355 if (!startMove(position))
361 bool CelestronSCT::startMove(uint32_t position)
365 static_cast<uint8_t
>((position >> 16) & 0xFF),
366 static_cast<uint8_t
>((position >> 8) & 0xFF),
367 static_cast<uint8_t
>(position & 0xFF)
370 LOGF_DEBUG(
"startMove %i, %x %x %x", position, data[0], data[1], data[2]);
377 int32_t newPosition = 0;
399 bool rc = readPosition();
421 backlashMove =
false;
422 if (startMove(finalPosition))
423 LOGF_INFO(
"Backlash move to %i", finalPosition);
433 LOG_INFO(
"Focuser reached requested position.");
438 if (calibrateInProgress)
444 bool complete = reply[0] > 0;
445 int state = reply[1];
447 if (complete || state == 0)
451 const char *msg = complete ?
"Calibrate complete" :
"Calibrate aborted";
453 calibrateInProgress =
false;
460 if (complete && readLimits())
469 if (state != calibrateState)
471 calibrateState = state;
473 snprintf(str, 20,
"Calibrate state %i", state);
485 if (calibrateInProgress)
487 LOG_WARN(
"Abort move not allowed when calibrating, use abort calibration to stop");
#define FOC_GET_HS_POSITIONS
bool commandBlind(int port, Target dest, Command cmd, buffer data)
static void setDeviceName(const std::string &device)
bool sendCommand(int port, Target dest, Command cmd, buffer data, buffer &reply)
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool AbortFocuser() override
AbortFocuser Abort Focuser motion.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual void TimerHit() override
TimerHit Primary Loop called every POLLMS milliseconds (set in Options) to check on the focuser statu...
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
const char * getDefaultName() override
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
const char * getDeviceName() const
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
INumberVectorProperty FocusAbsPosNP
INumberVectorProperty FocusRelPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INumber FocusBacklashN[1]
INumberVectorProperty FocusMaxPosNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Connection::Serial * serialConnection
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
std::vector< uint8_t > buffer