30 static std::unique_ptr<lacerta_mfoc_fmc> Lacerta_mfoc_fmc(
new lacerta_mfoc_fmc());
33 #define FOCUSMFOC_TIMEOUT 1000
35 #define MFOC_POSMAX_HARDWARE 250000
36 #define MFOC_POSMIN_HARDWARE 300
55 return "Lacerta MFOC FMC";
87 IUFillNumber(&CurrentHoldingN[0],
"CURRHOLD",
"holding current mA",
"%4d", 0, 1200, 1, 160);
91 IUFillNumber(&CurrentMovingN[0],
"CURRMOVE",
"moving current mA",
"%4d", 0, 1200, 1, 400);
156 char MFOC_cmd[32] =
": q #";
157 char MFOC_res[32] = {0};
158 char MFOC_res_type[32] =
"0";
160 int MFOC_pos_measd = 0;
161 int nbytes_written = 0;
164 bool device_found =
false;
174 LOGF_ERROR(
"Unknown device or MFOC firmware not compatible with this driver version! Please update firmware! %s",
device);
178 sscanf(MFOC_res,
"%s %s", MFOC_res_type,
device);
180 device_found = strcmp(
device,
"MFOC") == 0 || strcmp(
device,
"FMC") == 0;
187 }
while (!device_found && count != 10);
194 MFOC_res[nbytes_read] = 0;
197 sscanf(MFOC_res,
"%s %d", MFOC_res_type, &MFOC_pos_measd);
199 if (MFOC_res_type[0] ==
'p')
218 if (strcmp(TempTrackDirSP.
name, name) == 0)
223 char MFOC_cmd[32] =
": W ";
224 char MFOC_res[32] = {0};
226 int nbytes_written = 0;
227 int MFOC_tdir_measd = 0;
228 char MFOC_res_type[32] =
"0";
234 strcat(MFOC_cmd,
"0 #");
239 strcat(MFOC_cmd,
"1 #");
244 strcat(MFOC_cmd,
"2 #");
249 IDSetSwitch(&TempTrackDirSP,
"Unknown mode index %d", index);
256 LOGF_DEBUG(
"ISNewSwitch: CMD [%s]", MFOC_cmd);
259 MFOC_res[nbytes_read] = 0;
260 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &MFOC_tdir_measd);
261 LOGF_DEBUG(
"ISNewSwitch: RES [%s]", MFOC_res);
263 if (MFOC_tdir_measd == tdir)
277 if (strcmp(StartSavedPositionSP.
name, name) == 0)
282 char MFOC_cmd[32] =
": N ";
283 char MFOC_res[32] = {0};
285 int nbytes_written = 0;
286 int MFOC_svstart_measd = 0;
287 char MFOC_res_type[32] =
"0";
293 strcat(MFOC_cmd,
"1 #");
298 strcat(MFOC_cmd,
"0 #");
303 IDSetSwitch(&StartSavedPositionSP,
"Unknown mode index %d", index);
312 MFOC_res[nbytes_read] = 0;
313 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &MFOC_svstart_measd);
316 if (MFOC_svstart_measd == svstart)
318 StartSavedPositionSP.
s =
IPS_OK;
337 if (strcmp(name,
"TEMPCOMP_SETTINGS") == 0)
339 return SetTempComp(values, names, n);
342 if (strcmp(name,
"CURRHOLD_SETTINGS") == 0)
345 if (!SetCurrHold(CurrentHoldingN[0].value))
356 if (strcmp(name,
"CURRMOVE_SETTINGS") == 0)
359 if (!SetCurrMove(CurrentMovingN[0].value))
380 char MFOC_cmd[32] =
": B ";
381 char MFOC_res[32] = {0};
383 int nbytes_written = 0;
384 int MFOC_tdir_measd = 0;
385 char bl_char[32] = {0};
386 char MFOC_res_type[32] =
"0";
388 sprintf(bl_char,
"%d", steps);
389 strcat(bl_char,
" #");
390 strcat(MFOC_cmd, bl_char);
399 MFOC_res[nbytes_read] = 0;
400 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &MFOC_tdir_measd);
401 }
while(strcmp(
"b", MFOC_res_type) != 0);
407 bool lacerta_mfoc_fmc::SetCurrHold(
int currHoldValue)
409 char MFOC_cmd[32] =
": E ";
410 char MFOC_res[32] = {0};
412 int nbytes_written = 0;
413 int MFOC_ch_measd = 0;
414 char ch_char[32] = {0};
415 char MFOC_res_type[32] =
"0";
417 sprintf(ch_char,
"%d", currHoldValue);
418 strcat(ch_char,
" #");
419 strcat(MFOC_cmd, ch_char);
427 sscanf(MFOC_res,
"%s %d", MFOC_res_type, &MFOC_ch_measd);
428 MFOC_res[nbytes_read] = 0;
429 }
while(strcmp(
"e", MFOC_res_type) != 0);
432 LOGF_INFO(
"Holding Current set to %d mA", MFOC_ch_measd);
437 bool lacerta_mfoc_fmc::SetCurrMove(
int currMoveValue)
439 char MFOC_cmd[32] =
": F ";
440 char MFOC_res[32] = {0};
442 int nbytes_written = 0;
443 int MFOC_cm_measd = 0;
444 char cm_char[32] = {0};
445 char MFOC_res_type[32] =
"0";
447 sprintf(cm_char,
"%d", currMoveValue);
448 strcat(cm_char,
" #");
449 strcat(MFOC_cmd, cm_char);
457 sscanf(MFOC_res,
"%s %d", MFOC_res_type, &MFOC_cm_measd);
458 MFOC_res[nbytes_read] = 0;
459 }
while(strcmp(
"f", MFOC_res_type) != 0);
462 LOGF_INFO(
"Moving Current set to %d mA", MFOC_cm_measd);
467 bool lacerta_mfoc_fmc::SetTempComp(
double values[],
char *names[],
int n)
469 char MFOC_cmd[32] =
": U ";
470 char MFOC_res[32] = {0};
472 int nbytes_written = 0;
473 int MFOC_tc_measd = 0;
475 char tc_char[32] = {0};
476 char MFOC_res_type[32] =
"0";
480 tc_int = TempCompN[0].value;
481 sprintf(tc_char,
"%d", tc_int);
482 strcat(tc_char,
" #");
483 strcat(MFOC_cmd, tc_char);
492 MFOC_res[nbytes_read] = 0;
493 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &MFOC_tc_measd);
494 }
while(strcmp(
"u", MFOC_res_type) != 0);
504 char MFOC_cmd[32] =
": G ";
505 char MFOC_res[32] = {0};
507 int nbytes_written = 0;
508 int MFOC_pm_measd = 0;
509 char pm_char[32] = {0};
510 char MFOC_res_type[32] =
"0";
512 sprintf(pm_char,
"%d", ticks);
513 strcat(pm_char,
" #");
514 strcat(MFOC_cmd, pm_char);
518 IgnoreButLogResponse();
524 MFOC_res[nbytes_read] = 0;
525 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &MFOC_pm_measd);
526 }
while (strcmp(
"g", MFOC_res_type) != 0);
537 char MFOC_cmd[32] =
": M ";
538 char abs_pos_char[32] = {0};
539 int nbytes_written = 0;
542 sprintf(abs_pos_char,
"%d", targetTicks);
543 strcat(abs_pos_char,
" #");
544 strcat(MFOC_cmd, abs_pos_char);
548 IgnoreButLogResponse();
552 GetAbsFocuserPosition();
576 char MFOC_cmd[32] =
": P ";
577 char sync_pos[8] = {0};
579 int nbytes_written = 0;
581 sprintf(sync_pos,
"%d", ticks);
582 strcat(sync_pos,
" #");
583 strcat(MFOC_cmd, sync_pos);
587 IgnoreButLogResponse();
597 char MFOC_cmd[32] =
": H #";
598 char MFOC_res[32] = {0};
599 char MFOC_res_type[32] =
"0";
601 int nbytes_written = 0;
614 MFOC_res[nbytes_read] = 0;
615 sscanf (MFOC_res,
"%s %d", MFOC_res_type, &halt_flag);
616 }
while(strcmp(MFOC_res_type,
"H") != 0 && count <= 100);
644 uint32_t lacerta_mfoc_fmc::GetAbsFocuserPosition()
646 char MFOC_cmd[32] =
": q #";
647 char MFOC_res[32] = {0};
648 char MFOC_res_type[32] =
"0";
649 int MFOC_pos_measd = 0;
651 int nbytes_written = 0;
661 sscanf(MFOC_res,
"%s %d", MFOC_res_type, &MFOC_pos_measd);
664 while(strcmp(MFOC_res_type,
"p") != 0 && count < 100);
666 return static_cast<uint32_t
>(MFOC_pos_measd);
669 void lacerta_mfoc_fmc::IgnoreResponse()
676 void lacerta_mfoc_fmc::IgnoreButLogResponse() {
680 MFOC_res[nbytes_read] = 0;
const char * getDeviceName() const
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)
INumberVectorProperty FocusAbsPosNP
void SetCapability(uint32_t cap)
FI::SetCapability sets the focuser capabilities. All capabilities must be initialized.
INumber FocusBacklashN[1]
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
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 updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
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 IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
const char * getDefaultName() override
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * FOCUS_TAB
FOCUS_TAB Where all the properties for focuser are located.
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_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
int IUFindOnSwitchIndex(const ISwitchVectorProperty *svp)
Returns the index of first ON switch it finds in the vector switch property.
void IUSaveConfigNumber(FILE *fp, const INumberVectorProperty *nvp)
Add a number vector property value to the configuration file.
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 IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number'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 IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
#define MFOC_POSMAX_HARDWARE
#define FOCUSMFOC_TIMEOUT
#define MFOC_POSMIN_HARDWARE