54 delete serialConnection;
63 StatusTP[0].
fill(
"COVER",
"Cover",
nullptr);
64 StatusTP[1].
fill(
"LIGHT",
"Light",
nullptr);
65 StatusTP[2].
fill(
"MOTOR",
"Motor",
nullptr);
69 FirmwareTP[0].
fill(
"VERSION",
"Version",
nullptr);
94 return callHandshake();
104 return callHandshake();
158bool SnapCap::Handshake()
177bool SnapCap::callHandshake()
179 if (dustcapConnection > 0)
219 ForceSP.
update(states, names, n);
249 bool found = getFirmwareVersion();
253 found = getFirmwareVersion();
257bool SnapCap::sendCommand(
const char *command,
char *response)
259 int nbytes_written = 0, nbytes_read = 0, rc = -1;
262 tcflush(PortFD, TCIOFLUSH);
267 snprintf(buffer,
SNAP_CMD + 1,
"%s\r\n", command);
283 response[nbytes_read - 2] = 0;
289bool SnapCap::getStartupData()
291 bool rc1 = getFirmwareVersion();
292 bool rc2 = getStatus();
293 bool rc3 = getBrightness();
295 return (rc1 && rc2 && rc3);
302 simulationWorkCounter = 3;
309 if (ForceSP[1].getState() ==
ISS_ON)
310 strncpy(command,
">c000",
SNAP_CMD);
312 strncpy(command,
">C000",
SNAP_CMD);
314 if (!sendCommand(command, response))
317 if (strcmp(response,
"*C000") == 0 || strcmp(response,
"*c000") == 0)
320 prevCoverStatus = 10;
321 targetCoverStatus = 2;
332 simulationWorkCounter = 3;
339 if (ForceSP[1].getState() ==
ISS_ON)
340 strncpy(command,
">o000",
SNAP_CMD);
342 strncpy(command,
">O000",
SNAP_CMD);
344 if (!sendCommand(command, response))
347 if (strcmp(response,
"*O000") == 0 || strcmp(response,
"*o000") == 0)
350 prevCoverStatus = 10;
351 targetCoverStatus = 1;
362 simulationWorkCounter = 0;
368 if (!sendCommand(
">A000", response))
371 if (strcmp(response,
"*A000") == 0)
374 prevCoverStatus = 10;
390 strncpy(command,
">L000",
SNAP_CMD);
392 strncpy(command,
">D000",
SNAP_CMD);
394 if (!sendCommand(command, response))
399 snprintf(expectedResponse,
SNAP_RES,
"*L000");
401 snprintf(expectedResponse,
SNAP_RES,
"*D000");
403 if (strcmp(response, expectedResponse) == 0)
409bool SnapCap::getStatus()
419 simulationWorkCounter = 0;
441 if (!sendCommand(
">S000", response))
445 char motorStatus = response[2] -
'0';
446 char lightStatus = response[3] -
'0';
447 char coverStatus = response[4] -
'0';
454 bool statusUpdated =
false;
456 if (coverStatus != prevCoverStatus)
458 prevCoverStatus = coverStatus;
460 statusUpdated =
true;
465 StatusTP[0].setText(
"Opening/closing");
471 StatusTP[0].setText(
"Open");
483 StatusTP[0].setText(
"Closed");
493 StatusTP[0].setText(
"Timed out");
497 StatusTP[0].setText(
"Open circuit");
501 StatusTP[0].setText(
"Overcurrent");
505 StatusTP[0].setText(
"User abort");
510 if (lightStatus != prevLightStatus)
512 prevLightStatus = lightStatus;
514 statusUpdated =
true;
519 StatusTP[1].setText(
"Off");
529 StatusTP[1].setText(
"On");
540 if (motorStatus != prevMotorStatus)
542 prevMotorStatus = motorStatus;
544 statusUpdated =
true;
549 StatusTP[2].setText(
"Stopped");
553 StatusTP[2].setText(
"Running");
564bool SnapCap::getFirmwareVersion()
568 FirmwareTP[0].setText(
"Ssimulation");
575 if (!sendCommand(
">V000", response))
578 char versionString[4] = { 0 };
579 snprintf(versionString, 4,
"%s", response + 2);
580 FirmwareTP[0].setText(versionString);
596bool SnapCap::getBrightness()
605 if (!sendCommand(
">J000", response))
608 int brightnessValue = 0;
609 int rc = sscanf(response,
"*J%d", &brightnessValue);
613 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
617 if (brightnessValue != prevBrightness)
619 prevBrightness = brightnessValue;
639 snprintf(command,
SNAP_CMD,
">B%03d", value);
641 if (!sendCommand(command, response))
644 int brightnessValue = 0;
645 int rc = sscanf(response,
"*B%d", &brightnessValue);
649 LOGF_ERROR(
"Unable to parse brightness value (%s)", response);
653 if (brightnessValue != prevBrightness)
655 prevBrightness = brightnessValue;
665 return dustcapConnection;
672 if (value == 0 || (mask & value) == 0)
674 LOGF_ERROR(
"Invalid connection mode %d", value);
678 dustcapConnection = value;
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 ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
Provides interface to implement remotely controlled dust cover.
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 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.
Connection::Interface * getActiveConnection()
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
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
Initialize properties initial state and value. The child class must implement this function.
virtual IPState AbortCap() override
Abort motion. Must be implemented by child.
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.
void setDustcapConnection(const uint8_t &value)
setDustcapConnection Set Dustcap connection mode. Child class should call this in the constructor bef...
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.
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 implemented in the child class.
uint8_t getDustcapConnection() const
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.
#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())