diff --git a/fli_control/cmdlnopts.c b/fli_control/cmdlnopts.c index 7df38fd..545f2a6 100644 --- a/fli_control/cmdlnopts.c +++ b/fli_control/cmdlnopts.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "cmdlnopts.h" #include "usefull_macros.h" @@ -52,7 +53,8 @@ glob_pars const Gdefault = { .X1 = -1, .Y1 = -1, .temperature = 1e6, .shtr_cmd = -1, - .confio = -1, .setio = -1 + .confio = -1, .setio = -1, + .gotopos = INT_MAX, .addsteps = INT_MAX, }; /* @@ -68,7 +70,8 @@ myoption cmdlnopts[] = { {"close-shutter",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_CLOSE,arg_none,NULL, N_("close shutter")}, {"shutter-on-low",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_LOW,arg_none,NULL, N_("run exposition on LOW @ pin5 I/O port")}, {"shutter-on-high",NO_ARGS,&G.shtr_cmd,FLI_SHUTTER_EXTERNAL_EXPOSURE_CONTROL|FLI_SHUTTER_EXTERNAL_TRIGGER_HIGH,arg_none,NULL, N_("run exposition on HIGH @ pin5 I/O port")}, - {"get-ioport",NO_ARGS, NULL, 'g', arg_int, APTR(&G.getio), N_("get value of I/O port pins")}, + {"get-ioport",NO_ARGS, NULL, 'i', arg_int, APTR(&G.getio), N_("get value of I/O port pins")}, + {"async", NO_ARGS, &G.async,1, arg_none, NULL, N_("move stepper motor asynchronous")}, //{"fast", NO_ARGS, NULL, '8', arg_int, APTR(&G.fast), N_("run in 8-bit mode")}, //{"", NO_ARGS, NULL, '', arg_int, APTR(&G.), N_("")}, @@ -92,7 +95,8 @@ myoption cmdlnopts[] = { {"Y1", NEED_ARG, NULL, 0, arg_int, APTR(&G.Y1), N_("frame Y1 coordinate (-1 - all with overscan)")}, {"set-ioport",NEED_ARG, NULL, 's', arg_int, APTR(&G.setio), N_("set I/O port pins to given value (decimal number, pin1 is LSB)")}, {"conf-ioport",NEED_ARG,NULL, 'c', arg_int, APTR(&G.confio), N_("configure I/O port pins to given value (decimal number, pin1 is LSB, 1 == output, 0 == input)")}, - + {"goto", NEED_ARG, NULL, 'g', arg_int, APTR(&G.gotopos), N_("move wheel/turret motor to absolute position")}, + {"addsteps",NEED_ARG, NULL, 'a', arg_int, APTR(&G.addsteps), N_("move wheel/turret motor to relative position")}, //{"", NEED_ARG, NULL, '', arg_int, APTR(&G.), N_("")}, {"set-temp",NEED_ARG, NULL, 't', arg_double, APTR(&G.temperature),N_("set CCD temperature to given value (degr C)")}, diff --git a/fli_control/cmdlnopts.h b/fli_control/cmdlnopts.h index b29e6e1..a0150a9 100644 --- a/fli_control/cmdlnopts.h +++ b/fli_control/cmdlnopts.h @@ -50,6 +50,9 @@ typedef struct{ int setio; // set value of ioport int confio; // configure ioport double temperature; // temperature of CCD + int gotopos; // move stepper motor of focuser/wheel to absolute position + int addsteps; // move stepper motor of focuser/wheel to relative position + int async; // asynchronous moving } glob_pars; diff --git a/fli_control/main.c b/fli_control/main.c index 3b44048..6a81ff9 100644 --- a/fli_control/main.c +++ b/fli_control/main.c @@ -20,13 +20,19 @@ * MA 02110-1301, USA. * */ -//#include + +// for strcasestr +#define _GNU_SOURCE +#include + +#include #include #include #include #include #include #include + #include "main.h" #ifdef USEPNG @@ -84,27 +90,34 @@ void info(const char *fmt, ...){ } int main(int argc, char **argv){ - int i, numcams = 0; + int i, num; + long ltmp; char libver[LIBVERSIZ]; // FLI library version cam_t *cam = NULL; // list of CCDs available + flidev_t dev; + char buff[BUFF_SIZ]; initial_setup(); G = parse_args(argc, argv); - //TRYFUNC(FLISetDebugLevel, NULL /* "NO HOST" */, FLIDEBUG_ALL); + // #ifdef EBUG + TRYFUNC(FLISetDebugLevel, NULL /* "NO HOST" */, FLIDEBUG_NONE); + /* #else TRYFUNC(FLISetDebugLevel, NULL, FLIDEBUG_NONE); + #endif */ TRYFUNC(FLIGetLibVersion, libver, LIBVERSIZ); // Версия библиотеки '%s' info(_("Library version '%s'"), libver); - numcams = findcams(FLIDOMAIN_USB, &cam); - i = 0; - for (i = 0; i < numcams; i++){ - long x0,x1, y0,y1, row, img_rows, row_width, ltmp; - flidev_t dev; - char buff[BUFF_SIZ]; + /* + * Find CCDs and work with each of them + */ + num = findcams(FLIDOMAIN_USB | FLIDEVICE_CAMERA, &cam); + if(!num) WARNX(_("No CCD found")); + for (i = 0; i < num; i++){ + long x0,x1, y0,y1, row, img_rows, row_width; u_int16_t *img; int j; // Камера '%s' из домена %s info(_("Camera '%s', domain %s"), cam[i].name, cam[i].dname); - TRYFUNC(FLIOpen, &dev, cam[i].name, FLIDEVICE_CAMERA | cam[i].domain); + TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain); if(r) continue; TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ); // Модель:\t\t%s @@ -288,9 +301,128 @@ int main(int argc, char **argv){ FREE(img); TRYFUNC(FLIClose, dev); } - for (i = 0; i < numcams; i++) + for (i = 0; i < num; i++) FREE(cam[i].name); FREE(cam); + /* + * Find focusers and work with each of them + */ + num = findcams(FLIDOMAIN_USB | FLIDEVICE_FOCUSER, &cam); + if(!num) WARNX(_("No focusers found")); + for (i = 0; i < num; i++){ + TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain); + if(r) continue; + TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ); + if(!r){ + if(!strcasestr(buff, "focuser")){ // not focuser + TRYFUNC(FLIClose, dev); + continue; + } + // Модель:\t\t%s + info(_("Model:\t\t%s"), buff); + } + info(_("Focuser '%s', domain %s"), cam[i].name, cam[i].dname); + TRYFUNC(FLIGetHWRevision, dev, <mp); + // Апп. версия: %ld + if(!r) info(_("HW revision: %ld"), ltmp); + TRYFUNC(FLIGetFWRevision, dev, <mp); + // Прогр. версия: %ld + if(!r) info(_("SW revision: %ld"), ltmp); + TRYFUNC(FLIReadTemperature, dev, FLI_TEMPERATURE_INTERNAL, &t_ext); + // Температура (внешн.): %f + if(!r) green(_("Focuser temperature: %f\n"), t_ext); + long curpos = -1, maxpos = -1; + TRYFUNC(FLIGetStepperPosition, dev, <mp); + if(!r){ + // Позиция фокусера: %ld + info(_("Focuser position %ld"), ltmp); + curpos = ltmp; + } + TRYFUNC(FLIGetFocuserExtent, dev, <mp); + if(!r){ + // Максимальная позиция фокусера: %ld + info(_("Focuser extent: %ld"), ltmp); + maxpos = ltmp; + } + do{ + if(G->gotopos != INT_MAX && G->addsteps != INT_MAX){ + // Нельзя одновременно указывать относительную и абсолютную позицию + WARNX(_("You can't use both relative and absolute position")); + break; + } + if(curpos < 0 || maxpos < 0){ + // Ошибка определения позиции + WARNX(_("Error in position detection")); + break; + } + long pos = -1, steps = 0; + if(G->gotopos != INT_MAX){ // absolute pointing + pos = G->gotopos; + steps = pos - curpos; + }else if(G->addsteps != INT_MAX){ // relative pointing + steps = G->addsteps; + pos = curpos + steps; + }else break; + if(!steps){ + info(_("Already at position")); + break; + } + if(pos > maxpos || pos < 0){ + // Позиция не должна выходить за пределы 0...%ld + WARNX(_("Position should be in 0...%ld"), maxpos); + break; + } + if(pos == 0){ + // Перемещение в нулевую позицию + info(_("Moving to home position")); + if(G->async) TRYFUNC(FLIHomeDevice, dev); + else TRYFUNC(FLIHomeFocuser, dev); + }else{ + // Перемещение на %ld шагов + info(_("Moving for %ld steps"), steps); + if(G->async) TRYFUNC(FLIStepMotorAsync, dev, steps); + else TRYFUNC(FLIStepMotor, dev, steps); + } + TRYFUNC(FLIGetStepperPosition, dev, <mp); + // Достигнута позиция %ls + if(!r) info(_("Reached position %ld"), ltmp); + }while(0); + ; + TRYFUNC(FLIClose, dev); + } + for (i = 0; i < num; i++) + FREE(cam[i].name); + FREE(cam); + /* + * Find wheels and work with each of them + * + num = findcams(FLIDOMAIN_USB | FLIDEVICE_FILTERWHEEL, &cam); + if(!num) WARNX(_("No wheels found")); + for (i = 0; i < num; i++){ + info(_("Wheel '%s', domain %s"), cam[i].name, cam[i].dname); + TRYFUNC(FLIOpen, &dev, cam[i].name, cam[i].domain); + if(r) continue; + TRYFUNC(FLIGetModel, dev, buff, BUFF_SIZ); + // Модель:\t\t%s + info(_("Model:\t\t%s"), buff); + TRYFUNC(FLIGetHWRevision, dev, <mp); + // Апп. версия: %ld + info(_("HW revision: %ld"), ltmp); + TRYFUNC(FLIGetFWRevision, dev, <mp); + // Прогр. версия: %ld + info(_("SW revision: %ld"), ltmp); + TRYFUNC(FLIReadTemperature, dev, FLI_TEMPERATURE_INTERNAL, &t_ext); + // Температура (внешн.): %f + green(_("Wheel temperature: %f\n"), t_ext); + // Позиция турели: %ld + TRYFUNC(FLIGetFilterPos, dev, <mp); + info(_("Filter position"), ltmp); + ; + TRYFUNC(FLIClose, dev); + } + for (i = 0; i < num; i++) + FREE(cam[i].name); + FREE(cam);*/ exit(0); } @@ -298,13 +430,13 @@ int findcams(flidomain_t domain, cam_t **cam){ long r; char **tmplist; int numcams = 0; - TRYFUNC(FLIList, domain | FLIDEVICE_CAMERA, &tmplist); - if (tmplist != NULL && tmplist[0] != NULL){ + TRYFUNC(FLIList, domain, &tmplist); + if (tmplist && tmplist[0]){ int i, cams = 0; - for (i = 0; tmplist[i] != NULL; i++) cams++; + for (i = 0; tmplist[i]; i++) cams++; if ((*cam = realloc(*cam, (numcams + cams) * sizeof(cam_t))) == NULL) ERR("realloc() failed"); - for (i = 0; tmplist[i] != NULL; i++) { + for (i = 0; tmplist[i]; i++){ int j; cam_t *tmpcam = *cam + i; for (j = 0; tmplist[i][j] != '\0'; j++) @@ -313,7 +445,7 @@ int findcams(flidomain_t domain, cam_t **cam){ break; } tmpcam->domain = domain; - switch (domain){ + switch (domain & 0xff){ case FLIDOMAIN_PARALLEL_PORT: tmpcam->dname = "parallel port"; break; @@ -331,11 +463,11 @@ int findcams(flidomain_t domain, cam_t **cam){ break; } tmpcam->name = strdup(tmplist[i]); + DBG("found: %s @ %s", tmpcam->name, tmpcam->dname); } numcams += cams; } - // Камеры не найдены!\n - else WARNX(_("No cameras found!\n")); + else DBG("No devices"); TRYFUNC(FLIFreeList, tmplist); return numcams; } diff --git a/fli_control/main.h b/fli_control/main.h index 88f4870..e3208e6 100644 --- a/fli_control/main.h +++ b/fli_control/main.h @@ -24,8 +24,6 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#define _XOPEN_SOURCE 501 - #include "usefull_macros.h" #include "cmdlnopts.h" @@ -50,6 +48,7 @@ typedef struct{ }cam_t; int findcams(flidomain_t domain, cam_t **cam); + #ifdef USERAW int writeraw(char *filename, int width, int height, void *data); #endif // USERAW