36 #include <sys/ioctl.h>
39 static std::unique_ptr<FlipFlat> flipflat(
new FlipFlat());
43 #define FLAT_TIMEOUT 3
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);
131 bool FlipFlat::Handshake()
151 if (ioctl(PortFD, TIOCMBIC, &i) != 0)
158 if (ioctl(PortFD, TIOCMGET, &i) != 0)
220 bool FlipFlat::ping()
224 if (!sendCommand(
">P000", response))
227 char productString[3] = { 0 };
228 snprintf(productString, 3,
"%s", response + 2);
230 int rc = sscanf(productString,
"%" SCNu16, &productID);
233 LOGF_ERROR(
"Unable to parse input (%s)", response);
245 else if (productID == 98)
257 bool FlipFlat::getStartupData()
259 bool rc1 = getFirmwareVersion();
260 bool rc2 = getStatus();
261 bool rc3 = getBrightness();
263 return (rc1 && rc2 && rc3);
270 simulationWorkCounter = 3;
275 if (!sendCommand(
">C000", response))
279 snprintf(expectedResponse,
FLAT_RES,
"*C%02d", productID);
281 if (strstr(response, expectedResponse))
284 prevCoverStatus = 10;
298 simulationWorkCounter = 3;
303 if (!sendCommand(
">O000", response))
307 snprintf(expectedResponse,
FLAT_RES,
"*O%02d", productID);
309 if (strstr(response, expectedResponse))
312 prevCoverStatus = 10;
330 LOG_ERROR(
"Cannot control light while cap is unparked.");
338 strncpy(command,
">L000",
FLAT_CMD);
340 strncpy(command,
">D000",
FLAT_CMD);
342 if (!sendCommand(command, response))
347 snprintf(expectedResponse,
FLAT_RES,
"*L%02d", productID);
349 snprintf(expectedResponse,
FLAT_RES,
"*D%02d", productID);
353 return (strstr(response, expectedResponse));
356 bool FlipFlat::getStatus()
366 simulationWorkCounter = 0;
388 if (!sendCommand(
">S000", response))
392 char motorStatus = *(response + 4) -
'0';
393 char lightStatus = *(response + 5) -
'0';
394 char coverStatus = *(response + 6) -
'0';
396 bool statusUpdated =
false;
398 if (coverStatus != prevCoverStatus)
400 prevCoverStatus = coverStatus;
402 statusUpdated =
true;
440 if (lightStatus != prevLightStatus)
442 prevLightStatus = lightStatus;
444 statusUpdated =
true;
470 if (motorStatus != prevMotorStatus)
472 prevMotorStatus = motorStatus;
474 statusUpdated =
true;
494 bool FlipFlat::getFirmwareVersion()
504 if (!sendCommand(
">V000", response))
507 char versionString[4] = { 0 };
508 snprintf(versionString, 4,
"%s", response + 4);
534 bool FlipFlat::getBrightness()
542 if (!sendCommand(
">J000", response))
545 char brightnessString[4] = { 0 };
546 snprintf(brightnessString, 4,
"%s", response + 4);
548 int brightnessValue = 0;
549 int rc = sscanf(brightnessString,
"%d", &brightnessValue);
553 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
557 if (brightnessValue != prevBrightness)
559 prevBrightness = brightnessValue;
579 snprintf(command,
FLAT_CMD,
">B%03d", value);
581 if (!sendCommand(command, response))
584 char brightnessString[4] = { 0 };
585 snprintf(brightnessString, 4,
"%s", response + 4);
587 int brightnessValue = 0;
588 int rc = sscanf(brightnessString,
"%d", &brightnessValue);
592 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
596 if (brightnessValue != prevBrightness)
598 prevBrightness = brightnessValue;
606 bool FlipFlat::sendCommand(
const char *command,
char *response)
608 int nbytes_written = 0, nbytes_read = 0, rc = -1;
612 tcflush(PortFD, TCIOFLUSH);
619 for (i = 0; i < 3; i++)
640 response[nbytes_read - 1] = 0;
648 static_cast<FlipFlat*
>(context)->parkTimeout();
653 static_cast<FlipFlat*
>(context)->unparkTimeout();
656 void FlipFlat::parkTimeout()
660 LOG_WARN(
"Parking cap timed out. Retrying...");
665 void FlipFlat::unparkTimeout()
669 LOG_WARN(
"UnParking cap timed out. Retrying...");
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 ...
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be impelemented 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 impelemented 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
Initilize 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 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.
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.
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.
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 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 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 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_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