34 #include <sys/ioctl.h>
37 static std::unique_ptr<DeepSkyDadFP1> dsdFp1(
new DeepSkyDadFP1());
41 #define FLAT_TIMEOUT 3
60 IUFillText(&StatusT[0],
"Cover",
"Cover",
nullptr);
61 IUFillText(&StatusT[1],
"Light",
"Light",
nullptr);
62 IUFillText(&StatusT[2],
"Motor",
"Motor",
nullptr);
63 IUFillText(&StatusT[3],
"Heater",
"Heater",
nullptr);
67 IUFillText(&FirmwareT[0],
"Version",
"Version",
nullptr);
133 return "Deep Sky Dad FP1";
136 bool DeepSkyDadFP1::Handshake()
180 if (strcmp(HeaterModeSP.
name, name) == 0)
188 if (current_mode == target_mode)
199 bool rc = sendCommand(
cmd, response);
203 HeaterModeS[current_mode].s =
ISS_ON;
234 bool DeepSkyDadFP1::ping()
238 if (!sendCommand(
"[GPOS]", response))
254 bool DeepSkyDadFP1::getStartupData()
256 bool rc1 = getFirmwareVersion();
257 bool rc2 = getStatus();
258 bool rc3 = getBrightness();
260 return (rc1 && rc2 && rc3);
266 if (!sendCommand(
"[STRG270]", response) || !sendCommand(
"[SMOV]", response))
269 if (strcmp(response,
"(OK)") == 0)
272 prevCoverStatus = 10;
282 if (!sendCommand(
"[STRG0]", response) || !sendCommand(
"[SMOV]", response))
285 if (strcmp(response,
"(OK)") == 0)
288 prevCoverStatus = 10;
301 strncpy(command,
"[SLON1]",
FLAT_CMD);
303 strncpy(command,
"[SLON0]",
FLAT_CMD);
305 if (!sendCommand(command, response))
308 if (strcmp(response,
"(OK)") == 0)
314 bool DeepSkyDadFP1::getStatus()
321 int heaterTemperature;
324 if (!sendCommand(
"[GMOV]", response))
327 sscanf(response,
"(%d)", &motorStatus);
329 if (!sendCommand(
"[GLON]", response))
332 sscanf(response,
"(%d)", &lightStatus);
334 if (!sendCommand(
"[GPOS]", response))
337 sscanf(response,
"(%d)", &coverStatus);
339 if (!sendCommand(
"[GHTT]", response))
342 sscanf(response,
"(%d)", &heaterTemperature);
344 if (!sendCommand(
"[GHTM]", response))
347 sscanf(response,
"(%d)", &heaterMode);
350 bool statusUpdated =
false;
352 if (coverStatus != prevCoverStatus)
360 else if(coverStatus == 270)
371 prevCoverStatus = coverStatus;
373 statusUpdated =
true;
388 else if(coverStatus == 270)
413 if (lightStatus != prevLightStatus)
415 prevLightStatus = lightStatus;
417 statusUpdated =
true;
437 if (motorStatus != prevMotorStatus)
439 prevMotorStatus = motorStatus;
441 statusUpdated =
true;
458 int heaterConnected = heaterTemperature > -40;
459 if(heaterConnected != prevHeaterConnected)
461 prevHeaterConnected = heaterConnected;
462 if(heaterConnected == 1)
474 if(heaterMode != prevHeaterMode)
476 prevHeaterMode = heaterMode;
480 HeaterModeS[0].s =
ISS_ON;
482 else if(heaterMode == 1)
484 HeaterModeS[1].s =
ISS_ON;
486 else if(heaterMode == 2)
488 HeaterModeS[2].s =
ISS_ON;
496 bool DeepSkyDadFP1::getFirmwareVersion()
499 if (!sendCommand(
"[GFRM]", response))
502 char versionString[6] = { 0 };
503 snprintf(versionString, 6,
"%s", response + 31);
510 bool DeepSkyDadFP1::getBrightness()
513 if (!sendCommand(
"[GLBR]", response))
516 int32_t brightnessValue;
517 int rc = sscanf(response,
"(%d)", &brightnessValue);
521 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
525 if (brightnessValue != prevBrightness)
527 prevBrightness = brightnessValue;
539 snprintf(command,
FLAT_CMD,
"[SLBR%04d]", value);
541 if (!sendCommand(command, response))
544 if (strcmp(response,
"(OK)") != 0)
546 LOGF_ERROR(
"Unable to set brightness value", response);
553 bool DeepSkyDadFP1::sendCommand(
const char *
cmd,
char *res)
555 int nbytes_written = 0, nbytes_read = 0, rc = -1;
557 tcflush(PortFD, TCIOFLUSH);
565 LOGF_ERROR(
"Serial write error: %s.", errstr);
582 tcflush(PortFD, TCIOFLUSH);
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be impelemented in the child class, if supported.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
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...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be impelemented in the child class.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
@ OnIfFlapOpenOrLedActive
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
const char * getDefaultName() override
const char * getDeviceName() const
virtual bool updateProperties()
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)
Process the client newSwitch command.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
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)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
void syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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 initDustCapProperties(const char *deviceName, const char *groupName)
Initilize dust cap properties. It is recommended to call this function within initProperties() of you...
bool processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
ISwitchVectorProperty ParkCapSP
INumberVectorProperty LightIntensityNP
bool processLightBoxNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process light box number properties.
ISwitchVectorProperty LightSP
bool snoopLightBox(XMLEle *root)
INumber LightIntensityN[1]
bool processLightBoxSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process light box switch properties.
void initLightBoxProperties(const char *deviceName, const char *groupNam)
Initilize light box properties. It is recommended to call this function within initProperties() of yo...
bool processLightBoxText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process light box text properties.
bool updateLightBoxProperties()
bool saveLightBoxConfigItems(FILE *fp)
void isGetLightBoxProperties(const char *deviceName)
isGetLightBoxProperties Get light box properties
Provides interface to implement controllable light box/switch device.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
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.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
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 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 IDSetText(const ITextVectorProperty *tvp, const char *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,...)