mirror of
https://github.com/eddyem/SBIG_340.git
synced 2025-12-06 18:55:12 +03:00
Add watchdog to client
This commit is contained in:
parent
006a8bd9eb
commit
bf34128607
@ -57,9 +57,9 @@ glob_pars const Gdefault = {
|
||||
.port = "4444",
|
||||
.once = 0,
|
||||
.timestamp = 0,
|
||||
.dark_interval = 1800,
|
||||
.min_dark_exp = 30,
|
||||
.max_exptime = -1,
|
||||
.dark_interval = 1800.,
|
||||
.min_dark_exp = 30.,
|
||||
.max_exptime = -1.,
|
||||
.htrperiod = 0
|
||||
};
|
||||
|
||||
|
||||
@ -383,6 +383,11 @@ int writefits(imstorage *img){
|
||||
#endif // LIBCFITSIO
|
||||
#endif // !DAEMON
|
||||
|
||||
static double max_exptime = 180.;
|
||||
void set_max_exptime(double t){
|
||||
if(t > 30. && t < 300.) max_exptime = t;
|
||||
}
|
||||
|
||||
#ifndef CLIENT
|
||||
/**
|
||||
* Receive image data & fill img->imdata
|
||||
@ -399,12 +404,15 @@ uint16_t *get_imdata(imstorage *img){
|
||||
img->imdata = imdata;
|
||||
return imdata;
|
||||
}
|
||||
#endif // CLIENT
|
||||
|
||||
static double max_exptime = 180.;
|
||||
void set_max_exptime(double t){
|
||||
if(t > 30. && t < 300.) max_exptime = t;
|
||||
#else
|
||||
/**
|
||||
* calculate period for watchdog: 2*max_exptime + 3 minutes
|
||||
*/
|
||||
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`
|
||||
|
||||
@ -84,8 +84,11 @@ char *make_filename(imstorage *img, const char *suff);
|
||||
imstorage *chk_storeimg(imstorage *img, char* store, char *format);
|
||||
int store_image(imstorage *filename);
|
||||
void print_stat(imstorage *img);
|
||||
|
||||
#ifndef CLIENT
|
||||
uint16_t *get_imdata(imstorage *img);
|
||||
#else
|
||||
time_t get_wd_period();
|
||||
#endif
|
||||
int save_histo(FILE *f, imstorage *img);
|
||||
|
||||
|
||||
2
main.c
2
main.c
@ -59,7 +59,7 @@ int main(int argc, char **argv){
|
||||
imsubframe *F = NULL;
|
||||
#ifndef CLIENT
|
||||
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){
|
||||
list_speeds();
|
||||
return 0;
|
||||
|
||||
15
socket.c
15
socket.c
@ -339,9 +339,14 @@ static void daemon_(imstorage *img, int sock){
|
||||
}
|
||||
if(exp_calculated > 0.) img->exptime = exp_calculated;
|
||||
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?
|
||||
putlog("exptime > %g; dtime()=%.1f, lastDT = %.1f", min_dark_exp, dtime(), lastDT);
|
||||
if(dtime() - lastDT > dark_interval){
|
||||
putlog("Take dark image");
|
||||
lastDT = dtime();
|
||||
img->imtype = IMTYPE_DARK;
|
||||
}
|
||||
@ -411,7 +416,14 @@ static void client_(imstorage *img, int sock){
|
||||
if(sock < 0) return;
|
||||
size_t Bufsiz = BUFLEN10;
|
||||
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){
|
||||
// check watchdog
|
||||
if(time(NULL) - wd_time > wd_period){
|
||||
putlog("Watchdog triggered, exit!");
|
||||
return;
|
||||
}
|
||||
int rd = waittoread(sock);
|
||||
if(rd < 0){
|
||||
putlog("Server disconnected");
|
||||
@ -447,6 +459,7 @@ static void client_(imstorage *img, int sock){
|
||||
return;
|
||||
}
|
||||
DBG("read %zd bytes\n", offset);
|
||||
wd_time = time(NULL); // refresh watchdog - socket OK
|
||||
if(get_imstorage(img, recvBuff, offset)){
|
||||
if(store_image(img)){
|
||||
putlog("Error storing image");
|
||||
|
||||
6
term.c
6
term.c
@ -351,7 +351,11 @@ void run_terminal(){
|
||||
void heater(heater_cmd cmd){
|
||||
if(cmd == HEATER_LEAVE) return;
|
||||
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;
|
||||
for(i = 0; i < 10 && send_data(buf, 2); ++i);
|
||||
trans_status st = TRANS_TIMEOUT;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user