diff --git a/cmdlnopts.c b/cmdlnopts.c index 9e0a365..2956a58 100644 --- a/cmdlnopts.c +++ b/cmdlnopts.c @@ -57,6 +57,8 @@ glob_pars const Gdefault = { .port = "4444", .once = 0, .timestamp = 0, + .dark_interval = 1800, + .min_dark_exp = 30, }; /* @@ -99,6 +101,8 @@ myoption cmdlnopts[] = { {"timestamp",NO_ARGS, NULL, 't', arg_int, APTR(&G.timestamp), _("add timestamp to filename")}, #endif {"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: 4444)")}, + {"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)")}, #endif end_option }; diff --git a/cmdlnopts.h b/cmdlnopts.h index 6b3543a..6eabeb1 100644 --- a/cmdlnopts.h +++ b/cmdlnopts.h @@ -50,6 +50,8 @@ typedef struct{ char *imformat; // output file format char *hostname; // hostname to connect char *port; // port to connect + double dark_interval; // time interval (in seconds) between dark images taken + double min_dark_exp; // minimal exposition (in seconds) @ which darks would be taken char** rest_pars; // the rest parameters: array of char* } glob_pars; diff --git a/debayer.cpp b/debayer.cpp index fc44530..d795c7a 100644 --- a/debayer.cpp +++ b/debayer.cpp @@ -52,7 +52,8 @@ static int write_jpeg(const char *fname, const uint8_t *data, imstorage *img){ char date[256]; strftime(date, 256, "%d/%m/%y\n%H:%M:%S", localtime(&img->exposetime)); gdFTUseFontConfig(1); - char *ret = gdImageStringFT(im, NULL, 0xffffff, "monotype", 10, 0., 2, 12, date); + char *font = (char*)"monotype"; + char *ret = gdImageStringFT(im, NULL, 0xffffff, font, 10, 0., 2, 12, date); if(ret) fprintf(stderr, "Error: %s\n", ret); const char *prefx = ""; double ex = img->exptime; @@ -66,7 +67,7 @@ static int write_jpeg(const char *fname, const uint8_t *data, imstorage *img){ } } snprintf(date, 256, "exp=%.3g %ss", ex, prefx); - gdImageStringFT(im, NULL, 0xffffff, "monotype", 10, 0., 2, img->H-4, date); + gdImageStringFT(im, NULL, 0xffffff, font, 10, 0., 2, img->H-4, date); im->tpixels[10][10] = 0XFF0000; im->tpixels[15][15] = 0XFF0000; gdImageJpeg(im, fp, 90); diff --git a/imfunctions.c b/imfunctions.c index 942595e..c5f7be7 100644 --- a/imfunctions.c +++ b/imfunctions.c @@ -297,7 +297,7 @@ int writefits(imstorage *img){ WRITEKEY(TSTRING, "FIELD", "180 degrees", "Camera field of view"); switch(img->imtype){ case IMTYPE_AUTODARK: - sprintf(buf, "object without dark"); + sprintf(buf, "obj.-dark"); break; case IMTYPE_DARK: sprintf(buf, "dark"); @@ -345,7 +345,13 @@ int writefits(imstorage *img){ snprintf(buf, 80, "(%d, %d)", img->subframe->Xstart, img->subframe->Ystart); WRITEKEY(TSTRING, "SUBFRAME", buf, "Subframe start coordinates (Xstart, Ystart)"); } - TRYFITS(fits_write_img, fp, TUSHORT, 1, img->W * img->H, img->imdata); + // flip image around OX + size_t W = img->W, Wb = sizeof(uint16_t)*W, H = img->H, imsz = img->W * H, y; + uint16_t *image = MALLOC(uint16_t, imsz), *optr = image, *iptr = &img->imdata[W*(H-1)]; + for(y = 0; y < H; ++y, optr += W, iptr -= W) + memcpy(optr, iptr, Wb); + TRYFITS(fits_write_img, fp, TUSHORT, 1, imsz, image); + FREE(image); TRYFITS(fits_close_file, fp); if(*filename == '!') ++filename; // remove '!' from filename modifytimestamp(filename, img); @@ -483,7 +489,8 @@ int store_image(imstorage *img){ if(img->imformat & FORMAT_FITS){ // save FITS if(writefits(img)) status |= 4; } - if(write_debayer(img, glob_min)) status |= 8; // and save colour image + if(img->imtype != IMTYPE_DARK) // store debayer only if image type isn't dark + if(write_debayer(img, glob_min)) status |= 8; // and save colour image return status; } #endif diff --git a/main.c b/main.c index 72ba886..a585445 100644 --- a/main.c +++ b/main.c @@ -120,6 +120,9 @@ int main(int argc, char **argv){ img->timestamp = G->timestamp; #endif #if defined CLIENT || defined DAEMON + #ifdef DAEMON + set_darks(G->min_dark_exp, G->dark_interval); + #endif daemonize(img, G->hostname, G->port); #endif if(img){ diff --git a/socket.c b/socket.c index 4a10a82..1ff6e39 100644 --- a/socket.c +++ b/socket.c @@ -24,16 +24,14 @@ #include "usefull_macros.h" #include "socket.h" #include "term.h" -//#include -//#include #include // addrinfo #include // inet_ntop #include #include // INT_xxx -#include // pthread_kill -#include // daemon -#include // wait -#include //prctl +#include // pthread_kill +#include // daemon +#include // wait +#include //prctl #define BUFLEN (10240) #define BUFLEN10 (1048576) @@ -106,9 +104,15 @@ static int getdpar(uint8_t *str, char *parameter, double *ret){ /**************** CLIENT/SERVER FUNCTIONS ****************/ #ifdef DAEMON +static double min_dark_exp, dark_interval; static imstorage *storedima = NULL; static uint64_t imctr = 0; // image counter pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +// setter for min_dark_exp, dark_interval +void set_darks(double exp, double dt){ + min_dark_exp = exp; + dark_interval = dt; +} static void clearimstorage(){ if(!storedima) return; FREE(storedima->imname); @@ -296,6 +300,7 @@ static void daemon_(imstorage *img, int sock){ FNAME(); if(sock < 0) return; pthread_t sock_thread; + static double lastDT = 0.; // last time dark was taken if(pthread_create(&sock_thread, NULL, server, (void*) &sock)) ERR("pthread_create()"); int errcntr = 0; @@ -307,6 +312,15 @@ static void daemon_(imstorage *img, int sock){ ERR("pthread_create()"); } if(exp_calculated > 0.) img->exptime = exp_calculated; + if(img->imtype != IMTYPE_AUTODARK){ // check for darks + if(img->imtype == IMTYPE_DARK) img->imtype = IMTYPE_LIGHT; // last was dark + else if(img->exptime > min_dark_exp){ // need to store dark frame? + if(dtime() - lastDT > dark_interval){ + lastDT = dtime(); + img->imtype = IMTYPE_DARK; + } + } + } if(start_exposition(img, NULL)){ WARNX(_("Error starting exposition, try later")); ++errcntr; diff --git a/socket.h b/socket.h index c339843..fc2e80b 100644 --- a/socket.h +++ b/socket.h @@ -27,5 +27,8 @@ #include "imfunctions.h" void daemonize(imstorage *img, char *hostname, char *port); +#ifdef DAEMON +void set_darks(double exp, double dt); +#endif #endif // __SOCKET_H__