72 IUFillSwitchVector(&
HomeSP,
HomeS, 1,
getDeviceName(),
"HOME",
"Home",
MAIN_CONTROL_TAB,
IP_RW,
ISR_1OFMANY, 0,
145 int nbytes_written = 0;
172 memset(response, 0,
sizeof(response));
176 snprintf(response,
sizeof(response),
"%s", simulation);
177 nbytes_read = strlen(response) + 2;
184 LOGF_ERROR(
"%s() TTY error: %s", __FUNCTION__, errmsg);
189 if (nbytes_read <= 0)
191 LOG_ERROR(
"Controller error: Nothing returned by the IFW");
196 response[nbytes_read - 2] =
'\0';
208 memset(response, 0,
sizeof(response));
211 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
217 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
221 if (strcmp(response,
"!") != 0)
223 LOG_ERROR(
"failed, wrong response from IFW");
228 LOGF_DEBUG(
"Success, response from IFW is : %s", response);
241 memset(response, 0,
sizeof(response));
245 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
251 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
255 if (strcmp(response,
"END") != 0)
257 LOG_ERROR(
"failed, wrong response from IFW");
261 LOGF_DEBUG(
"IFW return in manual mode, response from IFW is : %s", response);
278 std::regex rx(
"^[A-Z0-9=.#/%[:space:]-]{1,8}$");
284 for (
int i = 0; i < n; i++)
286 LOGF_DEBUG(
"FilterName request N°%d : %s", i, texts[i]);
287 match = std::regex_match(texts[i], rx);
303 LOG_INFO(
"WARNING *****************************************************");
305 "One of the filter name is not valid. It should not have more than 8 chars");
306 LOG_INFO(
"Valid chars are A to Z, 0 to 9 = . # / - percent or space");
307 LOG_INFO(
"WARNING *****************************************************");
329 LOG_INFO(
"Executing Home command...");
341 LOG_DEBUG(
"Getting filter information...");
353 LOGF_INFO(
"%s() failed to get information", __FUNCTION__);
354 LOG_INFO(
"Please check unit and press 'Home' button");
451 memset(response, 0,
sizeof(response));
452 snprintf(
cmd, 32,
"%s%d",
"WGOTO", f);
459 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
495 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
498 else if (strncmp(response,
"*", 1) != 0)
535 memset(response, 0,
sizeof(response));
542 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
547 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
554 lenResponse = strlen(response);
574 LOGF_DEBUG(
"Length of response %d", lenResponse);
578 LOGF_DEBUG(
"Success, response from IFW is : %s", response);
583 filterList[0] =
'\0';
585 for (
int i = 0; i < maxFilter; i++)
590 LOGF_DEBUG(
"filterNameIFW[%d] : %s", i, filterNameIFW[i]);
591 strcat(filterList, filterNameIFW[i]);
592 strcat(filterList,
"/");
594 filterList[strlen(filterList) - 1] =
'\0';
608 for (
int i = 0; i < maxFilter; i++)
610 snprintf(filterName,
MAXINDINAME,
"FILTER_SLOT_NAME_%d", i + 1);
611 snprintf(filterLabel,
MAXINDILABEL,
"Filter n° %d", i + 1);
614 oneText.
fill(filterName, filterLabel, filterNameIFW[i]);
625 char *withSpace = filterList;
626 char *withoutSpace = filterList;
627 while (*withSpace !=
'\0')
629 if (*withSpace !=
' ')
631 *withoutSpace = *withSpace;
636 *withoutSpace =
'\0';
642 LOGF_ERROR(
"List of filters name is wrong Nbr char red are: %s", lenResponse);
646 LOG_ERROR(
"Failed to read filter names!");
662 memset(response, 0,
sizeof(response));
676 memset(tempo,
' ',
sizeof(tempo));
690 LOGF_DEBUG(
"Length of the command to write to IFW = %d", strlen(
cmd));
700 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
712 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
717 if (strncmp(response,
"ER=", 3) == 0)
733 LOG_INFO(
"Filters name are saved in IFW");
738 LOGF_INFO(
"Please wait for HOME command start... %d", i);
758 memset(response, 0,
sizeof(response));
765 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
772 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
775 else if (strncmp(response,
"ER=", 3) == 0)
777 LOGF_INFO(
"Get wheel ID error: %s", response);
804 char filter[2] = {0};
806 memset(response, 0,
sizeof(response));
813 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
823 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
836 result = atoi(response);
852 memset(response, 0,
sizeof(response));
863 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
873 LOGF_ERROR(
"(Function %s()) failed to read from TTY", __FUNCTION__);
878 if (strncmp(response,
"ER=", 3) == 0)
880 LOGF_INFO(
"Move to Home error: %s", response);
910 memset(response, 0,
sizeof(response));
917 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
924 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
927 else if (strncmp(response,
"ER=", 3) == 0)
929 LOGF_INFO(
"Get wheel ID error: %s", response);
944 for (
int i = 0; i < (int)strlen(response); i++)
946 if (isdigit(response[i]) != 0)
980 if (property ==
nullptr)
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
ITextVectorProperty WheelIDTP
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool loadConfig(bool silent=false, const char *property=nullptr) override
Load the last saved configuration file.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual void simulationTriggered(bool enable) override
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
virtual bool GetFilterNames() override
Obtains a list of filter names from the hardware and initializes the FilterNameTP property....
bool WriteTTY(char *command)
virtual bool Disconnect() override
Disconnect from device.
bool ReadTTY(char *resp, char *simulation, int timeout)
ISwitchVectorProperty CharSetSP
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
ISwitchVectorProperty HomeSP
ITextVectorProperty FirmwareTP
ISwitchVectorProperty FilterNbrSP
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool SetFilterNames() override
Set filter names as defined by the client for each filter position. The desired filter names are stor...
char filterSim[OPTEC_MAXLEN_NAMES+1]
virtual const char * getDefaultName() override
virtual bool SelectFilter(int) override
Select a new filter position.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
INDI::PropertyText getText(const char *name) const
virtual bool updateProperties()
virtual bool Disconnect()
Disconnect from 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 loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
bool isSimulation() const
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
INDI::PropertyNumber FilterSlotNP
INDI::PropertyText FilterNameTP
void SelectFilterDone(int newpos)
The child class calls this function when the hardware successfully finished selecting a new filter wh...
virtual bool updateProperties() override
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) override
Process the client newSwitch command.
Connection::Serial * serialConnection
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
void setFilterConnection(const uint8_t &value)
setFilterConnection Set Filter connection mode. Child class should call this in the constructor befor...
int PortFD
For Serial & TCP connections.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
void push(WidgetView< T > &&item)
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
bool isNameMatch(const char *otherName) const
const char * getGroupName() const
bool update(const char *const texts[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
std::unique_ptr< FilterIFW > filter_ifw(new FilterIFW())
#define OPTEC_TIMEOUT_WHOME
#define OPTEC_LEN_FLTNAME
#define OPTEC_TIMEOUT_FIRMWARE
#define OPTEC_MAXLEN_NAMES
#define OPTEC_MAXLEN_RESP
#define OPTEC_WAIT_DATA_OK
#define OPTEC_TIMEOUT_MOVE
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
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.
Implementations for common driver routines.
void IUSaveConfigSwitch(FILE *fp, const ISwitchVectorProperty *svp)
Add a switch vector property value to the configuration file.
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 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,...)
static Logger & getInstance()
Method to get a reference to the object (i.e., Singleton) It is a static method.
int addDebugLevel(const char *debugLevelName, const char *LoggingLevelName)
Adds a new debugging level to the driver.
void fill(const char *name, const char *label, const char *initialText)