From f07d63c9705a18d861c1be79432e379c2d375354 Mon Sep 17 00:00:00 2001 From: Edward Emelianov Date: Tue, 2 May 2023 16:35:36 +0300 Subject: [PATCH] port from libsofa to liberfa --- Daemons/10micron_stellarium/Makefile | 2 +- Daemons/10micron_stellarium/Readme | 5 +++ Daemons/10micron_stellarium/libsofa.c | 46 ++++++++++++------------- Daemons/10micron_stellarium/libsofa.h | 4 +-- Daemons/10micron_stellarium/main.c | 12 +++---- Daemons/10micron_stellarium/telescope.c | 8 ++--- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Daemons/10micron_stellarium/Makefile b/Daemons/10micron_stellarium/Makefile index ffe71f9..d4721a9 100644 --- a/Daemons/10micron_stellarium/Makefile +++ b/Daemons/10micron_stellarium/Makefile @@ -1,5 +1,5 @@ PROGRAM = stellariumdaemon -LDFLAGS = -lsofa_c -pthread +LDFLAGS = -lerfa -pthread SRCS = $(wildcard *.c) CC = gcc DEFINES = -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=1111 diff --git a/Daemons/10micron_stellarium/Readme b/Daemons/10micron_stellarium/Readme index d81b392..f1ee993 100644 --- a/Daemons/10micron_stellarium/Readme +++ b/Daemons/10micron_stellarium/Readme @@ -1 +1,6 @@ Stellarium control of 10-micron mount + + +Special commands in terminal mode: +PAUSE - pause output to port from everywhere except terminal thread +CONTINUE - allow to write to port for everyone diff --git a/Daemons/10micron_stellarium/libsofa.c b/Daemons/10micron_stellarium/libsofa.c index 9a0ac3b..37bc1d9 100644 --- a/Daemons/10micron_stellarium/libsofa.c +++ b/Daemons/10micron_stellarium/libsofa.c @@ -27,18 +27,18 @@ void reprd(char* s, double ra, double dc){ char pm; int i[4]; printf ( "%s:", s ); - iauA2tf ( 7, ra, &pm, i ); + eraA2tf ( 7, ra, &pm, i ); printf ( " %2.2d %2.2d %2.2d.%7.7d", i[0],i[1],i[2],i[3] ); - iauA2af ( 6, dc, &pm, i ); + eraA2af ( 6, dc, &pm, i ); printf ( " %c%2.2d %2.2d %2.2d.%6.6d\n", pm, i[0],i[1],i[2],i[3] ); } void radtodeg(double r){ int i[4]; char pm; - int rem = (int)(r / D2PI); - if(rem) r -= D2PI * rem; - if(r > DPI) r -= D2PI; - else if(r < -DPI) r += D2PI; - iauA2af (2, r, &pm, i); + int rem = (int)(r / ERFA_D2PI); + if(rem) r -= ERFA_D2PI * rem; + if(r > ERFA_DPI) r -= ERFA_D2PI; + else if(r < -ERFA_DPI) r += ERFA_D2PI; + eraA2af (2, r, &pm, i); printf("%c%02d %02d %02d.%2.d", pm, i[0],i[1],i[2],i[3]); } #define REP(a,b,c) reprd(a,b,c) @@ -98,7 +98,7 @@ almDut *getDUT(){ void r2sHMS(double radians, char *hms, int len){ char pm; int i[4]; - iauA2tf(2, radians, &pm, i); + eraA2tf(2, radians, &pm, i); snprintf(hms, len, "'%c%02d:%02d:%02d.%02d'", pm, i[0],i[1],i[2],i[3]); } @@ -111,7 +111,7 @@ void r2sHMS(double radians, char *hms, int len){ void r2sDMS(double radians, char *dms, int len){ char pm; int i[4]; - iauA2af(1, radians, &pm, i); + eraA2af(1, radians, &pm, i); snprintf(dms, len, "'%c%02d:%02d:%02d.%d'", pm, i[0],i[1],i[2],i[3]); } @@ -140,15 +140,15 @@ int get_MJDt(struct timeval *tval, sMJD *MJD){ d = tms.tm_mday; double utc1, utc2; /* UTC date. */ - if(iauDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0) return -1; + if(eraDtf2d("UTC", y, m, d, tms.tm_hour, tms.tm_min, tSeconds, &utc1, &utc2) < 0) return -1; if(!MJD) return 0; MJD->MJD = utc1 - 2400000.5 + utc2; MJD->utc1 = utc1; MJD->utc2 = utc2; //DBG("UTC(m): %g, %.8f\n", utc1 - 2400000.5, utc2); - if(iauUtctai(utc1, utc2, &MJD->tai1, &MJD->tai2)) return -1; + if(eraUtctai(utc1, utc2, &MJD->tai1, &MJD->tai2)) return -1; //DBG("TAI"); - if(iauTaitt(MJD->tai1, MJD->tai2, &MJD->tt1, &MJD->tt2)) return -1; + if(eraTaitt(MJD->tai1, MJD->tai2, &MJD->tt1, &MJD->tt2)) return -1; //DBG("TT"); return 0; } @@ -167,16 +167,16 @@ int get_LST(sMJD *mjd, double dUT1, double slong, double *LST){ if(!mjd){ if(get_MJDt(NULL, &Mjd)) return 1; }else memcpy(&Mjd, mjd, sizeof(sMJD)); - if(iauUtcut1(Mjd.utc1, Mjd.utc2, dUT1, &ut11, &ut12)) return 2; + if(eraUtcut1(Mjd.utc1, Mjd.utc2, dUT1, &ut11, &ut12)) return 2; /*double era = iauEra00(ut11, ut12) + slong; double eo = iauEe06a(mjd->tt1, mjd->tt2); printf("ERA = %s; ", radtohrs(era)); printf("ERA-eo = %s\n", radtohrs(era-eo));*/ if(!LST) return 0; - double ST = iauGst06a(ut11, ut12, Mjd.tt1, Mjd.tt2); + double ST = eraGst06a(ut11, ut12, Mjd.tt1, Mjd.tt2); ST += slong; - if(ST > D2PI) ST -= D2PI; - else if(ST < 0.) ST += D2PI; + if(ST > ERFA_D2PI) ST -= ERFA_D2PI; + else if(ST < 0.) ST += ERFA_D2PI; *LST = ST; return 0; } @@ -191,7 +191,7 @@ int get_LST(sMJD *mjd, double dUT1, double slong, double *LST){ void hor2eq(horizCrds *h, polarCrds *pc, double sidTime){ if(!h || !pc) return; placeData *p = getPlace(); - iauAe2hd(h->az, DPI/2. - h->zd, p->slat, &pc->ha, &pc->dec); // A,H -> HA,DEC; phi - site latitude + eraAe2hd(h->az, ERFA_DPI/2. - h->zd, p->slat, &pc->ha, &pc->dec); // A,H -> HA,DEC; phi - site latitude pc->ra = sidTime - pc->ha; pc->eo = 0.; } @@ -206,8 +206,8 @@ void eq2horH(polarCrds *pc, horizCrds *h){ if(!h || !pc) return; placeData *p = getPlace(); double alt; - iauHd2ae(pc->ha, pc->dec, p->slat, &h->az, &alt); - h->zd = DPI/2. - alt; + eraHd2ae(pc->ha, pc->dec, p->slat, &h->az, &alt); + h->zd = ERFA_DPI/2. - alt; } /** @@ -221,8 +221,8 @@ void eq2hor(polarCrds *pc, horizCrds *h, double sidTime){ double ha = sidTime - pc->ra + pc->eo; placeData *p = getPlace(); double alt; - iauHd2ae(ha, pc->dec, p->slat, &h->az, &alt); - h->zd = DPI/2. - alt; + eraHd2ae(ha, pc->dec, p->slat, &h->az, &alt); + h->zd = ERFA_DPI/2. - alt; } @@ -256,7 +256,7 @@ int get_ObsPlace(struct timeval *tval, polarCrds *p2000, localWeather *weath, po p2000->ra, p2000->dec, pr, pd, px, rv, MJD.utc1, MJD.utc2, d.DUT1, p.slong, p.slat, p.salt, d.px, d.py, p, t, h, wl); */ - if(iauAtco13(p2000->ra, p2000->dec, + if(eraAtco13(p2000->ra, p2000->dec, pr, pd, px, rv, MJD.utc1, MJD.utc2, dut1.DUT1, @@ -280,7 +280,7 @@ int get_ObsPlace(struct timeval *tval, polarCrds *p2000, localWeather *weath, po #ifdef EBUG printf("A(bta)/Z: "); radtodeg(aob); - printf("("); radtodeg(DPI-aob); + printf("("); radtodeg(ERFA_DPI-aob); printf(")/"); radtodeg(zob); printf("\n"); #endif diff --git a/Daemons/10micron_stellarium/libsofa.h b/Daemons/10micron_stellarium/libsofa.h index 3b6f5a1..7bb84ff 100644 --- a/Daemons/10micron_stellarium/libsofa.h +++ b/Daemons/10micron_stellarium/libsofa.h @@ -19,8 +19,8 @@ #ifndef LIBSOFA_H__ #define LIBSOFA_H__ -#include -#include +#include +#include #include // JD2451544.5 == 2000.0 diff --git a/Daemons/10micron_stellarium/main.c b/Daemons/10micron_stellarium/main.c index fcea49c..d5287cf 100644 --- a/Daemons/10micron_stellarium/main.c +++ b/Daemons/10micron_stellarium/main.c @@ -230,7 +230,7 @@ int proc_data(uint8_t *data, ssize_t len){ horizCrds hnow; // without refraction polarCrds p2000, pnow; p2000.ra = tagRA/12. * M_PI; - p2000.dec = tagDec * DD2R; + p2000.dec = tagDec * ERFA_DD2R; // now J2000 obs Jnow if(get_ObsPlace(NULL, &p2000, NULL, &pnow, &hnow)){ WARNX("Can't convert coordinates to Jnow"); @@ -238,22 +238,22 @@ int proc_data(uint8_t *data, ssize_t len){ } #ifdef EBUG int i[4], j[4]; char pm, pm1; - iauA2af(2, hnow.az, &pm, i); - iauA2af(2, hnow.zd, &pm1, j); + eraA2af(2, hnow.az, &pm, i); + eraA2af(2, hnow.zd, &pm1, j); DBG("az: %c%02d %02d %02d.%2.d, zd: %c%02d %02d %02d.%2.d", pm, i[0],i[1],i[2],i[3], pm1,j[0],j[1],j[2],j[3]); - iauA2af(2, M_PI_2 - hnow.zd, &pm, i); + eraA2af(2, M_PI_2 - hnow.zd, &pm, i); DBG("h: %c%02d %02d %02d.%2.d", pm, i[0],i[1],i[2],i[3]); #endif - if(hnow.zd > 80.*DD2R){ + if(hnow.zd > 80.*ERFA_DD2R){ WARNX("Z > 80degr, stop telescope"); putlog("Z>80 - stop!"); stop_telescope(); return 0; } tagRA = (pnow.ra - pnow.eo) / M_PI * 12.; - tagDec = pnow.dec / DD2R; + tagDec = pnow.dec / ERFA_DD2R; if(!setCoords(tagRA, tagDec)) return 0; return 1; } diff --git a/Daemons/10micron_stellarium/telescope.c b/Daemons/10micron_stellarium/telescope.c index c363615..89f61c2 100644 --- a/Daemons/10micron_stellarium/telescope.c +++ b/Daemons/10micron_stellarium/telescope.c @@ -499,7 +499,7 @@ void wrhdr(){ DBG("Failed"); return; } - LST *= 15.*DD2R; // convert hours to radians + LST *= 15.*ERFA_DD2R; // convert hours to radians }else{ lst = MALLOC(char, 32); r2sHMS(LST, lst, 32); @@ -512,7 +512,7 @@ void wrhdr(){ jd = MALLOC(char, 32); snprintf(jd, 32, "%.10f", mjd.MJD); } - polarCrds pNow = {.ra = r*15.*DD2R, .dec = d*DD2R}; // coordinates now + polarCrds pNow = {.ra = r*15.*ERFA_DD2R, .dec = d*ERFA_DD2R}; // coordinates now horizCrds hNow; eq2hor(&pNow, &hNow, LST); failcounter = 0; @@ -569,9 +569,9 @@ void wrhdr(){ WRHDR("RA", val, "Telescope right ascension, current epoch, deg"); snprintf(val, 22, "%.10f", d); WRHDR("DEC", val, "Telescope declination, current epoch, deg"); - snprintf(val, 22, "%.10f", hNow.az * DR2D); + snprintf(val, 22, "%.10f", hNow.az * ERFA_DR2D); WRHDR("AZ", val, "Telescope azimuth, current epoch, deg"); - snprintf(val, 22, "%.10f", hNow.zd * DR2D); + snprintf(val, 22, "%.10f", hNow.zd * ERFA_DR2D); WRHDR("ZD", val, "Telescope zenith distance, current epoch, deg"); WRHDR("TELSTAT", strstatus(mountstatus), "Telescope mount status"); if(!get_MJDt(NULL, &mjd)){