some fixes

This commit is contained in:
eddyem 2017-03-23 10:35:39 +03:00
parent b7654b2569
commit 91f3b192cd
9 changed files with 1971 additions and 446 deletions

View File

@ -11,24 +11,21 @@ OBJS := $(SRCS:%.c=%.o)
CC = gcc CC = gcc
CPP = g++ CPP = g++
all : sbig340 daemon client all : sbig340_standalone sbig340_daemon sbig340_client
debayer.o : debayer.cpp debayer.o : debayer.cpp
@echo -e "\t\tG++ debayer" @echo -e "\t\tG++ debayer"
$(CPP) $(CFLAGS) $(DEFINES) debayer.cpp -c $(CPP) $(CFLAGS) $(DEFINES) debayer.cpp -c
sbig340 : $(SRCS) debayer.o sbig340_standalone : $(SRCS) debayer.o
@echo -e "\t\tBuild sbig340" @echo -e "\t\tBuild standalone"
$(CC) $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(LDIMG) $(SRCS) debayer.o -o $@ $(CC) $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(LDIMG) $(SRCS) debayer.o -o $@
# $(CC) -c $(CFLAGS) -std=gnu99 $(DEFINES) $(SRCS) sbig340_daemon : $(SRCS)
# $(CPP) $(LDFLAGS) $(OBJS) debayer.o -o $@
daemon : $(SRCS)
@echo -e "\t\tBuild daemon" @echo -e "\t\tBuild daemon"
$(CC) -DDAEMON $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(SRCS) -o $@ $(CC) -DDAEMON $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(SRCS) -o $@
client : $(SRCS) debayer.o sbig340_client : $(SRCS) debayer.o
@echo -e "\t\tBuild client" @echo -e "\t\tBuild client"
$(CC) -DCLIENT $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(LDIMG) $(SRCS) debayer.o -o $@ $(CC) -DCLIENT $(CFLAGS) -std=gnu99 $(DEFINES) $(LDFLAGS) $(LDIMG) $(SRCS) debayer.o -o $@
@ -38,9 +35,9 @@ clean:
xclean: clean xclean: clean
@echo -e "\t\tRM binaries" @echo -e "\t\tRM binaries"
@rm -f sbig340 daemon client @rm -f sbig340_standalone sbig340_daemon sbig340_client
gentags: gentags:
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] *.cpp 2>/dev/null CFLAGS="$(CFLAGS) $(DEFINES)" geany -g sbig340.c.tags *.[hc] *.cpp 2>/dev/null
.PHONY: gentags clean xclean .PHONY: gentags clean xclean

View File

@ -3,7 +3,7 @@ SBIG all-sky 340c driving utilite
Run `make` to compile three binary files: Run `make` to compile three binary files:
* `sbig340` --- standalone utility (no daemon/client) * `sbig340_standalone` --- standalone utility (no daemon/client)
* `daemon` --- pure grabbing daemon (driven by socket) * `sbig340_daemon` --- pure grabbing daemon (driven by socket)
* `client` --- pure client (take images from daemon and save locally) * `sbig340_client` --- pure client (take images from daemon and save locally)

View File

@ -52,7 +52,7 @@ glob_pars const Gdefault = {
.imtype = "l", .imtype = "l",
.imformat = NULL, .imformat = NULL,
.imstoretype = NULL, .imstoretype = NULL,
.outpfname = "output.tiff", .outpfname = "output.fits",
.hostname = NULL, .hostname = NULL,
.port = "4444", .port = "4444",
.once = 0, .once = 0,
@ -77,7 +77,7 @@ myoption cmdlnopts[] = {
// not daemon options // not daemon options
#ifndef DAEMON #ifndef DAEMON
{"storetype",NEED_ARG, NULL, 'S', arg_string, APTR(&G.imstoretype),_("'overwrite'/'rewrite' to rewrite existing image, 'enumerate'/'numerate' to use given filename as base for series")}, {"storetype",NEED_ARG, NULL, 'S', arg_string, APTR(&G.imstoretype),_("'overwrite'/'rewrite' to rewrite existing image, 'enumerate'/'numerate' to use given filename as base for series")},
{"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outpfname), _("output file name (default: output.tiff)")}, {"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outpfname), _("output file name (default: output.fits)")},
{"imformat",NEED_ARG, NULL, 'f', arg_string, APTR(&G.imformat), _("image format: FITS (f), TIFF (t), raw dump with histogram storage (r,d), may be OR'ed; default: FITS or based on output image name")}, {"imformat",NEED_ARG, NULL, 'f', arg_string, APTR(&G.imformat), _("image format: FITS (f), TIFF (t), raw dump with histogram storage (r,d), may be OR'ed; default: FITS or based on output image name")},
#endif #endif
// not client options // not client options
@ -101,6 +101,9 @@ myoption cmdlnopts[] = {
{"timestamp",NO_ARGS, NULL, 't', arg_int, APTR(&G.timestamp), _("add timestamp to filename")}, {"timestamp",NO_ARGS, NULL, 't', arg_int, APTR(&G.timestamp), _("add timestamp to filename")},
#endif #endif
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: 4444)")}, {"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: 4444)")},
#endif
// only daemon options
#ifdef DAEMON
{"dark-interval",NEED_ARG,NULL, 'D', arg_double, APTR(&G.dark_interval),_("time interval (in seconds) between dark images taken (default: 1800)")}, {"dark-interval",NEED_ARG,NULL, 'D', arg_double, APTR(&G.dark_interval),_("time interval (in seconds) between dark images taken (default: 1800)")},
{"min-dark-exp",NEED_ARG,NULL, 'E', arg_double, APTR(&G.min_dark_exp),_("minimal exposition (in seconds) at which darks would be taken (default: 30)")}, {"min-dark-exp",NEED_ARG,NULL, 'E', arg_double, APTR(&G.min_dark_exp),_("minimal exposition (in seconds) at which darks would be taken (default: 30)")},
#endif #endif

View File

@ -71,6 +71,7 @@ char *make_filename(imstorage *img, const char *suff){
stm->tm_hour, stm->tm_min, stm->tm_sec); stm->tm_hour, stm->tm_min, stm->tm_sec);
outfile = fnbuf; outfile = fnbuf;
} }
DBG("name: %s", outfile);
if(st == STORE_NORMAL || st == STORE_REWRITE){ if(st == STORE_NORMAL || st == STORE_REWRITE){
snprintf(buff, FILENAME_MAX, "%s.%s", outfile, suff); snprintf(buff, FILENAME_MAX, "%s.%s", outfile, suff);
if(stat(buff, &filestat)){ if(stat(buff, &filestat)){
@ -106,8 +107,9 @@ char *make_filename(imstorage *img, const char *suff){
* @param store (i) - "overwrite" (or "rewrite"), "normal" (or NULL), "enumerate" (or "numerate") * @param store (i) - "overwrite" (or "rewrite"), "normal" (or NULL), "enumerate" (or "numerate")
* @param format (i) - image format (ft[rd]) * @param format (i) - image format (ft[rd])
*/ */
imstorage *chk_storeimg(char *filename, char* store, char *format){ imstorage *chk_storeimg(imstorage *ist, char* store, char *format){
FNAME(); FNAME();
if(!ist || !ist->imname) return NULL;
store_type st = STORE_NORMAL; store_type st = STORE_NORMAL;
image_format fmt = FORMAT_FITS; image_format fmt = FORMAT_FITS;
if(store){ // rewrite or enumerate if(store){ // rewrite or enumerate
@ -119,9 +121,7 @@ imstorage *chk_storeimg(char *filename, char* store, char *format){
return NULL; return NULL;
} }
} }
char *nm = strdup(filename); char *pt = strrchr(ist->imname, '.');
if(!nm) ERRX("strdup");
char *pt = strrchr(nm, '.');
DBG("input format: %s", format); DBG("input format: %s", format);
image_format fbysuff = FORMAT_NONE; image_format fbysuff = FORMAT_NONE;
// check if name's suffix is filetype // check if name's suffix is filetype
@ -142,7 +142,6 @@ imstorage *chk_storeimg(char *filename, char* store, char *format){
strchr(format, 'd') || strchr(format, 'D')) fbysuff |= FORMAT_RAW; strchr(format, 'd') || strchr(format, 'D')) fbysuff |= FORMAT_RAW;
if(fbysuff == FORMAT_NONE){ if(fbysuff == FORMAT_NONE){
WARNX(_("Wrong format string: %s"), format); WARNX(_("Wrong format string: %s"), format);
free(nm);
return NULL; return NULL;
} }
fmt = fbysuff; fmt = fbysuff;
@ -155,17 +154,12 @@ imstorage *chk_storeimg(char *filename, char* store, char *format){
#define FMTSZ (3) #define FMTSZ (3)
image_format formats[FMTSZ] = {FORMAT_FITS, FORMAT_TIFF, FORMAT_RAW}; image_format formats[FMTSZ] = {FORMAT_FITS, FORMAT_TIFF, FORMAT_RAW};
const char *suffixes[FMTSZ] = {SUFFIX_FITS, SUFFIX_TIFF, SUFFIX_RAW}; const char *suffixes[FMTSZ] = {SUFFIX_FITS, SUFFIX_TIFF, SUFFIX_RAW};
imstorage *ist = MALLOC(imstorage, 1);
ist->st = st; ist->st = st;
ist->imformat = fmt; ist->imformat = fmt;
ist->imname = strdup(nm);
for(size_t i = 0; i < FMTSZ; ++i){ for(size_t i = 0; i < FMTSZ; ++i){
if(!(formats[i] & fmt)) continue; if(!(formats[i] & fmt)) continue;
if(!make_filename(ist, suffixes[i])){ if(!make_filename(ist, suffixes[i])){
WARNX(_("Can't create output file (is it exists?)")); WARNX(_("Can't create output file (is it exists?)"));
free(nm);
free(ist->imname);
free(ist);
return NULL; return NULL;
} }
} }
@ -424,7 +418,7 @@ int save_histo(FILE *f, imstorage *img){
if(mul > mulmax) mul = mulmax; if(mul > mulmax) mul = mulmax;
double E = img->exptime * mul; double E = img->exptime * mul;
if(E < 5e-5) E = 5e-5; // too short exposition if(E < 5e-5) E = 5e-5; // too short exposition
else if(E > 300.) E = 300.; // no need to do expositions larger than 5 minutes else if(E > 90.) E = 90.; // no need to do expositions larger than 1.5 minutes
green("Recommended exposition time: %g seconds\n", E); green("Recommended exposition time: %g seconds\n", E);
exp_calculated = E; exp_calculated = E;
return 0; return 0;

View File

@ -79,7 +79,7 @@ extern double exp_calculated;
#define SUFFIX_JPEG "jpg" #define SUFFIX_JPEG "jpg"
char *make_filename(imstorage *img, const char *suff); char *make_filename(imstorage *img, const char *suff);
imstorage *chk_storeimg(char *filename, char* store, char *format); imstorage *chk_storeimg(imstorage *img, char* store, char *format);
int store_image(imstorage *filename); int store_image(imstorage *filename);
void print_stat(imstorage *img); void print_stat(imstorage *img);
#ifndef CLIENT #ifndef CLIENT

17
main.c
View File

@ -22,6 +22,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <signal.h> #include <signal.h>
#include <time.h>
#ifndef EBUG #ifndef EBUG
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
@ -81,11 +82,15 @@ int main(int argc, char **argv){
G->binning = 0xff; // take subframe G->binning = 0xff; // take subframe
} }
#endif // !CLIENT #endif // !CLIENT
img = MALLOC(imstorage, 1);
#ifdef CLIENT
img->once = G->once;
img->timestamp = G->timestamp;
#endif
#ifndef DAEMON #ifndef DAEMON
img = chk_storeimg(G->outpfname, G->imstoretype, G->imformat); img->imname = G->outpfname;
if(!img) return 1; img->exposetime = time(NULL);
#else if(!chk_storeimg(img, G->imstoretype, G->imformat)) return 1;
img = MALLOC(imstorage, 1); // just allocate empty: all we need in daemon is exposition & binning
#endif #endif
#ifndef CLIENT #ifndef CLIENT
if(img){ if(img){
@ -115,10 +120,6 @@ int main(int argc, char **argv){
run_terminal(); // non-echo terminal mode run_terminal(); // non-echo terminal mode
} }
#endif // !defined DAEMON && !defined CLIENT #endif // !defined DAEMON && !defined CLIENT
#ifdef CLIENT
img->once = G->once;
img->timestamp = G->timestamp;
#endif
#if defined CLIENT || defined DAEMON #if defined CLIENT || defined DAEMON
#ifdef DAEMON #ifdef DAEMON
set_darks(G->min_dark_exp, G->dark_interval); set_darks(G->min_dark_exp, G->dark_interval);

File diff suppressed because it is too large Load Diff

View File

@ -334,6 +334,7 @@ static void daemon_(imstorage *img, int sock){
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
if(copyima(img)){ if(copyima(img)){
++imctr; ++imctr;
if(img->imtype != IMTYPE_DARK)
save_histo(NULL, img); // calculate next optimal exposition save_histo(NULL, img); // calculate next optimal exposition
} }
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);

8
term.c
View File

@ -500,6 +500,14 @@ int start_exposition(imstorage *im, char *imtype){
b = bngs[binning]; b = bngs[binning];
}else b = "subframe"; }else b = "subframe";
cmd[4] = binning; cmd[4] = binning;
if(!imtype){
it = im->imtype;
switch(im->imtype){
case IMTYPE_DARK: imtype = "dark"; break;
case IMTYPE_AUTODARK: imtype = "autodark"; break;
case IMTYPE_LIGHT: default: imtype = "light";
}
}
// and now check image type // and now check image type
if(imtype){ if(imtype){
int L = strlen(imtype); int L = strlen(imtype);