Add watchdog to client

This commit is contained in:
eddyem 2017-05-03 10:17:17 +03:00
parent 006a8bd9eb
commit bf34128607
6 changed files with 39 additions and 11 deletions

View File

@ -57,9 +57,9 @@ glob_pars const Gdefault = {
.port = "4444", .port = "4444",
.once = 0, .once = 0,
.timestamp = 0, .timestamp = 0,
.dark_interval = 1800, .dark_interval = 1800.,
.min_dark_exp = 30, .min_dark_exp = 30.,
.max_exptime = -1, .max_exptime = -1.,
.htrperiod = 0 .htrperiod = 0
}; };

View File

@ -383,6 +383,11 @@ int writefits(imstorage *img){
#endif // LIBCFITSIO #endif // LIBCFITSIO
#endif // !DAEMON #endif // !DAEMON
static double max_exptime = 180.;
void set_max_exptime(double t){
if(t > 30. && t < 300.) max_exptime = t;
}
#ifndef CLIENT #ifndef CLIENT
/** /**
* Receive image data & fill img->imdata * Receive image data & fill img->imdata
@ -399,12 +404,15 @@ uint16_t *get_imdata(imstorage *img){
img->imdata = imdata; img->imdata = imdata;
return imdata; return imdata;
} }
#endif // CLIENT #else
/**
static double max_exptime = 180.; * calculate period for watchdog: 2*max_exptime + 3 minutes
void set_max_exptime(double t){ */
if(t > 30. && t < 300.) max_exptime = t; time_t get_wd_period(){
time_t period = 2 * (time_t) max_exptime + 180;
return period;
} }
#endif // !CLIENT
/** /**
* save truncated to 256 levels histogram of `img` into file `f` * save truncated to 256 levels histogram of `img` into file `f`

View File

@ -84,8 +84,11 @@ char *make_filename(imstorage *img, const char *suff);
imstorage *chk_storeimg(imstorage *img, char* store, char *format); imstorage *chk_storeimg(imstorage *img, char* store, char *format);
int store_image(imstorage *filename); int store_image(imstorage *filename);
void print_stat(imstorage *img); void print_stat(imstorage *img);
#ifndef CLIENT #ifndef CLIENT
uint16_t *get_imdata(imstorage *img); uint16_t *get_imdata(imstorage *img);
#else
time_t get_wd_period();
#endif #endif
int save_histo(FILE *f, imstorage *img); int save_histo(FILE *f, imstorage *img);

2
main.c
View File

@ -59,7 +59,7 @@ int main(int argc, char **argv){
imsubframe *F = NULL; imsubframe *F = NULL;
#ifndef CLIENT #ifndef CLIENT
if(G->htrperiod) set_heater_period(G->htrperiod); if(G->htrperiod) set_heater_period(G->htrperiod);
if(G->max_exptime) set_max_exptime(G->max_exptime); if(G->max_exptime > 0) set_max_exptime(G->max_exptime);
if(G->splist){ if(G->splist){
list_speeds(); list_speeds();
return 0; return 0;

View File

@ -339,9 +339,14 @@ static void daemon_(imstorage *img, int sock){
} }
if(exp_calculated > 0.) img->exptime = exp_calculated; if(exp_calculated > 0.) img->exptime = exp_calculated;
if(img->imtype != IMTYPE_AUTODARK){ // check for darks if(img->imtype != IMTYPE_AUTODARK){ // check for darks
if(img->imtype == IMTYPE_DARK) img->imtype = IMTYPE_LIGHT; // last was dark if(img->imtype == IMTYPE_DARK){
putlog("First light frame after dark");
img->imtype = IMTYPE_LIGHT; // last was dark
}
else if(img->exptime > min_dark_exp){ // need to store dark frame? else if(img->exptime > min_dark_exp){ // need to store dark frame?
putlog("exptime > %g; dtime()=%.1f, lastDT = %.1f", min_dark_exp, dtime(), lastDT);
if(dtime() - lastDT > dark_interval){ if(dtime() - lastDT > dark_interval){
putlog("Take dark image");
lastDT = dtime(); lastDT = dtime();
img->imtype = IMTYPE_DARK; img->imtype = IMTYPE_DARK;
} }
@ -411,7 +416,14 @@ static void client_(imstorage *img, int sock){
if(sock < 0) return; if(sock < 0) return;
size_t Bufsiz = BUFLEN10; size_t Bufsiz = BUFLEN10;
uint8_t *recvBuff = MALLOC(uint8_t, Bufsiz); uint8_t *recvBuff = MALLOC(uint8_t, Bufsiz);
time_t wd_time = time(NULL); // watchdog time
time_t wd_period = get_wd_period(); // watchdog period: about 3minutes + 2*max_exptime
while(1){ while(1){
// check watchdog
if(time(NULL) - wd_time > wd_period){
putlog("Watchdog triggered, exit!");
return;
}
int rd = waittoread(sock); int rd = waittoread(sock);
if(rd < 0){ if(rd < 0){
putlog("Server disconnected"); putlog("Server disconnected");
@ -447,6 +459,7 @@ static void client_(imstorage *img, int sock){
return; return;
} }
DBG("read %zd bytes\n", offset); DBG("read %zd bytes\n", offset);
wd_time = time(NULL); // refresh watchdog - socket OK
if(get_imstorage(img, recvBuff, offset)){ if(get_imstorage(img, recvBuff, offset)){
if(store_image(img)){ if(store_image(img)){
putlog("Error storing image"); putlog("Error storing image");

6
term.c
View File

@ -351,7 +351,11 @@ void run_terminal(){
void heater(heater_cmd cmd){ void heater(heater_cmd cmd){
if(cmd == HEATER_LEAVE) return; if(cmd == HEATER_LEAVE) return;
uint8_t buf[2] = {CMD_HEATER, 0}; uint8_t buf[2] = {CMD_HEATER, 0};
if(cmd == HEATER_ON) buf[1] = 1; if(cmd == HEATER_ON){
putlog("Turn heater ON");
buf[1] = 1;
}else
putlog("Turn heater OFF");
int i; int i;
for(i = 0; i < 10 && send_data(buf, 2); ++i); for(i = 0; i < 10 && send_data(buf, 2); ++i);
trans_status st = TRANS_TIMEOUT; trans_status st = TRANS_TIMEOUT;