diff --git a/APOGEE_cameras/apogee.c b/APOGEE_cameras/apogee.c index 725eefa..ba1466f 100644 --- a/APOGEE_cameras/apogee.c +++ b/APOGEE_cameras/apogee.c @@ -29,11 +29,11 @@ #include -#include "basestructs.h" +#include "ccdcapture.h" //#include "omp.h" -extern Camera camera; +extern cc_Camera camera; static int ncameras = 0; static int isopened = FALSE; static int osw = 0; // overscan width @@ -156,15 +156,15 @@ static int modelname(char *buf, int bufsz){ return TRUE; } -static int shutter(shutter_op cmd){ +static int shutter(cc_shutter_op cmd){ int op = (cmd == SHUTTER_OPEN) ? 1 : 0; ApnGlueOpenShutter(op); return TRUE; } -static int geometrylimits(frameformat *l, frameformat *s){ +static int geometrylimits(cc_frameformat *l, cc_frameformat *s){ if(l) *l = camera.array; - if(s) *s = (frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; + if(s) *s = (cc_frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; return TRUE; } @@ -173,7 +173,7 @@ static int sett(float t){ return TRUE; } -static int setfanspd(fan_speed s){ +static int setfanspd(cc_fan_speed s){ ApnGlueSetFan((int) s); return TRUE; } @@ -200,7 +200,7 @@ static int setfastspeed(int fast){ return TRUE; } -static int setgeometry(frameformat *f){ +static int setgeometry(cc_frameformat *f){ if(!f) return FALSE; if(f->xoff > camera.field.w - 1) f->xoff = camera.field.w - 1; if(f->yoff > camera.field.h - 1) f->yoff = camera.field.h - 1; @@ -287,7 +287,7 @@ static int getbin(int *h, int *v){ return TRUE; } -static int pollcapt(capture_status *st, float *remain){ +static int pollcapt(cc_capture_status *st, float *remain){ if(st) *st = CAPTURE_PROCESS; if(ApnGlueExpDone()){ if(st) *st = CAPTURE_READY; @@ -312,7 +312,7 @@ static int pollcapt(capture_status *st, float *remain){ return TRUE; } -static int capture(IMG *ima){ +static int capture(cc_IMG *ima){ FNAME(); if(!ima || !ima->data) return FALSE; DBG("ApnGlueReadPixels(%dx%d=%d)", imW, imH, imW * imH); @@ -334,7 +334,7 @@ static int ipfalse(_U_ int *i){ return FALSE; } /* * Global objects: camera, focuser and wheel */ -Camera camera = { +cc_Camera camera = { .check = ndev, .close = disconnect, .pollcapture = pollcapt, diff --git a/BASLER_cameras/basler.c b/BASLER_cameras/basler.c index 80ff5c1..3371010 100644 --- a/BASLER_cameras/basler.c +++ b/BASLER_cameras/basler.c @@ -22,11 +22,11 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" #include "omp.h" //#include "socket.h" // timestamp -extern Camera camera; +extern cc_Camera camera; static PYLON_DEVICE_HANDLE hDev; static int isopened = FALSE, is16bit = FALSE; @@ -247,7 +247,7 @@ static int getgeom(){ return TRUE; } -static int geometrylimits(frameformat *max, frameformat *step){ +static int geometrylimits(cc_frameformat *max, cc_frameformat *step){ FNAME(); if(!isopened || !max || !step) return FALSE; int64_values i; @@ -329,13 +329,13 @@ static int setbitdepth(int depth){ } // stub function: the capture process is blocking -static int pollcapt(capture_status *st, float *remain){ +static int pollcapt(cc_capture_status *st, float *remain){ if(st) *st = CAPTURE_READY; if(remain) *remain = 0.f; return TRUE; } -static int capture(IMG *ima){ +static int capture(cc_IMG *ima){ FNAME(); //double __t0 = dtime(); if(!ima || !ima->data || !imgBuf || !isopened) return FALSE; @@ -424,7 +424,7 @@ static int setgain(float e){ return TRUE; } -static int changeformat(frameformat *fmt){ +static int changeformat(cc_frameformat *fmt){ FNAME(); if(!isopened) return FALSE; if(!getbin(NULL, NULL)){curhbin = 1; curvbin = 1;} @@ -484,10 +484,10 @@ static int gett(float *t){ return TRUE; } -static int setfanspd(_U_ fan_speed s){ +static int setfanspd(_U_ cc_fan_speed s){ return FALSE; } -static int shutter(_U_ shutter_op cmd){ +static int shutter(_U_ cc_shutter_op cmd){ return FALSE; } @@ -501,7 +501,7 @@ static void vstub(){ return ;} /* * Global objects: camera, focuser and wheel */ -Camera camera = { +cc_Camera camera = { .check = connect, .close = disconnect, .pollcapture = pollcapt, diff --git a/CMakeLists.txt b/CMakeLists.txt index 4723d72..046fea4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,16 @@ cmake_minimum_required(VERSION 3.20) set(PROJ ccd_capture) +set(PROJLIB ccdcapture) set(MAJOR_VERSION "1") -set(MID_VERSION "1") -set(MINOR_VERSION "1") +set(MID_VERSION "2") +set(MINOR_VERSION "0") + +set(LIBSRC ccdcapture.c) +set(SOURCES main.c cmdlnopts.c ccdfunc.c server.c client.c) +set(LIBHEADER "ccdcapture.h") + set(VERSION "${MAJOR_VERSION}.${MID_VERSION}.${MINOR_VERSION}") - project(${PROJ} VERSION ${VERSION} LANGUAGES C) - message("VER: ${VERSION}") # list of options @@ -18,9 +22,10 @@ option(BASLER "Add support of BASLER cameras" OFF) option(HIKROBOT "Add support of HIKROBOT cameras" OFF) option(FLYCAP "Add support of Grasshopper FlyCap cameras" OFF) option(APOGEE "Add support of Apogee cameras" OFF) +option(EXAMPLES "Some examples" OFF) # default flags -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wextra -std=gnu99") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wextra") # change wrong behaviour with install prefix if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND CMAKE_INSTALL_PREFIX MATCHES "/usr/local") @@ -29,7 +34,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND CMAKE_INSTALL_PREFIX MATCHES endif() message("Install dir prefix: ${CMAKE_INSTALL_PREFIX}") if(NOT DEFINED LOCALEDIR) - if(DEFINED DEBUG AND DEBUG STREQUAL "yes") + if(DEBUG) set(LOCALEDIR ${CMAKE_CURRENT_SOURCE_DIR}/locale) else() set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale) @@ -43,7 +48,6 @@ add_definitions(-D_XOPEN_SOURCE=1234 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DLOCALEDIR set(CMAKE_COLOR_MAKEFILE ON) -set(SOURCES main.c cmdlnopts.c ccdfunc.c socket.c server.c client.c) # cmake -DDEBUG=yes -> debugging if(DEBUG) @@ -62,6 +66,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") find_package(CFITSIO REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(${PROJ} REQUIRED usefull_macros) +pkg_check_modules(${PROJLIB} REQUIRED usefull_macros) include(FindOpenMP) if(OPENMP_FOUND) @@ -101,6 +106,9 @@ endif() if(APOGEE) add_subdirectory(APOGEE_cameras) endif() +if(EXAMPLES) + add_subdirectory(examples) +endif() # directory should contain dir locale/ru for gettext translations set(LCPATH ${CMAKE_SOURCE_DIR}/locale/ru) @@ -110,15 +118,25 @@ set(PO_FILE ${LCPATH}/messages.po) set(MO_FILE ${LCPATH}/LC_MESSAGES/${PROJ}.mo) set(RU_FILE ${LCPATH}/ru.po) -# exe file +# exe & lib files +add_library(${PROJLIB} SHARED ${LIBSRC}) add_executable(${PROJ} ${SOURCES} ${PO_FILE} ${MO_FILE}) -target_link_libraries(${PROJ} ${CFITSIO_LIBRARIES} ${X11_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${${PROJ}_LIBRARIES} -lm ${CMAKE_DL_LIBS}) +target_link_libraries(${PROJ} ${CFITSIO_LIBRARIES} ${X11_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${${PROJ}_LIBRARIES} -lm ${CMAKE_DL_LIBS} ${PROJLIB}) +target_link_libraries(${PROJLIB} ${${PROJLIB}_LIBRARIES}) include_directories(${${PROJ}_INCLUDE_DIRS} .) link_directories(${${PROJ}_LIBRARY_DIRS} ) +set(PCFILE "${CMAKE_BINARY_DIR}/${PROJLIB}.pc") +configure_file("${PROJLIB}.pc.in" ${PCFILE} @ONLY) +set_target_properties(${PROJLIB} PROPERTIES VERSION ${VERSION}) +set_target_properties(${PROJLIB} PROPERTIES PUBLIC_HEADER ${LIBHEADER}) # Installation of the program install(FILES ${MO_FILE} DESTINATION "share/locale/ru/LC_MESSAGES") install(TARGETS ${PROJ} DESTINATION "bin") +install(TARGETS ${PROJLIB} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(FILES ${PCFILE} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) + find_package(Gettext REQUIRED) find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext) diff --git a/Dummy_cameras/dummyfunc.c b/Dummy_cameras/dummyfunc.c index 798e87c..182ad27 100644 --- a/Dummy_cameras/dummyfunc.c +++ b/Dummy_cameras/dummyfunc.c @@ -25,12 +25,12 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" #include "omp.h" -extern Camera camera; -extern Focuser focuser; -extern Wheel wheel; +extern cc_Camera camera; +extern cc_Focuser focuser; +extern cc_Wheel wheel; static const int filtermax = 5; static const float focmaxpos = 10.; @@ -38,11 +38,11 @@ static int curhbin = 1, curvbin = 1; static int filterpos = 0; static float focuserpos = 1., brightness = 1., gain = 0.; static float camtemp = -30., exptime = 0.; -static capture_status capstat = CAPTURE_NO; +static cc_capture_status capstat = CAPTURE_NO; static double texpstart = 0.; static uint8_t bitpix = 16; // bit depth: 8 or 16 -static int campoll(capture_status *st, float *remain){ +static int campoll(cc_capture_status *st, float *remain){ if(capstat != CAPTURE_PROCESS){ if(st) *st = capstat; if(remain) *remain = 0.; @@ -66,7 +66,7 @@ static int startexp(){ return TRUE; } -static int camcapt(IMG *ima){ +static int camcapt(cc_IMG *ima){ static int n = 0; if(!ima || !ima->data) return FALSE; #ifdef EBUG @@ -163,11 +163,11 @@ static int camsetbin(int h, int v){ return TRUE; } -static int camshutter(_U_ shutter_op s){ +static int camshutter(_U_ cc_shutter_op s){ return TRUE; } -static int camsetgeom(frameformat *f){ +static int camsetgeom(cc_frameformat *f){ if(!f) return FALSE; camera.geometry = *f; return TRUE; @@ -183,9 +183,9 @@ static int camgmg(float *mg){ return TRUE; } -static int camggl(frameformat *max, frameformat *step){ +static int camggl(cc_frameformat *max, cc_frameformat *step){ if(max) *max = camera.array; - if(step) *step = (frameformat){1,1,1,1}; + if(step) *step = (cc_frameformat){1,1,1,1}; return TRUE; } @@ -200,7 +200,7 @@ static int camgetio(int *io){ return TRUE; } -static int camfan(_U_ fan_speed spd){return TRUE;} +static int camfan(_U_ cc_fan_speed spd){return TRUE;} static int focsetpos(_U_ int a, float n){ if(n < 0. || n > focmaxpos) return FALSE; @@ -267,7 +267,7 @@ static int istub(_U_ int N){return TRUE;} /* * Global objects: camera, focuser and wheel */ -__attribute__ ((visibility("default"))) Camera camera = { +__attribute__ ((visibility("default"))) cc_Camera camera = { .check = stub, .Ndevices = 1, .close = vstub, @@ -305,12 +305,12 @@ __attribute__ ((visibility("default"))) Camera camera = { .getio = camgetio, .pixX = 10., .pixY = 10., - .field = (frameformat){.h = 1024, .w = 1024, .xoff = 10, .yoff = 10}, - .array = (frameformat){.h = 1050, .w = 1050, .xoff = 0, .yoff = 0}, + .field = (cc_frameformat){.h = 1024, .w = 1024, .xoff = 10, .yoff = 10}, + .array = (cc_frameformat){.h = 1050, .w = 1050, .xoff = 0, .yoff = 0}, .geometry = {0}, }; -__attribute__ ((visibility("default"))) Focuser focuser = { +__attribute__ ((visibility("default"))) cc_Focuser focuser = { .check = stub, .Ndevices = 1, .close = vstub, @@ -326,7 +326,7 @@ __attribute__ ((visibility("default"))) Focuser focuser = { .getMinPos = focmp, }; -__attribute__ ((visibility("default"))) Wheel wheel = { +__attribute__ ((visibility("default"))) cc_Wheel wheel = { .check = stub, .Ndevices = 1, .close = vstub, diff --git a/FLI_cameras/flifunc.c b/FLI_cameras/flifunc.c index 9f0786a..b5dc6c3 100644 --- a/FLI_cameras/flifunc.c +++ b/FLI_cameras/flifunc.c @@ -21,11 +21,11 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" -extern Camera camera; -extern Focuser focuser; -extern Wheel wheel; +extern cc_Camera camera; +extern cc_Focuser focuser; +extern cc_Wheel wheel; #define LIBVERSIZ 1024 @@ -63,7 +63,7 @@ static char camname[BUFSIZ] = {0}, whlname[BUFSIZ], focname[BUFSIZ]; static long fli_err, tmpl; static cam_t *camz = NULL, *whlz = NULL, *focz = NULL; static flidev_t camdev = -1, whldev = -1, focdev = -1; -static capture_status capStatus = CAPTURE_NO; +static cc_capture_status capStatus = CAPTURE_NO; static int curhbin = 1, curvbin = 1; static long filterpos = -1, filtermax = -1; // filter position static long focuserpos = -1, focmaxpos = -1; // focuser position @@ -135,7 +135,7 @@ static int fli_findCCD(){ return FALSE; } for(int i = 0; i < camera.Ndevices; i++){ - DBG("Camera '%s', domain %s", camz[i].name, camz[i].dname); + DBG("cc_Camera '%s', domain %s", camz[i].name, camz[i].dname); } } return TRUE; @@ -174,19 +174,19 @@ static int fli_setActiceCam(int n){ TRYFUNC(FLIGetVisibleArea, camdev, &x0, &y0, &x1, &y1); if(!fli_err){ DBG("Field of view: (%ld, %ld)(%ld, %ld)", x0, y0, x1, y1); - camera.field = (frameformat){.w = x1 - x0, .h = y1 - y0, .xoff = x0, .yoff = y0}; + camera.field = (cc_frameformat){.w = x1 - x0, .h = y1 - y0, .xoff = x0, .yoff = y0}; } TRYFUNC(FLIGetArrayArea, camdev, &x0, &y0, &x1, &y1); if(!fli_err){ DBG("Array field: (%ld, %ld)(%ld, %ld)", x0, y0, x1, y1); - camera.array = (frameformat){.w = x1 - x0, .h = y1 - y0, .xoff = x0, .yoff = y0}; + camera.array = (cc_frameformat){.w = x1 - x0, .h = y1 - y0, .xoff = x0, .yoff = y0}; } return TRUE; } -static int fli_geomlimits(frameformat *l, frameformat *s){ +static int fli_geomlimits(cc_frameformat *l, cc_frameformat *s){ if(l) *l = camera.array; - if(s) *s = (frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; + if(s) *s = (cc_frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; return TRUE; } @@ -203,7 +203,7 @@ static int fli_findFocuser(){ return FALSE; } for(int i = 0; i < focuser.Ndevices; i++){ - DBG("Focuser '%s', domain %s", focz[i].name, focz[i].dname); + DBG("cc_Focuser '%s', domain %s", focz[i].name, focz[i].dname); } } return TRUE; @@ -237,7 +237,7 @@ static int fli_setActiceFocuser(int n){ DBG("Not found"); return FALSE; } - DBG("Focuser: %s", focname); + DBG("cc_Focuser: %s", focname); #ifdef EBUG TRYFUNC(FLIGetHWRevision, focdev, &tmpl); if(!fli_err) DBG("HW revision: %ld", tmpl); @@ -315,7 +315,7 @@ static int fli_findWheel(){ return FALSE; } for(int i = 0; i < wheel.Ndevices; i++){ - DBG("Wheel '%s', domain %s", whlz[i].name, whlz[i].dname); + DBG("cc_Wheel '%s', domain %s", whlz[i].name, whlz[i].dname); } return TRUE; } @@ -350,7 +350,7 @@ static int fli_setActiceWheel(int n){ return FALSE; } TRYFUNC(FLIGetModel, whldev, whlname, BUFSIZ); - DBG("Wheel: %s", whlname); + DBG("cc_Wheel: %s", whlname); #ifdef EBUG TRYFUNC(FLIGetHWRevision, whldev, &tmpl); if(!fli_err) DBG("HW revision: %ld", tmpl); @@ -422,7 +422,7 @@ static int fli_startexp(){ return TRUE; } -static int fli_pollcapt(capture_status *st, float *remain){ +static int fli_pollcapt(cc_capture_status *st, float *remain){ static int errctr = 0; if(capStatus == CAPTURE_READY){ DBG("Capture ends"); @@ -460,7 +460,7 @@ retn: return TRUE; } -static int fli_capt(IMG *ima){ +static int fli_capt(cc_IMG *ima){ if(!ima || !ima->data) return FALSE; for(int row = 0; row < ima->h; row++){ void *ptr = (void*)((is16bit) ? ((uint16_t*)ima->data) + row * ima->w : ((uint8_t*)ima->data) + row * ima->w); @@ -492,7 +492,7 @@ static int fli_getbin(int *h, int *v){ return TRUE; } -static int fli_setgeometry(frameformat *f){ +static int fli_setgeometry(cc_frameformat *f){ if(!f) return FALSE; TRYFUNC(FLISetImageArea, camdev, f->xoff, f->yoff, f->xoff + f->w/curhbin, f->yoff + f->h/curvbin); @@ -560,7 +560,7 @@ static void fli_cancel(){ TRYFUNC(FLIEndExposure, camdev); } -static int fli_shutter(shutter_op cmd){ +static int fli_shutter(cc_shutter_op cmd){ flishutter_t shtr = FLI_SHUTTER_CLOSE; switch(cmd){ case SHUTTER_OPEN: @@ -633,7 +633,7 @@ static int fli_setfastspeed(int fast){ return TRUE; } -static int fli_setfanspd(fan_speed s){ +static int fli_setfanspd(cc_fan_speed s){ long sp = (s == FAN_OFF) ? FLI_FAN_SPEED_OFF : FLI_FAN_SPEED_ON; TRYFUNC(FLISetFanSpeed, camdev, sp); if(fli_err) return FALSE; @@ -667,7 +667,7 @@ static int fli_fpfalse(_U_ float *f){ return FALSE; } /* * Global objects: camera, focuser and wheel */ -__attribute__ ((visibility("default"))) Camera camera = { +__attribute__ ((visibility("default"))) cc_Camera camera = { .check = fli_findCCD, .close = fli_closecam, .pollcapture = fli_pollcapt, @@ -703,7 +703,7 @@ __attribute__ ((visibility("default"))) Camera camera = { .getio = fli_getio, }; -__attribute__ ((visibility("default"))) Focuser focuser = { +__attribute__ ((visibility("default"))) cc_Focuser focuser = { .check = fli_findFocuser, .setDevNo = fli_setActiceFocuser, .close = fli_closefocuser, @@ -716,7 +716,7 @@ __attribute__ ((visibility("default"))) Focuser focuser = { .setAbsPos = fli_fgoto, }; -__attribute__ ((visibility("default"))) Wheel wheel = { +__attribute__ ((visibility("default"))) cc_Wheel wheel = { .check = fli_findWheel, .setDevNo = fli_setActiceWheel, .close = fli_closewheel, diff --git a/GRH_cameras/grasshopper.c b/GRH_cameras/grasshopper.c index 8c4cd7b..f6c6e03 100644 --- a/GRH_cameras/grasshopper.c +++ b/GRH_cameras/grasshopper.c @@ -24,10 +24,10 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" #include "omp.h" -extern Camera camera; +extern cc_Camera camera; static fc2Context context; static fc2PGRGuid guid; @@ -176,7 +176,7 @@ static int getbin(int *binh, int *binv){ return TRUE; } -static int getformat(frameformat *fmt){ +static int getformat(cc_frameformat *fmt){ if(!fmt) return FALSE; unsigned int packsz; float pc; fc2Format7ImageSettings f7; @@ -209,7 +209,7 @@ static int getgeom(){ return TRUE; } -static int geometrylimits(frameformat *max, frameformat *step){ +static int geometrylimits(cc_frameformat *max, cc_frameformat *step){ FNAME(); if(!isopened || !max || !step) return FALSE; fc2Format7Info f = {.mode = FC2_MODE_0}; @@ -247,7 +247,7 @@ static int setdevno(int N){ } // stub function: the capture process is blocking -static int pollcapt(capture_status *st, float *remain){ +static int pollcapt(cc_capture_status *st, float *remain){ if(st) *st = CAPTURE_READY; if(remain) *remain = 0.f; return TRUE; @@ -287,7 +287,7 @@ rtn: return ret; } -static int capture(IMG *ima){ +static int capture(cc_IMG *ima){ FNAME(); if(canceled) return FALSE; if(!ima || !ima->data || !isopened) return FALSE; @@ -368,7 +368,7 @@ static int setgain(float e){ return TRUE; } -static int changeformat(frameformat *fmt){ +static int changeformat(cc_frameformat *fmt){ FNAME(); if(!isopened) return FALSE; DBG("set geom %dx%d (off: %dx%d)", fmt->w, fmt->h, fmt->xoff, fmt->yoff); @@ -390,7 +390,7 @@ static int changeformat(frameformat *fmt){ } static int setbitdepth(int i){ - frameformat fmt; + cc_frameformat fmt; if(!getformat(&fmt)) return FALSE; int o16bit = is16bit; if(i == 0) is16bit = FALSE; // 8 bit @@ -428,10 +428,10 @@ static int gett(float *t){ return getfloat(FC2_TEMPERATURE, t); } -static int setfanspd(_U_ fan_speed s){ +static int setfanspd(_U_ cc_fan_speed s){ return FALSE; } -static int shutter(_U_ shutter_op cmd){ +static int shutter(_U_ cc_shutter_op cmd){ return FALSE; } @@ -450,7 +450,7 @@ static int ipfalse(_U_ int *i){ return FALSE; } /* * Global objects: camera, focuser and wheel */ -Camera camera = { +cc_Camera camera = { .check = connect, .close = disconnect, .pollcapture = pollcapt, diff --git a/HIKROBOT_cameras/mvsfunc.c b/HIKROBOT_cameras/mvsfunc.c index 483eb62..5f3ec59 100644 --- a/HIKROBOT_cameras/mvsfunc.c +++ b/HIKROBOT_cameras/mvsfunc.c @@ -22,20 +22,20 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" #include "omp.h" #ifndef FLT_EPSILON #define FLT_EPSILON 1.19209290E-07F #endif -extern Camera camera; +extern cc_Camera camera; static MV_CC_DEVICE_INFO_LIST stDeviceList; static void *handle = NULL; static char camname[BUFSIZ] = {0}; //static long cam_err, tmpl; -static capture_status capStatus = CAPTURE_NO; +static cc_capture_status capStatus = CAPTURE_NO; static int curhbin = 1, curvbin = 1; static double starttime = 0.; // time when exposure started static float exptime = 0.; // exposition time (in seconds) @@ -383,9 +383,9 @@ static int cam_setActiceCam(int n){ return TRUE; } -static int cam_geomlimits(frameformat *l, frameformat *s){ +static int cam_geomlimits(cc_frameformat *l, cc_frameformat *s){ if(l) *l = camera.array; - if(s) *s = (frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; + if(s) *s = (cc_frameformat){.w = 1, .h = 1, .xoff = 1, .yoff = 1}; return TRUE; } @@ -400,7 +400,7 @@ static int cam_startexp(){ return TRUE; } -static int cam_pollcapt(capture_status *st, float *remain){ +static int cam_pollcapt(cc_capture_status *st, float *remain){ if(!handle || !pdata) return FALSE; DBG("capStatus = %d", capStatus); if(capStatus == CAPTURE_READY){ @@ -442,7 +442,7 @@ retn: return TRUE; } -static int cam_capt(IMG *ima){ +static int cam_capt(cc_IMG *ima){ if(!handle || !pdata) return FALSE; if(!ima || !ima->data) return FALSE; MVCC_ENUMVALUE EnumValue; @@ -473,7 +473,7 @@ static int cam_modelname(char *buf, int bufsz){ return TRUE; } -static int cam_setgeometry(frameformat *f){ +static int cam_setgeometry(cc_frameformat *f){ FNAME(); if(!f || !handle) return FALSE; DBG("getbin"); @@ -519,7 +519,7 @@ static void cam_cancel(){ TRY(StopGrabbing); } -static int cam_shutter(_U_ shutter_op cmd){ +static int cam_shutter(_U_ cc_shutter_op cmd){ return FALSE; } @@ -560,7 +560,7 @@ static int cam_setbitdepth(int i){ return TRUE; } -static int cam_setfanspd(_U_ fan_speed s){ +static int cam_setfanspd(_U_ cc_fan_speed s){ return FALSE; } @@ -572,7 +572,7 @@ static int cam_ipfalse(_U_ int *i){ return FALSE; } /* * Global objects: camera, focuser and wheel */ -Camera camera = { +cc_Camera camera = { .check = cam_findCCD, .close = cam_closecam, .pollcapture = cam_pollcapt, diff --git a/ZWO_cameras/zwofunc.c b/ZWO_cameras/zwofunc.c index da300fd..adc7b12 100644 --- a/ZWO_cameras/zwofunc.c +++ b/ZWO_cameras/zwofunc.c @@ -26,11 +26,11 @@ #include #include -#include "basestructs.h" +#include "ccdcapture.h" -extern Camera camera; -extern Focuser focuser; -extern Wheel wheel; +extern cc_Camera camera; +extern cc_Focuser focuser; +extern cc_Wheel wheel; // remove all these after removing stubs! // VVV @@ -82,7 +82,7 @@ static int asi_checkcam(){ return FALSE; } -static int campoll(capture_status *st, float *remain){ +static int campoll(cc_capture_status *st, float *remain){ if(!st) return FALSE; ASI_EXPOSURE_STATUS s; if(ASI_SUCCESS != ASIGetExpStatus(caminfo.CameraID, &s)){ @@ -112,7 +112,7 @@ static int campoll(capture_status *st, float *remain){ return TRUE; } -static int camcapt(IMG *ima){ +static int camcapt(cc_IMG *ima){ if(!ima || !ima->data) return FALSE; unsigned char *d = (unsigned char *)ima->data; long image_size = ima->h * ima->w * 2; @@ -160,7 +160,7 @@ static int setdevno(int n){ if(n > camera.Ndevices - 1 || n < 0) return FALSE; asi_closecam(); if(ASI_SUCCESS != ASIGetCameraProperty(&caminfo, n)) return FALSE; - DBG("Camera #%d, name: %s, ID: %d", n, caminfo.Name, caminfo.CameraID); + DBG("cc_Camera #%d, name: %s, ID: %d", n, caminfo.Name, caminfo.CameraID); DBG("WxH: %ldx%ld, %s", caminfo.MaxWidth, caminfo.MaxHeight, caminfo.IsColorCam == ASI_TRUE ? "color" : "monochrome"); DBG("Pixel size: %1.1f mkm; gain: %1.2f e/ADU", caminfo.PixelSize, caminfo.ElecPerADU); int *sup = caminfo.SupportedBins; @@ -168,7 +168,7 @@ static int setdevno(int n){ extrvalues.maxbin = *sup++; } camera.pixX = camera.pixY = (float)caminfo.PixelSize / 1e6; // um -> m - camera.array = (frameformat){.w = caminfo.MaxWidth, .h = caminfo.MaxHeight, .xoff = 0, .yoff = 0}; + camera.array = (cc_frameformat){.w = caminfo.MaxWidth, .h = caminfo.MaxHeight, .xoff = 0, .yoff = 0}; camera.field = camera.array; // initial setup (will update later) if(ASI_SUCCESS != ASIOpenCamera(caminfo.CameraID)){ WARNX("Can't open device for camera %s", caminfo.Name); @@ -332,13 +332,13 @@ static int camsetbin(int h, int v){ } // unsupported, but return TRUE if have mechanical shutter -static int camshutter(_U_ shutter_op s){ +static int camshutter(_U_ cc_shutter_op s){ if(!caminfo.MechanicalShutter) return FALSE; return TRUE; } // set ROI -static int camsetgeom(frameformat *f){ // w,h, xoff, yoff +static int camsetgeom(cc_frameformat *f){ // w,h, xoff, yoff if(!f) return FALSE; int imtype; DBG("w: %g, h: %g, bin: %d", (double)f->w / curbin, (double)f->h / curbin, curbin); @@ -375,10 +375,10 @@ static int camgmg(float *mg){ // get max gain return TRUE; } -static int camggl(frameformat *max, frameformat *step){ // get geometry limits +static int camggl(cc_frameformat *max, cc_frameformat *step){ // get geometry limits DBG("array: %dx%d, off: %dx%d", camera.array.w, camera.array.h, camera.array.xoff, camera.array.yoff); if(max) *max = camera.array; - if(step) *step = (frameformat){1,1,1,1}; + if(step) *step = (cc_frameformat){1,1,1,1}; return TRUE; } @@ -405,7 +405,7 @@ static int camgetio(_U_ int *io){ // not supported return FALSE; } -static int camfan(_U_ fan_speed spd){ // not supported, just turn it on/off +static int camfan(_U_ cc_fan_speed spd){ // not supported, just turn it on/off switch(spd){ case FAN_OFF: if(!zwo_setfloat(0., ASI_FAN_ON)){ @@ -490,7 +490,7 @@ static int istub(_U_ int N){ /* * Global objects: camera, focuser and wheel */ -__attribute__ ((visibility("default"))) Camera camera = { +__attribute__ ((visibility("default"))) cc_Camera camera = { .check = asi_checkcam, .close = asi_closecam, .pollcapture = campoll, @@ -526,7 +526,7 @@ __attribute__ ((visibility("default"))) Camera camera = { .getio = camgetio, }; -__attribute__ ((visibility("default"))) Focuser focuser = { +__attribute__ ((visibility("default"))) cc_Focuser focuser = { .check = stub, .close = vstub, // setters: @@ -541,7 +541,7 @@ __attribute__ ((visibility("default"))) Focuser focuser = { .getMinPos = focmp, }; -__attribute__ ((visibility("default"))) Wheel wheel = { +__attribute__ ((visibility("default"))) cc_Wheel wheel = { .check = stub, .close = vstub, // setters diff --git a/basestructs.h b/basestructs.h deleted file mode 100644 index 7b62011..0000000 --- a/basestructs.h +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is part of the CCD_Capture project. - * Copyright 2022 Edward V. Emelianov . - * - * 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 . - */ - -#pragma once -#include -#include // for size_t - -// magic to mark our SHM -#define SHM_MAGIC (0xdeadbeef) - -// base image parameters - sent by socket and stored in shared memory -typedef struct __attribute__((packed, aligned(4))){ - uint32_t MAGICK; // magick (DEADBEEF) - to mark our shm - double timestamp; // timestamp of image taken - uint8_t bitpix; // bits per pixel (8 or 16) - int w, h; // image size - uint16_t max, min; // min/max values - float avr, std; // statistics - size_t bytelen; // size of image in bytes - size_t imnumber; // counter of images captured from server's start - void *data; // pointer to data (next byte after this struct) - only for server - /* `data` is uint8_t or uint16_t depending on `bitpix` */ -} IMG; - -// format of single frame -typedef struct{ - int w; int h; // width & height - int xoff; int yoff; // X and Y offset -} frameformat; - -typedef enum{ - SHUTTER_OPEN, // open shutter now - SHUTTER_CLOSE, // close shutter now - SHUTTER_OPENATLOW, // ext. expose control @low - SHUTTER_OPENATHIGH, // -//- @high - SHUTTER_AMOUNT, // amount of entries -} shutter_op; - -typedef enum{ - CAPTURE_NO, // no capture initiated - CAPTURE_PROCESS, // in progress - CAPTURE_CANTSTART, // can't start - CAPTURE_ABORTED, // some error - aborted - CAPTURE_READY, // ready - user can read image -} capture_status; - -typedef enum{ - FAN_OFF, - FAN_LOW, - FAN_MID, - FAN_HIGH, -} fan_speed; - -// all setters and getters of Camera, Focuser and Wheel should return TRUE if success or FALSE if failed or unsupported -// camera -typedef struct{ - int (*check)(); // check if the device is available, connect and init - int Ndevices; // amount of devices found - void (*close)(); // disconnect & close device - int (*startexposition)(); // start exposition - int (*pollcapture)(capture_status *st, float *remain);// get `st` - status of capture process, `remain` - time remain (s); @return FALSE if error (exp aborted), TRUE while no errors - int (*capture)(IMG *ima); // capture an image, struct `ima` should be prepared before - void (*cancel)(); // cancel exposition - // setters: - int (*setDevNo)(int n); // set active device number - int (*setbrightness)(float b); - int (*setexp)(float e); - int (*setgain)(float g); - int (*setT)(float t); - int (*setbin)(int binh, int binv); // binning - int (*setnflushes)(int N); // flushes amount - int (*shuttercmd)(shutter_op s); // work with shutter - int (*confio)(int s); // configure IO-port - int (*setio)(int s); // set IO-port to given state - int (*setframetype)(int l); // set frametype: 1 - light, 0 - dark - int (*setbitdepth)(int h); // set bit depth : 1 - high (16 bit), 0 - low (8 bit) - int (*setfastspeed)(int s); // set readout speed: 1 - fast, 0 - low - // geometry (if TRUE, all args are changed to suitable values) - int (*setgeometry)(frameformat *fmt); // set geometry in UNBINNED coordinates - int (*setfanspeed)(fan_speed spd); // set fan speed - // getters: - int (*getbitpix)(uint8_t *bp); // get bit depth in bits per pixel (8, 12, 16 etc) - int (*getbrightness)(float *b);// get brightnes level - int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) - int (*getgain)(float *g); // get gain value - int (*getmaxgain)(float *g);// get max available gain value - // get limits of geometry: maximal values and steps - int (*getgeomlimits)(frameformat *max, frameformat *step); - int (*getTcold)(float *t); // cold-side T - int (*getThot)(float *t); // hot-side T - int (*getTbody)(float *t); // body T - int (*getbin)(int *binh, int *binv); - int (*getio)(int *s); // get IO-port state - float pixX, pixY; // pixel size in um - frameformat field; // max field of view - frameformat array; // array format - frameformat geometry; // current geometry settings (as in setgeometry) -} Camera; - -// focuser -typedef struct{ - int (*check)(); // check if the device is available - int Ndevices; - void (*close)(); - // setters: - int (*setDevNo)(int n); // set active device number - int (*setAbsPos)(int async, float n);// set absolute position (in millimeters!!!) - int (*home)(int async); // home device - // getters: - int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) - int (*getTbody)(float *t); // body T - int (*getPos)(float *p); // current position number (starting from zero) - int (*getMaxPos)(float *p); // max position - int (*getMinPos)(float *p); // min position -} Focuser; - -// wheel -typedef struct{ - int (*check)(); // check if the device is available - int Ndevices; - void (*close)(); - // setters: - int (*setDevNo)(int n); // set active device number - int (*setPos)(int n); // set absolute position (starting from 0) - // getters: - int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) - int (*getTbody)(float *t); // body T - int (*getPos)(int *p); // current position number (starting from zero) - int (*getMaxPos)(int *p); // amount of positions -} Wheel; - diff --git a/socket.c b/ccdcapture.c similarity index 54% rename from socket.c rename to ccdcapture.c index 7cf1a7c..c0501a2 100644 --- a/socket.c +++ b/ccdcapture.c @@ -17,6 +17,7 @@ */ #include // isspace +#include // dlopen/close #include #include #include @@ -38,15 +39,17 @@ double __t0 = 0.; #endif +static int ntries = 2; // amount of tries to send messages controlling the answer + /** - * @brief open_socket - create socket and open it + * @brief cc_open_socket - create socket and open it * @param isserver - TRUE for server, FALSE for client * @param path - UNIX-socket path or local INET socket port * @param isnet - 1/2 for INET socket (1 - localhost, 2 - network), 0 for UNIX * @return socket FD or -1 if failed */ -int open_socket(int isserver, char *path, int isnet){ - //DBG("isserver=%d, path=%s, isnet=%d", isserver, path, isnet); +int cc_open_socket(int isserver, char *path, int isnet){ + DBG("isserver=%d, path=%s, isnet=%d", isserver, path, isnet); if(!path) return 1; //DBG("path/port: %s", path); int sock = -1; @@ -59,10 +62,11 @@ int open_socket(int isserver, char *path, int isnet){ hints.ai_flags = AI_PASSIVE; const char *node = (isnet == 2) ? NULL : "127.0.0.1"; if(getaddrinfo(node, path, &hints, &res) != 0){ - ERR("getaddrinfo"); + WARN("getaddrinfo"); + return -1; } }else{ - //DBG("UNIX socket"); + DBG("UNIX socket"); char apath[128]; if(*path == 0){ DBG("convert name"); @@ -73,6 +77,7 @@ int open_socket(int isserver, char *path, int isnet){ apath[0] = 0; strncpy(apath+1, path+2, 126); }else strcpy(apath, path); + //unlink(apath); unaddr.sun_family = AF_UNIX; hints.ai_addr = (struct sockaddr*) &unaddr; hints.ai_addrlen = sizeof(unaddr); @@ -122,47 +127,8 @@ int open_socket(int isserver, char *path, int isnet){ return sock; } -/** - * @brief start_socket - create socket and run client or server - * @param isserver - TRUE for server, FALSE for client - * @return 0 if OK - */ -int start_socket(int isserver){ - char *path = NULL; - 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"); - int sock = open_socket(isserver, path, isnet), imsock = -1; - if(sock < 0){ - LOGERR("Can't open socket"); - ERRX("start_socket(): can't open socket"); - } - if(isserver){ - imsock = open_socket(TRUE, GP->imageport, 2); // image socket should be networked - server(sock, imsock); - }else{ -#ifdef IMAGEVIEW - if(GP->showimage){ - 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"); - }else -#endif - client(sock); - } - DBG("Close socket"); - close(sock); - if(isserver){ - close(imsock); - signals(0); - } - return 0; -} - -// send image data to client -int senddata(int fd, void *data, size_t l){ +// send data through the socket +int cc_senddata(int fd, void *data, size_t l){ DBG("fd=%d, l=%zd", fd, l); if(fd < 1 || !data || l < 1) return TRUE; // empty message DBG("send new data (size=%zd) to fd %d", l, fd); @@ -174,13 +140,16 @@ int senddata(int fd, void *data, size_t l){ return FALSE; } DBG("success"); - if(globlog) LOGDBG("SEND image (size=%d) to fd %d", l, fd); + if(globlog) LOGDBG("SEND data (size=%d) to fd %d", l, fd); return TRUE; } // simple wrapper over write: add missed newline and log data -int sendmessage(int fd, const char *msg, int l){ +int cc_sendmessage(int fd, const char *msg, int l){ + FNAME(); if(fd < 1 || !msg || l < 1) return TRUE; // empty message + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // thread safe + pthread_mutex_lock(&mutex); static char *tmpbuf = NULL; static int buflen = 0; if(l + 1 > buflen){ @@ -193,6 +162,7 @@ int sendmessage(int fd, const char *msg, int l){ if(l != send(fd, tmpbuf, l, MSG_NOSIGNAL)){ WARN("write()"); LOGWARN("write()"); + pthread_mutex_unlock(&mutex); return FALSE; }else{ //DBG("success"); @@ -201,35 +171,51 @@ int sendmessage(int fd, const char *msg, int l){ LOGDBG("SEND '%s'", tmpbuf); } } + pthread_mutex_unlock(&mutex); return TRUE; } -int sendstrmessage(int fd, const char *msg){ - if(fd < 1 || !msg) return FALSE; +int cc_sendstrmessage(int fd, const char *msg){ + FNAME(); + if(fd < 1 || !msg) return TRUE; // empty message int l = strlen(msg); - return sendmessage(fd, msg, l); + return cc_sendmessage(fd, msg, l); } -// text messages for `hresult` -static const char *resmessages[] = { +// 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_BADKEY] = "BADKEY", [RESULT_BADVAL] = "BADVAL", - [RESULT_SILENCE] = "", + [RESULT_BADKEY] = "BADKEY", +// [RESULT_SILENCE] = NULL, // nothing to send +// [RESULT_DISCONNECTED] = NULL, // not to send }; -const char *hresult2str(hresult r){ +const char *cc_hresult2str(cc_hresult r){ + /*red("ALL results:\n"); + for(cc_hresult res = 0; res < RESULT_NUM; ++res){ + printf("%d: %s\n", res, resmessages[res]); + }*/ if(r < 0 || r >= RESULT_NUM) return "BADRESULT"; return resmessages[r]; } +cc_hresult cc_str2hresult(const char *str){ + for(cc_hresult res = 0; res < RESULT_NUM; ++res){ + if(!resmessages[res]) continue; + if(0 == strcmp(resmessages[res], str)) return res; + } + return RESULT_NUM; // didn't find +} + /** - * @brief get_keyval - get value of `key = val` + * @brief cc_get_keyval - get value of `key = val` * @param keyval (io) - pair `key = val`, return `key` * @return `val` */ -char *get_keyval(char *keyval){ +char *cc_get_keyval(char *keyval){ //DBG("Got string %s", keyval); // remove starting spaces in key while(isspace(*keyval)) ++keyval; @@ -253,7 +239,7 @@ char *get_keyval(char *keyval){ * @param fd - file descriptor * @return 0 in case of timeout, 1 in case of fd have data, -1 if error */ -int canberead(int fd){ +int cc_canberead(int fd){ fd_set fds; struct timeval timeout; timeout.tv_sec = 0; @@ -279,19 +265,56 @@ int canberead(int fd){ } /** - * @brief getshm - get shared memory segment for image + * @brief cc_setNtries, cc_getNtries - ntries setter and getter + * @param n - new amount of tries + * @return cc_setNtries returns TRUE if succeed, cc_getNtries returns current ntries value + */ +int cc_setNtries(int n){ + if(n > 1000 || n < 1) return FALSE; + ntries = n; + return TRUE; +} +int cc_getNtries(){return ntries;} + +static cc_hresult sendstrN(int fd, const char *str){ + for(int i = 0; i < ntries; ++i){ + if(!cc_sendstrmessage(fd, str)) continue; + double t0 = dtime(); + while(dtime() - t0 < CC_ANSWER_TIMEOUT){ + // TODO: continue the code + } + } + return FALSE; +} + +/** + * @brief cc_sendint - send integer value over socket (make 2 tries) + * @param fd - socket fd + * @param cmd - setter + * @param val - value + * @return answer received + */ +cc_hresult cc_sendint(int fd, const char *cmd, int val){ +#define BBUFS (63) + char buf[BBUFS+1]; + snprintf(buf, BBUFS, "%s=%d\n", cmd, val); + return sendstrN(fd, buf); +} + +/** + * @brief cc_getshm - get shared memory segment for image * @param imsize - size of image data (in bytes): if !=0 allocate as server, else - as client (readonly) * @return pointer to shared memory region or NULL if failed */ -IMG *getshm(key_t key, size_t imsize){ - size_t shmsize = sizeof(IMG) + imsize; +cc_IMG *cc_getshm(key_t key, size_t imsize){ + size_t shmsize = sizeof(cc_IMG) + imsize; shmsize = 1024 * (1 + shmsize / 1024); DBG("Allocate %zd bytes in shared memory", shmsize); int shmid = -1; int flags = (imsize) ? IPC_CREAT | 0666 : 0; shmid = shmget(key, 0, flags); - if(shmid < 0){ - if(imsize) WARN("Can't get shared memory segment %d", key); // suppress warnings for client + if(shmid < 0 && imsize == 0){ // no SHM segment for client + WARN("Can't get shared memory segment %d", key); return NULL; } if(imsize){ // check if segment exists and its size equal to needs @@ -307,21 +330,146 @@ IMG *getshm(key_t key, size_t imsize){ } } flags = (imsize) ? 0 : SHM_RDONLY; // client opens memory in readonly mode - IMG *ptr = shmat(shmid, NULL, flags); + cc_IMG *ptr = shmat(shmid, NULL, flags); if(ptr == (void*)-1){ if(imsize) WARN("Can't attach SHM segment %d", key); return NULL; } if(!imsize){ - if(ptr->MAGICK != SHM_MAGIC){ + if(ptr->MAGICK != CC_SHM_MAGIC){ WARNX("Shared memory %d isn't belongs to image server", key); shmdt(ptr); return NULL; } return ptr; } - bzero(ptr, sizeof(IMG)); - ptr->data = (void*)((uint8_t*)ptr + sizeof(IMG)); - ptr->MAGICK = SHM_MAGIC; + bzero(ptr, sizeof(cc_IMG)); + ptr->data = (void*)((uint8_t*)ptr + sizeof(cc_IMG)); + ptr->MAGICK = CC_SHM_MAGIC; return ptr; } + + +// find plugin +static void *open_plugin(const char *name){ + DBG("try to open lib %s", name); + void* dlh = dlopen(name, RTLD_NOLOAD); // library may be already opened + if(!dlh){ + DBG("Not loaded - load"); + dlh = dlopen(name, RTLD_NOW); + } + if(!dlh){ + WARNX(_("Can't find plugin %s: %s"), name, dlerror()); + return NULL; + } + return dlh; +} + +cc_Focuser *open_focuser(const char *pluginname){ + FNAME(); + void* dlh = open_plugin(pluginname); + if(!dlh) return NULL; + cc_Focuser* f = (cc_Focuser*) dlsym(dlh, "focuser"); + if(!f){ + WARNX(_("Can't find focuser in plugin %s: %s"), pluginname, dlerror()); + return NULL; + } + return f; +} +cc_Camera *open_camera(const char *pluginname){ + FNAME(); + void* dlh = open_plugin(pluginname); + if(!dlh) return NULL; + cc_Camera *c = (cc_Camera*) dlsym(dlh, "camera"); + if(!c){ + WARNX(_("Can't find camera in plugin %s: %s"), pluginname, dlerror()); + return NULL; + } + return c; +} +cc_Wheel *open_wheel(const char *pluginname){ + FNAME(); + void* dlh = open_plugin(pluginname); + if(!dlh) return NULL; + cc_Wheel *w = (cc_Wheel*) dlsym(dlh, "wheel"); + if(!w){ + WARNX(_("Can't find wheel in plugin %s: %s"), pluginname, dlerror()); + return NULL; + } + return w; +} + +/** + * @brief cc_getNbytes - calculate amount of bytes to store bitpix (1/2) + * @param image - image + * @return 1 for bitpix<8 or 2 + */ +int cc_getNbytes(cc_IMG *image){ + int n = (image->bitpix + 7) / 8; + if(n < 1) n = 1; + if(n > 2) n = 2; + return n; +} + +cc_charbuff *cc_bufnew(size_t size){ + DBG("Allocate new buffer with size %zd", size); + cc_charbuff *b = MALLOC(cc_charbuff, 1); + b->bufsize = size; + b->buf = MALLOC(char, size); + return b; +} + +void cc_bufdel(cc_charbuff **buf){ + FREE((*buf)->buf); + FREE(*buf); +} + +/** + * @brief cc_read2buf - try to read next data portion from POLLED socket + * @param fd - socket fd to read from + * @param buf - buffer to read + * @return FALSE in case of buffer overflow or client disconnect, TRUE if got 0..n bytes of data + */ +int cc_read2buf(int fd, cc_charbuff *buf){ + int ret = FALSE; + if(!buf) return FALSE; + pthread_mutex_lock(&buf->mutex); + if(!buf->buf || buf->buflen >= buf->bufsize) goto ret; + size_t maxlen = buf->bufsize - buf->buflen; + ssize_t rd = read(fd, buf->buf + buf->buflen, maxlen); + if(rd <= 0) goto ret; + DBG("got %zd bytes", rd); + if(rd) buf->buflen += rd; + ret = TRUE; +ret: + pthread_mutex_unlock(&buf->mutex); + return ret; +} + +/** + * @brief cc_getline - read '\n'-terminated string from `b` and substitute '\n' by 0 + * @param b - input charbuf + * @param str (allocated outside) - string-receiver + * @param len - length of `str` (including terminating zero) + * @return amount of bytes read + */ +size_t cc_getline(cc_charbuff *b, char *str, size_t len){ + if(!b) return 0; + size_t idx = 0; + pthread_mutex_lock(&b->mutex); + if(!b->buf) goto ret; + --len; // for terminating zero + char *ptr = b->buf; + for(; idx < b->buflen; ++idx) if(*ptr++ == '\n') break; + if(idx == b->buflen) goto ret; + size_t minlen = (len > idx) ? idx : len; // prevent `str` overflow + memcpy(str, b->buf, minlen); + str[minlen] = 0; + if(++idx < b->buflen){ // move rest of data in buffer to beginning + memmove(b->buf, b->buf+idx, b->buflen-idx); + b->buflen -= idx; + }else b->buflen = 0; +ret: + pthread_mutex_unlock(&b->mutex); + return idx; +} diff --git a/ccdcapture.h b/ccdcapture.h new file mode 100644 index 0000000..c6af47c --- /dev/null +++ b/ccdcapture.h @@ -0,0 +1,283 @@ +/* + * This file is part of the CCD_Capture project. + * Copyright 2022 Edward V. Emelianov . + * + * 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 . + */ + +#pragma once +#include +#include +#include // for size_t + +// magic to mark our SHM +#define CC_SHM_MAGIC (0xdeadbeef) + +// base image parameters - sent by socket and stored in shared memory +typedef struct __attribute__((packed, aligned(4))){ + uint32_t MAGICK; // magick (DEADBEEF) - to mark our shm + double timestamp; // timestamp of image taken + uint8_t bitpix; // bits per pixel (8 or 16) + int w, h; // image size + uint16_t max, min; // min/max values + float avr, std; // statistics + size_t bytelen; // size of image in bytes + size_t imnumber; // counter of images captured from server's start + void *data; // pointer to data (next byte after this struct) - only for server + /* `data` is uint8_t or uint16_t depending on `bitpix` */ +} cc_IMG; + +// format of single frame +typedef struct{ + int w; int h; // width & height + int xoff; int yoff; // X and Y offset +} cc_frameformat; + +typedef enum{ + SHUTTER_OPEN, // open shutter now + SHUTTER_CLOSE, // close shutter now + SHUTTER_OPENATLOW, // ext. expose control @low + SHUTTER_OPENATHIGH, // -//- @high + SHUTTER_AMOUNT, // amount of entries +} cc_shutter_op; + +typedef enum{ + CAPTURE_NO, // no capture initiated + CAPTURE_PROCESS, // in progress + CAPTURE_CANTSTART, // can't start + CAPTURE_ABORTED, // some error - aborted + CAPTURE_READY, // ready - user can read image +} cc_capture_status; + +typedef enum{ + FAN_OFF, + FAN_LOW, + FAN_MID, + FAN_HIGH, +} cc_fan_speed; + +// all setters and getters of Camera, Focuser and cc_Wheel should return TRUE if success or FALSE if failed or unsupported +// camera +typedef struct{ + int (*check)(); // check if the device is available, connect and init + int Ndevices; // amount of devices found + void (*close)(); // disconnect & close device + int (*startexposition)(); // start exposition + int (*pollcapture)(cc_capture_status *st, float *remain);// get `st` - status of capture process, `remain` - time remain (s); @return FALSE if error (exp aborted), TRUE while no errors + int (*capture)(cc_IMG *ima); // capture an image, struct `ima` should be prepared before + void (*cancel)(); // cancel exposition + // setters: + int (*setDevNo)(int n); // set active device number + int (*setbrightness)(float b); + int (*setexp)(float e); + int (*setgain)(float g); + int (*setT)(float t); + int (*setbin)(int binh, int binv); // binning + int (*setnflushes)(int N); // flushes amount + int (*shuttercmd)(cc_shutter_op s); // work with shutter + int (*confio)(int s); // configure IO-port + int (*setio)(int s); // set IO-port to given state + int (*setframetype)(int l); // set frametype: 1 - light, 0 - dark + int (*setbitdepth)(int h); // set bit depth : 1 - high (16 bit), 0 - low (8 bit) + int (*setfastspeed)(int s); // set readout speed: 1 - fast, 0 - low + // geometry (if TRUE, all args are changed to suitable values) + int (*setgeometry)(cc_frameformat *fmt); // set geometry in UNBINNED coordinates + int (*setfanspeed)(cc_fan_speed spd); // set fan speed + // getters: + int (*getbitpix)(uint8_t *bp); // get bit depth in bits per pixel (8, 12, 16 etc) + int (*getbrightness)(float *b);// get brightnes level + int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) + int (*getgain)(float *g); // get gain value + int (*getmaxgain)(float *g);// get max available gain value + // get limits of geometry: maximal values and steps + int (*getgeomlimits)(cc_frameformat *max, cc_frameformat *step); + int (*getTcold)(float *t); // cold-side T + int (*getThot)(float *t); // hot-side T + int (*getTbody)(float *t); // body T + int (*getbin)(int *binh, int *binv); + int (*getio)(int *s); // get IO-port state + float pixX, pixY; // pixel size in um + cc_frameformat field; // max field of view + cc_frameformat array; // array format + cc_frameformat geometry; // current geometry settings (as in setgeometry) +} cc_Camera; + +// focuser +typedef struct{ + int (*check)(); // check if the device is available + int Ndevices; + void (*close)(); + // setters: + int (*setDevNo)(int n); // set active device number + int (*setAbsPos)(int async, float n);// set absolute position (in millimeters!!!) + int (*home)(int async); // home device + // getters: + int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) + int (*getTbody)(float *t); // body T + int (*getPos)(float *p); // current position number (starting from zero) + int (*getMaxPos)(float *p); // max position + int (*getMinPos)(float *p); // min position +} cc_Focuser; + +// wheel +typedef struct{ + int (*check)(); // check if the device is available + int Ndevices; + void (*close)(); + // setters: + int (*setDevNo)(int n); // set active device number + int (*setPos)(int n); // set absolute position (starting from 0) + // getters: + int (*getModelName)(char *n, int l);// string with model name (l - length of n in bytes) + int (*getTbody)(float *t); // body T + int (*getPos)(int *p); // current position number (starting from zero) + int (*getMaxPos)(int *p); // amount of positions +} cc_Wheel; + +cc_Focuser *open_focuser(const char *pluginname); +cc_Camera *open_camera(const char *pluginname); +cc_Wheel *open_wheel(const char *pluginname); +int cc_getNbytes(cc_IMG *image); + +/****** Content of old socket.h ******/ + +// max & min TCP socket port number +#define CC_PORTN_MAX (65535) +#define CC_PORTN_MIN (1024) + +// Max amount of connections +#define CC_MAXCLIENTS (30) + +// wait for mutex locking +#define CC_BUSY_TIMEOUT (1.0) +// waiting for answer timeout +#define CC_ANSWER_TIMEOUT (0.01) +// wait for exposition ends (between subsequent check calls) +#define CC_WAIT_TIMEOUT (2.0) +// client will disconnect after this time from last server message +#define CC_CLIENT_TIMEOUT (3.0) + +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_hresult; + +const char *cc_hresult2str(cc_hresult r); +cc_hresult cc_str2hresult(const char *str); +int cc_setNtries(int n); +int cc_getNtries(); + +// fd - socket fd to send private messages, key, val - key and its value +typedef cc_hresult (*cc_mesghandler)(int fd, const char *key, const char *val); + +typedef struct{ + cc_hresult (*chkfunction)(char *val); // function to check device is ready + cc_mesghandler handler; // handler function + const char *key; // keyword +} cc_handleritem; + +int cc_open_socket(int isserver, char *path, int isnet); +int cc_senddata(int fd, void *data, size_t l); +int cc_sendmessage(int fd, const char *msg, int l); +int cc_sendstrmessage(int fd, const char *msg); +char *cc_get_keyval(char *keyval); +cc_IMG *cc_getshm(key_t key, size_t imsize); +int cc_canberead(int fd); +cc_hresult cc_sendint(int fd, const char *cmd, int val); + + +/****** Content of old server.h ******/ + +typedef enum{ + CAMERA_IDLE, // idle state, client send this to cancel capture + CAMERA_CAPTURE, // capturing frame, client send this to start capture + CAMERA_FRAMERDY, // frame ready to be saved + CAMERA_ERROR // can't do exposition +} cc_camera_state; + +// common information about everything +#define CC_CMD_INFO "info" +#define CC_CMD_HELP "help" +// restart server +#define CC_CMD_RESTART "restartTheServer" +// get image size in pixels +#define CC_CMD_IMWIDTH "imwidth" +#define CC_CMD_IMHEIGHT "imheight" +// get shared memory key +#define CC_CMD_SHMEMKEY "shmemkey" + +// CCD/CMOS +#define CC_CMD_CAMLIST "camlist" +#define CC_CMD_CAMDEVNO "camdevno" +#define CC_CMD_EXPOSITION "exptime" +#define CC_CMD_LASTFNAME "lastfilename" +#define CC_CMD_FILENAME "filename" +#define CC_CMD_FILENAMEPREFIX "filenameprefix" +// rewrite=1 will rewrite files, =0 - not (only for `filename`) +#define CC_CMD_REWRITE "rewrite" +#define CC_CMD_HBIN "hbin" +#define CC_CMD_VBIN "vbin" +#define CC_CMD_CAMTEMPER "tcold" +#define CC_CMD_CAMFANSPD "ccdfanspeed" +#define CC_CMD_SHUTTER "shutter" +#define CC_CMD_CONFIO "confio" +#define CC_CMD_IO "io" +#define CC_CMD_GAIN "gain" +#define CC_CMD_BRIGHTNESS "brightness" +#define CC_CMD_FRAMEFORMAT "format" +#define CC_CMD_FRAMEMAX "maxformat" +#define CC_CMD_NFLUSHES "nflushes" +// expstate=CAMERA_CAPTURE will start exposition, CAMERA_IDLE - cancel +#define CC_CMD_EXPSTATE "expstate" +#define CC_CMD_TREMAIN "tremain" +#define CC_CMD_8BIT "8bit" +#define CC_CMD_FASTSPD "fastspeed" +#define CC_CMD_DARK "dark" +#define CC_CMD_INFTY "infty" +// FITS file keywords +#define CC_CMD_AUTHOR "author" +#define CC_CMD_INSTRUMENT "instrument" +#define CC_CMD_OBSERVER "observer" +#define CC_CMD_OBJECT "object" +#define CC_CMD_PROGRAM "program" +#define CC_CMD_OBJTYPE "objtype" +#define CC_CMD_HEADERFILES "headerfiles" + +// focuser +#define CC_CMD_FOCLIST "foclist" +#define CC_CMD_FDEVNO "focdevno" +#define CC_CMD_FGOTO "focpos" + +// wheel +#define CC_CMD_WLIST "wlist" +#define CC_CMD_WDEVNO "wdevno" +#define CC_CMD_WPOS "wpos" + +typedef struct{ + char* buf; // databuffer + size_t bufsize; // size of `buf` + size_t buflen; // current buffer length + pthread_mutex_t mutex; // mutex for atomic data access +} cc_charbuff; + +cc_charbuff *cc_bufnew(size_t size); +void cc_bufdel(cc_charbuff **buf); +int cc_read2buf(int fd, cc_charbuff *buf); +size_t cc_getline(cc_charbuff *b, char *str, size_t len); diff --git a/ccdcapture.pc.in b/ccdcapture.pc.in new file mode 100644 index 0000000..a94cf1d --- /dev/null +++ b/ccdcapture.pc.in @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @PROJLIB@ +Description: ccd_capture client library +Version: @VERSION@ +Libs: -L${libdir} -l@PROJLIB@ +Cflags: -I${includedir} diff --git a/ccdfunc.c b/ccdfunc.c index f41d958..c7ddd28 100644 --- a/ccdfunc.c +++ b/ccdfunc.c @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -#include // dlopen/close #include #include #include // pthread_kill @@ -34,9 +33,9 @@ #endif #include "omp.h" -Camera *camera = NULL; -Focuser *focuser = NULL; -Wheel *wheel = NULL; +cc_Camera *camera = NULL; +cc_Focuser *focuser = NULL; +cc_Wheel *wheel = NULL; static int fitserror = 0; @@ -56,52 +55,6 @@ do{ int status = 0; \ #define TMBUFSIZ 40 -// find plugin -static void *open_plugin(const char *name){ - DBG("try to open lib %s", name); - void* dlh = dlopen(name, RTLD_NOLOAD); // library may be already opened - if(!dlh) dlh = dlopen(name, RTLD_NOW); - if(!dlh){ - WARNX(_("Can't find plugin %s: %s"), name, dlerror()); - return NULL; - } - return dlh; -} - -static void *init_focuser(const char *pluginname){ - FNAME(); - void* dlh = open_plugin(pluginname); - if(!dlh) return NULL; - focuser = (Focuser*) dlsym(dlh, "focuser"); - if(!focuser){ - WARNX(_("Can't find focuser in plugin %s: %s"), pluginname, dlerror()); - return NULL; - } - return dlh; -} -static void *init_camera(const char *pluginname){ - FNAME(); - void* dlh = open_plugin(pluginname); - if(!dlh) return NULL; - camera = (Camera*) dlsym(dlh, "camera"); - if(!camera){ - WARNX(_("Can't find camera in plugin %s: %s"), pluginname, dlerror()); - return NULL; - } - return dlh; -} -static void *init_wheel(const char *pluginname){ - FNAME(); - void* dlh = open_plugin(pluginname); - if(!dlh) return NULL; - wheel = (Wheel*) dlsym(dlh, "wheel"); - if(!wheel){ - WARNX(_("Can't find wheel in plugin %s: %s"), pluginname, dlerror()); - return NULL; - } - return dlh; -} - /* static size_t curtime(char *s_time){ // current date/time time_t tm = time(NULL); @@ -178,7 +131,7 @@ static void addrec(fitsfile *f, char *filename){ // save FITS file `img` into GP->outfile or GP->outfileprefix_XXXX.fits // if outp != NULL, put into it strdup() of last file name // return FALSE if failed -int saveFITS(IMG *img, char **outp){ +int saveFITS(cc_IMG *img, char **outp){ int ret = FALSE; if(!camera){ LOGERR("Can't save image: no camera device"); @@ -225,7 +178,7 @@ int saveFITS(IMG *img, char **outp){ fitserror = 0; TRYFITS(fits_create_file, &fp, fnam); if(fitserror) goto cloerr; - int nbytes = getNbytes(img); + int nbytes = cc_getNbytes(img); if(nbytes == 1) TRYFITS(fits_create_img, fp, BYTE_IMG, 2, naxes); else TRYFITS(fits_create_img, fp, USHORT_IMG, 2, naxes); if(fitserror) goto cloerr; @@ -374,7 +327,7 @@ cloerr: return ret; } -static void stat8(IMG *image){ +static void stat8(cc_IMG *image){ double sum = 0., sum2 = 0.; size_t size = image->w * image->h; uint8_t max = 0, min = UINT8_MAX; @@ -406,7 +359,7 @@ static void stat8(IMG *image){ image->std = sqrt(fabs(sum2/sz - avr*avr)); image->max = max; image->min = min; } -static void stat16(IMG *image){ +static void stat16(cc_IMG *image){ double sum = 0., sum2 = 0.; size_t size = image->w * image->h; uint16_t max = 0, min = UINT16_MAX; @@ -440,7 +393,7 @@ static void stat16(IMG *image){ } -void calculate_stat(IMG *image){ +void calculate_stat(cc_IMG *image){ int nbytes = ((7 + image->bitpix) / 8); if(nbytes == 1) stat8(image); else stat16(image); @@ -451,20 +404,20 @@ void calculate_stat(IMG *image){ } } -int startFocuser(void **dlh){ +cc_Focuser *startFocuser(){ if(!GP->focuserdev && !GP->commondev){ verbose(3, _("Focuser device not pointed")); - return FALSE; + return NULL; }else{ char *plugin = GP->commondev ? GP->commondev : GP->focuserdev; - if(!(*dlh = init_focuser(plugin))) return FALSE; + if(!(focuser = open_focuser(plugin))) return NULL; } if(!focuser->check()){ verbose(3, _("No focusers found")); focuser = NULL; - return FALSE; + return NULL; } - return TRUE; + return focuser; } void focclose(){ @@ -542,20 +495,20 @@ retn: focclose(); } -int startWheel(void **dlh){ +cc_Wheel *startWheel(){ if(!GP->wheeldev && !GP->commondev){ - verbose(3, _("Wheel device not pointed")); - return FALSE; + verbose(3, _("cc_Wheel device not pointed")); + return NULL; }else{ char *plugin = GP->commondev ? GP->commondev : GP->wheeldev; - if(!(*dlh = init_wheel(plugin))) return FALSE; + if(!(wheel = open_wheel(plugin))) return NULL; } if(!wheel->check()){ verbose(3, _("No wheels found")); wheel = NULL; - return FALSE; + return NULL; } - return TRUE; + return wheel; } void closewheel(){ @@ -591,7 +544,7 @@ void wheels(){ } char buf[BUFSIZ]; if(wheel->getModelName(buf, BUFSIZ)){ - verbose(2, "Wheel model: %s", buf); + verbose(2, "cc_Wheel model: %s", buf); } float t; if(wheel->getTbody(&t)){ @@ -609,7 +562,7 @@ void wheels(){ pos = GP->setwheel; if(pos == -1) goto retn; // no wheel commands if(pos < 0 || pos > maxpos){ - WARNX(_("Wheel position should be from 0 to %d"), maxpos); + WARNX(_("cc_Wheel position should be from 0 to %d"), maxpos); goto retn; } if(!wheel->setPos(pos)) @@ -624,8 +577,8 @@ static void closeall(){ if(wheel){wheel->close(); wheel = NULL;} }*/ -static capture_status capt(){ - capture_status cs; +static cc_capture_status capt(){ + cc_capture_status cs; float tremain, tmpf; while(camera->pollcapture(&cs, &tremain)){ if(cs != CAPTURE_PROCESS) break; @@ -643,20 +596,20 @@ static capture_status capt(){ return cs; } -int startCCD(void **dlh){ +cc_Camera *startCCD(){ if(!GP->cameradev && !GP->commondev){ verbose(3, _("Camera device not pointed")); - return FALSE; + return NULL; }else{ char *plugin = GP->commondev ? GP->commondev : GP->cameradev; - if(!(*dlh = init_camera(plugin))) return FALSE; + if(!(camera = open_camera(plugin))) return NULL; } if(!camera->check()){ verbose(3, _("No cameras found")); LOGWARN(_("No cameras found")); - return FALSE; + return NULL; } - return TRUE; + return camera; } void closecam(){ @@ -692,7 +645,7 @@ int prepare_ccds(){ } if(GP->fanspeed > -1){ if(GP->fanspeed > FAN_HIGH) GP->fanspeed = FAN_HIGH; - if(!camera->setfanspeed((fan_speed)GP->fanspeed)) + if(!camera->setfanspeed((cc_fan_speed)GP->fanspeed)) WARNX(_("Can't set fan speed")); else verbose(0, _("Set fan speed to %d"), GP->fanspeed); } @@ -724,7 +677,7 @@ int prepare_ccds(){ 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]); - if(!camera->shuttercmd((shutter_op)GP->shtr_cmd)) + if(!camera->shuttercmd((cc_shutter_op)GP->shtr_cmd)) WARNX(_("Can't run shutter command %s (unsupported?)"), str[GP->shtr_cmd]); } if(GP->confio > -1){ @@ -774,7 +727,7 @@ int prepare_ccds(){ if(GP->X1 < GP->X0+1 || GP->X1 > x1) GP->X1 = x1; if(GP->Y1 < GP->Y0+1 || GP->Y1 > y1) GP->Y1 = y1; DBG("x1/x0: %d/%d", GP->X1, GP->X0); - frameformat fmt = {.w = GP->X1 - GP->X0, .h = GP->Y1 - GP->Y0, .xoff = GP->X0, .yoff = GP->Y0}; + cc_frameformat fmt = {.w = GP->X1 - GP->X0, .h = GP->Y1 - GP->Y0, .xoff = GP->X0, .yoff = GP->Y0}; if(!camera->setgeometry(&fmt)) WARNX(_("Can't set given geometry")); verbose(3, "Geometry: off=%d/%d, wh=%d/%d", fmt.xoff, fmt.yoff, fmt.w, fmt.h); @@ -809,13 +762,13 @@ retn: */ void ccds(){ FNAME(); - frameformat fmt = camera->geometry; + 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); // 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); - IMG ima = {.data = img, .w = raw_width, .h = raw_height}; + cc_IMG ima = {.data = img, .w = raw_width, .h = raw_height}; if(GP->nframes < 1) GP->nframes = 1; for(int j = 0; j < GP->nframes; ++j){ TIMESTAMP("Start next cycle"); @@ -870,18 +823,6 @@ void camstop(){ } } -/** - * @brief getNbytes - calculate amount of bytes to store bitpix (1/2) - * @param image - image - * @return 1 for bitpix<8 or 2 - */ -int getNbytes(IMG *image){ - int n = (image->bitpix + 7) / 8; - if(n < 1) n = 1; - if(n > 2) n = 2; - return n; -} - #ifdef IMAGEVIEW #define NFRM (10) void framerate(){ @@ -902,7 +843,7 @@ static volatile int exitgrab = FALSE; static volatile size_t lastgrabno = 0; static void *grabnext(void *arg){ FNAME(); - IMG *ima = (IMG*) arg; + cc_IMG *ima = (cc_IMG*) arg; do{ if(exitgrab) return NULL; TIMESTAMP("Start next exp"); @@ -913,7 +854,7 @@ static void *grabnext(void *arg){ usleep(10000); continue; } - capture_status cs = CAPTURE_ABORTED; + cc_capture_status cs = CAPTURE_ABORTED; TIMESTAMP("Poll"); while(camera->pollcapture(&cs, NULL)){ if(cs != CAPTURE_PROCESS) break; @@ -933,10 +874,10 @@ static void *grabnext(void *arg){ /** * @brief ccdcaptured - get new image data for viewer - * @param img - pointer to IMG* (if IMG* is NULL, will be allocated here) + * @param img - pointer to cc_IMG* (if cc_IMG* is NULL, will be allocated here) * @return TRUE if new image available */ -int ccdcaptured(IMG **imgptr){ +int ccdcaptured(cc_IMG **imgptr){ if(!imgptr) return FALSE; //TIMESTAMP("ccdcaptured() start"); static pthread_t grabthread = 0; @@ -952,14 +893,14 @@ int ccdcaptured(IMG **imgptr){ DBG("OK"); return FALSE; } - frameformat fmt = camera->geometry; + cc_frameformat fmt = camera->geometry; int raw_width = fmt.w / GP->hbin, raw_height = fmt.h / GP->vbin; - IMG *ima = NULL; + cc_IMG *ima = NULL; if(*imgptr && ((*imgptr)->w != raw_width || (*imgptr)->h != raw_height)) FREE(*imgptr); if(!*imgptr){ 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); - ima = MALLOC(IMG, 1); + ima = MALLOC(cc_IMG, 1); ima->data = img; ima->w = raw_width; ima->h = raw_height; @@ -987,3 +928,45 @@ int ccdcaptured(IMG **imgptr){ return FALSE; } #endif + +// common part of client-server +#include "client.h" +#include "server.h" +/** + * @brief start_socket - create socket and run client or server + * @param isserver - TRUE for server, FALSE for client + * @return 0 if OK + */ +int start_socket(int isserver){ + char *path = NULL; + 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"); + 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"); + } + if(isserver){ + imsock = cc_open_socket(TRUE, GP->imageport, 2); // image socket should be networked + server(sock, imsock); + }else{ +#ifdef IMAGEVIEW + if(GP->showimage){ + 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"); + }else +#endif + client(sock); + } + DBG("Close socket"); + close(sock); + if(isserver){ + close(imsock); + signals(0); + } + return 0; +} diff --git a/ccdfunc.h b/ccdfunc.h index f3aa659..a2b57f3 100644 --- a/ccdfunc.h +++ b/ccdfunc.h @@ -17,30 +17,29 @@ */ #pragma once -#include "basestructs.h" +#include "ccdcapture.h" -extern Camera *camera; -extern Focuser *focuser; -extern Wheel *wheel; +extern cc_Camera *camera; +extern cc_Focuser *focuser; +extern cc_Wheel *wheel; -void calculate_stat(IMG *image); -int saveFITS(IMG *img, char **outp); // for imageview module +void calculate_stat(cc_IMG *image); +int saveFITS(cc_IMG *img, char **outp); // for imageview module void focusers(); void wheels(); int prepare_ccds(); void ccds(); void camstop(); -int getNbytes(IMG *image); - -int startCCD(void **dlh); -int startWheel(void **dlh); -int startFocuser(void **dlh); +cc_Camera *startCCD(); +cc_Wheel *startWheel(); +cc_Focuser *startFocuser(); void focclose(); void closewheel(); void closecam(); #ifdef IMAGEVIEW void framerate(); -int ccdcaptured(IMG **img); +int ccdcaptured(cc_IMG **img); #endif +int start_socket(int isserver); diff --git a/client.c b/client.c index 6eb5d4b..b4d3632 100644 --- a/client.c +++ b/client.c @@ -34,11 +34,11 @@ static char sendbuf[BUFSIZ]; // send message and wait any answer -#define SENDMSG(...) do{DBG("SENDMSG"); snprintf(sendbuf, BUFSIZ-1, __VA_ARGS__); verbose(2, "\t> %s", sendbuf); sendstrmessage(sock, sendbuf); while(getans(sock, NULL));} while(0) +#define SENDMSG(...) do{DBG("SENDMSG"); snprintf(sendbuf, BUFSIZ-1, __VA_ARGS__); verbose(2, "\t> %s", sendbuf); cc_sendstrmessage(sock, sendbuf); while(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); sendstrmessage(sock, sendbuf);}while(!getans(sock, cmd)) +#define SENDMSGW(cmd, ...) do{DBG("SENDMSGW"); snprintf(sendbuf, BUFSIZ-1, cmd __VA_ARGS__); verbose(2, "\t> %s", sendbuf); cc_sendstrmessage(sock, sendbuf);}while(!getans(sock, cmd)) // send command and wait for answer on it -#define SENDCMDW(cmd) do{DBG("SENDCMDW"); strncpy(sendbuf, cmd, BUFSIZ-1); verbose(2, "\t> %s", sendbuf); sendstrmessage(sock, sendbuf);}while(!getans(sock, cmd)) +#define SENDCMDW(cmd) do{DBG("SENDCMDW"); strncpy(sendbuf, cmd, BUFSIZ-1); verbose(2, "\t> %s", sendbuf); cc_sendstrmessage(sock, sendbuf);}while(!getans(sock, cmd)) static volatile atomic_int expstate = CAMERA_CAPTURE; static int xm0,ym0,xm1,ym1; // max format static int xc0,yc0,xc1,yc1; // current format @@ -46,35 +46,27 @@ static int xc0,yc0,xc1,yc1; // current format #ifdef IMAGEVIEW static volatile atomic_int grabno = 0, oldgrabno = 0; // IPC key for shared memory -static IMG ima = {0}, *shmima = NULL; // ima - local storage, shmima - shm (if available) +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; #endif static char *readmsg(int fd){ - static char buf[BUFSIZ] = {0}, line[BUFSIZ]; - int curlen = strlen(buf); - if(curlen == BUFSIZ-1) curlen = 0; // buffer overflow - clear old content - ssize_t rd = 0; - if(1 == canberead(fd)){ - rd = read(fd, buf + curlen, BUFSIZ-1 - curlen); - if(rd <= 0){ - WARNX("Server disconnected"); - signals(1); + static cc_charbuff *buf = NULL; + static char line[BUFSIZ]; + if(!buf) buf = cc_bufnew(BUFSIZ); + if(1 == cc_canberead(fd)){ + if(cc_read2buf(fd, buf)){ + size_t got = cc_getline(buf, line, BUFSIZ); + if(got >= BUFSIZ){ + DBG("Client fd=%d gave buffer overflow", fd); + LOGMSG("SERVER client fd=%d buffer overflow", fd); + }else if(got){ + return line; } + }else ERRX("Server disconnected"); } - curlen += rd; - buf[curlen] = 0; - if(curlen == 0) return NULL; - //DBG("cur buffer: ----%s----", buf); - char *nl = strchr(buf, '\n'); - if(!nl) return NULL; - *nl++ = 0; - strcpy(line, buf); - int rest = curlen - (int)(nl-buf); - if(rest > 0) memmove(buf, nl, rest+1); - else *buf = 0; - return line; + return NULL; } // parser of CCD server messages; return TRUE to exit from polling cycle of `getans` (if receive 'FAIL', 'OK' or 'BUSY') @@ -82,41 +74,26 @@ static int parseans(char *ans){ if(!ans) return FALSE; //TIMESTAMP("parseans() begin"); //DBG("Parsing of '%s'", ans); - if(0 == strcmp(hresult2str(RESULT_BUSY), ans)){ + if(0 == strcmp(cc_hresult2str(RESULT_BUSY), ans)){ WARNX("Server busy"); return FALSE; } - if(0 == strcmp(hresult2str(RESULT_FAIL), ans)) return TRUE; - if(0 == strcmp(hresult2str(RESULT_OK), ans)) return TRUE; - char *val = get_keyval(ans); // now `ans` is a key and `val` its value - if(0 == strcmp(CMD_EXPSTATE, ans)){ + if(0 == strcmp(cc_hresult2str(RESULT_FAIL), ans)) return TRUE; + if(0 == strcmp(cc_hresult2str(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); DBG("Exposition state: %d", expstate); return TRUE; - }else if(0 == strcmp(CMD_FRAMEMAX, ans)){ + }else if(0 == strcmp(CC_CMD_FRAMEMAX, ans)){ sscanf(val, "%d,%d,%d,%d", &xm0, &ym0, &xm1, &ym1); DBG("Got maxformat: %d,%d,%d,%d", xm0, ym0, xm1, ym1); return TRUE; - }else if(0 == strcmp(CMD_FRAMEFORMAT, ans)){ + }else if(0 == strcmp(CC_CMD_FRAMEFORMAT, ans)){ sscanf(val, "%d,%d,%d,%d", &xc0, &yc0, &xc1, &yc1); DBG("Got current format: %d,%d,%d,%d", xc0, yc0, xc1, yc1); return TRUE; - }else if(0 == strcmp(CMD_INFTY, ans)) return TRUE; - /* -#ifdef IMAGEVIEW - else if(0 == strcmp(CMD_IMWIDTH, ans)){ - ima.w = atoi(val); - DBG("Get width: %d", ima.w); - imdatalen = ima.w * ima.h * 2; - return TRUE; - }else if(0 == strcmp(CMD_IMHEIGHT, ans)){ - ima.h = atoi(val); - DBG("Get height: %d", ima.h); - imdatalen = ima.w * ima.h * 2; - return TRUE; - } -#endif -*/ + }else if(0 == strcmp(CC_CMD_INFTY, ans)) return TRUE; //TIMESTAMP("parseans() end"); return FALSE; } @@ -126,13 +103,9 @@ static int parseans(char *ans){ static int getans(int sock, const char *msg){ double t0 = dtime(); char *ans = NULL; - while(dtime() - t0 < ANSWER_TIMEOUT){ + while(dtime() - t0 < CC_ANSWER_TIMEOUT){ char *s = readmsg(sock); if(!s) continue; - /*if(!s){ // buffer is empty, return last message or wait for it - if(ans) return (msg ? FALSE : TRUE); - else continue; - }*/ t0 = dtime(); ans = s; TIMESTAMP("Got from server: %s", ans); @@ -145,7 +118,7 @@ DBG("1 msg-> %s, ans -> %s", msg, ans); break; } } - DBG("GETANS: %s, %s", ans, (dtime()-t0 > ANSWER_TIMEOUT) ? "timeout" : "got answer"); + //DBG("GETANS: %s, %s", ans, (dtime()-t0 > CC_ANSWER_TIMEOUT) ? "timeout" : "got answer"); return ((ans) ? TRUE : FALSE); } @@ -154,22 +127,22 @@ DBG("1 msg-> %s, ans -> %s", msg, ans); */ static void send_headers(int sock){ // common information - SENDMSG(CMD_INFO); + SENDMSG(CC_CMD_INFO); // focuser - if(GP->listdevices) SENDMSG(CMD_FOCLIST); - if(GP->focdevno > -1) SENDMSG(CMD_FDEVNO "=%d", GP->focdevno); + if(GP->listdevices) SENDMSG(CC_CMD_FOCLIST); + if(GP->focdevno > -1) SENDMSG(CC_CMD_FDEVNO "=%d", GP->focdevno); if(!isnan(GP->gotopos)){ - SENDMSGW(CMD_FGOTO, "=%g", GP->gotopos); + SENDMSGW(CC_CMD_FGOTO, "=%g", GP->gotopos); } // wheel - if(GP->listdevices) SENDCMDW(CMD_WLIST); - if(GP->whldevno > -1) SENDMSGW(CMD_WDEVNO, "=%d", GP->whldevno); - if(GP->setwheel > -1) SENDMSGW(CMD_WPOS, "=%d", GP->setwheel); + if(GP->listdevices) SENDCMDW(CC_CMD_WLIST); + if(GP->whldevno > -1) SENDMSGW(CC_CMD_WDEVNO, "=%d", GP->whldevno); + if(GP->setwheel > -1) SENDMSGW(CC_CMD_WPOS, "=%d", GP->setwheel); DBG("nxt"); // CCD/CMOS if(GP->X0 > INT_MIN || GP->Y0 > INT_MIN || GP->X1 > INT_MIN || GP->Y1 > INT_MIN){ // set format - SENDCMDW(CMD_FRAMEMAX); - SENDCMDW(CMD_FRAMEFORMAT); + SENDCMDW(CC_CMD_FRAMEMAX); + SENDCMDW(CC_CMD_FRAMEFORMAT); // default values if(GP->X0 == INT_MIN) GP->X0 = xc0; if(GP->X1 == INT_MIN) GP->X1 = xc1; @@ -183,47 +156,47 @@ static void send_headers(int sock){ if(GP->X1 < GP->X0+1 || GP->X1 > xm1) GP->X1 = xm1; if(GP->Y1 < GP->Y0+1 || GP->Y1 > ym1) GP->Y1 = ym1; DBG("set format: (%d,%d)x(%d,%d)", GP->X0,GP->X1,GP->Y0,GP->Y1); - SENDMSGW(CMD_FRAMEFORMAT, "=%d,%d,%d,%d", GP->X0, GP->Y0, GP->X1, GP->Y1); + SENDMSGW(CC_CMD_FRAMEFORMAT, "=%d,%d,%d,%d", GP->X0, GP->Y0, GP->X1, GP->Y1); } - if(GP->cancelexpose) SENDMSGW(CMD_EXPSTATE, "=%d", CAMERA_IDLE); - if(GP->listdevices) SENDCMDW(CMD_CAMLIST); - if(GP->camdevno > -1) SENDMSGW(CMD_CAMDEVNO, "=%d", GP->camdevno); - if(GP->hbin) SENDMSGW(CMD_HBIN, "=%d", GP->hbin); - if(GP->vbin) SENDMSGW(CMD_VBIN, "=%d", GP->vbin); - if(!isnan(GP->temperature)) SENDMSGW(CMD_CAMTEMPER, "=%g", GP->temperature); - if(GP->shtr_cmd > -1) SENDMSGW(CMD_SHUTTER, "=%d", GP->shtr_cmd); - if(GP->confio > -1) SENDMSGW(CMD_CONFIO, "=%d", GP->confio); - if(GP->setio > -1) SENDMSGW(CMD_IO, "=%d", GP->setio);\ - if(!isnan(GP->gain)) SENDMSGW(CMD_GAIN, "=%g", GP->gain); - if(!isnan(GP->brightness)) SENDMSGW(CMD_BRIGHTNESS, "=%g", GP->brightness); - if(GP->nflushes > 0) SENDMSGW(CMD_NFLUSHES, "=%d", GP->nflushes); + if(GP->cancelexpose) SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_IDLE); + if(GP->listdevices) SENDCMDW(CC_CMD_CAMLIST); + if(GP->camdevno > -1) SENDMSGW(CC_CMD_CAMDEVNO, "=%d", GP->camdevno); + if(GP->hbin) SENDMSGW(CC_CMD_HBIN, "=%d", GP->hbin); + if(GP->vbin) SENDMSGW(CC_CMD_VBIN, "=%d", GP->vbin); + if(!isnan(GP->temperature)) SENDMSGW(CC_CMD_CAMTEMPER, "=%g", GP->temperature); + if(GP->shtr_cmd > -1) SENDMSGW(CC_CMD_SHUTTER, "=%d", GP->shtr_cmd); + if(GP->confio > -1) SENDMSGW(CC_CMD_CONFIO, "=%d", GP->confio); + if(GP->setio > -1) SENDMSGW(CC_CMD_IO, "=%d", GP->setio);\ + if(!isnan(GP->gain)) SENDMSGW(CC_CMD_GAIN, "=%g", GP->gain); + if(!isnan(GP->brightness)) SENDMSGW(CC_CMD_BRIGHTNESS, "=%g", GP->brightness); + if(GP->nflushes > 0) SENDMSGW(CC_CMD_NFLUSHES, "=%d", GP->nflushes); if(GP->exptime > -DBL_EPSILON){ // exposition and reading control: only if start of exposition - if(GP->_8bit) SENDMSGW(CMD_8BIT, "=1"); - else SENDMSGW(CMD_8BIT, "=0"); - if(GP->fast) SENDMSGW(CMD_FASTSPD, "=1"); - else SENDMSGW(CMD_FASTSPD, "=0"); - if(GP->dark) SENDMSGW(CMD_DARK, "=1"); - else SENDMSGW(CMD_DARK, "=0"); + if(GP->_8bit) SENDMSGW(CC_CMD_8BIT, "=1"); + else SENDMSGW(CC_CMD_8BIT, "=0"); + if(GP->fast) SENDMSGW(CC_CMD_FASTSPD, "=1"); + else SENDMSGW(CC_CMD_FASTSPD, "=0"); + if(GP->dark) SENDMSGW(CC_CMD_DARK, "=1"); + else SENDMSGW(CC_CMD_DARK, "=0"); } if(GP->outfile){ - if(!*GP->outfile) SENDMSGW(CMD_FILENAME, "="); - else SENDMSGW(CMD_FILENAME, "=%s", makeabspath(GP->outfile, FALSE)); - if(GP->rewrite) SENDMSGW(CMD_REWRITE, "=1"); - else SENDMSGW(CMD_REWRITE, "=0"); + if(!*GP->outfile) SENDMSGW(CC_CMD_FILENAME, "="); + else SENDMSGW(CC_CMD_FILENAME, "=%s", makeabspath(GP->outfile, FALSE)); + if(GP->rewrite) SENDMSGW(CC_CMD_REWRITE, "=1"); + else SENDMSGW(CC_CMD_REWRITE, "=0"); } if(GP->outfileprefix){ - if(!*GP->outfileprefix) SENDMSGW(CMD_FILENAMEPREFIX, "="); - else SENDMSGW(CMD_FILENAMEPREFIX, "=%s", makeabspath(GP->outfileprefix, FALSE)); + if(!*GP->outfileprefix) SENDMSGW(CC_CMD_FILENAMEPREFIX, "="); + else SENDMSGW(CC_CMD_FILENAMEPREFIX, "=%s", makeabspath(GP->outfileprefix, FALSE)); } - if(GP->exptime > -DBL_EPSILON) SENDMSGW(CMD_EXPOSITION, "=%g", GP->exptime); + if(GP->exptime > -DBL_EPSILON) SENDMSGW(CC_CMD_EXPOSITION, "=%g", GP->exptime); // FITS header keywords: #define CHKHDR(x, cmd) do{if(x) SENDMSG(cmd "=%s", x);}while(0) - CHKHDR(GP->author, CMD_AUTHOR); - CHKHDR(GP->instrument, CMD_INSTRUMENT); - CHKHDR(GP->observers, CMD_OBSERVER); - CHKHDR(GP->objname, CMD_OBJECT); - CHKHDR(GP->prog_id, CMD_PROGRAM); - CHKHDR(GP->objtype, CMD_OBJTYPE); + CHKHDR(GP->author, CC_CMD_AUTHOR); + CHKHDR(GP->instrument, CC_CMD_INSTRUMENT); + CHKHDR(GP->observers, CC_CMD_OBSERVER); + CHKHDR(GP->objname, CC_CMD_OBJECT); + CHKHDR(GP->prog_id, CC_CMD_PROGRAM); + CHKHDR(GP->objtype, CC_CMD_OBJTYPE); #undef CHKHDR if(GP->addhdr){ char buf[1024], *ptr = buf, **sptr = GP->addhdr; @@ -236,16 +209,16 @@ static void send_headers(int sock){ int N = snprintf(ptr, L-1, "%s,", *sptr++); L -= N; ptr += N; } - SENDMSGW(CMD_HEADERFILES, "=%s", buf); + SENDMSGW(CC_CMD_HEADERFILES, "=%s", buf); } } void client(int sock){ if(GP->restart){ - SENDCMDW(CMD_RESTART); + SENDCMDW(CC_CMD_RESTART); return; } - if(GP->infty > -1) SENDMSGW(CMD_INFTY, "=%d", GP->infty); + if(GP->infty > -1) SENDMSGW(CC_CMD_INFTY, "=%d", GP->infty); send_headers(sock); double t0 = dtime(), tw = t0; int Nremain = 0, nframe = 1; @@ -254,26 +227,26 @@ void client(int sock){ Nremain = GP->nframes - 1; if(Nremain < 1) Nremain = 0; else GP->waitexpend = TRUE; // N>1 - wait for exp ends - SENDMSGW(CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); + SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); }else{ int cntr = 0; - while(dtime() - t0 < WAIT_TIMEOUT && cntr < 10) + while(dtime() - t0 < CC_WAIT_TIMEOUT && cntr < 3) if(!getans(sock, NULL)) ++cntr; DBG("RETURN: no more data"); return; } - double timeout = GP->waitexpend ? CLIENT_TIMEOUT : WAIT_TIMEOUT; + double timeout = GP->waitexpend ? CC_CLIENT_TIMEOUT : CC_WAIT_TIMEOUT; verbose(1, "Exposing frame 1..."); if(GP->waitexpend){ expstate = CAMERA_CAPTURE; // could be changed earlier verbose(2, "Wait for exposition end"); } while(dtime() - t0 < timeout){ - if(GP->waitexpend && dtime() - tw > WAIT_TIMEOUT){ - SENDCMDW(CMD_TREMAIN); // get remained time + if(GP->waitexpend && dtime() - tw > CC_WAIT_TIMEOUT){ + SENDCMDW(CC_CMD_TREMAIN); // get remained time tw = dtime(); - sprintf(sendbuf, "%s", CMD_EXPSTATE); - sendstrmessage(sock, sendbuf); + sprintf(sendbuf, "%s", CC_CMD_EXPSTATE); + cc_sendstrmessage(sock, sendbuf); } if(getans(sock, NULL)){ // got next portion of data DBG("server message"); @@ -291,7 +264,7 @@ void client(int sock){ if(GP->pause_len > 0){ double delta, time1 = dtime() + GP->pause_len; while(1){ - SENDCMDW(CMD_CAMTEMPER); + SENDCMDW(CC_CMD_CAMTEMPER); if((delta = time1 - dtime()) < __FLT_EPSILON__) break; // %d секунд до окончания паузы\n if(delta > 1.) verbose(1, _("%d seconds till pause ends\n"), (int)delta); @@ -302,10 +275,10 @@ void client(int sock){ } verbose(1, "Exposing frame %d...", ++nframe); --Nremain; - SENDMSGW(CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); + SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); }else{ GP->waitexpend = 0; - timeout = ANSWER_TIMEOUT; // wait for last file name + timeout = CC_ANSWER_TIMEOUT; // wait for last file name } } } @@ -321,7 +294,7 @@ void init_grab_sock(int sock){ controlfd = sock; send_headers(sock); if(!GP->forceimsock && !shmima){ // init shm buffer if user don't ask to work through image socket - shmima = getshm(GP->shmkey, 0); // try to init client shm + shmima = cc_getshm(GP->shmkey, 0); // try to init client shm } } @@ -332,7 +305,7 @@ 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 < CLIENT_TIMEOUT /*&& canberead(fd)*/ && need){ + while(dtime() - t0 < CC_CLIENT_TIMEOUT /*&& cc_canberead(fd)*/ && need){ ssize_t rd = read(fd, buf + got, need); if(rd <= 0){ WARNX("Server disconnected"); @@ -352,15 +325,15 @@ static void getimage(){ int imsock = -1; static double oldtimestamp = -1.; TIMESTAMP("Get image sizes"); - /*SENDCMDW(CMD_IMWIDTH); - SENDCMDW(CMD_IMHEIGHT);*/ + /*SENDCMDW(CC_CMD_IMWIDTH); + SENDCMDW(CC_CMD_IMHEIGHT);*/ if(shmima){ // read image from shared memory - memcpy(&ima, shmima, sizeof(IMG)); + memcpy(&ima, shmima, sizeof(cc_IMG)); }else{ // get image by socket - imsock = open_socket(FALSE, GP->imageport, TRUE); + imsock = cc_open_socket(FALSE, GP->imageport, TRUE); if(imsock < 0) ERRX("getimage(): can't open image transport socket"); // get image size - if(!readNbytes(imsock, sizeof(IMG), (uint8_t*)&ima)){ + if(!readNbytes(imsock, sizeof(cc_IMG), (uint8_t*)&ima)){ WARNX("Can't read image header"); goto eofg; } @@ -380,7 +353,7 @@ static void getimage(){ 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(IMG); + uint8_t *datastart = (uint8_t*)shmima + sizeof(cc_IMG); memcpy(imbuf, datastart, ima.bytelen); TIMESTAMP("Got by shared memory"); }else{ @@ -390,6 +363,7 @@ static void getimage(){ } TIMESTAMP("Got by socket"); } + DBG("timestamps old-new=%g; imno: %zd", oldtimestamp-ima.timestamp, ima.imnumber); if(ima.timestamp != oldtimestamp){ // test if image is really new oldtimestamp = ima.timestamp; grabno = ima.imnumber; @@ -405,11 +379,11 @@ static void *grabnext(void _U_ *arg){ // daemon grabbing images through the net int sock = controlfd; while(1){ if(!getWin()) exit(1); - expstate = CAMERA_CAPTURE; TIMESTAMP("End of cycle, start new"); + expstate = CAMERA_CAPTURE; TIMEINIT(); - SENDMSGW(CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); // start capture - double timeout = GP->exptime + CLIENT_TIMEOUT, t0 = dtime(); + SENDMSGW(CC_CMD_EXPSTATE, "=%d", CAMERA_CAPTURE); // start capture + double timeout = GP->exptime + CC_CLIENT_TIMEOUT, t0 = dtime(); useconds_t sleept = 500000; // 0.5s if(GP->exptime < 0.5){ sleept = (useconds_t)(GP->exptime * 500000.); @@ -455,7 +429,7 @@ static void *waitimage(void _U_ *arg){ // passive waiting for next image } // try to capture images through socket -int sockcaptured(IMG **imgptr){ +int sockcaptured(cc_IMG **imgptr){ //TIMESTAMP("sockcaptured() start"); if(!imgptr) return FALSE; static pthread_t grabthread = 0; diff --git a/client.h b/client.h index d8b22f9..eae3790 100644 --- a/client.h +++ b/client.h @@ -18,11 +18,11 @@ #pragma once -#include "basestructs.h" +#include "ccdcapture.h" // client-side functions void client(int fd); #ifdef IMAGEVIEW void init_grab_sock(int sock); -int sockcaptured(IMG **img); +int sockcaptured(cc_IMG **img); #endif diff --git a/cmdlnopts.c b/cmdlnopts.c index 8b586f0..a237d23 100644 --- a/cmdlnopts.c +++ b/cmdlnopts.c @@ -8,7 +8,7 @@ #include #include "cmdlnopts.h" -#include "basestructs.h" +#include "ccdcapture.h" static int help; glob_pars *GP = NULL; @@ -104,8 +104,8 @@ myoption cmdlnopts[] = { {"viewer", NO_ARGS, &G.viewer,1, arg_none, NULL, N_("passive viewer (only get last images)")}, {"restart", NO_ARGS, &G.restart,1, arg_none, NULL, N_("restart image server")}, - {"shmkey", NEED_ARG, NULL, 'k', arg_int, APTR(&G.shmkey), N_("shared memory (with image data) key (default: 7777777")}, - {"forceimsock",NO_ARGS, &G.forceimsock,1, arg_none, NULL, N_("force using image through socket transition even if can use SHM")}, + {"shmkey", NEED_ARG, NULL, 'k', arg_int, APTR(&G.shmkey), N_("shared memory (with image data) key (default: 7777777)")}, + {"forceimsock",NO_ARGS, &G.forceimsock,1, arg_none, NULL, N_("force using image through socket transition even if can use SHM)")}, {"infty", NEED_ARG, NULL, 0, arg_int, APTR(&G.infty), N_("start (!=0) or stop(==0) infinity capturing loop")}, #ifdef IMAGEVIEW @@ -125,7 +125,7 @@ myoption cmdlnopts[] = { */ glob_pars *parse_args(int argc, char **argv){ // format of help: "Usage: progname [args]\n" - change_helpstring("Usage: %s [args] [output file prefix or file/dir name to view]\nTo restart server kill it with SIGUSR1\n\tArgs are:\n"); + change_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); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..f4a403e --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) + +include_directories(..) +add_executable(ccd_client main.c) +target_link_libraries(ccd_client ccdcapture usefull_macros) diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 0000000..1746d1b --- /dev/null +++ b/examples/main.c @@ -0,0 +1,107 @@ +/* + * This file is part of the CCD_Capture project. + * Copyright 2023 Edward V. Emelianov . + * + * 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 . + */ + +/* + * A simple example to take 8-bit images with default size and given exposition time. + * Works in `infinity` mode or requesting each file after receiving previous. + */ + +#include +#include +#include + +#include "socket.h" + +typedef struct{ + char *sockname; // UNIX socket name of command socket or port of local socket + int isun; // command socket is UNIX socket instead of INET + int shmkey; // shared memory (with image data) key + int infty; // run in infinity loop (if not - run by requests) + int nframes; // amount of frames to take + int help; // show this help + double exptime; // time of exposition in seconds +} glob_pars; + + +static glob_pars G = { + .shmkey = 7777777, + .nframes = 10 +}; + +/* + * Define command line options by filling structure: + * name has_arg flag val type argptr help +*/ +myoption 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)"}, + {"infty", NO_ARGS, NULL, 'i', arg_int, APTR(&G.infty), "run in infinity capturing loop (else - request each frame)"}, + {"nframes", NEED_ARG, NULL, 'n', arg_int, APTR(&G.nframes), "make series of N frames"}, + {"exptime", NEED_ARG, NULL, 'x', arg_double, APTR(&G.exptime), "set exposure time to given value (seconds!)"}, + {"help", NO_ARGS, NULL, 'h', arg_int, APTR(&G.help), "show this help"}, +}; + +static cc_IMG *shimg = NULL, img = {0}; + +static int refresh_img(){ + if(!shimg) return FALSE; + static size_t imnumber = 0; + if(shimg->imnumber == imnumber) return FALSE; + imnumber = shimg->imnumber; + void *optr = img.data; + memcpy(&img, shimg, sizeof(img)); + img.data = realloc(optr, img.bytelen); + memcpy(img.data, (uint8_t*)shimg + sizeof(cc_IMG), img.bytelen); + return TRUE; +} + +int main(int argc, char **argv){ + initial_setup(); + parseargs(&argc, &argv, cmdlnopts); + if(G.help) showhelp(-1, cmdlnopts); + if(argc > 0){ + WARNX("%d unused parameters:", argc); + for(int i = 0; i < argc; ++i) + printf("%4d: %s\n", i, argv[i]); + } + if(!G.sockname) ERRX("Point socket name or port"); + int sock = cc_open_socket(FALSE, G.sockname, !G.isun); + if(sock < 0) ERR("Can't open socket %s", G.sockname); + shimg = cc_getshm(G.shmkey, 0); + if(!shimg) ERRX("Can't get shared memory segment"); + int i = 0; + time_t oldtime = time(NULL); + double oldtimestamp = shimg->timestamp; + do{ + time_t now = time(NULL); + if(now - oldtime > 5){ + WARNX("No new images for 5 seconds"); + break; + } + if(!refresh_img()){ + usleep(1000); + continue; + } + ++i; + oldtime = now; + printf("Got image #%zd, size %dx%d, bitpix %d, time %g\n", img.imnumber, img.w, img.h, img.bitpix, img.timestamp-oldtimestamp); + }while(i < 10); + close(sock); + return 0; +} diff --git a/imageview.c b/imageview.c index 953719a..313eb86 100644 --- a/imageview.c +++ b/imageview.c @@ -449,7 +449,7 @@ result: 0.0014689s * @param w,h - image width and height * @return data allocated here */ -static uint8_t *equalize(IMG *img, int w, int h){ +static uint8_t *equalize(cc_IMG *img, int w, int h){ uint8_t *retn = MALLOC(uint8_t, w*h); double orig_hysto[0x10000] = {0.}; // original hystogram uint8_t eq_levls[0x10000] = {0}; // levels to convert: newpix = eq_levls[oldpix] @@ -469,7 +469,7 @@ static uint8_t *equalize(IMG *img, int w, int h){ for(int i = 0; i < 0x10000; ++i) orig_hysto[i] += histogram_private[i]; } }*/ - int bytes = getNbytes(img); + int bytes = cc_getNbytes(img); if(bytes == 1){ uint8_t *data = (uint8_t*) img->data; @@ -518,12 +518,12 @@ cuts: 0.00188208s */ // count image cuts as [median-sigma median+5sigma] -static uint8_t *mkcuts(IMG *img, int w, int h){ +static uint8_t *mkcuts(cc_IMG *img, int w, int h){ uint8_t *retn = MALLOC(uint8_t, w*h); int orig_hysto[0x10000] = {0.}; // original hystogram int s = w*h; double sum = 0., sum2 = 0.; - int bytes = getNbytes(img); + int bytes = cc_getNbytes(img); TIMESTAMP("Make histogram"); if(bytes == 1){ uint8_t *data = (uint8_t*) img->data; @@ -607,7 +607,7 @@ static uint8_t *mkcuts(IMG *img, int w, int h){ return retn; } -static void change_displayed_image(IMG *img){ +static void change_displayed_image(cc_IMG *img){ if(!win || !img) return; static size_t lastN = 0; ssize_t delta = img->imnumber - lastN; @@ -704,7 +704,7 @@ int viewer(imagefunc newimage){ WARNX(_("Can't open OpenGL window, image preview will be inaccessible")); return 1; } - IMG *img = NULL; + cc_IMG *img = NULL; //double t0 = dtime(); while(1){ if(!win || win->killthread){ // got kill from ctrl+q diff --git a/imageview.h b/imageview.h index 46607f3..aa162ba 100644 --- a/imageview.h +++ b/imageview.h @@ -82,6 +82,6 @@ void conv_mouse_to_image_coords(int x, int y, float *X, float *Y, windowData *wi void conv_image_to_mouse_coords(float X, float Y, int *x, int *y, windowData *window); windowData* getWin(); -typedef int (*imagefunc)(IMG**); +typedef int (*imagefunc)(cc_IMG**); int viewer(imagefunc); diff --git a/locale/ru/LC_MESSAGES/ccd_capture.mo b/locale/ru/LC_MESSAGES/ccd_capture.mo index 9e0b9c9..04e3f03 100644 Binary files a/locale/ru/LC_MESSAGES/ccd_capture.mo and b/locale/ru/LC_MESSAGES/ccd_capture.mo differ diff --git a/locale/ru/messages.po b/locale/ru/messages.po index 15446ac..04646b0 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: 2023-12-25 16:15+0300\n" +"POT-Creation-Date: 2024-01-24 11:37+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -246,11 +246,11 @@ msgid "restart image server" msgstr "" #: cmdlnopts.c:107 -msgid "shared memory (with image data) key (default: 7777777" +msgid "shared memory (with image data) key (default: 7777777)" msgstr "" #: cmdlnopts.c:108 -msgid "force using image through socket transition even if can use SHM" +msgid "force using image through socket transition even if can use SHM)" msgstr "" #: cmdlnopts.c:109 @@ -261,321 +261,301 @@ msgstr "" msgid "Display image in OpenGL window" msgstr "" -#: ccdfunc.c:65 -#, c-format -msgid "Can't find plugin %s: %s" -msgstr "" - -#: ccdfunc.c:77 -#, c-format -msgid "Can't find focuser in plugin %s: %s" -msgstr "" - -#: ccdfunc.c:88 -#, c-format -msgid "Can't find camera in plugin %s: %s" -msgstr "" - -#: ccdfunc.c:99 -#, c-format -msgid "Can't find wheel in plugin %s: %s" -msgstr "" - -#: ccdfunc.c:185 +#: ccdfunc.c:138 msgid "Camera device unknown" msgstr "" #. п²п╣ п╪п╬пЁя┐ я│п╬я┘я─п╟п╫п╦я┌я▄ я└п╟п╧п╩ -#: ccdfunc.c:209 +#: ccdfunc.c:162 #, c-format msgid "Can't save file with prefix %s" msgstr "" -#: ccdfunc.c:362 +#: ccdfunc.c:315 #, c-format msgid "File saved as '%s'" msgstr "" -#: ccdfunc.c:371 +#: ccdfunc.c:324 msgid "Error saving file" msgstr "" -#: ccdfunc.c:448 +#: ccdfunc.c:401 #, c-format msgid "Image stat:\n" msgstr "" -#: ccdfunc.c:456 +#: ccdfunc.c:409 msgid "Focuser device not pointed" msgstr "" -#: ccdfunc.c:463 +#: ccdfunc.c:416 msgid "No focusers found" msgstr "" -#: ccdfunc.c:494 +#: ccdfunc.c:447 #, c-format msgid "Found %d focusers, you point number %d" msgstr "" -#: ccdfunc.c:498 +#: ccdfunc.c:451 msgid "Can't set active focuser number" msgstr "" -#: ccdfunc.c:512 +#: ccdfunc.c:465 msgid "Can't get focuser limit positions" msgstr "" -#: ccdfunc.c:519 +#: ccdfunc.c:472 msgid "Can't get current focuser position" msgstr "" -#: ccdfunc.c:533 +#: ccdfunc.c:486 #, c-format msgid "Can't set position %g: out of limits [%g, %g]" msgstr "" -#: ccdfunc.c:537 +#: ccdfunc.c:490 msgid "Can't home focuser" msgstr "" -#: ccdfunc.c:539 +#: ccdfunc.c:492 #, c-format msgid "Can't set position %g" msgstr "" -#: ccdfunc.c:547 -msgid "Wheel device not pointed" +#: ccdfunc.c:500 +msgid "cc_Wheel device not pointed" msgstr "" -#: ccdfunc.c:554 +#: ccdfunc.c:507 msgid "No wheels found" msgstr "" -#: ccdfunc.c:585 +#: ccdfunc.c:538 #, c-format msgid "Found %d wheels, you point number %d" msgstr "" -#: ccdfunc.c:589 +#: ccdfunc.c:542 msgid "Can't set active wheel number" msgstr "" -#: ccdfunc.c:605 +#: ccdfunc.c:558 msgid "Can't get max wheel position" msgstr "" -#: ccdfunc.c:612 +#: ccdfunc.c:565 #, c-format -msgid "Wheel position should be from 0 to %d" +msgid "cc_Wheel position should be from 0 to %d" msgstr "" -#: ccdfunc.c:616 +#: ccdfunc.c:569 #, c-format msgid "Can't set wheel position %d" msgstr "" -#: ccdfunc.c:633 +#: ccdfunc.c:586 #, c-format msgid "%.1f seconds till exposition ends" msgstr "" -#: ccdfunc.c:648 +#: ccdfunc.c:601 msgid "Camera device not pointed" msgstr "" -#: ccdfunc.c:655 ccdfunc.c:656 +#: ccdfunc.c:608 ccdfunc.c:609 msgid "No cameras found" msgstr "" -#: ccdfunc.c:686 +#: ccdfunc.c:639 #, c-format msgid "Found %d cameras, you point number %d" msgstr "" -#: ccdfunc.c:690 +#: ccdfunc.c:643 msgid "Can't set active camera number" msgstr "" -#: ccdfunc.c:696 +#: ccdfunc.c:649 msgid "Can't set fan speed" msgstr "" -#: ccdfunc.c:697 +#: ccdfunc.c:650 #, c-format msgid "Set fan speed to %d" msgstr "" -#: ccdfunc.c:702 +#: ccdfunc.c:655 #, c-format msgid "Camera model: %s" msgstr "" -#: ccdfunc.c:703 +#: ccdfunc.c:656 #, c-format msgid "Pixel size: %g x %g" msgstr "" -#: ccdfunc.c:709 +#: ccdfunc.c:662 #, c-format msgid "Full array: %s" msgstr "" -#: ccdfunc.c:712 +#: ccdfunc.c:665 #, c-format msgid "Field of view: %s" msgstr "" -#: ccdfunc.c:715 +#: ccdfunc.c:668 #, c-format msgid "Current format: %s" msgstr "" -#: ccdfunc.c:718 +#: ccdfunc.c:671 #, c-format msgid "Can't set T to %g degC" msgstr "" -#: ccdfunc.c:726 +#: ccdfunc.c:679 #, c-format msgid "Shutter command: %s\n" msgstr "" -#: ccdfunc.c:728 +#: ccdfunc.c:681 #, c-format msgid "Can't run shutter command %s (unsupported?)" msgstr "" #. "п÷п╬п©я▀я┌п╨п╟ я│п╨п╬п╫я└п╦пЁя┐я─п╦я─п╬п╡п╟я┌я▄ п©п╬я─я┌ I/O п╨п╟п╨ %d\n" -#: ccdfunc.c:732 +#: ccdfunc.c:685 #, c-format msgid "Try to configure I/O port as %d" msgstr "" -#: ccdfunc.c:734 +#: ccdfunc.c:687 msgid "Can't configure (unsupported?)" msgstr "" -#: ccdfunc.c:741 +#: ccdfunc.c:694 msgid "Can't get IOport state (unsupported?)" msgstr "" #. "п÷п╬п©я▀я┌п╨п╟ п╥п╟п©п╦я│п╦ %d п╡ п©п╬я─я┌ I/O\n" -#: ccdfunc.c:745 +#: ccdfunc.c:698 #, c-format msgid "Try to write %d to I/O port" msgstr "" -#: ccdfunc.c:747 +#: ccdfunc.c:700 msgid "Can't set IOport" msgstr "" -#: ccdfunc.c:754 +#: ccdfunc.c:707 #, c-format msgid "Set gain to %g" msgstr "" -#: ccdfunc.c:755 +#: ccdfunc.c:708 #, c-format msgid "Can't set gain to %g" msgstr "" -#: ccdfunc.c:760 +#: ccdfunc.c:713 #, c-format msgid "Set brightness to %g" msgstr "" -#: ccdfunc.c:761 +#: ccdfunc.c:714 #, c-format msgid "Can't set brightness to %g" msgstr "" -#: ccdfunc.c:767 server.c:265 +#: ccdfunc.c:720 server.c:264 #, c-format msgid "Can't set binning %dx%d" msgstr "" -#: ccdfunc.c:779 server.c:266 +#: ccdfunc.c:732 server.c:265 msgid "Can't set given geometry" msgstr "" -#: ccdfunc.c:783 +#: ccdfunc.c:736 #, c-format msgid "Can't set %d flushes" msgstr "" -#: ccdfunc.c:787 +#: ccdfunc.c:740 #, c-format msgid "Can't set exposure time to %f seconds" msgstr "" -#: ccdfunc.c:790 +#: ccdfunc.c:743 msgid "Can't change frame type" msgstr "" -#: ccdfunc.c:793 +#: ccdfunc.c:746 msgid "Can't set bit depth" msgstr "" -#: ccdfunc.c:795 +#: ccdfunc.c:748 msgid "Can't set readout speed" msgstr "" -#: ccdfunc.c:796 +#: ccdfunc.c:749 #, c-format msgid "Readout mode: %s" msgstr "" -#: ccdfunc.c:797 +#: ccdfunc.c:750 msgid "Only show statistics" msgstr "" #. GET binning should be AFTER setgeometry! -#: ccdfunc.c:799 +#: ccdfunc.c:752 msgid "Can't get current binning" msgstr "" #. п≈п╟я┘п╡п╟я┌ п╨п╟п╢я─п╟ %d\n -#: ccdfunc.c:824 +#: ccdfunc.c:777 #, c-format msgid "Capture frame %d" msgstr "" -#: ccdfunc.c:826 ccdfunc.c:912 server.c:149 +#: ccdfunc.c:779 ccdfunc.c:853 server.c:148 msgid "Can't start exposition" msgstr "" -#: ccdfunc.c:831 +#: ccdfunc.c:784 msgid "Can't capture image" msgstr "" -#: ccdfunc.c:834 +#: ccdfunc.c:787 msgid "Read grabbed image" msgstr "" -#: ccdfunc.c:838 ccdfunc.c:925 +#: ccdfunc.c:791 ccdfunc.c:866 msgid "Can't grab image" msgstr "" #. %d я│п╣п╨я┐п╫п╢ п╢п╬ п╬п╨п╬п╫я┤п╟п╫п╦я▐ п©п╟я┐п╥я▀\n -#: ccdfunc.c:850 client.c:297 +#: ccdfunc.c:803 client.c:270 #, c-format msgid "%d seconds till pause ends\n" msgstr "" -#: ccdfunc.c:923 +#: ccdfunc.c:864 msgid "Some error when capture" msgstr "" -#: server.c:189 +#: server.c:188 msgid "No camera device" msgstr "" -#: client.c:282 +#: client.c:255 msgid "Can't make exposition" msgstr "" -#: client.c:313 +#: client.c:286 msgid "Server timeout" msgstr "" diff --git a/locale/ru/ru.po b/locale/ru/ru.po index 1d552e6..b01c785 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: 2023-12-25 15:48+0300\n" + "POT-Creation-Date: 2024-01-24 11:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,13 +16,13 @@ msgstr "Project-Id-Version: PACKAGE VERSION\n" "Content-Type: text/plain; charset=koi8-r\n" "Content-Transfer-Encoding: 8bit\n" -#: ccdfunc.c:633 +#: ccdfunc.c:586 #, c-format msgid "%.1f seconds till exposition ends" msgstr "%.1f секунд до окончания экспозиции" #. %d я│п╣п╨я┐п╫п╢ п╢п╬ п╬п╨п╬п╫я┤п╟п╫п╦я▐ п©п╟я┐п╥я▀\n -#: ccdfunc.c:850 client.c:297 +#: ccdfunc.c:803 client.c:270 #, c-format msgid "%d seconds till pause ends\n" msgstr "%d секунд до окончания паузы\n" @@ -39,77 +39,57 @@ msgstr " msgid "CMOS gain level" msgstr "уровень Gain CMOS" -#: ccdfunc.c:648 +#: ccdfunc.c:601 msgid "Camera device not pointed" msgstr "Устройство свеоприемника не подключено" -#: ccdfunc.c:185 +#: ccdfunc.c:138 msgid "Camera device unknown" msgstr "Устройство свеоприемника не опознано" -#: ccdfunc.c:702 +#: ccdfunc.c:655 #, c-format msgid "Camera model: %s" msgstr "Модель светоприемника: %s" -#: ccdfunc.c:831 +#: ccdfunc.c:784 msgid "Can't capture image" msgstr "Не могу захватить изображение" -#: ccdfunc.c:790 +#: ccdfunc.c:743 msgid "Can't change frame type" msgstr "Не могу изменить тип кадра" -#: ccdfunc.c:734 +#: ccdfunc.c:687 msgid "Can't configure (unsupported?)" msgstr "Не могу сконфигурировать (опция не поддерживается?)" -#: ccdfunc.c:88 -#, c-format -msgid "Can't find camera in plugin %s: %s" -msgstr "Не могу найти плагин камеры %s: %s" - -#: ccdfunc.c:77 -#, c-format -msgid "Can't find focuser in plugin %s: %s" -msgstr "Не могу найти плагин фокусера %s: %s" - -#: ccdfunc.c:65 -#, c-format -msgid "Can't find plugin %s: %s" -msgstr "Не могу найти плагин %s: %s" - -#: ccdfunc.c:99 -#, c-format -msgid "Can't find wheel in plugin %s: %s" -msgstr "Не могу найти плагин турели %s: %s" - -#: ccdfunc.c:741 +#: ccdfunc.c:694 msgid "Can't get IOport state (unsupported?)" msgstr "Не могу получить состояние порта I/O (не поддерживается?)" #. GET binning should be AFTER setgeometry! -#: ccdfunc.c:799 +#: ccdfunc.c:752 msgid "Can't get current binning" msgstr "Не могу получить текущее значение биннинга" -#: ccdfunc.c:519 +#: ccdfunc.c:472 msgid "Can't get current focuser position" msgstr "Не могу определить текущую позицию фокусера" -#: ccdfunc.c:512 +#: ccdfunc.c:465 msgid "Can't get focuser limit positions" msgstr "Не могу определить предельную позицию фокусера" -#: ccdfunc.c:605 +#: ccdfunc.c:558 msgid "Can't get max wheel position" msgstr "Не могу определить предельную позицию колеса" -#: ccdfunc.c:838 ccdfunc.c:925 +#: ccdfunc.c:791 ccdfunc.c:866 msgid "Can't grab image" msgstr "Не могу захватить изображение" -#: ccdfunc.c:537 +#: ccdfunc.c:490 msgid "Can't home focuser" msgstr "Не могу установить фокусер в нуль" @@ -117,7 +97,7 @@ msgstr " msgid "Can't init mutex!" msgstr "Не могу инициализировать мьютекс!" -#: client.c:282 +#: client.c:255 msgid "Can't make exposition" msgstr "Не могу выполнить экспозицию" @@ -125,105 +105,105 @@ msgstr " msgid "Can't open OpenGL window, image preview will be inaccessible" msgstr "Не могу открыть окно OpenGL, отображение будет недоступно" -#: ccdfunc.c:728 +#: ccdfunc.c:681 #, c-format msgid "Can't run shutter command %s (unsupported?)" msgstr "Не могу выполнить команду затвора %s (не поддерживается?)" #. п²п╣ п╪п╬пЁя┐ я│п╬я┘я─п╟п╫п╦я┌я▄ я└п╟п╧п╩ -#: ccdfunc.c:209 +#: ccdfunc.c:162 #, c-format msgid "Can't save file with prefix %s" msgstr "Не могу сохранить файл с префиксом %s" -#: ccdfunc.c:783 +#: ccdfunc.c:736 #, c-format msgid "Can't set %d flushes" msgstr "Не могу установить %d сбросов" -#: ccdfunc.c:747 +#: ccdfunc.c:700 msgid "Can't set IOport" msgstr "Не могу поменять значения порта I/O" -#: ccdfunc.c:718 +#: ccdfunc.c:671 #, c-format msgid "Can't set T to %g degC" msgstr "Не могу установить температуру в %g градЦ" -#: ccdfunc.c:690 +#: ccdfunc.c:643 msgid "Can't set active camera number" msgstr "Не могу установить номер активной камеры" -#: ccdfunc.c:498 +#: ccdfunc.c:451 msgid "Can't set active focuser number" msgstr "Не могу установить номер активного фокусера" -#: ccdfunc.c:589 +#: ccdfunc.c:542 msgid "Can't set active wheel number" msgstr "Не могу установить номер активного колеса" -#: ccdfunc.c:767 server.c:265 +#: ccdfunc.c:720 server.c:264 #, c-format msgid "Can't set binning %dx%d" msgstr "Не могу установить биннинг %dx%d" -#: ccdfunc.c:793 +#: ccdfunc.c:746 msgid "Can't set bit depth" msgstr "Не могу установить разрядность АЦП" -#: ccdfunc.c:761 +#: ccdfunc.c:714 #, c-format msgid "Can't set brightness to %g" msgstr "Не могу установить яркость в %g" -#: ccdfunc.c:787 +#: ccdfunc.c:740 #, c-format msgid "Can't set exposure time to %f seconds" msgstr "Не могу установить экспозицию в %f секунд" -#: ccdfunc.c:696 +#: ccdfunc.c:649 msgid "Can't set fan speed" msgstr "Не могу установить скорость вентиляторов" -#: ccdfunc.c:755 +#: ccdfunc.c:708 #, c-format msgid "Can't set gain to %g" msgstr "Не могу установить Gain в %g" -#: ccdfunc.c:779 server.c:266 +#: ccdfunc.c:732 server.c:265 msgid "Can't set given geometry" msgstr "Не могу установить геометрию" -#: ccdfunc.c:539 +#: ccdfunc.c:492 #, c-format msgid "Can't set position %g" msgstr "Не могу изменить позицию на %g" -#: ccdfunc.c:533 +#: ccdfunc.c:486 #, c-format msgid "Can't set position %g: out of limits [%g, %g]" msgstr "Не могу установить позицию %g: вне пределов [%g, %g]" -#: ccdfunc.c:795 +#: ccdfunc.c:748 msgid "Can't set readout speed" msgstr "Не могу установить скорость считывания" -#: ccdfunc.c:616 +#: ccdfunc.c:569 #, c-format msgid "Can't set wheel position %d" msgstr "Не могу установить положение колеса %d" -#: ccdfunc.c:826 ccdfunc.c:912 server.c:149 +#: ccdfunc.c:779 ccdfunc.c:853 server.c:148 msgid "Can't start exposition" msgstr "Не могу начать экспозицию" #. п≈п╟я┘п╡п╟я┌ п╨п╟п╢я─п╟ %d\n -#: ccdfunc.c:824 +#: ccdfunc.c:777 #, c-format msgid "Capture frame %d" msgstr "Захват кадра %d" -#: ccdfunc.c:715 +#: ccdfunc.c:668 #, c-format msgid "Current format: %s" msgstr "" @@ -237,40 +217,40 @@ msgstr " msgid "Equalization of histogram: %s" msgstr "Эквализация гистограммы: %s" -#: ccdfunc.c:371 +#: ccdfunc.c:324 msgid "Error saving file" msgstr "Ошибка сохранения файла" -#: ccdfunc.c:712 +#: ccdfunc.c:665 #, c-format msgid "Field of view: %s" msgstr "Поле зрения: %s" -#: ccdfunc.c:362 +#: ccdfunc.c:315 #, c-format msgid "File saved as '%s'" msgstr "Файл сохранен как '%s'" -#: ccdfunc.c:456 +#: ccdfunc.c:409 msgid "Focuser device not pointed" msgstr "Устройство фокусера не указано" -#: ccdfunc.c:686 +#: ccdfunc.c:639 #, c-format msgid "Found %d cameras, you point number %d" msgstr "Обнаружено %d камер, вы указали %d" -#: ccdfunc.c:494 +#: ccdfunc.c:447 #, c-format msgid "Found %d focusers, you point number %d" msgstr "Обнаружено %d фокусеров, вы указали %d" -#: ccdfunc.c:585 +#: ccdfunc.c:538 #, c-format msgid "Found %d wheels, you point number %d" msgstr "Обнаружено %d колес, вы указали %d" -#: ccdfunc.c:709 +#: ccdfunc.c:662 #, c-format msgid "Full array: %s" msgstr "Полный формат: %s" @@ -285,7 +265,7 @@ msgstr " msgid "INET image socket port" msgstr "порт локального сетевого сокета" -#: ccdfunc.c:448 +#: ccdfunc.c:401 #, c-format msgid "Image stat:\n" msgstr "Статистика по изображению: \n" @@ -294,76 +274,76 @@ msgstr " msgid "N flushes before exposing (default: 1)" msgstr "N засвечиваний перед экспозицией (по умолчанию: 1)" -#: server.c:189 +#: server.c:188 msgid "No camera device" msgstr "Не указано устройство камеры" -#: ccdfunc.c:655 ccdfunc.c:656 +#: ccdfunc.c:608 ccdfunc.c:609 msgid "No cameras found" msgstr "Камер не обнаружено" -#: ccdfunc.c:463 +#: ccdfunc.c:416 msgid "No focusers found" msgstr "Фокусеров не обнаружено" -#: ccdfunc.c:554 +#: ccdfunc.c:507 msgid "No wheels found" msgstr "Турелей не обнаружено" -#: ccdfunc.c:797 +#: ccdfunc.c:750 msgid "Only show statistics" msgstr "Только отобразить статистику" -#: ccdfunc.c:703 +#: ccdfunc.c:656 #, c-format msgid "Pixel size: %g x %g" msgstr "Размер пикселя: %g x %g" -#: ccdfunc.c:834 +#: ccdfunc.c:787 msgid "Read grabbed image" msgstr "Считывание изображения" -#: ccdfunc.c:796 +#: ccdfunc.c:749 #, c-format msgid "Readout mode: %s" msgstr "Режим считывания: %s" -#: client.c:313 +#: client.c:286 msgid "Server timeout" msgstr "Таймаут сервера" -#: ccdfunc.c:760 +#: ccdfunc.c:713 #, c-format msgid "Set brightness to %g" msgstr "Установить яркость в %g" -#: ccdfunc.c:697 +#: ccdfunc.c:650 #, c-format msgid "Set fan speed to %d" msgstr "Не могу установить скорость вентиляторов в %d" -#: ccdfunc.c:754 +#: ccdfunc.c:707 #, c-format msgid "Set gain to %g" msgstr "Установить Gain в %g" -#: ccdfunc.c:726 +#: ccdfunc.c:679 #, c-format msgid "Shutter command: %s\n" msgstr "Команда затвора: %s\n" -#: ccdfunc.c:923 +#: ccdfunc.c:864 msgid "Some error when capture" msgstr "" #. "п÷п╬п©я▀я┌п╨п╟ я│п╨п╬п╫я└п╦пЁя┐я─п╦я─п╬п╡п╟я┌я▄ п©п╬я─я┌ I/O п╨п╟п╨ %d\n" -#: ccdfunc.c:732 +#: ccdfunc.c:685 #, c-format msgid "Try to configure I/O port as %d" msgstr "Попытка сконфигурировать порт I/O как %d" #. "п÷п╬п©я▀я┌п╨п╟ п╥п╟п©п╦я│п╦ %d п╡ п©п╬я─я┌ I/O\n" -#: ccdfunc.c:745 +#: ccdfunc.c:698 #, c-format msgid "Try to write %d to I/O port" msgstr "Попытка записи %d в порт I/O" @@ -373,15 +353,6 @@ msgstr " msgid "UNIX socket name (command socket)" msgstr "Имя UNIX-сокета" -#: ccdfunc.c:547 -msgid "Wheel device not pointed" -msgstr "Устройство турели не указано" - -#: ccdfunc.c:612 -#, c-format -msgid "Wheel position should be from 0 to %d" -msgstr "Позиция колеса должна быть от 0 до %d" - #: cmdlnopts.c:76 msgid "absolute (not divided by binning!) frame X0 coordinate (-1 - all " "with overscan)" @@ -416,6 +387,16 @@ msgstr " msgid "cancel current exposition" msgstr "отмена текущей экспозиции" +#: ccdfunc.c:500 +#, fuzzy +msgid "cc_Wheel device not pointed" +msgstr "Устройство турели не указано" + +#: ccdfunc.c:565 +#, fuzzy, c-format +msgid "cc_Wheel position should be from 0 to %d" +msgstr "Позиция колеса должна быть от 0 до %d" + #: cmdlnopts.c:82 msgid "close shutter" msgstr "закрыть затвор" @@ -447,7 +428,7 @@ msgid "focuser device plugin (e.g. devzwo.so)" msgstr "плагин фокусера (например, devzwo.so)" #: cmdlnopts.c:108 -msgid "force using image through socket transition even if can use SHM" +msgid "force using image through socket transition even if can use SHM)" msgstr "" #: cmdlnopts.c:85 @@ -585,7 +566,7 @@ msgid "set wheel position" msgstr "установить положение колеса" #: cmdlnopts.c:107 -msgid "shared memory (with image data) key (default: 7777777" +msgid "shared memory (with image data) key (default: 7777777)" msgstr "" #: cmdlnopts.c:50 @@ -612,6 +593,22 @@ msgstr " msgid "wheel device plugin (e.g. devdummy.so)" msgstr "плагин устройства турели (например, devdummy.so)" +#, c-format +#~ msgid "Can't find camera in plugin %s: %s" +#~ msgstr "Не могу найти плагин камеры %s: %s" + +#, c-format +#~ msgid "Can't find focuser in plugin %s: %s" +#~ msgstr "Не могу найти плагин фокусера %s: %s" + +#, c-format +#~ msgid "Can't find plugin %s: %s" +#~ msgstr "Не могу найти плагин %s: %s" + +#, c-format +#~ msgid "Can't find wheel in plugin %s: %s" +#~ msgstr "Не могу найти плагин турели %s: %s" + #~ msgid "Neither filename nor filename prefix pointed!" #~ msgstr "Ни имя файла, ни префикс не указаны!" diff --git a/locale/ru/ru.po.bkp b/locale/ru/ru.po.bkp new file mode 100644 index 0000000..8b70e75 --- /dev/null +++ b/locale/ru/ru.po.bkp @@ -0,0 +1,586 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "Project-Id-Version: PACKAGE VERSION\n" + "Report-Msgid-Bugs-To: \n" + "POT-Creation-Date: 2022-04-18 16:50+0300\n" + "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" + "Last-Translator: FULL NAME \n" + "Language-Team: LANGUAGE \n" + "Language: \n" + "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=koi8-r\n" + "Content-Transfer-Encoding: 8bit\n" + +#: ccdfunc.c:570 +#, c-format +msgid "%.1f seconds till exposition ends" +msgstr "%.1f секунд до окончания экспозиции" + +#. %d секунд до окончания паузы\n +#: ccdfunc.c:805 client.c:260 +#, c-format +msgid "%d seconds till pause ends\n" +msgstr "%d секунд до окончания паузы\n" + +#: imageview.c:282 +msgid "Already initialized!" +msgstr "Уже инициализировано!" + +#: cmdlnopts.c:97 +msgid "CMOS brightness level" +msgstr "уровень яркости CMOS" + +#: cmdlnopts.c:96 +msgid "CMOS gain level" +msgstr "уровень Gain CMOS" + +#: ccdfunc.c:584 +msgid "Camera device not pointed" +msgstr "Устройство свеоприемника не подключено" + +#: ccdfunc.c:155 +msgid "Camera device unknown" +msgstr "Устройство свеоприемника не опознано" + +#: ccdfunc.c:643 +#, c-format +msgid "Camera model: %s" +msgstr "Модель светоприемника: %s" + +#: ccdfunc.c:762 ccdfunc.c:784 ccdfunc.c:825 +msgid "Can't capture image" +msgstr "Не могу захватить изображение" + +#: ccdfunc.c:726 +msgid "Can't change frame type" +msgstr "Не могу изменить тип кадра" + +#: ccdfunc.c:671 +msgid "Can't configure (unsupported?)" +msgstr "Не могу сконфигурировать (опция не поддерживается?)" + +#: ccdfunc.c:86 +#, c-format +msgid "Can't find camera in plugin %s: %s" +msgstr "Не могу найти плагин камеры %s: %s" + +#: ccdfunc.c:75 +#, c-format +msgid "Can't find focuser in plugin %s: %s" +msgstr "Не могу найти плагин фокусера %s: %s" + +#: ccdfunc.c:63 +#, c-format +msgid "Can't find plugin %s: %s" +msgstr "Не могу найти плагин %s: %s" + +#: ccdfunc.c:97 +#, c-format +msgid "Can't find wheel in plugin %s: %s" +msgstr "Не могу найти плагин турели %s: %s" + +#: ccdfunc.c:677 +msgid "Can't get IOport state (unsupported?)" +msgstr "Не могу получить состояние порта I/O (не поддерживается?)" + +#. GET binning should be AFTER setgeometry! +#: ccdfunc.c:735 +msgid "Can't get current binning" +msgstr "Не могу получить текущее значение биннинга" + +#: ccdfunc.c:455 +msgid "Can't get current focuser position" +msgstr "Не могу определить текущую позицию фокусера" + +#: ccdfunc.c:448 +msgid "Can't get focuser limit positions" +msgstr "Не могу определить предельную позицию фокусера" + +#: ccdfunc.c:542 +msgid "Can't get max wheel position" +msgstr "Не могу определить предельную позицию колеса" + +#: ccdfunc.c:768 ccdfunc.c:788 ccdfunc.c:829 +msgid "Can't grab image" +msgstr "Не могу захватить изображение" + +#: ccdfunc.c:473 +msgid "Can't home focuser" +msgstr "Не могу установить фокусер в нуль" + +#: imageview.c:264 +msgid "Can't init mutex!" +msgstr "Не могу инициализировать мьютекс!" + +#: client.c:247 +msgid "Can't make exposition" +msgstr "Не могу выполнить экспозицию" + +#: ccdfunc.c:748 +msgid "Can't open OpenGL window, image preview will be inaccessible" +msgstr "Не могу открыть окно OpenGL, отображение будет недоступно" + +#: ccdfunc.c:665 +#, c-format +msgid "Can't run shutter command %s (unsupported?)" +msgstr "Не могу выполнить команду затвора %s (не поддерживается?)" + +#. Не могу сохранить файл +#: ccdfunc.c:180 +#, c-format +msgid "Can't save file with prefix %s" +msgstr "Не могу сохранить файл с префиксом %s" + +#: ccdfunc.c:719 +#, c-format +msgid "Can't set %d flushes" +msgstr "Не могу установить %d сбросов" + +#: ccdfunc.c:683 +msgid "Can't set IOport" +msgstr "Не могу поменять значения порта I/O" + +#: ccdfunc.c:656 +#, c-format +msgid "Can't set T to %g degC" +msgstr "Не могу установить температуру в %g градЦ" + +#: ccdfunc.c:631 +msgid "Can't set active camera number" +msgstr "Не могу установить номер активной камеры" + +#: ccdfunc.c:434 +msgid "Can't set active focuser number" +msgstr "Не могу установить номер активного фокусера" + +#: ccdfunc.c:526 +msgid "Can't set active wheel number" +msgstr "Не могу установить номер активного колеса" + +#: ccdfunc.c:705 server.c:223 +#, c-format +msgid "Can't set binning %dx%d" +msgstr "Не могу установить биннинг %dx%d" + +#: ccdfunc.c:729 +msgid "Can't set bit depth" +msgstr "Не могу установить разрядность АЦП" + +#: ccdfunc.c:697 +#, c-format +msgid "Can't set brightness to %g" +msgstr "Не могу установить яркость в %g" + +#: ccdfunc.c:723 +#, c-format +msgid "Can't set exposure time to %f seconds" +msgstr "Не могу установить экспозицию в %f секунд" + +#: ccdfunc.c:637 +msgid "Can't set fan speed" +msgstr "Не могу установить скорость вентиляторов" + +#: ccdfunc.c:691 +#, c-format +msgid "Can't set gain to %g" +msgstr "Не могу установить Gain в %g" + +#: ccdfunc.c:715 server.c:224 +msgid "Can't set given geometry" +msgstr "Не могу установить геометрию" + +#: ccdfunc.c:475 +#, c-format +msgid "Can't set position %g" +msgstr "Не могу изменить позицию на %g" + +#: ccdfunc.c:469 +#, c-format +msgid "Can't set position %g: out of limits [%g, %g]" +msgstr "Не могу установить позицию %g: вне пределов [%g, %g]" + +#: ccdfunc.c:731 +msgid "Can't set readout speed" +msgstr "Не могу установить скорость считывания" + +#: ccdfunc.c:553 +#, c-format +msgid "Can't set wheel position %d" +msgstr "Не могу установить положение колеса %d" + +#: ccdfunc.c:758 server.c:121 +msgid "Can't start exposition" +msgstr "Не могу начать экспозицию" + +#. Захват кадра %d\n +#: ccdfunc.c:756 +#, c-format +msgid "Capture frame %d" +msgstr "Захват кадра %d" + +#: cmdlnopts.c:107 +msgid "Display image in OpenGL window" +msgstr "Отображение изображения в окне OpenGL" + +#: imageview.c:517 +#, c-format +msgid "Equalization of histogram: %s" +msgstr "Эквализация гистограммы: %s" + +#: ccdfunc.c:343 +msgid "Error saving file" +msgstr "Ошибка сохранения файла" + +#: ccdfunc.c:653 +#, c-format +msgid "Field of view: %s" +msgstr "Поле зрения: %s" + +#: ccdfunc.c:334 +#, c-format +msgid "File saved as '%s'" +msgstr "Файл сохранен как '%s'" + +#: ccdfunc.c:391 +msgid "Focuser device not pointed" +msgstr "Устройство фокусера не указано" + +#: ccdfunc.c:627 +#, c-format +msgid "Found %d cameras, you point number %d" +msgstr "Обнаружено %d камер, вы указали %d" + +#: ccdfunc.c:430 +#, c-format +msgid "Found %d focusers, you point number %d" +msgstr "Обнаружено %d фокусеров, вы указали %d" + +#: ccdfunc.c:522 +#, c-format +msgid "Found %d wheels, you point number %d" +msgstr "Обнаружено %d колес, вы указали %d" + +#: ccdfunc.c:650 +#, c-format +msgid "Full array: %s" +msgstr "Полный формат: %s" + +#: imageview.c:408 +#, c-format +msgid "Histogram conversion: %s" +msgstr "Преобразование гистограммы: %s" + +#: ccdfunc.c:383 +#, c-format +msgid "Image stat:\n" +msgstr "Статистика по изображению: \n" + +#: cmdlnopts.c:69 +msgid "N flushes before exposing (default: 1)" +msgstr "N засвечиваний перед экспозицией (по умолчанию: 1)" + +#: ccdfunc.c:161 +msgid "Neither filename nor filename prefix pointed!" +msgstr "Ни имя файла, ни префикс не указаны!" + +#: server.c:163 +msgid "No camera device" +msgstr "Не указано устройство камеры" + +#: ccdfunc.c:591 ccdfunc.c:592 +msgid "No cameras found" +msgstr "Камер не обнаружено" + +#: ccdfunc.c:398 +msgid "No focusers found" +msgstr "Фокусеров не обнаружено" + +#: ccdfunc.c:490 +msgid "No wheels found" +msgstr "Турелей не обнаружено" + +#: ccdfunc.c:733 +msgid "Only show statistics" +msgstr "Только отобразить статистику" + +#: cmdlnopts.c:103 +msgid "PID file (default: " +msgstr "PID-файл (по умолчанию: " + +#: ccdfunc.c:644 +#, c-format +msgid "Pixel size: %g x %g" +msgstr "Размер пикселя: %g x %g" + +#: ccdfunc.c:765 +msgid "Read grabbed image" +msgstr "Считывание изображения" + +#: ccdfunc.c:732 +#, c-format +msgid "Readout mode: %s" +msgstr "Режим считывания: %s" + +#: client.c:276 +msgid "Server timeout" +msgstr "Таймаут сервера" + +#: ccdfunc.c:696 +#, c-format +msgid "Set brightness to %g" +msgstr "Установить яркость в %g" + +#: ccdfunc.c:638 +#, c-format +msgid "Set fan speed to %d" +msgstr "Не могу установить скорость вентиляторов в %d" + +#: ccdfunc.c:690 +#, c-format +msgid "Set gain to %g" +msgstr "Установить Gain в %g" + +#: ccdfunc.c:663 +#, c-format +msgid "Shutter command: %s\n" +msgstr "Команда затвора: %s\n" + +#. "Попытка сконфигурировать порт I/O как %d\n" +#: ccdfunc.c:669 +#, c-format +msgid "Try to configure I/O port as %d" +msgstr "Попытка сконфигурировать порт I/O как %d" + +#. "Попытка записи %d в порт I/O\n" +#: ccdfunc.c:681 +#, c-format +msgid "Try to write %d to I/O port" +msgstr "Попытка записи %d в порт I/O" + +#: cmdlnopts.c:100 +msgid "UNIX socket name" +msgstr "Имя UNIX-сокета" + +#: ccdfunc.c:483 +msgid "Wheel device not pointed" +msgstr "Устройство турели не указано" + +#: ccdfunc.c:549 +#, c-format +msgid "Wheel position should be from 0 to %d" +msgstr "Позиция колеса должна быть от 0 до %d" + +#: cmdlnopts.c:76 +msgid "absolute (not divided by binning!) frame X0 coordinate (-1 - all " + "with overscan)" +msgstr "абсолютная (не деленная на биннинг!) координата X0 (-1 - включая оверскан)" + +#: cmdlnopts.c:78 +msgid "absolute frame X1 coordinate (-1 - all with overscan)" +msgstr "абсолютная координата X1 (-1 - включая оверскан)" + +#: cmdlnopts.c:77 +msgid "absolute frame Y0 coordinate (-1 - all with overscan)" +msgstr "абсолютная координата Y0 (-1 - включая оверскан)" + +#: cmdlnopts.c:79 +msgid "absolute frame Y1 coordinate (-1 - all with overscan)" +msgstr "абсолютная координата Y1 (-1 - включая оверскан)" + +#: cmdlnopts.c:65 +msgid "add records to header from given file[s]" +msgstr "добавить записи к шапке FITS-файла из заданных файлов" + +#: cmdlnopts.c:47 +msgid "camera device number (if many: 0, 1, 2 etc)" +msgstr "номер устройства камеры" + +#: cmdlnopts.c:43 +msgid "camera device plugin (e.g. devfli.so)" +msgstr "плагин камеры (например, devfli.so)" + +#: cmdlnopts.c:75 +msgid "cancel current exposition" +msgstr "отмена текущей экспозиции" + +#: cmdlnopts.c:82 +msgid "close shutter" +msgstr "закрыть затвор" + +#: cmdlnopts.c:42 +msgid "common device plugin (e.g devfli.so)" +msgstr "общий плагин для всех устройств (например, devfli.so)" + +#: cmdlnopts.c:89 +msgid "configure I/O port pins to given value (decimal number, pin1 is LSB, " + "1 == output, 0 == input)" +msgstr "сконфигурировать порт I/O в заданное состояние (десятичное число, pin1 - младший бит, 1 - выход, 0 - вход)" + +#: cmdlnopts.c:55 +msgid "fast readout mode" +msgstr "быстрый режим считывания" + +#: cmdlnopts.c:48 +msgid "filter wheel device number (if many: 0, 1, 2 etc)" +msgstr "номер устройства турели" + +#: cmdlnopts.c:49 +msgid "focuser device number (if many: 0, 1, 2 etc)" +msgstr "номер устройства фокусера" + +#: cmdlnopts.c:44 +msgid "focuser device plugin (e.g. devzwo.so)" +msgstr "плагин фокусера (например, devzwo.so)" + +#: cmdlnopts.c:85 +msgid "get value of I/O port pins" +msgstr "получить значение порта I/O" + +#: cmdlnopts.c:70 +msgid "horizontal binning to N pixels" +msgstr "горизонтальный биннинг в N пикселей" + +#: cmdlnopts.c:61 +msgid "instrument name" +msgstr "название прибора" + +#: cmdlnopts.c:46 +msgid "list connected devices" +msgstr "список подключенных устройств" + +#: cmdlnopts.c:101 +msgid "local INET socket port" +msgstr "порт локального сетевого сокета" + +#: cmdlnopts.c:99 +msgid "logging file name (if run as server)" +msgstr "имя файла логгирования (если запущен сервер)" + +#: cmdlnopts.c:73 +msgid "make pause for N seconds between expositions" +msgstr "пауза в N секунд между экспозициями" + +#: cmdlnopts.c:72 +msgid "make series of N frames" +msgstr "последовательность из N кадров" + +#: cmdlnopts.c:91 +msgid "move focuser to absolute position, mm" +msgstr "переместить фокусер в абсолютное положение, мм" + +#: cmdlnopts.c:92 +msgid "move focuser to relative position, mm (only for standalone)" +msgstr "переместить фокусер в относительное положение, мм (не для сервер/клиент)" + +#: cmdlnopts.c:86 +msgid "move stepper motor asynchronous" +msgstr "асинхронное движение шагового двигателя" + +#: cmdlnopts.c:53 +msgid "not open shutter, when exposing (\"dark frames\")" +msgstr "не открывать затвор при экспозиции (\"темновые\")" + +#: cmdlnopts.c:62 +msgid "object name" +msgstr "название объекта" + +#: cmdlnopts.c:60 +msgid "object type (neon, object, flat etc)" +msgstr "тип объекта (neon, object, flat и т.д.)" + +#: cmdlnopts.c:63 +msgid "observers' names" +msgstr "имена наблюдателей" + +#: cmdlnopts.c:64 +msgid "observing program name" +msgstr "название программы" + +#: imageview.c:517 +msgid "off" +msgstr "выкл" + +#: imageview.c:517 +msgid "on" +msgstr "вкл" + +#: cmdlnopts.c:81 +msgid "open shutter" +msgstr "открыть затвор" + +#: cmdlnopts.c:66 +msgid "output file name" +msgstr "имя файла" + +#: cmdlnopts.c:59 +msgid "program author" +msgstr "автор программы" + +#: cmdlnopts.c:104 +msgid "restart image server" +msgstr "перезапуск сервера" + +#: cmdlnopts.c:51 +msgid "rewrite output file if exists" +msgstr "перезапись выходного файла" + +#: cmdlnopts.c:102 +msgid "run as client" +msgstr "запустить клиент" + +#: cmdlnopts.c:84 +msgid "run exposition on HIGH @ pin5 I/O port" +msgstr "" + +#: cmdlnopts.c:83 +msgid "run exposition on LOW @ pin5 I/O port" +msgstr "" + +#: cmdlnopts.c:54 +msgid "run in 8-bit mode" +msgstr "8-битный режим" + +#: cmdlnopts.c:56 +msgid "set CCD temperature to given value (degr C)" +msgstr "установить температуру светоприемника (градЦ)" + +#: cmdlnopts.c:88 +msgid "set I/O port pins to given value (decimal number, pin1 is LSB)" +msgstr "установить порт I/O (десятичное число, pin1 - младший бит)" + +#: cmdlnopts.c:74 +msgid "set exposure time to given value (seconds!)" +msgstr "установить время экспозиции (секунды!)" + +#: cmdlnopts.c:57 +msgid "set fan speed (0 - off, 1 - low, 2 - high)" +msgstr "установить скорость вентилятора (0 - выкл, 1 - низкая, 2 - высокая)" + +#: cmdlnopts.c:94 +msgid "set wheel position" +msgstr "установить положение колеса" + +#: cmdlnopts.c:50 +msgid "show this help" +msgstr "отобразить эту справку" + +#: cmdlnopts.c:52 +msgid "verbose level (-V - messages, -VV - debug, -VVV - all shit)" +msgstr "уровень болтливости (-V - сообщения, -VV - отладка, -VVV - все)" + +#: cmdlnopts.c:71 +msgid "vertical binning to N pixels" +msgstr "вертикальный биннинг в N пикселей" + +#: cmdlnopts.c:67 +msgid "wait while exposition ends" +msgstr "ждать, пока не кончится экспозиция" + +#: cmdlnopts.c:45 +msgid "wheel device plugin (e.g. devdummy.so)" +msgstr "плагин устройства турели (например, devdummy.so)" diff --git a/main.c b/main.c index 5078f9c..f0943ed 100644 --- a/main.c +++ b/main.c @@ -71,7 +71,7 @@ void signals(int signo){ int main(int argc, char **argv){ initial_setup(); #if defined GETTEXT_PACKAGE && defined LOCALEDIR - printf("GETTEXT_PACKAGE=" GETTEXT_PACKAGE ", LOCALEDIR=" LOCALEDIR "\n"); + //printf("GETTEXT_PACKAGE=" GETTEXT_PACKAGE ", LOCALEDIR=" LOCALEDIR "\n"); bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); textdomain(GETTEXT_PACKAGE); #endif @@ -97,7 +97,7 @@ int main(int argc, char **argv){ return 1; } int port = atoi(GP->port); - if(port < PORTN_MIN || port > PORTN_MAX){ + if(port < CC_PORTN_MIN || port > CC_PORTN_MAX){ WARNX("Wrong port value: %d", port); return 1; } diff --git a/server.c b/server.c index 5fdbe55..d7986db 100644 --- a/server.c +++ b/server.c @@ -30,17 +30,16 @@ #include "server.h" #include "socket.h" -static int processData(int fd, handleritem *handlers, char *buf, int buflen); +static int parsestring(int fd, cc_handleritem *handlers, char *str); static atomic_int camdevno = 0, wheeldevno = 0, focdevno = 0; // current devices numbers -static _Atomic camera_state camstate = CAMERA_IDLE; +static _Atomic cc_camera_state camstate = CAMERA_IDLE; #define FLAG_STARTCAPTURE (1<<0) #define FLAG_CANCEL (1<<1) #define FLAG_RESTARTSERVER (1<<2) static atomic_int camflags = 0, camfanspd = 0, confio = 0, nflushes, infty = 0; static char *outfile = NULL, *lastfile = NULL; // current output file name/prefix; last name of saved file -static frameformat frmformatmax = {0}, curformat = {0}; // maximal format -static void *camdev = NULL, *focdev = NULL, *wheeldev = NULL; +static cc_frameformat frmformatmax = {0}, curformat = {0}; // maximal format static float focmaxpos = 0., focminpos = 0.; // focuser extremal positions static int wmaxpos = 0.; // wheel max pos @@ -56,50 +55,50 @@ typedef struct{ // cat | awk '{print "{ " $3 ", \"\" }," }' | sort strpair allcommands[] = { - { CMD_8BIT, "run in 8 bit mode instead of 16 bit" }, - { CMD_AUTHOR, "FITS 'AUTHOR' field" }, - { CMD_BRIGHTNESS, "camera brightness" }, - { CMD_CAMDEVNO, "camera device number" }, - { CMD_CAMLIST, "list all connected cameras" }, - { CMD_CAMFANSPD, "fan speed of camera" }, - { CMD_CONFIO, "camera IO configuration" }, - { CMD_DARK, "don't open shutter @ exposure" }, - { CMD_EXPSTATE, "get exposition state" }, - { CMD_EXPOSITION, "exposition time" }, - { CMD_FASTSPD, "fast readout speed" }, - { CMD_FILENAME, "save file with this name, like file.fits" }, - { CMD_FILENAMEPREFIX,"prefix of files, like ex (will be saved as exXXXX.fits)" }, - { CMD_FDEVNO, "focuser device number" }, - { CMD_FOCLIST, "list all connected focusers" }, - { CMD_FGOTO, "focuser position" }, - { CMD_FRAMEFORMAT, "camera frame format (X0,Y0,X1,Y1)" }, - { CMD_GAIN, "camera gain" }, - { CMD_HBIN, "horizontal binning" }, - { CMD_HEADERFILES, "add FITS records from these files (comma-separated list)" }, - { CMD_HELP, "show this help" }, - { CMD_IMHEIGHT, "last image height" }, - { CMD_IMWIDTH, "last image width" }, - { CMD_INFO, "connected devices state" }, - { CMD_INFTY, "an infinity loop taking images until there's connected clients" }, - { CMD_INSTRUMENT, "FITS 'INSTRUME' field" }, - { CMD_IO, "get/set camera IO" }, - { CMD_LASTFNAME, "path to last saved file"}, - { CMD_FRAMEMAX, "camera maximal available format" }, - { CMD_NFLUSHES, "camera number of preflushes" }, - { CMD_OBJECT, "FITS 'OBJECT' field" }, - { CMD_OBJTYPE, "FITS 'IMAGETYP' field" }, - { CMD_OBSERVER, "FITS 'OBSERVER' field" }, - { CMD_PROGRAM, "FITS 'PROG-ID' field" }, - { CMD_RESTART, "restart server" }, - { CMD_REWRITE, "rewrite file (if give `filename`, not `filenameprefix`" }, - { CMD_SHMEMKEY, "get shared memory key" }, - { CMD_SHUTTER, "camera shutter's operations" }, - { CMD_CAMTEMPER, "camera chip temperature" }, - { CMD_TREMAIN, "time (in seconds) of exposition remained" }, - { CMD_VBIN, "vertical binning" }, - { CMD_WDEVNO, "wheel device number" }, - { CMD_WLIST, "list all connected wheels" }, - { CMD_WPOS, "wheel position" }, + { CC_CMD_8BIT, "run in 8 bit mode instead of 16 bit" }, + { CC_CMD_AUTHOR, "FITS 'AUTHOR' field" }, + { CC_CMD_BRIGHTNESS, "camera brightness" }, + { CC_CMD_CAMDEVNO, "camera device number" }, + { CC_CMD_CAMLIST, "list all connected cameras" }, + { CC_CMD_CAMFANSPD, "fan speed of camera" }, + { CC_CMD_CONFIO, "camera IO configuration" }, + { CC_CMD_DARK, "don't open shutter @ exposure" }, + { CC_CMD_EXPSTATE, "get exposition state" }, + { CC_CMD_EXPOSITION, "exposition time" }, + { CC_CMD_FASTSPD, "fast readout speed" }, + { CC_CMD_FILENAME, "save file with this name, like file.fits" }, + { CC_CMD_FILENAMEPREFIX,"prefix of files, like ex (will be saved as exXXXX.fits)" }, + { CC_CMD_FDEVNO, "focuser device number" }, + { CC_CMD_FOCLIST, "list all connected focusers" }, + { CC_CMD_FGOTO, "focuser position" }, + { CC_CMD_FRAMEFORMAT, "camera frame format (X0,Y0,X1,Y1)" }, + { CC_CMD_GAIN, "camera gain" }, + { CC_CMD_HBIN, "horizontal binning" }, + { CC_CMD_HEADERFILES, "add FITS records from these files (comma-separated list)" }, + { CC_CMD_HELP, "show this help" }, + { CC_CMD_IMHEIGHT, "last image height" }, + { CC_CMD_IMWIDTH, "last image width" }, + { CC_CMD_INFO, "connected devices state" }, + { CC_CMD_INFTY, "an infinity loop taking images until there's connected clients" }, + { CC_CMD_INSTRUMENT, "FITS 'INSTRUME' field" }, + { CC_CMD_IO, "get/set camera IO" }, + { CC_CMD_LASTFNAME, "path to last saved file"}, + { CC_CMD_FRAMEMAX, "camera maximal available format" }, + { CC_CMD_NFLUSHES, "camera number of preflushes" }, + { CC_CMD_OBJECT, "FITS 'OBJECT' field" }, + { CC_CMD_OBJTYPE, "FITS 'IMAGETYP' field" }, + { CC_CMD_OBSERVER, "FITS 'OBSERVER' field" }, + { CC_CMD_PROGRAM, "FITS 'PROG-ID' field" }, + { CC_CMD_RESTART, "restart server" }, + { CC_CMD_REWRITE, "rewrite file (if give `filename`, not `filenameprefix`" }, + { CC_CMD_SHMEMKEY, "get shared memory key" }, + { CC_CMD_SHUTTER, "camera shutter's operations" }, + { CC_CMD_CAMTEMPER, "camera chip temperature" }, + { CC_CMD_TREMAIN, "time (in seconds) of exposition remained" }, + { CC_CMD_VBIN, "vertical binning" }, + { CC_CMD_WDEVNO, "wheel device number" }, + { CC_CMD_WLIST, "list all connected wheels" }, + { CC_CMD_WPOS, "wheel position" }, {NULL, NULL}, }; @@ -117,14 +116,14 @@ static void unlock(){ if(pthread_mutex_unlock(&locmutex)) ERR("Can't unlock mutex"); } -static IMG *ima = NULL; +static cc_IMG *ima = NULL; static void fixima(){ FNAME(); if(!camera) return; int raw_width = curformat.w / GP->hbin, raw_height = curformat.h / GP->vbin; // allocate memory for largest possible image - if(!ima) ima = getshm(GP->shmkey, camera->array.h * camera->array.w * 2); + if(!ima) ima = cc_getshm(GP->shmkey, camera->array.h * camera->array.w * 2); if(!ima) ERRX("Can't allocate memory for image"); shmkey = GP->shmkey; //if(raw_width == ima->w && raw_height == ima->h) return; // all OK @@ -133,7 +132,7 @@ static void fixima(){ ima->w = raw_width; if(!camera->getbitpix(&ima->bitpix)) ima->bitpix = 16; if(ima->bitpix < 8 || ima->bitpix > 16) ima->bitpix = 16; // use maximum in any strange cases - ima->bytelen = raw_height * raw_width * getNbytes(ima); + ima->bytelen = raw_height * raw_width * cc_getNbytes(ima); DBG("new image: %dx%d", raw_width, raw_height); } @@ -153,7 +152,7 @@ static inline void cameraidlestate(){ // idle - wait for capture commands } } static inline void cameracapturestate(){ // capturing - wait for exposition ends - capture_status cs; + cc_capture_status cs; if(camera->pollcapture(&cs, &tremain)){ if(cs != CAPTURE_PROCESS){ TIMESTAMP("Capture ready"); @@ -220,7 +219,7 @@ static void* processCAM(_U_ void *d){ unlock(); continue; } - camera_state curstate = camstate; + cc_camera_state curstate = camstate; switch(curstate){ case CAMERA_IDLE: cameraidlestate(); @@ -250,7 +249,7 @@ static int camdevini(int n){ } camdevno = n; LOGMSG("Set camera device number to %d", camdevno); - frameformat step; + cc_frameformat step; camera->getgeomlimits(&frmformatmax, &step); curformat = frmformatmax; DBG("\n\nGeometry format max (offx/offy) w/h: (%d/%d) %d/%d", curformat.xoff, curformat.yoff, @@ -293,7 +292,7 @@ static int wheeldevini(int n){ /******************************************************************************* *************************** Service handlers ********************************** ******************************************************************************/ -static hresult restarthandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult restarthandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ camflags |= FLAG_RESTARTSERVER; return RESULT_OK; } @@ -302,26 +301,26 @@ static hresult restarthandler(_U_ int fd, _U_ const char *key, _U_ const char *v *************************** CCD/CMOS handlers ********************************* ******************************************************************************/ // image size -static hresult imsizehandler(int fd, const char *key, _U_ const char *val){ +static cc_hresult imsizehandler(int fd, const char *key, _U_ const char *val){ char buf[64]; // send image width/height in pixels - if(0 == strcmp(key, CMD_IMHEIGHT)) snprintf(buf, 63, CMD_IMHEIGHT "=%d", ima->h); - else snprintf(buf, 63, CMD_IMWIDTH "=%d", ima->w); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + 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; } -static hresult camlisthandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult camlisthandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[BUFSIZ], modname[256]; for(int i = 0; i < camera->Ndevices; ++i){ if(!camera->setDevNo(i)) continue; camera->getModelName(modname, 255); - snprintf(buf, BUFSIZ-1, CMD_CAMLIST "='%s'", modname); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_CAMLIST "='%s'", modname); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(camdevno > -1) camera->setDevNo(camdevno); return RESULT_SILENCE; } -static hresult camsetNhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult camsetNhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int num = atoi(val); @@ -330,12 +329,12 @@ static hresult camsetNhandler(_U_ int fd, _U_ const char *key, _U_ const char *v } if(!camdevini(num)) return RESULT_FAIL; } - snprintf(buf, 63, CMD_CAMDEVNO "=%d", camdevno); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_CAMDEVNO "=%d", camdevno); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // exposition time setter/getter -static hresult exphandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult exphandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ DBG("setexp to %s", val); @@ -346,20 +345,20 @@ static hresult exphandler(int fd, _U_ const char *key, const char *val){ }else LOGWARN("Can't set exptime to %g", v); } DBG("expt: %g", GP->exptime); - snprintf(buf, 63, CMD_EXPOSITION "=%g", GP->exptime); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_EXPOSITION "=%g", GP->exptime); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // show last filename of saved FITS -static hresult lastfnamehandler(int fd, _U_ const char *key, _U_ const char *val){ +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, CMD_LASTFNAME "=%s", lastfile); - else snprintf(buf, PATH_MAX+31, CMD_LASTFNAME "="); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + 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; } // filename setter/getter -static hresult namehandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult namehandler(int fd, _U_ const char *key, const char *val){ char buf[PATH_MAX+32]; DBG("filename=%s", val); if(val && *val){ @@ -380,12 +379,12 @@ static hresult namehandler(int fd, _U_ const char *key, const char *val){ return RESULT_OK; } if(!GP->outfile) return RESULT_FAIL; - snprintf(buf, PATH_MAX+31, CMD_FILENAME "=%s", GP->outfile); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, PATH_MAX+31, CC_CMD_FILENAME "=%s", GP->outfile); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // filename prefix -static hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){ +static cc_hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *val){ char buf[PATH_MAX+32]; DBG("filename prefix=%s", val); if(val){ @@ -404,28 +403,28 @@ static hresult nameprefixhandler(_U_ int fd, _U_ const char *key, const char *va return RESULT_OK; } if(!GP->outfileprefix) return RESULT_FAIL; - snprintf(buf, PATH_MAX+31, CMD_FILENAMEPREFIX "=%s", GP->outfileprefix); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, PATH_MAX+31, CC_CMD_FILENAMEPREFIX "=%s", GP->outfileprefix); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // rewrite -static hresult rewritefilehandler(_U_ int fd, _U_ const char *key, const char *val){ +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; GP->rewrite = n; } - snprintf(buf, 63, CMD_REWRITE "=%d", GP->rewrite); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_REWRITE "=%d", GP->rewrite); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult binhandler(_U_ int fd, const char *key, const char *val){ +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(0 == strcmp(key, CMD_HBIN)) GP->hbin = b; + if(0 == strcmp(key, CC_CMD_HBIN)) GP->hbin = b; else GP->vbin = b; if(!camera->setbin(GP->hbin, GP->vbin)){ return RESULT_BADVAL; @@ -433,15 +432,15 @@ static hresult binhandler(_U_ int fd, const char *key, const char *val){ } int r = camera->getbin(&GP->hbin, &GP->vbin); if(r){ - if(0 == strcmp(key, CMD_HBIN)) snprintf(buf, 63, "%s=%d", key, GP->hbin); + 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(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } return RESULT_FAIL; } -static hresult temphandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult temphandler(int fd, _U_ const char *key, const char *val){ float f; char buf[64]; int r; @@ -456,41 +455,41 @@ static hresult temphandler(int fd, _U_ const char *key, const char *val){ } r = camera->getTcold(&f); if(r){ - snprintf(buf, 63, CMD_CAMTEMPER "=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_CAMTEMPER "=%.1f", f); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; r = camera->getTbody(&f); if(r){ snprintf(buf, 63, "tbody=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } r = camera->getThot(&f); if(r){ snprintf(buf, 63, "thot=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } return RESULT_SILENCE; }else return RESULT_FAIL; } -static hresult camfanhandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult camfanhandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int spd = atoi(val); if(spd < 0) return RESULT_BADVAL; if(spd > FAN_HIGH) spd = FAN_HIGH; - int r = camera->setfanspeed((fan_speed)spd); + int r = camera->setfanspeed((cc_fan_speed)spd); if(!r) return RESULT_FAIL; camfanspd = spd; } - snprintf(buf, 63, CMD_CAMFANSPD "=%d", camfanspd); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_CAMFANSPD "=%d", camfanspd); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } const char *shutterstr[] = {"open", "close", "expose @high", "expose @low"}; -static hresult shutterhandler(_U_ int fd, _U_ const char *key, const char *val){ +static cc_hresult shutterhandler(_U_ int fd, _U_ const char *key, const char *val){ if(val){ int x = atoi(val); if(x < 0 || x >= SHUTTER_AMOUNT) return RESULT_BADVAL; - int r = camera->shuttercmd((shutter_op)x); + int r = camera->shuttercmd((cc_shutter_op)x); if(r){ LOGMSG("Shutter command '%s'", shutterstr[x]); }else{ @@ -500,7 +499,7 @@ static hresult shutterhandler(_U_ int fd, _U_ const char *key, const char *val){ } return RESULT_OK; } -static hresult confiohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult confiohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int io = atoi(val); @@ -508,11 +507,11 @@ static hresult confiohandler(_U_ int fd, _U_ const char *key, _U_ const char *va if(!r) return RESULT_FAIL; confio = io; } - snprintf(buf, 63, CMD_CONFIO "=%d", confio); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_CONFIO "=%d", confio); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult iohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult iohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; int io; if(val){ @@ -522,11 +521,11 @@ static hresult iohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ } int r = camera->getio(&io); if(!r) return RESULT_FAIL; - snprintf(buf, 63, CMD_IO "=%d", io); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_IO "=%d", io); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult gainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult gainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; float f; if(val){ @@ -536,11 +535,11 @@ static hresult gainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val) } int r = camera->getgain(&f); if(!r) return RESULT_FAIL; - snprintf(buf, 63, CMD_GAIN "=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_GAIN "=%.1f", f); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult brightnesshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult brightnesshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; float b; if(val){ @@ -550,18 +549,18 @@ static hresult brightnesshandler(_U_ int fd, _U_ const char *key, _U_ const char } int r = camera->getbrightness(&b); if(!r) return RESULT_FAIL; - snprintf(buf, 63, CMD_BRIGHTNESS "=%.1f", b); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_BRIGHTNESS "=%.1f", b); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // set format: `format=X0,X1,Y0,Y1` // get geomlimits: `maxformat=X0,X1,Y0,Y1` -static hresult formathandler(int fd, const char *key, const char *val){ +static cc_hresult formathandler(int fd, const char *key, const char *val){ char buf[64]; - frameformat fmt; + cc_frameformat fmt; DBG("key=%s, val=%s", key, val); if(val){ - if(0 == strcmp(key, CMD_FRAMEMAX)){ + if(0 == strcmp(key, CC_CMD_FRAMEMAX)){ DBG("CANT SET MAXFORMAT"); return RESULT_BADKEY; // can't set maxformat } @@ -576,14 +575,14 @@ static hresult formathandler(int fd, const char *key, const char *val){ DBG("curformat: w=%d, h=%d", curformat.w, curformat.h); fixima(); } - if(0 == strcmp(key, CMD_FRAMEMAX)) snprintf(buf, 63, CMD_FRAMEMAX "=%d,%d,%d,%d", + if(0 == strcmp(key, CC_CMD_FRAMEMAX)) snprintf(buf, 63, CC_CMD_FRAMEMAX "=%d,%d,%d,%d", frmformatmax.xoff, frmformatmax.yoff, frmformatmax.xoff+frmformatmax.w, frmformatmax.yoff+frmformatmax.h); - else snprintf(buf, 63, CMD_FRAMEFORMAT "=%d,%d,%d,%d", + 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(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult nflusheshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult nflusheshandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int n = atoi(val); @@ -593,11 +592,11 @@ static hresult nflusheshandler(_U_ int fd, _U_ const char *key, _U_ const char * } nflushes = n; } - snprintf(buf, 63, CMD_NFLUSHES "=%d", nflushes); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_NFLUSHES "=%d", nflushes); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult expstatehandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult expstatehandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(val){ int n = atoi(val); @@ -613,19 +612,19 @@ static hresult expstatehandler(_U_ int fd, _U_ const char *key, _U_ const char * } else return RESULT_BADVAL; } - snprintf(buf, 63, CMD_EXPSTATE "=%d", camstate); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_EXPSTATE "=%d", camstate); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; snprintf(buf, 63, "camflags=%d", camflags); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult tremainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult tremainhandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; - snprintf(buf, 63, CMD_TREMAIN "=%g", tremain); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_TREMAIN "=%g", tremain); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult _8bithandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult _8bithandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int s = atoi(val); @@ -634,11 +633,11 @@ static hresult _8bithandler(int fd, _U_ const char *key, const char *val){ fixima(); GP->_8bit = s; } - snprintf(buf, 63, CMD_8BIT "=%d", GP->_8bit); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_8BIT "=%d", GP->_8bit); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult fastspdhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult fastspdhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int b = atoi(val); @@ -646,11 +645,11 @@ static hresult fastspdhandler(int fd, _U_ const char *key, const char *val){ GP->fast = b; if(!camera->setfastspeed(b)) return RESULT_FAIL; } - snprintf(buf, 63, CMD_FASTSPD "=%d", GP->fast); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_FASTSPD "=%d", GP->fast); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult darkhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult darkhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int d = atoi(val); @@ -659,23 +658,23 @@ static hresult darkhandler(int fd, _U_ const char *key, const char *val){ d = !d; if(!camera->setframetype(d)) return RESULT_FAIL; } - snprintf(buf, 63, CMD_DARK "=%d", GP->dark); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_DARK "=%d", GP->dark); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult FITSparhandler(int fd, const char *key, const char *val){ +static cc_hresult FITSparhandler(int fd, const char *key, const char *val){ char buf[256], **fitskey = NULL; - if(0 == strcmp(key, CMD_AUTHOR)){ + if(0 == strcmp(key, CC_CMD_AUTHOR)){ fitskey = &GP->author; - }else if(0 == strcmp(key, CMD_INSTRUMENT)){ + }else if(0 == strcmp(key, CC_CMD_INSTRUMENT)){ fitskey = &GP->instrument; - }else if(0 == strcmp(key, CMD_OBSERVER)){ + }else if(0 == strcmp(key, CC_CMD_OBSERVER)){ fitskey = &GP->observers; - }else if(0 == strcmp(key, CMD_OBJECT)){ + }else if(0 == strcmp(key, CC_CMD_OBJECT)){ fitskey = &GP->objname; - }else if(0 == strcmp(key, CMD_PROGRAM)){ + }else if(0 == strcmp(key, CC_CMD_PROGRAM)){ fitskey = &GP->prog_id; - }else if(0 == strcmp(key, CMD_OBJTYPE)){ + }else if(0 == strcmp(key, CC_CMD_OBJTYPE)){ fitskey = &GP->objtype; }else return RESULT_BADKEY; if(val){ @@ -683,10 +682,10 @@ static hresult FITSparhandler(int fd, const char *key, const char *val){ *fitskey = strdup(val); } snprintf(buf, 255, "%s=%s", key, *fitskey); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val){ char buf[BUFSIZ], **sptr; static char *curhdr = NULL; static int firstrun = 1; @@ -753,32 +752,32 @@ static hresult FITSheaderhandler(int fd, _U_ const char *key, const char *val){ curhdr = strdup(buf); } } - snprintf(buf, BUFSIZ-1, CMD_HEADERFILES "=%s", curhdr); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_HEADERFILES "=%s", curhdr); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } /* -static hresult handler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult handler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; return RESULT_SILENCE; } */ /******************************************************************************* - ***************************** Wheel handlers ********************************** + ***************************** cc_Wheel handlers ********************************** ******************************************************************************/ -static hresult wlisthandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult wlisthandler(int fd, _U_ const char *key, _U_ const char *val){ if(wheel->Ndevices < 1) return 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, CMD_WLIST "='%s'", modname); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_WLIST "='%s'", modname); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(wheeldevno > -1) wheel->setDevNo(wheeldevno); return RESULT_SILENCE; } -static hresult wsetNhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult wsetNhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int num = atoi(val); @@ -787,12 +786,12 @@ static hresult wsetNhandler(int fd, _U_ const char *key, const char *val){ } if(!wheeldevini(num)) return RESULT_FAIL; } - snprintf(buf, 63, CMD_WDEVNO "=%d", wheeldevno); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_WDEVNO "=%d", wheeldevno); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; int pos; if(val){ @@ -804,8 +803,8 @@ static hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char *val } int r = wheel->getPos(&pos); if(!r) return RESULT_FAIL; - snprintf(buf, 63, CMD_WPOS "=%d", pos); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_WPOS "=%d", pos); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } @@ -813,19 +812,19 @@ static hresult wgotohandler(_U_ int fd, _U_ const char *key, _U_ const char *val **************************** Focuser handlers ********************************* ******************************************************************************/ -static hresult foclisthandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult foclisthandler(int fd, _U_ const char *key, _U_ const char *val){ if(focuser->Ndevices < 1) return 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, CMD_FOCLIST "='%s'", modname); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_FOCLIST "='%s'", modname); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(focdevno > -1) focuser->setDevNo(focdevno); return RESULT_SILENCE; } -static hresult fsetNhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult fsetNhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int num = atoi(val); @@ -834,11 +833,11 @@ static hresult fsetNhandler(int fd, _U_ const char *key, const char *val){ } if(!focdevini(num)) return RESULT_FAIL; } - snprintf(buf, 63, CMD_FDEVNO "=%d", focdevno); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_FDEVNO "=%d", focdevno); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } -static hresult fgotohandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult fgotohandler(int fd, _U_ const char *key, const char *val){ char buf[64]; float f; int r; @@ -854,8 +853,8 @@ static hresult fgotohandler(int fd, _U_ const char *key, const char *val){ } r = focuser->getPos(&f); if(!r) return RESULT_FAIL; - snprintf(buf, 63, CMD_FGOTO "=%g", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_FGOTO "=%g", f); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } @@ -864,93 +863,94 @@ static hresult fgotohandler(int fd, _U_ const char *key, const char *val){ ******************************************************************************/ // information about everything -static hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult infohandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[BUFSIZ], buf1[256]; float f; int i; if(camera){ if(camera->getModelName(buf1, 255)){ - snprintf(buf, BUFSIZ-1, CMD_CAMLIST "='%s'", buf1); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_CAMLIST "='%s'", buf1); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } #define RUN(f, arg) do{if(RESULT_DISCONNECTED == f(fd, arg, NULL)) return RESULT_DISCONNECTED;}while(0) - RUN(namehandler, CMD_FILENAME); - RUN(binhandler, CMD_HBIN); - RUN(binhandler, CMD_VBIN); - RUN(temphandler, CMD_CAMTEMPER); - RUN(exphandler, CMD_EXPOSITION); - RUN(lastfnamehandler, CMD_LASTFNAME); - RUN(expstatehandler, CMD_EXPSTATE); + RUN(namehandler, CC_CMD_FILENAME); + RUN(binhandler, CC_CMD_HBIN); + RUN(binhandler, CC_CMD_VBIN); + RUN(temphandler, CC_CMD_CAMTEMPER); + RUN(exphandler, CC_CMD_EXPOSITION); + RUN(lastfnamehandler, CC_CMD_LASTFNAME); + RUN(expstatehandler, CC_CMD_EXPSTATE); #undef RUN } - DBG("chk wheel"); if(wheel){ - DBG("Wname"); + DBG("chk wheel"); if(wheel->getModelName(buf1, 255)){ - snprintf(buf, BUFSIZ-1, CMD_WLIST "='%s'", buf1); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_WLIST "='%s'", buf1); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(wheel->getTbody(&f)){ snprintf(buf, BUFSIZ-1, "wtemp=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(wheel->getPos(&i)){ - snprintf(buf, BUFSIZ-1, CMD_WPOS "=%d", i); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_WPOS "=%d", i); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } snprintf(buf, BUFSIZ-1, "wmaxpos=%d", wmaxpos); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(focuser){ + DBG("Chk focuser"); if(focuser->getModelName(buf1, 255)){ - snprintf(buf, BUFSIZ-1, CMD_FOCLIST "='%s'", buf1); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_FOCLIST "='%s'", buf1); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } if(focuser->getTbody(&f)){ snprintf(buf, BUFSIZ-1, "foctemp=%.1f", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } snprintf(buf, BUFSIZ-1, "focminpos=%g", focminpos); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; snprintf(buf, BUFSIZ-1, "focmaxpos=%g", focmaxpos); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; if(focuser->getPos(&f)){ - snprintf(buf, BUFSIZ-1, CMD_FGOTO "=%g", f); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, BUFSIZ-1, CC_CMD_FGOTO "=%g", f); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; } } + DBG("EOF"); return RESULT_SILENCE; } // show help -static hresult helphandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult helphandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[256]; strpair *ptr = allcommands; while(ptr->key){ snprintf(buf, 255, "%s - %s", ptr->key, ptr->help); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; ++ptr; } return RESULT_SILENCE; } // shared memory key -static hresult shmemkeyhandler(int fd, _U_ const char *key, _U_ const char *val){ +static cc_hresult shmemkeyhandler(int fd, _U_ const char *key, _U_ const char *val){ char buf[64]; if(shmkey == IPC_PRIVATE) return RESULT_FAIL; - snprintf(buf, 63, CMD_SHMEMKEY "=%d", shmkey); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_SHMEMKEY "=%d", shmkey); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } // infinity loop -static hresult inftyhandler(int fd, _U_ const char *key, const char *val){ +static cc_hresult inftyhandler(int fd, _U_ const char *key, const char *val){ char buf[64]; if(val){ int i = atoi(val); infty = (i) ? 1 : 0; } - snprintf(buf, 63, CMD_INFTY "=%d", infty); - if(!sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; + snprintf(buf, 63, CC_CMD_INFTY "=%d", infty); + if(!cc_sendstrmessage(fd, buf)) return RESULT_DISCONNECTED; return RESULT_SILENCE; } @@ -963,73 +963,73 @@ static int CAMbusy(){ return FALSE; } // check funtions -static hresult chktrue(_U_ char *val){ // dummy check for `infohandler` (need to lock mutex anymore) +static cc_hresult chktrue(_U_ char *val){ // dummy check for `infohandler` (need to lock mutex anymore) return RESULT_OK; } -static hresult chkcam(char *val){ +static cc_hresult chkcam(char *val){ if(val && CAMbusy()) return RESULT_BUSY; if(camera) return RESULT_OK; return RESULT_FAIL; } -static hresult chkcc(_U_ char *val){ // just check that camera connected +static cc_hresult chkcc(_U_ char *val){ // just check that camera connected if(camera) return RESULT_OK; return RESULT_FAIL; } -static hresult chkwhl(char *val){ +static cc_hresult chkwhl(char *val){ if(val && CAMbusy()) return RESULT_BUSY; if(wheel) return RESULT_OK; return RESULT_FAIL; } -static hresult chkfoc(char *val){ +static cc_hresult chkfoc(char *val){ if(val && CAMbusy()) return RESULT_BUSY; if(focuser) return RESULT_OK; return RESULT_FAIL; } -static handleritem items[] = { - {chktrue,infohandler, CMD_INFO}, - {NULL, helphandler, CMD_HELP}, - {NULL, restarthandler, CMD_RESTART}, - {chkcc, camlisthandler, CMD_CAMLIST}, - {chkcc, camsetNhandler, CMD_CAMDEVNO}, - {chkcc, camfanhandler, CMD_CAMFANSPD}, - {chkcc, exphandler, CMD_EXPOSITION}, - {chkcc, namehandler, CMD_FILENAME}, - {chkcc, binhandler, CMD_HBIN}, - {chkcc, binhandler, CMD_VBIN}, - {chkcc, temphandler, CMD_CAMTEMPER}, - {chkcam, shutterhandler, CMD_SHUTTER}, - {chkcc, confiohandler, CMD_CONFIO}, - {chkcc, iohandler, CMD_IO}, - {chkcc, gainhandler, CMD_GAIN}, - {chkcc, brightnesshandler, CMD_BRIGHTNESS}, - {chkcc, formathandler, CMD_FRAMEFORMAT}, - {chkcc, formathandler, CMD_FRAMEMAX}, - {chkcc, nflusheshandler, CMD_NFLUSHES}, - {chkcam, expstatehandler, CMD_EXPSTATE}, - {chktrue,shmemkeyhandler, CMD_SHMEMKEY}, - {chktrue,imsizehandler, CMD_IMWIDTH}, - {chktrue,imsizehandler, CMD_IMHEIGHT}, - {chkcc, nameprefixhandler, CMD_FILENAMEPREFIX}, - {chkcc, rewritefilehandler, CMD_REWRITE}, - {chkcc, _8bithandler, CMD_8BIT}, - {chkcc, fastspdhandler, CMD_FASTSPD}, - {chkcc, darkhandler, CMD_DARK}, - {chkcc, inftyhandler, CMD_INFTY}, - {NULL, tremainhandler, CMD_TREMAIN}, - {NULL, FITSparhandler, CMD_AUTHOR}, - {NULL, FITSparhandler, CMD_INSTRUMENT}, - {NULL, FITSparhandler, CMD_OBSERVER}, - {NULL, FITSparhandler, CMD_OBJECT}, - {NULL, FITSparhandler, CMD_PROGRAM}, - {NULL, FITSparhandler, CMD_OBJTYPE}, - {NULL, FITSheaderhandler, CMD_HEADERFILES}, - {NULL, lastfnamehandler, CMD_LASTFNAME}, - {chkfoc, foclisthandler, CMD_FOCLIST}, - {chkfoc, fsetNhandler, CMD_FDEVNO}, - {chkfoc, fgotohandler, CMD_FGOTO}, - {chkwhl, wlisthandler, CMD_WLIST}, - {chkwhl, wsetNhandler, CMD_WDEVNO}, - {chkwhl, wgotohandler, CMD_WPOS}, +static cc_handleritem items[] = { + {chktrue,infohandler, CC_CMD_INFO}, + {NULL, helphandler, CC_CMD_HELP}, + {NULL, restarthandler, CC_CMD_RESTART}, + {chkcc, camlisthandler, CC_CMD_CAMLIST}, + {chkcc, camsetNhandler, CC_CMD_CAMDEVNO}, + {chkcc, camfanhandler, CC_CMD_CAMFANSPD}, + {chkcc, exphandler, CC_CMD_EXPOSITION}, + {chkcc, namehandler, CC_CMD_FILENAME}, + {chkcc, binhandler, CC_CMD_HBIN}, + {chkcc, binhandler, CC_CMD_VBIN}, + {chkcc, temphandler, CC_CMD_CAMTEMPER}, + {chkcam, shutterhandler, CC_CMD_SHUTTER}, + {chkcc, confiohandler, CC_CMD_CONFIO}, + {chkcc, iohandler, CC_CMD_IO}, + {chkcc, gainhandler, CC_CMD_GAIN}, + {chkcc, brightnesshandler, CC_CMD_BRIGHTNESS}, + {chkcc, formathandler, CC_CMD_FRAMEFORMAT}, + {chkcc, formathandler, CC_CMD_FRAMEMAX}, + {chkcc, nflusheshandler, CC_CMD_NFLUSHES}, + {chkcam, expstatehandler, CC_CMD_EXPSTATE}, + {chktrue,shmemkeyhandler, CC_CMD_SHMEMKEY}, + {chktrue,imsizehandler, CC_CMD_IMWIDTH}, + {chktrue,imsizehandler, CC_CMD_IMHEIGHT}, + {chkcc, nameprefixhandler, CC_CMD_FILENAMEPREFIX}, + {chkcc, rewritefilehandler, CC_CMD_REWRITE}, + {chkcc, _8bithandler, CC_CMD_8BIT}, + {chkcc, fastspdhandler, CC_CMD_FASTSPD}, + {chkcc, darkhandler, CC_CMD_DARK}, + {chkcc, inftyhandler, CC_CMD_INFTY}, + {NULL, tremainhandler, CC_CMD_TREMAIN}, + {NULL, FITSparhandler, CC_CMD_AUTHOR}, + {NULL, FITSparhandler, CC_CMD_INSTRUMENT}, + {NULL, FITSparhandler, CC_CMD_OBSERVER}, + {NULL, FITSparhandler, CC_CMD_OBJECT}, + {NULL, FITSparhandler, CC_CMD_PROGRAM}, + {NULL, FITSparhandler, CC_CMD_OBJTYPE}, + {NULL, FITSheaderhandler, CC_CMD_HEADERFILES}, + {NULL, lastfnamehandler, CC_CMD_LASTFNAME}, + {chkfoc, foclisthandler, CC_CMD_FOCLIST}, + {chkfoc, fsetNhandler, CC_CMD_FDEVNO}, + {chkfoc, fgotohandler, CC_CMD_FGOTO}, + {chkwhl, wlisthandler, CC_CMD_WLIST}, + {chkwhl, wsetNhandler, CC_CMD_WDEVNO}, + {chkwhl, wgotohandler, CC_CMD_WPOS}, {NULL, NULL, NULL}, }; @@ -1038,43 +1038,45 @@ static handleritem items[] = { // send image as raw data static void sendimage(int client){ if(ima->h < 1 || ima->w < 1) return; - senddata(client, ima, sizeof(IMG)); - senddata(client, ima->data, ima->bytelen); - /*void *mem = malloc(ima->bytelen); - memcpy(mem, ima->data, ima->bytelen); - senddata(client, mem, ima->bytelen); - FREE(mem);*/ + cc_senddata(client, ima, sizeof(cc_IMG)); + cc_senddata(client, ima->data, ima->bytelen); } 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 support"); - else if(listen(imsock, MAXCLIENTS) == -1){ + if(imsock < 0) WARNX("Server run without image transport socket"); + else if(listen(imsock, CC_MAXCLIENTS) == -1){ WARN("listen()"); LOGWARN("listen()"); return; } - if(listen(sock, MAXCLIENTS) == -1){ + if(listen(sock, CC_MAXCLIENTS) == -1){ WARN("listen()"); LOGWARN("listen()"); return; } // init everything - startFocuser(&focdev); + int ctr = 3; + if(startFocuser()) --ctr; focdevini(0); - startWheel(&wheeldev); + if(startWheel()) --ctr; wheeldevini(0); - startCCD(&camdev); + if(startCCD()) --ctr; camdevini(0); + if(ctr == 3) ERRX("No devices found"); // start camera thread pthread_t camthread; if(camera){ if(pthread_create(&camthread, NULL, processCAM, NULL)) ERR("pthread_create()"); } int nfd = 2; // only two listening sockets @start: command and image - struct pollfd poll_set[MAXCLIENTS+2]; - char buffers[MAXCLIENTS][CLBUFSZ]; // buffers for data reading + struct pollfd poll_set[CC_MAXCLIENTS+2]; + cc_charbuff *buffers[CC_MAXCLIENTS]; + for(int i = 0; i < CC_MAXCLIENTS; ++i){ + buffers[i] = cc_bufnew(CLBUFSZ); + } + char string[CLBUFSZ]; // string to read data from buffers bzero(poll_set, sizeof(poll_set)); // ZERO - listening server socket poll_set[0].fd = sock; @@ -1083,7 +1085,7 @@ void server(int sock, int imsock){ poll_set[1].events = POLLIN; while(1){ poll(poll_set, nfd, 1); // max timeout - 1ms - //if(imsock > -1 && canberead(imsock) > 0){ + //if(imsock > -1 && cc_canberead(imsock) > 0){ if(imsock > -1 && (poll_set[1].revents & POLLIN)){ //uint8_t buf[32]; //int l = read(imsock, buf, 32); @@ -1107,7 +1109,7 @@ void server(int sock, int imsock){ if(client > -1){ DBG("New connection"); LOGMSG("SERVER got connection, fd=%d", client); - if(nfd == MAXCLIENTS + 1){ + if(nfd == CC_MAXCLIENTS + 1){ LOGWARN("Max amount of connections, disconnect fd=%d", client); WARNX("Limit of connections reached"); close(client); @@ -1126,16 +1128,16 @@ void server(int sock, int imsock){ ++ima->imnumber; // increment counter } char buff[PATH_MAX+32]; - snprintf(buff, PATH_MAX, CMD_EXPSTATE "=%d", camstate); + 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"); - sendstrmessage(poll_set[i].fd, buff); + cc_sendstrmessage(poll_set[i].fd, buff); } if(camstate == CAMERA_FRAMERDY && (GP->outfile || GP->outfileprefix)){ // send to all last file name if file saved - snprintf(buff, PATH_MAX+31, CMD_LASTFNAME "=%s", lastfile); + snprintf(buff, PATH_MAX+31, CC_CMD_LASTFNAME "=%s", lastfile); for(int i = 2; i < nfd; ++i) - sendstrmessage(poll_set[i].fd, buff); + cc_sendstrmessage(poll_set[i].fd, buff); } camstate = CAMERA_IDLE; } @@ -1143,10 +1145,21 @@ void server(int sock, int imsock){ for(int fdidx = 2; fdidx < nfd; ++fdidx){ if((poll_set[fdidx].revents & POLLIN) == 0) continue; int fd = poll_set[fdidx].fd; - if(!processData(fd, items, buffers[fdidx-1], CLBUFSZ)){ // socket closed + cc_charbuff *curbuff = buffers[fdidx-1]; + int disconnected = 0; + if(cc_read2buf(fd, curbuff)){ + size_t got = cc_getline(curbuff, string, CLBUFSZ); + if(got >= CLBUFSZ){ + DBG("Client fd=%d gave buffer overflow", fd); + LOGMSG("SERVER client fd=%d buffer overflow", fd); + }else if(got){ + if(!parsestring(fd, items, string)) disconnected = 1; + } + }else disconnected = 1; + if(disconnected){ DBG("Client fd=%d disconnected", fd); LOGMSG("SERVER client fd=%d disconnected", fd); - buffers[fdidx-1][0] = 0; // clear rest of data in buffer + curbuff->buflen = 0; // clear rest of data in buffer close(fd); // move last FD to current position poll_set[fdidx] = poll_set[nfd - 1]; @@ -1156,13 +1169,16 @@ void server(int sock, int imsock){ // check `infty` if(camstate == CAMERA_IDLE && infty){ // start new exposition // mark to start new capture in infinity loop when at least one client connected - if(nfd > 2) camflags |= FLAG_STARTCAPTURE; - TIMESTAMP("start new capture due to `infty`"); - TIMEINIT(); + if(nfd > 2){ + camflags |= FLAG_STARTCAPTURE; + TIMESTAMP("start new capture due to `infty`"); + TIMEINIT(); + } } } - focclose(focdev); - closewheel(wheeldev); + // never reached + focclose(); + closewheel(); closecam(); } @@ -1199,9 +1215,9 @@ char *makeabspath(const char *path, int shouldbe){ // parse string of data (command or key=val) // the CONTENT of buffer `str` WILL BE BROKEN! // @return FALSE if client closed (nothing to read) -static int parsestring(int fd, handleritem *handlers, char *str){ +static int parsestring(int fd, cc_handleritem *handlers, char *str){ if(fd < 1 || !handlers || !handlers->key || !str || !*str) return FALSE; - char *val = get_keyval(str); + char *val = cc_get_keyval(str); if(val){ DBG("RECEIVE '%s=%s'", str, val); LOGDBG("RECEIVE '%s=%s'", str, val); @@ -1209,63 +1225,33 @@ static int parsestring(int fd, handleritem *handlers, char *str){ DBG("RECEIVE '%s'", str); LOGDBG("RECEIVE '%s'", str); } - for(handleritem *h = handlers; h->key; ++h){ - if(strcmp(str, h->key) == 0){ // found command - hresult r = RESULT_OK; - int l = FALSE; - if(h->chkfunction){ - double t0 = dtime(); - do{ l = lock(); } while(!l && dtime() - t0 < BUSY_TIMEOUT); - DBG("time: %g", dtime() - t0); - if(!l){ - WARN("Can't lock mutex"); //signals(1); - return 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(h->handler) r = h->handler(fd, str, val); - else r = RESULT_FAIL; + for(cc_handleritem *h = handlers; h->key; ++h){ + if(strcmp(str, h->key)) continue; + cc_hresult r = 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); + if(!l){ + WARN("Can't lock mutex"); //signals(1); + return RESULT_BUSY; // long blocking work } - if(l) unlock(); - if(r == RESULT_DISCONNECTED){ - DBG("handler return RESULT_DISCONNECTED"); - return FALSE; - } - return sendstrmessage(fd, hresult2str(r)); + 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(h->handler) r = h->handler(fd, str, val); + else r = RESULT_FAIL; } + if(l) unlock(); + if(r == RESULT_DISCONNECTED){ + DBG("handler return 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 sendstrmessage(fd, hresult2str(RESULT_BADKEY)); + return cc_sendstrmessage(fd, cc_hresult2str(RESULT_BADKEY)); } -/** - * @brief processData - read (if available) data from fd and run processing, sending to fd messages for each command - * @param fd - socket file descriptor - * @param handlers - NULL-terminated array of handlers - * @param buf (io) - zero-terminated buffer for storing rest of data (without newline), its content will be changed - * @param buflen - its length - * @return FALSE if client closed (nothing to read) - */ -static int processData(int fd, handleritem *handlers, char *buf, int buflen){ - int curlen = strlen(buf); - if(curlen == buflen-1) curlen = 0; // buffer overflow - clear old content - ssize_t rd = read(fd, buf + curlen, buflen-1 - curlen); - if(rd <= 0){ - //DBG("read %zd bytes from client", rd); - return FALSE; - } - //DBG("got %s[%zd] from %d", buf, rd, fd); - char *restofdata = buf, *eptr = buf + curlen + rd; - *eptr = 0; - do{ - char *nl = strchr(restofdata, '\n'); - if(!nl) break; - *nl++ = 0; - if(!parsestring(fd, handlers, restofdata)) return FALSE; // client disconnected - restofdata = nl; - //DBG("rest of data: %s", restofdata); - }while(1); - if(restofdata != buf) memmove(buf, restofdata, eptr - restofdata + 1); - return TRUE; -} diff --git a/server.h b/server.h index b762a38..0a68dc3 100644 --- a/server.h +++ b/server.h @@ -18,13 +18,6 @@ #pragma once -typedef enum{ - CAMERA_IDLE, // idle state, client send this to cancel capture - CAMERA_CAPTURE, // capturing frame, client send this to start capture - CAMERA_FRAMERDY, // frame ready to be saved - CAMERA_ERROR // can't do exposition -} camera_state; - // pause (seconds) between temperature logging #define TLOG_PAUSE 60. @@ -32,60 +25,3 @@ typedef enum{ void server(int fd, int imsock); char *makeabspath(const char *path, int shouldbe); -// common information about everything -#define CMD_INFO "info" -#define CMD_HELP "help" -// restart server -#define CMD_RESTART "restartTheServer" -// get image size in pixels -#define CMD_IMWIDTH "imwidth" -#define CMD_IMHEIGHT "imheight" -// get shared memory key -#define CMD_SHMEMKEY "shmemkey" - -// CCD/CMOS -#define CMD_CAMLIST "camlist" -#define CMD_CAMDEVNO "camdevno" -#define CMD_EXPOSITION "exptime" -#define CMD_LASTFNAME "lastfilename" -#define CMD_FILENAME "filename" -#define CMD_FILENAMEPREFIX "filenameprefix" -// rewrite=1 will rewrite files, =0 - not (only for `filename`) -#define CMD_REWRITE "rewrite" -#define CMD_HBIN "hbin" -#define CMD_VBIN "vbin" -#define CMD_CAMTEMPER "tcold" -#define CMD_CAMFANSPD "ccdfanspeed" -#define CMD_SHUTTER "shutter" -#define CMD_CONFIO "confio" -#define CMD_IO "io" -#define CMD_GAIN "gain" -#define CMD_BRIGHTNESS "brightness" -#define CMD_FRAMEFORMAT "format" -#define CMD_FRAMEMAX "maxformat" -#define CMD_NFLUSHES "nflushes" -// expstate=CAMERA_CAPTURE will start exposition, CAMERA_IDLE - cancel -#define CMD_EXPSTATE "expstate" -#define CMD_TREMAIN "tremain" -#define CMD_8BIT "8bit" -#define CMD_FASTSPD "fastspeed" -#define CMD_DARK "dark" -#define CMD_INFTY "infty" -// FITS file keywords -#define CMD_AUTHOR "author" -#define CMD_INSTRUMENT "instrument" -#define CMD_OBSERVER "observer" -#define CMD_OBJECT "object" -#define CMD_PROGRAM "program" -#define CMD_OBJTYPE "objtype" -#define CMD_HEADERFILES "headerfiles" - -// focuser -#define CMD_FOCLIST "foclist" -#define CMD_FDEVNO "focdevno" -#define CMD_FGOTO "focpos" - -// wheel -#define CMD_WLIST "wlist" -#define CMD_WDEVNO "wdevno" -#define CMD_WPOS "wpos" diff --git a/socket.h b/socket.h index 5d19c8c..184ed7f 100644 --- a/socket.h +++ b/socket.h @@ -23,61 +23,14 @@ #include #include -#include "basestructs.h" - -// max & min TCP socket port number -#define PORTN_MAX (65535) -#define PORTN_MIN (1024) - -#define BUFLEN (1024) -// Max amount of connections -#define MAXCLIENTS (30) - -// wait for mutex locking -#define BUSY_TIMEOUT (1.0) -// waiting for answer timeout -#define ANSWER_TIMEOUT (0.01) -// wait for exposition ends (between subsequent check calls) -#define WAIT_TIMEOUT (2.0) -// client will disconnect after this time from last server message -#define CLIENT_TIMEOUT (3.0) +#include "ccdcapture.h" #ifdef EBUG extern double __t0; #define TIMEINIT() do{__t0 = dtime();}while(0) -#define TIMESTAMP(...) do{DBG(__VA_ARGS__); fprintf(stderr, COLOR_GREEN "%g" COLOR_OLD "\n", dtime()-__t0);}while(0) +#define TIMESTAMP(...) do{DBG(__VA_ARGS__); green("%g\n", dtime()-__t0); fflush(stdout);}while(0) #else #define TIMEINIT() #define TIMESTAMP(...) #endif -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 -} hresult; - -const char *hresult2str(hresult r); - -// fd - socket fd to send private messages, key, val - key and its value -typedef hresult (*mesghandler)(int fd, const char *key, const char *val); - -typedef struct{ - hresult (*chkfunction)(char *val); // function to check device is ready - mesghandler handler; // handler function - const char *key; // keyword -} handleritem; - -int open_socket(int isserver, char *path, int isnet); -int start_socket(int server); -int senddata(int fd, void *data, size_t l); -int sendmessage(int fd, const char *msg, int l); -int sendstrmessage(int fd, const char *msg); -char *get_keyval(char *keyval); -IMG *getshm(key_t key, size_t imsize); -int canberead(int fd);