mirror of
https://github.com/eddyem/small_tel.git
synced 2025-12-06 10:45:16 +03:00
add datetime settings
This commit is contained in:
parent
f6fdff12a5
commit
ab524d4bf6
@ -46,7 +46,7 @@ void radtodeg(double r){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// temporal stubs for weather/place data; return 0 if all OK
|
// temporal stubs for weather/place data; return 0 if all OK
|
||||||
static int getPlace(placeData *p){
|
int getPlace(placeData *p){
|
||||||
if(!p) return 0;
|
if(!p) return 0;
|
||||||
/* Site longitude, latitude (radians) and height above the geoid (m). */
|
/* Site longitude, latitude (radians) and height above the geoid (m). */
|
||||||
p->slong = 0.7232763200;
|
p->slong = 0.7232763200;
|
||||||
@ -59,14 +59,14 @@ static int getPlace(placeData *p){
|
|||||||
//DBG("long: %.10f, lat: %.10f", p->slong, p->slat);
|
//DBG("long: %.10f, lat: %.10f", p->slong, p->slat);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int getWeath(placeWeather *w){
|
int getWeath(placeWeather *w){
|
||||||
if(!w) return 0;
|
if(!w) return 0;
|
||||||
w->relhum = 0.7;
|
w->relhum = 0.7;
|
||||||
w->tc = 0.;
|
w->tc = 0.;
|
||||||
w->php = 780.;
|
w->php = 780.;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static int getDUT(almDut *a){
|
int getDUT(almDut *a){
|
||||||
if(!a) return 0;
|
if(!a) return 0;
|
||||||
a->px = a->py = a->DUT1 = 0.;
|
a->px = a->py = a->DUT1 = 0.;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -70,5 +70,7 @@ typedef struct{
|
|||||||
|
|
||||||
int get_MJDt(struct timeval *tval, sMJD *MJD);
|
int get_MJDt(struct timeval *tval, sMJD *MJD);
|
||||||
int get_ObsPlace(struct timeval *tval, polarCrds *p2000, polarCrds *pnow, horizCrds *hnow);
|
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__
|
#endif // LIBSOFA_H__
|
||||||
|
|||||||
@ -49,18 +49,22 @@ static uint8_t buff[BUFLEN+1];
|
|||||||
// global parameters
|
// global parameters
|
||||||
static glob_pars *GP = NULL;
|
static glob_pars *GP = NULL;
|
||||||
|
|
||||||
|
static pid_t childpid = 1; // PID of child process
|
||||||
static volatile int global_quit = 0;
|
static volatile int global_quit = 0;
|
||||||
// quit by signal
|
// quit by signal
|
||||||
void signals(int sig){
|
void signals(int sig){
|
||||||
signal(sig, SIG_IGN);
|
signal(sig, SIG_IGN);
|
||||||
unlink(GP->crdsfile); // remove header file
|
unlink(GP->crdsfile); // remove header file
|
||||||
unlink(GP->pidfile); // and remove pidfile
|
unlink(GP->pidfile); // and remove pidfile
|
||||||
|
if(childpid){ // parent process
|
||||||
restore_console();
|
restore_console();
|
||||||
restore_tty();
|
restore_tty();
|
||||||
|
}
|
||||||
DBG("Get signal %d, quit.\n", sig);
|
DBG("Get signal %d, quit.\n", sig);
|
||||||
global_quit = 1;
|
global_quit = 1;
|
||||||
sleep(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);
|
exit(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,6 +407,7 @@ int main(int argc, char **argv){
|
|||||||
if(GP->logfile) openlogfile(GP->logfile);
|
if(GP->logfile) openlogfile(GP->logfile);
|
||||||
|
|
||||||
signal(SIGTERM, signals); // kill (-15) - quit
|
signal(SIGTERM, signals); // kill (-15) - quit
|
||||||
|
signal(SIGKILL, signals); // kill (-9) - quit
|
||||||
signal(SIGHUP, SIG_IGN); // hup - ignore
|
signal(SIGHUP, SIG_IGN); // hup - ignore
|
||||||
signal(SIGINT, signals); // ctrl+C - quit
|
signal(SIGINT, signals); // ctrl+C - quit
|
||||||
signal(SIGQUIT, signals); // ctrl+\ - quit
|
signal(SIGQUIT, signals); // ctrl+\ - quit
|
||||||
@ -423,7 +428,7 @@ int main(int argc, char **argv){
|
|||||||
#endif // EBUG
|
#endif // EBUG
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
pid_t childpid = fork();
|
childpid = fork();
|
||||||
if(childpid < 0){
|
if(childpid < 0){
|
||||||
putlog("fork() error");
|
putlog("fork() error");
|
||||||
ERR("ERROR on fork");
|
ERR("ERROR on fork");
|
||||||
|
|||||||
@ -98,6 +98,46 @@ static char *write_cmd(const char *cmd){
|
|||||||
return NULL;
|
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(){
|
int chkconn(){
|
||||||
char tmpbuf[4096];
|
char tmpbuf[4096];
|
||||||
@ -131,11 +171,13 @@ int connect_telescope(char *dev, char *hdrname){
|
|||||||
if(!chkconn()) return 0;
|
if(!chkconn()) return 0;
|
||||||
}
|
}
|
||||||
write_cmd(":U2#");
|
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);
|
putlog("Connected to %s@115200, will write FITS-header into %s", dev, hdrname);
|
||||||
hdname = strdup(hdrname);
|
hdname = strdup(hdrname);
|
||||||
DBG("connected");
|
DBG("connected");
|
||||||
Target = 0;
|
Target = 0;
|
||||||
|
write_cmd(":gT#"); // correct time by GPS
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,12 +366,16 @@ static void getplace(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief wrhdr - try to write into header file
|
* @brief wrhdr - try to write into header file
|
||||||
*/
|
*/
|
||||||
void wrhdr(){
|
void wrhdr(){
|
||||||
static int failcounter = 0;
|
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;
|
char *ans = NULL, *jd = NULL, *lst = NULL, *date = NULL, *pS = NULL;
|
||||||
// get coordinates for writing to file & sending to stellarium client
|
// get coordinates for writing to file & sending to stellarium client
|
||||||
ans = write_cmd(":GR#");
|
ans = write_cmd(":GR#");
|
||||||
@ -354,7 +400,7 @@ void wrhdr(){
|
|||||||
tlast = time(NULL);
|
tlast = time(NULL);
|
||||||
if(!hdname) return;
|
if(!hdname) return;
|
||||||
if(!elevation || !longitude || !latitude) getplace();
|
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(":GS#"); lst = dups(ans, 1);
|
||||||
ans = write_cmd(":GUDT#");
|
ans = write_cmd(":GUDT#");
|
||||||
if(ans){
|
if(ans){
|
||||||
@ -395,12 +441,14 @@ void wrhdr(){
|
|||||||
if(!get_MJDt(NULL, &mjd)){
|
if(!get_MJDt(NULL, &mjd)){
|
||||||
snprintf(val, 22, "%.10f", 2000.+(mjd.MJD-MJD2000)/365.25); // calculate EPOCH/EQUINOX
|
snprintf(val, 22, "%.10f", 2000.+(mjd.MJD-MJD2000)/365.25); // calculate EPOCH/EQUINOX
|
||||||
WRHDR("EQUINOX", val, "Equinox of celestial coordinate system");
|
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(pS) WRHDR("PIERSIDE", pS, "Pier side of telescope mount");
|
||||||
if(elevation) WRHDR("ELEVAT", elevation, "Elevation of site over the sea level");
|
if(elevation) WRHDR("ELEVAT", elevation, "Elevation of site over the sea level");
|
||||||
if(longitude) WRHDR("LONGITUD", longitude, "Geo longitude of site (east negative)");
|
if(longitude) WRHDR("LONGITUD", longitude, "Geo longitude of site (east negative)");
|
||||||
if(latitude) WRHDR("LATITUDE", latitude, "Geo latitude of site (south 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(lst) WRHDR("LSTEND", lst, "Local sidereal time of observations end");
|
||||||
if(date) WRHDR("DATE-END", date, "Date (UTC) of observations end");
|
if(date) WRHDR("DATE-END", date, "Date (UTC) of observations end");
|
||||||
FREE(jd); FREE(lst); FREE(date); FREE(pS);
|
FREE(jd); FREE(lst); FREE(date); FREE(pS);
|
||||||
@ -409,6 +457,4 @@ void wrhdr(){
|
|||||||
close(hdrfd);
|
close(hdrfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LSTSTART - sid time
|
|
||||||
// MJD-END
|
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
// max time after last coordinates reading
|
// max time after last coordinates reading
|
||||||
#define COORDS_TOO_OLD_TIME (5)
|
#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 connect_telescope(char *dev, char *hdrname);
|
||||||
int point_telescope(double ra, double decl);
|
int point_telescope(double ra, double decl);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user