36 #include <sys/ioctl.h>
43 #define SNAP_TIMEOUT 3
55 StatusTP[0].
fill(
"COVER",
"Cover",
nullptr);
56 StatusTP[1].
fill(
"LIGHT",
"Light",
nullptr);
57 StatusTP[2].
fill(
"MOTOR",
"Motor",
nullptr);
61 FirmwareTP[0].
fill(
"VERSION",
"Version",
nullptr);
142 return (
const char *)
"SnapCap";
145 bool SnapCap::Handshake()
202 AbortSP.
update(states, names, n);
232 bool found = getFirmwareVersion();
236 found = getFirmwareVersion();
240 bool SnapCap::sendCommand(
const char *command,
char *response)
242 int nbytes_written = 0, nbytes_read = 0, rc = -1;
245 tcflush(PortFD, TCIOFLUSH);
266 response[nbytes_read - 2] = 0;
272 bool SnapCap::getStartupData()
274 bool rc1 = getFirmwareVersion();
275 bool rc2 = getStatus();
276 bool rc3 = getBrightness();
278 return (rc1 && rc2 && rc3);
285 simulationWorkCounter = 3;
292 if (ForceSP[1].getState() ==
ISS_ON)
293 strncpy(command,
">c000",
SNAP_CMD);
295 strncpy(command,
">C000",
SNAP_CMD);
297 if (!sendCommand(command, response))
300 if (strcmp(response,
"*C000") == 0 || strcmp(response,
"*c000") == 0)
303 prevCoverStatus = 10;
304 targetCoverStatus = 2;
315 simulationWorkCounter = 3;
322 if (ForceSP[1].getState() ==
ISS_ON)
323 strncpy(command,
">o000",
SNAP_CMD);
325 strncpy(command,
">O000",
SNAP_CMD);
327 if (!sendCommand(command, response))
330 if (strcmp(response,
"*O000") == 0 || strcmp(response,
"*o000") == 0)
333 prevCoverStatus = 10;
334 targetCoverStatus = 1;
345 simulationWorkCounter = 0;
351 if (!sendCommand(
">A000", response))
354 if (strcmp(response,
"*A000") == 0)
357 prevCoverStatus = 10;
373 strncpy(command,
">L000",
SNAP_CMD);
375 strncpy(command,
">D000",
SNAP_CMD);
377 if (!sendCommand(command, response))
382 snprintf(expectedResponse,
SNAP_RES,
"*L000");
384 snprintf(expectedResponse,
SNAP_RES,
"*D000");
386 if (strcmp(response, expectedResponse) == 0)
392 bool SnapCap::getStatus()
402 simulationWorkCounter = 0;
424 if (!sendCommand(
">S000", response))
428 char motorStatus = response[2] -
'0';
429 char lightStatus = response[3] -
'0';
430 char coverStatus = response[4] -
'0';
437 bool statusUpdated =
false;
439 if (coverStatus != prevCoverStatus)
441 prevCoverStatus = coverStatus;
443 statusUpdated =
true;
448 StatusTP[0].setText(
"Opening/closing");
454 StatusTP[0].setText(
"Open");
466 StatusTP[0].setText(
"Closed");
476 StatusTP[0].setText(
"Timed out");
480 StatusTP[0].setText(
"Open circuit");
484 StatusTP[0].setText(
"Overcurrent");
488 StatusTP[0].setText(
"User abort");
493 if (lightStatus != prevLightStatus)
495 prevLightStatus = lightStatus;
497 statusUpdated =
true;
502 StatusTP[1].setText(
"Off");
512 StatusTP[1].setText(
"On");
523 if (motorStatus != prevMotorStatus)
525 prevMotorStatus = motorStatus;
527 statusUpdated =
true;
532 StatusTP[2].setText(
"Stopped");
536 StatusTP[2].setText(
"Running");
547 bool SnapCap::getFirmwareVersion()
551 FirmwareTP[0].setText(
"Ssimulation");
558 if (!sendCommand(
">V000", response))
561 char versionString[4] = { 0 };
562 snprintf(versionString, 4,
"%s", response + 2);
563 FirmwareTP[0].setText(versionString);
579 bool SnapCap::getBrightness()
588 if (!sendCommand(
">J000", response))
591 int brightnessValue = 0;
592 int rc = sscanf(response,
"*J%d", &brightnessValue);
596 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
600 if (brightnessValue != prevBrightness)
602 prevBrightness = brightnessValue;
622 snprintf(command,
SNAP_CMD,
">B%03d", value);
624 if (!sendCommand(command, response))
627 int brightnessValue = 0;
628 int rc = sscanf(response,
"*B%d", &brightnessValue);
632 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
636 if (brightnessValue != prevBrightness)
638 prevBrightness = brightnessValue;
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...
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 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
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool isNameMatch(const char *otherName) const
bool update(const ISState states[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
Provides interface to implement controllable light box/switch device.
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
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 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 ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
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.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be impelemented in the child class.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
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 IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, 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
std::unique_ptr< SnapCap > snapcap(new SnapCap())