From c50a789aef72041a690ced91d0091aab7ae716da Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Wed, 16 Apr 2025 09:33:25 +0300 Subject: [PATCH] fixed for usefull_macros v0.3.2 --- APOGEE_cameras/apogee.c | 4 +- Astar_cameras/artifical_star.c | 42 ++-- BASLER_cameras/basler.c | 12 +- CMakeLists.txt | 2 +- Dummy_cameras/dummyfunc.c | 10 +- GRH_cameras/grasshopper.c | 19 +- HIKROBOT_cameras/mvsfunc.c | 4 +- ZWO_cameras/zwofunc.c | 4 +- ccdcapture.c | 78 +++---- ccdcapture.h | 16 +- ccdfunc.c | 14 +- client.c | 50 +++-- cmdlnopts.c | 8 +- examples/ccd_client.c | 24 +-- examples/centroids.c | 30 +-- locale/ru/messages.po | 2 +- locale/ru/ru.po | 2 +- main.c | 8 +- server.c | 374 ++++++++++++++++----------------- socket.h | 4 +- 20 files changed, 357 insertions(+), 350 deletions(-) diff --git a/APOGEE_cameras/apogee.c b/APOGEE_cameras/apogee.c index 791e19c..cf25ff8 100644 --- a/APOGEE_cameras/apogee.c +++ b/APOGEE_cameras/apogee.c @@ -255,7 +255,7 @@ static int thot(float *t){ } static int startexp(){ - tstart = dtime(); + tstart = sl_dtime(); DBG("Start exposition %g seconds (isobject=%d)", exptime, isobject); CCDerr r = ApnGlueStartExp(&exptime, isobject); if(ALTA_OK != r){ @@ -302,7 +302,7 @@ static int pollcapt(cc_capture_status *st, float *remain){ if(remain) *remain = 0.f; return TRUE; }else DBG("Capture in process"); - double d = exptime - (dtime() - tstart); + double d = exptime - (sl_dtime() - tstart); DBG("Poll capture, tremain=%g", d); if(d < -5.){ // capture error? WARNX("Abort capture"); diff --git a/Astar_cameras/artifical_star.c b/Astar_cameras/artifical_star.c index ab11657..a2439e3 100644 --- a/Astar_cameras/artifical_star.c +++ b/Astar_cameras/artifical_star.c @@ -231,21 +231,21 @@ static int campoll(cc_capture_status *st, float *remain){ if(remain) *remain = 0.; return TRUE; } - if(dtime() - texpstart > exptime){ + if(sl_dtime() - texpstart > exptime){ if(st) *st = CAPTURE_READY; if(remain) *remain = 0.; capstat = CAPTURE_NO; return TRUE; } if(st) *st = capstat; - if(remain) *remain = exptime + texpstart - dtime(); + if(remain) *remain = exptime + texpstart - sl_dtime(); return TRUE; } static int startexp(){ if(capstat == CAPTURE_PROCESS) return FALSE; capstat = CAPTURE_PROCESS; - double Tnow = dtime(), dT = Tnow - texpstart, Xcd, Ycd; + double Tnow = sl_dtime(), dT = Tnow - texpstart, Xcd, Ycd; if(dT < 0.) dT = 0.; else if(dT > 1.) dT = 1.; // dT for fluctuations amplitude if(Tstart < 0.) Tstart = Tnow; @@ -282,7 +282,7 @@ static int camcapt(cc_IMG *ima){ DBG("Prepare, xc=%d, yc=%d, bitpix=%d", Xc, Yc, bitpix); if(!ima || !ima->data) return FALSE; #ifdef EBUG - double t0 = dtime(); + double t0 = sl_dtime(); #endif ima->bitpix = bitpix; ima->w = camera.geometry.w; @@ -292,7 +292,7 @@ static int camcapt(cc_IMG *ima){ if(!star) ERRX(_("No star template - die")); if(bitpix == 16) gen16(ima); else gen8(ima); - DBG("Time of capture: %g", dtime() - t0); + DBG("Time of capture: %g", sl_dtime() - t0); return TRUE; } @@ -463,11 +463,11 @@ static cc_hresult setstarsamount(const char *str, cc_charbuff *ans){ } snprintf(buf, 31, "nstars=%d", settings.Nstars); cc_charbufaddline(ans, buf); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult setstarno(const char *str, cc_charbuff *ans){ - return RESULT_SILENCE; + return CC_RESULT_SILENCE; }*/ static cc_hresult setXYs(const char *str, cc_charbuff *ans){ @@ -479,7 +479,7 @@ static cc_hresult setXYs(const char *str, cc_charbuff *ans){ snprintf(buf, 255, "x[%d]=%g, y[%d]=%g\n", i, settings.xs[i], i, settings.ys[i]); cc_charbufaddline(ans, buf); } - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } double dval = atof(val); if(strcmp(bptr, "x") == 0){ @@ -493,9 +493,9 @@ static cc_hresult setXYs(const char *str, cc_charbuff *ans){ snprintf(buf, 255, "y[%d]=%g\n", settings.curstarno, dval); cc_charbufaddline(ans, buf); } - else{ return RESULT_BADKEY;} // unreachable + else{ return CC_RESULT_BADKEY;} // unreachable - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult setmag(const char *str, cc_charbuff *ans){ @@ -507,38 +507,38 @@ static cc_hresult setmag(const char *str, cc_charbuff *ans){ snprintf(buf, 255, "mag[%d]=%g", i, settings.mag[i]); cc_charbufaddline(ans, buf); } - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } double dval = atof(val); - if(strcmp(bptr, "mag") != 0) return RESULT_BADKEY; + if(strcmp(bptr, "mag") != 0) return CC_RESULT_BADKEY; if(dval > magmax || dval < magmin){ snprintf(buf, 255, "%g < mag < %g", magmin, magmax); cc_charbufaddline(ans, buf); - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } DBG("mag[%d]=%g", settings.curstarno, dval); settings.mag[settings.curstarno] = dval; snprintf(buf, 255, "mag[%d]=%g\n", settings.curstarno, dval); cc_charbufaddline(ans, buf); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult loadmask(const char *str, cc_charbuff *ans){ char buf[FILENAME_MAX+32], *bptr = buf; strncpy(buf, str, FILENAME_MAX+31); char *val = cc_get_keyval(&bptr); - if(strcmp(bptr, "mask") != 0) return RESULT_BADKEY; + if(strcmp(bptr, "mask") != 0) return CC_RESULT_BADKEY; if(imagemask) il_Image_free(&imagemask); imagemask = il_Image_read(val); char *nm = strdup (val); - cc_hresult res = RESULT_OK; + cc_hresult res = CC_RESULT_OK; if(!imagemask){ snprintf(buf, FILENAME_MAX, "Can't read image '%s'", nm); - res = RESULT_FAIL; + res = CC_RESULT_FAIL; }else{ if(imagemask->pixbytes != 1){ snprintf(buf, FILENAME_MAX, "Image '%s' isn't a 8-bit image", nm); - res = RESULT_FAIL; + res = CC_RESULT_FAIL; }else snprintf(buf, FILENAME_MAX, "Got image '%s'; w=%d, h=%d, type=%d (impix=%d)", nm, imagemask->width, imagemask->height, imagemask->type, imagemask->pixbytes); } @@ -551,14 +551,14 @@ static cc_hresult loadbg(const char *str, cc_charbuff *ans){ char buf[FILENAME_MAX+32], *bptr = buf; strncpy(buf, str, FILENAME_MAX+31); char *val = cc_get_keyval(&bptr); - if(strcmp(bptr, "bkg") != 0) return RESULT_BADKEY; + if(strcmp(bptr, "bkg") != 0) return CC_RESULT_BADKEY; if(imagebg) il_Image_free(&imagebg); imagebg = il_Image_read(val); char *nm = strdup (val); - cc_hresult res = RESULT_OK; + cc_hresult res = CC_RESULT_OK; if(!imagebg){ snprintf(buf, FILENAME_MAX, "Can't read image '%s'", nm); - res = RESULT_FAIL; + res = CC_RESULT_FAIL; }else{ snprintf(buf, FILENAME_MAX, "Got image '%s'; w=%d, h=%d, type=%d (impix=%d)", nm, imagebg->width, imagebg->height, imagebg->type, imagebg->pixbytes); } diff --git a/BASLER_cameras/basler.c b/BASLER_cameras/basler.c index 638dc66..8a28390 100644 --- a/BASLER_cameras/basler.c +++ b/BASLER_cameras/basler.c @@ -71,7 +71,7 @@ static char* describeError(GENAPIC_RESULT reserr){ #define PYLONFN(fn, ...) do{register GENAPIC_RESULT reserr; if(GENAPI_E_OK != (reserr=fn(__VA_ARGS__))){ \ WARNX(#fn "(): %s", describeError(reserr)); return FALSE;}}while(0) -static void disconnect(){ +static void b_disconnect(){ FNAME(); if(!isopened) return; FREE(imgBuf); @@ -188,13 +188,13 @@ static void disableauto(){ } static void GENAPIC_CC removalCallbackFunction(_U_ PYLON_DEVICE_HANDLE hDevice){ - disconnect(); + b_disconnect(); } -static int connect(){ +static int b_connect(){ FNAME(); size_t numDevices; - disconnect(); + b_disconnect(); PylonInitialize(); PYLONFN(PylonEnumerateDevices, &numDevices); if(!numDevices){ @@ -509,8 +509,8 @@ static void vstub(){ return ;} * Global objects: camera, focuser and wheel */ cc_Camera camera = { - .check = connect, - .close = disconnect, + .check = b_connect, + .close = b_disconnect, .pollcapture = pollcapt, .capture = capture, .cancel = vstub, diff --git a/CMakeLists.txt b/CMakeLists.txt index c034f7d..5c419d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ set(PROJ ccd_capture) set(PROJLIB ccdcapture) set(MAJOR_VERSION "1") set(MID_VERSION "2") -set(MINOR_VERSION "0") +set(MINOR_VERSION "1") set(LIBSRC ccdcapture.c) set(SOURCES main.c cmdlnopts.c ccdfunc.c server.c client.c) diff --git a/Dummy_cameras/dummyfunc.c b/Dummy_cameras/dummyfunc.c index 23fb0aa..fd1dd1e 100644 --- a/Dummy_cameras/dummyfunc.c +++ b/Dummy_cameras/dummyfunc.c @@ -51,21 +51,21 @@ static int campoll(cc_capture_status *st, float *remain){ if(remain) *remain = 0.; return TRUE; } - if(dtime() - texpstart > exptime){ + if(sl_dtime() - texpstart > exptime){ if(st) *st = CAPTURE_READY; if(remain) *remain = 0.; capstat = CAPTURE_NO; return TRUE; } if(st) *st = capstat; - if(remain) *remain = exptime + texpstart - dtime(); + if(remain) *remain = exptime + texpstart - sl_dtime(); return TRUE; } static int startexp(){ if(capstat == CAPTURE_PROCESS) return FALSE; capstat = CAPTURE_PROCESS; - texpstart = dtime(); + texpstart = sl_dtime(); return TRUE; } @@ -73,7 +73,7 @@ static int camcapt(cc_IMG *ima){ static int n = 0; if(!ima || !ima->data) return FALSE; #ifdef EBUG - double t0 = dtime(); + double t0 = sl_dtime(); #endif int y1 = ima->h * curvbin, x1 = ima->w * curhbin; if(bitpix == 16){ @@ -97,7 +97,7 @@ static int camcapt(cc_IMG *ima){ } ++n; ima->bitpix = bitpix; - DBG("Time of capture: %g", dtime() - t0); + DBG("Time of capture: %g", sl_dtime() - t0); return TRUE; } diff --git a/GRH_cameras/grasshopper.c b/GRH_cameras/grasshopper.c index f6c6e03..fdb8952 100644 --- a/GRH_cameras/grasshopper.c +++ b/GRH_cameras/grasshopper.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ static char camname[BUFSIZ] = {0}; #define FC2FN(fn, ...) do{err = FC2_ERROR_OK; if(FC2_ERROR_OK != (err=fn(context __VA_OPT__(,) __VA_ARGS__))){ \ WARNX(Stringify(fn) "(): %s", fc2ErrorToDescription(err)); return FALSE;}}while(0) -static void disconnect(){ +static void g_disconnect(){ FNAME(); if(!isopened) return; fc2DestroyContext(context); @@ -145,10 +146,10 @@ static void disableauto(){ propOnOff(FC2_FRAME_RATE, false); } -static int connect(){ +static int g_connect(){ FNAME(); unsigned int numDevices; - disconnect(); + g_disconnect(); DBG("fc2CreateContext"); if(FC2_ERROR_OK != (err = fc2CreateContext(&context))){ WARNX("fc2CreateContext(): %s", fc2ErrorToDescription(err)); @@ -321,16 +322,16 @@ static int capture(cc_IMG *ima){ int w2 = width<<1; OMP_FOR() for(int y = 0; y < height; ++y){ - uint16_t *Out = &ima->data[y*width]; - const uint8_t *In = &convertedImage.pData[y*stride]; + uint16_t *Out = &((uint16_t*)(ima->data))[y*width]; + const uint8_t *In = (uint8_t*)&convertedImage.pData[y*stride]; memcpy(Out, In, w2); //DBG("Row %d copied. First byte: %d", y, *((uint16_t*)In)); } }else{ OMP_FOR() for(int y = 0; y < height; ++y){ - uint16_t *Out = &ima->data[y*width]; - const uint8_t *In = &convertedImage.pData[y*stride]; + uint16_t *Out = &((uint16_t*)(ima->data))[y*width]; + const uint8_t *In = (uint8_t*)&convertedImage.pData[y*stride]; for(int x = 0; x < width; ++x){ *Out++ = *In++; } @@ -451,8 +452,8 @@ static int ipfalse(_U_ int *i){ return FALSE; } * Global objects: camera, focuser and wheel */ cc_Camera camera = { - .check = connect, - .close = disconnect, + .check = g_connect, + .close = g_disconnect, .pollcapture = pollcapt, .capture = capture, .cancel = capcancel, diff --git a/HIKROBOT_cameras/mvsfunc.c b/HIKROBOT_cameras/mvsfunc.c index 5f3ec59..e0f2adb 100644 --- a/HIKROBOT_cameras/mvsfunc.c +++ b/HIKROBOT_cameras/mvsfunc.c @@ -395,7 +395,7 @@ static int cam_startexp(){ MV_CC_StopGrabbing(handle); TRY(StartGrabbing); ONERR() return FALSE; - starttime = dtime(); + starttime = sl_dtime(); capStatus = CAPTURE_PROCESS; return TRUE; } @@ -422,7 +422,7 @@ static int cam_pollcapt(cc_capture_status *st, float *remain){ } DBG("not ready"); if(remain){ - float diff = exptime - (dtime() - starttime); + float diff = exptime - (sl_dtime() - starttime); DBG("diff = %g", diff); if(diff < -5.0){ capStatus = CAPTURE_NO; diff --git a/ZWO_cameras/zwofunc.c b/ZWO_cameras/zwofunc.c index adc7b12..f86e4d7 100644 --- a/ZWO_cameras/zwofunc.c +++ b/ZWO_cameras/zwofunc.c @@ -105,7 +105,7 @@ static int campoll(cc_capture_status *st, float *remain){ *st = CAPTURE_READY; } if(remain){ - float diff = exptime - (dtime() - starttime); + float diff = exptime - (sl_dtime() - starttime); if(diff < 0.) diff = 0.; *remain = diff; } @@ -141,7 +141,7 @@ static int startcapt(){ camcancel(); //red("ISDARK = %s\n", isdark ? "true" : "false"); if(ASI_SUCCESS == ASIStartExposure(caminfo.CameraID, isdark)){ - starttime = dtime(); + starttime = sl_dtime(); return TRUE; } return FALSE; diff --git a/ccdcapture.c b/ccdcapture.c index 65c13af..3372301 100644 --- a/ccdcapture.c +++ b/ccdcapture.c @@ -142,7 +142,7 @@ int cc_senddata(int fd, void *data, size_t l){ return FALSE; } DBG("success"); - if(globlog) LOGDBG("SEND data (size=%d) to fd %d", l, fd); + if(sl_globlog) LOGDBG("SEND data (size=%d) to fd %d", l, fd); return TRUE; } @@ -167,7 +167,7 @@ int cc_sendmessage(int fd, const char *msg, int l){ return FALSE; }else{ //DBG("success"); - if(globlog){ // logging turned ON + if(sl_globlog){ // logging turned ON tmpbuf[l-1] = 0; // remove trailing '\n' for logging LOGDBG("SEND '%s'", tmpbuf); } @@ -183,25 +183,27 @@ int cc_sendstrmessage(int fd, const char *msg){ // text messages for `cc_hresult` // WARNING! You should initialize ABSOLUTELY ALL members of `cc_hresult` or some pointers would give segfault -static const char *resmessages[RESULT_NUM] = { - [RESULT_OK] = "OK", - [RESULT_BUSY] = "BUSY", - [RESULT_FAIL] = "FAIL", - [RESULT_BADVAL] = "BADVAL", - [RESULT_BADKEY] = "BADKEY", +static const char *resmessages[CC_RESULT_NUM] = { + [CC_RESULT_OK] = "OK", + [CC_RESULT_BUSY] = "BUSY", + [CC_RESULT_FAIL] = "FAIL", + [CC_RESULT_BADVAL] = "BADVAL", + [CC_RESULT_BADKEY] = "BADKEY", + [CC_RESULT_SILENCE] = "", + [CC_RESULT_DISCONNECTED] = "DISCONNECTED", }; const char *cc_hresult2str(cc_hresult r){ - if(r < 0 || r >= RESULT_NUM) return "BADRESULT"; + if(r < 0 || r >= CC_RESULT_NUM) return "BADRESULT"; return resmessages[r]; } cc_hresult cc_str2hresult(const char *str){ - for(cc_hresult res = 0; res < RESULT_NUM; ++res){ + for(cc_hresult res = 0; res < CC_RESULT_NUM; ++res){ if(!resmessages[res]) continue; if(0 == strcmp(resmessages[res], str)) return res; } - return RESULT_NUM; // didn't find + return CC_RESULT_NUM; // didn't find } /** @@ -533,25 +535,25 @@ double cc_getAnsTmout(){return answer_timeout;} * @param fd - fd of socket * @param buf - buffer to store data read from socket * @param cmdwargs (i) - "par=val" - * @return RESULT_OK if got same string or other error + * @return CC_RESULT_OK if got same string or other error */ static cc_hresult ask4cmd(int fd, cc_strbuff *buf, const char *cmdwargs){ DBG("ask for command %s", cmdwargs); char *keyptr = strdup(cmdwargs), *key = keyptr; cc_get_keyval(&key); // pick out key from `cmdwargs` int l = strlen(key); - cc_hresult ret = RESULT_FAIL; + cc_hresult ret = CC_RESULT_FAIL; for(int i = 0; i < ntries; ++i){ DBG("Try %d time", i+1); if(!cc_sendstrmessage(fd, cmdwargs)) continue; - double t0 = dtime(); - while(dtime() - t0 < answer_timeout){ + double t0 = sl_dtime(); + while(sl_dtime() - t0 < answer_timeout){ int r = cc_canberead(fd); if(r == 0) continue; else if(r < 0){ LOGERR("Socket disconnected"); WARNX("Socket disconnected"); - ret = RESULT_DISCONNECTED; + ret = CC_RESULT_DISCONNECTED; goto rtn; } while(cc_refreshbuf(fd, buf)); @@ -563,11 +565,11 @@ static cc_hresult ask4cmd(int fd, cc_strbuff *buf, const char *cmdwargs){ LOGMSG("SERVER client fd=%d buffer overflow", fd); }else if(got){ if(strncmp(buf->string, key, l) == 0){ - ret = RESULT_OK; + ret = CC_RESULT_OK; goto rtn; }else{ // answers like 'OK' etc cc_hresult r = cc_str2hresult(buf->string); - if(r != RESULT_NUM){ // some other data + if(r != CC_RESULT_NUM){ // some other data ret = r; goto rtn; } @@ -604,13 +606,13 @@ cc_hresult cc_getint(int fd, cc_strbuff *cbuf, const char *cmd, int *val){ char buf[BBUFS+1]; snprintf(buf, BBUFS, "%s\n", cmd); cc_hresult r = ask4cmd(fd, cbuf, buf); - if(r == RESULT_OK){ + if(r == CC_RESULT_OK){ char *p = cbuf->string; char *sv = cc_get_keyval(&p); - if(!sv) return RESULT_FAIL; + if(!sv) return CC_RESULT_FAIL; char *ep; long L = strtol(sv, &ep, 0); - if(sv == ep || L < INT_MIN || L > INT_MAX) return RESULT_BADVAL; + if(sv == ep || L < INT_MIN || L > INT_MAX) return CC_RESULT_BADVAL; if(val) *val = (int) L; } return r; @@ -635,13 +637,13 @@ cc_hresult cc_getfloat(int fd, cc_strbuff *cbuf, const char *cmd, float *val){ char buf[BBUFS+1]; snprintf(buf, BBUFS, "%s\n", cmd); cc_hresult r = ask4cmd(fd, cbuf, buf); - if(r == RESULT_OK){ + if(r == CC_RESULT_OK){ char *p = cbuf->string; char *sv = cc_get_keyval(&p); - if(!sv) return RESULT_FAIL; + if(!sv) return CC_RESULT_FAIL; char *ep; double d = strtod(sv, &ep); - if(sv == ep || d < (-FLT_MAX) || d > FLT_MAX) return RESULT_BADVAL; + if(sv == ep || d < (-FLT_MAX) || d > FLT_MAX) return CC_RESULT_BADVAL; if(val) *val = (float)d; } return r; @@ -672,7 +674,7 @@ char *cc_nextkw(char *buf, char record[FLEN_CARD+1], int newlines){ */ size_t cc_kwfromfile(cc_charbuff *b, char *filename){ if(!b) return 0; - mmapbuf *buf = My_mmap(filename); + sl_mmapbuf_t *buf = sl_mmap(filename); if(!buf || buf->len < 1){ WARNX("Can't add FITS records from file %s", filename); LOGWARN("Can't add FITS records from file %s", filename); @@ -693,7 +695,7 @@ size_t cc_kwfromfile(cc_charbuff *b, char *filename){ if(status) fits_report_error(stderr, status); else cc_charbufaddline(b, card); }while(data && *data); - My_munmap(buf); + sl_munmap(buf); return b->buflen - blen0; } @@ -760,30 +762,30 @@ static size_t print_val(cc_partype_t t, void *val, char *buf, size_t bufl){ * @param str - string like "par" (getter/cmd) or "par=val" (setter) * @param handlers - NULL-terminated array of handlers for custom commands * @param ans - buffer for output string - * @return RESULT_OK if all OK or error code + * @return CC_RESULT_OK if all OK or error code */ cc_hresult cc_plugin_customcmd(const char *str, cc_parhandler_t *handlers, cc_charbuff *ans){ - if(!str || !handlers) return RESULT_FAIL; + if(!str || !handlers) return CC_RESULT_FAIL; char key[256], *kptr = key; snprintf(key, 255, "%s", str); char *val = cc_get_keyval(&kptr); cc_parhandler_t *phptr = handlers; - cc_hresult result = RESULT_BADKEY; + cc_hresult result = CC_RESULT_BADKEY; char buf[512]; #define ADDL(...) do{if(ans){size_t l = snprintf(bptr, L, __VA_ARGS__); bptr += l; L -= l;}}while(0) #define PRINTVAL(v) do{if(ans){size_t l = print_val(phptr->type, phptr->v, bptr, L); bptr += l; L -= l;}}while(0) while(phptr->cmd){ if(0 == strcmp(kptr, phptr->cmd)){ char *bptr = buf; size_t L = 511; - result = RESULT_OK; + result = CC_RESULT_OK; if(phptr->checker) result = phptr->checker(str, ans); if(phptr->ptr){ // setter/getter - if(val){if(result == RESULT_OK){// setter: change value only if [handler] returns OK (`handler` could be value checker) + if(val){if(result == CC_RESULT_OK){// setter: change value only if [handler] returns OK (`handler` could be value checker) int ival; float fval; double dval; #define UPDATE_VAL(type, val, pr) do{ \ - if(phptr->max && val > *(type*)phptr->max){ADDL("max=" pr, *(type*)phptr->max); result = RESULT_BADVAL;} \ - if(phptr->min && val < *(type*)phptr->min){ADDL("min=" pr, *(type*)phptr->min); result = RESULT_BADVAL;} \ - if(result == RESULT_OK) *(type*)phptr->ptr = val; \ + if(phptr->max && val > *(type*)phptr->max){ADDL("max=" pr, *(type*)phptr->max); result = CC_RESULT_BADVAL;} \ + if(phptr->min && val < *(type*)phptr->min){ADDL("min=" pr, *(type*)phptr->min); result = CC_RESULT_BADVAL;} \ + if(result == CC_RESULT_OK) *(type*)phptr->ptr = val; \ }while(0) switch(phptr->type){ case CC_PAR_INT: @@ -803,12 +805,12 @@ cc_hresult cc_plugin_customcmd(const char *str, cc_parhandler_t *handlers, cc_ch *(char**)phptr->ptr = strdup(val); break; default: - result = RESULT_FAIL; + result = CC_RESULT_FAIL; } #undef UPDATE_VAL - }}else result = RESULT_SILENCE; // getter - don't show "OK" + }}else result = CC_RESULT_SILENCE; // getter - don't show "OK" DBG("res=%d", result); - if(result == RESULT_SILENCE || result == RESULT_OK){ + if(result == CC_RESULT_SILENCE || result == CC_RESULT_OK){ ADDL("%s=", phptr->cmd); PRINTVAL(ptr); } @@ -818,7 +820,7 @@ cc_hresult cc_plugin_customcmd(const char *str, cc_parhandler_t *handlers, cc_ch } ++phptr; } - if(ans && result == RESULT_BADKEY){ // cmd not found - display full help + if(ans && result == CC_RESULT_BADKEY){ // cmd not found - display full help cc_charbufaddline(ans, "Custom plugin commands:\n"); phptr = handlers; while(phptr->cmd){ diff --git a/ccdcapture.h b/ccdcapture.h index ba1bcc0..ee351e1 100644 --- a/ccdcapture.h +++ b/ccdcapture.h @@ -91,14 +91,14 @@ typedef enum{ } cc_fan_speed; typedef enum{ - RESULT_OK, // 0: all OK - RESULT_BUSY, // 1: camera busy and no setters can be done - RESULT_FAIL, // 2: failed running command - RESULT_BADVAL, // 3: bad key's value - RESULT_BADKEY, // 4: bad key - RESULT_SILENCE, // 5: send nothing to client - RESULT_DISCONNECTED,// 6: client disconnected - RESULT_NUM + CC_RESULT_OK, // 0: all OK + CC_RESULT_BUSY, // 1: camera busy and no setters can be done + CC_RESULT_FAIL, // 2: failed running command + CC_RESULT_BADVAL, // 3: bad key's value + CC_RESULT_BADKEY, // 4: bad key + CC_RESULT_SILENCE, // 5: send nothing to client + CC_RESULT_DISCONNECTED,// 6: client disconnected + CC_RESULT_NUM } cc_hresult; // all setters and getters of Camera, Focuser and cc_Wheel should return TRUE if success or FALSE if failed or unsupported camera diff --git a/ccdfunc.c b/ccdfunc.c index b1f7e0b..2e2c268 100644 --- a/ccdfunc.c +++ b/ccdfunc.c @@ -225,7 +225,7 @@ int saveFITS(cc_IMG *img, char **outp){ long naxes[2] = {width, height}; struct tm *tm_time; char bufc[FLEN_CARD]; - double dsavetime = dtime(); + double dsavetime = sl_dtime(); time_t savetime = time(NULL); fitsfile *fp; fitserror = 0; @@ -615,12 +615,12 @@ int prepare_ccds(){ while(p && *p){ cc_charbufclr(b); cc_hresult r = camera->plugincmd(*p, b); - if(r == RESULT_OK || r == 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); } - if(r != 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; @@ -788,8 +788,8 @@ DBG("w=%d, h=%d", raw_width, raw_height); saveFITS(&ima, NULL); TIMESTAMP("Ready"); if(GP->pause_len && j != (GP->nframes - 1)){ - double delta, time1 = dtime() + GP->pause_len; - while((delta = time1 - dtime()) > 0.){ + double delta, time1 = sl_dtime() + GP->pause_len; + while((delta = time1 - sl_dtime()) > 0.){ verbose(1, _("%d seconds till pause ends\n"), (int)delta); float tmpf; if(camera->getTcold && camera->getTcold(&tmpf)) verbose(1, "CCDTEMP=%.1f\n", tmpf); @@ -819,8 +819,8 @@ void framerate(){ if(GP->verbose == 0) return; static double tlast = 0., lastn[NFRM] = {0.}, sumn = 0.; static int lastidx = 0; - if(tlast == 0.){tlast = dtime(); return;} - double t = dtime(), dT = t-tlast; + if(tlast == 0.){tlast = sl_dtime(); return;} + double t = sl_dtime(), dT = t-tlast; if(++lastidx > NFRM-1) lastidx = 0; sumn = sumn - lastn[lastidx] + dT; lastn[lastidx] = dT; diff --git a/client.c b/client.c index b488dfd..7a2fc54 100644 --- a/client.c +++ b/client.c @@ -83,12 +83,12 @@ static int parseans(char *ans){ if(!ans) return FALSE; //TIMESTAMP("parseans() begin"); //DBG("Parsing of '%s'", ans); - if(0 == strcmp(cc_hresult2str(RESULT_BUSY), ans)){ + if(0 == strcmp(cc_hresult2str(CC_RESULT_BUSY), ans)){ WARNX("Server busy"); return FALSE; } - if(0 == strcmp(cc_hresult2str(RESULT_FAIL), ans)) return TRUE; - if(0 == strcmp(cc_hresult2str(RESULT_OK), ans)) return TRUE; + if(0 == strcmp(cc_hresult2str(CC_RESULT_FAIL), ans)) return TRUE; + if(0 == strcmp(cc_hresult2str(CC_RESULT_OK), ans)) return TRUE; char *val = cc_get_keyval(&ans); // now `ans` is a key and `val` its value if(0 == strcmp(CC_CMD_EXPSTATE, ans)){ expstate = atoi(val); @@ -110,12 +110,12 @@ static int parseans(char *ans){ // read until timeout all messages from server; return FALSE if there was no messages from server // if msg != NULL - wait for it in answer static int getans(int sock, const char *msg){ - double t0 = dtime(); + double t0 = sl_dtime(); char *ans = NULL; - while(dtime() - t0 < answer_timeout){ + while(sl_dtime() - t0 < answer_timeout){ char *s = readmsg(sock); if(!s) continue; - t0 = dtime(); + t0 = sl_dtime(); ans = s; TIMESTAMP("Got from server: %s", ans); verbose(1, "\t%s", ans); @@ -240,7 +240,7 @@ void client(int sock){ return; } send_headers(sock); - double t0 = dtime(), tw = t0; + double t0 = sl_dtime(), tw = t0; int Nremain = 0, nframe = 1; // if client gives filename/prefix or Nframes, make exposition if((GP->outfile && *GP->outfile) || (GP->outfileprefix && *GP->outfileprefix) || GP->nframes > 0){ @@ -250,7 +250,7 @@ void client(int sock){ SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); }else{ int cntr = 0; - while(dtime() - t0 < CC_WAIT_TIMEOUT && cntr < 3) + while(sl_dtime() - t0 < CC_WAIT_TIMEOUT && cntr < 3) if(!getans(sock, NULL)) ++cntr; DBG("RETURN: no more data"); return; @@ -261,16 +261,16 @@ void client(int sock){ expstate = CAMERA_CAPTURE; // could be changed earlier verbose(2, "Wait for exposition end"); } - while(dtime() - t0 < timeout){ - if(GP->waitexpend && dtime() - tw > CC_WAIT_TIMEOUT){ + while(sl_dtime() - t0 < timeout){ + if(GP->waitexpend && sl_dtime() - tw > CC_WAIT_TIMEOUT){ SENDCMDW(CC_CMD_TREMAIN); // get remained time - tw = dtime(); + tw = sl_dtime(); sprintf(sendbuf, "%s", CC_CMD_EXPSTATE); cc_sendstrmessage(sock, sendbuf); } if(getans(sock, NULL)){ // got next portion of data DBG("server message"); - t0 = dtime(); + t0 = sl_dtime(); if(expstate == CAMERA_ERROR){ WARNX(_("Can't make exposition")); continue; @@ -282,10 +282,10 @@ void client(int sock){ if(Nremain){ verbose(1, "\n"); if(GP->pause_len > 0){ - double delta, time1 = dtime() + GP->pause_len; + double delta, time1 = sl_dtime() + GP->pause_len; while(1){ SENDCMDW(CC_CMD_CAMTEMPER); - if((delta = time1 - dtime()) < __FLT_EPSILON__) break; + if((delta = time1 - sl_dtime()) < __FLT_EPSILON__) break; if(delta > 1.) verbose(1, _("%d seconds till pause ends\n"), (int)delta); if(delta > 6.) sleep(5); else if(delta > 1.) sleep((int)delta); @@ -303,6 +303,11 @@ void client(int sock){ } } if(GP->waitexpend) WARNX(_("Server timeout")); + // clear "filename" and "filenameprefix" + SENDMSGW(CC_CMD_FILENAME, "="); + SENDMSGW(CC_CMD_FILENAMEPREFIX, "="); + // clear "rewrite" + SENDMSGW(CC_CMD_REWRITE, "=0"); DBG("Timeout"); } @@ -323,8 +328,9 @@ void init_grab_sock(int sock){ */ static int readNbytes(int fd, size_t N, uint8_t *buf){ size_t got = 0, need = N; - double t0 = dtime(); - while(dtime() - t0 < CC_CLIENT_TIMEOUT /*&& cc_canberead(fd)*/ && need){ + double t0 = sl_dtime(); + while(sl_dtime() - t0 < CC_CLIENT_TIMEOUT /*&& cc_canberead(fd)*/ && need){ + t0 = sl_dtime(); ssize_t rd = read(fd, buf + got, need); if(rd <= 0){ WARNX("Server disconnected"); @@ -344,8 +350,6 @@ static void getimage(){ int imsock = -1; static double oldtimestamp = -1.; TIMESTAMP("Get image sizes"); - /*SENDCMDW(CC_CMD_IMWIDTH); - SENDCMDW(CC_CMD_IMHEIGHT);*/ if(shmima){ // read image from shared memory memcpy(&ima, shmima, sizeof(cc_IMG)); }else{ // get image by socket @@ -402,23 +406,23 @@ static void *grabnext(void _U_ *arg){ // daemon grabbing images through the net expstate = CAMERA_CAPTURE; TIMEINIT(); SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); // start capture - double timeout = GP->exptime + CC_CLIENT_TIMEOUT, t0 = dtime(); + double timeout = GP->exptime + CC_CLIENT_TIMEOUT, t0 = sl_dtime(); useconds_t sleept = 500000; // 0.5s if(GP->exptime < 0.5){ sleept = (useconds_t)(GP->exptime * 500000.); if(sleept < 1000) sleept = 1000; } // double exptime = GP->exptime; - while(dtime() - t0 < timeout){ + while(sl_dtime() - t0 < timeout){ TIMESTAMP("Wait for exposition ends (%u us)", sleept); usleep(sleept); TIMESTAMP("check answer"); - getans(sock, NULL); + // getans(sock, NULL); //TIMESTAMP("EXPSTATE ===> %d", expstate); if(expstate != CAMERA_CAPTURE) break; - if(dtime() - t0 < GP->exptime + 0.5) sleept = 1000; + if(sl_dtime() - t0 < GP->exptime + 0.5) sleept = 1000; } - if(dtime() - t0 >= timeout || expstate != CAMERA_FRAMERDY){ + if(sl_dtime() - t0 >= timeout || expstate != CAMERA_FRAMERDY){ WARNX("Image wasn't received"); continue; } diff --git a/cmdlnopts.c b/cmdlnopts.c index d274137..9830898 100644 --- a/cmdlnopts.c +++ b/cmdlnopts.c @@ -44,7 +44,7 @@ static glob_pars G = { * Define command line options by filling structure: * name has_arg flag val type argptr help */ -myoption cmdlnopts[] = { +sl_option_t cmdlnopts[] = { {"plugin" ,NEED_ARG, NULL, NA, arg_string, APTR(&G.commondev), N_("common device plugin (e.g devfli.so)")}, {"plugincmd",MULT_PAR, NULL, '_', arg_string, APTR(&G.plugincmd), N_("custom camera device plugin command")}, {"cameradev", NEED_ARG, NULL, 'C', arg_string, APTR(&G.cameradev), N_("camera device plugin (e.g. devfli.so)")}, @@ -133,10 +133,10 @@ myoption cmdlnopts[] = { */ glob_pars *parse_args(int argc, char **argv){ // format of help: "Usage: progname [args]\n" - change_helpstring("Version: " PACKAGE_VERSION "\nUsage: %s [args] [output file prefix]\nTo restart server kill it with SIGUSR1\n\tArgs are:\n"); + sl_helpstring("Version: " PACKAGE_VERSION "\nUsage: %s [args] [output file prefix]\nTo restart server kill it with SIGUSR1\n\tArgs are:\n"); // parse arguments - parseargs(&argc, &argv, cmdlnopts); - if(help) showhelp(-1, cmdlnopts); + sl_parseargs(&argc, &argv, cmdlnopts); + if(help) sl_showhelp(-1, cmdlnopts); if(argc > 0){ G.outfileprefix = strdup(argv[0]); if(argc > 1){ diff --git a/examples/ccd_client.c b/examples/ccd_client.c index f1f263b..65bcfa7 100644 --- a/examples/ccd_client.c +++ b/examples/ccd_client.c @@ -48,7 +48,7 @@ static glob_pars G = { * Define command line options by filling structure: * name has_arg flag val type argptr help */ -myoption cmdlnopts[] = { +sl_option_t cmdlnopts[] = { {"sock", NEED_ARG, NULL, 's', arg_string, APTR(&G.sockname), "command socket name or port"}, {"isun", NO_ARGS, NULL, 'U', arg_int, APTR(&G.isun), "use UNIX socket"}, {"shmkey", NEED_ARG, NULL, 'k', arg_int, APTR(&G.shmkey), "shared memory (with image data) key (default: 7777777)"}, @@ -64,7 +64,7 @@ static int refresh_img(){ if(!shimg) return FALSE; static size_t imnumber = 0; if(shimg->imnumber == imnumber) return FALSE; - double ts = dtime(); + double ts = sl_dtime(); if(ts - shimg->timestamp > G.exptime + 1.) return FALSE; // too old image imnumber = shimg->imnumber; void *optr = img.data; @@ -77,9 +77,9 @@ static int refresh_img(){ #define STRBUFSZ (256) int main(int argc, char **argv){ - initial_setup(); - parseargs(&argc, &argv, cmdlnopts); - if(G.help) showhelp(-1, cmdlnopts); + sl_init(); + sl_parseargs(&argc, &argv, cmdlnopts); + if(G.help) sl_showhelp(-1, cmdlnopts); if(argc > 0){ WARNX("%d unused parameters:", argc); for(int i = 0; i < argc; ++i) @@ -91,23 +91,23 @@ int main(int argc, char **argv){ int sock = cc_open_socket(FALSE, G.sockname, !G.isun); if(sock < 0) ERR("Can't open socket %s", G.sockname); int shmemkey = 0; - if(RESULT_OK == cc_getint(sock, cbuf, CC_CMD_SHMEMKEY, &shmemkey)){ + if(CC_RESULT_OK == cc_getint(sock, cbuf, CC_CMD_SHMEMKEY, &shmemkey)){ green("Got shm key: %d\n", shmemkey); }else{ red("Can't read shmkey, try yours\n"); shmemkey = G.shmkey; } if(G.infty){ - if(RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n"); + if(CC_RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n"); else red("Can't ask for INFTY\n"); } float xt = 0.f; - if(RESULT_OK == cc_getfloat(sock, cbuf, CC_CMD_EXPOSITION, &xt)){ + if(CC_RESULT_OK == cc_getfloat(sock, cbuf, CC_CMD_EXPOSITION, &xt)){ green("Old exp time: %gs\n", xt); } fflush(stdout); if(G.exptime > 0.){ - if(RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, G.exptime)) green("ask for exptime %gs\n", G.exptime); + if(CC_RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, G.exptime)) green("ask for exptime %gs\n", G.exptime); else red("Can't change exptime to %gs\n", G.exptime); } shimg = cc_getshm(shmemkey, 0); @@ -117,7 +117,7 @@ int main(int argc, char **argv){ double waittime = ((int)G.exptime) + 5.; do{ if(!G.infty){ // ask new image in non-infty mode - if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_EXPSTATE, CAMERA_CAPTURE)){ + if(CC_RESULT_OK != cc_setint(sock, cbuf, CC_CMD_EXPSTATE, CAMERA_CAPTURE)){ WARNX("Can't ask new image\n"); usleep(1000); continue; @@ -141,10 +141,10 @@ int main(int argc, char **argv){ printf("Got image #%zd, size %dx%d, bitpix %d, time %.2f\n", img.imnumber, img.w, img.h, img.bitpix, img.timestamp); }while(i < G.nframes); if(G.infty){ - if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n"); + if(CC_RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n"); } if(xt > 0.){ - if(RESULT_OK != cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, xt)) red("Can't return exptime to %gs\n", xt); + if(CC_RESULT_OK != cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, xt)) red("Can't return exptime to %gs\n", xt); } cc_strbufdel(&cbuf); close(sock); diff --git a/examples/centroids.c b/examples/centroids.c index 478e6b4..3fbd4bf 100644 --- a/examples/centroids.c +++ b/examples/centroids.c @@ -54,7 +54,7 @@ static glob_pars G = { * Define command line options by filling structure: * name has_arg flag val type argptr help */ -myoption cmdlnopts[] = { +sl_option_t cmdlnopts[] = { {"background",NEED_ARG, NULL, 'b', arg_double, APTR(&G.background),"fixed background level"}, {"sock", NEED_ARG, NULL, 's', arg_string, APTR(&G.sockname), "command socket name or port"}, {"isun", NO_ARGS, NULL, 'U', arg_int, APTR(&G.isun), "use UNIX socket"}, @@ -80,7 +80,7 @@ static void calcimg(){ sqsz = m; }*/ double Xs = 0., X2s = 0., Ys = 0., Y2s = 0., Is = 0; - double t0 = dtime(); + double t0 = sl_dtime(); uint8_t *d = (uint8_t*)img.data; double Timestamp = img.timestamp; static double bg = -1.; @@ -129,7 +129,7 @@ static void calcimg(){ il_write_png(buf, W, H, 1, img.data);*/ printf("Xs=%g, X2s=%g, Ys=%g, Y2s=%g, Is=%g\n", Xs, X2s, Ys, Y2s, Is); double xc = Xs/Is, yc = Ys/Is, sX = sqrt(X2s/Is-xc*xc), sY = sqrt(Y2s/Is-yc*yc); - green("Xc = %.2f, Yc=%.2f, Xcs=%.2f, Ycs=%.2f, I=%.1f, T=%gms; npix=%d\n", xc, yc, sX, sY, Is, (dtime() - t0)*1e3, npix); + green("Xc = %.2f, Yc=%.2f, Xcs=%.2f, Ycs=%.2f, I=%.1f, T=%gms; npix=%d\n", xc, yc, sX, sY, Is, (sl_dtime() - t0)*1e3, npix); if(out) fprintf(out, "%.2f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n", Timestamp, xc, yc, Is, sX, sY); } @@ -137,7 +137,7 @@ static int refresh_img(){ if(!shimg) return FALSE; static size_t imnumber = 0; if(shimg->imnumber == imnumber) return FALSE; - double ts = dtime(); + double ts = sl_dtime(); if(ts - shimg->timestamp > G.exptime + 1.) return FALSE; // too old image imnumber = shimg->imnumber; void *optr = img.data; @@ -149,9 +149,9 @@ static int refresh_img(){ } int main(int argc, char **argv){ - initial_setup(); - parseargs(&argc, &argv, cmdlnopts); - if(G.help) showhelp(-1, cmdlnopts); + sl_init(); + sl_parseargs(&argc, &argv, cmdlnopts); + if(G.help) sl_showhelp(-1, cmdlnopts); if(argc > 0){ WARNX("%d unused parameters:", argc); for(int i = 0; i < argc; ++i) @@ -168,26 +168,26 @@ int main(int argc, char **argv){ int sock = cc_open_socket(FALSE, G.sockname, !G.isun); if(sock < 0) ERR("Can't open socket %s", G.sockname); int shmemkey = 0; - if(RESULT_OK == cc_getint(sock, cbuf, CC_CMD_SHMEMKEY, &shmemkey)){ + if(CC_RESULT_OK == cc_getint(sock, cbuf, CC_CMD_SHMEMKEY, &shmemkey)){ green("Got shm key: %d\n", shmemkey); }else{ red("Can't read shmkey, try yours\n"); shmemkey = G.shmkey; } - if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_8BIT, 1)){ + if(CC_RESULT_OK != cc_setint(sock, cbuf, CC_CMD_8BIT, 1)){ ERRX("Can't set 8 bit mode"); } if(G.infty){ - if(RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n"); + if(CC_RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n"); else red("Can't ask for INFTY\n"); } float xt = 0.f; - if(RESULT_OK == cc_getfloat(sock, cbuf, CC_CMD_EXPOSITION, &xt)){ + if(CC_RESULT_OK == cc_getfloat(sock, cbuf, CC_CMD_EXPOSITION, &xt)){ green("Old exp time: %gs\n", xt); } fflush(stdout); if(G.exptime > 0.){ - if(RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, G.exptime)) green("ask for exptime %gs\n", G.exptime); + if(CC_RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, G.exptime)) green("ask for exptime %gs\n", G.exptime); else red("Can't change exptime to %gs\n", G.exptime); }else G.exptime = xt; shimg = cc_getshm(shmemkey, 0); @@ -197,7 +197,7 @@ int main(int argc, char **argv){ double waittime = ((int)G.exptime) + 5.; do{ if(!G.infty){ // ask new image in non-infty mode - if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_EXPSTATE, CAMERA_CAPTURE)){ + if(CC_RESULT_OK != cc_setint(sock, cbuf, CC_CMD_EXPSTATE, CAMERA_CAPTURE)){ WARNX("Can't ask new image\n"); usleep(1000); continue; @@ -221,10 +221,10 @@ int main(int argc, char **argv){ printf("Got image #%zd, size %dx%d, bitpix %d, time %.2f\n", img.imnumber, img.w, img.h, img.bitpix, img.timestamp); }while(i < G.nframes); if(G.infty){ - if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n"); + if(CC_RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n"); } if(xt > 0.){ - if(RESULT_OK != cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, xt)) red("Can't return exptime to %gs\n", xt); + if(CC_RESULT_OK != cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, xt)) red("Can't return exptime to %gs\n", xt); } cc_strbufdel(&cbuf); close(sock); diff --git a/locale/ru/messages.po b/locale/ru/messages.po index 8a3579a..8dd5f5a 100644 --- a/locale/ru/messages.po +++ b/locale/ru/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-04-10 17:06+0300\n" +"POT-Creation-Date: 2025-04-16 09:25+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/locale/ru/ru.po b/locale/ru/ru.po index 24a9ab2..b1809dc 100644 --- a/locale/ru/ru.po +++ b/locale/ru/ru.po @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" - "POT-Creation-Date: 2025-04-10 17:05+0300\n" + "POT-Creation-Date: 2025-04-16 08:48+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/main.c b/main.c index 57dbdb3..9c61027 100644 --- a/main.c +++ b/main.c @@ -69,7 +69,7 @@ void signals(int signo){ } int main(int argc, char **argv){ - initial_setup(); + sl_init(); #if defined GETTEXT_PACKAGE && defined LOCALEDIR //printf("GETTEXT_PACKAGE=" GETTEXT_PACKAGE ", LOCALEDIR=" LOCALEDIR "\n"); bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); @@ -121,7 +121,7 @@ int main(int argc, char **argv){ if(lvl > LOGLEVEL_ANY) lvl = LOGLEVEL_ANY; verbose(1, "Log file %s @ level %d\n", GP->logfile, lvl); OPENLOG(GP->logfile, lvl, 1); - if(!globlog) WARNX("Can't create log file"); + if(!sl_globlog) WARNX("Can't create log file"); } signal(SIGINT, signals); signal(SIGQUIT, signals); @@ -156,11 +156,11 @@ int main(int argc, char **argv){ while(1){ childpid = fork(); if(childpid){ // master - double t0 = dtime(); + double t0 = sl_dtime(); LOGMSG("Created child with pid %d", childpid); wait(NULL); LOGERR("Child %d died", childpid); - if(dtime() - t0 < 1.) pause += 5; + if(sl_dtime() - t0 < 1.) pause += 5; else pause = 1; if(pause > 900) pause = 900; sleep(pause); // wait a little before respawn diff --git a/server.c b/server.c index 3513c72..3b294ee 100644 --- a/server.c +++ b/server.c @@ -181,7 +181,7 @@ static inline void cameracapturestate(){ // capturing - wait for exposition ends return; }else{ ima->gotstat = 0; // fresh image without statistics - recalculate when save - ima->timestamp = dtime(); // set timestamp + ima->timestamp = sl_dtime(); // set timestamp ++ima->imnumber; // increment counter if(saveFITS(ima, &lastfile)){ DBG("LAST file name changed"); @@ -210,8 +210,8 @@ static void* processCAM(_U_ void *d){ if(tremain < 0.5 && tremain > 0.) usleep(tremain*1e6); if(lock()){ // log - if(dtime() - logt > TLOG_PAUSE){ - logt = dtime(); + if(sl_dtime() - logt > TLOG_PAUSE){ + logt = sl_dtime(); float t; if(camera->getTcold && camera->getTcold(&t)){ LOGMSG("CCDTEMP=%.1f", t); @@ -310,7 +310,7 @@ static int wheeldevini(int n){ ******************************************************************************/ static cc_hresult restarthandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ camflags |= FLAG_RESTARTSERVER; - return RESULT_OK; + return CC_RESULT_OK; } /******************************************************************************* @@ -322,33 +322,33 @@ static cc_hresult imsizehandler(int fd, const char *key, _U_ const char *val){ // send image width/height in pixels if(0 == strcmp(key, CC_CMD_IMHEIGHT)) snprintf(buf, 63, CC_CMD_IMHEIGHT "=%d", ima->h); else snprintf(buf, 63, CC_CMD_IMWIDTH "=%d", ima->w); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult camlisthandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[BUFSIZ], modname[256]; - if(!camera->getModelName) return RESULT_FAIL; + if(!camera->getModelName) return CC_RESULT_FAIL; for(int i = 0; i < camera->Ndevices; ++i){ if(camera->setDevNo && !camera->setDevNo(i)) continue; camera->getModelName(modname, 255); snprintf(buf, BUFSIZ-1, CC_CMD_CAMLIST "='%s'", modname); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(camdevno > -1 && camera->setDevNo) camera->setDevNo(camdevno); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult camsetNhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int num = atoi(val); if(num > camera->Ndevices - 1 || num < 0){ - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } - if(!camdevini(num)) return RESULT_FAIL; + if(!camdevini(num)) return CC_RESULT_FAIL; } snprintf(buf, 63, CC_CMD_CAMDEVNO "=%d", camdevno); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // exposition time setter/getter static cc_hresult exphandler(int fd, _U_ const char *key, const char *val){ @@ -356,24 +356,24 @@ static cc_hresult exphandler(int fd, _U_ const char *key, const char *val){ if(val){ DBG("setexp to %s", val); double v = atof(val); - if(v < DBL_EPSILON) return RESULT_BADVAL; - if(!camera->setexp) return RESULT_FAIL; + if(v < DBL_EPSILON) return CC_RESULT_BADVAL; + if(!camera->setexp) return CC_RESULT_FAIL; if(camera->setexp(v)){ GP->exptime = v; }else LOGWARN("Can't set exptime to %g", v); } DBG("expt: %g", GP->exptime); snprintf(buf, 63, CC_CMD_EXPOSITION "=%g", GP->exptime); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // show last filename of saved FITS static cc_hresult lastfnamehandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[PATH_MAX+32]; if(lastfile && *lastfile) snprintf(buf, PATH_MAX+31, CC_CMD_LASTFNAME "=%s", lastfile); else snprintf(buf, PATH_MAX+31, CC_CMD_LASTFNAME "="); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // filename setter/getter static cc_hresult namehandler(int fd, _U_ const char *key, const char *val){ @@ -384,7 +384,7 @@ static cc_hresult namehandler(int fd, _U_ const char *key, const char *val){ char *path = makeabspath(val, FALSE); if(!path){ LOGERR("Can't create file '%s'", val); - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } FREE(outfile); outfile = strdup(path); @@ -394,12 +394,12 @@ static cc_hresult namehandler(int fd, _U_ const char *key, const char *val){ DBG("Clear names"); GP->outfileprefix = NULL; GP->outfile = NULL; - return RESULT_OK; + return CC_RESULT_OK; } - if(!GP->outfile) return RESULT_FAIL; + if(!GP->outfile) return CC_RESULT_FAIL; snprintf(buf, PATH_MAX+31, CC_CMD_FILENAME "=%s", GP->outfile); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // filename prefix static cc_hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){ @@ -409,7 +409,7 @@ static cc_hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char char *path = makeabspath(val, FALSE); if(!path){ LOGERR("Can't create file '%s'", val); - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } FREE(outfile); outfile = strdup(path); @@ -418,174 +418,174 @@ static cc_hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char }else{ // clear names GP->outfileprefix = NULL; GP->outfile = NULL; - return RESULT_OK; + return CC_RESULT_OK; } - if(!GP->outfileprefix) return RESULT_FAIL; + if(!GP->outfileprefix) return CC_RESULT_FAIL; snprintf(buf, PATH_MAX+31, CC_CMD_FILENAMEPREFIX "=%s", GP->outfileprefix); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // rewrite static cc_hresult rewritefilehandler(_U_ int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int n = atoi(val); - if(n < 0 || n > 1) return RESULT_BADVAL; + if(n < 0 || n > 1) return CC_RESULT_BADVAL; GP->rewrite = n; } snprintf(buf, 63, CC_CMD_REWRITE "=%d", GP->rewrite); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult binhandler(_U_ int fd, const char *key, const char *val){ char buf[64]; if(val){ int b = atoi(val); - if(b < 1) return RESULT_BADVAL; + if(b < 1) return CC_RESULT_BADVAL; if(0 == strcmp(key, CC_CMD_HBIN)) GP->hbin = b; else GP->vbin = b; - if(!camera->setbin) return RESULT_FAIL; + if(!camera->setbin) return CC_RESULT_FAIL; if(!camera->setbin(GP->hbin, GP->vbin)){ - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } } - if(!camera->getbin) return RESULT_SILENCE; + if(!camera->getbin) return CC_RESULT_SILENCE; int r = camera->getbin(&GP->hbin, &GP->vbin); if(r){ if(0 == strcmp(key, CC_CMD_HBIN)) snprintf(buf, 63, "%s=%d", key, GP->hbin); else snprintf(buf, 63, "%s=%d", key, GP->vbin); if(val) fixima(); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } - return RESULT_FAIL; + return CC_RESULT_FAIL; } static cc_hresult temphandler(int fd, _U_ const char *key, const char *val){ float f; char buf[64]; int r; - if(!camera->setT) return RESULT_FAIL; + if(!camera->setT) return CC_RESULT_FAIL; if(val){ f = atof(val); r = camera->setT((float)f); if(!r){ LOGWARN("Can't set camera T to %.1f", f); - return RESULT_FAIL; + return CC_RESULT_FAIL; } LOGMSG("Set camera T to %.1f", f); } - if(!camera->getTcold) return RESULT_SILENCE; + if(!camera->getTcold) return CC_RESULT_SILENCE; r = camera->getTcold(&f); if(r){ snprintf(buf, 63, CC_CMD_CAMTEMPER "=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; if(camera->getTbody){ r = camera->getTbody(&f); if(r){ snprintf(buf, 63, "tbody=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } } if(camera->getThot){ r = camera->getThot(&f); if(r){ snprintf(buf, 63, "thot=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } } - return RESULT_SILENCE; - }else return RESULT_FAIL; + return CC_RESULT_SILENCE; + }else return CC_RESULT_FAIL; } static cc_hresult camfanhandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - if(!camera->setfanspeed) return RESULT_FAIL; + if(!camera->setfanspeed) return CC_RESULT_FAIL; if(val){ int spd = atoi(val); - if(spd < 0) return RESULT_BADVAL; + if(spd < 0) return CC_RESULT_BADVAL; if(spd > FAN_HIGH) spd = FAN_HIGH; int r = camera->setfanspeed((cc_fan_speed)spd); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; camfanspd = spd; } snprintf(buf, 63, CC_CMD_CAMFANSPD "=%d", camfanspd); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } const char *shutterstr[] = {"open", "close", "expose @high", "expose @low"}; static cc_hresult shutterhandler(_U_ int fd, _U_ const char *key, const char *val){ - if(!camera->shuttercmd) return RESULT_FAIL; + if(!camera->shuttercmd) return CC_RESULT_FAIL; if(val){ int x = atoi(val); - if(x < 0 || x >= SHUTTER_AMOUNT) return RESULT_BADVAL; + if(x < 0 || x >= SHUTTER_AMOUNT) return CC_RESULT_BADVAL; int r = camera->shuttercmd((cc_shutter_op)x); if(r){ LOGMSG("Shutter command '%s'", shutterstr[x]); }else{ LOGWARN("Can't run shutter command '%s'", shutterstr[x]); - return RESULT_FAIL; + return CC_RESULT_FAIL; } } - return RESULT_OK; + return CC_RESULT_OK; } static cc_hresult confiohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - if(!camera->confio) return RESULT_FAIL; + if(!camera->confio) return CC_RESULT_FAIL; if(val){ int io = atoi(val); int r = camera->confio(io); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; confio = io; } snprintf(buf, 63, CC_CMD_CONFIO "=%d", confio); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult iohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; int io; - if(!camera->setio) return RESULT_FAIL; + if(!camera->setio) return CC_RESULT_FAIL; if(val){ io = atoi(val); int r = camera->setio(io); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; } int r = camera->getio(&io); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_IO "=%d", io); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult gainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; float f; - if(!camera->setgain) return RESULT_FAIL; + if(!camera->setgain) return CC_RESULT_FAIL; if(val){ f = atof(val); int r = camera->setgain(f); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; } - if(!camera->getgain) return RESULT_SILENCE; + if(!camera->getgain) return CC_RESULT_SILENCE; int r = camera->getgain(&f); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_GAIN "=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult brightnesshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; float b; - if(!camera->setbrightness) return RESULT_FAIL; + if(!camera->setbrightness) return CC_RESULT_FAIL; if(val){ b = atof(val); int r = camera->setbrightness(b); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; } - if(!camera->getbrightness) return RESULT_SILENCE; + if(!camera->getbrightness) return CC_RESULT_SILENCE; int r = camera->getbrightness(&b); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_BRIGHTNESS "=%.1f", b); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // set format: `format=X0,X1,Y0,Y1` // get geomlimits: `maxformat=X0,X1,Y0,Y1` @@ -594,18 +594,18 @@ static cc_hresult formathandler(int fd, const char *key, const char *val){ cc_frameformat fmt; DBG("key=%s, val=%s", key, val); if(val){ - if(!camera->setgeometry) return RESULT_FAIL; + if(!camera->setgeometry) return CC_RESULT_FAIL; if(0 == strcmp(key, CC_CMD_FRAMEMAX)){ DBG("CANT SET MAXFORMAT"); - return RESULT_BADKEY; // can't set maxformat + return CC_RESULT_BADKEY; // can't set maxformat } if(4 != sscanf(val, "%d,%d,%d,%d", &fmt.xoff, &fmt.yoff, &fmt.w, &fmt.h)){ DBG("Wrong format %s", val); - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } fmt.w -= fmt.xoff; fmt.h -= fmt.yoff; int r = camera->setgeometry(&fmt); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; curformat = fmt; DBG("curformat: w=%d, h=%d", curformat.w, curformat.h); fixima(); @@ -614,23 +614,23 @@ static cc_hresult formathandler(int fd, const char *key, const char *val){ frmformatmax.xoff, frmformatmax.yoff, frmformatmax.xoff+frmformatmax.w, frmformatmax.yoff+frmformatmax.h); else snprintf(buf, 63, CC_CMD_FRAMEFORMAT "=%d,%d,%d,%d", camera->geometry.xoff, camera->geometry.yoff, camera->geometry.xoff+camera->geometry.w, camera->geometry.yoff+camera->geometry.h); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult nflusheshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - if(!camera->setnflushes) return RESULT_FAIL; + if(!camera->setnflushes) return CC_RESULT_FAIL; if(val){ int n = atoi(val); - if(n < 1) return RESULT_BADVAL; + if(n < 1) return CC_RESULT_BADVAL; if(!camera->setnflushes(n)){ - return RESULT_FAIL; + return CC_RESULT_FAIL; } nflushes = n; } snprintf(buf, 63, CC_CMD_NFLUSHES "=%d", nflushes); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult expstatehandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; @@ -638,68 +638,68 @@ static cc_hresult expstatehandler(_U_ int fd, _U_ const char *key, _U_ const cha int n = atoi(val); if(n == CAMERA_IDLE){ // cancel expositions camflags |= FLAG_CANCEL; - return RESULT_OK; + return CC_RESULT_OK; } else if(n == CAMERA_CAPTURE){ // start exposition TIMESTAMP("Get FLAG_STARTCAPTURE"); TIMEINIT(); camflags |= FLAG_STARTCAPTURE; - return RESULT_OK; + return CC_RESULT_OK; } - else return RESULT_BADVAL; + else return CC_RESULT_BADVAL; } snprintf(buf, 63, CC_CMD_EXPSTATE "=%d", camstate); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; snprintf(buf, 63, "camflags=%d", camflags); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult tremainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; snprintf(buf, 63, CC_CMD_TREMAIN "=%g", tremain); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult _8bithandler(int fd, _U_ const char *key, const char *val){ char buf[64]; - if(!camera->setbitdepth) return RESULT_FAIL; + if(!camera->setbitdepth) return CC_RESULT_FAIL; if(val){ int s = atoi(val); - if(s != 0 && s != 1) return RESULT_BADVAL; - if(!camera->setbitdepth(!s)) return RESULT_FAIL; + if(s != 0 && s != 1) return CC_RESULT_BADVAL; + if(!camera->setbitdepth(!s)) return CC_RESULT_FAIL; fixima(); GP->_8bit = s; } snprintf(buf, 63, CC_CMD_8BIT "=%d", GP->_8bit); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult fastspdhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; - if(!camera->setfastspeed) return RESULT_FAIL; + if(!camera->setfastspeed) return CC_RESULT_FAIL; if(val){ int b = atoi(val); - if(b != 0 && b != 1) return RESULT_BADVAL; + if(b != 0 && b != 1) return CC_RESULT_BADVAL; GP->fast = b; - if(!camera->setfastspeed(b)) return RESULT_FAIL; + if(!camera->setfastspeed(b)) return CC_RESULT_FAIL; } snprintf(buf, 63, CC_CMD_FASTSPD "=%d", GP->fast); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult darkhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; - if(!camera->setframetype) return RESULT_FAIL; + if(!camera->setframetype) return CC_RESULT_FAIL; if(val){ int d = atoi(val); - if(d != 0 && d != 1) return RESULT_BADVAL; + if(d != 0 && d != 1) return CC_RESULT_BADVAL; GP->dark = d; d = !d; - if(!camera->setframetype(d)) return RESULT_FAIL; + if(!camera->setframetype(d)) return CC_RESULT_FAIL; } snprintf(buf, 63, CC_CMD_DARK "=%d", GP->dark); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult FITSparhandler(int fd, const char *key, const char *val){ char buf[256], **fitskey = NULL; @@ -715,14 +715,14 @@ static cc_hresult FITSparhandler(int fd, const char *key, const char *val){ fitskey = &GP->prog_id; }else if(0 == strcmp(key, CC_CMD_OBJTYPE)){ fitskey = &GP->objtype; - }else return RESULT_BADKEY; + }else return CC_RESULT_BADKEY; if(val){ FREE(*fitskey); *fitskey = strdup(val); } snprintf(buf, 255, "%s=%s", key, *fitskey); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val){ char buf[BUFSIZ], **sptr; @@ -751,7 +751,7 @@ static cc_hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val FREE(*sptr++); } FREE(list); - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } *lptr++ = strdup(newpath); if(++amount == sz){ @@ -792,42 +792,42 @@ static cc_hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val } } snprintf(buf, BUFSIZ-1, CC_CMD_HEADERFILES "=%s", curhdr); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } /* static cc_hresult handler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } */ /******************************************************************************* ***************************** cc_Wheel handlers ********************************** ******************************************************************************/ static cc_hresult wlisthandler(int fd, _U_ const char *key, _U_ const char *val){ - if(wheel->Ndevices < 1) return RESULT_FAIL; + if(wheel->Ndevices < 1) return CC_RESULT_FAIL; for(int i = 0; i < wheel->Ndevices; ++i){ if(!wheel->setDevNo(i)) continue; char modname[256], buf[BUFSIZ]; wheel->getModelName(modname, 255); snprintf(buf, BUFSIZ-1, CC_CMD_WLIST "='%s'", modname); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(wheeldevno > -1) wheel->setDevNo(wheeldevno); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult wsetNhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int num = atoi(val); if(num > wheel->Ndevices - 1 || num < 0){ - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } - if(!wheeldevini(num)) return RESULT_FAIL; + if(!wheeldevini(num)) return CC_RESULT_FAIL; } snprintf(buf, 63, CC_CMD_WDEVNO "=%d", wheeldevno); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ @@ -838,13 +838,13 @@ static cc_hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char * DBG("USER wants to %d", pos); int r = wheel->setPos(pos); DBG("wheel->setPos(%d)", pos); - if(!r) return RESULT_BADVAL; + if(!r) return CC_RESULT_BADVAL; } int r = wheel->getPos(&pos); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_WPOS "=%d", pos); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } /******************************************************************************* @@ -852,29 +852,29 @@ static cc_hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char * ******************************************************************************/ static cc_hresult foclisthandler(int fd, _U_ const char *key, _U_ const char *val){ - if(focuser->Ndevices < 1) return RESULT_FAIL; + if(focuser->Ndevices < 1) return CC_RESULT_FAIL; for(int i = 0; i < focuser->Ndevices; ++i){ char modname[256], buf[BUFSIZ]; if(!focuser->setDevNo(i)) continue; focuser->getModelName(modname, 255); snprintf(buf, BUFSIZ-1, CC_CMD_FOCLIST "='%s'", modname); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(focdevno > -1) focuser->setDevNo(focdevno); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } static cc_hresult fsetNhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int num = atoi(val); if(num > focuser->Ndevices - 1 || num < 0){ - return RESULT_BADVAL; + return CC_RESULT_BADVAL; } - if(!focdevini(num)) return RESULT_FAIL; + if(!focdevini(num)) return CC_RESULT_FAIL; } snprintf(buf, 63, CC_CMD_FDEVNO "=%d", focdevno); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } static cc_hresult fgotohandler(int fd, _U_ const char *key, const char *val){ char buf[64]; @@ -882,19 +882,19 @@ static cc_hresult fgotohandler(int fd, _U_ const char *key, const char *val){ int r; if(val){ f = atof(val); - if(f < focminpos || f > focmaxpos) return RESULT_BADVAL; + if(f < focminpos || f > focmaxpos) return CC_RESULT_BADVAL; if(f - focminpos < __FLT_EPSILON__){ r = focuser->home(1); }else{ r = focuser->setAbsPos(1, f); } - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; } r = focuser->getPos(&f); - if(!r) return RESULT_FAIL; + if(!r) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_FGOTO "=%g", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } /******************************************************************************* @@ -909,9 +909,9 @@ static cc_hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){ if(camera){ if(camera->getModelName && camera->getModelName(buf1, 255)){ snprintf(buf, BUFSIZ-1, CC_CMD_CAMLIST "='%s'", buf1); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } -#define RUN(f, arg) do{if(RESULT_DISCONNECTED == f(fd, arg, NULL)) return RESULT_DISCONNECTED;}while(0) +#define RUN(f, arg) do{if(CC_RESULT_DISCONNECTED == f(fd, arg, NULL)) return CC_RESULT_DISCONNECTED;}while(0) RUN(namehandler, CC_CMD_FILENAME); RUN(binhandler, CC_CMD_HBIN); RUN(binhandler, CC_CMD_VBIN); @@ -925,40 +925,40 @@ static cc_hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){ DBG("chk wheel"); if(wheel->getModelName(buf1, 255)){ snprintf(buf, BUFSIZ-1, CC_CMD_WLIST "='%s'", buf1); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(wheel->getTbody(&f)){ snprintf(buf, BUFSIZ-1, "wtemp=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(wheel->getPos(&i)){ snprintf(buf, BUFSIZ-1, CC_CMD_WPOS "=%d", i); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } snprintf(buf, BUFSIZ-1, "wmaxpos=%d", wmaxpos); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(focuser){ DBG("Chk focuser"); if(focuser->getModelName(buf1, 255)){ snprintf(buf, BUFSIZ-1, CC_CMD_FOCLIST "='%s'", buf1); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } if(focuser->getTbody(&f)){ snprintf(buf, BUFSIZ-1, "foctemp=%.1f", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } snprintf(buf, BUFSIZ-1, "focminpos=%g", focminpos); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; snprintf(buf, BUFSIZ-1, "focmaxpos=%g", focmaxpos); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; if(focuser->getPos(&f)){ snprintf(buf, BUFSIZ-1, CC_CMD_FGOTO "=%g", f); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; } } DBG("EOF"); - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } // show help static cc_hresult helphandler(int fd, _U_ const char *key, _U_ const char *val){ @@ -966,19 +966,19 @@ static cc_hresult helphandler(int fd, _U_ const char *key, _U_ const char *val){ strpair *ptr = allcommands; while(ptr->key){ snprintf(buf, 255, "%s - %s", ptr->key, ptr->help); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; ++ptr; } - return RESULT_SILENCE; + return CC_RESULT_SILENCE; } // shared memory key static cc_hresult shmemkeyhandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - if(shmkey == IPC_PRIVATE) return RESULT_FAIL; + if(shmkey == IPC_PRIVATE) return CC_RESULT_FAIL; snprintf(buf, 63, CC_CMD_SHMEMKEY "=%d", shmkey); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // infinity loop @@ -989,29 +989,29 @@ static cc_hresult inftyhandler(int fd, _U_ const char *key, const char *val){ infty = (i) ? 1 : 0; } snprintf(buf, 63, CC_CMD_INFTY "=%d", infty); - if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!cc_sendstrmessage(fd, buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // custom camera plugin command static cc_hresult pluginhandler(int fd, _U_ const char *key, const char *val){ - if(!camera->plugincmd) return RESULT_BADKEY; + if(!camera->plugincmd) return CC_RESULT_BADKEY; static cc_charbuff *ans = NULL; if(!ans) ans = cc_charbufnew(); cc_buff_lock(ans); cc_charbufclr(ans); cc_hresult r = camera->plugincmd(val, ans); cc_buff_unlock(ans); - if(ans->buflen && !cc_sendstrmessage(fd, ans->buf)) r = RESULT_DISCONNECTED; + if(ans->buflen && !cc_sendstrmessage(fd, ans->buf)) r = CC_RESULT_DISCONNECTED; return r; } // get headers static cc_hresult gethdrshandler(int fd, _U_ const char *key, _U_ const char *val){ cc_charbuff *b = getFITSheader(ima); - if(!b) return RESULT_FAIL; - if(!cc_sendstrmessage(fd, b->buf)) return RESULT_DISCONNECTED; - return RESULT_SILENCE; + if(!b) return CC_RESULT_FAIL; + if(!cc_sendstrmessage(fd, b->buf)) return CC_RESULT_DISCONNECTED; + return CC_RESULT_SILENCE; } // for setters: do nothing when camera not in idle state @@ -1024,26 +1024,26 @@ static int CAMbusy(){ } // check funtions static cc_hresult chktrue(_U_ char *val){ // dummy check for `infohandler` (need to lock mutex anymore) - return RESULT_OK; + return CC_RESULT_OK; } static cc_hresult chkcam(char *val){ - if(val && CAMbusy()) return RESULT_BUSY; - if(camera) return RESULT_OK; - return RESULT_FAIL; + if(val && CAMbusy()) return CC_RESULT_BUSY; + if(camera) return CC_RESULT_OK; + return CC_RESULT_FAIL; } static cc_hresult chkcc(_U_ char *val){ // just check that camera connected - if(camera) return RESULT_OK; - return RESULT_FAIL; + if(camera) return CC_RESULT_OK; + return CC_RESULT_FAIL; } static cc_hresult chkwhl(char *val){ - if(val && CAMbusy()) return RESULT_BUSY; - if(wheel) return RESULT_OK; - return RESULT_FAIL; + if(val && CAMbusy()) return CC_RESULT_BUSY; + if(wheel) return CC_RESULT_OK; + return CC_RESULT_FAIL; } static cc_hresult chkfoc(char *val){ - if(val && CAMbusy()) return RESULT_BUSY; - if(focuser) return RESULT_OK; - return RESULT_FAIL; + if(val && CAMbusy()) return CC_RESULT_BUSY; + if(focuser) return CC_RESULT_OK; + return CC_RESULT_FAIL; } static cc_handleritem items[] = { {chktrue,infohandler, CC_CMD_INFO}, @@ -1286,30 +1286,30 @@ static int parsestring(int fd, cc_handleritem *handlers, char *str){ } for(cc_handleritem *h = handlers; h->key; ++h){ if(strcmp(str, h->key)) continue; - cc_hresult r = RESULT_OK; + cc_hresult r = CC_RESULT_OK; int l = FALSE; if(h->chkfunction){ - double t0 = dtime(); - do{ l = lock(); } while(!l && dtime() - t0 < CC_BUSY_TIMEOUT); - DBG("time: %g", dtime() - t0); + double t0 = sl_dtime(); + 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); - return RESULT_BUSY; // long blocking work + return CC_RESULT_BUSY; // long blocking work } r = h->chkfunction(val); } // else NULL instead of chkfuntion -> don't check and don't lock mutex - if(r == RESULT_OK){ // no test function or it returns TRUE + if(r == CC_RESULT_OK){ // no test function or it returns TRUE if(h->handler) r = h->handler(fd, str, val); - else r = RESULT_FAIL; + else r = CC_RESULT_FAIL; } if(l) unlock(); - if(r == RESULT_DISCONNECTED){ - DBG("handler return RESULT_DISCONNECTED"); + if(r == CC_RESULT_DISCONNECTED){ + DBG("handler return CC_RESULT_DISCONNECTED"); return FALSE; } DBG("handler returns with '%s' (%d)", cc_hresult2str(r), r); return cc_sendstrmessage(fd, cc_hresult2str(r)); } DBG("Command not found!"); - return cc_sendstrmessage(fd, cc_hresult2str(RESULT_BADKEY)); + return cc_sendstrmessage(fd, cc_hresult2str(CC_RESULT_BADKEY)); } diff --git a/socket.h b/socket.h index 184ed7f..8763989 100644 --- a/socket.h +++ b/socket.h @@ -27,8 +27,8 @@ #ifdef EBUG extern double __t0; -#define TIMEINIT() do{__t0 = dtime();}while(0) -#define TIMESTAMP(...) do{DBG(__VA_ARGS__); green("%g\n", dtime()-__t0); fflush(stdout);}while(0) +#define TIMEINIT() do{__t0 = sl_dtime();}while(0) +#define TIMESTAMP(...) do{DBG(__VA_ARGS__); green("%g\n", sl_dtime()-__t0); fflush(stdout);}while(0) #else #define TIMEINIT() #define TIMESTAMP(...)