39static std::unique_ptr<FlipFlat> flipflat(
new FlipFlat());
55 IUFillText(&StatusT[0],
"Cover",
"Cover",
nullptr);
56 IUFillText(&StatusT[1],
"Light",
"Light",
nullptr);
57 IUFillText(&StatusT[2],
"Motor",
"Motor",
nullptr);
61 IUFillText(&FirmwareT[0],
"Version",
"Version",
nullptr);
128bool FlipFlat::Handshake()
148 if (ioctl(PortFD, TIOCMBIC, &i) != 0)
153 LOG_DEBUG(
"Successfully connected to flip-flat without hardware IOCTL");
161 if (ioctl(PortFD, TIOCMGET, &i) != 0)
227 if (!sendCommand(
">P000", response))
230 char productString[3] = { 0 };
231 snprintf(productString, 3,
"%s", response + 2);
233 int rc = sscanf(productString,
"%" SCNu16, &productID);
236 LOGF_ERROR(
"Unable to parse input (%s)", response);
248 else if (productID == 98)
260bool FlipFlat::getStartupData()
262 bool rc1 = getFirmwareVersion();
263 bool rc2 = getStatus();
264 bool rc3 = getBrightness();
266 return (rc1 && rc2 && rc3);
273 simulationWorkCounter = 3;
278 if (!sendCommand(
">C000", response))
282 snprintf(expectedResponse,
FLAT_RES,
"*C%02d", productID);
284 if (strstr(response, expectedResponse))
287 prevCoverStatus = 10;
301 simulationWorkCounter = 3;
306 if (!sendCommand(
">O000", response))
310 snprintf(expectedResponse,
FLAT_RES,
"*O%02d", productID);
312 if (strstr(response, expectedResponse))
315 prevCoverStatus = 10;
333 LOG_ERROR(
"Cannot control light while cap is unparked.");
341 strncpy(command,
">L000",
FLAT_CMD);
343 strncpy(command,
">D000",
FLAT_CMD);
345 if (!sendCommand(command, response))
350 snprintf(expectedResponse,
FLAT_RES,
"*L%02d", productID);
352 snprintf(expectedResponse,
FLAT_RES,
"*D%02d", productID);
356 return (strstr(response, expectedResponse));
359bool FlipFlat::getStatus()
369 simulationWorkCounter = 0;
391 if (!sendCommand(
">S000", response))
395 char motorStatus = *(response + 4) -
'0';
396 char lightStatus = *(response + 5) -
'0';
397 char coverStatus = *(response + 6) -
'0';
399 bool statusUpdated =
false;
401 if (coverStatus != prevCoverStatus)
403 prevCoverStatus = coverStatus;
405 statusUpdated =
true;
443 if (lightStatus != prevLightStatus)
445 prevLightStatus = lightStatus;
447 statusUpdated =
true;
473 if (motorStatus != prevMotorStatus)
475 prevMotorStatus = motorStatus;
477 statusUpdated =
true;
497bool FlipFlat::getFirmwareVersion()
507 if (!sendCommand(
">V000", response))
510 char versionString[4] = { 0 };
511 snprintf(versionString, 4,
"%s", response + 4);
537bool FlipFlat::getBrightness()
545 if (!sendCommand(
">J000", response))
548 char brightnessString[4] = { 0 };
549 snprintf(brightnessString, 4,
"%s", response + 4);
551 int brightnessValue = 0;
552 int rc = sscanf(brightnessString,
"%d", &brightnessValue);
556 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
560 if (brightnessValue != prevBrightness)
562 prevBrightness = brightnessValue;
582 snprintf(command,
FLAT_CMD,
">B%03d", value);
584 if (!sendCommand(command, response))
587 char brightnessString[4] = { 0 };
588 snprintf(brightnessString, 4,
"%s", response + 4);
590 int brightnessValue = 0;
591 int rc = sscanf(brightnessString,
"%d", &brightnessValue);
595 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
599 if (brightnessValue != prevBrightness)
601 prevBrightness = brightnessValue;
609bool FlipFlat::sendCommand(
const char *command,
char *response)
611 int nbytes_written = 0, nbytes_read = 0, rc = -1;
615 tcflush(PortFD, TCIOFLUSH);
620 snprintf(buffer,
FLAT_CMD + 1,
"%s\n", command);
622 for (i = 0; i < 3; i++)
643 response[nbytes_read - 1] = 0;
651 static_cast<FlipFlat*
>(context)->parkTimeout();
656 static_cast<FlipFlat*
>(context)->unparkTimeout();
659void FlipFlat::parkTimeout()
663 LOG_WARN(
"Parking cap timed out. Retrying...");
668void FlipFlat::unparkTimeout()
672 LOG_WARN(
"UnParking cap timed out. Retrying...");
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Provides interface to implement remotely controlled dust cover.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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 ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
static void parkTimeoutHelper(void *context)
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
const char * getDefaultName() override
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be implemented in the child class, if supported.
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
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 bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
static void unparkTimeoutHelper(void *context)
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 setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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()
Initialize properties initial state and value. The child class must implement this function.
bool isSimulation() const
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.
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.
INDI::PropertySwitch ParkCapSP
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
void initProperties(const char *group, uint32_t capabilities=0)
Initialize dust cap properties. It is recommended to call this function within initProperties() of yo...
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
void initProperties(const char *group, uint32_t capabilities)
Initialize light box properties. It is recommended to call this function within initProperties() of y...
void ISGetProperties(const char *deviceName)
isGetLightBoxProperties Get light box properties
INDI::PropertyNumber LightIntensityNP
bool saveConfigItems(FILE *fp)
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process light box switch properties.
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process light box text properties.
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process light box number properties.
INDI::PropertySwitch LightSP
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
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.
void IERmTimer(int timerid)
Remove the timer with the given timerid, as returned from IEAddTimer() or IEAddPeriodicTimer().
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer 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 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 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 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