34static std::unique_ptr<RigelDome> rigelDome(
new RigelDome());
40#define SIM_SHUTTER_TIMER 5.0
41#define SIM_FLAP_TIMER 5.0
42#define SIM_DOME_HI_SPEED 5.0
43#define SIM_DOME_LO_SPEED 0.5
60 OperationSP[OPERATION_FIND_HOME].fill(
"OPERATION_FIND_HOME",
"Find Home",
ISS_OFF);
61 OperationSP[OPERATION_CALIBRATE].fill(
"OPERATION_CALIBRATE",
"Calibrate",
ISS_OFF);
64 InfoTP[INFO_FIRMWARE].fill(
"FIRMWARE",
"Version",
"NA");
65 InfoTP[INFO_MODEL].fill(
"MODEL",
"Model",
"NA");
66 InfoTP[INFO_TICKS].fill(
"TICKS_PER_REV",
"Ticks/Rev",
"NA");
67 InfoTP[INFO_BATTERY].fill(
"BATTERY",
"Battery",
"NA");
70 HomePositionNP[
AXIS_AZ].fill(
"HOME_AZ",
"AZ D:M:S",
"%10.6m", 0.0, 360.0, 0.0, 0);
79 stuckAngleCounter = 0;
87bool RigelDome::getStartupValues()
99 if (readShutterStatus())
102 if (readHomePosition())
103 HomePositionNP.
apply();
125 char res[DRIVER_LEN] = {0};
126 sendCommand(
"PULSAR", res);
128 bool rc = readShutterStatus();
178 if (OperationSP.isNameMatch(name))
181 if (OperationSP[OPERATION_FIND_HOME].isNameMatch(requestedOperation))
186 OperationSP[OPERATION_FIND_HOME].s =
ISS_ON;
188 LOG_INFO(
"Dome is moving to home position...");
196 else if (OperationSP[OPERATION_CALIBRATE].isNameMatch(requestedOperation))
201 OperationSP[OPERATION_CALIBRATE].s =
ISS_ON;
227 if (HomePositionNP.isNameMatch(name))
229 HomePositionNP.update(values, names,
n);
230 HomePositionNP.setState(
IPS_OK);
231 auto homeAz = HomePositionNP[
AXIS_AZ].getValue();
233 LOGF_INFO(
"Setting home position to %3.1f", homeAz);
234 HomePositionNP.apply();
263 if (std::abs(currentAngle - previousAngle) < ANGLE_TOLERANCE && isMoving)
267 if (stuckAngleCounter >= STUCK_THRESHOLD)
269 stuckAngleCounter = 0;
270 char res[DRIVER_LEN] = {0};
272 if (sendCommand(
"STOP", res))
274 double diff = std::abs(targetAz - currentAngle);
279 LOGF_INFO(
"Motor stopped after %d cycles with no movement. Current: %.3f°, Target: %.3f°, Difference: %.3f°",
280 STUCK_THRESHOLD, currentAngle, targetAz, diff);
290 stuckAngleCounter = 0;
293 previousAngle = currentAngle;
298 bool isHoming = (OperationSP.getState() ==
IPS_BUSY && OperationSP[OPERATION_FIND_HOME].getState() ==
ISS_ON);
299 bool isCalibrating = (OperationSP.getState() ==
IPS_BUSY && OperationSP[OPERATION_CALIBRATE].getState() ==
ISS_ON);
303 LOG_INFO(
"Dome completed homing...");
305 OperationSP.setState(
IPS_OK);
309 else if (isCalibrating)
311 LOG_INFO(
"Dome completed calibration...");
313 OperationSP.setState(
IPS_OK);
338 ShutterState newShutterState = parseShutterState(m_rawShutterState);
344 if (readBatteryLevels())
356 char cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0};
359 snprintf(
cmd, DRIVER_LEN,
"GO %3.1f", az);
360 if (sendCommand(
cmd, res) ==
false)
364 stuckAngleCounter = 0;
384 char cmd[DRIVER_LEN] = {0}, res[DRIVER_LEN] = {0};
387 snprintf(
cmd, DRIVER_LEN,
"ANGLE K %3.1f", az);
388 if (sendCommand(
cmd, res) ==
false)
391 return (res[0] ==
'A');
400 if (setParkAz(targetAz))
403 stuckAngleCounter = 0;
405 char res[DRIVER_LEN] = {0};
406 if (sendCommand(
"GO P", res) ==
false)
417bool RigelDome::home()
420 stuckAngleCounter = 0;
421 targetAz = HomePositionNP[0].getValue();
423 char res[DRIVER_LEN] = {0};
424 if (sendCommand(
"GO H", res) ==
false)
427 return (res[0] ==
'A');
433bool RigelDome::calibrate()
436 stuckAngleCounter = 0;
438 char res[DRIVER_LEN] = {0};
439 if (sendCommand(
"CALIBRATE", res) ==
false)
442 return (res[0] ==
'A');
448bool RigelDome::setHome(
double az)
450 char cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0};
453 snprintf(
cmd, DRIVER_LEN,
"HOME %3.1f", az);
454 if (sendCommand(
cmd, res) ==
false)
457 return (res[0] ==
'A');
473 char res[DRIVER_LEN] = {0};
477 m_TargetShutter = operation;
478 sendCommand(
"OPEN", res);
482 m_TargetShutter = operation;
483 sendCommand(
"CLOSE", res);
494 if (sendCommand(
"STOP"))
497 stuckAngleCounter = 0;
499 if (OperationSP.getState() ==
IPS_BUSY)
501 LOGF_INFO(
"%s is aborted.", OperationSP[OPERATION_CALIBRATE].getState() ==
ISS_ON ?
"Calibration" :
"Finding home");
510 LOG_WARN(
"Shutter motion aborted!");
545bool RigelDome::setShutterConnected(
bool enabled)
547 char cmd[DRIVER_LEN] = {0};
548 snprintf(
cmd, DRIVER_LEN,
"BBOND %d", enabled ? 1 : 0);
549 return sendCommand(
cmd);
555bool RigelDome::isShutterConnected()
557 char res[DRIVER_LEN] = {0};
558 if (sendCommand(
"BBOND", res) ==
false)
560 bool rc = (std::stoi(res) != 0);
561 LOGF_DEBUG(
"Shutter is %s.", (rc ?
"connected" :
"disconnected"));
568bool RigelDome::readStepsPerRevolution()
570 char res[DRIVER_LEN] = {0};
571 if (sendCommand(
"ENCREV", res) ==
false)
574 InfoTP[INFO_TICKS].setText(res);
581bool RigelDome::readBatteryLevels()
583 char res[DRIVER_LEN] = {0};
584 if (sendCommand(
"BAT", res) ==
false)
590 if (sscanf(res,
"%d %lf", &percent, &volts) != 2)
593 char levels[DRIVER_LEN] = {0};
594 snprintf(levels, DRIVER_LEN,
"%.2fv (%d%%)", volts / 1000.0, percent);
595 InfoTP[INFO_BATTERY].setText(levels);
602bool RigelDome::readPosition()
604 char res[DRIVER_LEN] = {0};
605 if (sendCommand(
"ANGLE", res) ==
false)
612bool RigelDome::readHomePosition()
614 char res[DRIVER_LEN] = {0};
616 if (sendCommand(
"HOME", res) ==
false)
619 HomePositionNP[0].setValue(std::stod(res));
626bool RigelDome::setParkAz(
double az)
628 char cmd[DRIVER_LEN] = {0},
res[DRIVER_LEN] = {0};
630 snprintf(
cmd, DRIVER_LEN,
"PARK %3.1f", az);
631 if (sendCommand(
cmd, res) ==
false)
634 return res[0] ==
'A';
640bool RigelDome::readState()
642 char res[DRIVER_LEN] = {0};
643 if (sendCommand(
"V", res) ==
false)
646 std::vector<std::string> fields = split(res,
"\t");
647 if (fields.size() < 13)
685bool RigelDome::readShutterStatus()
687 char res[DRIVER_LEN] = {0};
688 if (sendCommand(
"SHUTTER", res) ==
false)
698bool RigelDome::readFirmware()
700 char res[DRIVER_LEN] = {0};
702 if (sendCommand(
"VER", res) ==
false)
705 InfoTP[INFO_FIRMWARE].setText(res);
712bool RigelDome::readModel()
714 char res[DRIVER_LEN] = {0};
716 if (sendCommand(
"PULSAR", res) ==
false)
719 InfoTP[INFO_MODEL].setText(res);
726bool RigelDome::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
728 int nbytes_written = 0, nbytes_read = 0, rc = -1;
730 tcflush(
PortFD, TCIOFLUSH);
734 char hex_cmd[DRIVER_LEN * 3] = {0};
735 hexDump(hex_cmd,
cmd, cmd_len);
743 char formatted_command[DRIVER_LEN] = {0};
744 snprintf(formatted_command, DRIVER_LEN,
"%s\r",
cmd);
752 LOGF_ERROR(
"Serial write error: %s.", errstr);
760 rc =
tty_read(
PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
774 char hex_res[DRIVER_LEN * 3] = {0};
775 hexDump(hex_res, res, res_len);
781 res[nbytes_read - 1] = 0;
785 tcflush(
PortFD, TCIOFLUSH);
793void RigelDome::hexDump(
char * buf,
const char * data,
int size)
795 for (
int i = 0; i < size; i++)
796 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
799 buf[3 * size - 1] =
'\0';
805std::vector<std::string> RigelDome::split(
const std::string &input,
const std::string ®ex)
808 std::regex re(regex);
809 std::sregex_token_iterator
810 first{input.begin(), input.end(), re, -1},
812 return {first, last};
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
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.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void SetParked(bool isparked)
SetParked Change the mount parking status. The data park file (stored in ~/.indi/ParkData....
void SetDomeCapability(uint32_t cap)
SetDomeCapability set the dome capabilities. All capabilities must be initialized.
void SetAxis1Park(double value)
SetRAPark Set current AZ parking position. The data park file (stored in ~/.indi/ParkData....
ShutterOperation
Shutter operation command.
void SetAxis1ParkDefault(double steps)
SetAxis1Park Set default AZ parking position.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
uint32_t GetDomeCapability() const
GetDomeCapability returns the capability of the dome.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
INDI::PropertyNumber DomeAbsPosNP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void setShutterState(const ShutterState &value)
void setDomeState(const DomeState &value)
bool InitPark()
InitPark Loads parking data (stored in ~/.indi/ParkData.xml) that contains parking status and parking...
Connection::Serial * serialConnection
void SetParkDataType(DomeParkData type)
setParkDataType Sets the type of parking data stored in the park data file and presented to the user.
INDI::PropertySwitch DomeShutterSP
ShutterState getShutterState() const
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
DomeState getDomeState() const
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
virtual bool SetCurrentPark() override
SetCurrentPark Set current coordinates/encoders value as the desired parking position.
virtual bool SetDefaultPark() override
SetDefaultPark Set default coordinates/encoders value as the desired parking position.
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool Sync(double az) override
Sync sets the dome current azimuth as the supplied azimuth position.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
virtual bool Abort() override
Abort all dome motion.
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual const char * getDefaultName() override
virtual IPState MoveRel(double azDiff) override
Move the Dome to an relative position.
virtual bool Handshake() override
perform handshake with device to check communication
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)