49static std::unique_ptr<DomeScript> scope_script(
new DomeScript());
57 return "Dome Scripting Gateway";
64 ScriptsTP[
SCRIPT_FOLDER].fill(
"SCRIPT_FOLDER",
"Folder",
"/usr/local/share/indi/scripts");
66 ScriptsTP[
SCRIPT_FOLDER].fill(
"SCRIPT_FOLDER",
"Folder",
"/usr/share/indi/scripts");
69 ScriptsTP[
SCRIPT_CONNECT].fill(
"SCRIPT_CONNECT",
"Connect script",
"connect.py");
70 ScriptsTP[
SCRIPT_DISCONNECT].fill(
"SCRIPT_DISCONNECT",
"Disconnect script",
"disconnect.py");
71 ScriptsTP[
SCRIPT_STATUS].fill(
"SCRIPT_STATUS",
"Get status script",
"status.py");
72 ScriptsTP[
SCRIPT_OPEN].fill(
"SCRIPT_OPEN",
"Open shutter script",
"open.py");
73 ScriptsTP[
SCRIPT_CLOSE].fill(
"SCRIPT_CLOSE",
"Close shutter script",
"close.py");
74 ScriptsTP[
SCRIPT_PARK].fill(
"SCRIPT_PARK",
"Park script",
"park.py");
75 ScriptsTP[
SCRIPT_UNPARK].fill(
"SCRIPT_UNPARK",
"Unpark script",
"unpark.py");
76 ScriptsTP[
SCRIPT_GOTO].fill(
"SCRIPT_GOTO",
"Goto script",
"goto.py");
77 ScriptsTP[
SCRIPT_MOVE_CW].fill(
"SCRIPT_MOVE_CW",
"Move clockwise script",
"move_cw.py");
78 ScriptsTP[
SCRIPT_MOVE_CCW].fill(
"SCRIPT_MOVE_CCW",
"Move counter clockwise script",
"move_ccw.py");
79 ScriptsTP[
SCRIPT_ABORT].fill(
"SCRIPT_ABORT",
"Abort motion script",
"abort.py");
84 TypeSP[Dome].fill(
"DOME",
"Dome",
ISS_ON);
85 TypeSP[Rolloff].fill(
"ROLLOFF",
"Roll off",
ISS_OFF);
89 if (TypeSP[Dome].getState() ==
ISS_ON)
134 if (ScriptsTP.isNameMatch(name))
136 ScriptsTP.update(texts, names,
n);
137 ScriptsTP.setState(
IPS_OK);
153 if (TypeSP.isNameMatch(name))
155 TypeSP.update(states, names,
n);
159 LOG_INFO(
"Driver must be restarted for this change to take effect");
169bool DomeScript::RunScript(
int script, ...)
172 snprintf(tmp,
sizeof(tmp),
"%s", ScriptsTP[script].
getText());
174 char **args = (
char **)malloc(
MAXARGS *
sizeof(
char *));
180 char *pp = strstr(p,
" ");
188 va_start(ap, script);
191 char *pp = va_arg(ap,
char *);
198 snprintf(path,
sizeof(path),
"%s/%s", ScriptsTP[0].
getText(), tmp);
200 if (access(path, F_OK | X_OK) != 0)
208 snprintf(dbg,
sizeof(dbg),
"execvp('%s'", path);
209 for (
int i = 0; args[i]; i++)
212 strcat(dbg, args[i]);
215 strcat(dbg,
", nullptr)");
234 waitpid(pid, &status, 0);
269 char tmpfile[] =
"/tmp/indi_dome_script_status_XXXXXX";
270 int fd = mkstemp(tmpfile);
273 LOGF_ERROR(
"Temp file %s creation for status script failed, %s", tmpfile, strerror(
errno));
281 int parked = 0, shutter = 0;
283 FILE *file = fopen(tmpfile,
"r");
284 int rc = fscanf(file,
"%d %d %f", &parked, &shutter, &az);
297 LOG_INFO(
"Park successfully executed");
306 LOG_INFO(
"Unpark successfully executed");
309 if (TypeSP[Dome].getState() ==
ISS_ON && std::round(az * 10) != std::round(TargetAz * 10))
311 LOGF_INFO(
"Moving %g -> %g %d", std::round(az * 10) / 10, std::round(TargetAz * 10) / 10,
getDomeState());
320 if (TypeSP[Dome].getState() ==
ISS_ON)
342 if (TypeSP[Dome].getState() ==
ISS_ON && !
isParked() && TimeSinceUpdate++ > 4)
377 LOG_INFO(
"Successfully disconnected");
433 snprintf(_az, 16,
"%f",
round(az * 10) / 10);
434 bool status = RunScript(
SCRIPT_GOTO, _az,
nullptr);
449 auto commandOk =
false;
468 if (TypeSP[Dome].getState())
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual const char * getDefaultName() override
virtual IPState Park() override
Goto Park Position. The park position is an absolute azimuth value.
virtual IPState UnPark() override
UnPark dome. The action of the Unpark command is dome specific, but it may include opening the shutte...
virtual bool Abort() override
Abort all dome motion.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual IPState Move(DomeDirection dir, DomeMotionCommand operation) override
Move the Dome in a particular direction.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
virtual IPState MoveAbs(double az) override
Move the Dome to an absolute azimuth.
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual IPState ControlShutter(ShutterOperation operation) override
Open or Close shutter.
virtual bool Disconnect() override
Disconnect from device.
INDI::PropertyText getText(const char *name) const
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
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.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
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.
bool isParked()
isParked is dome currently parked?
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
ShutterState m_ShutterState
void SetAxis1Park(double value)
SetRAPark Set current AZ parking position. The data park file (stored in ~/.indi/ParkData....
void UpdateMountCoords()
updateCoords updates the horizontal coordinates (Az & Alt) of the mount from the snooped RA,...
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.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
INDI::PropertyNumber DomeAbsPosNP
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Dome Presets in the configuration file
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...
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
DomeState getDomeState() const
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Implementations for common driver routines.
*brief user defined string literal for JSON values *sa std::size_t n
#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,...)
double round(double value, int decimal_places)