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 strncpy(response, simulation,
sizeof(response));
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]);
592 strcat(filterList,
"/");
594 filterList[strlen(filterList) - 1] =
'\0';
616 for (
int i = 0; i < maxFilter; i++)
618 snprintf(filterName,
MAXINDINAME,
"FILTER_SLOT_NAME_%d", i + 1);
619 snprintf(filterLabel,
MAXINDILABEL,
"Filter n° %d", i + 1);
629 char *withSpace = filterList;
630 char *withoutSpace = filterList;
631 while (*withSpace !=
'\0')
633 if (*withSpace !=
' ')
635 *withoutSpace = *withSpace;
640 *withoutSpace =
'\0';
646 LOGF_ERROR(
"List of filters name is wrong Nbr char red are: %s", lenResponse);
650 LOG_ERROR(
"Failed to read filter names!");
666 memset(response, 0,
sizeof(response));
680 memset(tempo,
' ',
sizeof(tempo));
696 LOGF_DEBUG(
"Length of the command to write to IFW = %d", strlen(
cmd));
706 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
718 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
723 if (strncmp(response,
"ER=", 3) == 0)
739 LOG_INFO(
"Filters name are saved in IFW");
744 LOGF_INFO(
"Please wait for HOME command start... %d", i);
764 memset(response, 0,
sizeof(response));
771 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
778 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
781 else if (strncmp(response,
"ER=", 3) == 0)
783 LOGF_INFO(
"Get wheel ID error: %s", response);
810 char filter[2] = {0};
812 memset(response, 0,
sizeof(response));
819 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
829 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
841 result = atoi(response);
857 memset(response, 0,
sizeof(response));
868 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
878 LOGF_ERROR(
"(Function %s()) failed to read from TTY", __FUNCTION__);
883 if (strncmp(response,
"ER=", 3) == 0)
885 LOGF_INFO(
"Move to Home error: %s", response);
915 memset(response, 0,
sizeof(response));
922 LOGF_ERROR(
"(Function %s()) failed to write to TTY", __FUNCTION__);
929 LOGF_ERROR(
"(Function %s()) failed to read to TTY", __FUNCTION__);
932 else if (strncmp(response,
"ER=", 3) == 0)
934 LOGF_INFO(
"Get wheel ID error: %s", response);
949 for (
int i = 0; i < (int)strlen(response); i++)
951 if (isdigit(response[i]) != 0)
985 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
Initilize 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.
const char * getDeviceName() 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.
ITextVectorProperty * FilterNameTP
INumberVectorProperty FilterSlotNP
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
Initilize 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.
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 IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
void IUUpdateMinMax(const INumberVectorProperty *nvp)
Function to update the min and max elements of a number in the client.
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.