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

View File

@ -305,6 +305,7 @@ static int gett(_U_ float *t){
}
static int camsetbin(int h, int v){
DBG("set bin %dx%d", h, v);
if(h != v){
WARNX(_("BinX and BinY should be equal"));
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
void saveFITS(IMG *img){
// return FALSE if failed
int saveFITS(IMG *img){
int ret = FALSE;
if(!camera){
LOGERR("Can't save image: no camera device");
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){
LOGERR("Can't save image: 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
struct stat filestat;
int s = stat(GP->outfile, &filestat);
if(s){ // not exists
snprintf(fnam, PATH_MAX-1, "%s", GP->outfile);
snprintf(fnam, PATH_MAX, "%s", GP->outfile);
}else{ // exists
if(!GP->rewrite){
LOGERR("Can't save image: 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
if(!check_filenameprefix(fnam, PATH_MAX)){
@ -323,15 +325,18 @@ void saveFITS(IMG *img){
TRYFITS(fits_write_img, fp, TUSHORT, 1, width * height, data);
if(fitserror) goto cloerr;
TRYFITS(fits_close_file, fp);
DBG("file %s saved", fnam);
cloerr:
if(fitserror == 0){
LOGMSG("Save file '%s'", fnam);
verbose(1, _("File saved as '%s'"), fnam);
ret = TRUE;
}else{
LOGERR("Can't save %s", fnam);
WARNX(_("Error saving file"));
fitserror = 0;
}
return ret;
}
void calculate_stat(IMG *image){

View File

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

View File

@ -76,32 +76,11 @@ static char *getans(int sock){
buf[n] = 0;
DBG("Got from server: %s", buf);
verbose(1, "%s", buf);
if(buf[n-1] == '\n') break;
}
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
*/

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)")},
{"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")},
{"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 ")")},
#ifdef IMAGEVIEW

View File

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

View File

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

5
main.c
View File

@ -52,7 +52,7 @@ void signals(int signo){
// slave: cancel exposition
WARNX("Get signal %d - exit", signo);
DBG("Cancel capturing");
cancel();
if(!GP->client) cancel();
#ifdef IMAGEVIEW
DBG("KILL GL");
closeGL();
@ -75,7 +75,7 @@ int main(int argc, char **argv){
struct stat filestat;
if(0 == stat(GP->outfile, &filestat)) ERRX("File %s exists!", GP->outfile);
}
if(GP->port || GP->path){
if(GP->port){
if(GP->path){
WARNX("Options `port` and `path` can't be used together! Point `port` for TCP socket or `path` for UNIX.");
return 1;
@ -87,6 +87,7 @@ int main(int argc, char **argv){
}
if(!GP->client) isserver = TRUE;
}
if(GP->path && !GP->client) isserver = TRUE;
if(GP->logfile){
int lvl = LOGLEVEL_WARN + GP->verbose;
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 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 void fixima(){
FREE(ima.data);
FNAME();
int raw_width = curformat.w / GP->hbin, raw_height = curformat.h / GP->vbin;
ima.h = curformat.h;
ima.w = curformat.w;
if(ima.data && raw_width == ima.w && raw_height == ima.h) return; // all OK
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);
DBG("new image: %dx%d", raw_width, raw_height);
}
// functions for processCAM finite state machine
static inline void cameraidlestate(){ // idle - wait for capture commands
if(camflags & FLAG_STARTCAPTURE){ // start capturing
camflags &= ~FLAG_STARTCAPTURE;
DBG("Start exposition");
camflags &= ~(FLAG_STARTCAPTURE | FLAG_CANCEL);
camstate = CAMERA_CAPTURE;
camera->cancel();
fixima();
if(!camera->startexposition()){
LOGERR("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
if(camflags & FLAG_CANCEL){ // cancel all expositions
camflags &= ~FLAG_CANCEL;
DBG("Cancel exposition");
camflags &= ~(FLAG_STARTCAPTURE | FLAG_CANCEL);
camera->cancel();
camstate = CAMERA_IDLE;
return;
@ -77,9 +122,21 @@ static inline void cameracapturestate(){ // capturing - wait for exposition ends
capture_status cs;
if(camera->pollcapture(&cs, &tremain)){
if(cs != CAPTURE_PROCESS){
DBG("Capture ready");
tremain = 0.;
camstate = CAMERA_FRAMERDY;
return;
// now 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);
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
static void* processCAM(_U_ void *d){
if(!camera) ERRX(_("No camera device"));
camera_state curstate = camstate;
double logt = dtime();
double logt = 0;
while(1){
// log
if(dtime() - logt > TLOG_PAUSE){
@ -104,6 +160,7 @@ static void* processCAM(_U_ void *d){
LOGMSG("BODYTEMP=%f", t);
}
}
camera_state curstate = camstate;
switch(curstate){
case CAMERA_IDLE:
cameraidlestate();
@ -213,7 +270,7 @@ static hresult exphandler(int fd, _U_ const char *key, const char *val){
GP->exptime = v;
}else LOGWARN("Can't set exptime to %g", v);
pthread_mutex_unlock(&locmutex);
}
}else return RESULT_BUSY;
}
snprintf(buf, 63, CMD_EXPOSITION "=%g", GP->exptime);
sendstrmessage(fd, buf);
@ -221,33 +278,45 @@ static hresult exphandler(int fd, _U_ const char *key, const char *val){
}
// filename setter/getter
static hresult namehandler(int fd, _U_ const char *key, const char *val){
char buf[64];
char buf[PATH_MAX+1];
if(val){
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);
outfile = strdup(val);
outfile = strdup(path);
GP->outfile = outfile;
GP->outfileprefix = NULL;
pthread_mutex_unlock(&locmutex);
}
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);
return RESULT_SILENCE;
}
// filename prefix
static hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){
char buf[64];
char buf[PATH_MAX+1];
if(val){
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);
outfile = strdup(val);
outfile = strdup(path);
GP->outfileprefix = outfile;
GP->outfile = NULL;
pthread_mutex_unlock(&locmutex);
}
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);
return RESULT_SILENCE;
}
@ -278,6 +347,7 @@ static hresult binhandler(_U_ int fd, const char *key, const char *val){
return RESULT_BADVAL;
}
fixima();
pthread_mutex_unlock(&locmutex);
}
pthread_mutex_lock(&locmutex);
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){
float f;
char buf[64];
int r;
if(val){
f = atof(val);
pthread_mutex_lock(&locmutex);
if(!camera->setT((float)f)){
pthread_mutex_unlock(&locmutex);
r = camera->setT((float)f);
pthread_mutex_unlock(&locmutex);
if(!r){
LOGWARN("Can't set camera T to %.1f", f);
return RESULT_FAIL;
}
LOGMSG("Set camera T to %.1f", f);
}
pthread_mutex_lock(&locmutex);
int r = camera->getTcold(&f);
r = camera->getTcold(&f);
pthread_mutex_unlock(&locmutex);
if(r){
snprintf(buf, 63, CMD_CAMTEMPER "=%.1f", f);
@ -443,10 +515,10 @@ static hresult formathandler(int fd, const char *key, const char *val){
curformat = fmt;
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);
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);
return RESULT_SILENCE;
}
@ -600,17 +672,14 @@ static hresult fgotohandler(int fd, _U_ const char *key, const char *val){
r = focuser->getPos(&f);
pthread_mutex_unlock(&locmutex);
if(!r) return RESULT_FAIL;
snprintf(buf, 63, "FOCPOS=%g", f);
snprintf(buf, 63, CMD_FGOTO "=%g", f);
sendstrmessage(fd, buf);
return RESULT_SILENCE;
}
/*
static hresult handler(_U_ int fd, _U_ const char *key, _U_ const char *val){
char buf[64];
return RESULT_SILENCE;
}
*/
/*******************************************************************************
**************************** Common handlers **********************************
******************************************************************************/
// information about everything
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);
}
if(wheel->getTbody(&f)){
snprintf(buf, BUFSIZ-1, "WHEELTEMP=%.1f", f);
snprintf(buf, BUFSIZ-1, "wtemp=%.1f", f);
sendstrmessage(fd, buf);
}
if(wheel->getPos(&i)){
snprintf(buf, BUFSIZ-1, "WHEELPOS=%d", i);
snprintf(buf, BUFSIZ-1, CMD_WPOS "=%d", i);
sendstrmessage(fd, buf);
}
snprintf(buf, BUFSIZ-1, "WHEELMAXPOS=%d", wmaxpos);
snprintf(buf, BUFSIZ-1, "wmaxpos=%d", wmaxpos);
sendstrmessage(fd, buf);
}
if(focuser){
@ -650,20 +719,31 @@ static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){
sendstrmessage(fd, buf);
}
if(focuser->getTbody(&f)){
snprintf(buf, BUFSIZ-1, "FOCTEMP=%.1f", f);
snprintf(buf, BUFSIZ-1, "foctemp=%.1f", f);
sendstrmessage(fd, buf);
}
snprintf(buf, BUFSIZ-1, "FOCMINPOS=%g", focminpos);
snprintf(buf, BUFSIZ-1, "focminpos=%g", focminpos);
sendstrmessage(fd, buf);
snprintf(buf, BUFSIZ-1, "FOCMAXPOS=%g", focmaxpos);
snprintf(buf, BUFSIZ-1, "focmaxpos=%g", focmaxpos);
sendstrmessage(fd, buf);
if(focuser->getPos(&f)){
snprintf(buf, BUFSIZ-1, "FOCPOS=%g", f);
snprintf(buf, BUFSIZ-1, CMD_FGOTO "=%g", f);
sendstrmessage(fd, buf);
}
}
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
static int CAMbusy(){
@ -691,6 +771,7 @@ static int chkfoc(char *val){
}
static handleritem items[] = {
{chktrue, infohandler, CMD_INFO},
{chktrue, helphandler, CMD_HELP},
{chkcam, camlisthandler, CMD_CAMLIST},
{chkcam, camsetNhandler, CMD_CAMDEVNO},
{chkcam, camfanhandler, CMD_CAMFANSPD},
@ -769,21 +850,10 @@ void server(int sock){
// process some data & send messages to ALL
if(camstate == CAMERA_FRAMERDY || camstate == CAMERA_ERROR){
char buff[32];
int l = 0;
snprintf(buff, 31, CMD_EXPSTATE "=%d", camstate);
DBG("Send %s to %d clients", buff, nfd - 1);
for(int i = 1; i < nfd; ++i)
sendmessage(poll_set[i].fd, buff, l);
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);
}
}
}
sendstrmessage(poll_set[i].fd, buff);
camstate = CAMERA_IDLE;
}
// scan connections
@ -806,3 +876,25 @@ void server(int sock){
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
void server(int fd);
char *makeabspath(const char *path);
// common information about everything
#define CMD_INFO "info"
#define CMD_HELP "help"
// CCD/CMOS
#define CMD_CAMLIST "camlist"
@ -63,7 +65,7 @@ void server(int fd);
// focuser
#define CMD_FOCLIST "foclist"
#define CMD_FDEVNO "focdevno"
#define CMD_FGOTO "focgoto"
#define CMD_FGOTO "focpos"
// wheel
#define CMD_WLIST "wlist"

View File

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