some changes in artifical-star plugin, add simplest centroids example

This commit is contained in:
2024-05-14 17:20:03 +03:00
parent eb8f497b0b
commit 1788fea1c3
10 changed files with 346 additions and 167 deletions

View File

@@ -40,7 +40,8 @@ typedef struct{
static glob_pars G = {
.shmkey = 7777777,
.nframes = 10
.nframes = 2,
.exptime = -1.
};
/*
@@ -63,6 +64,8 @@ static int refresh_img(){
if(!shimg) return FALSE;
static size_t imnumber = 0;
if(shimg->imnumber == imnumber) return FALSE;
double ts = dtime();
if(ts - shimg->timestamp > G.exptime + 1.) return FALSE; // too old image
imnumber = shimg->imnumber;
void *optr = img.data;
memcpy(&img, shimg, sizeof(img));
@@ -82,6 +85,7 @@ int main(int argc, char **argv){
for(int i = 0; i < argc; ++i)
printf("%4d: %s\n", i, argv[i]);
}
if(G.nframes < 1) ERRX("nframes should be > 0");
if(!G.sockname) ERRX("Point socket name or port");
cc_strbuff *cbuf = cc_strbufnew(BUFSIZ, STRBUFSZ);
int sock = cc_open_socket(FALSE, G.sockname, !G.isun);
@@ -93,27 +97,39 @@ int main(int argc, char **argv){
red("Can't read shmkey, try yours\n");
shmemkey = G.shmkey;
}
if(RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n");
else red("Can't ask for INFTY\n");
if(G.infty){
if(RESULT_OK == cc_setint(sock, cbuf, CC_CMD_INFTY, 1)) green("ask for INFTY\n");
else red("Can't ask for INFTY\n");
}
float xt = 0.f;
if(RESULT_OK == cc_getfloat(sock, cbuf, CC_CMD_EXPOSITION, &xt)){
green("Old exp time: %gs\n", xt);
}
fflush(stdout);
if(RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, 0.5)) green("ask for exptime 0.5s\n");
else red("Can't change exptime to 0.5s\n");
if(G.exptime > 0.){
if(RESULT_OK == cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, G.exptime)) green("ask for exptime %gs\n", G.exptime);
else red("Can't change exptime to %gs\n", G.exptime);
}
shimg = cc_getshm(shmemkey, 0);
if(!shimg) ERRX("Can't get shared memory segment");
int i = 0;
time_t oldtime = time(NULL);
double oldtimestamp = shimg->timestamp;
double waittime = ((int)G.exptime) + 5.;
do{
if(cc_refreshbuf(sock, cbuf) && cc_getline(cbuf)){
printf("\t\tServer sent: `%s`\n", cbuf->string);
if(!G.infty){ // ask new image in non-infty mode
if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_EXPSTATE, CAMERA_CAPTURE)){
WARNX("Can't ask new image\n");
usleep(1000);
continue;
}
usleep(1000);
}
if(cc_refreshbuf(sock, cbuf)){
while(cc_getline(cbuf)) printf("\t\tServer sent: `%s`\n", cbuf->string);
}
time_t now = time(NULL);
if(now - oldtime > 5){
WARNX("No new images for 5 seconds");
if(now - oldtime > waittime){
WARNX("No new images for %g seconds", waittime);
break;
}
if(!refresh_img()){
@@ -122,9 +138,11 @@ int main(int argc, char **argv){
}
++i;
oldtime = now;
printf("Got image #%zd, size %dx%d, bitpix %d, time %g\n", img.imnumber, img.w, img.h, img.bitpix, img.timestamp-oldtimestamp);
}while(i < 2);
if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n");
printf("Got image #%zd, size %dx%d, bitpix %d, time %.2f\n", img.imnumber, img.w, img.h, img.bitpix, img.timestamp);
}while(i < G.nframes);
if(G.infty){
if(RESULT_OK != cc_setint(sock, cbuf, CC_CMD_INFTY, 0)) red("Can't clear INFTY\n");
}
if(xt > 0.){
if(RESULT_OK != cc_setfloat(sock, cbuf, CC_CMD_EXPOSITION, xt)) red("Can't return exptime to %gs\n", xt);
}