forget to commit -a

This commit is contained in:
eddyem 2017-02-09 00:56:53 +03:00
parent 80a52be7e1
commit f6f0bd6f0f
10 changed files with 199 additions and 114 deletions

View File

@ -1,41 +1,51 @@
# run `make DEF=...` to add extra defines # run `make DEF=...` to add extra defines
PROGRAM := sbig340
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
LDFLAGS += -ltiff -lm $(shell pkg-config --libs cfitsio) LDFLAGS += -lm -pthread
SRCS := $(wildcard *.c) SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_XOPEN_SOURCE=1111 -DEBUG DEFINES := $(DEF) -D_XOPEN_SOURCE=1111
OBJDIR := mk DEFINES += -DEBUG
#OBJDIR := mk
CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines -std=gnu99 CFLAGS += -O2 -Wall -Werror -Wextra -Wno-trampolines -std=gnu99
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o)) #OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
DEPS := $(OBJS:.o=.d) #DEPS := $(OBJS:.o=.d)
CC = gcc CC = gcc
all : $(OBJDIR) $(PROGRAM) all : sbig340 daemon client
# $(OBJDIR)
$(PROGRAM) : $(OBJS) sbig340 : $(SRCS)
@echo -e "\t\tLD $(PROGRAM)" @echo -e "\t\tLD sbig340"
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM) $(CC) $(CFLAGS) $(DEFINES) $(LDFLAGS) $(shell pkg-config --libs cfitsio) -ltiff $(SRCS) -o sbig340
$(OBJDIR): daemon : $(SRCS)
mkdir $(OBJDIR) @echo -e "\t\tLD daemon"
$(CC) -DDAEMON $(CFLAGS) $(DEFINES) $(LDFLAGS) $(SRCS) -o daemon
ifneq ($(MAKECMDGOALS),clean) client : $(SRCS)
-include $(DEPS) @echo -e "\t\tLD client"
endif $(CC) -DCLIENT $(CFLAGS) $(DEFINES) $(LDFLAGS) $(shell pkg-config --libs cfitsio) -ltiff $(SRCS) -o client
$(OBJDIR)/%.o: %.c #$(OBJDIR):
@echo -e "\t\tCC $<" # mkdir $(OBJDIR)
$(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $<
clean: #ifneq ($(MAKECMDGOALS),clean)
@echo -e "\t\tCLEAN" #-include $(DEPS)
@rm -f $(OBJS) $(DEPS) #endif
@rmdir $(OBJDIR) 2>/dev/null || true
xclean: clean #$(OBJDIR)/%.o: %.c
@rm -f $(PROGRAM) # @echo -e "\t\tCC $<"
# $(CC) -MD -c $(LDFLAGS) $(CFLAGS) $(DEFINES) -o $@ $<
#clean:
# @echo -e "\t\tCLEAN"
# @rm -f $(OBJS) $(DEPS)
# @rmdir $(OBJDIR) 2>/dev/null || true
#xclean: clean
# @rm -f $(PROGRAM)
gentags: gentags:
CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null CFLAGS="$(CFLAGS) $(DEFINES)" geany -g $(PROGRAM).c.tags *[hc] 2>/dev/null
.PHONY: gentags clean xclean .PHONY: gentags
#clean xclean

View File

@ -1,2 +0,0 @@
# SBIG_340
Sbig all-sky 340 C support

View File

@ -32,13 +32,10 @@
int help; int help;
glob_pars G; glob_pars G;
int rewrite_ifexists = 0, // rewrite existing files == 0 or 1
verbose = 0; // each -v increments this value, e.g. -vvv sets it to 3
#define DEFAULT_COMDEV "/dev/ttyUSB0" #define DEFAULT_COMDEV "/dev/ttyUSB0"
// DEFAULTS // DEFAULTS
// default global parameters // default global parameters
glob_pars const Gdefault = { glob_pars const Gdefault = {
.daemon = 0,
.terminal = 0, .terminal = 0,
.heater = HEATER_LEAVE, .heater = HEATER_LEAVE,
.device = DEFAULT_COMDEV, .device = DEFAULT_COMDEV,
@ -56,6 +53,8 @@ glob_pars const Gdefault = {
.imformat = NULL, .imformat = NULL,
.imstoretype = NULL, .imstoretype = NULL,
.outpfname = "output.tiff", .outpfname = "output.tiff",
.hostname = "localhost",
.port = "4444"
}; };
/* /*
@ -63,10 +62,22 @@ glob_pars const Gdefault = {
* name has_arg flag val type argptr help * name has_arg flag val type argptr help
*/ */
myoption cmdlnopts[] = { myoption cmdlnopts[] = {
// set 1 to param despite of its repeating number: // common options
{"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")}, {"help", NO_ARGS, NULL, 'h', arg_int, APTR(&help), _("show this help")},
{"daemon", NO_ARGS, NULL, 'd', arg_int, APTR(&G.daemon), _("run as daemon")}, // only standalone options
#if !defined DAEMON && !defined CLIENT
{"imtype", NEED_ARG, NULL, 'T', arg_string, APTR(&G.imtype), _("image type: light (l, L), autodark (a, A), dark (d, D); default: light")},
{"terminal",NO_ARGS, NULL, 't', arg_int, APTR(&G.terminal), _("run as terminal")}, {"terminal",NO_ARGS, NULL, 't', arg_int, APTR(&G.terminal), _("run as terminal")},
{"start-exp",NO_ARGS, NULL, 'X', arg_int, APTR(&G.takeimg), _("start exposition")},
#endif
// not daemon options
#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")},
{"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outpfname), _("output file name (default: output.tiff)")},
{"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
// not client options
#ifndef CLIENT
{"device", NEED_ARG, NULL, 'i', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_COMDEV ")")}, {"device", NEED_ARG, NULL, 'i', arg_string, APTR(&G.device), _("serial device name (default: " DEFAULT_COMDEV ")")},
{"heater-on",NO_ARGS, APTR(&G.heater),HEATER_ON, arg_none, NULL, _("turn heater on")}, {"heater-on",NO_ARGS, APTR(&G.heater),HEATER_ON, arg_none, NULL, _("turn heater on")},
{"heater-off",NO_ARGS, APTR(&G.heater),HEATER_OFF, arg_none, NULL, _("turn heater off")}, {"heater-off",NO_ARGS, APTR(&G.heater),HEATER_OFF, arg_none, NULL, _("turn heater off")},
@ -77,12 +88,14 @@ myoption cmdlnopts[] = {
{"subframe",NEED_ARG, NULL, 0, arg_string, APTR(&G.subframe), _("select subframe: x,y,size")}, {"subframe",NEED_ARG, NULL, 0, arg_string, APTR(&G.subframe), _("select subframe: x,y,size")},
{"exptime", NEED_ARG, NULL, 'x', arg_double, APTR(&G.exptime), _("exposition time in seconds (default: 1s)")}, {"exptime", NEED_ARG, NULL, 'x', arg_double, APTR(&G.exptime), _("exposition time in seconds (default: 1s)")},
{"binning", NEED_ARG, NULL, 'B', arg_int, APTR(&G.binning), _("binning (default 0: full size)")}, {"binning", NEED_ARG, NULL, 'B', arg_int, APTR(&G.binning), _("binning (default 0: full size)")},
{"start-exp",NO_ARGS, NULL, 'X', arg_int, APTR(&G.takeimg), _("start exposition")}, #endif
{"imtype", NEED_ARG, NULL, 'T', arg_string, APTR(&G.imtype), _("image type: light (l, L), autodark (a, A), dark (d, D); default: light")}, // not standalone options
{"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")}, #if defined DAEMON || defined CLIENT
{"output", NEED_ARG, NULL, 'o', arg_string, APTR(&G.outpfname), _("output file name (default: output.tiff)")}, #ifndef DAEMON
{"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")}, {"hostname",NEED_ARG, NULL, 'H', arg_string, APTR(&G.hostname), _("hostname to connect (default: localhost)")},
// simple integer parameter with obligatory arg: #endif
{"port", NEED_ARG, NULL, 'p', arg_string, APTR(&G.port), _("port to connect (default: 4444)")},
#endif
end_option end_option
}; };

View File

@ -30,7 +30,6 @@
* here are some typedef's for global data * here are some typedef's for global data
*/ */
typedef struct{ typedef struct{
int daemon; // to daemonize
int terminal; // run as terminal (send/receive) int terminal; // run as terminal (send/receive)
char *device; // serial device name char *device; // serial device name
int rest_pars_num; // number of rest parameters int rest_pars_num; // number of rest parameters
@ -47,12 +46,11 @@ typedef struct{
char *imstoretype; // "overwrite" (or "rewrite"), "normal" (or NULL), "enumerate" (or "numerate") char *imstoretype; // "overwrite" (or "rewrite"), "normal" (or NULL), "enumerate" (or "numerate")
char *outpfname; // output filename for image storing char *outpfname; // output filename for image storing
char *imformat; // output file format char *imformat; // output file format
char *hostname; // hostname to connect
char *port; // port to connect
char** rest_pars; // the rest parameters: array of char* char** rest_pars; // the rest parameters: array of char*
} glob_pars; } glob_pars;
// default & global parameters
extern int rewrite_ifexists, verbose;
glob_pars *parse_args(int argc, char **argv); glob_pars *parse_args(int argc, char **argv);
#endif // __CMDLNOPTS_H__ #endif // __CMDLNOPTS_H__

View File

@ -32,6 +32,8 @@
#include <libgen.h> // basename #include <libgen.h> // basename
#include <sys/stat.h> // utimensat #include <sys/stat.h> // utimensat
#include <fcntl.h> // AT_... #include <fcntl.h> // AT_...
double exp_calculated = -1.; // optimal exposition, calculated in histogram saver
/** /**
* All image-storing functions modify ctime of saved files to be the time of * All image-storing functions modify ctime of saved files to be the time of
* exposition start! * exposition start!
@ -144,7 +146,7 @@ imstorage *chk_storeimg(char *filename, char* store, char *format){
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(nm, suffixes[i], st)){ if(!make_filename(nm, suffixes[i], st)){
WARNX(_("Can't create output file")); WARNX(_("Can't create output file (is it exists?)"));
free(nm); free(nm);
return NULL; return NULL;
} }
@ -334,7 +336,7 @@ int writefits(imstorage *img){
return 0; return 0;
} }
#ifndef CLIENT
/** /**
* Receive image data & fill img->imdata * Receive image data & fill img->imdata
* @return imdata or NULL if failed * @return imdata or NULL if failed
@ -350,13 +352,14 @@ uint16_t *get_imdata(imstorage *img){
img->imdata = imdata; img->imdata = imdata;
return imdata; return imdata;
} }
#endif
/** /**
* save truncated to 256 levels histogram of `img` into file `f` * save truncated to 256 levels histogram of `img` into file `f`
* @return 0 if all OK * @return 0 if all OK
*/ */
int save_histo(FILE *f, imstorage *img){ int save_histo(FILE *f, imstorage *img){
if(!img->imdata) return 1000; if(!img || !img->imdata) return 1000;
size_t histogram[256]; size_t histogram[256];
size_t l, S = img->W*img->H; size_t l, S = img->W*img->H;
uint16_t *ptr = img->imdata; uint16_t *ptr = img->imdata;
@ -364,32 +367,42 @@ int save_histo(FILE *f, imstorage *img){
for(l = 0; l < S; ++l, ++ptr){ for(l = 0; l < S; ++l, ++ptr){
++histogram[((*ptr)>>8)&0xff]; ++histogram[((*ptr)>>8)&0xff];
} }
if(f){
for(l = 0; l < 256; ++l){ for(l = 0; l < 256; ++l){
int status = fprintf(f, "%zd\t%zd\n", l, histogram[l]); int status = fprintf(f, "%zd\t%zd\n", l, histogram[l]);
if(status < 0){ if(status < 0){
return status; return status;
} }
} }
}
size_t low2 = S/50, med = S/2, up2 = (S*49)/50, acc = 0; size_t low2 = S/50, med = S/2, up2 = (S*49)/50, acc = 0;
int lval = -1, mval = -1, tval = -1; int lval = -1, mval = -1, tval = -1;
for(l = 0; l < 256; ++l){ // get stat parameters for(l = 0; l < 256; ++l){ // get stat parameters
acc += histogram[l]; acc += histogram[l];
if(lval < 0 && acc >= low2) lval = l; if(lval < 0 && acc >= low2) lval = l;
else if(mval < 0 && acc >= med) mval = l; if(mval < 0 && acc >= med) mval = l;
else if(tval < 0 && acc >= up2) tval = l; if(tval < 0 && acc >= up2) tval = l;
} }
DBG("acc = %zd, S = %zd", acc, S);
printf("low 2%% (%zd pixels) = %d, median (%zd pixels) = %d, up 2%% (%zd pixels) = %d\n", printf("low 2%% (%zd pixels) = %d, median (%zd pixels) = %d, up 2%% (%zd pixels) = %d\n",
low2, lval, med, mval, up2, tval); low2, lval, med, mval, up2, tval);
double mul = 1., mulmax = 255. / tval; double mul = 1., mulmax = 255. / tval;
if(mval < 120 || mval > 134){ if(tval <= 252){ // no overexposed pixels
if(lval > 32) mul = 96. / mval; if(lval < 32){ // narrow histogram with overexposed black level
else if(mval < 127) mul = 120. / mval; mul = 252. / tval;
else if(mval < 196) mul = 120. / (mval - lval); }else mul = 32. / lval;
else if(mval < 245) mul = 96. / (tval - lval); }else{
else mval = 0.03; if(mval > 134){
if(mval < 245) mul = 64. / mval;
else mul = 0.1;
}
} }
if(mul > mulmax) mul = mulmax; if(mul > mulmax) mul = mulmax;
green("Recommended exposition time: %.2f seconds\n", img->exptime * mul); double E = img->exptime * mul;
if(E < 5e-5) E = 5e-5; // too short exposition
else if(E > 120.) E = 120.; // no need to do expositions larger than 2 minutes
green("Recommended exposition time: %g seconds\n", E);
exp_calculated = E;
return 0; return 0;
} }
@ -436,7 +449,11 @@ int writedump(imstorage *img){
*/ */
int store_image(imstorage *img){ int store_image(imstorage *img){
int status = 0; int status = 0;
if(!img->imdata && !get_imdata(img)) return 1; if((!img->imdata
#ifndef CLIENT
&& !get_imdata(img)
#endif
) || !img->W || !img->H) return 1;
print_stat(img); print_stat(img);
if(img->imformat & FORMAT_TIFF){ // save tiff file if(img->imformat & FORMAT_TIFF){ // save tiff file
if(writetiff(img)) status |= 1; if(writetiff(img)) status |= 1;

View File

@ -68,9 +68,14 @@ typedef struct{
time_t exposetime; // time of exposition start time_t exposetime; // time of exposition start
} imstorage; } imstorage;
extern double exp_calculated;
imstorage *chk_storeimg(char *filename, char* store, char *format); imstorage *chk_storeimg(char *filename, 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
uint16_t *get_imdata(imstorage *img); uint16_t *get_imdata(imstorage *img);
#endif
int save_histo(FILE *f, imstorage *img);
#endif // __IMFUNCTIONS_H__ #endif // __IMFUNCTIONS_H__

68
main.c
View File

@ -19,31 +19,44 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
#include "usefull_macros.h" #include "usefull_macros.h"
#include <sys/wait.h>
#include <sys/prctl.h>
#include <signal.h> #include <signal.h>
#ifndef EBUG
#include <sys/prctl.h>
#endif
#ifndef CLIENT
#include "term.h" #include "term.h"
#endif
#include "cmdlnopts.h" #include "cmdlnopts.h"
#include "imfunctions.h" #include "imfunctions.h"
#if defined CLIENT || defined DAEMON
#include "socket.h"
#endif
void signals(int signo){ void signals(int signo){
#ifndef CLIENT
abort_image(); abort_image();
restore_console(); restore_console();
restore_tty(); restore_tty();
#endif
exit(signo); exit(signo);
} }
int main(int argc, char **argv){ int main(int argc, char **argv){
initial_setup(); initial_setup();
for(int i = 0; i < 255; ++i) signal(i, signals); signal(SIGTERM, signals); // kill (-15) - quit
signal(SIGTSTP, SIG_IGN); // ctrl+Z - ignore signal(SIGHUP, SIG_IGN); // hup - ignore
signal(SIGQUIT, SIG_IGN); // ctrl+\ - ignore signal(SIGINT, signals); // ctrl+C - quit
signal(SIGQUIT, signals); // ctrl+\ - quit
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
glob_pars *G = parse_args(argc, argv); glob_pars *G = parse_args(argc, argv);
printf("sp: %d\n", G->splist);
imstorage *img = NULL;
imsubframe *F = NULL;
#ifndef CLIENT
if(G->splist) list_speeds(); if(G->splist) list_speeds();
if(G->daemon && G->terminal){
WARNX(_("Options --daemon and --terminal can't be together!"));
return 1;
}
if(!try_connect(G->device, G->speed)){ if(!try_connect(G->device, G->speed)){
WARNX(_("Check power and connection: device not answer!")); WARNX(_("Check power and connection: device not answer!"));
return 1; return 1;
@ -56,41 +69,60 @@ int main(int argc, char **argv){
WARNX(_("Can't send shutter command: %s"), G->shutter_cmd); WARNX(_("Can't send shutter command: %s"), G->shutter_cmd);
if(G->heater != HEATER_LEAVE) if(G->heater != HEATER_LEAVE)
heater(G->heater); // turn on/off heater heater(G->heater); // turn on/off heater
#if !defined DAEMON && !defined CLIENT
if(G->takeimg){ if(G->takeimg){
imsubframe *F = NULL; #endif
if(G->subframe){ if(G->subframe){
if(!(F = define_subframe(G->subframe))) if(!(F = define_subframe(G->subframe)))
ERRX(_("Error defining subframe")); ERRX(_("Error defining subframe"));
G->binning = 0xff; // take subframe G->binning = 0xff; // take subframe
} }
imstorage *img = chk_storeimg(G->outpfname, G->imstoretype, G->imformat); #endif // !CLIENT
#ifndef DAEMON
img = chk_storeimg(G->outpfname, G->imstoretype, G->imformat);
#else
img = MALLOC(imstorage, 1); // just allocate empty: all we need in daemon is exposition & binning
#endif
#ifndef CLIENT
if(img){ if(img){
DBG("OK"); DBG("OK");
img->subframe = F; img->subframe = F;
img->exptime = G->exptime; img->exptime = G->exptime;
img->binning = G->binning; img->binning = G->binning;
if(start_exposition(img, G->imtype)){
if(start_exposition(img, G->imtype)){ // start test exposition even in daemon
WARNX(_("Error starting exposition")); WARNX(_("Error starting exposition"));
}else{ }else{
if(!get_imdata(img)){ if(!get_imdata(img)){
WARNX(_("Error image transfer")); WARNX(_("Error image transfer"));
}else{ }else{
#ifndef DAEMON
if(store_image(img)) if(store_image(img))
WARNX(_("Error storing image")); WARNX(_("Error storing image"));
#endif // !DAEMON
} }
} }
}
#endif // !CLIENT
#if !defined DAEMON && !defined CLIENT
}
if(G->terminal){
red(_("All other commandline options rejected!\n"));
run_terminal(); // non-echo terminal mode
}
#endif // !defined DAEMON && !defined CLIENT
#if defined CLIENT || defined DAEMON
daemonize(img, G->hostname, G->port);
#endif
if(img){
FREE(img->imname); FREE(img->imname);
FREE(img->imdata); FREE(img->imdata);
FREE(img); FREE(img);
} }
FREE(F); FREE(F);
} #if !defined DAEMON && !defined CLIENT
if(G->daemon || G->terminal){
red(_("All other commandline options rejected!\n"));
if(G->terminal) run_terminal(); // non-echo terminal mode
if(G->daemon) daemonize();
}
if(!G->shutter_cmd){ // close shutter if there wasn't direct command to do something else if(!G->shutter_cmd){ // close shutter if there wasn't direct command to do something else
shutter_command("ck"); shutter_command("ck");
} }
#endif // !defined DAEMON && !defined CLIENT
} }

View File

@ -26,15 +26,20 @@ long_line_behaviour=1
long_line_column=100 long_line_column=100
[files] [files]
current_page=0 current_page=12
FILE_NAME_0=240;Make;0;EUTF-8;1;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2FMakefile;0;4 FILE_NAME_0=684;Make;0;EUTF-8;1;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2FMakefile;0;4
FILE_NAME_1=1333;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fmain.c;0;4 FILE_NAME_1=1058;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fmain.c;0;4
FILE_NAME_2=5126;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fterm.c;0;4 FILE_NAME_2=3665;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fcmdlnopts.c;0;4
FILE_NAME_3=0;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fterm.h;0;4 FILE_NAME_3=2158;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fcmdlnopts.h;0;4
FILE_NAME_4=0;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fcmdlnopts.c;0;4 FILE_NAME_4=2541;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fterm.c;0;4
FILE_NAME_5=0;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fcmdlnopts.h;0;4 FILE_NAME_5=3090;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fterm.h;0;4
FILE_NAME_6=1494;Make;0;EUTF-8;1;1;0;%2Fhome%2Feddy%2FDropbox%2FProjects%2Fstm32samples%2FF0-nolib%2Fblink%2FMakefile;0;4 FILE_NAME_6=2204;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fimfunctions.h;0;4
FILE_NAME_7=4569;C;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fusefull_macros.c;0;4 FILE_NAME_7=14598;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Fimfunctions.c;0;4
FILE_NAME_8=736;C++;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2Fdemosaic%2Fsrc%2Fio_tiff.cpp;0;4
FILE_NAME_9=959;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2Fdemosaic%2Fsrc%2Fio_tiff.h;0;4
FILE_NAME_10=4748;C++;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2Fdemosaic%2Fsrc%2FdemosaickingIpol.cpp;0;4
FILE_NAME_11=1322;C;0;EUTF-8;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2Ftestimages%2Finotify.c;0;4
FILE_NAME_12=67;Markdown;0;EKOI8-R;0;1;0;%2Fhome%2Feddy%2FDocs%2FSAO%2FCameras%2FSBIG%2Fallsky_340%2FSBIG_340%2FReadme.md;0;4
[VTE] [VTE]
last_dir=/home/eddy/Docs/SAO/Cameras/FLI_camera/my/Mytakepic last_dir=/home/eddy/Docs/SAO/Cameras/FLI_camera/my/Mytakepic

34
term.c
View File

@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
#ifndef CLIENT
#include "usefull_macros.h" #include "usefull_macros.h"
#include "term.h" #include "term.h"
#include <strings.h> // strncasecmp #include <strings.h> // strncasecmp
@ -96,7 +98,7 @@ trans_status wait_checksum(){
int r; int r;
double d0 = dtime(); double d0 = dtime();
do{ do{
if((r = read_tty(&chr, 1))) break; if((r = read_tty(&chr, 1)) && chr == last_chksum) break;
DBG("wait.."); DBG("wait..");
}while(dtime() - d0 < WAIT_TMOUT); }while(dtime() - d0 < WAIT_TMOUT);
if(dtime() - d0 >= WAIT_TMOUT) return TRANS_TIMEOUT; if(dtime() - d0 >= WAIT_TMOUT) return TRANS_TIMEOUT;
@ -208,6 +210,7 @@ int try_connect(char *device, int speed){
green(_("Connecting to %s... "), device); green(_("Connecting to %s... "), device);
for(curspd = spdstart; curspd < spdmax; ++curspd){ for(curspd = spdstart; curspd < spdmax; ++curspd){
tty_init(device, Bspeeds[curspd]); tty_init(device, Bspeeds[curspd]);
read_tty(tmpbuf, 4096); // clear rbuf
DBG("Try speed %d", speeds[curspd]); DBG("Try speed %d", speeds[curspd]);
int ctr; int ctr;
for(ctr = 0; ctr < 10; ++ctr){ // 10 tries to send data for(ctr = 0; ctr < 10; ++ctr){ // 10 tries to send data
@ -326,12 +329,6 @@ void run_terminal(){
} }
} }
/**
* Run as daemon
*/
void daemonize(){
}
void heater(heater_cmd cmd){ void heater(heater_cmd cmd){
if(cmd == HEATER_LEAVE) return; if(cmd == HEATER_LEAVE) return;
uint8_t buf[2] = {CMD_HEATER, 0}; uint8_t buf[2] = {CMD_HEATER, 0};
@ -477,11 +474,12 @@ int start_exposition(imstorage *im, char *imtype){
FNAME(); FNAME();
double exptime = im->exptime; double exptime = im->exptime;
uint64_t exp100us = exptime * 10000.; uint64_t exp100us = exptime * 10000.;
uint8_t cmd[6] = {CMD_TAKE_IMAGE}; static uint8_t cmd[6] = {CMD_TAKE_IMAGE}; // `static` to save all data after first call
int binning = im->binning; int binning = im->binning;
image_type it = IMTYPE_AUTODARK; image_type it = IMTYPE_AUTODARK;
const char *m = "autodark";
if(exptime < 5e-5){// 50us if(exptime < 5e-5){// 50us
WARNX(_("Exposition time should be not less than 1us")); WARNX(_("Exposition time should be not less than 50us"));
return 1; return 1;
} }
DBG("exp: %lu", exp100us); DBG("exp: %lu", exp100us);
@ -503,10 +501,9 @@ int start_exposition(imstorage *im, char *imtype){
}else b = "subframe"; }else b = "subframe";
cmd[4] = binning; cmd[4] = binning;
// and now check image type // and now check image type
if(!imtype) return 4; if(imtype){
int L = strlen(imtype); int L = strlen(imtype);
if(!L){ WARNX(_("Empty image type")); return 4;} if(!L){ WARNX(_("Empty image type")); return 4;}
const char *m = "autodark";
if(0 == strncasecmp(imtype, "autodark", L)){ if(0 == strncasecmp(imtype, "autodark", L)){
if(binning == 0){ if(binning == 0){
WARNX(_("Auto dark mode don't support full image")); WARNX(_("Auto dark mode don't support full image"));
@ -519,6 +516,11 @@ int start_exposition(imstorage *im, char *imtype){
WARNX(_("Wrong image type: %s, should be \"autodark\", \"light\" or \"dark\""), imtype); WARNX(_("Wrong image type: %s, should be \"autodark\", \"light\" or \"dark\""), imtype);
return 6; return 6;
} }
}else{
it = im->imtype;
if(it == IMTYPE_DARK) m = "dark";
else if(it == IMTYPE_LIGHT) m = "light";
}
if(it != IMTYPE_DARK){ if(it != IMTYPE_DARK){
if(shutter_command("ok")){ // open shutter if(shutter_command("ok")){ // open shutter
WARNX(_("Can't open shutter")); WARNX(_("Can't open shutter"));
@ -548,6 +550,7 @@ int start_exposition(imstorage *im, char *imtype){
break; break;
case 0xff: // subframe case 0xff: // subframe
W = H = im->subframe->size; W = H = im->subframe->size;
DBG("subfrsz: %d", im->subframe->size);
break; break;
case 0: // full image case 0: // full image
default: default:
@ -555,6 +558,7 @@ int start_exposition(imstorage *im, char *imtype){
H = IMHEIGHT; H = IMHEIGHT;
} }
im->W = W; im->H = H; im->W = W; im->H = H;
DBG("W=%zd, H=%zd\n", im->W, im->H);
im->exposetime = time(NULL); im->exposetime = time(NULL);
return 0; return 0;
} }
@ -608,7 +612,8 @@ int wait4image(){
*/ */
uint16_t *get_image(imstorage *img){ uint16_t *get_image(imstorage *img){
char *iptr = indi; char *iptr = indi;
size_t L = img->W * img->H, rest = L * 2; // rest is datasize in bytes size_t L = img->W * img->H, rest = L * sizeof(uint16_t); // rest is datasize in bytes
DBG("L = %zd, W=%zd, H=%zd", L, img->W, img->H);
uint16_t *buff = MALLOC(uint16_t, L); uint16_t *buff = MALLOC(uint16_t, L);
if(TRANS_SUCCEED != send_cmd_cs(CMD_XFER_IMAGE)){ if(TRANS_SUCCEED != send_cmd_cs(CMD_XFER_IMAGE)){
WARNX(_("Error sending transfer command")); WARNX(_("Error sending transfer command"));
@ -681,8 +686,8 @@ uint16_t *get_image(imstorage *img){
download_in_progress = 0; download_in_progress = 0;
return NULL; return NULL;
} }
//DBG("portion %d", ++i);
rest -= need - 1; rest -= need - 1;
//DBG("need: %zd", need);
bptr = ptr; bptr = ptr;
}while(rest); }while(rest);
printf("\b Done!\n"); printf("\b Done!\n");
@ -690,3 +695,6 @@ uint16_t *get_image(imstorage *img){
download_in_progress = 0; download_in_progress = 0;
return buff; return buff;
} }
#endif // CLIENT

1
term.h
View File

@ -80,7 +80,6 @@ typedef enum{
#define ANS_EXP_DONE 'D' #define ANS_EXP_DONE 'D'
void run_terminal(); void run_terminal();
void daemonize();
int open_serial(char *dev); int open_serial(char *dev);
int get_curspeed(); int get_curspeed();
int try_connect(char *device, int speed); int try_connect(char *device, int speed);