mirror of
https://github.com/eddyem/CCD_Capture.git
synced 2026-08-12 09:49:25 +03:00
some fixes (still have problems in client-server mode)
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <float.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#define TOUPCAM_HRESULT_ERRORCODE_NEEDED
|
||||
#include <toupcam.h>
|
||||
#include <usefull_macros.h>
|
||||
|
||||
@@ -62,6 +63,28 @@ static double exptime = 0., starttime = 0.;
|
||||
// return constant string with error code description
|
||||
static const char *errcode(int ecode){
|
||||
switch(ecode){
|
||||
#ifndef STR
|
||||
#define STR(par) # par
|
||||
#endif
|
||||
#define ECASE(code) case code: return STR(code)
|
||||
ECASE(S_OK);
|
||||
ECASE(S_FALSE);
|
||||
ECASE(E_UNEXPECTED);
|
||||
ECASE(E_NOTIMPL);
|
||||
ECASE(E_NOINTERFACE);
|
||||
ECASE(E_ACCESSDENIED);
|
||||
ECASE(E_OUTOFMEMORY);
|
||||
ECASE(E_INVALIDARG);
|
||||
ECASE(E_POINTER);
|
||||
ECASE(E_FAIL);
|
||||
ECASE(E_WRONG_THREAD);
|
||||
ECASE(E_GEN_FAILURE);
|
||||
ECASE(E_BUSY);
|
||||
ECASE(E_PENDING);
|
||||
ECASE(E_TIMEOUT);
|
||||
ECASE(E_UNREACH);
|
||||
#undef ECASE
|
||||
#if 0
|
||||
case 0: return "S_OK";
|
||||
case 1: return "S_FALSE";
|
||||
case 0x8000ffff: return "E_UNEXPECTED";
|
||||
@@ -78,6 +101,7 @@ static const char *errcode(int ecode){
|
||||
case 0x8000000a: return "E_PENDING";
|
||||
case 0x8001011f: return "E_TIMEOUT";
|
||||
case 0x80072743: return "E_UNREACH";
|
||||
#endif
|
||||
default: return "Unknown error";
|
||||
}
|
||||
}
|
||||
@@ -88,7 +112,7 @@ static const char *errcode(int ecode){
|
||||
static void camcancel(){
|
||||
if(!toupcam.hcam) return;
|
||||
int e = Toupcam_Trigger(toupcam.hcam, 0); // stop triggering
|
||||
if(e < 0) WARNX("Can't trigger 0: %s", errcode(e));
|
||||
if(e < 0 && e != E_UNEXPECTED) WARNX(_("Can't stop image triggering: %s"), errcode(e));
|
||||
e = Toupcam_Stop(toupcam.hcam);
|
||||
if(e < 0) WARNX("Can't stop: %s", errcode(e));
|
||||
toupcam.state = IM_SLEEP;
|
||||
@@ -371,7 +395,7 @@ static int camgetbrig(float *b){
|
||||
if(Toupcam_get_Brightness(toupcam.hcam, &br) < 0) return FALSE;
|
||||
DBG("brightness=%d", br);
|
||||
if(b) *b = (float) br;
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -472,7 +496,7 @@ static int camgettc(float *t){
|
||||
* @return FALSE if failed or no such property
|
||||
*/
|
||||
static int camgetth(float _U_ *t){
|
||||
TCHECK();
|
||||
//TCHECK();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -482,7 +506,7 @@ static int camgetth(float _U_ *t){
|
||||
* @return FALSE if failed or no such property
|
||||
*/
|
||||
static int gettb(float _U_ *t){
|
||||
TCHECK();
|
||||
//TCHECK();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -548,6 +572,8 @@ static int camshutter(cc_shutter_op s){
|
||||
*/
|
||||
static int camsetgeom(cc_frameformat *f){
|
||||
TCHECK();
|
||||
if(!f) return FALSE;
|
||||
// WARNX("Your ROI is: off - %dx%d, frame - %dx%d", f->xoff, f->yoff, f->w, f->h);
|
||||
if(Toupcam_put_Roi(toupcam.hcam, (unsigned) f->xoff, (unsigned) f->yoff, (unsigned) f->w, (unsigned) f->h) < 0) return FALSE;
|
||||
camera.geometry = *f;
|
||||
return TRUE;
|
||||
@@ -561,10 +587,10 @@ static int camsetgeom(cc_frameformat *f){
|
||||
*/
|
||||
static int camgetnam(char *n, int l){
|
||||
TCHECK();
|
||||
if(!toupcam.dev) return FALSE;
|
||||
if(!toupcam.dev || !n || l < 1) return FALSE;
|
||||
DBG("name: %s, strncpy to %d buf", toupcam.dev->displayname, l);
|
||||
strncpy(n, toupcam.dev->displayname, l);
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,8 +602,8 @@ static int camgmg(float *mg){
|
||||
TCHECK();
|
||||
unsigned short gmin, gmax, gdef;
|
||||
if(Toupcam_get_ExpoAGainRange(toupcam.hcam, &gmin, &gmax, &gdef) < 0) return FALSE;
|
||||
if(mg) *mg = gmax;
|
||||
return FALSE;
|
||||
if(mg) *mg = (float)gmax / 100.f;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,7 +616,7 @@ static int camggl(cc_frameformat *max, cc_frameformat _U_ *step){
|
||||
TCHECK();
|
||||
if(max) *max = camera.array;
|
||||
if(step) *step = (cc_frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1};
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
27
ccdcapture.c
27
ccdcapture.c
@@ -69,6 +69,7 @@ int cc_lock_shm(int isserver){
|
||||
if(locked){
|
||||
double t0 = sl_dtime();
|
||||
while(sem_trywait(sem) && sl_dtime() - t0 < 0.1) sem_post(sem); // force locking
|
||||
if(sl_dtime() - t0 >= 0.1) return FALSE; // can't lock - timeout
|
||||
}
|
||||
}else{
|
||||
if(sem_timedwait(sem, &ts)){
|
||||
@@ -90,7 +91,7 @@ void cc_unlock_shm(){
|
||||
case EOVERFLOW: // already unlocked
|
||||
break;
|
||||
default: // not a valid? or other?
|
||||
WARN("Can't unlock image semaphore");
|
||||
WARN(_("Can't unlock image semaphore"));
|
||||
LOGERR("Can't unlock image semaphore");
|
||||
return;
|
||||
}
|
||||
@@ -147,20 +148,23 @@ int cc_open_socket(int isserver, char *path, int isnet){
|
||||
}else{
|
||||
DBG("UNIX socket");
|
||||
char apath[128];
|
||||
int len = sizeof(sa_family_t);
|
||||
if(*path == 0){
|
||||
DBG("convert name");
|
||||
apath[0] = 0;
|
||||
strncpy(apath+1, path+1, 126);
|
||||
len += strlen(path+1);
|
||||
}else if(strncmp("\\0", path, 2) == 0){
|
||||
DBG("convert name");
|
||||
apath[0] = 0;
|
||||
strncpy(apath+1, path+2, 126);
|
||||
len += strlen(path+2);
|
||||
}else strcpy(apath, path);
|
||||
//unlink(apath);
|
||||
unaddr.sun_family = AF_UNIX;
|
||||
hints.ai_addr = (struct sockaddr*) &unaddr;
|
||||
hints.ai_addrlen = sizeof(unaddr);
|
||||
memcpy(unaddr.sun_path, apath, 106); // if sun_path[0] == 0 we don't create a file
|
||||
memcpy(unaddr.sun_path, apath, len); // if sun_path[0] == 0 we don't create a file
|
||||
hints.ai_family = AF_UNIX;
|
||||
hints.ai_socktype = SOCK_SEQPACKET;
|
||||
res = &hints;
|
||||
@@ -238,7 +242,8 @@ int cc_sendmessage(int fd, const char *msg, int l){
|
||||
buflen = 1024 * (1 + l/1024);
|
||||
char *newbuf = realloc(tmpbuf, buflen);
|
||||
if(!newbuf){
|
||||
LOGERR("realloc())");
|
||||
WARN("realloc()");
|
||||
LOGERR("realloc()");
|
||||
return FALSE;
|
||||
}
|
||||
tmpbuf = newbuf;
|
||||
@@ -335,7 +340,7 @@ cc_IMG *cc_getshm(key_t key, size_t imsize){
|
||||
int flags = (imsize) ? IPC_CREAT | 0666 : 0;
|
||||
shmid = shmget(key, 0, flags);
|
||||
if(shmid < 0 && imsize == 0){ // no SHM segment for client
|
||||
WARN("Can't get shared memory segment %d", key);
|
||||
WARN(_("Can't get shared memory segment %d"), key);
|
||||
return NULL;
|
||||
}
|
||||
if(imsize){ // check if segment exists and its size equal to needs
|
||||
@@ -346,25 +351,25 @@ cc_IMG *cc_getshm(key_t key, size_t imsize){
|
||||
}
|
||||
shmid = shmget(key, shmsize, flags);
|
||||
if(shmid < 0){
|
||||
WARN("Can't create shared memory segment %d", key);
|
||||
WARN(_("Can't create shared memory segment %d"), key);
|
||||
return NULL;
|
||||
}
|
||||
}else{
|
||||
#ifdef EBUG
|
||||
struct shmid_ds buf;
|
||||
if(shmctl(shmid, IPC_STAT, &buf)) WARNX("Can't get SHM data");
|
||||
if(shmctl(shmid, IPC_STAT, &buf)) WARNX(_("Can't get SHM data"));
|
||||
else DBG("SHM size = %zd", buf.shm_segsz);
|
||||
#endif
|
||||
}
|
||||
flags = (imsize) ? 0 : SHM_RDONLY; // client opens memory in readonly mode
|
||||
cc_IMG *ptr = shmat(shmid, NULL, 0);
|
||||
if(ptr == (void*)-1){
|
||||
if(imsize) WARN("Can't attach SHM segment %d", key);
|
||||
if(imsize) WARN(_("Can't attach SHM segment %d"), key);
|
||||
return NULL;
|
||||
}
|
||||
if(!imsize){
|
||||
if(ptr->MAGICK != CC_SHM_MAGIC){
|
||||
WARNX("Shared memory %d isn't belongs to image server", key);
|
||||
WARNX(_("Shared memory %d isn't belongs to image server"), key);
|
||||
shmdt(ptr);
|
||||
return NULL;
|
||||
}
|
||||
@@ -446,7 +451,7 @@ int cc_getNbytes(cc_IMG *image){
|
||||
*/
|
||||
cc_strbuff *cc_strbufnew(size_t bufsize, size_t stringsize){
|
||||
if(bufsize < 8 || stringsize < 8){
|
||||
WARNX("Need to allocate at least 8 bytes in buffers");
|
||||
WARNX(_("Need to allocate at least 8 bytes in buffers"));
|
||||
return NULL;
|
||||
}
|
||||
DBG("Allocate new string buffer with size %zd and string size %zd", bufsize, stringsize);
|
||||
@@ -629,7 +634,7 @@ static cc_hresult ask4cmd(int fd, cc_strbuff *buf, const char *cmdwargs){
|
||||
if(r == 0) continue;
|
||||
else if(r < 0){
|
||||
LOGERR("Socket disconnected");
|
||||
WARNX("Socket disconnected");
|
||||
WARNX(_("Socket disconnected"));
|
||||
ret = CC_RESULT_DISCONNECTED;
|
||||
goto rtn;
|
||||
}
|
||||
@@ -753,7 +758,7 @@ size_t cc_kwfromfile(cc_IMG *img, char *filename){
|
||||
if(!img) return 0;
|
||||
sl_mmapbuf_t *buf = sl_mmap(filename);
|
||||
if(!buf || buf->len < 1){
|
||||
WARNX("Can't add FITS records from file %s", filename);
|
||||
WARNX(_("Can't add FITS records from file %s"), filename);
|
||||
LOGWARN("Can't add FITS records from file %s", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
185
ccdfunc.c
185
ccdfunc.c
@@ -106,14 +106,16 @@ do{ int status = 0, kt = 0; \
|
||||
FORMKW("ORIGIN = 'SAO RAS' / Organization responsible for the data");
|
||||
FORMKW("OBSERVAT = 'Special Astrophysical Observatory, Russia' / Observatory name");
|
||||
FORMKW("INSTRUME = 'direct imaging' / Instrument");
|
||||
snprintf(templ, FLEN_CARD, "VIEWFLD = '(%d, %d)(%d, %d)' / Camera maximal field of view", camera->field.xoff, camera->field.yoff,
|
||||
camera->field.xoff + camera->field.w, camera->field.yoff + camera->field.h);
|
||||
FORMKW(templ);
|
||||
snprintf(templ, FLEN_CARD, "ARRAYFLD = '(%d, %d)(%d, %d)' / Camera full array size (with overscans)", camera->array.xoff, camera->array.yoff,
|
||||
camera->array.xoff + camera->array.w, camera->array.yoff + camera->array.h);
|
||||
FORMKW(templ);
|
||||
snprintf(templ, FLEN_CARD, "GEOMETRY = '(%d, %d)(%d, %d)' / Camera current frame geometry", camera->geometry.xoff, camera->geometry.yoff,
|
||||
camera->geometry.xoff + camera->geometry.w, camera->geometry.yoff + camera->geometry.h);
|
||||
if(camera){
|
||||
snprintf(templ, FLEN_CARD, "VIEWFLD = '(%d, %d)(%d, %d)' / Camera maximal field of view", camera->field.xoff, camera->field.yoff,
|
||||
camera->field.xoff + camera->field.w, camera->field.yoff + camera->field.h);
|
||||
FORMKW(templ);
|
||||
snprintf(templ, FLEN_CARD, "ARRAYFLD = '(%d, %d)(%d, %d)' / Camera full array size (with overscans)", camera->array.xoff, camera->array.yoff,
|
||||
camera->array.xoff + camera->array.w, camera->array.yoff + camera->array.h);
|
||||
FORMKW(templ);
|
||||
snprintf(templ, FLEN_CARD, "GEOMETRY = '(%d, %d)(%d, %d)' / Camera current frame geometry", camera->geometry.xoff, camera->geometry.yoff,
|
||||
camera->geometry.xoff + camera->geometry.w, camera->geometry.yoff + camera->geometry.h);
|
||||
}
|
||||
FORMKW(templ);
|
||||
if(GP->X0 > -1) FORMINT("X0", GP->X0, "Subframe left border without binning");
|
||||
if(GP->Y0 > -1) FORMINT("Y0", GP->Y0, "Subframe upper border without binning");
|
||||
@@ -127,17 +129,19 @@ do{ int status = 0, kt = 0; \
|
||||
FORMINT("STATMAX", img->max, "Max data value");
|
||||
FORMFLT("STATAVR", img->avr, "Average data value");
|
||||
FORMFLT("STATSTD", img->std, "Std. of data value");
|
||||
if(camera->getTcold && camera->getTcold(&tmpf))
|
||||
FORMFLT("CAMTEMP", tmpf, "Camera temperature at exp. end, degr C");
|
||||
if(camera->getTbody && camera->getTbody(&tmpf))
|
||||
FORMFLT("BODYTEMP", tmpf, "Camera body temperature at exp. end, degr C");
|
||||
if(camera->getThot && camera->getThot(&tmpf))
|
||||
FORMFLT("HOTTEMP", tmpf, "Camera peltier hot side temperature at exp. end, degr C");
|
||||
FORMFLT( "EXPTIME", GP->exptime, "Actual exposition time (sec)");
|
||||
if(camera->getgain && camera->getgain(&tmpf))
|
||||
FORMFLT("CAMGAIN", tmpf, "CMOS gain value");
|
||||
if(camera->getbrightness && camera->getbrightness(&tmpf))
|
||||
FORMFLT("CAMBRIGH", tmpf, "CMOS brightness value");
|
||||
if(camera){
|
||||
if(camera->getTcold && camera->getTcold(&tmpf))
|
||||
FORMFLT("CAMTEMP", tmpf, "Camera temperature at exp. end, degr C");
|
||||
if(camera->getTbody && camera->getTbody(&tmpf))
|
||||
FORMFLT("BODYTEMP", tmpf, "Camera body temperature at exp. end, degr C");
|
||||
if(camera->getThot && camera->getThot(&tmpf))
|
||||
FORMFLT("HOTTEMP", tmpf, "Camera peltier hot side temperature at exp. end, degr C");
|
||||
FORMFLT( "EXPTIME", GP->exptime, "Actual exposition time (sec)");
|
||||
if(camera->getgain && camera->getgain(&tmpf))
|
||||
FORMFLT("CAMGAIN", tmpf, "CMOS gain value");
|
||||
if(camera->getbrightness && camera->getbrightness(&tmpf))
|
||||
FORMFLT("CAMBRIGH", tmpf, "CMOS brightness value");
|
||||
}
|
||||
|
||||
snprintf(templ, 2*FLEN_CARD, "TIMESTAM = %.6f / Time of acquisition end (UNIX)", img->timestamp);
|
||||
FORMKW(templ);
|
||||
@@ -181,7 +185,7 @@ do{ int status = 0, kt = 0; \
|
||||
if(GP->prog_id) FORMSTR("PROG-ID", GP->prog_id, "Observation program identifier");
|
||||
if(GP->author) FORMSTR("AUTHOR", GP->author, "Author of the program");
|
||||
if(GP->objname) FORMSTR("OBJECT", GP->objname, "Object name");
|
||||
if(camera->getModelName && camera->getModelName(bufc, FLEN_CARD))
|
||||
if(camera && camera->getModelName && camera->getModelName(bufc, FLEN_CARD))
|
||||
FORMSTR("DETECTOR", bufc, "Detector model");
|
||||
if(GP->instrument) FORMSTR("INSTRUME", GP->instrument, "Instrument");
|
||||
return img->headerstrings;
|
||||
@@ -195,7 +199,7 @@ int saveFITS(cc_IMG *img, char **outp){
|
||||
char fnam[PATH_MAX+1];
|
||||
if(!GP->outfile && !GP->outfileprefix){
|
||||
LOGWARN("Image not saved: neither filename nor filename prefix pointed");
|
||||
WARNX("Image not saved: neither filename nor filename prefix pointed");
|
||||
WARNX(_("Image not saved: neither filename nor filename prefix pointed"));
|
||||
return FALSE;
|
||||
}
|
||||
if(GP->outfile){ // pointed specific output file name like "file.fits", check it
|
||||
@@ -206,7 +210,7 @@ int saveFITS(cc_IMG *img, char **outp){
|
||||
}else{ // exists
|
||||
if(!GP->rewrite){
|
||||
LOGERR("Can't save image: file %s exists", GP->outfile);
|
||||
WARNX("File %s exists!", GP->outfile);
|
||||
WARNX(_("File %s exists!"), GP->outfile);
|
||||
return FALSE;
|
||||
}
|
||||
snprintf(fnam, PATH_MAX, "!%s", GP->outfile);
|
||||
@@ -273,7 +277,7 @@ fits_write_history(fp, bufhdr->buf, &s);
|
||||
cloerr:
|
||||
if(fitserror == 0){
|
||||
LOGMSG("Save file '%s'", fnam);
|
||||
verbose(1, _("File saved as '%s'"), fnam);
|
||||
verbose(VERBOSE_PRIMARY, _("File saved as '%s'"), fnam);
|
||||
DBG("file %s saved", fnam);
|
||||
if(outp){
|
||||
FREE(*outp);
|
||||
@@ -346,14 +350,14 @@ void calculate_stat(cc_IMG *image){
|
||||
|
||||
cc_Focuser *startFocuser(){
|
||||
if(!GP->focuserdev && !GP->commondev){
|
||||
verbose(3, _("Focuser device not pointed"));
|
||||
verbose(VERBOSE_MESG, _("Focuser device not pointed"));
|
||||
return NULL;
|
||||
}else{
|
||||
char *plugin = GP->commondev ? GP->commondev : GP->focuserdev;
|
||||
if(!(focuser = open_focuser(plugin))) return NULL;
|
||||
}
|
||||
if(!focuser->check()){
|
||||
verbose(3, _("No focusers found"));
|
||||
verbose(VERBOSE_MESG, _("No focusers found"));
|
||||
focuser = NULL;
|
||||
return NULL;
|
||||
}
|
||||
@@ -377,7 +381,7 @@ void focusers(){
|
||||
if(!focuser->setDevNo(i)) continue;
|
||||
char modname[256];
|
||||
focuser->getModelName(modname, 255);
|
||||
printf("Found focuser #%d: %s\n", i, modname);
|
||||
verbose(VERBOSE_PRIMARY, _("Found focuser #%d: %s\n"), i, modname);
|
||||
}
|
||||
}
|
||||
int num = GP->focdevno;
|
||||
@@ -392,11 +396,11 @@ void focusers(){
|
||||
}
|
||||
char buf[BUFSIZ];
|
||||
if(focuser->getModelName(buf, BUFSIZ)){
|
||||
verbose(2, "Focuser model: %s", buf);
|
||||
verbose(VERBOSE_SECONDARY, "Focuser model: %s", buf);
|
||||
}
|
||||
float t;
|
||||
if(focuser->getTbody(&t)){
|
||||
verbose(1, "FOCTEMP=%.1f", t);
|
||||
verbose(VERBOSE_PRIMARY, "FOCTEMP=%.1f", t);
|
||||
DBG("FOCTEMP=%.1f", t);
|
||||
}
|
||||
float minpos, maxpos, curpos;
|
||||
@@ -404,14 +408,14 @@ void focusers(){
|
||||
WARNX(_("Can't get focuser limit positions"));
|
||||
goto retn;
|
||||
}
|
||||
verbose(1, "FOCMINPOS=%g", minpos);
|
||||
verbose(1, "FOCMAXPOS=%g", maxpos);
|
||||
verbose(VERBOSE_PRIMARY, "FOCMINPOS=%g", minpos);
|
||||
verbose(VERBOSE_PRIMARY, "FOCMAXPOS=%g", maxpos);
|
||||
DBG("FOCMINPOS=%g, FOCMAXPOS=%g", minpos, maxpos);
|
||||
if(!focuser->getPos(&curpos)){
|
||||
WARNX(_("Can't get current focuser position"));
|
||||
goto retn;
|
||||
}
|
||||
verbose(1, "FOCPOS=%g", curpos);
|
||||
verbose(VERBOSE_PRIMARY, "FOCPOS=%g", curpos);
|
||||
DBG("Curpos = %g", curpos);
|
||||
if(isnan(GP->gotopos) && isnan(GP->addsteps)) goto retn; // no focuser commands
|
||||
float tagpos = 0.;
|
||||
@@ -436,14 +440,14 @@ retn:
|
||||
|
||||
cc_Wheel *startWheel(){
|
||||
if(!GP->wheeldev && !GP->commondev){
|
||||
verbose(3, _("Wheel device not pointed"));
|
||||
verbose(VERBOSE_MESG, _("Wheel device not pointed"));
|
||||
return NULL;
|
||||
}else{
|
||||
char *plugin = GP->commondev ? GP->commondev : GP->wheeldev;
|
||||
if(!(wheel = open_wheel(plugin))) return NULL;
|
||||
}
|
||||
if(!wheel->check()){
|
||||
verbose(3, _("No wheels found"));
|
||||
verbose(VERBOSE_MESG, _("No wheels found"));
|
||||
wheel = NULL;
|
||||
return NULL;
|
||||
}
|
||||
@@ -467,7 +471,7 @@ void wheels(){
|
||||
if(!wheel->setDevNo(i)) continue;
|
||||
char modname[256];
|
||||
wheel->getModelName(modname, 255);
|
||||
printf("Found wheel #%d: %s\n", i, modname);
|
||||
verbose(VERBOSE_PRIMARY, _("Found wheel #%d: %s\n"), i, modname);
|
||||
}
|
||||
}
|
||||
int num = GP->whldevno;
|
||||
@@ -482,21 +486,21 @@ void wheels(){
|
||||
}
|
||||
char buf[BUFSIZ];
|
||||
if(wheel->getModelName(buf, BUFSIZ)){
|
||||
verbose(2, "cc_Wheel model: %s", buf);
|
||||
verbose(VERBOSE_SECONDARY, _("Wheel model: %s"), buf);
|
||||
}
|
||||
float t;
|
||||
if(wheel->getTbody(&t)){
|
||||
verbose(1, "WHEELTEMP=%.1f", t);
|
||||
verbose(VERBOSE_PRIMARY, "WHEELTEMP=%.1f", t);
|
||||
}
|
||||
int pos, maxpos;
|
||||
if(wheel->getPos(&pos)){
|
||||
verbose(1, "WHEELPOS=%d", pos);
|
||||
}else WARNX("Can't get current wheel position");
|
||||
verbose(VERBOSE_PRIMARY, "WHEELPOS=%d", pos);
|
||||
}else WARNX(_("Can't get current wheel position"));
|
||||
if(!wheel->getMaxPos(&maxpos)){
|
||||
WARNX(_("Can't get max wheel position"));
|
||||
goto retn;
|
||||
}
|
||||
verbose(1, "WHEELMAXPOS=%d", maxpos);
|
||||
verbose(VERBOSE_PRIMARY, "WHEELMAXPOS=%d", maxpos);
|
||||
pos = GP->setwheel;
|
||||
if(pos == -1) goto retn; // no wheel commands
|
||||
if(pos < 0 || pos > maxpos){
|
||||
@@ -518,16 +522,16 @@ static void closeall(){
|
||||
static cc_capture_status capt(){
|
||||
cc_capture_status cs;
|
||||
float tremain, tmpf;
|
||||
if(!camera->pollcapture){
|
||||
if(!camera || !camera->pollcapture){
|
||||
WARNX(_("Camera plugin have no capture polling funtion."));
|
||||
return CAPTURE_ABORTED;
|
||||
}
|
||||
while(camera->pollcapture(&cs, &tremain)){
|
||||
if(cs != CAPTURE_PROCESS) break;
|
||||
if(tremain > 0.1){
|
||||
verbose(2, _("%.1f seconds till exposition ends"), tremain);
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(1, "CCDTEMP=%.1f", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(1, "BODYTEMP=%.1f", tmpf);
|
||||
verbose(VERBOSE_SECONDARY, _("%.1f seconds till exposition ends"), tremain);
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(VERBOSE_PRIMARY, "CCDTEMP=%.1f", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(VERBOSE_PRIMARY, "BODYTEMP=%.1f", tmpf);
|
||||
}
|
||||
if(tremain > 6.) sleep(5);
|
||||
else if(tremain > 0.999999) sleep((int)(tremain+1e-6));
|
||||
@@ -540,7 +544,7 @@ static cc_capture_status capt(){
|
||||
|
||||
cc_Camera *startCCD(){
|
||||
if(!GP->cameradev && !GP->commondev){
|
||||
verbose(3, _("Camera device not pointed"));
|
||||
verbose(VERBOSE_MESG, _("Camera device not pointed"));
|
||||
return NULL;
|
||||
}else{
|
||||
char *plugin = GP->commondev ? GP->commondev : GP->cameradev;
|
||||
@@ -573,7 +577,7 @@ int prepare_ccds(){
|
||||
if(camera->setDevNo && !camera->setDevNo(i)) continue;
|
||||
// if camera have no setDevNo function, it could have getModelName
|
||||
camera->getModelName(buf, BUFSIZ-1);
|
||||
printf("Found camera #%d: %s\n", i, buf);
|
||||
verbose(VERBOSE_PRIMARY, _("Found camera #%d: %s\n"), i, buf);
|
||||
}
|
||||
}
|
||||
int num = GP->camdevno;
|
||||
@@ -598,12 +602,12 @@ int prepare_ccds(){
|
||||
DBG("got %s", *p);
|
||||
cc_charbufclr(b);
|
||||
cc_hresult r = camera->plugincmd(*p, b);
|
||||
if(r == CC_RESULT_OK || r == CC_RESULT_SILENCE) green("Command '%s'", *p);
|
||||
if(r == CC_RESULT_OK || r == CC_RESULT_SILENCE) green(_("Command '%s'"), *p);
|
||||
else{
|
||||
stop = TRUE;
|
||||
red("Command '%s'", *p);
|
||||
red(_("Command '%s'"), *p);
|
||||
}
|
||||
if(r != CC_RESULT_SILENCE) printf(" returns \"%s\"", cc_hresult2str(r));
|
||||
if(r != CC_RESULT_SILENCE) printf(_(" returns \"%s\""), cc_hresult2str(r));
|
||||
if(b->buflen) printf("\n%s", b->buf);
|
||||
else printf("\n");
|
||||
++p;
|
||||
@@ -621,43 +625,60 @@ int prepare_ccds(){
|
||||
else verbose(0, _("Set fan speed to %d"), GP->fanspeed);
|
||||
}
|
||||
}
|
||||
int x0,x1, y0,y1;
|
||||
int x0,x1, y0,y1; // will be inited here and used later
|
||||
if(camera->getModelName && camera->getModelName(buf, BUFSIZ))
|
||||
verbose(2, _("Camera model: %s"), buf);
|
||||
verbose(2, _("Pixel size: %g x %g"), camera->pixX, camera->pixY);
|
||||
verbose(VERBOSE_SECONDARY, _("Camera model: %s"), buf);
|
||||
verbose(VERBOSE_SECONDARY, _("Pixel size: %g x %g"), camera->pixX, camera->pixY);
|
||||
x0 = camera->array.xoff;
|
||||
y0 = camera->array.yoff;
|
||||
x1 = camera->array.xoff + camera->array.w;
|
||||
y1 = camera->array.yoff + camera->array.h;
|
||||
snprintf(buf, BUFSIZ, "(%d, %d)(%d, %d)", x0, y0, x1, y1);
|
||||
verbose(2, _("Full array: %s"), buf);
|
||||
verbose(VERBOSE_SECONDARY, _("Full array: %s"), buf);
|
||||
snprintf(buf, BUFSIZ, "(%d, %d)(%d, %d)", camera->field.xoff, camera->field.yoff,
|
||||
camera->field.xoff + camera->field.w, camera->field.yoff + camera->field.h);
|
||||
verbose(2, _("Field of view: %s"), buf);
|
||||
verbose(VERBOSE_SECONDARY, _("Field of view: %s"), buf);
|
||||
snprintf(buf, BUFSIZ, "(%d, %d)(%d, %d)", camera->geometry.xoff, camera->geometry.yoff,
|
||||
camera->geometry.xoff + camera->geometry.w, camera->geometry.yoff + camera->geometry.h);
|
||||
verbose(2, _("Current format: %s"), buf);
|
||||
verbose(VERBOSE_SECONDARY, _("Current format: %s"), buf);
|
||||
cc_frameformat max, step;
|
||||
if(camera->getgeomlimits && camera->getgeomlimits(&max, &step)){
|
||||
verbose(VERBOSE_SECONDARY, _("Maximal geometry (WxH): %dx%d"), max.w, max.h);
|
||||
verbose(VERBOSE_SECONDARY, _("Minimal offset: %dx%d"), max.xoff, max.yoff);
|
||||
verbose(VERBOSE_SECONDARY, _("Geometry steps: offset - %dx%d, size - %dx%d"), step.xoff, step.yoff, step.w, step.h);
|
||||
}
|
||||
int tmpi, tmpi1;
|
||||
if(camera->getbin && camera->getbin(&tmpi, &tmpi1))
|
||||
verbose(VERBOSE_SECONDARY, _("Current binning: %d x %d"), tmpi, tmpi1);
|
||||
uint8_t u8;
|
||||
if(camera->getbitpix && camera->getbitpix(&u8))
|
||||
verbose(VERBOSE_SECONDARY, _("Current settings: %d bits per pixel"), u8);
|
||||
float tmpf;
|
||||
if(camera->getbrightness && camera->getbrightness(&tmpf))
|
||||
verbose(VERBOSE_SECONDARY, _("Current brightness: %g"), tmpf);
|
||||
if(camera->getgain && camera->getgain(&tmpf))
|
||||
verbose(VERBOSE_SECONDARY, _("Current gain: %g"), &tmpf);
|
||||
if(camera->getmaxgain && camera->getmaxgain(&tmpf))
|
||||
verbose(VERBOSE_SECONDARY, _("Maximal gain: %g"), tmpf);
|
||||
if(!isnan(GP->temperature)){
|
||||
if(!camera->setT)WARNX(_("Camera plugin have no temperature setter"));
|
||||
else{if(!camera->setT((float)GP->temperature)) WARNX(_("Can't set T to %g degC"), GP->temperature);
|
||||
else verbose(3, "SetT=%.1f", GP->temperature);
|
||||
else verbose(VERBOSE_MESG, "SetT=%.1f", GP->temperature);
|
||||
}
|
||||
}
|
||||
float tmpf;
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(1, "CCDTEMP=%.1f", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(1, "BODYTEMP=%.1f", tmpf);
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(VERBOSE_PRIMARY, "CCDTEMP=%.1f", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(VERBOSE_PRIMARY, "BODYTEMP=%.1f", tmpf);
|
||||
if(GP->shtr_cmd > -1 && GP->shtr_cmd < SHUTTER_AMOUNT){
|
||||
const char *str[] = {"open", "close", "expose @high", "expose @low"};
|
||||
verbose(1, _("Shutter command: %s\n"), str[GP->shtr_cmd]);
|
||||
verbose(VERBOSE_PRIMARY, _("Shutter command: %s\n"), str[GP->shtr_cmd]);
|
||||
if(!camera->shuttercmd || !camera->shuttercmd((cc_shutter_op)GP->shtr_cmd))
|
||||
WARNX(_("Can't run shutter command %s (unsupported?)"), str[GP->shtr_cmd]);
|
||||
}
|
||||
if(GP->confio > -1){
|
||||
verbose(1, _("Try to configure I/O port as %d"), GP->confio);
|
||||
verbose(VERBOSE_PRIMARY, _("Try to configure I/O port as %d"), GP->confio);
|
||||
if(!camera->confio || !camera->confio(GP->confio))
|
||||
WARNX(_("Can't configure (unsupported?)"));
|
||||
}
|
||||
int tmpi;
|
||||
if(GP->getio){
|
||||
if(camera->getio && camera->getio(&tmpi))
|
||||
verbose(0, "CCDIOPORT=0x%02X\n", tmpi);
|
||||
@@ -665,22 +686,22 @@ int prepare_ccds(){
|
||||
WARNX(_("Can't get IOport state (unsupported?)"));
|
||||
}
|
||||
if(GP->setio > -1){
|
||||
verbose(1, _("Try to write %d to I/O port"), GP->setio);
|
||||
verbose(VERBOSE_PRIMARY, _("Try to write %d to I/O port"), GP->setio);
|
||||
if(!camera->setio || !camera->setio(GP->setio))
|
||||
ERRX(_("Can't set IOport"));
|
||||
WARNX(_("Can't set IOport"));
|
||||
}
|
||||
if(GP->exptime < 0.) goto retn;
|
||||
if(!isnan(GP->gain)){
|
||||
DBG("Change gain to %g", GP->gain);
|
||||
if(camera->setgain && camera->setgain(GP->gain)){
|
||||
if(camera->getgain) camera->getgain(&GP->gain);
|
||||
verbose(1, _("Set gain to %g"), GP->gain);
|
||||
}else ERRX(_("Can't set gain to %g"), GP->gain);
|
||||
verbose(VERBOSE_PRIMARY, _("Set gain to %g"), GP->gain);
|
||||
}else WARNX(_("Can't set gain to %g"), GP->gain);
|
||||
}
|
||||
if(!isnan(GP->brightness)){
|
||||
if(camera->setbrightness && camera->setbrightness(GP->brightness)){
|
||||
if(camera->getbrightness) camera->getbrightness(&GP->brightness);
|
||||
verbose(1, _("Set brightness to %g"), GP->brightness);
|
||||
verbose(VERBOSE_PRIMARY, _("Set brightness to %g"), GP->brightness);
|
||||
}else WARNX(_("Can't set brightness to %g"), GP->brightness);
|
||||
}
|
||||
/*********************** expose control ***********************/
|
||||
@@ -700,11 +721,11 @@ int prepare_ccds(){
|
||||
cc_frameformat fmt = {.w = GP->X1 - GP->X0, .h = GP->Y1 - GP->Y0, .xoff = GP->X0, .yoff = GP->Y0};
|
||||
if(!camera->setgeometry || !camera->setgeometry(&fmt))
|
||||
ERRX(_("Can't set given geometry"));
|
||||
verbose(3, "Geometry: off=%d/%d, wh=%d/%d", fmt.xoff, fmt.yoff, fmt.w, fmt.h);
|
||||
verbose(VERBOSE_MESG, "Geometry: off=%d/%d, wh=%d/%d", fmt.xoff, fmt.yoff, fmt.w, fmt.h);
|
||||
if(GP->nflushes > 0){
|
||||
if(!camera->setnflushes || !camera->setnflushes(GP->nflushes))
|
||||
WARNX(_("Can't set %d flushes"), GP->nflushes);
|
||||
else verbose(3, "Nflushes=%d", GP->nflushes);
|
||||
else verbose(VERBOSE_MESG, "Nflushes=%d", GP->nflushes);
|
||||
}
|
||||
if(!camera->setexp) ERRX(_("Camera plugin have no exposition setter"));
|
||||
if(!camera->setexp(GP->exptime))
|
||||
@@ -717,12 +738,12 @@ int prepare_ccds(){
|
||||
WARNX(_("Can't set bit depth"));
|
||||
if(!camera->setfastspeed || !camera->setfastspeed(GP->fast))
|
||||
WARNX(_("Can't set readout speed"));
|
||||
else verbose(1, _("Readout mode: %s"), GP->fast ? "fast" : "normal");
|
||||
if(!GP->outfile) verbose(1, _("Only show statistics"));
|
||||
else verbose(VERBOSE_PRIMARY, _("Readout mode: %s"), GP->fast ? "fast" : "normal");
|
||||
if(!GP->outfile) verbose(VERBOSE_PRIMARY, _("Only show statistics"));
|
||||
// GET binning should be AFTER setgeometry!
|
||||
if(!camera->getbin || !camera->getbin(&GP->hbin, &GP->vbin))
|
||||
WARNX(_("Can't get current binning"));
|
||||
verbose(2, "Binning: %d x %d", GP->hbin, GP->vbin);
|
||||
verbose(VERBOSE_SECONDARY, "Binning: %d x %d", GP->hbin, GP->vbin);
|
||||
rtn = TRUE;
|
||||
retn:
|
||||
if(!rtn) closecam();
|
||||
@@ -736,7 +757,7 @@ void ccds(){
|
||||
FNAME();
|
||||
cc_frameformat fmt = camera->geometry;
|
||||
int raw_width = fmt.w / GP->hbin, raw_height = fmt.h / GP->vbin;
|
||||
DBG("w=%d, h=%d", raw_width, raw_height);
|
||||
DBG("w=%d, h=%d", raw_width, raw_height);
|
||||
// allocate maximum available memory - for 16bit image
|
||||
uint16_t *img = MALLOC(uint16_t, raw_width * raw_height);
|
||||
DBG("\n\nAllocated image 2x%dx%d=%d", raw_width, raw_height, 2 * raw_width * raw_height);
|
||||
@@ -746,7 +767,7 @@ DBG("w=%d, h=%d", raw_width, raw_height);
|
||||
for(int j = 0; j < GP->nframes; ++j){
|
||||
TIMEINIT();
|
||||
TIMESTAMP("Start next cycle");
|
||||
verbose(1, _("Capture frame %d"), j);
|
||||
verbose(VERBOSE_PRIMARY, _("Capture frame %d"), j);
|
||||
if(!camera->startexposition) ERRX(_("Camera plugin have no function `start exposition`"));
|
||||
if(!camera->startexposition()){
|
||||
WARNX(_("Can't start exposition"));
|
||||
@@ -757,7 +778,7 @@ DBG("w=%d, h=%d", raw_width, raw_height);
|
||||
WARNX(_("Can't capture image"));
|
||||
break;
|
||||
}
|
||||
verbose(2, _("Read grabbed image"));
|
||||
verbose(VERBOSE_SECONDARY, _("Read grabbed image"));
|
||||
TIMESTAMP("Read grabbed");
|
||||
if(!camera->capture) ERRX(_("Camera plugin have no function `capture`"));
|
||||
if(!camera->capture(&ima)){
|
||||
@@ -775,10 +796,10 @@ DBG("w=%d, h=%d", raw_width, raw_height);
|
||||
if(GP->pause_len && j != (GP->nframes - 1)){
|
||||
double delta, time1 = sl_dtime() + GP->pause_len;
|
||||
while((delta = time1 - sl_dtime()) > 0.){
|
||||
verbose(1, _("%d seconds till pause ends\n"), (int)delta);
|
||||
verbose(VERBOSE_PRIMARY, _("%d seconds till pause ends\n"), (int)delta);
|
||||
float tmpf;
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(1, "CCDTEMP=%.1f\n", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(1, "BODYTEMP=%.1f\n", tmpf);
|
||||
if(camera->getTcold && camera->getTcold(&tmpf)) verbose(VERBOSE_PRIMARY, "CCDTEMP=%.1f\n", tmpf);
|
||||
if(camera->getTbody && camera->getTbody(&tmpf)) verbose(VERBOSE_PRIMARY, "BODYTEMP=%.1f\n", tmpf);
|
||||
if(delta > 6.) sleep(5);
|
||||
else if(delta > 0.9) sleep((int)(delta+0.99));
|
||||
else usleep((int)(delta*1e6 + 1));
|
||||
@@ -810,7 +831,7 @@ void framerate(){
|
||||
sumn = sumn - lastn[lastidx] + dT;
|
||||
lastn[lastidx] = dT;
|
||||
//for(int i = 0; i < NFRM; ++i) printf("last[%d]=%g\n", i, lastn[i]);
|
||||
green("Framerate=%.2f (%g seconds for exp); mean framerate=%.2f\n", 1./dT, dT, NFRM/sumn);
|
||||
verbose(VERBOSE_SECONDARY, _("Framerate=%.2f (%g seconds for exp); mean framerate=%.2f"), 1./dT, dT, NFRM/sumn);
|
||||
tlast = t;
|
||||
}
|
||||
|
||||
@@ -888,7 +909,7 @@ int ccdcaptured(cc_IMG **imgptr){
|
||||
TIMESTAMP("Start new grab");
|
||||
TIMEINIT();
|
||||
if(pthread_create(&grabthread, NULL, &grabnext, (void*)ima)){
|
||||
WARN("Can't create grabbing thread");
|
||||
WARN(_("Can't create grabbing thread"));
|
||||
grabthread = 0;
|
||||
}
|
||||
}else{ // grab in process
|
||||
@@ -919,11 +940,11 @@ int start_socket(int isserver){
|
||||
int isnet = 0;
|
||||
if(GP->path) path = GP->path;
|
||||
else if(GP->port){ path = GP->port; isnet = 1; }
|
||||
else ERRX("Point network port or UNIX-socket path");
|
||||
else ERRX(_("Point network port or UNIX-socket path"));
|
||||
int sock = cc_open_socket(isserver, path, isnet), imsock = -1;
|
||||
if(sock < 0){
|
||||
LOGERR("Can't open socket");
|
||||
ERRX("start_socket(): can't open socket");
|
||||
ERRX(_("start_socket(): can't open socket"));
|
||||
}
|
||||
if(isserver){
|
||||
imsock = cc_open_socket(TRUE, GP->imageport, 2); // image socket should be networked
|
||||
@@ -932,7 +953,7 @@ int start_socket(int isserver){
|
||||
}else{
|
||||
#ifdef IMAGEVIEW
|
||||
if(GP->showimage){
|
||||
if(!GP->viewer && GP->exptime < 0.00001) ERRX("Need exposition time!");
|
||||
if(!GP->viewer && GP->exptime < 0.00001) ERRX(_("Need exposition time!"));
|
||||
init_grab_sock(sock);
|
||||
viewer(sockcaptured); // start viewer with socket client parser
|
||||
DBG("done");
|
||||
|
||||
85
client.c
85
client.c
@@ -39,11 +39,11 @@ extern double answer_timeout;
|
||||
static char sendbuf[BUFSIZ];
|
||||
static char *lastfilename = NULL;
|
||||
// send message and wait any answer
|
||||
#define SENDMSG(...) do{DBG("SENDMSG"); snprintf(sendbuf, BUFSIZ-1, __VA_ARGS__); verbose(2, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX("Server disconnected"); while(getans(sock, NULL));} while(0)
|
||||
#define SENDMSG(...) do{DBG("SENDMSG"); snprintf(sendbuf, BUFSIZ-1, __VA_ARGS__); verbose(VERBOSE_SECONDARY, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX(_("Server disconnected")); getans(sock, NULL);} while(0)
|
||||
// send message and wait answer starting with 'cmd'
|
||||
#define SENDMSGW(cmd, ...) do{DBG("SENDMSGW"); snprintf(sendbuf, BUFSIZ-1, cmd __VA_ARGS__); verbose(2, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX("Server disconnected");}while(!getans(sock, cmd))
|
||||
#define SENDMSGW(cmd, ...) do{DBG("SENDMSGW"); snprintf(sendbuf, BUFSIZ-1, cmd __VA_ARGS__); verbose(VERBOSE_SECONDARY, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX(_("Server disconnected")); else getans(sock, cmd);}while(0)
|
||||
// send command and wait for answer on it
|
||||
#define SENDCMDW(cmd) do{DBG("SENDCMDW"); strncpy(sendbuf, cmd, BUFSIZ-1); verbose(2, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX("Server disconnected");}while(!getans(sock, cmd))
|
||||
#define SENDCMDW(cmd) do{DBG("SENDCMDW"); strncpy(sendbuf, cmd, BUFSIZ-1); verbose(VERBOSE_SECONDARY, "\t> %s", sendbuf); if(!cc_sendstrmessage(sock, sendbuf)) ERRX(_("Server disconnected")); else getans(sock, cmd);}while(0)
|
||||
static volatile atomic_int expstate = CAMERA_CAPTURE;
|
||||
static int xm0,ym0,xm1,ym1; // max format
|
||||
static int xc0,yc0,xc1,yc1; // current format
|
||||
@@ -54,7 +54,7 @@ static int oldgrabno = 0;
|
||||
static cc_IMG ima = {0}, *shmima = NULL; // ima - local storage, shmima - shm (if available)
|
||||
static size_t imbufsz = 0; // image buffer for allocated `ima`
|
||||
static uint8_t *imbuf = NULL; // we can't use shmima->data as it belongs to server, so we use `imbuf` and set ima.data = imbuf
|
||||
static int current_image_number = -1; // for net-parser - last number of exposed image
|
||||
static volatile atomic_int current_image_number = -1; // for net-parser - last number of exposed image
|
||||
|
||||
#if 0
|
||||
// read message from queue or file descriptor
|
||||
@@ -91,7 +91,7 @@ static cc_hresult parseans(char *ans){
|
||||
for(cc_hresult res = CC_RESULT_BUSY; res < CC_RESULT_NUM; ++res){
|
||||
const char *resmsg = cc_hresult2str(res);
|
||||
if(0 == strcmp(resmsg, ans)){
|
||||
verbose(1, "Server answered: %s", resmsg);
|
||||
verbose(VERBOSE_PRIMARY, "Server answered: %s", resmsg);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ static cc_hresult parseans(char *ans){
|
||||
DBG("Got current format: %d,%d,%d,%d", xc0, yc0, xc1, yc1);
|
||||
return CC_RESULT_SILENCE;
|
||||
}else if(0 == CMP_ANS(CC_CMD_IMNUMBER, ans)){
|
||||
current_image_number = atoi(val);
|
||||
atomic_store(¤t_image_number, atoi(val));
|
||||
}
|
||||
//TIMESTAMP("parseans() end");
|
||||
return CC_RESULT_SILENCE; // echo of sent command or something else
|
||||
@@ -147,7 +147,7 @@ static int getans(int sock, const char *msg){
|
||||
tmout = answer_timeout;
|
||||
t0 = sl_dtime();
|
||||
TIMESTAMP("Got from server: %s", ans);
|
||||
verbose(1, "\t%s", ans);
|
||||
verbose(VERBOSE_PRIMARY, "\t%s", ans);
|
||||
DBG("1 msg-> %s, ans -> %s", msg, ans);
|
||||
res = parseans(ans);
|
||||
DBG("2 msg-> %s, ans -> %s; result: %d", msg, ans, res);
|
||||
@@ -170,9 +170,9 @@ static int getans(int sock, const char *msg){
|
||||
static void send_headers(int sock){
|
||||
if(GP->plugincmd){
|
||||
char **p = GP->plugincmd;
|
||||
green("Send custom plugin commands\n");
|
||||
verbose(VERBOSE_PRIMARY, _("Send custom plugin commands\n"));
|
||||
while(p && *p){
|
||||
printf("\t%s\n", *p);
|
||||
verbose(VERBOSE_PRIMARY, "\t%s\n", *p);
|
||||
SENDMSGW(CC_CMD_PLUGINCMD, "=%s", *p);
|
||||
++p;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ static int readNbytes(int fd, size_t N, uint8_t *buf){
|
||||
ssize_t rd = read(fd, buf + got, need);
|
||||
if(rd <= 0){
|
||||
if(errno == EAGAIN || errno == EWOULDBLOCK) continue;
|
||||
WARNX("Server disconnected");
|
||||
WARNX(_("Server disconnected"));
|
||||
signals(1);
|
||||
}
|
||||
got += rd; need -= rd;
|
||||
@@ -304,7 +304,7 @@ static int getimage(int askheader){
|
||||
usleep(100);
|
||||
}
|
||||
if(!shmlocked){
|
||||
WARNX("Can't lock shared memory");
|
||||
WARNX(_("Can't lock shared memory"));
|
||||
return FALSE;
|
||||
}
|
||||
memcpy(&ima, shmima, sizeof(cc_IMG));
|
||||
@@ -313,19 +313,19 @@ static int getimage(int askheader){
|
||||
DBG("Open socket @ %s", GP->imageport);
|
||||
imsock = cc_open_socket(FALSE, GP->imageport, TRUE);
|
||||
}
|
||||
if(imsock < 0) ERRX("getimage(): can't open image transport socket");
|
||||
if(imsock < 0) ERRX(_("getimage(): can't open image transport socket"));
|
||||
// get image size
|
||||
if(!readNbytes(imsock, sizeof(cc_IMG), (uint8_t*)&ima)){
|
||||
WARNX("Can't read image header");
|
||||
WARNX(_("Can't read image header"));
|
||||
goto eofg;
|
||||
}
|
||||
}
|
||||
if(ima.MAGICK != CC_SHM_MAGIC){
|
||||
WARNX("Wrong image: bad magick");
|
||||
WARNX(_("Wrong image: bad magick"));
|
||||
goto eofg;
|
||||
}
|
||||
if(ima.bytelen < 1){
|
||||
WARNX("Wrong image size");
|
||||
WARNX(_("Wrong image size"));
|
||||
goto eofg;
|
||||
}
|
||||
DBG("bytelen=%zd, w=%d, h=%d; bitpix=%d", ima.bytelen, ima.w, ima.h, ima.bitpix);
|
||||
@@ -333,14 +333,22 @@ static int getimage(int askheader){
|
||||
if(imbufsz < ima.bytelen){
|
||||
size_t newsz = 1024 * (1 + ima.bytelen / 1024);
|
||||
DBG("Reallocate memory from %zd to %zd", imbufsz, newsz);
|
||||
imbufsz = newsz;
|
||||
uint8_t *b = imbuf;
|
||||
imbuf = realloc(imbuf, imbufsz);
|
||||
if(imbuf){
|
||||
imbufsz = newsz;
|
||||
DBG("Size after realloc: %zd", imbufsz);
|
||||
}else{
|
||||
WARNX(_("Can't reallocate memory for image buffer"));
|
||||
imbuf = b;
|
||||
goto eofg;
|
||||
}
|
||||
}
|
||||
ima.data = imbuf; // renew this value each time after getting `ima` from server
|
||||
TIMESTAMP("Start of data read");
|
||||
if(shmima){
|
||||
uint8_t *datastart = ((uint8_t*)shmima) + sizeof(cc_IMG);
|
||||
DBG("first image byte: %d", *datastart);
|
||||
DBG("first image byte: %d; bytelen: %zd", *datastart, ima.bytelen);
|
||||
memcpy(imbuf, datastart, ima.bytelen);
|
||||
TIMESTAMP("Got by shared memory");
|
||||
if(!askheader){
|
||||
@@ -350,7 +358,7 @@ static int getimage(int askheader){
|
||||
ret = TRUE;
|
||||
}else{
|
||||
if(!readNbytes(imsock, ima.bytelen, imbuf)){
|
||||
WARNX("Can't read image data");
|
||||
WARNX(_("Can't read image data"));
|
||||
goto eofg;
|
||||
}
|
||||
ret = TRUE;
|
||||
@@ -369,7 +377,7 @@ static int getimage(int askheader){
|
||||
uint8_t card[FLEN_CARD];
|
||||
for(size_t i = 0; i < ima.headerstrings; ++i){
|
||||
if(!readNbytes(imsock, FLEN_CARD, card)){
|
||||
WARNX("Can't read full header, got %zd records from %zd", i, ima.headerstrings);
|
||||
WARNX(_("Can't read full header, got %zd records from %zd"), i, ima.headerstrings);
|
||||
break;
|
||||
}
|
||||
memcpy(&ima.fitsheader[i], card, FLEN_CARD);
|
||||
@@ -399,14 +407,14 @@ static int curImNo(int sock){
|
||||
}
|
||||
// no shared memory: try to get number over TCP
|
||||
SENDCMDW(CC_CMD_IMNUMBER);
|
||||
return current_image_number;
|
||||
return atomic_load(¤t_image_number);
|
||||
}
|
||||
|
||||
void client(int sock){
|
||||
if(sock < 0) ERRX("Can't run without command socket");
|
||||
if(sock < 0) ERRX(_("Can't run without command socket"));
|
||||
if(!GP->forceimsock && !shmima){ // init shm buffer if user don't ask to force workign through image socket
|
||||
shmima = cc_getshm(GP->shmkey, 0); // try to init client shm
|
||||
cc_init_sem(FALSE);
|
||||
if(shmima) cc_init_sem(FALSE);
|
||||
DBG("Got access to shared memory: %s", shmima ? "OK" : "FAIL");
|
||||
}
|
||||
if(GP->restart){
|
||||
@@ -425,10 +433,10 @@ void client(int sock){
|
||||
SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); // call to start capture
|
||||
} else return; // just send headers and exit
|
||||
double timeout = CC_CLIENT_TIMEOUT;
|
||||
verbose(1, "Exposing frame 1...");
|
||||
verbose(VERBOSE_PRIMARY, _("Exposing frame 1..."));
|
||||
atomic_store(&expstate, CAMERA_CAPTURE); // could be changed earlier
|
||||
DBG("Current state: %d", atomic_load(&expstate));
|
||||
verbose(2, "Wait for exposition end");
|
||||
verbose(VERBOSE_PRIMARY, _("Wait for exposition end"));
|
||||
t0 = sl_dtime();
|
||||
tw = tstart = t0;
|
||||
int lastImNo = curImNo(sock);
|
||||
@@ -436,19 +444,22 @@ void client(int sock){
|
||||
if(sl_dtime() - tw > CC_WAIT_TIMEOUT){
|
||||
SENDCMDW(CC_CMD_TREMAIN); // get remained time
|
||||
tw = sl_dtime();
|
||||
usleep(100000);
|
||||
}
|
||||
if(sl_dtime() - tstart < GP->exptime){
|
||||
t0 = sl_dtime(); // refresh timeout until exp not ends
|
||||
usleep(1000);
|
||||
continue;
|
||||
}else{
|
||||
SENDCMDW(CC_CMD_EXPSTATE);
|
||||
usleep(1000);
|
||||
}
|
||||
int curst = atomic_load(&expstate);
|
||||
DBG("Current state: %d", curst);
|
||||
if(curst == CAMERA_ERROR){
|
||||
WARNX(_("Can't make exposition"));
|
||||
if(Nremain > 1){
|
||||
verbose(1, "Exposing frame %d...", nframe);
|
||||
verbose(VERBOSE_PRIMARY, _("Exposing frame %d..."), nframe);
|
||||
SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE);
|
||||
tstart = sl_dtime();
|
||||
}
|
||||
@@ -459,16 +470,16 @@ void client(int sock){
|
||||
int cur = curImNo(sock);
|
||||
DBG("Current state: %d, imno: %d", atomic_load(&expstate), cur);
|
||||
if(Nremain > 1){ // start next capture
|
||||
verbose(1, "Exposing frame %d...", nframe);
|
||||
verbose(VERBOSE_PRIMARY, _("Exposing frame %d..."), nframe);
|
||||
SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE);
|
||||
tstart = sl_dtime();
|
||||
}
|
||||
int failed = TRUE;
|
||||
if(lastImNo < cur){
|
||||
lastImNo = cur;
|
||||
verbose(2, "Frame ready, try to grab");
|
||||
verbose(VERBOSE_SECONDARY, _("Frame ready, try to grab"));
|
||||
if(!getimage(TRUE)){
|
||||
WARNX("Can't get next image");
|
||||
WARNX(_("Can't get next image"));
|
||||
}else{
|
||||
if(saveFITS(&ima, &lastfilename)){
|
||||
--Nremain;
|
||||
@@ -476,9 +487,9 @@ void client(int sock){
|
||||
failed = FALSE;
|
||||
}
|
||||
}
|
||||
}else verbose(2, "Got already saved image, wait next");
|
||||
}else verbose(VERBOSE_SECONDARY, _("Got already saved image, wait next"));
|
||||
if(failed && Nremain == 1){ // last image -> should re-expose
|
||||
verbose(1, "Exposing frame %d...", nframe);
|
||||
verbose(VERBOSE_PRIMARY, _("Exposing frame %d..."), nframe);
|
||||
SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE);
|
||||
tstart = sl_dtime();
|
||||
}
|
||||
@@ -488,14 +499,14 @@ void client(int sock){
|
||||
while(1){
|
||||
SENDCMDW(CC_CMD_CAMTEMPER);
|
||||
if((delta = time1 - sl_dtime()) < __FLT_EPSILON__) break;
|
||||
if(delta > 1.) verbose(1, _("%d seconds till pause ends\n"), (int)delta);
|
||||
if(delta > 1.) verbose(VERBOSE_PRIMARY, _("%d seconds till pause ends\n"), (int)delta);
|
||||
if(delta > 6.) sleep(5);
|
||||
else if(delta > 1.) sleep((int)delta);
|
||||
else usleep((int)(delta*1e6 + 1));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
DBG("All images saved -> exit");
|
||||
verbose(VERBOSE_SECONDARY, "Got all images, closing...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -506,7 +517,7 @@ void client(int sock){
|
||||
#ifdef IMAGEVIEW
|
||||
static int controlfd = -1; // control socket FD
|
||||
void init_grab_sock(int sock){
|
||||
if(sock < 0) ERRX("Can't run without command socket");
|
||||
if(sock < 0) ERRX(_("Can't run without command socket"));
|
||||
controlfd = sock;
|
||||
send_headers(sock);
|
||||
if(!GP->forceimsock && !shmima){ // init shm buffer if user don't ask to work through image socket
|
||||
@@ -549,7 +560,7 @@ static void *grabnext(void _U_ *arg){
|
||||
}
|
||||
int cur = curImNo(sock);
|
||||
if(sl_dtime() - t0 >= timeout || curst != CAMERA_FRAMERDY || cur <= lastImNo){
|
||||
WARNX("Image wasn't received, state: %d, waiting: %g, lastNo: %d, curNo: %d (timeout: %g)", curst, sl_dtime() - t0, lastImNo, cur, timeout);
|
||||
WARNX(_("Image wasn't received, state: %d, waiting: %g, lastNo: %d, curNo: %d (timeout: %g)"), curst, sl_dtime() - t0, lastImNo, cur, timeout);
|
||||
continue;
|
||||
}
|
||||
lastImNo = cur;
|
||||
@@ -607,16 +618,16 @@ int sockcaptured(cc_IMG **imgptr){
|
||||
if(!grabthread || pthread_kill(grabthread, 0)){ // start new grab
|
||||
if(GP->viewer){
|
||||
TIMEINIT();
|
||||
DBG("\n\n\nStart new waiting");
|
||||
DBG("\n\n\nStart new capturing");
|
||||
if(pthread_create(&grabthread, NULL, &waitimage, NULL)){
|
||||
WARN("Can't create waiting thread");
|
||||
WARN(_("Can't create capturing thread"));
|
||||
grabthread = 0;
|
||||
}
|
||||
}else{
|
||||
TIMEINIT();
|
||||
DBG("\n\n\nStart new grab");
|
||||
if(pthread_create(&grabthread, NULL, &grabnext, NULL)){
|
||||
WARN("Can't create grabbing thread");
|
||||
WARN(_("Can't create capturing thread"));
|
||||
grabthread = 0;
|
||||
}
|
||||
}
|
||||
|
||||
21
cmdlnopts.c
21
cmdlnopts.c
@@ -1,4 +1,20 @@
|
||||
|
||||
/*
|
||||
* This file is part of the CCD_Capture project.
|
||||
* Copyright 2026 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h> // NAN
|
||||
@@ -137,10 +153,11 @@ glob_pars *parse_args(int argc, char **argv){
|
||||
// parse arguments
|
||||
sl_parseargs(&argc, &argv, cmdlnopts);
|
||||
if(help) sl_showhelp(-1, cmdlnopts);
|
||||
if(G.verbose > VERBOSE_MESG) G.verbose = VERBOSE_MESG;
|
||||
if(argc > 0){
|
||||
G.outfileprefix = strdup(argv[0]);
|
||||
if(argc > 1){
|
||||
WARNX("%d unused parameters:\n", argc - 1);
|
||||
WARNX(_("%d unused parameters:\n"), argc - 1);
|
||||
for(int i = 1; i < argc; ++i)
|
||||
printf("\t%4d: %s\n", i, argv[i]);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
#pragma once
|
||||
#include <usefull_macros.h>
|
||||
|
||||
// verbose levels
|
||||
enum{
|
||||
VERBOSE_NONE = 0, // show nothing
|
||||
VERBOSE_PRIMARY, // only main messages
|
||||
VERBOSE_SECONDARY, // also secondary messages
|
||||
VERBOSE_MESG, // debug messages
|
||||
VERBOSE_AMOUNT // just amount of levels
|
||||
};
|
||||
|
||||
/*
|
||||
* here are some typedef's for global data
|
||||
*/
|
||||
|
||||
17
imageview.c
17
imageview.c
@@ -422,7 +422,7 @@ static void change_colorfun(colorfn_type f){
|
||||
colorfun = linfun;
|
||||
cfn = "linear";
|
||||
}
|
||||
verbose(1, _("Histogram conversion: %s"), cfn);
|
||||
verbose(VERBOSE_PRIMARY, _("Histogram conversion: %s"), cfn);
|
||||
}
|
||||
|
||||
// cycle switch between palettes
|
||||
@@ -612,7 +612,7 @@ static void change_displayed_image(cc_IMG *img){
|
||||
static size_t lastN = 0;
|
||||
ssize_t delta = img->imnumber - lastN;
|
||||
TIMESTAMP("Got image #%zd", img->imnumber);
|
||||
if(delta > 0 && delta != 1) WARNX("Missed %zd images", delta-1);
|
||||
if(delta > 0 && delta != 1) WARNX(_("Missed %zd images"), delta-1);
|
||||
lastN = img->imnumber;
|
||||
//pthread_mutex_lock(&win->mutex);
|
||||
rawimage *im = win->image;
|
||||
@@ -694,12 +694,12 @@ void closeGL(){ // killed by external signal or ctrl+c
|
||||
*/
|
||||
int viewer(imagefunc newimage){
|
||||
if(!newimage){
|
||||
WARNX("No image changing function defined");
|
||||
WARNX(_("No image changing function defined"));
|
||||
return 1;
|
||||
}
|
||||
imageview_init();
|
||||
DBG("Create new win");
|
||||
createGLwin("Sample window", 1024, 1024, NULL);
|
||||
createGLwin("ccd_capture", 1024, 1024, NULL);
|
||||
if(!win){
|
||||
WARNX(_("Can't open OpenGL window, image preview will be inaccessible"));
|
||||
return 1;
|
||||
@@ -731,7 +731,12 @@ int viewer(imagefunc newimage){
|
||||
continue;
|
||||
}
|
||||
if(win->winevt & WINEVT_SAVEIMAGE){ // save image
|
||||
verbose(2, "Make screenshot\n");
|
||||
verbose(VERBOSE_PRIMARY, _("Make screenshot"));
|
||||
if(GP->outfile) GP->rewrite = TRUE;
|
||||
else if(!GP->outfileprefix){
|
||||
GP->outfileprefix = strdup("ccd_capture-screenshot");
|
||||
verbose(VERBOSE_PRIMARY, _("Set output prefix to %s"), GP->outfileprefix);
|
||||
}
|
||||
saveFITS(img, NULL);
|
||||
win->winevt &= ~WINEVT_SAVEIMAGE;
|
||||
}
|
||||
@@ -743,7 +748,7 @@ int viewer(imagefunc newimage){
|
||||
if(win->winevt & WINEVT_EQUALIZE){
|
||||
win->winevt &= ~WINEVT_EQUALIZE;
|
||||
imequalize = !imequalize;
|
||||
verbose(1, _("Equalization of histogram: %s"), imequalize ? N_("on") : N_("off"));
|
||||
verbose(VERBOSE_PRIMARY, _("Equalization of histogram: %s"), imequalize ? N_("on") : N_("off"));
|
||||
change_displayed_image(img);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
593
locale/ru/ru.po
593
locale/ru/ru.po
File diff suppressed because it is too large
Load Diff
31
main.c
31
main.c
@@ -49,12 +49,12 @@ void signals(int signo){
|
||||
signal(signo, signals);
|
||||
return;
|
||||
}
|
||||
WARNX("Master killed with sig=%d", signo);
|
||||
WARNX(_("Master killed with sig=%d"), signo);
|
||||
LOGERR("Master killed with sig=%d", signo);
|
||||
exit(signo);
|
||||
}
|
||||
// slave: cancel exposition
|
||||
if(signo) WARNX("Get signal %d - exit", signo);
|
||||
if(signo) WARNX(_("Get signal %d - exit"), signo);
|
||||
if(!GP->client){
|
||||
DBG("Cancel capturing and close all");
|
||||
stop_server();
|
||||
@@ -88,47 +88,48 @@ int main(int argc, char **argv){
|
||||
GP->client = 1;
|
||||
GP->showimage = 1;
|
||||
}
|
||||
if(GP->outfile && GP->outfileprefix) ERRX("Can't use outfile name and prefix together");
|
||||
if(GP->outfile && GP->outfileprefix) ERRX(_("Can't use outfile name and prefix together"));
|
||||
if(GP->outfile && !GP->rewrite){
|
||||
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->anstmout > 0.){
|
||||
if(!cc_setAnsTmout(GP->anstmout)) ERRX("Can't set answer timeout to %g", GP->anstmout);
|
||||
if(!cc_setAnsTmout(GP->anstmout)) ERRX(_("Can't set answer timeout to %g"), GP->anstmout);
|
||||
}
|
||||
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.");
|
||||
WARNX(_("Options `port` and `path` can't be used together! Point `port` for TCP socket or `path` for UNIX."));
|
||||
return 1;
|
||||
}
|
||||
int port = atoi(GP->port);
|
||||
if(port < CC_PORTN_MIN || port > CC_PORTN_MAX){
|
||||
WARNX("Wrong port value: %d", port);
|
||||
WARNX(_("Wrong port value: %d"), port);
|
||||
return 1;
|
||||
}
|
||||
if(!GP->client) isserver = TRUE;
|
||||
}
|
||||
if(GP->path && !GP->client) isserver = TRUE;
|
||||
if(!GP->path && !GP->port){
|
||||
/*if(!GP->path && !GP->port){ // standalone
|
||||
WARNX("Point one of options: `port` or `path` for command socket");
|
||||
}
|
||||
}*/
|
||||
if((isserver || GP->client) && !GP->imageport){
|
||||
GP->imageport = MALLOC(char, 32);
|
||||
if(!GP->port) sprintf(GP->imageport, "12345");
|
||||
else snprintf(GP->imageport, 31, "%d", 1+atoi(GP->port));
|
||||
printf("Set image port to %s\n", GP->imageport);
|
||||
verbose(VERBOSE_PRIMARY, _("Set image port to %s\n"), GP->imageport);
|
||||
}
|
||||
if(GP->client && (GP->commondev || GP->focuserdev || GP->cameradev || GP->wheeldev))
|
||||
ERRX("Can't be client and standalone in same time!");
|
||||
ERRX(_("Can't be client and standalone in same time!"));
|
||||
if(GP->logfile){
|
||||
int lvl = LOGLEVEL_WARN + GP->verbose;
|
||||
int lvl = LOGLEVEL_ERR + GP->verbose;
|
||||
DBG("level = %d", lvl);
|
||||
if(lvl > LOGLEVEL_ANY) lvl = LOGLEVEL_ANY;
|
||||
verbose(1, "Log file %s @ level %d\n", GP->logfile, lvl);
|
||||
verbose(VERBOSE_PRIMARY, _("Log file %s @ level %d\n"), GP->logfile, lvl);
|
||||
OPENLOG(GP->logfile, lvl, 1);
|
||||
if(!sl_globlog) WARNX("Can't create log file");
|
||||
if(!sl_globlog) WARNX(_("Can't create log file"));
|
||||
}
|
||||
if(GP->info && GP->verbose < 2) GP->verbose = 2; // increase verbose messages level for `info`
|
||||
if(GP->info && GP->verbose < VERBOSE_SECONDARY) // increase verbose messages level for `info`
|
||||
GP->verbose = VERBOSE_SECONDARY;
|
||||
signal(SIGINT, signals);
|
||||
signal(SIGQUIT, signals);
|
||||
signal(SIGABRT, signals);
|
||||
|
||||
60
server.c
60
server.c
@@ -123,7 +123,7 @@ static int lock(){
|
||||
static void unlock(){
|
||||
if(pthread_mutex_unlock(&locmutex)){
|
||||
LOGERR("Can't unlock socket mutex");
|
||||
ERR("Can't unlock socket mutex");
|
||||
ERR(_("Can't unlock socket mutex"));
|
||||
}
|
||||
//DBG("UNLOCK()");
|
||||
}
|
||||
@@ -160,7 +160,7 @@ static void fixima(){
|
||||
// allocate memory for largest possible image
|
||||
if(!ima){
|
||||
ima = cc_getshm(GP->shmkey, camera->array.h * camera->array.w * 2);
|
||||
if(!ima) ERR("Can't allocate memory for image");
|
||||
if(!ima) ERR(_("Can't allocate memory for image"));
|
||||
// init shared semaphore
|
||||
cc_init_sem(TRUE);
|
||||
}
|
||||
@@ -191,13 +191,13 @@ static inline void cameraidlestate(){ // idle - wait for capture commands
|
||||
camstate = CAMERA_CAPTURE;
|
||||
fixima();
|
||||
if(!camera->startexposition){
|
||||
LOGERR(_("Camera plugin have no function `start exposition`"));
|
||||
LOGERR("Camera plugin have no function `start exposition`");
|
||||
WARNX(_("Camera plugin have no function `start exposition`"));
|
||||
camstate = CAMERA_ERROR;
|
||||
return;
|
||||
}
|
||||
if(!camera->startexposition()){
|
||||
LOGERR(_("Can't start exposition"));
|
||||
LOGERR("Can't start exposition");
|
||||
WARNX(_("Can't start exposition"));
|
||||
camstate = CAMERA_ERROR;
|
||||
return;
|
||||
@@ -216,7 +216,7 @@ static inline void cameracapturestate(){ // capturing - wait for exposition ends
|
||||
TIMESTAMP("start capture");
|
||||
if(!camera->capture){
|
||||
WARNX(_("Camera plugin have no function `capture`"));
|
||||
LOGERR(_("Camera plugin have no function `capture`"));
|
||||
LOGERR("Camera plugin have no function `capture`");
|
||||
camstate = CAMERA_ERROR;
|
||||
return;
|
||||
}
|
||||
@@ -1025,16 +1025,30 @@ static void *sendimage(void *C){
|
||||
int client = *(int*)C;
|
||||
if(ima->h < 1 || ima->w < 1) return NULL;
|
||||
DBG("client fd: %d", client);
|
||||
cc_lock_shm(TRUE);
|
||||
cc_IMG *locimage = calloc(1, sizeof(cc_IMG));
|
||||
void *data = calloc(1, ima->bytelen);
|
||||
if(!locimage || !data){
|
||||
cc_unlock_shm();
|
||||
if(data) free(data);
|
||||
if(locimage) free(locimage);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(locimage, ima, sizeof(cc_IMG));
|
||||
memcpy(data, ima->data, ima->bytelen);
|
||||
cc_unlock_shm();
|
||||
do{
|
||||
// send image body
|
||||
if(!cc_senddata(client, ima, sizeof(cc_IMG))) break;
|
||||
if(!cc_senddata(client, locimage, sizeof(cc_IMG))) break;
|
||||
// send image itself (client can close socket if don't need image data)
|
||||
if(!cc_senddata(client, ima->data, ima->bytelen)) break;
|
||||
if(!cc_senddata(client, data, locimage->bytelen)) break;
|
||||
// send FITS header (client can close socket if don't need it)
|
||||
for(size_t i = 0; i < ima->headerstrings; ++i){ // send header
|
||||
if(!cc_senddata(client, &ima->fitsheader[i], FLEN_CARD)) break;
|
||||
for(size_t i = 0; i < locimage->headerstrings; ++i){ // send header
|
||||
if(!cc_senddata(client, &locimage->fitsheader[i], FLEN_CARD)) break;
|
||||
}
|
||||
}while(0);
|
||||
free(locimage);
|
||||
free(data);
|
||||
close(client);
|
||||
TIMESTAMP("Image sent");
|
||||
DBG("%d closed", client);
|
||||
@@ -1043,8 +1057,8 @@ static void *sendimage(void *C){
|
||||
|
||||
void server(int sock, int imsock){
|
||||
DBG("sockfd=%d, imsockfd=%d", sock, imsock);
|
||||
if(sock < 0) ERRX("server(): need at least command socket fd");
|
||||
if(imsock < 0) WARNX("Server run without image transport socket");
|
||||
if(sock < 0) ERRX(_("server(): need at least command socket fd"));
|
||||
if(imsock < 0) WARNX(_("Server run without image transport socket"));
|
||||
else if(listen(imsock, CC_MAXCLIENTS) == -1){
|
||||
WARN("listen()");
|
||||
LOGERR("server(): error in listen() for image socket");
|
||||
@@ -1065,7 +1079,7 @@ void server(int sock, int imsock){
|
||||
camdevini(0);
|
||||
if(ctr == 3){
|
||||
LOGERR("server(): no devices found");
|
||||
WARNX("No devices found");
|
||||
WARNX(_("No devices found"));
|
||||
}
|
||||
// start camera thread
|
||||
pthread_t camthread;
|
||||
@@ -1110,7 +1124,7 @@ void server(int sock, int imsock){
|
||||
// sending image could be a very long operation -> run it in separate thread
|
||||
if(client > -1){
|
||||
if(ima->imnumber == 0){
|
||||
WARNX("Client wants an image, but there's no data");
|
||||
WARNX(_("Client wants an image, but there's no data"));
|
||||
close(client);
|
||||
}else{
|
||||
pthread_t sendthread;
|
||||
@@ -1139,7 +1153,7 @@ void server(int sock, int imsock){
|
||||
LOGMSG("SERVER got connection, fd=%d", client);
|
||||
if(nfd == CC_MAXCLIENTS + 1){
|
||||
LOGWARN("Max amount of connections, disconnect fd=%d", client);
|
||||
WARNX("Limit of connections reached");
|
||||
WARNX(_("Limit of connections reached"));
|
||||
close(client);
|
||||
}else{
|
||||
memset(&poll_set[nfd], 0, sizeof(struct pollfd));
|
||||
@@ -1149,20 +1163,6 @@ void server(int sock, int imsock){
|
||||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
// process some data & send messages to ALL
|
||||
if(camstate == CAMERA_FRAMERDY || camstate == CAMERA_ERROR){
|
||||
DBG("new image: timestamp=%.1f, num=%zd", ima->timestamp, ima->imnumber);
|
||||
char buff[PATH_MAX+32];
|
||||
snprintf(buff, PATH_MAX, CC_CMD_EXPSTATE "=%d", camstate);
|
||||
DBG("Send %s to %d clients", buff, nfd - 2);
|
||||
for(int i = 2; i < nfd; ++i){
|
||||
TIMESTAMP("Send message that all ready");
|
||||
cc_sendstrmessage(poll_set[i].fd, buff);
|
||||
}
|
||||
camstate = CAMERA_IDLE;
|
||||
}
|
||||
#endif
|
||||
// scan connections
|
||||
for(int fdidx = 2; fdidx < nfd; ++fdidx){
|
||||
if((poll_set[fdidx].revents & POLLIN) == 0) continue;
|
||||
@@ -1222,7 +1222,7 @@ char *makeabspath(const char *path, int shouldbe){
|
||||
if(shouldbe) return NULL;
|
||||
f = fopen(path, "a");
|
||||
if(!f){
|
||||
WARN("Can't create %s", path);
|
||||
WARN(_("Can't create %s"), path);
|
||||
return NULL;
|
||||
}
|
||||
unl = 1;
|
||||
@@ -1258,7 +1258,7 @@ static int parsestring(int fd, cc_handleritem *handlers, char *str){
|
||||
do{ l = lock(); } while(!l && sl_dtime() - t0 < CC_BUSY_TIMEOUT);
|
||||
DBG("time: %g", sl_dtime() - t0);
|
||||
if(!l){
|
||||
WARN("Can't lock mutex"); //signals(1);
|
||||
WARN(_("Can't lock mutex")); //signals(1);
|
||||
return CC_RESULT_BUSY; // long blocking work
|
||||
}
|
||||
r = h->chkfunction(val);
|
||||
|
||||
Reference in New Issue
Block a user