diff --git a/Daemons/10micron_stellarium/libsofa.c b/Daemons/10micron_stellarium/libsofa.c index f51b0b9..b6f4b62 100644 --- a/Daemons/10micron_stellarium/libsofa.c +++ b/Daemons/10micron_stellarium/libsofa.c @@ -46,7 +46,7 @@ void radtodeg(double r){ #endif // temporal stubs for weather/place data; return 0 if all OK -static int getPlace(placeData *p){ +int getPlace(placeData *p){ if(!p) return 0; /* Site longitude, latitude (radians) and height above the geoid (m). */ p->slong = 0.7232763200; @@ -59,14 +59,14 @@ static int getPlace(placeData *p){ //DBG("long: %.10f, lat: %.10f", p->slong, p->slat); return 0; } -static int getWeath(placeWeather *w){ +int getWeath(placeWeather *w){ if(!w) return 0; w->relhum = 0.7; w->tc = 0.; w->php = 780.; return 0; } -static int getDUT(almDut *a){ +int getDUT(almDut *a){ if(!a) return 0; a->px = a->py = a->DUT1 = 0.; return 0; diff --git a/Daemons/10micron_stellarium/libsofa.h b/Daemons/10micron_stellarium/libsofa.h index 058d65c..24f5956 100644 --- a/Daemons/10micron_stellarium/libsofa.h +++ b/Daemons/10micron_stellarium/libsofa.h @@ -70,5 +70,7 @@ typedef struct{ int get_MJDt(struct timeval *tval, sMJD *MJD); int get_ObsPlace(struct timeval *tval, polarCrds *p2000, polarCrds *pnow, horizCrds *hnow); - +int getDUT(almDut *a); +int getWeath(placeWeather *w); +int getPlace(placeData *p); #endif // LIBSOFA_H__ diff --git a/Daemons/10micron_stellarium/main.c b/Daemons/10micron_stellarium/main.c index 4bbe94e..349cead 100644 --- a/Daemons/10micron_stellarium/main.c +++ b/Daemons/10micron_stellarium/main.c @@ -49,18 +49,22 @@ static uint8_t buff[BUFLEN+1]; // global parameters static glob_pars *GP = NULL; +static pid_t childpid = 1; // PID of child process static volatile int global_quit = 0; // quit by signal void signals(int sig){ signal(sig, SIG_IGN); unlink(GP->crdsfile); // remove header file unlink(GP->pidfile); // and remove pidfile - restore_console(); - restore_tty(); + if(childpid){ // parent process + restore_console(); + restore_tty(); + } DBG("Get signal %d, quit.\n", sig); global_quit = 1; sleep(1); - WARNX(_("PID %d exit with status %d"), getpid(), sig); + if(childpid) putlog("PID %d exit with status %d after child's %d death", getpid(), sig, childpid); + else WARN("Child %d died with %d", getpid(), sig); exit(sig); } @@ -403,6 +407,7 @@ int main(int argc, char **argv){ if(GP->logfile) openlogfile(GP->logfile); signal(SIGTERM, signals); // kill (-15) - quit + signal(SIGKILL, signals); // kill (-9) - quit signal(SIGHUP, SIG_IGN); // hup - ignore signal(SIGINT, signals); // ctrl+C - quit signal(SIGQUIT, signals); // ctrl+\ - quit @@ -423,7 +428,7 @@ int main(int argc, char **argv){ #endif // EBUG while(1){ - pid_t childpid = fork(); + childpid = fork(); if(childpid < 0){ putlog("fork() error"); ERR("ERROR on fork"); diff --git a/Daemons/10micron_stellarium/telescope.c b/Daemons/10micron_stellarium/telescope.c index 3153585..3822e71 100644 --- a/Daemons/10micron_stellarium/telescope.c +++ b/Daemons/10micron_stellarium/telescope.c @@ -98,6 +98,46 @@ static char *write_cmd(const char *cmd){ return NULL; } +// write to telescope mount corrections: datetime, pressure and temperature +static void makecorr(){ + // write current date&time + char buf[64], *ans; +#ifdef EBUG + write_cmd(":GUDT#"); +#endif + write_cmd(":gT#"); // correct time by GPS + ans = write_cmd(":gtg#"); + if(!ans || *ans != '1'){ + WARNX("mount don't synchronized with GPS! Refresh datetime"); + time_t t = time(NULL); + struct tm *stm = localtime(&t); + struct timeval tv; + gettimeofday(&tv,NULL); + snprintf(buf, 64, ":SLDT%04d-%02d-%02d,%02d:%02d:%02d.%02ld#", 1900+stm->tm_year, stm->tm_mon, stm->tm_mday, + stm->tm_hour, stm->tm_min, stm->tm_sec, tv.tv_usec/10000); + ans = write_cmd(buf); + if(!ans || *ans != '1'){ + WARNX("Can't write current date/time"); + putlog("Can't set system time"); + }else putlog("Set system time by command %s", buf); +#ifdef EBUG + write_cmd(":GUDT#"); +#endif + } + placeWeather w; + if(getWeath(&w)) putlog("Can't determine weather data"); + else{ // set refraction model data + snprintf(buf, 64, ":SRPRS%.1f#", w.php); + ans = write_cmd(buf); + if(!ans || *ans != '1') putlog("Can't set pressure data of refraction model"); + else putlog("Correct pressure to %g", w.php); + snprintf(buf, 64, ":SRTMP%.1f#", w.tc); + ans = write_cmd(buf); + if(!ans || *ans != '1') putlog("Can't set temperature data of refraction model"); + else putlog("Correct temperature to %g", w.tc); + } +} + int chkconn(){ char tmpbuf[4096]; @@ -131,11 +171,13 @@ int connect_telescope(char *dev, char *hdrname){ if(!chkconn()) return 0; } write_cmd(":U2#"); - write_cmd(":U2#"); + write_cmd(":U2#"); // set high precision + write_cmd(":So10#"); // set minimum altitude to 10 degrees putlog("Connected to %s@115200, will write FITS-header into %s", dev, hdrname); hdname = strdup(hdrname); DBG("connected"); Target = 0; + write_cmd(":gT#"); // correct time by GPS return 1; } @@ -324,12 +366,16 @@ static void getplace(){ } } - /** * @brief wrhdr - try to write into header file */ void wrhdr(){ static int failcounter = 0; + static time_t lastcorr = 0; // last time of corrections made + if(time(NULL) - lastcorr > CORRECTIONS_TIMEDIFF){ + lastcorr = time(NULL); + makecorr(); + } char *ans = NULL, *jd = NULL, *lst = NULL, *date = NULL, *pS = NULL; // get coordinates for writing to file & sending to stellarium client ans = write_cmd(":GR#"); @@ -354,7 +400,7 @@ void wrhdr(){ tlast = time(NULL); if(!hdname) return; if(!elevation || !longitude || !latitude) getplace(); - ans = write_cmd(":GJD#"); jd = dups(ans, 0); + ans = write_cmd(":GJD1#"); jd = dups(ans, 0); ans = write_cmd(":GS#"); lst = dups(ans, 1); ans = write_cmd(":GUDT#"); if(ans){ @@ -395,12 +441,14 @@ void wrhdr(){ if(!get_MJDt(NULL, &mjd)){ snprintf(val, 22, "%.10f", 2000.+(mjd.MJD-MJD2000)/365.25); // calculate EPOCH/EQUINOX WRHDR("EQUINOX", val, "Equinox of celestial coordinate system"); + snprintf(val, 22, "%.10f", mjd.MJD); + WRHDR("MJD-END", val, "Modified julian date of observations end"); } + if(jd) WRHDR("JD-END", jd, "Julian date of observations end"); if(pS) WRHDR("PIERSIDE", pS, "Pier side of telescope mount"); if(elevation) WRHDR("ELEVAT", elevation, "Elevation of site over the sea level"); if(longitude) WRHDR("LONGITUD", longitude, "Geo longitude of site (east negative)"); if(latitude) WRHDR("LATITUDE", latitude, "Geo latitude of site (south negative)"); - if(jd) WRHDR("JD-END", jd, "Julian date of observations end"); if(lst) WRHDR("LSTEND", lst, "Local sidereal time of observations end"); if(date) WRHDR("DATE-END", date, "Date (UTC) of observations end"); FREE(jd); FREE(lst); FREE(date); FREE(pS); @@ -409,6 +457,4 @@ void wrhdr(){ close(hdrfd); } -// LSTSTART - sid time -// MJD-END diff --git a/Daemons/10micron_stellarium/telescope.h b/Daemons/10micron_stellarium/telescope.h index efabb74..3e23117 100644 --- a/Daemons/10micron_stellarium/telescope.h +++ b/Daemons/10micron_stellarium/telescope.h @@ -26,6 +26,8 @@ // max time after last coordinates reading #define COORDS_TOO_OLD_TIME (5) +// make datetime/pressure/temperature corrections each CORRECTIONS_TIMEDIFF seconds +#define CORRECTIONS_TIMEDIFF (3600) int connect_telescope(char *dev, char *hdrname); int point_telescope(double ra, double decl);