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