fix some little bugs, test client and server @dummy camera

This commit is contained in:
Edward Emelianov 2022-03-18 15:28:47 +03:00
parent ebf6a53d63
commit c452b36a16
12 changed files with 334 additions and 230 deletions

View File

@ -36,18 +36,31 @@ static const float focmaxpos = 10.;
static int curhbin = 1, curvbin = 1; static int curhbin = 1, curvbin = 1;
static int filterpos = 0; static int filterpos = 0;
static float focuserpos = 1., brightness = 1., gain = 0.; static float focuserpos = 1., brightness = 1., gain = 0.;
static float camtemp = -30.; static float camtemp = -30., exptime = 0.;
static capture_status capstat = CAPTURE_NO; static capture_status capstat = CAPTURE_NO;
static double texpstart = 0.;
static int campoll(capture_status *st, float *remain){ static int campoll(capture_status *st, float *remain){
if(capstat == CAPTURE_NO){ if(capstat != CAPTURE_PROCESS){
if(st) *st = capstat = CAPTURE_PROCESS; if(st) *st = capstat;
if(remain) *remain = 1e-6; if(remain) *remain = 0.;
}else{ return TRUE;
capstat = CAPTURE_NO; }
if(dtime() - texpstart > exptime){
if(st) *st = CAPTURE_READY; if(st) *st = CAPTURE_READY;
if(remain) *remain = 0.; if(remain) *remain = 0.;
capstat = CAPTURE_NO;
return TRUE;
} }
if(st) *st = capstat;
if(remain) *remain = exptime + texpstart - dtime();
return TRUE;
}
static int startexp(){
if(capstat == CAPTURE_PROCESS) return FALSE;
capstat = CAPTURE_PROCESS;
texpstart = dtime();
return TRUE; return TRUE;
} }
@ -84,7 +97,8 @@ static int camgetbrig(float *b){
return TRUE; return TRUE;
} }
static int camsetexp(_U_ float t){ static int camsetexp(float t){
exptime = t;
return TRUE; return TRUE;
} }
@ -114,6 +128,7 @@ static int gett(float *t){
} }
static int camsetbin(int h, int v){ static int camsetbin(int h, int v){
DBG("set bin %dx%d", h, v);
curhbin = h; curvbin = v; curhbin = h; curvbin = v;
return TRUE; return TRUE;
} }
@ -189,7 +204,7 @@ static int focmp(float *p){
} }
static int whlsetpos(int n){ static int whlsetpos(int n){
if(n > filtermax || n < 0) return FALSE; if(n >= filtermax || n < 0) return FALSE;
filterpos = n; filterpos = n;
return TRUE; return TRUE;
} }
@ -229,7 +244,7 @@ __attribute__ ((visibility("default"))) Camera camera = {
.pollcapture = campoll, .pollcapture = campoll,
.capture = camcapt, .capture = camcapt,
.cancel = camcancel, .cancel = camcancel,
.startexposition = stub, .startexposition = startexp,
// setters: // setters:
.setDevNo = setdevno, .setDevNo = setdevno,
.setbrightness = camsetbrig, .setbrightness = camsetbrig,

View File

@ -305,6 +305,7 @@ static int gett(_U_ float *t){
} }
static int camsetbin(int h, int v){ static int camsetbin(int h, int v){
DBG("set bin %dx%d", h, v);
if(h != v){ if(h != v){
WARNX(_("BinX and BinY should be equal")); WARNX(_("BinX and BinY should be equal"));
return FALSE; return FALSE;

View File

@ -146,30 +146,32 @@ static void addrec(fitsfile *f, char *filename){
} }
// save FITS file `img` into GP->outfile or GP->outfileprefix_XXXX.fits // save FITS file `img` into GP->outfile or GP->outfileprefix_XXXX.fits
void saveFITS(IMG *img){ // return FALSE if failed
int saveFITS(IMG *img){
int ret = FALSE;
if(!camera){ if(!camera){
LOGERR("Can't save image: no camera device"); LOGERR("Can't save image: no camera device");
WARNX(_("Camera device unknown")); WARNX(_("Camera device unknown"));
return; return FALSE;
} }
char buff[PATH_MAX], fnam[PATH_MAX]; char buff[PATH_MAX+1], fnam[PATH_MAX+1];
if(!GP->outfile && !GP->outfileprefix){ if(!GP->outfile && !GP->outfileprefix){
LOGERR("Can't save image: neither filename nor filename prefix pointed"); LOGERR("Can't save image: neither filename nor filename prefix pointed");
WARNX(_("Neither filename nor filename prefix pointed!")); WARNX(_("Neither filename nor filename prefix pointed!"));
return; return FALSE;
} }
if(GP->outfile){ // pointed specific output file name like "file.fits", check it if(GP->outfile){ // pointed specific output file name like "file.fits", check it
struct stat filestat; struct stat filestat;
int s = stat(GP->outfile, &filestat); int s = stat(GP->outfile, &filestat);
if(s){ // not exists if(s){ // not exists
snprintf(fnam, PATH_MAX-1, "%s", GP->outfile); snprintf(fnam, PATH_MAX, "%s", GP->outfile);
}else{ // exists }else{ // exists
if(!GP->rewrite){ if(!GP->rewrite){
LOGERR("Can't save image: file %s exists", GP->outfile); LOGERR("Can't save image: file %s exists", GP->outfile);
WARNX("File %s exists!", GP->outfile); WARNX("File %s exists!", GP->outfile);
return; return FALSE;
} }
snprintf(fnam, PATH_MAX-1, "!%s", GP->outfile); snprintf(fnam, PATH_MAX, "!%s", GP->outfile);
} }
}else{ // user pointed output file prefix }else{ // user pointed output file prefix
if(!check_filenameprefix(fnam, PATH_MAX)){ if(!check_filenameprefix(fnam, PATH_MAX)){
@ -323,15 +325,18 @@ void saveFITS(IMG *img){
TRYFITS(fits_write_img, fp, TUSHORT, 1, width * height, data); TRYFITS(fits_write_img, fp, TUSHORT, 1, width * height, data);
if(fitserror) goto cloerr; if(fitserror) goto cloerr;
TRYFITS(fits_close_file, fp); TRYFITS(fits_close_file, fp);
DBG("file %s saved", fnam);
cloerr: cloerr:
if(fitserror == 0){ if(fitserror == 0){
LOGMSG("Save file '%s'", fnam); LOGMSG("Save file '%s'", fnam);
verbose(1, _("File saved as '%s'"), fnam); verbose(1, _("File saved as '%s'"), fnam);
ret = TRUE;
}else{ }else{
LOGERR("Can't save %s", fnam); LOGERR("Can't save %s", fnam);
WARNX(_("Error saving file")); WARNX(_("Error saving file"));
fitserror = 0; fitserror = 0;
} }
return ret;
} }
void calculate_stat(IMG *image){ void calculate_stat(IMG *image){

View File

@ -27,7 +27,7 @@ extern Focuser *focuser;
extern Wheel *wheel; extern Wheel *wheel;
void calculate_stat(IMG *image); void calculate_stat(IMG *image);
void saveFITS(IMG *img); // for imageview module int saveFITS(IMG *img); // for imageview module
void focusers(); void focusers();
void wheels(); void wheels();
void ccds(); void ccds();

View File

@ -76,32 +76,11 @@ static char *getans(int sock){
buf[n] = 0; buf[n] = 0;
DBG("Got from server: %s", buf); DBG("Got from server: %s", buf);
verbose(1, "%s", buf); verbose(1, "%s", buf);
if(buf[n-1] == '\n') break;
} }
return ans; return ans;
} }
static char *makeabspath(const char *path){
static char buf[PATH_MAX];
if(!path) return NULL;
char *ret = NULL;
int unl = 0;
FILE *f = fopen(path, "r");
if(!f){
f = fopen(path, "a");
if(!f){
ERR("Can't create %s", path);
return NULL;
}
unl = 1;
}
if(!realpath(path, buf)){
ERR("realpath()");
}else ret = buf;
fclose(f);
if(unl) unlink(path);
return ret;
}
/** /**
* @brief processData - process here some actions and make messages for server * @brief processData - process here some actions and make messages for server
*/ */

View File

@ -100,6 +100,7 @@ myoption cmdlnopts[] = {
{"logfile", NEED_ARG, NULL, 0, arg_string, APTR(&G.logfile), N_("logging file name (if run as server)")}, {"logfile", NEED_ARG, NULL, 0, arg_string, APTR(&G.logfile), N_("logging file name (if run as server)")},
{"path", NEED_ARG, NULL, 0, arg_string, APTR(&G.path), N_("UNIX socket name")}, {"path", NEED_ARG, NULL, 0, arg_string, APTR(&G.path), N_("UNIX socket name")},
{"port", NEED_ARG, NULL, 0, arg_string, APTR(&G.port), N_("local INET socket port")}, {"port", NEED_ARG, NULL, 0, arg_string, APTR(&G.port), N_("local INET socket port")},
{"client", NO_ARGS, &G.client,1, arg_none, NULL, N_("run as client")},
{"pidfile", NEED_ARG, NULL, 0, arg_string, APTR(&G.pidfile), N_("PID file (default: " DEFAULT_PID_FILE ")")}, {"pidfile", NEED_ARG, NULL, 0, arg_string, APTR(&G.pidfile), N_("PID file (default: " DEFAULT_PID_FILE ")")},
#ifdef IMAGEVIEW #ifdef IMAGEVIEW

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-17 18:04+0300\n" "POT-Creation-Date: 2022-03-18 15:13+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -230,10 +230,14 @@ msgid "local INET socket port"
msgstr "" msgstr ""
#: cmdlnopts.c:103 #: cmdlnopts.c:103
msgid "run as client"
msgstr ""
#: cmdlnopts.c:104
msgid "PID file (default: " msgid "PID file (default: "
msgstr "" msgstr ""
#: cmdlnopts.c:106 #: cmdlnopts.c:107
msgid "Display image in OpenGL window" msgid "Display image in OpenGL window"
msgstr "" msgstr ""
@ -257,300 +261,300 @@ msgstr ""
msgid "Can't find wheel in plugin %s: %s" msgid "Can't find wheel in plugin %s: %s"
msgstr "" msgstr ""
#: ccdfunc.c:152 #: ccdfunc.c:154
msgid "Camera device unknown" msgid "Camera device unknown"
msgstr "" msgstr ""
#: ccdfunc.c:158 #: ccdfunc.c:160
msgid "Neither filename nor filename prefix pointed!" msgid "Neither filename nor filename prefix pointed!"
msgstr "" msgstr ""
#. Не могу сохранить файл #. Не могу сохранить файл
#: ccdfunc.c:177 #: ccdfunc.c:179
#, c-format #, c-format
msgid "Can't save file with prefix %s" msgid "Can't save file with prefix %s"
msgstr "" msgstr ""
#: ccdfunc.c:329 #: ccdfunc.c:332
#, c-format #, c-format
msgid "File saved as '%s'" msgid "File saved as '%s'"
msgstr "" msgstr ""
#: ccdfunc.c:332 #: ccdfunc.c:336
msgid "Error saving file" msgid "Error saving file"
msgstr "" msgstr ""
#: ccdfunc.c:371 #: ccdfunc.c:376
#, c-format #, c-format
msgid "Image stat:\n" msgid "Image stat:\n"
msgstr "" msgstr ""
#: ccdfunc.c:379 #: ccdfunc.c:384
msgid "Focuser device not pointed" msgid "Focuser device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:386 #: ccdfunc.c:391
msgid "No focusers found" msgid "No focusers found"
msgstr "" msgstr ""
#: ccdfunc.c:417 #: ccdfunc.c:422
#, c-format #, c-format
msgid "Found %d focusers, you point number %d" msgid "Found %d focusers, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:421 #: ccdfunc.c:426
msgid "Can't set active focuser number" msgid "Can't set active focuser number"
msgstr "" msgstr ""
#: ccdfunc.c:435 #: ccdfunc.c:440
msgid "Can't get focuser limit positions" msgid "Can't get focuser limit positions"
msgstr "" msgstr ""
#: ccdfunc.c:442 #: ccdfunc.c:447
msgid "Can't get current focuser position" msgid "Can't get current focuser position"
msgstr "" msgstr ""
#: ccdfunc.c:456 #: ccdfunc.c:461
#, c-format #, c-format
msgid "Can't set position %g: out of limits [%g, %g]" msgid "Can't set position %g: out of limits [%g, %g]"
msgstr "" msgstr ""
#: ccdfunc.c:460 #: ccdfunc.c:465
msgid "Can't home focuser" msgid "Can't home focuser"
msgstr "" msgstr ""
#: ccdfunc.c:462 #: ccdfunc.c:467
#, c-format #, c-format
msgid "Can't set position %g" msgid "Can't set position %g"
msgstr "" msgstr ""
#: ccdfunc.c:470 #: ccdfunc.c:475
msgid "Wheel device not pointed" msgid "Wheel device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:477 #: ccdfunc.c:482
msgid "No wheels found" msgid "No wheels found"
msgstr "" msgstr ""
#: ccdfunc.c:508 #: ccdfunc.c:513
#, c-format #, c-format
msgid "Found %d wheels, you point number %d" msgid "Found %d wheels, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:512 #: ccdfunc.c:517
msgid "Can't set active wheel number" msgid "Can't set active wheel number"
msgstr "" msgstr ""
#: ccdfunc.c:528 #: ccdfunc.c:533
msgid "Can't get max wheel position" msgid "Can't get max wheel position"
msgstr "" msgstr ""
#: ccdfunc.c:535 #: ccdfunc.c:540
#, c-format #, c-format
msgid "Wheel position should be from 0 to %d" msgid "Wheel position should be from 0 to %d"
msgstr "" msgstr ""
#: ccdfunc.c:539 #: ccdfunc.c:544
#, c-format #, c-format
msgid "Can't set wheel position %d" msgid "Can't set wheel position %d"
msgstr "" msgstr ""
#: ccdfunc.c:556 #: ccdfunc.c:561
#, c-format #, c-format
msgid "%.1f seconds till exposition ends" msgid "%.1f seconds till exposition ends"
msgstr "" msgstr ""
#: ccdfunc.c:570 #: ccdfunc.c:575
msgid "Camera device not pointed" msgid "Camera device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:577 ccdfunc.c:578 #: ccdfunc.c:582 ccdfunc.c:583
msgid "No cameras found" msgid "No cameras found"
msgstr "" msgstr ""
#: ccdfunc.c:613 #: ccdfunc.c:618
#, c-format #, c-format
msgid "Found %d cameras, you point number %d" msgid "Found %d cameras, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:617 #: ccdfunc.c:622
msgid "Can't set active camera number" msgid "Can't set active camera number"
msgstr "" msgstr ""
#: ccdfunc.c:623 #: ccdfunc.c:628
msgid "Can't set fan speed" msgid "Can't set fan speed"
msgstr "" msgstr ""
#: ccdfunc.c:624
#, c-format
msgid "Set fan speed to %d"
msgstr ""
#: ccdfunc.c:629 #: ccdfunc.c:629
#, c-format #, c-format
msgid "Set fan speed to %d"
msgstr ""
#: ccdfunc.c:634
#, c-format
msgid "Camera model: %s" msgid "Camera model: %s"
msgstr "" msgstr ""
#: ccdfunc.c:630 #: ccdfunc.c:635
#, c-format #, c-format
msgid "Pixel size: %g x %g" msgid "Pixel size: %g x %g"
msgstr "" msgstr ""
#: ccdfunc.c:636 #: ccdfunc.c:641
#, c-format #, c-format
msgid "Full array: %s" msgid "Full array: %s"
msgstr "" msgstr ""
#: ccdfunc.c:639 #: ccdfunc.c:644
#, c-format #, c-format
msgid "Field of view: %s" msgid "Field of view: %s"
msgstr "" msgstr ""
#: ccdfunc.c:642 #: ccdfunc.c:647
#, c-format #, c-format
msgid "Can't set T to %g degC" msgid "Can't set T to %g degC"
msgstr "" msgstr ""
#: ccdfunc.c:649 #: ccdfunc.c:654
#, c-format #, c-format
msgid "Shutter command: %s\n" msgid "Shutter command: %s\n"
msgstr "" msgstr ""
#: ccdfunc.c:651 #: ccdfunc.c:656
#, c-format #, c-format
msgid "Can't run shutter command %s (unsupported?)" msgid "Can't run shutter command %s (unsupported?)"
msgstr "" msgstr ""
#. "Попытка сконфигурировать порт I/O как %d\n" #. "Попытка сконфигурировать порт I/O как %d\n"
#: ccdfunc.c:655 #: ccdfunc.c:660
#, c-format #, c-format
msgid "Try to configure I/O port as %d" msgid "Try to configure I/O port as %d"
msgstr "" msgstr ""
#: ccdfunc.c:657 #: ccdfunc.c:662
msgid "Can't configure (unsupported?)" msgid "Can't configure (unsupported?)"
msgstr "" msgstr ""
#: ccdfunc.c:663 #: ccdfunc.c:668
msgid "Can't get IOport state (unsupported?)" msgid "Can't get IOport state (unsupported?)"
msgstr "" msgstr ""
#. "Попытка записи %d в порт I/O\n" #. "Попытка записи %d в порт I/O\n"
#: ccdfunc.c:667 #: ccdfunc.c:672
#, c-format #, c-format
msgid "Try to write %d to I/O port" msgid "Try to write %d to I/O port"
msgstr "" msgstr ""
#: ccdfunc.c:669 #: ccdfunc.c:674
msgid "Can't set IOport" msgid "Can't set IOport"
msgstr "" msgstr ""
#: ccdfunc.c:676 #: ccdfunc.c:681
#, c-format #, c-format
msgid "Set gain to %g" msgid "Set gain to %g"
msgstr "" msgstr ""
#: ccdfunc.c:677 #: ccdfunc.c:682
#, c-format #, c-format
msgid "Can't set gain to %g" msgid "Can't set gain to %g"
msgstr "" msgstr ""
#: ccdfunc.c:682 #: ccdfunc.c:687
#, c-format #, c-format
msgid "Set brightness to %g" msgid "Set brightness to %g"
msgstr "" msgstr ""
#: ccdfunc.c:683 #: ccdfunc.c:688
#, c-format #, c-format
msgid "Can't set brightness to %g" msgid "Can't set brightness to %g"
msgstr "" msgstr ""
#: ccdfunc.c:689 #: ccdfunc.c:694
#, c-format #, c-format
msgid "Can't set binning %dx%d" msgid "Can't set binning %dx%d"
msgstr "" msgstr ""
#: ccdfunc.c:699 #: ccdfunc.c:704
msgid "Can't set given geometry" msgid "Can't set given geometry"
msgstr "" msgstr ""
#: ccdfunc.c:703 #: ccdfunc.c:708
#, c-format #, c-format
msgid "Can't set %d flushes" msgid "Can't set %d flushes"
msgstr "" msgstr ""
#: ccdfunc.c:707 #: ccdfunc.c:712
#, c-format #, c-format
msgid "Can't set exposure time to %f seconds" msgid "Can't set exposure time to %f seconds"
msgstr "" msgstr ""
#: ccdfunc.c:710 #: ccdfunc.c:715
msgid "Can't change frame type" msgid "Can't change frame type"
msgstr "" msgstr ""
#: ccdfunc.c:713 #: ccdfunc.c:718
msgid "Can't set bit depth" msgid "Can't set bit depth"
msgstr "" msgstr ""
#: ccdfunc.c:715 #: ccdfunc.c:720
msgid "Can't set readout speed" msgid "Can't set readout speed"
msgstr "" msgstr ""
#: ccdfunc.c:716 #: ccdfunc.c:721
#, c-format #, c-format
msgid "Readout mode: %s" msgid "Readout mode: %s"
msgstr "" msgstr ""
#: ccdfunc.c:717 #: ccdfunc.c:722
msgid "Only show statistics" msgid "Only show statistics"
msgstr "" msgstr ""
#. GET binning should be AFTER setgeometry! #. GET binning should be AFTER setgeometry!
#: ccdfunc.c:719 #: ccdfunc.c:724
msgid "Can't get current binning" msgid "Can't get current binning"
msgstr "" msgstr ""
#: ccdfunc.c:732 #: ccdfunc.c:737
msgid "Can't open OpenGL window, image preview will be inaccessible" msgid "Can't open OpenGL window, image preview will be inaccessible"
msgstr "" msgstr ""
#. Захват кадра %d\n #. Захват кадра %d\n
#: ccdfunc.c:739 #: ccdfunc.c:744
#, c-format #, c-format
msgid "Capture frame %d" msgid "Capture frame %d"
msgstr "" msgstr ""
#: ccdfunc.c:741 server.c:64 #: ccdfunc.c:746 server.c:108
msgid "Can't start exposition" msgid "Can't start exposition"
msgstr "" msgstr ""
#: ccdfunc.c:745 ccdfunc.c:767 ccdfunc.c:808 #: ccdfunc.c:750 ccdfunc.c:772 ccdfunc.c:813
msgid "Can't capture image" msgid "Can't capture image"
msgstr "" msgstr ""
#: ccdfunc.c:748 #: ccdfunc.c:753
msgid "Read grabbed image" msgid "Read grabbed image"
msgstr "" msgstr ""
#: ccdfunc.c:751 ccdfunc.c:771 ccdfunc.c:812 #: ccdfunc.c:756 ccdfunc.c:776 ccdfunc.c:817
msgid "Can't grab image" msgid "Can't grab image"
msgstr "" msgstr ""
#. %d секунд до окончания паузы\n #. %d секунд до окончания паузы\n
#: ccdfunc.c:788 #: ccdfunc.c:793
#, c-format #, c-format
msgid "%d seconds till pause ends\n" msgid "%d seconds till pause ends\n"
msgstr "" msgstr ""
#: server.c:89 #: server.c:146
msgid "No camera device" msgid "No camera device"
msgstr "" msgstr ""
#: client.c:164 #: client.c:143
msgid "Can't make exposition" msgid "Can't make exposition"
msgstr "" msgstr ""
#: client.c:174 #: client.c:153
msgid "Server timeout" msgid "Server timeout"
msgstr "" msgstr ""

View File

@ -7,7 +7,7 @@
msgid "" msgid ""
msgstr "Project-Id-Version: PACKAGE VERSION\n" msgstr "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-17 18:04+0300\n" "POT-Creation-Date: 2022-03-18 15:13+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -16,13 +16,13 @@ msgstr "Project-Id-Version: PACKAGE VERSION\n"
"Content-Type: text/plain; charset=koi8-r\n" "Content-Type: text/plain; charset=koi8-r\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: ccdfunc.c:556 #: ccdfunc.c:561
#, c-format #, c-format
msgid "%.1f seconds till exposition ends" msgid "%.1f seconds till exposition ends"
msgstr "" msgstr ""
#. %d секунд до окончания паузы\n #. %d секунд до окончания паузы\n
#: ccdfunc.c:788 #: ccdfunc.c:793
#, c-format #, c-format
msgid "%d seconds till pause ends\n" msgid "%d seconds till pause ends\n"
msgstr "" msgstr ""
@ -39,28 +39,28 @@ msgstr ""
msgid "CMOS gain level" msgid "CMOS gain level"
msgstr "" msgstr ""
#: ccdfunc.c:570 #: ccdfunc.c:575
msgid "Camera device not pointed" msgid "Camera device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:152 #: ccdfunc.c:154
msgid "Camera device unknown" msgid "Camera device unknown"
msgstr "" msgstr ""
#: ccdfunc.c:629 #: ccdfunc.c:634
#, c-format #, c-format
msgid "Camera model: %s" msgid "Camera model: %s"
msgstr "" msgstr ""
#: ccdfunc.c:745 ccdfunc.c:767 ccdfunc.c:808 #: ccdfunc.c:750 ccdfunc.c:772 ccdfunc.c:813
msgid "Can't capture image" msgid "Can't capture image"
msgstr "" msgstr ""
#: ccdfunc.c:710 #: ccdfunc.c:715
msgid "Can't change frame type" msgid "Can't change frame type"
msgstr "" msgstr ""
#: ccdfunc.c:657 #: ccdfunc.c:662
msgid "Can't configure (unsupported?)" msgid "Can't configure (unsupported?)"
msgstr "" msgstr ""
@ -84,32 +84,32 @@ msgstr ""
msgid "Can't find wheel in plugin %s: %s" msgid "Can't find wheel in plugin %s: %s"
msgstr "" msgstr ""
#: ccdfunc.c:663 #: ccdfunc.c:668
msgid "Can't get IOport state (unsupported?)" msgid "Can't get IOport state (unsupported?)"
msgstr "" msgstr ""
#. GET binning should be AFTER setgeometry! #. GET binning should be AFTER setgeometry!
#: ccdfunc.c:719 #: ccdfunc.c:724
msgid "Can't get current binning" msgid "Can't get current binning"
msgstr "" msgstr ""
#: ccdfunc.c:442 #: ccdfunc.c:447
msgid "Can't get current focuser position" msgid "Can't get current focuser position"
msgstr "" msgstr ""
#: ccdfunc.c:435 #: ccdfunc.c:440
msgid "Can't get focuser limit positions" msgid "Can't get focuser limit positions"
msgstr "" msgstr ""
#: ccdfunc.c:528 #: ccdfunc.c:533
msgid "Can't get max wheel position" msgid "Can't get max wheel position"
msgstr "" msgstr ""
#: ccdfunc.c:751 ccdfunc.c:771 ccdfunc.c:812 #: ccdfunc.c:756 ccdfunc.c:776 ccdfunc.c:817
msgid "Can't grab image" msgid "Can't grab image"
msgstr "" msgstr ""
#: ccdfunc.c:460 #: ccdfunc.c:465
msgid "Can't home focuser" msgid "Can't home focuser"
msgstr "" msgstr ""
@ -117,113 +117,113 @@ msgstr ""
msgid "Can't init mutex!" msgid "Can't init mutex!"
msgstr "" msgstr ""
#: client.c:164 #: client.c:143
msgid "Can't make exposition" msgid "Can't make exposition"
msgstr "" msgstr ""
#: ccdfunc.c:732 #: ccdfunc.c:737
msgid "Can't open OpenGL window, image preview will be inaccessible" msgid "Can't open OpenGL window, image preview will be inaccessible"
msgstr "" msgstr ""
#: ccdfunc.c:651 #: ccdfunc.c:656
#, c-format #, c-format
msgid "Can't run shutter command %s (unsupported?)" msgid "Can't run shutter command %s (unsupported?)"
msgstr "" msgstr ""
#. Не могу сохранить файл #. Не могу сохранить файл
#: ccdfunc.c:177 #: ccdfunc.c:179
#, c-format #, c-format
msgid "Can't save file with prefix %s" msgid "Can't save file with prefix %s"
msgstr "" msgstr ""
#: ccdfunc.c:703 #: ccdfunc.c:708
#, c-format #, c-format
msgid "Can't set %d flushes" msgid "Can't set %d flushes"
msgstr "" msgstr ""
#: ccdfunc.c:669 #: ccdfunc.c:674
msgid "Can't set IOport" msgid "Can't set IOport"
msgstr "" msgstr ""
#: ccdfunc.c:642 #: ccdfunc.c:647
#, c-format #, c-format
msgid "Can't set T to %g degC" msgid "Can't set T to %g degC"
msgstr "" msgstr ""
#: ccdfunc.c:617 #: ccdfunc.c:622
msgid "Can't set active camera number" msgid "Can't set active camera number"
msgstr "" msgstr ""
#: ccdfunc.c:421 #: ccdfunc.c:426
msgid "Can't set active focuser number" msgid "Can't set active focuser number"
msgstr "" msgstr ""
#: ccdfunc.c:512 #: ccdfunc.c:517
msgid "Can't set active wheel number" msgid "Can't set active wheel number"
msgstr "" msgstr ""
#: ccdfunc.c:689 #: ccdfunc.c:694
#, c-format #, c-format
msgid "Can't set binning %dx%d" msgid "Can't set binning %dx%d"
msgstr "" msgstr ""
#: ccdfunc.c:713 #: ccdfunc.c:718
msgid "Can't set bit depth" msgid "Can't set bit depth"
msgstr "" msgstr ""
#: ccdfunc.c:683 #: ccdfunc.c:688
#, c-format #, c-format
msgid "Can't set brightness to %g" msgid "Can't set brightness to %g"
msgstr "" msgstr ""
#: ccdfunc.c:707 #: ccdfunc.c:712
#, c-format #, c-format
msgid "Can't set exposure time to %f seconds" msgid "Can't set exposure time to %f seconds"
msgstr "" msgstr ""
#: ccdfunc.c:623 #: ccdfunc.c:628
msgid "Can't set fan speed" msgid "Can't set fan speed"
msgstr "" msgstr ""
#: ccdfunc.c:677 #: ccdfunc.c:682
#, c-format #, c-format
msgid "Can't set gain to %g" msgid "Can't set gain to %g"
msgstr "" msgstr ""
#: ccdfunc.c:699 #: ccdfunc.c:704
msgid "Can't set given geometry" msgid "Can't set given geometry"
msgstr "" msgstr ""
#: ccdfunc.c:462 #: ccdfunc.c:467
#, c-format #, c-format
msgid "Can't set position %g" msgid "Can't set position %g"
msgstr "" msgstr ""
#: ccdfunc.c:456 #: ccdfunc.c:461
#, c-format #, c-format
msgid "Can't set position %g: out of limits [%g, %g]" msgid "Can't set position %g: out of limits [%g, %g]"
msgstr "" msgstr ""
#: ccdfunc.c:715 #: ccdfunc.c:720
msgid "Can't set readout speed" msgid "Can't set readout speed"
msgstr "" msgstr ""
#: ccdfunc.c:539 #: ccdfunc.c:544
#, c-format #, c-format
msgid "Can't set wheel position %d" msgid "Can't set wheel position %d"
msgstr "" msgstr ""
#: ccdfunc.c:741 server.c:64 #: ccdfunc.c:746 server.c:108
msgid "Can't start exposition" msgid "Can't start exposition"
msgstr "" msgstr ""
#. Захват кадра %d\n #. Захват кадра %d\n
#: ccdfunc.c:739 #: ccdfunc.c:744
#, c-format #, c-format
msgid "Capture frame %d" msgid "Capture frame %d"
msgstr "" msgstr ""
#: cmdlnopts.c:106 #: cmdlnopts.c:107
msgid "Display image in OpenGL window" msgid "Display image in OpenGL window"
msgstr "" msgstr ""
@ -232,40 +232,40 @@ msgstr ""
msgid "Equalization of histogram: %s" msgid "Equalization of histogram: %s"
msgstr "" msgstr ""
#: ccdfunc.c:332 #: ccdfunc.c:336
msgid "Error saving file" msgid "Error saving file"
msgstr "" msgstr ""
#: ccdfunc.c:639 #: ccdfunc.c:644
#, c-format #, c-format
msgid "Field of view: %s" msgid "Field of view: %s"
msgstr "" msgstr ""
#: ccdfunc.c:329 #: ccdfunc.c:332
#, c-format #, c-format
msgid "File saved as '%s'" msgid "File saved as '%s'"
msgstr "" msgstr ""
#: ccdfunc.c:379 #: ccdfunc.c:384
msgid "Focuser device not pointed" msgid "Focuser device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:613 #: ccdfunc.c:618
#, c-format #, c-format
msgid "Found %d cameras, you point number %d" msgid "Found %d cameras, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:417 #: ccdfunc.c:422
#, c-format #, c-format
msgid "Found %d focusers, you point number %d" msgid "Found %d focusers, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:508 #: ccdfunc.c:513
#, c-format #, c-format
msgid "Found %d wheels, you point number %d" msgid "Found %d wheels, you point number %d"
msgstr "" msgstr ""
#: ccdfunc.c:636 #: ccdfunc.c:641
#, c-format #, c-format
msgid "Full array: %s" msgid "Full array: %s"
msgstr "" msgstr ""
@ -275,7 +275,7 @@ msgstr ""
msgid "Histogram conversion: %s" msgid "Histogram conversion: %s"
msgstr "" msgstr ""
#: ccdfunc.c:371 #: ccdfunc.c:376
#, c-format #, c-format
msgid "Image stat:\n" msgid "Image stat:\n"
msgstr "" msgstr ""
@ -284,80 +284,80 @@ msgstr ""
msgid "N flushes before exposing (default: 1)" msgid "N flushes before exposing (default: 1)"
msgstr "" msgstr ""
#: ccdfunc.c:158 #: ccdfunc.c:160
msgid "Neither filename nor filename prefix pointed!" msgid "Neither filename nor filename prefix pointed!"
msgstr "" msgstr ""
#: server.c:89 #: server.c:146
msgid "No camera device" msgid "No camera device"
msgstr "" msgstr ""
#: ccdfunc.c:577 ccdfunc.c:578 #: ccdfunc.c:582 ccdfunc.c:583
msgid "No cameras found" msgid "No cameras found"
msgstr "" msgstr ""
#: ccdfunc.c:386 #: ccdfunc.c:391
msgid "No focusers found" msgid "No focusers found"
msgstr "" msgstr ""
#: ccdfunc.c:477 #: ccdfunc.c:482
msgid "No wheels found" msgid "No wheels found"
msgstr "" msgstr ""
#: ccdfunc.c:717 #: ccdfunc.c:722
msgid "Only show statistics" msgid "Only show statistics"
msgstr "" msgstr ""
#: cmdlnopts.c:103 #: cmdlnopts.c:104
msgid "PID file (default: " msgid "PID file (default: "
msgstr "" msgstr ""
#: ccdfunc.c:630 #: ccdfunc.c:635
#, c-format #, c-format
msgid "Pixel size: %g x %g" msgid "Pixel size: %g x %g"
msgstr "" msgstr ""
#: ccdfunc.c:748 #: ccdfunc.c:753
msgid "Read grabbed image" msgid "Read grabbed image"
msgstr "" msgstr ""
#: ccdfunc.c:716 #: ccdfunc.c:721
#, c-format #, c-format
msgid "Readout mode: %s" msgid "Readout mode: %s"
msgstr "" msgstr ""
#: client.c:174 #: client.c:153
msgid "Server timeout" msgid "Server timeout"
msgstr "" msgstr ""
#: ccdfunc.c:682 #: ccdfunc.c:687
#, c-format #, c-format
msgid "Set brightness to %g" msgid "Set brightness to %g"
msgstr "" msgstr ""
#: ccdfunc.c:624 #: ccdfunc.c:629
#, c-format #, c-format
msgid "Set fan speed to %d" msgid "Set fan speed to %d"
msgstr "" msgstr ""
#: ccdfunc.c:676 #: ccdfunc.c:681
#, c-format #, c-format
msgid "Set gain to %g" msgid "Set gain to %g"
msgstr "" msgstr ""
#: ccdfunc.c:649 #: ccdfunc.c:654
#, c-format #, c-format
msgid "Shutter command: %s\n" msgid "Shutter command: %s\n"
msgstr "" msgstr ""
#. "Попытка сконфигурировать порт I/O как %d\n" #. "Попытка сконфигурировать порт I/O как %d\n"
#: ccdfunc.c:655 #: ccdfunc.c:660
#, c-format #, c-format
msgid "Try to configure I/O port as %d" msgid "Try to configure I/O port as %d"
msgstr "" msgstr ""
#. "Попытка записи %d в порт I/O\n" #. "Попытка записи %d в порт I/O\n"
#: ccdfunc.c:667 #: ccdfunc.c:672
#, c-format #, c-format
msgid "Try to write %d to I/O port" msgid "Try to write %d to I/O port"
msgstr "" msgstr ""
@ -366,11 +366,11 @@ msgstr ""
msgid "UNIX socket name" msgid "UNIX socket name"
msgstr "" msgstr ""
#: ccdfunc.c:470 #: ccdfunc.c:475
msgid "Wheel device not pointed" msgid "Wheel device not pointed"
msgstr "" msgstr ""
#: ccdfunc.c:535 #: ccdfunc.c:540
#, c-format #, c-format
msgid "Wheel position should be from 0 to %d" msgid "Wheel position should be from 0 to %d"
msgstr "" msgstr ""
@ -525,6 +525,10 @@ msgstr ""
msgid "rewrite output file if exists" msgid "rewrite output file if exists"
msgstr "" msgstr ""
#: cmdlnopts.c:103
msgid "run as client"
msgstr ""
#: cmdlnopts.c:85 #: cmdlnopts.c:85
msgid "run exposition on HIGH @ pin5 I/O port" msgid "run exposition on HIGH @ pin5 I/O port"
msgstr "" msgstr ""

5
main.c
View File

@ -52,7 +52,7 @@ void signals(int signo){
// slave: cancel exposition // slave: cancel exposition
WARNX("Get signal %d - exit", signo); WARNX("Get signal %d - exit", signo);
DBG("Cancel capturing"); DBG("Cancel capturing");
cancel(); if(!GP->client) cancel();
#ifdef IMAGEVIEW #ifdef IMAGEVIEW
DBG("KILL GL"); DBG("KILL GL");
closeGL(); closeGL();
@ -75,7 +75,7 @@ int main(int argc, char **argv){
struct stat filestat; struct stat filestat;
if(0 == stat(GP->outfile, &filestat)) ERRX("File %s exists!", GP->outfile); if(0 == stat(GP->outfile, &filestat)) ERRX("File %s exists!", GP->outfile);
} }
if(GP->port || GP->path){ if(GP->port){
if(GP->path){ if(GP->path){
WARNX("Options `port` and `path` can't be used together! Point `port` for TCP socket or `path` for UNIX."); WARNX("Options `port` and `path` can't be used together! Point `port` for TCP socket or `path` for UNIX.");
return 1; return 1;
@ -87,6 +87,7 @@ int main(int argc, char **argv){
} }
if(!GP->client) isserver = TRUE; if(!GP->client) isserver = TRUE;
} }
if(GP->path && !GP->client) isserver = TRUE;
if(GP->logfile){ if(GP->logfile){
int lvl = LOGLEVEL_WARN + GP->verbose; int lvl = LOGLEVEL_WARN + GP->verbose;
DBG("level = %d", lvl); DBG("level = %d", lvl);

186
server.c
View File

@ -44,21 +44,65 @@ static float focmaxpos = 0., focminpos = 0.; // focuser extremal positions
static int wmaxpos = 0.; // wheel max pos static int wmaxpos = 0.; // wheel max pos
static float tremain = 0.; // time when capture done static float tremain = 0.; // time when capture done
typedef struct{
const char *key;
const char *help;
}strpair;
// cat | awk '{print "{ " $3 ", \"\" }," }' | sort
strpair allcommands[] = {
{ "brightness", "camera brightness" },
{ "camdevno", "camera device number" },
{ "camlist", "list all connected cameras" },
{ "ccdfanspeed", "fan speed of camera" },
{ "confio", "camera IO configuration" },
{ "expstate", "get exposition state" },
{ "exptime", "exposition time" },
{ "filename", "save file with this name, like file.fits" },
{ "filenameprefix", "prefix of files, like ex (will be saved as exXXXX.fits)" },
{ "focdevno", "focuser device number" },
{ "foclist", "list all connected focusers" },
{ "focpos", "focuser position" },
{ "format", "camera frame format (X0,Y0,X1,Y1)" },
{ "gain", "camera gain" },
{ "hbin", "horizontal binning" },
{ "help", "show this help" },
{ "info", "connected devices state" },
{ "io", "get/set camera IO" },
{ "maxformat", "camera maximal available format" },
{ "nflushes", "camera number of preflushes" },
{ "rewrite", "rewrite file (if give `filename`, not `filenameprefix`" },
{ "shutter", "camera shutter's operations" },
{ "tcold", "camera chip temperature" },
{ "tremain", "time (in seconds) of exposition remained" },
{ "vbin", "vertical binning" },
{ "wdevno", "wheel device number" },
{ "wlist", "list all connected wheels" },
{ "wpos", "wheel position" },
{NULL, NULL},
};
static IMG ima = {0}; static IMG ima = {0};
static void fixima(){ static void fixima(){
FREE(ima.data); FNAME();
int raw_width = curformat.w / GP->hbin, raw_height = curformat.h / GP->vbin; int raw_width = curformat.w / GP->hbin, raw_height = curformat.h / GP->vbin;
ima.h = curformat.h; if(ima.data && raw_width == ima.w && raw_height == ima.h) return; // all OK
ima.w = curformat.w; FREE(ima.data);
DBG("curformat: %dx%d", curformat.w, curformat.h);
ima.h = raw_height;
ima.w = raw_width;
ima.data = MALLOC(uint16_t, raw_width * raw_height); ima.data = MALLOC(uint16_t, raw_width * raw_height);
DBG("new image: %dx%d", raw_width, raw_height);
} }
// functions for processCAM finite state machine // functions for processCAM finite state machine
static inline void cameraidlestate(){ // idle - wait for capture commands static inline void cameraidlestate(){ // idle - wait for capture commands
if(camflags & FLAG_STARTCAPTURE){ // start capturing if(camflags & FLAG_STARTCAPTURE){ // start capturing
camflags &= ~FLAG_STARTCAPTURE; DBG("Start exposition");
camflags &= ~(FLAG_STARTCAPTURE | FLAG_CANCEL);
camstate = CAMERA_CAPTURE; camstate = CAMERA_CAPTURE;
camera->cancel(); camera->cancel();
fixima();
if(!camera->startexposition()){ if(!camera->startexposition()){
LOGERR("Can't start exposition"); LOGERR("Can't start exposition");
WARNX(_("Can't start exposition")); WARNX(_("Can't start exposition"));
@ -69,7 +113,8 @@ static inline void cameraidlestate(){ // idle - wait for capture commands
} }
static inline void cameracapturestate(){ // capturing - wait for exposition ends static inline void cameracapturestate(){ // capturing - wait for exposition ends
if(camflags & FLAG_CANCEL){ // cancel all expositions if(camflags & FLAG_CANCEL){ // cancel all expositions
camflags &= ~FLAG_CANCEL; DBG("Cancel exposition");
camflags &= ~(FLAG_STARTCAPTURE | FLAG_CANCEL);
camera->cancel(); camera->cancel();
camstate = CAMERA_IDLE; camstate = CAMERA_IDLE;
return; return;
@ -77,9 +122,21 @@ static inline void cameracapturestate(){ // capturing - wait for exposition ends
capture_status cs; capture_status cs;
if(camera->pollcapture(&cs, &tremain)){ if(camera->pollcapture(&cs, &tremain)){
if(cs != CAPTURE_PROCESS){ if(cs != CAPTURE_PROCESS){
DBG("Capture ready");
tremain = 0.; tremain = 0.;
camstate = CAMERA_FRAMERDY; // now save frame
return; if(!ima.data) LOGERR("Can't save image: not initialized");
else{
if(!camera->capture(&ima)) LOGERR("Can't capture image");
else{
calculate_stat(&ima);
if(saveFITS(&ima)){
camstate = CAMERA_FRAMERDY;
return;
}
}
}
camstate = CAMERA_ERROR;
} }
} }
} }
@ -87,8 +144,7 @@ static inline void cameracapturestate(){ // capturing - wait for exposition ends
// base camera thread // base camera thread
static void* processCAM(_U_ void *d){ static void* processCAM(_U_ void *d){
if(!camera) ERRX(_("No camera device")); if(!camera) ERRX(_("No camera device"));
camera_state curstate = camstate; double logt = 0;
double logt = dtime();
while(1){ while(1){
// log // log
if(dtime() - logt > TLOG_PAUSE){ if(dtime() - logt > TLOG_PAUSE){
@ -104,6 +160,7 @@ static void* processCAM(_U_ void *d){
LOGMSG("BODYTEMP=%f", t); LOGMSG("BODYTEMP=%f", t);
} }
} }
camera_state curstate = camstate;
switch(curstate){ switch(curstate){
case CAMERA_IDLE: case CAMERA_IDLE:
cameraidlestate(); cameraidlestate();
@ -213,7 +270,7 @@ static hresult exphandler(int fd, _U_ const char *key, const char *val){
GP->exptime = v; GP->exptime = v;
}else LOGWARN("Can't set exptime to %g", v); }else LOGWARN("Can't set exptime to %g", v);
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
} }else return RESULT_BUSY;
} }
snprintf(buf, 63, CMD_EXPOSITION "=%g", GP->exptime); snprintf(buf, 63, CMD_EXPOSITION "=%g", GP->exptime);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
@ -221,33 +278,45 @@ static hresult exphandler(int fd, _U_ const char *key, const char *val){
} }
// filename setter/getter // filename setter/getter
static hresult namehandler(int fd, _U_ const char *key, const char *val){ static hresult namehandler(int fd, _U_ const char *key, const char *val){
char buf[64]; char buf[PATH_MAX+1];
if(val){ if(val){
pthread_mutex_lock(&locmutex); pthread_mutex_lock(&locmutex);
char *path = makeabspath(val);
if(!path){
LOGERR("Can't create file '%s'", val);
pthread_mutex_unlock(&locmutex);
return RESULT_BADVAL;
}
FREE(outfile); FREE(outfile);
outfile = strdup(val); outfile = strdup(path);
GP->outfile = outfile; GP->outfile = outfile;
GP->outfileprefix = NULL; GP->outfileprefix = NULL;
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
} }
if(!GP->outfile) return RESULT_FAIL; if(!GP->outfile) return RESULT_FAIL;
snprintf(buf, 63, CMD_FILENAME "=%s", GP->outfile); snprintf(buf, PATH_MAX, CMD_FILENAME "=%s", GP->outfile);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
return RESULT_SILENCE; return RESULT_SILENCE;
} }
// filename prefix // filename prefix
static hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){ static hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){
char buf[64]; char buf[PATH_MAX+1];
if(val){ if(val){
pthread_mutex_lock(&locmutex); pthread_mutex_lock(&locmutex);
char *path = makeabspath(val);
if(!path){
LOGERR("Can't create file '%s'", val);
pthread_mutex_unlock(&locmutex);
return RESULT_BADVAL;
}
FREE(outfile); FREE(outfile);
outfile = strdup(val); outfile = strdup(path);
GP->outfileprefix = outfile; GP->outfileprefix = outfile;
GP->outfile = NULL; GP->outfile = NULL;
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
} }
if(!GP->outfileprefix) return RESULT_FAIL; if(!GP->outfileprefix) return RESULT_FAIL;
snprintf(buf, 63, CMD_FILENAMEPREFIX "=%s", GP->outfileprefix); snprintf(buf, PATH_MAX, CMD_FILENAMEPREFIX "=%s", GP->outfileprefix);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
return RESULT_SILENCE; return RESULT_SILENCE;
} }
@ -278,6 +347,7 @@ static hresult binhandler(_U_ int fd, const char *key, const char *val){
return RESULT_BADVAL; return RESULT_BADVAL;
} }
fixima(); fixima();
pthread_mutex_unlock(&locmutex);
} }
pthread_mutex_lock(&locmutex); pthread_mutex_lock(&locmutex);
int r = camera->getbin(&GP->hbin, &GP->vbin); int r = camera->getbin(&GP->hbin, &GP->vbin);
@ -293,18 +363,20 @@ static hresult binhandler(_U_ int fd, const char *key, const char *val){
static hresult temphandler(_U_ int fd, _U_ const char *key, const char *val){ static hresult temphandler(_U_ int fd, _U_ const char *key, const char *val){
float f; float f;
char buf[64]; char buf[64];
int r;
if(val){ if(val){
f = atof(val); f = atof(val);
pthread_mutex_lock(&locmutex); pthread_mutex_lock(&locmutex);
if(!camera->setT((float)f)){ r = camera->setT((float)f);
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
if(!r){
LOGWARN("Can't set camera T to %.1f", f); LOGWARN("Can't set camera T to %.1f", f);
return RESULT_FAIL; return RESULT_FAIL;
} }
LOGMSG("Set camera T to %.1f", f); LOGMSG("Set camera T to %.1f", f);
} }
pthread_mutex_lock(&locmutex); pthread_mutex_lock(&locmutex);
int r = camera->getTcold(&f); r = camera->getTcold(&f);
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
if(r){ if(r){
snprintf(buf, 63, CMD_CAMTEMPER "=%.1f", f); snprintf(buf, 63, CMD_CAMTEMPER "=%.1f", f);
@ -443,10 +515,10 @@ static hresult formathandler(int fd, const char *key, const char *val){
curformat = fmt; curformat = fmt;
fixima(); fixima();
} }
if(strcmp(key, CMD_FRAMEMAX)) snprintf(buf, 63, CMD_FRAMEMAX "=%d,%d,%d,%d", if(0 == strcmp(key, CMD_FRAMEMAX)) snprintf(buf, 63, CMD_FRAMEMAX "=%d,%d,%d,%d",
frmformatmax.xoff, frmformatmax.yoff, frmformatmax.xoff+frmformatmax.w, frmformatmax.yoff+frmformatmax.w); frmformatmax.xoff, frmformatmax.yoff, frmformatmax.xoff+frmformatmax.w, frmformatmax.yoff+frmformatmax.w);
else snprintf(buf, 63, CMD_FRAMEFORMAT "=%d,%d,%d,%d", else snprintf(buf, 63, CMD_FRAMEFORMAT "=%d,%d,%d,%d",
camera->array.xoff, camera->array.yoff, camera->array.xoff+camera->array.w, camera->array.yoff+camera->array.w); camera->array.xoff, camera->array.yoff, camera->array.xoff+camera->array.w, camera->array.yoff+camera->array.w);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
return RESULT_SILENCE; return RESULT_SILENCE;
} }
@ -600,17 +672,14 @@ static hresult fgotohandler(int fd, _U_ const char *key, const char *val){
r = focuser->getPos(&f); r = focuser->getPos(&f);
pthread_mutex_unlock(&locmutex); pthread_mutex_unlock(&locmutex);
if(!r) return RESULT_FAIL; if(!r) return RESULT_FAIL;
snprintf(buf, 63, "FOCPOS=%g", f); snprintf(buf, 63, CMD_FGOTO "=%g", f);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
return RESULT_SILENCE; return RESULT_SILENCE;
} }
/* /*******************************************************************************
static hresult handler(_U_ int fd, _U_ const char *key, _U_ const char *val){ **************************** Common handlers **********************************
char buf[64]; ******************************************************************************/
return RESULT_SILENCE;
}
*/
// information about everything // information about everything
static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){ static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){
@ -634,14 +703,14 @@ static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
if(wheel->getTbody(&f)){ if(wheel->getTbody(&f)){
snprintf(buf, BUFSIZ-1, "WHEELTEMP=%.1f", f); snprintf(buf, BUFSIZ-1, "wtemp=%.1f", f);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
if(wheel->getPos(&i)){ if(wheel->getPos(&i)){
snprintf(buf, BUFSIZ-1, "WHEELPOS=%d", i); snprintf(buf, BUFSIZ-1, CMD_WPOS "=%d", i);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
snprintf(buf, BUFSIZ-1, "WHEELMAXPOS=%d", wmaxpos); snprintf(buf, BUFSIZ-1, "wmaxpos=%d", wmaxpos);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
if(focuser){ if(focuser){
@ -650,20 +719,31 @@ static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
if(focuser->getTbody(&f)){ if(focuser->getTbody(&f)){
snprintf(buf, BUFSIZ-1, "FOCTEMP=%.1f", f); snprintf(buf, BUFSIZ-1, "foctemp=%.1f", f);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
snprintf(buf, BUFSIZ-1, "FOCMINPOS=%g", focminpos); snprintf(buf, BUFSIZ-1, "focminpos=%g", focminpos);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
snprintf(buf, BUFSIZ-1, "FOCMAXPOS=%g", focmaxpos); snprintf(buf, BUFSIZ-1, "focmaxpos=%g", focmaxpos);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
if(focuser->getPos(&f)){ if(focuser->getPos(&f)){
snprintf(buf, BUFSIZ-1, "FOCPOS=%g", f); snprintf(buf, BUFSIZ-1, CMD_FGOTO "=%g", f);
sendstrmessage(fd, buf); sendstrmessage(fd, buf);
} }
} }
return RESULT_SILENCE; return RESULT_SILENCE;
} }
// show help
static hresult helphandler(int fd, _U_ const char *key, _U_ const char *val){
char buf[256];
strpair *ptr = allcommands;
while(ptr->key){
snprintf(buf, 255, "%s - %s", ptr->key, ptr->help);
sendstrmessage(fd, buf);
++ptr;
}
return RESULT_SILENCE;
}
// for setters: do nothing when camera not in idle state // for setters: do nothing when camera not in idle state
static int CAMbusy(){ static int CAMbusy(){
@ -691,6 +771,7 @@ static int chkfoc(char *val){
} }
static handleritem items[] = { static handleritem items[] = {
{chktrue, infohandler, CMD_INFO}, {chktrue, infohandler, CMD_INFO},
{chktrue, helphandler, CMD_HELP},
{chkcam, camlisthandler, CMD_CAMLIST}, {chkcam, camlisthandler, CMD_CAMLIST},
{chkcam, camsetNhandler, CMD_CAMDEVNO}, {chkcam, camsetNhandler, CMD_CAMDEVNO},
{chkcam, camfanhandler, CMD_CAMFANSPD}, {chkcam, camfanhandler, CMD_CAMFANSPD},
@ -769,21 +850,10 @@ void server(int sock){
// process some data & send messages to ALL // process some data & send messages to ALL
if(camstate == CAMERA_FRAMERDY || camstate == CAMERA_ERROR){ if(camstate == CAMERA_FRAMERDY || camstate == CAMERA_ERROR){
char buff[32]; char buff[32];
int l = 0;
snprintf(buff, 31, CMD_EXPSTATE "=%d", camstate); snprintf(buff, 31, CMD_EXPSTATE "=%d", camstate);
DBG("Send %s to %d clients", buff, nfd - 1); DBG("Send %s to %d clients", buff, nfd - 1);
for(int i = 1; i < nfd; ++i) for(int i = 1; i < nfd; ++i)
sendmessage(poll_set[i].fd, buff, l); sendstrmessage(poll_set[i].fd, buff);
if(camstate == CAMERA_FRAMERDY){ // save frame
if(!ima.data) LOGERR("Can't save image: not initialized");
else{
if(!camera->capture(&ima)) LOGERR("Can't capture image");
else{
calculate_stat(&ima);
saveFITS(&ima);
}
}
}
camstate = CAMERA_IDLE; camstate = CAMERA_IDLE;
} }
// scan connections // scan connections
@ -806,3 +876,25 @@ void server(int sock){
closecam(camdev); closecam(camdev);
} }
char *makeabspath(const char *path){
static char buf[PATH_MAX+1];
if(!path) return NULL;
char *ret = NULL;
int unl = 0;
FILE *f = fopen(path, "r");
if(!f){
f = fopen(path, "a");
if(!f){
WARN("Can't create %s", path);
return NULL;
}
unl = 1;
}
if(!realpath(path, buf)){
WARN("realpath()");
return NULL;
}else ret = buf;
fclose(f);
if(unl) unlink(path);
return ret;
}

View File

@ -32,9 +32,11 @@ typedef enum{
// server-side functions // server-side functions
void server(int fd); void server(int fd);
char *makeabspath(const char *path);
// common information about everything // common information about everything
#define CMD_INFO "info" #define CMD_INFO "info"
#define CMD_HELP "help"
// CCD/CMOS // CCD/CMOS
#define CMD_CAMLIST "camlist" #define CMD_CAMLIST "camlist"
@ -63,7 +65,7 @@ void server(int fd);
// focuser // focuser
#define CMD_FOCLIST "foclist" #define CMD_FOCLIST "foclist"
#define CMD_FDEVNO "focdevno" #define CMD_FDEVNO "focdevno"
#define CMD_FGOTO "focgoto" #define CMD_FGOTO "focpos"
// wheel // wheel
#define CMD_WLIST "wlist" #define CMD_WLIST "wlist"

View File

@ -129,7 +129,7 @@ void sendmessage(int fd, const char *msg, int l){
}else{ }else{
if(globlog){ // logging turned ON if(globlog){ // logging turned ON
tmpbuf[l-1] = 0; // remove trailing '\n' for logging tmpbuf[l-1] = 0; // remove trailing '\n' for logging
LOGMSG("SEND '%s'", tmpbuf); LOGDBG("SEND '%s'", tmpbuf);
} }
} }
FREE(tmpbuf); FREE(tmpbuf);
@ -183,8 +183,8 @@ char *get_keyval(char *keyval){
static void parsestring(int fd, handleritem *handlers, char *str){ static void parsestring(int fd, handleritem *handlers, char *str){
if(fd < 1 || !handlers || !handlers->key || !str || !*str) return; if(fd < 1 || !handlers || !handlers->key || !str || !*str) return;
char *val = get_keyval(str); char *val = get_keyval(str);
if(val) LOGMSG("RECEIVE '%s=%s'", str, val); if(val) LOGDBG("RECEIVE '%s=%s'", str, val);
else LOGMSG("RECEIVE '%s'", str); else LOGDBG("RECEIVE '%s'", str);
for(handleritem *h = handlers; h->key; ++h){ for(handleritem *h = handlers; h->key; ++h){
if(strcmp(str, h->key) == 0){ // found command if(strcmp(str, h->key) == 0){ // found command
if(h->chkfunction && !h->chkfunction(val)) sendstrmessage(fd, resmessages[RESULT_FAIL]); if(h->chkfunction && !h->chkfunction(val)) sendstrmessage(fd, resmessages[RESULT_FAIL]);